2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/compiler/expression/modifier_expression.h"
18 #include "hphp/util/parser/hphp.tab.hpp"
22 ///////////////////////////////////////////////////////////////////////////////
23 // constructors/destructors
25 ModifierExpression::ModifierExpression
26 (EXPRESSION_CONSTRUCTOR_PARAMETERS
)
27 : Expression(EXPRESSION_CONSTRUCTOR_PARAMETER_VALUES(ModifierExpression
)) {
30 ExpressionPtr
ModifierExpression::clone() {
31 ModifierExpressionPtr
exp(new ModifierExpression(*this));
32 Expression::deepCopy(exp
);
36 ///////////////////////////////////////////////////////////////////////////////
39 void ModifierExpression::add(int modifier
) {
40 m_modifiers
.push_back(modifier
);
43 int ModifierExpression::operator[](int index
) {
44 assert(index
>= 0 && index
< getCount());
45 return m_modifiers
[index
];
48 bool ModifierExpression::isPublic() const {
49 for (unsigned int i
= 0; i
< m_modifiers
.size(); i
++) {
50 switch (m_modifiers
[i
]) {
51 case T_PUBLIC
: return true;
53 case T_PRIVATE
: return false;
61 bool ModifierExpression::hasModifier(int modifier
) const {
62 for (unsigned int i
= 0; i
< m_modifiers
.size(); i
++) {
63 if (m_modifiers
[i
] == modifier
) {
70 bool ModifierExpression::isProtected() const {
71 return hasModifier(T_PROTECTED
);
74 bool ModifierExpression::isPrivate() const {
75 return hasModifier(T_PRIVATE
);
78 bool ModifierExpression::isStatic() const {
79 return hasModifier(T_STATIC
);
82 bool ModifierExpression::isAbstract() const {
83 return hasModifier(T_ABSTRACT
);
86 bool ModifierExpression::isFinal() const {
87 return hasModifier(T_FINAL
);
90 ///////////////////////////////////////////////////////////////////////////////
91 // static analysis functions
93 void ModifierExpression::analyzeProgram(AnalysisResultPtr ar
) {
97 TypePtr
ModifierExpression::inferTypes(AnalysisResultPtr ar
, TypePtr type
,
103 ///////////////////////////////////////////////////////////////////////////////
104 // code generation functions
106 void ModifierExpression::outputPHP(CodeGenerator
&cg
, AnalysisResultPtr ar
) {
107 if (m_modifiers
.empty()) {
112 bool printed
= false;
113 for (unsigned int i
= 0; i
< m_modifiers
.size(); i
++) {
114 switch (m_modifiers
[i
]) {
115 case T_PUBLIC
: cg_printf("public"); printed
= true; break;
116 case T_PROTECTED
: cg_printf("protected"); printed
= true; break;
117 case T_PRIVATE
: cg_printf("private"); printed
= true; break;
124 for (unsigned int i
= 0; i
< m_modifiers
.size(); i
++) {
125 switch (m_modifiers
[i
]) {
126 case T_PUBLIC
: break;
127 case T_PROTECTED
: break;
128 case T_PRIVATE
: break;
129 case T_STATIC
: cg_printf(" static"); break;
130 case T_ABSTRACT
: cg_printf(" abstract"); break;
131 case T_FINAL
: cg_printf(" final"); break;