2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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 #ifndef incl_HPHP_STATEMENT_H_
18 #define incl_HPHP_STATEMENT_H_
20 #include "hphp/compiler/expression/expression.h"
21 #include "hphp/compiler/analysis/label_scope.h"
24 #define STATEMENT_CONSTRUCTOR_BASE_PARAMETERS \
25 BlockScopePtr scope, LabelScopePtr labelScope, \
26 const Location::Range& r, Construct::KindOf kindOf
27 #define STATEMENT_CONSTRUCTOR_BASE_PARAMETER_VALUES \
28 scope, labelScope, r, kindOf
29 #define STATEMENT_CONSTRUCTOR_PARAMETERS \
30 BlockScopePtr scope, LabelScopePtr labelScope, const Location::Range& r
31 #define STATEMENT_CONSTRUCTOR_PARAMETER_VALUES(kindOf) \
32 scope, labelScope, r, Statement::KindOf##kindOf
33 #define DECLARE_BASE_STATEMENT_VIRTUAL_FUNCTIONS \
34 void analyzeProgram(AnalysisResultPtr ar) override; \
35 StatementPtr clone() override; \
36 void outputPHP(CodeGenerator &cg, AnalysisResultPtr ar) override;
37 #define DECLARE_STATEMENT_VIRTUAL_FUNCTIONS \
38 DECLARE_BASE_STATEMENT_VIRTUAL_FUNCTIONS; \
39 ConstructPtr getNthKid(int n) const override; \
40 int getKidCount() const override; \
41 void setNthKid(int n, ConstructPtr cp) override
43 #define NULL_STATEMENT() \
44 std::make_shared<BlockStatement>(getScope(), \
50 ///////////////////////////////////////////////////////////////////////////////
51 DECLARE_BOOST_TYPES(Statement
);
52 DECLARE_BOOST_TYPES(LabelScope
);
54 struct Statement
: Construct
{
56 static const char *Names
[];
59 static const char* nameOfKind(Construct::KindOf
);
62 Statement(STATEMENT_CONSTRUCTOR_BASE_PARAMETERS
);
66 * This is to avoid dynamic casting to StatementList in Parser.
68 virtual void addElement(StatementPtr stmt
);
69 virtual void insertElement(StatementPtr stmt
, int index
= 0);
72 * Return a name for stats purpose.
74 virtual std::string
getName() const { return "";}
76 StatementPtr
getNthStmt(int n
) const {
77 return dynamic_pointer_cast
<Statement
>(getNthKid(n
));
81 * Called before type inference.
83 virtual StatementPtr
preOptimize(AnalysisResultConstPtr
/*ar*/) {
84 return StatementPtr();
87 bool hasReachableLabel() const;
89 virtual bool hasDecl() const { return false; }
90 virtual bool hasImpl() const { return hasEffect(); }
91 virtual bool hasBody() const { return true;}
92 virtual bool hasRetExp() const { return false; }
94 virtual StatementPtr
clone() {
96 return StatementPtr();
99 virtual int getRecursiveCount() const { return 1; }
101 LabelScopePtr
getLabelScope() { return m_labelScope
; }
102 void setLabelScope(LabelScopePtr labelScope
) { m_labelScope
= labelScope
; }
105 int m_silencerCountMax
;
106 int m_silencerCountCurrent
;
107 LabelScopePtr m_labelScope
;
110 ///////////////////////////////////////////////////////////////////////////////
112 #endif // incl_HPHP_STATEMENT_H_