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/encaps_list_expression.h"
18 #include "hphp/compiler/expression/expression_list.h"
19 #include "hphp/compiler/expression/binary_op_expression.h"
20 #include "hphp/compiler/analysis/code_error.h"
21 #include "hphp/runtime/base/builtin_functions.h"
25 ///////////////////////////////////////////////////////////////////////////////
26 // constructors/destructors
28 EncapsListExpression::EncapsListExpression
29 (EXPRESSION_CONSTRUCTOR_PARAMETERS
, int type
, ExpressionListPtr expList
)
30 : Expression(EXPRESSION_CONSTRUCTOR_PARAMETER_VALUES(EncapsListExpression
)),
31 m_type(type
), m_exps(expList
) {
34 ExpressionPtr
EncapsListExpression::clone() {
35 EncapsListExpressionPtr
exp(new EncapsListExpression(*this));
36 Expression::deepCopy(exp
);
37 exp
->m_exps
= Clone(m_exps
);
41 ///////////////////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////////////////
45 // static analysis functions
47 void EncapsListExpression::analyzeProgram(AnalysisResultPtr ar
) {
49 for (int i
= 0; i
< m_exps
->getCount(); i
++) {
50 (*m_exps
)[i
]->analyzeProgram(ar
);
55 ConstructPtr
EncapsListExpression::getNthKid(int n
) const {
63 return ConstructPtr();
66 int EncapsListExpression::getKidCount() const {
70 void EncapsListExpression::setNthKid(int n
, ConstructPtr cp
) {
73 m_exps
= boost::dynamic_pointer_cast
<ExpressionList
>(cp
);
81 void EncapsListExpression::stripConcat() {
82 m_exps
->stripConcat();
85 ExpressionPtr
EncapsListExpression::preOptimize(AnalysisResultConstPtr ar
) {
86 if (m_type
!= '`' && m_type
!= '\'' && m_exps
) {
87 int count
= m_exps
->getCount();
88 // turn into cascaded concat
91 BinaryOpExpressionPtr(new BinaryOpExpression(
92 getScope(), getLocation(),
93 (*m_exps
)[0], (*m_exps
)[1], '.'));
94 for (int i
= 2; i
< count
; i
++) {
96 BinaryOpExpressionPtr(new BinaryOpExpression(
97 getScope(), getLocation(),
98 exp
, (*m_exps
)[i
], '.'));
103 return ExpressionPtr();
106 TypePtr
EncapsListExpression::inferTypes(AnalysisResultPtr ar
, TypePtr type
,
109 for (int i
= 0; i
< m_exps
->getCount(); i
++) {
110 (*m_exps
)[i
]->inferAndCheck(ar
, Type::String
, false);
116 bool EncapsListExpression::canonCompare(ExpressionPtr e
) const {
117 if (!Expression::canonCompare(e
)) return false;
118 EncapsListExpressionPtr el
= static_pointer_cast
<EncapsListExpression
>(e
);
119 return m_type
== el
->m_type
;
122 ///////////////////////////////////////////////////////////////////////////////
123 // code generation functions
125 void EncapsListExpression::outputPHP(CodeGenerator
&cg
, AnalysisResultPtr ar
) {
126 if (m_type
== '`') cg_printf("shell_exec(");
129 for (int i
= 0; i
< m_exps
->getCount(); i
++) {
130 if (i
> 0) cg_printf(" . ");
131 (*m_exps
)[i
]->outputPHP(cg
, ar
);
137 if (m_type
== '`') cg_printf(")");