2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2015 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_CONSTANT_TABLE_H_
18 #define incl_HPHP_CONSTANT_TABLE_H_
20 #include "hphp/compiler/analysis/symbol_table.h"
22 #include "hphp/compiler/analysis/block_scope.h"
25 ///////////////////////////////////////////////////////////////////////////////
27 DECLARE_BOOST_TYPES(Expression
);
28 DECLARE_BOOST_TYPES(CodeError
);
29 DECLARE_BOOST_TYPES(ConstantTable
);
30 DECLARE_BOOST_TYPES(ClassScope
);
33 * These are the only places that a new constant can be declared:
35 * const T_STRING = static_scalar
36 * class { const T_STRING = static_scalar,...}
37 * define('NAME', static_scalar)
39 class ConstantTable
: public SymbolTable
{
41 explicit ConstantTable(BlockScope
&blockScope
);
44 * Whether defining something to be non-scalar value or redeclared, or
45 * marked up by "Dynamic" note.
47 bool isDynamic(const std::string
&name
) const {
48 const Symbol
*sym
= getSymbol(name
);
49 return sym
&& sym
->isDynamic();
52 bool hasDynamic() const { return m_hasDynamic
; }
55 * Explicitly setting a constant to be dynamic, mainly for "Dynamic" note.
57 void setDynamic(AnalysisResultConstPtr ar
, const std::string
&name
);
60 * Called when a constant is declared (l-value).
62 void add(const std::string
&name
, ExpressionPtr exp
,
63 AnalysisResultConstPtr ar
, ConstructPtr construct
);
66 * Called after a constants value is determined
68 void setValue(AnalysisResultConstPtr ar
, const std::string
&name
,
72 * Generate all constant declarations for this symbol table.
74 void outputPHP(CodeGenerator
&cg
, AnalysisResultPtr ar
);
76 bool isRecursivelyDeclared(AnalysisResultConstPtr ar
,
77 const std::string
&name
) const;
78 ConstructPtr
getValueRecur(AnalysisResultConstPtr ar
, const std::string
&name
,
79 ClassScopePtr
&defClass
) const;
80 ConstructPtr
getDeclarationRecur(AnalysisResultConstPtr ar
,
81 const std::string
&name
,
82 ClassScopePtr
&defClass
) const;
84 void cleanupForError(AnalysisResultConstPtr ar
);
88 ClassScopePtr
findParent(AnalysisResultConstPtr ar
,
89 const std::string
&name
) const;
90 ClassScopeRawPtr
findBase(AnalysisResultConstPtr ar
,
91 const std::string
&name
,
92 const std::vector
<std::string
> &bases
) const;
95 ///////////////////////////////////////////////////////////////////////////////
97 #endif // incl_HPHP_CONSTANT_TABLE_H_