6faa7cbea1
Adds runtime support for non-class typehints. Typedefs are introduced using type statements, and autoloaded via a new autoload map entry. Shapes are parsed but the structure is currently thrown away and treated as arrays at runtime. This extends the NamedEntity structure to sometimes cache 'NameDefs', which are either Typedef*'s or Class*'s. VerifyParamType now has to check for typedefs if an object fails a class check, or when checking non-Object types against a non-primitive type name that isn't a class.
161 linhas
6.0 KiB
C++
161 linhas
6.0 KiB
C++
/*
|
|
+----------------------------------------------------------------------+
|
|
| HipHop for PHP |
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| http://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#ifndef __STATEMENT_H__
|
|
#define __STATEMENT_H__
|
|
|
|
#include <compiler/expression/expression.h>
|
|
|
|
#define STATEMENT_CONSTRUCTOR_BASE_PARAMETERS \
|
|
BlockScopePtr scope, LocationPtr loc, Statement::KindOf kindOf
|
|
#define STATEMENT_CONSTRUCTOR_BASE_PARAMETER_VALUES \
|
|
scope, loc, kindOf
|
|
#define STATEMENT_CONSTRUCTOR_PARAMETERS \
|
|
BlockScopePtr scope, LocationPtr loc
|
|
#define STATEMENT_CONSTRUCTOR_PARAMETER_VALUES(kindOf) \
|
|
scope, loc, Statement::KindOf##kindOf
|
|
#define DECLARE_BASE_STATEMENT_VIRTUAL_FUNCTIONS \
|
|
virtual void analyzeProgram(AnalysisResultPtr ar); \
|
|
virtual StatementPtr clone(); \
|
|
virtual void inferTypes(AnalysisResultPtr ar); \
|
|
virtual void outputPHP(CodeGenerator &cg, AnalysisResultPtr ar);
|
|
#define DECLARE_STATEMENT_VIRTUAL_FUNCTIONS \
|
|
DECLARE_BASE_STATEMENT_VIRTUAL_FUNCTIONS; \
|
|
virtual ConstructPtr getNthKid(int n) const; \
|
|
virtual int getKidCount() const; \
|
|
virtual void setNthKid(int n, ConstructPtr cp)
|
|
#define NULL_STATEMENT() \
|
|
BlockStatementPtr(new BlockStatement(getScope(), getLocation(), \
|
|
StatementListPtr()))
|
|
|
|
namespace HPHP {
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
DECLARE_BOOST_TYPES(Statement);
|
|
|
|
#define DECLARE_STATEMENT_TYPES(x) \
|
|
x(FunctionStatement), \
|
|
x(ClassStatement), \
|
|
x(InterfaceStatement), \
|
|
x(ClassVariable), \
|
|
x(ClassConstant), \
|
|
x(MethodStatement), \
|
|
x(StatementList), \
|
|
x(BlockStatement), \
|
|
x(IfBranchStatement), \
|
|
x(IfStatement), \
|
|
x(WhileStatement), \
|
|
x(DoStatement), \
|
|
x(ForStatement), \
|
|
x(SwitchStatement), \
|
|
x(CaseStatement), \
|
|
x(BreakStatement), \
|
|
x(ContinueStatement), \
|
|
x(ReturnStatement), \
|
|
x(GlobalStatement), \
|
|
x(StaticStatement), \
|
|
x(EchoStatement), \
|
|
x(UnsetStatement), \
|
|
x(ExpStatement), \
|
|
x(ForEachStatement), \
|
|
x(FinallyStatement), \
|
|
x(CatchStatement), \
|
|
x(TryStatement), \
|
|
x(ThrowStatement), \
|
|
x(GotoStatement), \
|
|
x(LabelStatement), \
|
|
x(UseTraitStatement), \
|
|
x(TraitPrecStatement), \
|
|
x(TraitAliasStatement), \
|
|
x(TypedefStatement)
|
|
|
|
class Statement : public Construct {
|
|
public:
|
|
#define DEC_STMT_ENUM(x) KindOf##x
|
|
enum KindOf {
|
|
DECLARE_STATEMENT_TYPES(DEC_STMT_ENUM)
|
|
/* KindOfCount = 29 */
|
|
};
|
|
static const char *Names[];
|
|
|
|
protected:
|
|
Statement(STATEMENT_CONSTRUCTOR_BASE_PARAMETERS);
|
|
|
|
public:
|
|
|
|
/**
|
|
* Type checking without RTTI.
|
|
*/
|
|
bool is(KindOf type) const { return m_kindOf == type;}
|
|
KindOf getKindOf() const { return m_kindOf;}
|
|
|
|
/**
|
|
* This is to avoid dynamic casting to StatementList in Parser.
|
|
*/
|
|
virtual void addElement(StatementPtr stmt);
|
|
virtual void insertElement(StatementPtr stmt, int index = 0);
|
|
|
|
/**
|
|
* Return a name for stats purpose.
|
|
*/
|
|
virtual std::string getName() const { return "";}
|
|
|
|
StatementPtr getNthStmt(int n) const {
|
|
return boost::dynamic_pointer_cast<Statement>(getNthKid(n));
|
|
}
|
|
|
|
/**
|
|
* Called before type inference.
|
|
*/
|
|
virtual StatementPtr preOptimize(AnalysisResultConstPtr ar) {
|
|
return StatementPtr();
|
|
}
|
|
|
|
/**
|
|
* Called after type inference.
|
|
*/
|
|
virtual StatementPtr postOptimize(AnalysisResultConstPtr ar) {
|
|
return StatementPtr();
|
|
}
|
|
|
|
/**
|
|
* Called when types need to be inferred inside this statement.
|
|
*/
|
|
virtual void inferTypes(AnalysisResultPtr ar) = 0;
|
|
|
|
bool hasReachableLabel() const;
|
|
|
|
virtual bool hasDecl() const { return false; }
|
|
virtual bool hasImpl() const { return hasEffect(); }
|
|
virtual bool hasBody() const { return true;}
|
|
virtual bool hasRetExp() const { return false; }
|
|
|
|
virtual StatementPtr clone() {
|
|
assert(false);
|
|
return StatementPtr();
|
|
}
|
|
|
|
virtual int getRecursiveCount() const { return 1; }
|
|
|
|
protected:
|
|
KindOf m_kindOf;
|
|
int m_silencerCountMax;
|
|
int m_silencerCountCurrent;
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
}
|
|
#endif // __STATEMENT_H__
|