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/ordering.h"
18 #include "hphp/compiler/analysis/code_error.h"
19 #include "hphp/runtime/base/complex-types.h"
20 #include "hphp/compiler/code_model_enums.h"
24 ///////////////////////////////////////////////////////////////////////////////
25 // constructors/destructors
28 (EXPRESSION_CONSTRUCTOR_PARAMETERS
,
29 ExpressionPtr key
, std::string direction
)
30 : Expression(EXPRESSION_CONSTRUCTOR_PARAMETER_VALUES(Ordering
)),
32 if (direction
== "") {
33 m_direction
= PHP_NOT_SPECIFIED
;
34 } else if (strcasecmp(direction
.c_str(), "ascending") == 0) {
35 m_direction
= PHP_ASCENDING
;
37 assert(strcasecmp(direction
.c_str(), "descending") == 0);
38 m_direction
= PHP_DESCENDING
;
42 ExpressionPtr
Ordering::clone() {
43 OrderingPtr
exp(new Ordering(*this));
44 Expression::deepCopy(exp
);
45 exp
->m_key
= Clone(m_key
);
46 exp
->m_direction
= m_direction
;
50 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
54 // static analysis functions
56 void Ordering::analyzeProgram(AnalysisResultPtr ar
) {
57 m_key
->analyzeProgram(ar
);
60 ConstructPtr
Ordering::getNthKid(int n
) const {
68 return ConstructPtr();
71 int Ordering::getKidCount() const {
75 void Ordering::setNthKid(int n
, ConstructPtr cp
) {
78 m_key
= dynamic_pointer_cast
<Expression
>(cp
);
85 TypePtr
Ordering::inferTypes(AnalysisResultPtr ar
, TypePtr type
,
87 m_key
->inferAndCheck(ar
, Type::Some
, false);
91 ///////////////////////////////////////////////////////////////////////////////
93 void Ordering::outputCodeModel(CodeGenerator
&cg
) {
94 cg
.printObjectHeader("Ordering", 3);
95 cg
.printPropertyHeader("expression");
96 m_key
->outputCodeModel(cg
);
97 cg
.printPropertyHeader("order");
98 cg
.printValue(m_direction
);
99 cg
.printPropertyHeader("sourceLocation");
100 cg
.printLocation(this->getLocation());
101 cg
.printObjectFooter();
104 ///////////////////////////////////////////////////////////////////////////////
105 // code generation functions
107 void Ordering::outputPHP(CodeGenerator
&cg
, AnalysisResultPtr ar
) {
108 m_key
->outputPHP(cg
, ar
);
109 switch (m_direction
) {
111 cg_printf(" ascending");
114 cg_printf(" decending");