| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 #define DECLARE_TYPE_ENUM(type) k##type, | 128 #define DECLARE_TYPE_ENUM(type) k##type, |
| 129 enum Type { | 129 enum Type { |
| 130 AST_NODE_LIST(DECLARE_TYPE_ENUM) | 130 AST_NODE_LIST(DECLARE_TYPE_ENUM) |
| 131 kInvalid = -1 | 131 kInvalid = -1 |
| 132 }; | 132 }; |
| 133 #undef DECLARE_TYPE_ENUM | 133 #undef DECLARE_TYPE_ENUM |
| 134 | 134 |
| 135 static const int kNoNumber = -1; | 135 static const int kNoNumber = -1; |
| 136 static const int kFunctionEntryId = 2; // Using 0 could disguise errors. | 136 static const int kFunctionEntryId = 2; // Using 0 could disguise errors. |
| 137 | 137 |
| 138 AstNode() : id_(GetNextId()) { | 138 AstNode() { |
| 139 Isolate* isolate = Isolate::Current(); | 139 Isolate* isolate = Isolate::Current(); |
| 140 isolate->set_ast_node_count(isolate->ast_node_count() + 1); | 140 isolate->set_ast_node_count(isolate->ast_node_count() + 1); |
| 141 } | 141 } |
| 142 | 142 |
| 143 virtual ~AstNode() { } | 143 virtual ~AstNode() { } |
| 144 | 144 |
| 145 virtual void Accept(AstVisitor* v) = 0; | 145 virtual void Accept(AstVisitor* v) = 0; |
| 146 virtual Type node_type() const { return kInvalid; } | 146 virtual Type node_type() const { return kInvalid; } |
| 147 | 147 |
| 148 // Type testing & conversion functions overridden by concrete subclasses. | 148 // Type testing & conversion functions overridden by concrete subclasses. |
| 149 #define DECLARE_NODE_FUNCTIONS(type) \ | 149 #define DECLARE_NODE_FUNCTIONS(type) \ |
| 150 virtual type* As##type() { return NULL; } | 150 virtual type* As##type() { return NULL; } |
| 151 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 151 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 152 #undef DECLARE_NODE_FUNCTIONS | 152 #undef DECLARE_NODE_FUNCTIONS |
| 153 | 153 |
| 154 virtual Statement* AsStatement() { return NULL; } | 154 virtual Statement* AsStatement() { return NULL; } |
| 155 virtual Expression* AsExpression() { return NULL; } | 155 virtual Expression* AsExpression() { return NULL; } |
| 156 virtual TargetCollector* AsTargetCollector() { return NULL; } | 156 virtual TargetCollector* AsTargetCollector() { return NULL; } |
| 157 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 157 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 158 virtual IterationStatement* AsIterationStatement() { return NULL; } | 158 virtual IterationStatement* AsIterationStatement() { return NULL; } |
| 159 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 159 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| 160 virtual Slot* AsSlot() { return NULL; } | 160 virtual Slot* AsSlot() { return NULL; } |
| 161 | 161 |
| 162 // True if the node is simple enough for us to inline calls containing it. | 162 // True if the node is simple enough for us to inline calls containing it. |
| 163 virtual bool IsInlineable() const = 0; | 163 virtual bool IsInlineable() const = 0; |
| 164 | 164 |
| 165 static int Count() { return Isolate::Current()->ast_node_count(); } | 165 static int Count() { return Isolate::Current()->ast_node_count(); } |
| 166 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } | 166 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } |
| 167 unsigned id() const { return id_; } | |
| 168 | 167 |
| 169 protected: | 168 protected: |
| 170 static unsigned GetNextId() { | 169 static unsigned GetNextId() { return ReserveIdRange(1); } |
| 171 Isolate* isolate = Isolate::Current(); | |
| 172 unsigned tmp = isolate->ast_node_id(); | |
| 173 isolate->set_ast_node_id(tmp + 1); | |
| 174 return tmp; | |
| 175 } | |
| 176 static unsigned ReserveIdRange(int n) { | 170 static unsigned ReserveIdRange(int n) { |
| 177 Isolate* isolate = Isolate::Current(); | 171 Isolate* isolate = Isolate::Current(); |
| 178 unsigned tmp = isolate->ast_node_id(); | 172 unsigned tmp = isolate->ast_node_id(); |
| 179 isolate->set_ast_node_id(tmp + n); | 173 isolate->set_ast_node_id(tmp + n); |
| 180 return tmp; | 174 return tmp; |
| 181 } | 175 } |
| 182 | 176 |
| 183 private: | |
| 184 unsigned id_; | |
| 185 | |
| 186 friend class CaseClause; // Generates AST IDs. | 177 friend class CaseClause; // Generates AST IDs. |
| 187 }; | 178 }; |
| 188 | 179 |
| 189 | 180 |
| 190 class Statement: public AstNode { | 181 class Statement: public AstNode { |
| 191 public: | 182 public: |
| 192 Statement() : statement_pos_(RelocInfo::kNoPosition) {} | 183 Statement() : statement_pos_(RelocInfo::kNoPosition) {} |
| 193 | 184 |
| 194 virtual Statement* AsStatement() { return this; } | 185 virtual Statement* AsStatement() { return this; } |
| 195 | 186 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 213 // code generation. | 204 // code generation. |
| 214 kUninitialized, | 205 kUninitialized, |
| 215 // Evaluated for its side effects. | 206 // Evaluated for its side effects. |
| 216 kEffect, | 207 kEffect, |
| 217 // Evaluated for its value (and side effects). | 208 // Evaluated for its value (and side effects). |
| 218 kValue, | 209 kValue, |
| 219 // Evaluated for control flow (and side effects). | 210 // Evaluated for control flow (and side effects). |
| 220 kTest | 211 kTest |
| 221 }; | 212 }; |
| 222 | 213 |
| 223 Expression() {} | 214 Expression() : id_(GetNextId()) {} |
| 224 | 215 |
| 225 virtual int position() const { | 216 virtual int position() const { |
| 226 UNREACHABLE(); | 217 UNREACHABLE(); |
| 227 return 0; | 218 return 0; |
| 228 } | 219 } |
| 229 | 220 |
| 230 virtual Expression* AsExpression() { return this; } | 221 virtual Expression* AsExpression() { return this; } |
| 231 | 222 |
| 232 virtual bool IsTrivial() { return false; } | 223 virtual bool IsTrivial() { return false; } |
| 233 virtual bool IsValidLeftHandSide() { return false; } | 224 virtual bool IsValidLeftHandSide() { return false; } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return Handle<Map>(); | 262 return Handle<Map>(); |
| 272 } | 263 } |
| 273 | 264 |
| 274 ExternalArrayType external_array_type() const { | 265 ExternalArrayType external_array_type() const { |
| 275 return external_array_type_; | 266 return external_array_type_; |
| 276 } | 267 } |
| 277 void set_external_array_type(ExternalArrayType array_type) { | 268 void set_external_array_type(ExternalArrayType array_type) { |
| 278 external_array_type_ = array_type; | 269 external_array_type_ = array_type; |
| 279 } | 270 } |
| 280 | 271 |
| 272 unsigned id() const { return id_; } |
| 273 |
| 281 private: | 274 private: |
| 282 ExternalArrayType external_array_type_; | 275 ExternalArrayType external_array_type_; |
| 276 unsigned id_; |
| 283 }; | 277 }; |
| 284 | 278 |
| 285 | 279 |
| 286 /** | 280 /** |
| 287 * A sentinel used during pre parsing that represents some expression | 281 * A sentinel used during pre parsing that represents some expression |
| 288 * that is a valid left hand side without having to actually build | 282 * that is a valid left hand side without having to actually build |
| 289 * the expression. | 283 * the expression. |
| 290 */ | 284 */ |
| 291 class ValidLeftHandSideSentinel: public Expression { | 285 class ValidLeftHandSideSentinel: public Expression { |
| 292 public: | 286 public: |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 // HasThenStatement() and HasElseStatement() functions to check if a | 702 // HasThenStatement() and HasElseStatement() functions to check if a |
| 709 // given if-statement has a then- or an else-part containing code. | 703 // given if-statement has a then- or an else-part containing code. |
| 710 class IfStatement: public Statement { | 704 class IfStatement: public Statement { |
| 711 public: | 705 public: |
| 712 IfStatement(Expression* condition, | 706 IfStatement(Expression* condition, |
| 713 Statement* then_statement, | 707 Statement* then_statement, |
| 714 Statement* else_statement) | 708 Statement* else_statement) |
| 715 : condition_(condition), | 709 : condition_(condition), |
| 716 then_statement_(then_statement), | 710 then_statement_(then_statement), |
| 717 else_statement_(else_statement), | 711 else_statement_(else_statement), |
| 712 if_id_(GetNextId()), |
| 718 then_id_(GetNextId()), | 713 then_id_(GetNextId()), |
| 719 else_id_(GetNextId()) { | 714 else_id_(GetNextId()) { |
| 720 } | 715 } |
| 721 | 716 |
| 722 DECLARE_NODE_TYPE(IfStatement) | 717 DECLARE_NODE_TYPE(IfStatement) |
| 723 | 718 |
| 724 virtual bool IsInlineable() const; | 719 virtual bool IsInlineable() const; |
| 725 | 720 |
| 726 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } | 721 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } |
| 727 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } | 722 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } |
| 728 | 723 |
| 729 Expression* condition() const { return condition_; } | 724 Expression* condition() const { return condition_; } |
| 730 Statement* then_statement() const { return then_statement_; } | 725 Statement* then_statement() const { return then_statement_; } |
| 731 Statement* else_statement() const { return else_statement_; } | 726 Statement* else_statement() const { return else_statement_; } |
| 732 | 727 |
| 728 int IfId() const { return if_id_; } |
| 733 int ThenId() const { return then_id_; } | 729 int ThenId() const { return then_id_; } |
| 734 int ElseId() const { return else_id_; } | 730 int ElseId() const { return else_id_; } |
| 735 | 731 |
| 736 private: | 732 private: |
| 737 Expression* condition_; | 733 Expression* condition_; |
| 738 Statement* then_statement_; | 734 Statement* then_statement_; |
| 739 Statement* else_statement_; | 735 Statement* else_statement_; |
| 736 int if_id_; |
| 740 int then_id_; | 737 int then_id_; |
| 741 int else_id_; | 738 int else_id_; |
| 742 }; | 739 }; |
| 743 | 740 |
| 744 | 741 |
| 745 // NOTE: TargetCollectors are represented as nodes to fit in the target | 742 // NOTE: TargetCollectors are represented as nodes to fit in the target |
| 746 // stack in the compiler; this should probably be reworked. | 743 // stack in the compiler; this should probably be reworked. |
| 747 class TargetCollector: public AstNode { | 744 class TargetCollector: public AstNode { |
| 748 public: | 745 public: |
| 749 explicit TargetCollector(ZoneList<Label*>* targets) | 746 explicit TargetCollector(ZoneList<Label*>* targets) |
| (...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2179 | 2176 |
| 2180 private: | 2177 private: |
| 2181 Isolate* isolate_; | 2178 Isolate* isolate_; |
| 2182 bool stack_overflow_; | 2179 bool stack_overflow_; |
| 2183 }; | 2180 }; |
| 2184 | 2181 |
| 2185 | 2182 |
| 2186 } } // namespace v8::internal | 2183 } } // namespace v8::internal |
| 2187 | 2184 |
| 2188 #endif // V8_AST_H_ | 2185 #endif // V8_AST_H_ |
| OLD | NEW |