| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // Nodes are allocated in a separate zone, which allows faster | 47 // Nodes are allocated in a separate zone, which allows faster |
| 48 // allocation and constant-time deallocation of the entire syntax | 48 // allocation and constant-time deallocation of the entire syntax |
| 49 // tree. | 49 // tree. |
| 50 | 50 |
| 51 | 51 |
| 52 // ---------------------------------------------------------------------------- | 52 // ---------------------------------------------------------------------------- |
| 53 // Nodes of the abstract syntax tree. Only concrete classes are | 53 // Nodes of the abstract syntax tree. Only concrete classes are |
| 54 // enumerated here. | 54 // enumerated here. |
| 55 | 55 |
| 56 #define NODE_LIST(V) \ | 56 #define STATEMENT_NODE_LIST(V) \ |
| 57 V(Block) \ | 57 V(Block) \ |
| 58 V(Declaration) \ | |
| 59 V(ExpressionStatement) \ | 58 V(ExpressionStatement) \ |
| 60 V(EmptyStatement) \ | 59 V(EmptyStatement) \ |
| 61 V(IfStatement) \ | 60 V(IfStatement) \ |
| 62 V(ContinueStatement) \ | 61 V(ContinueStatement) \ |
| 63 V(BreakStatement) \ | 62 V(BreakStatement) \ |
| 64 V(ReturnStatement) \ | 63 V(ReturnStatement) \ |
| 65 V(WithEnterStatement) \ | 64 V(WithEnterStatement) \ |
| 66 V(WithExitStatement) \ | 65 V(WithExitStatement) \ |
| 67 V(SwitchStatement) \ | 66 V(SwitchStatement) \ |
| 68 V(LoopStatement) \ | 67 V(LoopStatement) \ |
| 69 V(ForInStatement) \ | 68 V(ForInStatement) \ |
| 70 V(TryCatch) \ | 69 V(TryCatch) \ |
| 71 V(TryFinally) \ | 70 V(TryFinally) \ |
| 72 V(DebuggerStatement) \ | 71 V(DebuggerStatement) |
| 72 |
| 73 #define EXPRESSION_NODE_LIST(V) \ |
| 73 V(FunctionLiteral) \ | 74 V(FunctionLiteral) \ |
| 74 V(FunctionBoilerplateLiteral) \ | 75 V(FunctionBoilerplateLiteral) \ |
| 75 V(Conditional) \ | 76 V(Conditional) \ |
| 76 V(Slot) \ | 77 V(Slot) \ |
| 77 V(VariableProxy) \ | 78 V(VariableProxy) \ |
| 78 V(Literal) \ | 79 V(Literal) \ |
| 79 V(RegExpLiteral) \ | 80 V(RegExpLiteral) \ |
| 80 V(ObjectLiteral) \ | 81 V(ObjectLiteral) \ |
| 81 V(ArrayLiteral) \ | 82 V(ArrayLiteral) \ |
| 82 V(CatchExtensionObject) \ | 83 V(CatchExtensionObject) \ |
| 83 V(Assignment) \ | 84 V(Assignment) \ |
| 84 V(Throw) \ | 85 V(Throw) \ |
| 85 V(Property) \ | 86 V(Property) \ |
| 86 V(Call) \ | 87 V(Call) \ |
| 87 V(CallEval) \ | 88 V(CallEval) \ |
| 88 V(CallNew) \ | 89 V(CallNew) \ |
| 89 V(CallRuntime) \ | 90 V(CallRuntime) \ |
| 90 V(UnaryOperation) \ | 91 V(UnaryOperation) \ |
| 91 V(CountOperation) \ | 92 V(CountOperation) \ |
| 92 V(BinaryOperation) \ | 93 V(BinaryOperation) \ |
| 93 V(CompareOperation) \ | 94 V(CompareOperation) \ |
| 94 V(ThisFunction) | 95 V(ThisFunction) |
| 95 | 96 |
| 97 #define AST_NODE_LIST(V) \ |
| 98 V(Declaration) \ |
| 99 STATEMENT_NODE_LIST(V) \ |
| 100 EXPRESSION_NODE_LIST(V) |
| 96 | 101 |
| 97 // Forward declarations | 102 // Forward declarations |
| 98 class TargetCollector; | 103 class TargetCollector; |
| 99 class MaterializedLiteral; | 104 class MaterializedLiteral; |
| 100 | 105 |
| 101 #define DEF_FORWARD_DECLARATION(type) class type; | 106 #define DEF_FORWARD_DECLARATION(type) class type; |
| 102 NODE_LIST(DEF_FORWARD_DECLARATION) | 107 NODE_LIST(DEF_FORWARD_DECLARATION) |
| 103 #undef DEF_FORWARD_DECLARATION | 108 #undef DEF_FORWARD_DECLARATION |
| 104 | 109 |
| 105 | 110 |
| 106 // Typedef only introduced to avoid unreadable code. | 111 // Typedef only introduced to avoid unreadable code. |
| 107 // Please do appreciate the required space in "> >". | 112 // Please do appreciate the required space in "> >". |
| 108 typedef ZoneList<Handle<String> > ZoneStringList; | 113 typedef ZoneList<Handle<String> > ZoneStringList; |
| 109 | 114 |
| 110 | 115 |
| 111 class Node: public ZoneObject { | 116 class AstNode: public ZoneObject { |
| 112 public: | 117 public: |
| 113 Node(): statement_pos_(RelocInfo::kNoPosition) { } | 118 AstNode(): statement_pos_(RelocInfo::kNoPosition) { } |
| 114 virtual ~Node() { } | 119 virtual ~AstNode() { } |
| 115 virtual void Accept(AstVisitor* v) = 0; | 120 virtual void Accept(AstVisitor* v) = 0; |
| 116 | 121 |
| 117 // Type testing & conversion. | 122 // Type testing & conversion. |
| 118 virtual Statement* AsStatement() { return NULL; } | 123 virtual Statement* AsStatement() { return NULL; } |
| 119 virtual ExpressionStatement* AsExpressionStatement() { return NULL; } | 124 virtual ExpressionStatement* AsExpressionStatement() { return NULL; } |
| 120 virtual EmptyStatement* AsEmptyStatement() { return NULL; } | 125 virtual EmptyStatement* AsEmptyStatement() { return NULL; } |
| 121 virtual Expression* AsExpression() { return NULL; } | 126 virtual Expression* AsExpression() { return NULL; } |
| 122 virtual Literal* AsLiteral() { return NULL; } | 127 virtual Literal* AsLiteral() { return NULL; } |
| 123 virtual Slot* AsSlot() { return NULL; } | 128 virtual Slot* AsSlot() { return NULL; } |
| 124 virtual VariableProxy* AsVariableProxy() { return NULL; } | 129 virtual VariableProxy* AsVariableProxy() { return NULL; } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } | 141 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } |
| 137 | 142 |
| 138 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } | 143 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } |
| 139 int statement_pos() const { return statement_pos_; } | 144 int statement_pos() const { return statement_pos_; } |
| 140 | 145 |
| 141 private: | 146 private: |
| 142 int statement_pos_; | 147 int statement_pos_; |
| 143 }; | 148 }; |
| 144 | 149 |
| 145 | 150 |
| 146 class Statement: public Node { | 151 class Statement: public AstNode { |
| 147 public: | 152 public: |
| 148 virtual Statement* AsStatement() { return this; } | 153 virtual Statement* AsStatement() { return this; } |
| 149 virtual ReturnStatement* AsReturnStatement() { return NULL; } | 154 virtual ReturnStatement* AsReturnStatement() { return NULL; } |
| 150 | 155 |
| 151 bool IsEmpty() { return AsEmptyStatement() != NULL; } | 156 bool IsEmpty() { return AsEmptyStatement() != NULL; } |
| 152 }; | 157 }; |
| 153 | 158 |
| 154 | 159 |
| 155 class Expression: public Node { | 160 class Expression: public AstNode { |
| 156 public: | 161 public: |
| 157 virtual Expression* AsExpression() { return this; } | 162 virtual Expression* AsExpression() { return this; } |
| 158 | 163 |
| 159 virtual bool IsValidJSON() { return false; } | 164 virtual bool IsValidJSON() { return false; } |
| 160 virtual bool IsValidLeftHandSide() { return false; } | 165 virtual bool IsValidLeftHandSide() { return false; } |
| 161 | 166 |
| 162 // Mark the expression as being compiled as an expression | 167 // Mark the expression as being compiled as an expression |
| 163 // statement. This is used to transform postfix increments to | 168 // statement. This is used to transform postfix increments to |
| 164 // (faster) prefix increments. | 169 // (faster) prefix increments. |
| 165 virtual void MarkAsStatement() { /* do nothing */ } | 170 virtual void MarkAsStatement() { /* do nothing */ } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 238 |
| 234 ZoneList<Statement*>* statements() { return &statements_; } | 239 ZoneList<Statement*>* statements() { return &statements_; } |
| 235 bool is_initializer_block() const { return is_initializer_block_; } | 240 bool is_initializer_block() const { return is_initializer_block_; } |
| 236 | 241 |
| 237 private: | 242 private: |
| 238 ZoneList<Statement*> statements_; | 243 ZoneList<Statement*> statements_; |
| 239 bool is_initializer_block_; | 244 bool is_initializer_block_; |
| 240 }; | 245 }; |
| 241 | 246 |
| 242 | 247 |
| 243 class Declaration: public Node { | 248 class Declaration: public AstNode { |
| 244 public: | 249 public: |
| 245 Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun) | 250 Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun) |
| 246 : proxy_(proxy), | 251 : proxy_(proxy), |
| 247 mode_(mode), | 252 mode_(mode), |
| 248 fun_(fun) { | 253 fun_(fun) { |
| 249 ASSERT(mode == Variable::VAR || mode == Variable::CONST); | 254 ASSERT(mode == Variable::VAR || mode == Variable::CONST); |
| 250 // At the moment there are no "const functions"'s in JavaScript... | 255 // At the moment there are no "const functions"'s in JavaScript... |
| 251 ASSERT(fun == NULL || mode == Variable::VAR); | 256 ASSERT(fun == NULL || mode == Variable::VAR); |
| 252 } | 257 } |
| 253 | 258 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 521 |
| 517 private: | 522 private: |
| 518 Expression* condition_; | 523 Expression* condition_; |
| 519 Statement* then_statement_; | 524 Statement* then_statement_; |
| 520 Statement* else_statement_; | 525 Statement* else_statement_; |
| 521 }; | 526 }; |
| 522 | 527 |
| 523 | 528 |
| 524 // NOTE: TargetCollectors are represented as nodes to fit in the target | 529 // NOTE: TargetCollectors are represented as nodes to fit in the target |
| 525 // stack in the compiler; this should probably be reworked. | 530 // stack in the compiler; this should probably be reworked. |
| 526 class TargetCollector: public Node { | 531 class TargetCollector: public AstNode { |
| 527 public: | 532 public: |
| 528 explicit TargetCollector(ZoneList<BreakTarget*>* targets) | 533 explicit TargetCollector(ZoneList<BreakTarget*>* targets) |
| 529 : targets_(targets) { | 534 : targets_(targets) { |
| 530 } | 535 } |
| 531 | 536 |
| 532 // Adds a jump target to the collector. The collector stores a pointer not | 537 // Adds a jump target to the collector. The collector stores a pointer not |
| 533 // a copy of the target to make binding work, so make sure not to pass in | 538 // a copy of the target to make binding work, so make sure not to pass in |
| 534 // references to something on the stack. | 539 // references to something on the stack. |
| 535 void AddTarget(BreakTarget* target); | 540 void AddTarget(BreakTarget* target); |
| 536 | 541 |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 // ---------------------------------------------------------------------------- | 1676 // ---------------------------------------------------------------------------- |
| 1672 // Basic visitor | 1677 // Basic visitor |
| 1673 // - leaf node visitors are abstract. | 1678 // - leaf node visitors are abstract. |
| 1674 | 1679 |
| 1675 class AstVisitor BASE_EMBEDDED { | 1680 class AstVisitor BASE_EMBEDDED { |
| 1676 public: | 1681 public: |
| 1677 AstVisitor() : stack_overflow_(false) { } | 1682 AstVisitor() : stack_overflow_(false) { } |
| 1678 virtual ~AstVisitor() { } | 1683 virtual ~AstVisitor() { } |
| 1679 | 1684 |
| 1680 // Dispatch | 1685 // Dispatch |
| 1681 void Visit(Node* node) { node->Accept(this); } | 1686 void Visit(AstNode* node) { node->Accept(this); } |
| 1682 | 1687 |
| 1683 // Iteration | 1688 // Iteration |
| 1684 virtual void VisitStatements(ZoneList<Statement*>* statements); | 1689 virtual void VisitStatements(ZoneList<Statement*>* statements); |
| 1685 virtual void VisitExpressions(ZoneList<Expression*>* expressions); | 1690 virtual void VisitExpressions(ZoneList<Expression*>* expressions); |
| 1686 | 1691 |
| 1687 // Stack overflow tracking support. | 1692 // Stack overflow tracking support. |
| 1688 bool HasStackOverflow() const { return stack_overflow_; } | 1693 bool HasStackOverflow() const { return stack_overflow_; } |
| 1689 bool CheckStackOverflow() { | 1694 bool CheckStackOverflow() { |
| 1690 if (stack_overflow_) return true; | 1695 if (stack_overflow_) return true; |
| 1691 StackLimitCheck check; | 1696 StackLimitCheck check; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1706 #undef DEF_VISIT | 1711 #undef DEF_VISIT |
| 1707 | 1712 |
| 1708 private: | 1713 private: |
| 1709 bool stack_overflow_; | 1714 bool stack_overflow_; |
| 1710 }; | 1715 }; |
| 1711 | 1716 |
| 1712 | 1717 |
| 1713 } } // namespace v8::internal | 1718 } } // namespace v8::internal |
| 1714 | 1719 |
| 1715 #endif // V8_AST_H_ | 1720 #endif // V8_AST_H_ |
| OLD | NEW |