Chromium Code Reviews| Index: src/ast.h |
| diff --git a/src/ast.h b/src/ast.h |
| index 34fadab62d8ec52949ab352a97051ad7ad6ae4f1..c442b2f6e239d010d7482acf64efce943c8ae0ec 100644 |
| --- a/src/ast.h |
| +++ b/src/ast.h |
| @@ -39,6 +39,7 @@ |
| #include "small-pointer-list.h" |
| #include "smart-array-pointer.h" |
| #include "token.h" |
| +#include "utils.h" |
| #include "variables.h" |
| #include "zone-inl.h" |
| @@ -103,6 +104,9 @@ namespace internal { |
| EXPRESSION_NODE_LIST(V) |
| // Forward declarations |
| +class AstConstructionVisitor; |
| +class AstNodeFactory; |
| +class AstProperties; |
| class AstVisitor; |
| class BreakableStatement; |
| class Expression; |
| @@ -136,6 +140,11 @@ 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; } \ |
| + |
| + |
| class AstNode: public ZoneObject { |
| public: |
| #define DECLARE_TYPE_ENUM(type) k##type, |
| @@ -152,14 +161,11 @@ class AstNode: public ZoneObject { |
| // that emit code (function declarations). |
| static const int kDeclarationsId = 3; |
| - // Override ZoneObject's new to count allocated AST nodes. |
| void* operator new(size_t size, Zone* zone) { |
| - Isolate* isolate = zone->isolate(); |
| - isolate->set_ast_node_count(isolate->ast_node_count() + 1); |
| return zone->New(static_cast<int>(size)); |
| } |
| - AstNode() {} |
| + AstNode() { } |
| virtual ~AstNode() { } |
| @@ -180,10 +186,6 @@ class AstNode: public ZoneObject { |
| virtual IterationStatement* AsIterationStatement() { return NULL; } |
| virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| - // True if the node is simple enough for us to inline calls containing it. |
| - virtual bool IsInlineable() const = 0; |
| - |
| - static int Count() { return Isolate::Current()->ast_node_count(); } |
| static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } |
| protected: |
| @@ -376,21 +378,8 @@ class BreakableStatement: public Statement { |
| class Block: public BreakableStatement { |
| public: |
| - Block(Isolate* isolate, |
| - ZoneStringList* labels, |
| - int capacity, |
| - bool is_initializer_block) |
| - : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY), |
| - statements_(capacity), |
| - is_initializer_block_(is_initializer_block), |
| - block_scope_(NULL) { |
| - } |
| - |
| - |
| DECLARE_NODE_TYPE(Block) |
| - virtual bool IsInlineable() const; |
| - |
| void AddStatement(Statement* statement) { statements_.Add(statement); } |
| ZoneList<Statement*>* statements() { return &statements_; } |
| @@ -399,6 +388,19 @@ class Block: public BreakableStatement { |
| Scope* block_scope() const { return block_scope_; } |
| void set_block_scope(Scope* block_scope) { block_scope_ = block_scope; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + Block(Isolate* isolate, |
| + ZoneStringList* labels, |
| + int capacity, |
| + bool is_initializer_block) |
| + : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY), |
| + statements_(capacity), |
| + is_initializer_block_(is_initializer_block), |
| + block_scope_(NULL) { |
| + } |
| + |
| private: |
| ZoneList<Statement*> statements_; |
| bool is_initializer_block_; |
| @@ -408,6 +410,17 @@ class Block: public BreakableStatement { |
| class Declaration: public AstNode { |
| public: |
| + DECLARE_NODE_TYPE(Declaration) |
| + |
| + VariableProxy* proxy() const { return proxy_; } |
| + VariableMode mode() const { return mode_; } |
| + FunctionLiteral* fun() const { return fun_; } // may be NULL |
| + bool IsInlineable() const; |
| + Scope* scope() const { return scope_; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| Declaration(VariableProxy* proxy, |
| VariableMode mode, |
| FunctionLiteral* fun, |
| @@ -424,14 +437,6 @@ class Declaration: public AstNode { |
| ASSERT(fun == NULL || mode == VAR || mode == LET); |
| } |
| - DECLARE_NODE_TYPE(Declaration) |
| - |
| - VariableProxy* proxy() const { return proxy_; } |
| - VariableMode mode() const { return mode_; } |
| - FunctionLiteral* fun() const { return fun_; } // may be NULL |
| - virtual bool IsInlineable() const; |
| - Scope* scope() const { return scope_; } |
| - |
| private: |
| VariableProxy* proxy_; |
| VariableMode mode_; |
| @@ -477,14 +482,6 @@ class IterationStatement: public BreakableStatement { |
| class DoWhileStatement: public IterationStatement { |
| public: |
| - DoWhileStatement(Isolate* isolate, ZoneStringList* labels) |
| - : IterationStatement(isolate, labels), |
| - cond_(NULL), |
| - condition_position_(-1), |
| - continue_id_(GetNextId(isolate)), |
| - back_edge_id_(GetNextId(isolate)) { |
| - } |
| - |
| DECLARE_NODE_TYPE(DoWhileStatement) |
| void Initialize(Expression* cond, Statement* body) { |
| @@ -504,7 +501,16 @@ class DoWhileStatement: public IterationStatement { |
| virtual int StackCheckId() const { return back_edge_id_; } |
| int BackEdgeId() const { return back_edge_id_; } |
| - virtual bool IsInlineable() const; |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + DoWhileStatement(Isolate* isolate, ZoneStringList* labels) |
| + : IterationStatement(isolate, labels), |
| + cond_(NULL), |
| + condition_position_(-1), |
| + continue_id_(GetNextId(isolate)), |
| + back_edge_id_(GetNextId(isolate)) { |
| + } |
| private: |
| Expression* cond_; |
| @@ -516,13 +522,6 @@ class DoWhileStatement: public IterationStatement { |
| class WhileStatement: public IterationStatement { |
| public: |
| - WhileStatement(Isolate* isolate, ZoneStringList* labels) |
| - : IterationStatement(isolate, labels), |
| - cond_(NULL), |
| - may_have_function_literal_(true), |
| - body_id_(GetNextId(isolate)) { |
| - } |
| - |
| DECLARE_NODE_TYPE(WhileStatement) |
| void Initialize(Expression* cond, Statement* body) { |
| @@ -537,13 +536,22 @@ class WhileStatement: public IterationStatement { |
| void set_may_have_function_literal(bool value) { |
| may_have_function_literal_ = value; |
| } |
| - virtual bool IsInlineable() const; |
| // Bailout support. |
| virtual int ContinueId() const { return EntryId(); } |
| virtual int StackCheckId() const { return body_id_; } |
| int BodyId() const { return body_id_; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + WhileStatement(Isolate* isolate, ZoneStringList* labels) |
| + : IterationStatement(isolate, labels), |
| + cond_(NULL), |
| + may_have_function_literal_(true), |
| + body_id_(GetNextId(isolate)) { |
| + } |
| + |
| private: |
| Expression* cond_; |
| // True if there is a function literal subexpression in the condition. |
| @@ -554,17 +562,6 @@ class WhileStatement: public IterationStatement { |
| class ForStatement: public IterationStatement { |
| public: |
| - ForStatement(Isolate* isolate, ZoneStringList* labels) |
| - : IterationStatement(isolate, labels), |
| - init_(NULL), |
| - cond_(NULL), |
| - next_(NULL), |
| - may_have_function_literal_(true), |
| - loop_variable_(NULL), |
| - continue_id_(GetNextId(isolate)), |
| - body_id_(GetNextId(isolate)) { |
| - } |
| - |
| DECLARE_NODE_TYPE(ForStatement) |
| void Initialize(Statement* init, |
| @@ -596,7 +593,20 @@ class ForStatement: public IterationStatement { |
| bool is_fast_smi_loop() { return loop_variable_ != NULL; } |
| Variable* loop_variable() { return loop_variable_; } |
| void set_loop_variable(Variable* var) { loop_variable_ = var; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + ForStatement(Isolate* isolate, ZoneStringList* labels) |
| + : IterationStatement(isolate, labels), |
| + init_(NULL), |
| + cond_(NULL), |
| + next_(NULL), |
| + may_have_function_literal_(true), |
| + loop_variable_(NULL), |
| + continue_id_(GetNextId(isolate)), |
| + body_id_(GetNextId(isolate)) { |
| + } |
| private: |
| Statement* init_; |
| @@ -612,13 +622,6 @@ class ForStatement: public IterationStatement { |
| class ForInStatement: public IterationStatement { |
| public: |
| - ForInStatement(Isolate* isolate, ZoneStringList* labels) |
| - : IterationStatement(isolate, labels), |
| - each_(NULL), |
| - enumerable_(NULL), |
| - assignment_id_(GetNextId(isolate)) { |
| - } |
| - |
| DECLARE_NODE_TYPE(ForInStatement) |
| void Initialize(Expression* each, Expression* enumerable, Statement* body) { |
| @@ -629,13 +632,22 @@ class ForInStatement: public IterationStatement { |
| Expression* each() const { return each_; } |
| Expression* enumerable() const { return enumerable_; } |
| - virtual bool IsInlineable() const; |
| // Bailout support. |
| int AssignmentId() const { return assignment_id_; } |
| virtual int ContinueId() const { return EntryId(); } |
| virtual int StackCheckId() const { return EntryId(); } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + ForInStatement(Isolate* isolate, ZoneStringList* labels) |
| + : IterationStatement(isolate, labels), |
| + each_(NULL), |
| + enumerable_(NULL), |
| + assignment_id_(GetNextId(isolate)) { |
| + } |
| + |
| private: |
| Expression* each_; |
| Expression* enumerable_; |
| @@ -645,16 +657,17 @@ class ForInStatement: public IterationStatement { |
| class ExpressionStatement: public Statement { |
| public: |
| - explicit ExpressionStatement(Expression* expression) |
| - : expression_(expression) { } |
| - |
| DECLARE_NODE_TYPE(ExpressionStatement) |
| - virtual bool IsInlineable() const; |
| - |
| void set_expression(Expression* e) { expression_ = e; } |
| Expression* expression() const { return expression_; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + explicit ExpressionStatement(Expression* expression) |
| + : expression_(expression) { } |
| + |
| private: |
| Expression* expression_; |
| }; |
| @@ -662,13 +675,15 @@ class ExpressionStatement: public Statement { |
| class ContinueStatement: public Statement { |
| public: |
| - explicit ContinueStatement(IterationStatement* target) |
| - : target_(target) { } |
| - |
| DECLARE_NODE_TYPE(ContinueStatement) |
| IterationStatement* target() const { return target_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + explicit ContinueStatement(IterationStatement* target) |
| + : target_(target) { } |
| private: |
| IterationStatement* target_; |
| @@ -677,13 +692,15 @@ class ContinueStatement: public Statement { |
| class BreakStatement: public Statement { |
| public: |
| - explicit BreakStatement(BreakableStatement* target) |
| - : target_(target) { } |
| - |
| DECLARE_NODE_TYPE(BreakStatement) |
| BreakableStatement* target() const { return target_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + explicit BreakStatement(BreakableStatement* target) |
| + : target_(target) { } |
| private: |
| BreakableStatement* target_; |
| @@ -692,13 +709,15 @@ class BreakStatement: public Statement { |
| class ReturnStatement: public Statement { |
| public: |
| - explicit ReturnStatement(Expression* expression) |
| - : expression_(expression) { } |
| - |
| DECLARE_NODE_TYPE(ReturnStatement) |
| Expression* expression() const { return expression_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + explicit ReturnStatement(Expression* expression) |
| + : expression_(expression) { } |
| private: |
| Expression* expression_; |
| @@ -707,15 +726,17 @@ class ReturnStatement: public Statement { |
| class WithStatement: public Statement { |
| public: |
| - WithStatement(Expression* expression, Statement* statement) |
| - : expression_(expression), statement_(statement) { } |
| - |
| DECLARE_NODE_TYPE(WithStatement) |
| Expression* expression() const { return expression_; } |
| Statement* statement() const { return statement_; } |
| - virtual bool IsInlineable() const; |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + WithStatement(Expression* expression, Statement* statement) |
| + : expression_(expression), |
| + statement_(statement) { } |
| private: |
| Expression* expression_; |
| @@ -771,13 +792,6 @@ class CaseClause: public ZoneObject { |
| class SwitchStatement: public BreakableStatement { |
| public: |
| - SwitchStatement(Isolate* isolate, ZoneStringList* labels) |
| - : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), |
| - tag_(NULL), |
| - cases_(NULL) { |
| - } |
| - |
| - |
| DECLARE_NODE_TYPE(SwitchStatement) |
| void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
| @@ -787,7 +801,14 @@ class SwitchStatement: public BreakableStatement { |
| Expression* tag() const { return tag_; } |
| ZoneList<CaseClause*>* cases() const { return cases_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + SwitchStatement(Isolate* isolate, ZoneStringList* labels) |
| + : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), |
| + tag_(NULL), |
| + cases_(NULL) { } |
| private: |
| Expression* tag_; |
| @@ -802,22 +823,8 @@ class SwitchStatement: public BreakableStatement { |
| // given if-statement has a then- or an else-part containing code. |
| class IfStatement: public Statement { |
| public: |
| - IfStatement(Isolate* isolate, |
| - Expression* condition, |
| - Statement* then_statement, |
| - Statement* else_statement) |
| - : condition_(condition), |
| - then_statement_(then_statement), |
| - else_statement_(else_statement), |
| - if_id_(GetNextId(isolate)), |
| - then_id_(GetNextId(isolate)), |
| - else_id_(GetNextId(isolate)) { |
| - } |
| - |
| DECLARE_NODE_TYPE(IfStatement) |
| - virtual bool IsInlineable() const; |
| - |
| bool HasThenStatement() const { return !then_statement()->IsEmpty(); } |
| bool HasElseStatement() const { return !else_statement()->IsEmpty(); } |
| @@ -829,6 +836,21 @@ class IfStatement: public Statement { |
| int ThenId() const { return then_id_; } |
| int ElseId() const { return else_id_; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + IfStatement(Isolate* isolate, |
| + Expression* condition, |
| + Statement* then_statement, |
| + Statement* else_statement) |
| + : condition_(condition), |
| + then_statement_(then_statement), |
| + else_statement_(else_statement), |
| + if_id_(GetNextId(isolate)), |
| + then_id_(GetNextId(isolate)), |
| + else_id_(GetNextId(isolate)) { |
| + } |
| + |
| private: |
| Expression* condition_; |
| Statement* then_statement_; |
| @@ -843,7 +865,7 @@ class IfStatement: public Statement { |
| // stack in the compiler; this should probably be reworked. |
| class TargetCollector: public AstNode { |
| public: |
| - TargetCollector(): targets_(0) { } |
| + TargetCollector() : targets_(0) { } |
| // Adds a jump target to the collector. The collector stores a pointer not |
| // a copy of the target to make binding work, so make sure not to pass in |
| @@ -855,7 +877,6 @@ class TargetCollector: public AstNode { |
| virtual TargetCollector* AsTargetCollector() { return this; } |
| ZoneList<Label*>* targets() { return &targets_; } |
| - virtual bool IsInlineable() const; |
| private: |
| ZoneList<Label*> targets_; |
| @@ -864,12 +885,6 @@ class TargetCollector: public AstNode { |
| class TryStatement: public Statement { |
| public: |
| - explicit TryStatement(int index, Block* try_block) |
| - : index_(index), |
| - try_block_(try_block), |
| - escaping_targets_(NULL) { |
| - } |
| - |
| void set_escaping_targets(ZoneList<Label*>* targets) { |
| escaping_targets_ = targets; |
| } |
| @@ -877,7 +892,12 @@ class TryStatement: public Statement { |
| int index() const { return index_; } |
| Block* try_block() const { return try_block_; } |
| ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + TryStatement(int index, Block* try_block) |
| + : index_(index), |
| + try_block_(try_block), |
| + escaping_targets_(NULL) { } |
| private: |
| // Unique (per-function) index of this handler. This is not an AST ID. |
| @@ -890,6 +910,15 @@ class TryStatement: public Statement { |
| class TryCatchStatement: public TryStatement { |
| public: |
| + DECLARE_NODE_TYPE(TryCatchStatement) |
| + |
| + Scope* scope() { return scope_; } |
| + Variable* variable() { return variable_; } |
| + Block* catch_block() const { return catch_block_; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| TryCatchStatement(int index, |
| Block* try_block, |
| Scope* scope, |
| @@ -901,13 +930,6 @@ class TryCatchStatement: public TryStatement { |
| catch_block_(catch_block) { |
| } |
| - DECLARE_NODE_TYPE(TryCatchStatement) |
| - |
| - Scope* scope() { return scope_; } |
| - Variable* variable() { return variable_; } |
| - Block* catch_block() const { return catch_block_; } |
| - virtual bool IsInlineable() const; |
| - |
| private: |
| Scope* scope_; |
| Variable* variable_; |
| @@ -917,14 +939,16 @@ class TryCatchStatement: public TryStatement { |
| class TryFinallyStatement: public TryStatement { |
| public: |
| - TryFinallyStatement(int index, Block* try_block, Block* finally_block) |
| - : TryStatement(index, try_block), |
| - finally_block_(finally_block) { } |
| - |
| DECLARE_NODE_TYPE(TryFinallyStatement) |
| Block* finally_block() const { return finally_block_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + TryFinallyStatement(int index, Block* try_block, Block* finally_block) |
| + : TryStatement(index, try_block), |
| + finally_block_(finally_block) { } |
| private: |
| Block* finally_block_; |
| @@ -934,7 +958,11 @@ class TryFinallyStatement: public TryStatement { |
| class DebuggerStatement: public Statement { |
| public: |
| DECLARE_NODE_TYPE(DebuggerStatement) |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + DebuggerStatement() {} |
| }; |
| @@ -942,15 +970,15 @@ class EmptyStatement: public Statement { |
| public: |
| DECLARE_NODE_TYPE(EmptyStatement) |
| - virtual bool IsInlineable() const; |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + EmptyStatement() {} |
| }; |
| class Literal: public Expression { |
| public: |
| - Literal(Isolate* isolate, Handle<Object> handle) |
| - : Expression(isolate), handle_(handle) { } |
| - |
| DECLARE_NODE_TYPE(Literal) |
| // Check if this literal is identical to the other literal. |
| @@ -989,7 +1017,13 @@ class Literal: public Expression { |
| } |
| Handle<Object> handle() const { return handle_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + Literal(Isolate* isolate, Handle<Object> handle) |
| + : Expression(isolate), |
| + handle_(handle) { } |
| private: |
| Handle<Object> handle_; |
| @@ -999,15 +1033,6 @@ class Literal: public Expression { |
| // Base class for literals that needs space in the corresponding JSFunction. |
| class MaterializedLiteral: public Expression { |
| public: |
| - MaterializedLiteral(Isolate* isolate, |
| - int literal_index, |
| - bool is_simple, |
| - int depth) |
| - : Expression(isolate), |
| - literal_index_(literal_index), |
| - is_simple_(is_simple), |
| - depth_(depth) {} |
| - |
| virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
| int literal_index() { return literal_index_; } |
| @@ -1017,14 +1042,23 @@ class MaterializedLiteral: public Expression { |
| bool is_simple() const { return is_simple_; } |
| int depth() const { return depth_; } |
| - virtual bool IsInlineable() const; |
| - |
| - private: |
| - int literal_index_; |
| - bool is_simple_; |
| - int depth_; |
| -}; |
| - |
| + |
| + protected: |
| + MaterializedLiteral(Isolate* isolate, |
| + int literal_index, |
| + bool is_simple, |
| + int depth) |
| + : Expression(isolate), |
| + literal_index_(literal_index), |
| + is_simple_(is_simple), |
| + depth_(depth) {} |
| + |
| + private: |
| + int literal_index_; |
| + bool is_simple_; |
| + int depth_; |
| +}; |
| + |
| // An object literal has a boilerplate object that is used |
| // for minimizing the work when constructing it at runtime. |
| @@ -1044,7 +1078,7 @@ class ObjectLiteral: public MaterializedLiteral { |
| }; |
| Property(Literal* key, Expression* value); |
| - Property(bool is_getter, FunctionLiteral* value); |
| + Property(bool is_getter, FunctionLiteral* value, AstNodeFactory* factory); |
| Literal* key() { return key_; } |
| Expression* value() { return value_; } |
| @@ -1062,20 +1096,6 @@ class ObjectLiteral: public MaterializedLiteral { |
| bool emit_store_; |
| }; |
| - ObjectLiteral(Isolate* isolate, |
| - Handle<FixedArray> constant_properties, |
| - ZoneList<Property*>* properties, |
| - int literal_index, |
| - bool is_simple, |
| - bool fast_elements, |
| - int depth, |
| - bool has_function) |
| - : MaterializedLiteral(isolate, literal_index, is_simple, depth), |
| - constant_properties_(constant_properties), |
| - properties_(properties), |
| - fast_elements_(fast_elements), |
| - has_function_(has_function) {} |
| - |
| DECLARE_NODE_TYPE(ObjectLiteral) |
| Handle<FixedArray> constant_properties() const { |
| @@ -1098,6 +1118,23 @@ class ObjectLiteral: public MaterializedLiteral { |
| kHasFunction = 1 << 1 |
| }; |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + ObjectLiteral(Isolate* isolate, |
| + Handle<FixedArray> constant_properties, |
| + ZoneList<Property*>* properties, |
| + int literal_index, |
| + bool is_simple, |
| + bool fast_elements, |
| + int depth, |
| + bool has_function) |
| + : MaterializedLiteral(isolate, literal_index, is_simple, depth), |
| + constant_properties_(constant_properties), |
| + properties_(properties), |
| + fast_elements_(fast_elements), |
| + has_function_(has_function) {} |
| + |
| private: |
| Handle<FixedArray> constant_properties_; |
| ZoneList<Property*>* properties_; |
| @@ -1109,6 +1146,14 @@ class ObjectLiteral: public MaterializedLiteral { |
| // Node for capturing a regexp literal. |
| class RegExpLiteral: public MaterializedLiteral { |
| public: |
| + DECLARE_NODE_TYPE(RegExpLiteral) |
| + |
| + Handle<String> pattern() const { return pattern_; } |
| + Handle<String> flags() const { return flags_; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| RegExpLiteral(Isolate* isolate, |
| Handle<String> pattern, |
| Handle<String> flags, |
| @@ -1117,11 +1162,6 @@ class RegExpLiteral: public MaterializedLiteral { |
| pattern_(pattern), |
| flags_(flags) {} |
| - DECLARE_NODE_TYPE(RegExpLiteral) |
| - |
| - Handle<String> pattern() const { return pattern_; } |
| - Handle<String> flags() const { return flags_; } |
| - |
| private: |
| Handle<String> pattern_; |
| Handle<String> flags_; |
| @@ -1131,6 +1171,17 @@ class RegExpLiteral: public MaterializedLiteral { |
| // for minimizing the work when constructing it at runtime. |
| class ArrayLiteral: public MaterializedLiteral { |
| public: |
| + DECLARE_NODE_TYPE(ArrayLiteral) |
| + |
| + Handle<FixedArray> constant_elements() const { return constant_elements_; } |
| + ZoneList<Expression*>* values() const { return values_; } |
| + |
| + // Return an AST id for an element that is used in simulate instructions. |
| + int GetIdForElement(int i) { return first_element_id_ + i; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| ArrayLiteral(Isolate* isolate, |
| Handle<FixedArray> constant_elements, |
| ZoneList<Expression*>* values, |
| @@ -1142,14 +1193,6 @@ class ArrayLiteral: public MaterializedLiteral { |
| values_(values), |
| first_element_id_(ReserveIdRange(isolate, values->length())) {} |
| - DECLARE_NODE_TYPE(ArrayLiteral) |
| - |
| - Handle<FixedArray> constant_elements() const { return constant_elements_; } |
| - ZoneList<Expression*>* values() const { return values_; } |
| - |
| - // Return an AST id for an element that is used in simulate instructions. |
| - int GetIdForElement(int i) { return first_element_id_ + i; } |
| - |
| private: |
| Handle<FixedArray> constant_elements_; |
| ZoneList<Expression*>* values_; |
| @@ -1159,21 +1202,12 @@ class ArrayLiteral: public MaterializedLiteral { |
| class VariableProxy: public Expression { |
| public: |
| - VariableProxy(Isolate* isolate, Variable* var); |
| - |
| - VariableProxy(Isolate* isolate, |
| - Handle<String> name, |
| - bool is_this, |
| - int position = RelocInfo::kNoPosition); |
| - |
| DECLARE_NODE_TYPE(VariableProxy) |
| virtual bool IsValidLeftHandSide() { |
| return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
| } |
| - virtual bool IsInlineable() const; |
| - |
| bool IsVariable(Handle<String> n) { |
| return !is_this() && name().is_identical_to(n); |
| } |
| @@ -1195,7 +1229,20 @@ class VariableProxy: public Expression { |
| // Bind this proxy to the variable var. |
| void BindTo(Variable* var); |
| + void set_ast_properties(AstProperties* properties) { |
| + ast_properties_ = properties; |
| + } |
| + |
| protected: |
| + friend class AstNodeFactory; |
| + |
| + VariableProxy(Isolate* isolate, Variable* var); |
| + |
| + VariableProxy(Isolate* isolate, |
| + Handle<String> name, |
| + bool is_this, |
| + int position); |
| + |
| Handle<String> name_; |
| Variable* var_; // resolved variable, or NULL |
| bool is_this_; |
| @@ -1204,29 +1251,15 @@ class VariableProxy: public Expression { |
| // or with a increment/decrement operator. |
| bool is_lvalue_; |
| int position_; |
| + AstProperties* ast_properties_; |
|
fschneider
2012/01/30 13:54:26
It seems quite expensive to add a pointer to each
Jakob Kummerow
2012/02/01 14:46:09
The problem is that at the time the VariableProxy
fschneider
2012/02/02 15:54:07
It seems that we only visit the VariableProxy to f
Jakob Kummerow
2012/02/03 10:06:22
Done.
|
| }; |
| class Property: public Expression { |
| public: |
| - Property(Isolate* isolate, |
| - Expression* obj, |
| - Expression* key, |
| - int pos) |
| - : Expression(isolate), |
| - obj_(obj), |
| - key_(key), |
| - pos_(pos), |
| - is_monomorphic_(false), |
| - is_array_length_(false), |
| - is_string_length_(false), |
| - is_string_access_(false), |
| - is_function_prototype_(false) { } |
| - |
| DECLARE_NODE_TYPE(Property) |
| virtual bool IsValidLeftHandSide() { return true; } |
| - virtual bool IsInlineable() const; |
| Expression* obj() const { return obj_; } |
| Expression* key() const { return key_; } |
| @@ -1242,6 +1275,23 @@ class Property: public Expression { |
| virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } |
| bool IsArrayLength() { return is_array_length_; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + Property(Isolate* isolate, |
| + Expression* obj, |
| + Expression* key, |
| + int pos) |
| + : Expression(isolate), |
| + obj_(obj), |
| + key_(key), |
| + pos_(pos), |
| + is_monomorphic_(false), |
| + is_array_length_(false), |
| + is_string_length_(false), |
| + is_string_access_(false), |
| + is_function_prototype_(false) { } |
| + |
| private: |
| Expression* obj_; |
| Expression* key_; |
| @@ -1258,23 +1308,8 @@ class Property: public Expression { |
| class Call: public Expression { |
| public: |
| - Call(Isolate* isolate, |
| - Expression* expression, |
| - ZoneList<Expression*>* arguments, |
| - int pos) |
| - : Expression(isolate), |
| - expression_(expression), |
| - arguments_(arguments), |
| - pos_(pos), |
| - is_monomorphic_(false), |
| - check_type_(RECEIVER_MAP_CHECK), |
| - return_id_(GetNextId(isolate)) { |
| - } |
| - |
| DECLARE_NODE_TYPE(Call) |
| - virtual bool IsInlineable() const; |
| - |
| Expression* expression() const { return expression_; } |
| ZoneList<Expression*>* arguments() const { return arguments_; } |
| virtual int position() const { return pos_; } |
| @@ -1299,6 +1334,21 @@ class Call: public Expression { |
| bool return_is_recorded_; |
| #endif |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + Call(Isolate* isolate, |
| + Expression* expression, |
| + ZoneList<Expression*>* arguments, |
| + int pos) |
| + : Expression(isolate), |
| + expression_(expression), |
| + arguments_(arguments), |
| + pos_(pos), |
| + is_monomorphic_(false), |
| + check_type_(RECEIVER_MAP_CHECK), |
| + return_id_(GetNextId(isolate)) { } |
| + |
| private: |
| Expression* expression_; |
| ZoneList<Expression*>* arguments_; |
| @@ -1317,6 +1367,15 @@ class Call: public Expression { |
| class CallNew: public Expression { |
| public: |
| + DECLARE_NODE_TYPE(CallNew) |
| + |
| + Expression* expression() const { return expression_; } |
| + ZoneList<Expression*>* arguments() const { return arguments_; } |
| + virtual int position() const { return pos_; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| CallNew(Isolate* isolate, |
| Expression* expression, |
| ZoneList<Expression*>* arguments, |
| @@ -1326,14 +1385,6 @@ class CallNew: public Expression { |
| arguments_(arguments), |
| pos_(pos) { } |
| - DECLARE_NODE_TYPE(CallNew) |
| - |
| - virtual bool IsInlineable() const; |
| - |
| - Expression* expression() const { return expression_; } |
| - ZoneList<Expression*>* arguments() const { return arguments_; } |
| - virtual int position() const { return pos_; } |
| - |
| private: |
| Expression* expression_; |
| ZoneList<Expression*>* arguments_; |
| @@ -1347,6 +1398,16 @@ class CallNew: public Expression { |
| // implemented in JavaScript (see "v8natives.js"). |
| class CallRuntime: public Expression { |
| public: |
| + DECLARE_NODE_TYPE(CallRuntime) |
| + |
| + Handle<String> name() const { return name_; } |
| + const Runtime::Function* function() const { return function_; } |
| + ZoneList<Expression*>* arguments() const { return arguments_; } |
| + bool is_jsruntime() const { return function_ == NULL; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| CallRuntime(Isolate* isolate, |
| Handle<String> name, |
| const Runtime::Function* function, |
| @@ -1356,15 +1417,6 @@ class CallRuntime: public Expression { |
| function_(function), |
| arguments_(arguments) { } |
| - DECLARE_NODE_TYPE(CallRuntime) |
| - |
| - virtual bool IsInlineable() const; |
| - |
| - Handle<String> name() const { return name_; } |
| - const Runtime::Function* function() const { return function_; } |
| - ZoneList<Expression*>* arguments() const { return arguments_; } |
| - bool is_jsruntime() const { return function_ == NULL; } |
| - |
| private: |
| Handle<String> name_; |
| const Runtime::Function* function_; |
| @@ -1374,6 +1426,20 @@ class CallRuntime: public Expression { |
| class UnaryOperation: public Expression { |
| public: |
| + DECLARE_NODE_TYPE(UnaryOperation) |
| + |
| + virtual bool ResultOverwriteAllowed(); |
| + |
| + Token::Value op() const { return op_; } |
| + Expression* expression() const { return expression_; } |
| + virtual int position() const { return pos_; } |
| + |
| + int MaterializeTrueId() { return materialize_true_id_; } |
| + int MaterializeFalseId() { return materialize_false_id_; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| UnaryOperation(Isolate* isolate, |
| Token::Value op, |
| Expression* expression, |
| @@ -1391,19 +1457,6 @@ class UnaryOperation: public Expression { |
| } |
| } |
| - DECLARE_NODE_TYPE(UnaryOperation) |
| - |
| - virtual bool IsInlineable() const; |
| - |
| - virtual bool ResultOverwriteAllowed(); |
| - |
| - Token::Value op() const { return op_; } |
| - Expression* expression() const { return expression_; } |
| - virtual int position() const { return pos_; } |
| - |
| - int MaterializeTrueId() { return materialize_true_id_; } |
| - int MaterializeFalseId() { return materialize_false_id_; } |
| - |
| private: |
| Token::Value op_; |
| Expression* expression_; |
| @@ -1418,22 +1471,8 @@ class UnaryOperation: public Expression { |
| class BinaryOperation: public Expression { |
| public: |
| - BinaryOperation(Isolate* isolate, |
| - Token::Value op, |
| - Expression* left, |
| - Expression* right, |
| - int pos) |
| - : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) { |
| - ASSERT(Token::IsBinaryOp(op)); |
| - right_id_ = (op == Token::AND || op == Token::OR) |
| - ? static_cast<int>(GetNextId(isolate)) |
| - : AstNode::kNoNumber; |
| - } |
| - |
| DECLARE_NODE_TYPE(BinaryOperation) |
| - virtual bool IsInlineable() const; |
| - |
| virtual bool ResultOverwriteAllowed(); |
| Token::Value op() const { return op_; } |
| @@ -1444,6 +1483,21 @@ class BinaryOperation: public Expression { |
| // Bailout support. |
| int RightId() const { return right_id_; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + BinaryOperation(Isolate* isolate, |
| + Token::Value op, |
| + Expression* left, |
| + Expression* right, |
| + int pos) |
| + : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) { |
| + ASSERT(Token::IsBinaryOp(op)); |
| + right_id_ = (op == Token::AND || op == Token::OR) |
| + ? static_cast<int>(GetNextId(isolate)) |
| + : AstNode::kNoNumber; |
| + } |
| + |
| private: |
| Token::Value op_; |
| Expression* left_; |
| @@ -1457,19 +1511,6 @@ class BinaryOperation: public Expression { |
| class CountOperation: public Expression { |
| public: |
| - CountOperation(Isolate* isolate, |
| - Token::Value op, |
| - bool is_prefix, |
| - Expression* expr, |
| - int pos) |
| - : Expression(isolate), |
| - op_(op), |
| - is_prefix_(is_prefix), |
| - expression_(expr), |
| - pos_(pos), |
| - assignment_id_(GetNextId(isolate)), |
| - count_id_(GetNextId(isolate)) {} |
| - |
| DECLARE_NODE_TYPE(CountOperation) |
| bool is_prefix() const { return is_prefix_; } |
| @@ -1485,8 +1526,6 @@ class CountOperation: public Expression { |
| virtual void MarkAsStatement() { is_prefix_ = true; } |
| - virtual bool IsInlineable() const; |
| - |
| void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| virtual bool IsMonomorphic() { return is_monomorphic_; } |
| virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } |
| @@ -1495,6 +1534,22 @@ class CountOperation: public Expression { |
| int AssignmentId() const { return assignment_id_; } |
| int CountId() const { return count_id_; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + CountOperation(Isolate* isolate, |
| + Token::Value op, |
| + bool is_prefix, |
| + Expression* expr, |
| + int pos) |
| + : Expression(isolate), |
| + op_(op), |
| + is_prefix_(is_prefix), |
| + expression_(expr), |
| + pos_(pos), |
| + assignment_id_(GetNextId(isolate)), |
| + count_id_(GetNextId(isolate)) {} |
| + |
| private: |
| Token::Value op_; |
| bool is_prefix_; |
| @@ -1509,20 +1564,6 @@ class CountOperation: public Expression { |
| class CompareOperation: public Expression { |
| public: |
| - CompareOperation(Isolate* isolate, |
| - Token::Value op, |
| - Expression* left, |
| - Expression* right, |
| - int pos) |
| - : Expression(isolate), |
| - op_(op), |
| - left_(left), |
| - right_(right), |
| - pos_(pos), |
| - compare_type_(NONE) { |
| - ASSERT(Token::IsCompareOp(op)); |
| - } |
| - |
| DECLARE_NODE_TYPE(CompareOperation) |
| Token::Value op() const { return op_; } |
| @@ -1530,8 +1571,6 @@ class CompareOperation: public Expression { |
| Expression* right() const { return right_; } |
| virtual int position() const { return pos_; } |
| - virtual bool IsInlineable() const; |
| - |
| // Type feedback information. |
| void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| bool IsSmiCompare() { return compare_type_ == SMI_ONLY; } |
| @@ -1542,6 +1581,23 @@ class CompareOperation: public Expression { |
| bool IsLiteralCompareUndefined(Expression** expr); |
| bool IsLiteralCompareNull(Expression** expr); |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + CompareOperation(Isolate* isolate, |
| + Token::Value op, |
| + Expression* left, |
| + Expression* right, |
| + int pos) |
| + : Expression(isolate), |
| + op_(op), |
| + left_(left), |
| + right_(right), |
| + pos_(pos), |
| + compare_type_(NONE) { |
| + ASSERT(Token::IsCompareOp(op)); |
| + } |
| + |
| private: |
| Token::Value op_; |
| Expression* left_; |
| @@ -1555,6 +1611,21 @@ class CompareOperation: public Expression { |
| class Conditional: public Expression { |
| public: |
| + DECLARE_NODE_TYPE(Conditional) |
| + |
| + Expression* condition() const { return condition_; } |
| + Expression* then_expression() const { return then_expression_; } |
| + Expression* else_expression() const { return else_expression_; } |
| + |
| + int then_expression_position() const { return then_expression_position_; } |
| + int else_expression_position() const { return else_expression_position_; } |
| + |
| + int ThenId() const { return then_id_; } |
| + int ElseId() const { return else_id_; } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| Conditional(Isolate* isolate, |
| Expression* condition, |
| Expression* then_expression, |
| @@ -1568,22 +1639,7 @@ class Conditional: public Expression { |
| then_expression_position_(then_expression_position), |
| else_expression_position_(else_expression_position), |
| then_id_(GetNextId(isolate)), |
| - else_id_(GetNextId(isolate)) { |
| - } |
| - |
| - DECLARE_NODE_TYPE(Conditional) |
| - |
| - virtual bool IsInlineable() const; |
| - |
| - Expression* condition() const { return condition_; } |
| - Expression* then_expression() const { return then_expression_; } |
| - Expression* else_expression() const { return else_expression_; } |
| - |
| - int then_expression_position() const { return then_expression_position_; } |
| - int else_expression_position() const { return else_expression_position_; } |
| - |
| - int ThenId() const { return then_id_; } |
| - int ElseId() const { return else_id_; } |
| + else_id_(GetNextId(isolate)) { } |
| private: |
| Expression* condition_; |
| @@ -1598,16 +1654,8 @@ class Conditional: public Expression { |
| class Assignment: public Expression { |
| public: |
| - Assignment(Isolate* isolate, |
| - Token::Value op, |
| - Expression* target, |
| - Expression* value, |
| - int pos); |
| - |
| DECLARE_NODE_TYPE(Assignment) |
| - virtual bool IsInlineable() const; |
| - |
| Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
| Token::Value binary_op() const; |
| @@ -1639,6 +1687,16 @@ class Assignment: public Expression { |
| int CompoundLoadId() const { return compound_load_id_; } |
| int AssignmentId() const { return assignment_id_; } |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + Assignment(Isolate* isolate, |
| + Token::Value op, |
| + Expression* target, |
| + Expression* value, |
| + int pos, |
| + AstNodeFactory* factory); |
| + |
| private: |
| Token::Value op_; |
| Expression* target_; |
| @@ -1658,14 +1716,16 @@ class Assignment: public Expression { |
| class Throw: public Expression { |
| public: |
| - Throw(Isolate* isolate, Expression* exception, int pos) |
| - : Expression(isolate), exception_(exception), pos_(pos) {} |
| - |
| DECLARE_NODE_TYPE(Throw) |
| Expression* exception() const { return exception_; } |
| virtual int position() const { return pos_; } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + Throw(Isolate* isolate, Expression* exception, int pos) |
| + : Expression(isolate), exception_(exception), pos_(pos) {} |
| private: |
| Expression* exception_; |
| @@ -1681,38 +1741,6 @@ class FunctionLiteral: public Expression { |
| DECLARATION |
| }; |
| - FunctionLiteral(Isolate* isolate, |
| - Handle<String> name, |
| - Scope* scope, |
| - ZoneList<Statement*>* body, |
| - int materialized_literal_count, |
| - int expected_property_count, |
| - int handler_count, |
| - bool has_only_simple_this_property_assignments, |
| - Handle<FixedArray> this_property_assignments, |
| - int parameter_count, |
| - Type type, |
| - bool has_duplicate_parameters) |
| - : Expression(isolate), |
| - name_(name), |
| - scope_(scope), |
| - body_(body), |
| - this_property_assignments_(this_property_assignments), |
| - inferred_name_(isolate->factory()->empty_string()), |
| - materialized_literal_count_(materialized_literal_count), |
| - expected_property_count_(expected_property_count), |
| - handler_count_(handler_count), |
| - parameter_count_(parameter_count), |
| - function_token_position_(RelocInfo::kNoPosition) { |
| - bitfield_ = |
| - HasOnlySimpleThisPropertyAssignments::encode( |
| - has_only_simple_this_property_assignments) | |
| - IsExpression::encode(type != DECLARATION) | |
| - IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | |
| - Pretenure::encode(false) | |
| - HasDuplicateParameters::encode(has_duplicate_parameters); |
| - } |
| - |
| DECLARE_NODE_TYPE(FunctionLiteral) |
| Handle<String> name() const { return name_; } |
| @@ -1752,18 +1780,61 @@ class FunctionLiteral: public Expression { |
| bool pretenure() { return Pretenure::decode(bitfield_); } |
| void set_pretenure() { bitfield_ |= Pretenure::encode(true); } |
| - virtual bool IsInlineable() const; |
| bool has_duplicate_parameters() { |
| return HasDuplicateParameters::decode(bitfield_); |
| } |
| + bool ShouldSelfOptimize(); |
| + int AstNodeCount(); |
| + AstProperties* ast_properties() { return ast_properties_; } |
| + void set_ast_properties(AstProperties* ast_properties) { |
| + ast_properties_ = ast_properties; |
| + } |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + FunctionLiteral(Isolate* isolate, |
| + Handle<String> name, |
| + Scope* scope, |
| + ZoneList<Statement*>* body, |
| + int materialized_literal_count, |
| + int expected_property_count, |
| + int handler_count, |
| + bool has_only_simple_this_property_assignments, |
| + Handle<FixedArray> this_property_assignments, |
| + int parameter_count, |
| + Type type, |
| + bool has_duplicate_parameters) |
| + : Expression(isolate), |
| + name_(name), |
| + scope_(scope), |
| + body_(body), |
| + this_property_assignments_(this_property_assignments), |
| + inferred_name_(isolate->factory()->empty_string()), |
| + ast_properties_(NULL), |
| + materialized_literal_count_(materialized_literal_count), |
| + expected_property_count_(expected_property_count), |
| + handler_count_(handler_count), |
| + parameter_count_(parameter_count), |
| + function_token_position_(RelocInfo::kNoPosition) { |
| + bitfield_ = |
| + HasOnlySimpleThisPropertyAssignments::encode( |
| + has_only_simple_this_property_assignments) | |
| + IsExpression::encode(type != DECLARATION) | |
| + IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | |
| + Pretenure::encode(false) | |
| + HasDuplicateParameters::encode(has_duplicate_parameters); |
| + } |
| + |
| private: |
| Handle<String> name_; |
| Scope* scope_; |
| ZoneList<Statement*>* body_; |
| Handle<FixedArray> this_property_assignments_; |
| Handle<String> inferred_name_; |
| + AstProperties* ast_properties_; |
| int materialized_literal_count_; |
| int expected_property_count_; |
| @@ -1782,17 +1853,20 @@ class FunctionLiteral: public Expression { |
| class SharedFunctionInfoLiteral: public Expression { |
| public: |
| - SharedFunctionInfoLiteral( |
| - Isolate* isolate, |
| - Handle<SharedFunctionInfo> shared_function_info) |
| - : Expression(isolate), shared_function_info_(shared_function_info) { } |
| - |
| DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) |
| Handle<SharedFunctionInfo> shared_function_info() const { |
| return shared_function_info_; |
| } |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + SharedFunctionInfoLiteral( |
| + Isolate* isolate, |
| + Handle<SharedFunctionInfo> shared_function_info) |
| + : Expression(isolate), |
| + shared_function_info_(shared_function_info) { } |
| private: |
| Handle<SharedFunctionInfo> shared_function_info_; |
| @@ -1801,9 +1875,12 @@ class SharedFunctionInfoLiteral: public Expression { |
| class ThisFunction: public Expression { |
| public: |
| - explicit ThisFunction(Isolate* isolate) : Expression(isolate) {} |
| DECLARE_NODE_TYPE(ThisFunction) |
| - virtual bool IsInlineable() const; |
| + |
| + protected: |
| + friend class AstNodeFactory; |
| + |
| + explicit ThisFunction(Isolate* isolate): Expression(isolate) {} |
| }; |
| @@ -2207,6 +2284,237 @@ class AstVisitor BASE_EMBEDDED { |
| }; |
| +// ---------------------------------------------------------------------------- |
| +// Construction time visitor. |
| + |
| +enum AstPropertiesFlag { |
| + kDontCrankshaft, |
| + kDontInline, |
| + kDontSelfOptimize, |
| + kDontSoftInline |
| +}; |
| + |
| + |
| +class AstProperties : public ZoneObject { |
| + public: |
| + class Flags : public EnumSet<AstPropertiesFlag, int> {}; |
| + |
| + AstProperties() : node_count_(0) {} |
| + virtual ~AstProperties(); // Implementation is out-of-line to make ld happy. |
| + |
| + Flags* flags() { return &flags_; } |
| + int node_count() { return node_count_; } |
| + void increase_node_count() { node_count_++; } |
| + |
| + void RevisitVariableProxy(VariableProxy* node); |
| + |
| + private: |
| + Flags flags_; |
| + int node_count_; |
| +}; |
| + |
| + |
| +class AstConstructionVisitor : public AstVisitor { |
| + public: |
| + AstConstructionVisitor() : properties_(NULL) {} |
| + virtual ~AstConstructionVisitor() {} |
| + |
| + AstProperties* properties() { return properties_; } |
| + void set_ast_properties(AstProperties* properties) { |
| + properties_ = properties; |
| + } |
| + |
| + private: |
| + // Node visitors. |
| +#define DEF_VISIT(type) \ |
| + virtual void Visit##type(type* node); |
| + AST_NODE_LIST(DEF_VISIT) |
| +#undef DEF_VISIT |
| + |
| + inline void increase_node_count() { |
| + properties_->increase_node_count(); |
| + } |
| + inline void add_flag(AstPropertiesFlag flag) { |
| + properties_->flags()->Add(flag); |
| + } |
| + |
| + AstProperties* properties_; |
| +}; |
| + |
| + |
| + |
| +// ---------------------------------------------------------------------------- |
| +// AstNode factory |
| + |
| +class AstNodeFactory { |
|
fschneider
2012/01/30 12:10:35
maybe make it BASE_EMBEDDED.
Jakob Kummerow
2012/02/01 14:46:09
Done.
|
| + public: |
| + AstNodeFactory(Isolate* isolate, |
| + Zone* zone = NULL, |
| + AstVisitor* visitor = NULL) |
| + : isolate_(isolate), |
| + zone_(zone), |
| + visitor_(visitor) { |
| + if (zone == NULL) { |
| + zone_ = isolate_->zone(); |
| + } |
| + } |
| + |
| + AstVisitor* visitor() { return visitor_; } |
| + void set_visitor(AstVisitor* visitor) { |
| + visitor_ = visitor; |
| + } |
| + |
| + Block* NewBlock(ZoneStringList* labels, |
| + int capacity, |
| + bool is_initializer_block); |
| + |
| + Declaration* NewDeclaration(VariableProxy* proxy, |
| + VariableMode mode, |
| + FunctionLiteral* fun, |
| + Scope* scope); |
| + |
| + DoWhileStatement* NewDoWhileStatement(ZoneStringList* labels); |
| + |
| + WhileStatement* NewWhileStatement(ZoneStringList* labels); |
| + |
| + ForStatement* NewForStatement(ZoneStringList* labels); |
| + |
| + ForInStatement* NewForInStatement(ZoneStringList* labels); |
| + |
| + ExpressionStatement* NewExpressionStatement(Expression* expression); |
| + |
| + ContinueStatement* NewContinueStatement(IterationStatement* target); |
| + |
| + BreakStatement* NewBreakStatement(BreakableStatement* target); |
| + |
| + ReturnStatement* NewReturnStatement(Expression* expression); |
| + |
| + WithStatement* NewWithStatement(Expression* expression, |
| + Statement* statement); |
| + |
| + SwitchStatement* NewSwitchStatement(ZoneStringList* labels); |
| + |
| + IfStatement* NewIfStatement(Expression* condition, |
| + Statement* then_statement, |
| + Statement* else_statement); |
| + |
| + TryCatchStatement* NewTryCatchStatement(int index, |
| + Block* try_block, |
| + Scope* scope, |
| + Variable* variable, |
| + Block* catch_block); |
| + |
| + TryFinallyStatement* NewTryFinallyStatement(int index, |
| + Block* try_block, |
| + Block* finally_block); |
| + |
| + DebuggerStatement* NewDebuggerStatement(); |
| + |
| + EmptyStatement* NewEmptyStatement(); |
| + |
| + Literal* NewLiteral(Handle<Object> handle); |
| + |
| + Literal* NewNumberLiteral(double number); |
| + |
| + ObjectLiteral* NewObjectLiteral( |
| + Handle<FixedArray> constant_properties, |
| + ZoneList<ObjectLiteral::Property*>* properties, |
| + int literal_index, |
| + bool is_simple, |
| + bool fast_elements, |
| + int depth, |
| + bool has_function); |
| + |
| + RegExpLiteral* NewRegExpLiteral(Handle<String> pattern, |
| + Handle<String> flags, |
| + int literal_index); |
| + |
| + ArrayLiteral* NewArrayLiteral(Handle<FixedArray> constant_elements, |
| + ZoneList<Expression*>* values, |
| + int literal_index, |
| + bool is_simple, |
| + int depth); |
| + |
| + VariableProxy* NewVariableProxy(Variable* var); |
| + |
| + VariableProxy* NewVariableProxy(Handle<String> name, |
| + bool is_this, |
| + int position = RelocInfo::kNoPosition); |
| + |
| + Property* NewProperty(Expression* obj, Expression* key, int pos); |
| + |
| + Call* NewCall(Expression* expression, |
| + ZoneList<Expression*>* arguments, |
| + int pos); |
| + |
| + CallNew* NewCallNew(Expression* expression, |
| + ZoneList<Expression*>* arguments, |
| + int pos); |
| + |
| + CallRuntime* NewCallRuntime(Handle<String> name, |
| + const Runtime::Function* function, |
| + ZoneList<Expression*>* arguments); |
| + |
| + UnaryOperation* NewUnaryOperation(Token::Value op, |
| + Expression* expression, |
| + int pos); |
| + |
| + BinaryOperation* NewBinaryOperation(Token::Value op, |
| + Expression* left, |
| + Expression* right, |
| + int pos); |
| + |
| + CountOperation* NewCountOperation(Token::Value op, |
| + bool is_prefix, |
| + Expression* expr, |
| + int pos); |
| + |
| + CompareOperation* NewCompareOperation(Token::Value op, |
| + Expression* left, |
| + Expression* right, |
| + int pos); |
| + |
| + Conditional* NewConditional(Expression* condition, |
| + Expression* then_expression, |
| + Expression* else_expression, |
| + int then_expression_position, |
| + int else_expression_position); |
| + |
| + Assignment* NewAssignment(Token::Value op, |
| + Expression* target, |
| + Expression* value, |
| + int pos); |
| + |
| + Throw* NewThrow(Expression* exception, int pos); |
| + |
| + FunctionLiteral* NewFunctionLiteral( |
| + Handle<String> name, |
| + Scope* scope, |
| + ZoneList<Statement*>* body, |
| + int materialized_literal_count, |
| + int expected_property_count, |
| + int handler_count, |
| + bool has_only_simple_this_property_assignments, |
| + Handle<FixedArray> this_property_assignments, |
| + int parameter_count, |
| + FunctionLiteral::Type type, |
| + bool has_duplicate_parameters, |
| + bool visit_with_visitor = true); |
| + |
| + SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( |
| + Handle<SharedFunctionInfo> shared_function_info); |
| + |
| + ThisFunction* NewThisFunction(); |
| + |
| + private: |
| + void Visit(AstNode* node); |
| + |
| + Isolate* isolate_; |
| + Zone* zone_; |
| + AstVisitor* visitor_; |
| +}; |
| + |
| + |
| } } // namespace v8::internal |
| #endif // V8_AST_H_ |