diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-10-01 14:18:59 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-01 14:19:11 -0700 |
commit | c9627e0a0d191583e266836b8ce279e6dc527a40 (patch) | |
tree | f830b00031cc1d5eed1988d76e0a4647ca0be3a8 /deps/v8/src/ast.h | |
parent | 5829716649a543f2c7e43859e5c0e32491b61198 (diff) | |
download | node-new-c9627e0a0d191583e266836b8ce279e6dc527a40.tar.gz |
Upgrade V8 to 2.4.7
Diffstat (limited to 'deps/v8/src/ast.h')
-rw-r--r-- | deps/v8/src/ast.h | 254 |
1 files changed, 102 insertions, 152 deletions
diff --git a/deps/v8/src/ast.h b/deps/v8/src/ast.h index 9fcf25672f..fc34fd4614 100644 --- a/deps/v8/src/ast.h +++ b/deps/v8/src/ast.h @@ -118,35 +118,38 @@ typedef ZoneList<Handle<String> > ZoneStringList; typedef ZoneList<Handle<Object> > ZoneObjectList; +#define DECLARE_NODE_TYPE(type) \ + virtual void Accept(AstVisitor* v); \ + virtual AstNode::Type node_type() const { return AstNode::k##type; } \ + virtual type* As##type() { return this; } + + class AstNode: public ZoneObject { public: +#define DECLARE_TYPE_ENUM(type) k##type, + enum Type { + AST_NODE_LIST(DECLARE_TYPE_ENUM) + kInvalid = -1 + }; +#undef DECLARE_TYPE_ENUM + virtual ~AstNode() { } + virtual void Accept(AstVisitor* v) = 0; + virtual Type node_type() const { return kInvalid; } + + // Type testing & conversion functions overridden by concrete subclasses. +#define DECLARE_NODE_FUNCTIONS(type) \ + virtual type* As##type() { return NULL; } + AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) +#undef DECLARE_NODE_FUNCTIONS - // Type testing & conversion. virtual Statement* AsStatement() { return NULL; } - virtual Block* AsBlock() { return NULL; } - virtual ExpressionStatement* AsExpressionStatement() { return NULL; } - virtual EmptyStatement* AsEmptyStatement() { return NULL; } virtual Expression* AsExpression() { return NULL; } - virtual Literal* AsLiteral() { return NULL; } - virtual Slot* AsSlot() { return NULL; } - virtual VariableProxy* AsVariableProxy() { return NULL; } - virtual Property* AsProperty() { return NULL; } - virtual Call* AsCall() { return NULL; } virtual TargetCollector* AsTargetCollector() { return NULL; } virtual BreakableStatement* AsBreakableStatement() { return NULL; } virtual IterationStatement* AsIterationStatement() { return NULL; } - virtual ForStatement* AsForStatement() { return NULL; } - virtual UnaryOperation* AsUnaryOperation() { return NULL; } - virtual CountOperation* AsCountOperation() { return NULL; } - virtual BinaryOperation* AsBinaryOperation() { return NULL; } - virtual Assignment* AsAssignment() { return NULL; } - virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } - virtual ObjectLiteral* AsObjectLiteral() { return NULL; } - virtual ArrayLiteral* AsArrayLiteral() { return NULL; } - virtual CompareOperation* AsCompareOperation() { return NULL; } }; @@ -155,7 +158,6 @@ class Statement: public AstNode { Statement() : statement_pos_(RelocInfo::kNoPosition) {} virtual Statement* AsStatement() { return this; } - virtual ReturnStatement* AsReturnStatement() { return NULL; } virtual Assignment* StatementAsSimpleAssignment() { return NULL; } virtual CountOperation* StatementAsCountOperation() { return NULL; } @@ -172,18 +174,6 @@ class Statement: public AstNode { class Expression: public AstNode { public: - enum Context { - // Not assigned a context yet, or else will not be visited during - // code generation. - kUninitialized, - // Evaluated for its side effects. - kEffect, - // Evaluated for its value (and side effects). - kValue, - // Evaluated for control flow (and side effects). - kTest - }; - Expression() : bitfields_(0) {} virtual Expression* AsExpression() { return this; } @@ -325,9 +315,7 @@ class Block: public BreakableStatement { public: inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block); - virtual void Accept(AstVisitor* v); - - virtual Block* AsBlock() { return this; } + DECLARE_NODE_TYPE(Block) virtual Assignment* StatementAsSimpleAssignment() { if (statements_.length() != 1) return NULL; @@ -342,7 +330,7 @@ class Block: public BreakableStatement { void AddStatement(Statement* statement) { statements_.Add(statement); } ZoneList<Statement*>* statements() { return &statements_; } - bool is_initializer_block() const { return is_initializer_block_; } + bool is_initializer_block() const { return is_initializer_block_; } private: ZoneList<Statement*> statements_; @@ -361,11 +349,11 @@ class Declaration: public AstNode { ASSERT(fun == NULL || mode == Variable::VAR); } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(Declaration) - VariableProxy* proxy() const { return proxy_; } - Variable::Mode mode() const { return mode_; } - FunctionLiteral* fun() const { return fun_; } // may be NULL + VariableProxy* proxy() const { return proxy_; } + Variable::Mode mode() const { return mode_; } + FunctionLiteral* fun() const { return fun_; } // may be NULL private: VariableProxy* proxy_; @@ -402,13 +390,13 @@ class DoWhileStatement: public IterationStatement { public: explicit inline DoWhileStatement(ZoneStringList* labels); + DECLARE_NODE_TYPE(DoWhileStatement) + void Initialize(Expression* cond, Statement* body) { IterationStatement::Initialize(body); cond_ = cond; } - virtual void Accept(AstVisitor* v); - Expression* cond() const { return cond_; } // Position where condition expression starts. We need it to make @@ -426,13 +414,13 @@ class WhileStatement: public IterationStatement { public: explicit WhileStatement(ZoneStringList* labels); + DECLARE_NODE_TYPE(WhileStatement) + void Initialize(Expression* cond, Statement* body) { IterationStatement::Initialize(body); cond_ = cond; } - virtual void Accept(AstVisitor* v); - Expression* cond() const { return cond_; } bool may_have_function_literal() const { return may_have_function_literal_; @@ -452,7 +440,7 @@ class ForStatement: public IterationStatement { public: explicit inline ForStatement(ZoneStringList* labels); - virtual ForStatement* AsForStatement() { return this; } + DECLARE_NODE_TYPE(ForStatement) void Initialize(Statement* init, Expression* cond, @@ -464,13 +452,11 @@ class ForStatement: public IterationStatement { next_ = next; } - virtual void Accept(AstVisitor* v); - - Statement* init() const { return init_; } + Statement* init() const { return init_; } void set_init(Statement* stmt) { init_ = stmt; } - Expression* cond() const { return cond_; } + Expression* cond() const { return cond_; } void set_cond(Expression* expr) { cond_ = expr; } - Statement* next() const { return next_; } + Statement* next() const { return next_; } void set_next(Statement* stmt) { next_ = stmt; } bool may_have_function_literal() const { @@ -498,14 +484,14 @@ class ForInStatement: public IterationStatement { public: explicit inline ForInStatement(ZoneStringList* labels); + DECLARE_NODE_TYPE(ForInStatement) + void Initialize(Expression* each, Expression* enumerable, Statement* body) { IterationStatement::Initialize(body); each_ = each; enumerable_ = enumerable; } - virtual void Accept(AstVisitor* v); - Expression* each() const { return each_; } Expression* enumerable() const { return enumerable_; } @@ -520,10 +506,7 @@ class ExpressionStatement: public Statement { explicit ExpressionStatement(Expression* expression) : expression_(expression) { } - virtual void Accept(AstVisitor* v); - - // Type testing & conversion. - virtual ExpressionStatement* AsExpressionStatement() { return this; } + DECLARE_NODE_TYPE(ExpressionStatement) virtual Assignment* StatementAsSimpleAssignment(); virtual CountOperation* StatementAsCountOperation(); @@ -541,9 +524,9 @@ class ContinueStatement: public Statement { explicit ContinueStatement(IterationStatement* target) : target_(target) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(ContinueStatement) - IterationStatement* target() const { return target_; } + IterationStatement* target() const { return target_; } private: IterationStatement* target_; @@ -555,9 +538,9 @@ class BreakStatement: public Statement { explicit BreakStatement(BreakableStatement* target) : target_(target) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(BreakStatement) - BreakableStatement* target() const { return target_; } + BreakableStatement* target() const { return target_; } private: BreakableStatement* target_; @@ -569,10 +552,7 @@ class ReturnStatement: public Statement { explicit ReturnStatement(Expression* expression) : expression_(expression) { } - virtual void Accept(AstVisitor* v); - - // Type testing & conversion. - virtual ReturnStatement* AsReturnStatement() { return this; } + DECLARE_NODE_TYPE(ReturnStatement) Expression* expression() { return expression_; } @@ -586,9 +566,9 @@ class WithEnterStatement: public Statement { explicit WithEnterStatement(Expression* expression, bool is_catch_block) : expression_(expression), is_catch_block_(is_catch_block) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(WithEnterStatement) - Expression* expression() const { return expression_; } + Expression* expression() const { return expression_; } bool is_catch_block() const { return is_catch_block_; } @@ -602,7 +582,7 @@ class WithExitStatement: public Statement { public: WithExitStatement() { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(WithExitStatement) }; @@ -610,13 +590,13 @@ class CaseClause: public ZoneObject { public: CaseClause(Expression* label, ZoneList<Statement*>* statements); - bool is_default() const { return label_ == NULL; } - Expression* label() const { + bool is_default() const { return label_ == NULL; } + Expression* label() const { CHECK(!is_default()); return label_; } JumpTarget* body_target() { return &body_target_; } - ZoneList<Statement*>* statements() const { return statements_; } + ZoneList<Statement*>* statements() const { return statements_; } private: Expression* label_; @@ -629,15 +609,15 @@ class SwitchStatement: public BreakableStatement { public: explicit inline SwitchStatement(ZoneStringList* labels); + DECLARE_NODE_TYPE(SwitchStatement) + void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { tag_ = tag; cases_ = cases; } - virtual void Accept(AstVisitor* v); - - Expression* tag() const { return tag_; } - ZoneList<CaseClause*>* cases() const { return cases_; } + Expression* tag() const { return tag_; } + ZoneList<CaseClause*>* cases() const { return cases_; } private: Expression* tag_; @@ -659,7 +639,7 @@ class IfStatement: public Statement { then_statement_(then_statement), else_statement_(else_statement) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(IfStatement) bool HasThenStatement() const { return !then_statement()->IsEmpty(); } bool HasElseStatement() const { return !else_statement()->IsEmpty(); } @@ -729,10 +709,10 @@ class TryCatchStatement: public TryStatement { catch_block_(catch_block) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(TryCatchStatement) - VariableProxy* catch_var() const { return catch_var_; } - Block* catch_block() const { return catch_block_; } + VariableProxy* catch_var() const { return catch_var_; } + Block* catch_block() const { return catch_block_; } private: VariableProxy* catch_var_; @@ -746,7 +726,7 @@ class TryFinallyStatement: public TryStatement { : TryStatement(try_block), finally_block_(finally_block) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(TryFinallyStatement) Block* finally_block() const { return finally_block_; } @@ -757,18 +737,13 @@ class TryFinallyStatement: public TryStatement { class DebuggerStatement: public Statement { public: - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(DebuggerStatement) }; class EmptyStatement: public Statement { public: - EmptyStatement() {} - - virtual void Accept(AstVisitor* v); - - // Type testing & conversion. - virtual EmptyStatement* AsEmptyStatement() { return this; } + DECLARE_NODE_TYPE(EmptyStatement) }; @@ -776,13 +751,11 @@ class Literal: public Expression { public: explicit Literal(Handle<Object> handle) : handle_(handle) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(Literal) + virtual bool IsTrivial() { return true; } virtual bool IsSmiLiteral() { return handle_->IsSmi(); } - // Type testing & conversion. - virtual Literal* AsLiteral() { return this; } - // Check if this literal is identical to the other literal. bool IsIdenticalTo(const Literal* other) const { return handle_.is_identical_to(other->handle_); @@ -876,8 +849,7 @@ class ObjectLiteral: public MaterializedLiteral { properties_(properties), fast_elements_(fast_elements) {} - virtual ObjectLiteral* AsObjectLiteral() { return this; } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(ObjectLiteral) Handle<FixedArray> constant_properties() const { return constant_properties_; @@ -903,7 +875,7 @@ class RegExpLiteral: public MaterializedLiteral { pattern_(pattern), flags_(flags) {} - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(RegExpLiteral) Handle<String> pattern() const { return pattern_; } Handle<String> flags() const { return flags_; } @@ -926,8 +898,7 @@ class ArrayLiteral: public MaterializedLiteral { constant_elements_(constant_elements), values_(values) {} - virtual void Accept(AstVisitor* v); - virtual ArrayLiteral* AsArrayLiteral() { return this; } + DECLARE_NODE_TYPE(ArrayLiteral) Handle<FixedArray> constant_elements() const { return constant_elements_; } ZoneList<Expression*>* values() const { return values_; } @@ -947,7 +918,7 @@ class CatchExtensionObject: public Expression { : key_(key), value_(value) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(CatchExtensionObject) Literal* key() const { return key_; } VariableProxy* value() const { return value_; } @@ -960,19 +931,20 @@ class CatchExtensionObject: public Expression { class VariableProxy: public Expression { public: - virtual void Accept(AstVisitor* v); + explicit VariableProxy(Variable* var); + + DECLARE_NODE_TYPE(VariableProxy) // Type testing & conversion virtual Property* AsProperty() { return var_ == NULL ? NULL : var_->AsProperty(); } - virtual VariableProxy* AsVariableProxy() { - return this; - } - Variable* AsVariable() { - return this == NULL || var_ == NULL ? NULL : var_->AsVariable(); + if (this == NULL || var_ == NULL) return NULL; + Expression* rewrite = var_->rewrite(); + if (rewrite == NULL || rewrite->AsSlot() != NULL) return var_; + return NULL; } virtual bool IsValidLeftHandSide() { @@ -994,10 +966,10 @@ class VariableProxy: public Expression { return (variable == NULL) ? false : variable->is_arguments(); } - Handle<String> name() const { return name_; } - Variable* var() const { return var_; } - bool is_this() const { return is_this_; } - bool inside_with() const { return inside_with_; } + Handle<String> name() const { return name_; } + Variable* var() const { return var_; } + bool is_this() const { return is_this_; } + bool inside_with() const { return inside_with_; } void MarkAsTrivial() { is_trivial_ = true; } @@ -1062,10 +1034,7 @@ class Slot: public Expression { ASSERT(var != NULL); } - virtual void Accept(AstVisitor* v); - - // Type testing & conversion - virtual Slot* AsSlot() { return this; } + DECLARE_NODE_TYPE(Slot) bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } @@ -1092,10 +1061,7 @@ class Property: public Expression { Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) : obj_(obj), key_(key), pos_(pos), type_(type) { } - virtual void Accept(AstVisitor* v); - - // Type testing & conversion - virtual Property* AsProperty() { return this; } + DECLARE_NODE_TYPE(Property) virtual bool IsValidLeftHandSide() { return true; } @@ -1124,10 +1090,7 @@ class Call: public Expression { Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) : expression_(expression), arguments_(arguments), pos_(pos) { } - virtual void Accept(AstVisitor* v); - - // Type testing and conversion. - virtual Call* AsCall() { return this; } + DECLARE_NODE_TYPE(Call) Expression* expression() const { return expression_; } ZoneList<Expression*>* arguments() const { return arguments_; } @@ -1149,7 +1112,7 @@ class CallNew: public Expression { CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) : expression_(expression), arguments_(arguments), pos_(pos) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(CallNew) Expression* expression() const { return expression_; } ZoneList<Expression*>* arguments() const { return arguments_; } @@ -1173,7 +1136,7 @@ class CallRuntime: public Expression { ZoneList<Expression*>* arguments) : name_(name), function_(function), arguments_(arguments) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(CallRuntime) Handle<String> name() const { return name_; } Runtime::Function* function() const { return function_; } @@ -1194,11 +1157,9 @@ class UnaryOperation: public Expression { ASSERT(Token::IsUnaryOp(op)); } - virtual void Accept(AstVisitor* v); - virtual bool ResultOverwriteAllowed(); + DECLARE_NODE_TYPE(UnaryOperation) - // Type testing & conversion - virtual UnaryOperation* AsUnaryOperation() { return this; } + virtual bool ResultOverwriteAllowed(); Token::Value op() const { return op_; } Expression* expression() const { return expression_; } @@ -1222,11 +1183,9 @@ class BinaryOperation: public Expression { // Create the binary operation corresponding to a compound assignment. explicit BinaryOperation(Assignment* assignment); - virtual void Accept(AstVisitor* v); - virtual bool ResultOverwriteAllowed(); + DECLARE_NODE_TYPE(BinaryOperation) - // Type testing & conversion - virtual BinaryOperation* AsBinaryOperation() { return this; } + virtual bool ResultOverwriteAllowed(); Token::Value op() const { return op_; } Expression* left() const { return left_; } @@ -1248,12 +1207,12 @@ class IncrementOperation: public Expression { ASSERT(Token::IsCountOp(op)); } + DECLARE_NODE_TYPE(IncrementOperation) + Token::Value op() const { return op_; } bool is_increment() { return op_ == Token::INC; } Expression* expression() const { return expression_; } - virtual void Accept(AstVisitor* v); - private: Token::Value op_; Expression* expression_; @@ -1266,9 +1225,7 @@ class CountOperation: public Expression { CountOperation(bool is_prefix, IncrementOperation* increment, int pos) : is_prefix_(is_prefix), increment_(increment), pos_(pos) { } - virtual void Accept(AstVisitor* v); - - virtual CountOperation* AsCountOperation() { return this; } + DECLARE_NODE_TYPE(CountOperation) bool is_prefix() const { return is_prefix_; } bool is_postfix() const { return !is_prefix_; } @@ -1301,16 +1258,13 @@ class CompareOperation: public Expression { ASSERT(Token::IsCompareOp(op)); } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(CompareOperation) Token::Value op() const { return op_; } Expression* left() const { return left_; } Expression* right() const { return right_; } int position() const { return pos_; } - // Type testing & conversion - virtual CompareOperation* AsCompareOperation() { return this; } - private: Token::Value op_; Expression* left_; @@ -1324,7 +1278,7 @@ class CompareToNull: public Expression { CompareToNull(bool is_strict, Expression* expression) : is_strict_(is_strict), expression_(expression) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(CompareToNull) bool is_strict() const { return is_strict_; } Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; } @@ -1349,7 +1303,7 @@ class Conditional: public Expression { then_expression_position_(then_expression_position), else_expression_position_(else_expression_position) { } - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(Conditional) Expression* condition() const { return condition_; } Expression* then_expression() const { return then_expression_; } @@ -1375,8 +1329,7 @@ class Assignment: public Expression { ASSERT(Token::IsAssignmentOp(op)); } - virtual void Accept(AstVisitor* v); - virtual Assignment* AsAssignment() { return this; } + DECLARE_NODE_TYPE(Assignment) Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } @@ -1413,7 +1366,7 @@ class Throw: public Expression { Throw(Expression* exception, int pos) : exception_(exception), pos_(pos) {} - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(Throw) Expression* exception() const { return exception_; } int position() const { return pos_; } @@ -1459,14 +1412,11 @@ class FunctionLiteral: public Expression { #endif } - virtual void Accept(AstVisitor* v); - - // Type testing & conversion - virtual FunctionLiteral* AsFunctionLiteral() { return this; } + DECLARE_NODE_TYPE(FunctionLiteral) - Handle<String> name() const { return name_; } - Scope* scope() const { return scope_; } - ZoneList<Statement*>* body() const { return body_; } + Handle<String> name() const { return name_; } + Scope* scope() const { return scope_; } + ZoneList<Statement*>* body() const { return body_; } void set_function_token_position(int pos) { function_token_position_ = pos; } int function_token_position() const { return function_token_position_; } int start_position() const { return start_position_; } @@ -1486,7 +1436,7 @@ class FunctionLiteral: public Expression { bool AllowsLazyCompilation(); - Handle<String> inferred_name() const { return inferred_name_; } + Handle<String> inferred_name() const { return inferred_name_; } void set_inferred_name(Handle<String> inferred_name) { inferred_name_ = inferred_name; } @@ -1529,12 +1479,12 @@ class SharedFunctionInfoLiteral: public Expression { Handle<SharedFunctionInfo> shared_function_info) : shared_function_info_(shared_function_info) { } + DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) + Handle<SharedFunctionInfo> shared_function_info() const { return shared_function_info_; } - virtual void Accept(AstVisitor* v); - private: Handle<SharedFunctionInfo> shared_function_info_; }; @@ -1542,7 +1492,7 @@ class SharedFunctionInfoLiteral: public Expression { class ThisFunction: public Expression { public: - virtual void Accept(AstVisitor* v); + DECLARE_NODE_TYPE(ThisFunction) }; |