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/join_clause.h"
18 #include "hphp/compiler/analysis/code_error.h"
19 #include "hphp/runtime/base/complex-types.h"
23 ///////////////////////////////////////////////////////////////////////////////
24 // constructors/destructors
26 JoinClause::JoinClause
27 (EXPRESSION_CONSTRUCTOR_PARAMETERS
,
28 const std::string
&var
, ExpressionPtr coll
, ExpressionPtr left
,
29 ExpressionPtr right
, const std::string
&group
)
30 : Expression(EXPRESSION_CONSTRUCTOR_PARAMETER_VALUES(JoinClause
)),
31 m_var(var
), m_coll(coll
), m_left(left
),
32 m_right(right
), m_group(group
) {
35 ExpressionPtr
JoinClause::clone() {
36 JoinClausePtr
exp(new JoinClause(*this));
37 Expression::deepCopy(exp
);
39 exp
->m_coll
= Clone(m_coll
);
40 exp
->m_left
= Clone(m_left
);
41 exp
->m_right
= Clone(m_right
);
42 exp
->m_group
= m_group
;
46 ///////////////////////////////////////////////////////////////////////////////
49 ///////////////////////////////////////////////////////////////////////////////
50 // static analysis functions
52 void JoinClause::analyzeProgram(AnalysisResultPtr ar
) {
53 m_coll
->analyzeProgram(ar
);
54 m_left
->analyzeProgram(ar
);
55 m_right
->analyzeProgram(ar
);
58 ConstructPtr
JoinClause::getNthKid(int n
) const {
70 return ConstructPtr();
73 int JoinClause::getKidCount() const {
77 void JoinClause::setNthKid(int n
, ConstructPtr cp
) {
80 m_coll
= dynamic_pointer_cast
<Expression
>(cp
);
83 m_left
= dynamic_pointer_cast
<Expression
>(cp
);
86 m_right
= dynamic_pointer_cast
<Expression
>(cp
);
93 TypePtr
JoinClause::inferTypes(AnalysisResultPtr ar
, TypePtr type
,
95 m_coll
->inferAndCheck(ar
, Type::Some
, false);
96 m_left
->inferAndCheck(ar
, Type::Some
, false);
97 m_right
->inferAndCheck(ar
, Type::Some
, false);
101 ///////////////////////////////////////////////////////////////////////////////
103 void JoinClause::outputCodeModel(CodeGenerator
&cg
) {
105 if (!m_group
.empty()) numProps
++;
106 cg
.printObjectHeader("JoinClause", numProps
);
107 cg
.printPropertyHeader("identifier");
108 cg
.printValue(m_var
);
109 cg
.printPropertyHeader("collection");
110 m_coll
->outputCodeModel(cg
);
111 cg
.printPropertyHeader("left");
112 m_left
->outputCodeModel(cg
);
113 cg
.printPropertyHeader("right");
114 m_right
->outputCodeModel(cg
);
115 if (!m_group
.empty()) {
116 cg
.printPropertyHeader("group");
117 cg
.printValue(m_group
);
119 cg
.printPropertyHeader("sourceLocation");
120 cg
.printLocation(this->getLocation());
121 cg
.printObjectFooter();
124 ///////////////////////////////////////////////////////////////////////////////
125 // code generation functions
127 void JoinClause::outputPHP(CodeGenerator
&cg
, AnalysisResultPtr ar
) {
128 cg_printf("join %s in ", m_var
.c_str());
129 m_coll
->outputPHP(cg
, ar
);
131 m_left
->outputPHP(cg
, ar
);
132 cg_printf(" equals ");
133 m_right
->outputPHP(cg
, ar
);
134 if (!m_group
.empty()) {
135 cg_printf(" into %s", m_group
.c_str());