OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 52 |
53 // Nodes are allocated in a separate zone, which allows faster | 53 // Nodes are allocated in a separate zone, which allows faster |
54 // allocation and constant-time deallocation of the entire syntax | 54 // allocation and constant-time deallocation of the entire syntax |
55 // tree. | 55 // tree. |
56 | 56 |
57 | 57 |
58 // ---------------------------------------------------------------------------- | 58 // ---------------------------------------------------------------------------- |
59 // Nodes of the abstract syntax tree. Only concrete classes are | 59 // Nodes of the abstract syntax tree. Only concrete classes are |
60 // enumerated here. | 60 // enumerated here. |
61 | 61 |
62 #define DECLARATION_NODE_LIST(V) \ | |
63 V(VariableDeclaration) \ | |
64 | |
62 #define STATEMENT_NODE_LIST(V) \ | 65 #define STATEMENT_NODE_LIST(V) \ |
63 V(Block) \ | 66 V(Block) \ |
64 V(ExpressionStatement) \ | 67 V(ExpressionStatement) \ |
65 V(EmptyStatement) \ | 68 V(EmptyStatement) \ |
66 V(IfStatement) \ | 69 V(IfStatement) \ |
67 V(ContinueStatement) \ | 70 V(ContinueStatement) \ |
68 V(BreakStatement) \ | 71 V(BreakStatement) \ |
69 V(ReturnStatement) \ | 72 V(ReturnStatement) \ |
70 V(WithStatement) \ | 73 V(WithStatement) \ |
71 V(SwitchStatement) \ | 74 V(SwitchStatement) \ |
(...skipping 20 matching lines...) Expand all Loading... | |
92 V(Call) \ | 95 V(Call) \ |
93 V(CallNew) \ | 96 V(CallNew) \ |
94 V(CallRuntime) \ | 97 V(CallRuntime) \ |
95 V(UnaryOperation) \ | 98 V(UnaryOperation) \ |
96 V(CountOperation) \ | 99 V(CountOperation) \ |
97 V(BinaryOperation) \ | 100 V(BinaryOperation) \ |
98 V(CompareOperation) \ | 101 V(CompareOperation) \ |
99 V(ThisFunction) | 102 V(ThisFunction) |
100 | 103 |
101 #define AST_NODE_LIST(V) \ | 104 #define AST_NODE_LIST(V) \ |
102 V(Declaration) \ | 105 DECLARATION_NODE_LIST(V) \ |
103 STATEMENT_NODE_LIST(V) \ | 106 STATEMENT_NODE_LIST(V) \ |
104 EXPRESSION_NODE_LIST(V) | 107 EXPRESSION_NODE_LIST(V) |
105 | 108 |
106 // Forward declarations | 109 // Forward declarations |
107 class AstConstructionVisitor; | 110 class AstConstructionVisitor; |
108 template<class> class AstNodeFactory; | 111 template<class> class AstNodeFactory; |
109 class AstVisitor; | 112 class AstVisitor; |
113 class Declaration; | |
110 class BreakableStatement; | 114 class BreakableStatement; |
111 class Expression; | 115 class Expression; |
112 class IterationStatement; | 116 class IterationStatement; |
113 class MaterializedLiteral; | 117 class MaterializedLiteral; |
114 class Statement; | 118 class Statement; |
115 class TargetCollector; | 119 class TargetCollector; |
116 class TypeFeedbackOracle; | 120 class TypeFeedbackOracle; |
117 | 121 |
118 class RegExpAlternative; | 122 class RegExpAlternative; |
119 class RegExpAssertion; | 123 class RegExpAssertion; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 virtual void Accept(AstVisitor* v) = 0; | 199 virtual void Accept(AstVisitor* v) = 0; |
196 virtual Type node_type() const { return kInvalid; } | 200 virtual Type node_type() const { return kInvalid; } |
197 | 201 |
198 // Type testing & conversion functions overridden by concrete subclasses. | 202 // Type testing & conversion functions overridden by concrete subclasses. |
199 #define DECLARE_NODE_FUNCTIONS(type) \ | 203 #define DECLARE_NODE_FUNCTIONS(type) \ |
200 bool Is##type() { return node_type() == AstNode::k##type; } \ | 204 bool Is##type() { return node_type() == AstNode::k##type; } \ |
201 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } | 205 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } |
202 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 206 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
203 #undef DECLARE_NODE_FUNCTIONS | 207 #undef DECLARE_NODE_FUNCTIONS |
204 | 208 |
209 virtual Declaration* AsDeclaration() { return NULL; } | |
205 virtual Statement* AsStatement() { return NULL; } | 210 virtual Statement* AsStatement() { return NULL; } |
206 virtual Expression* AsExpression() { return NULL; } | 211 virtual Expression* AsExpression() { return NULL; } |
207 virtual TargetCollector* AsTargetCollector() { return NULL; } | 212 virtual TargetCollector* AsTargetCollector() { return NULL; } |
208 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 213 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
209 virtual IterationStatement* AsIterationStatement() { return NULL; } | 214 virtual IterationStatement* AsIterationStatement() { return NULL; } |
210 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 215 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
211 | 216 |
212 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } | 217 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } |
213 | 218 |
214 protected: | 219 protected: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 | 431 |
427 private: | 432 private: |
428 ZoneList<Statement*> statements_; | 433 ZoneList<Statement*> statements_; |
429 bool is_initializer_block_; | 434 bool is_initializer_block_; |
430 Scope* block_scope_; | 435 Scope* block_scope_; |
431 }; | 436 }; |
432 | 437 |
433 | 438 |
434 class Declaration: public AstNode { | 439 class Declaration: public AstNode { |
435 public: | 440 public: |
436 DECLARE_NODE_TYPE(Declaration) | |
437 | |
438 VariableProxy* proxy() const { return proxy_; } | 441 VariableProxy* proxy() const { return proxy_; } |
439 VariableMode mode() const { return mode_; } | 442 VariableMode mode() const { return mode_; } |
440 FunctionLiteral* fun() const { return fun_; } // may be NULL | |
441 bool IsInlineable() const; | |
442 Scope* scope() const { return scope_; } | 443 Scope* scope() const { return scope_; } |
444 virtual bool IsInlineable() const; | |
Kevin Millikin (Chromium)
2012/02/08 15:23:04
I think this method is obsolete (and the check in
Jakob Kummerow
2012/02/08 15:40:28
This is true for all AstNodes *except* Declaration
rossberg
2012/02/08 15:46:43
I can't tell, but according to Jakob, the info is
| |
445 | |
446 virtual Declaration* AsDeclaration() { return this; } | |
447 virtual VariableDeclaration* AsVariableDeclaration() { return NULL; } | |
443 | 448 |
444 protected: | 449 protected: |
445 template<class> friend class AstNodeFactory; | 450 template<class> friend class AstNodeFactory; |
Jakob Kummerow
2012/02/08 15:40:28
I think you don't need this any more.
rossberg
2012/02/08 15:52:21
Done.
| |
446 | 451 |
447 Declaration(VariableProxy* proxy, | 452 Declaration(VariableProxy* proxy, |
448 VariableMode mode, | 453 VariableMode mode, |
449 FunctionLiteral* fun, | |
450 Scope* scope) | 454 Scope* scope) |
451 : proxy_(proxy), | 455 : proxy_(proxy), |
452 mode_(mode), | 456 mode_(mode), |
453 fun_(fun), | |
454 scope_(scope) { | 457 scope_(scope) { |
455 ASSERT(mode == VAR || | 458 ASSERT(mode == VAR || |
456 mode == CONST || | 459 mode == CONST || |
457 mode == CONST_HARMONY || | 460 mode == CONST_HARMONY || |
458 mode == LET); | 461 mode == LET); |
459 // At the moment there are no "const functions"'s in JavaScript... | |
460 ASSERT(fun == NULL || mode == VAR || mode == LET); | |
461 } | 462 } |
462 | 463 |
463 private: | 464 private: |
464 VariableProxy* proxy_; | 465 VariableProxy* proxy_; |
465 VariableMode mode_; | 466 VariableMode mode_; |
466 FunctionLiteral* fun_; | |
467 | 467 |
468 // Nested scope from which the declaration originated. | 468 // Nested scope from which the declaration originated. |
469 Scope* scope_; | 469 Scope* scope_; |
470 }; | 470 }; |
471 | 471 |
472 | 472 |
473 class VariableDeclaration: public Declaration { | |
Kevin Millikin (Chromium)
2012/02/08 15:23:04
It's a little weird that VariableDeclaration inclu
rossberg
2012/02/08 15:46:43
Not yet, it currently still just calls them "decla
| |
474 public: | |
475 VariableDeclaration(VariableProxy* proxy, | |
Jakob Kummerow
2012/02/08 15:40:28
Suggestion: Move the constructor to a "protected:"
rossberg
2012/02/08 15:52:21
Done.
| |
476 VariableMode mode, | |
477 FunctionLiteral* fun, | |
478 Scope* scope) | |
479 : Declaration(proxy, mode, scope), | |
480 fun_(fun) { | |
481 // At the moment there are no "const functions"'s in JavaScript... | |
482 ASSERT(fun == NULL || mode == VAR || mode == LET); | |
483 } | |
484 | |
485 DECLARE_NODE_TYPE(VariableDeclaration) | |
486 | |
487 virtual VariableDeclaration* AsVariableDeclaration() { return this; } | |
488 | |
489 FunctionLiteral* fun() const { return fun_; } // may be NULL | |
490 virtual bool IsInlineable() const; | |
491 | |
492 private: | |
493 FunctionLiteral* fun_; | |
494 }; | |
495 | |
496 | |
473 class IterationStatement: public BreakableStatement { | 497 class IterationStatement: public BreakableStatement { |
474 public: | 498 public: |
475 // Type testing & conversion. | 499 // Type testing & conversion. |
476 virtual IterationStatement* AsIterationStatement() { return this; } | 500 virtual IterationStatement* AsIterationStatement() { return this; } |
477 | 501 |
478 Statement* body() const { return body_; } | 502 Statement* body() const { return body_; } |
479 | 503 |
480 // Bailout support. | 504 // Bailout support. |
481 int OsrEntryId() const { return osr_entry_id_; } | 505 int OsrEntryId() const { return osr_entry_id_; } |
482 virtual int ContinueId() const = 0; | 506 virtual int ContinueId() const = 0; |
(...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2361 explicit AstNodeFactory(Isolate* isolate) | 2385 explicit AstNodeFactory(Isolate* isolate) |
2362 : isolate_(isolate), | 2386 : isolate_(isolate), |
2363 zone_(isolate_->zone()) { } | 2387 zone_(isolate_->zone()) { } |
2364 | 2388 |
2365 Visitor* visitor() { return &visitor_; } | 2389 Visitor* visitor() { return &visitor_; } |
2366 | 2390 |
2367 #define VISIT_AND_RETURN(NodeType, node) \ | 2391 #define VISIT_AND_RETURN(NodeType, node) \ |
2368 visitor_.Visit##NodeType((node)); \ | 2392 visitor_.Visit##NodeType((node)); \ |
2369 return node; | 2393 return node; |
2370 | 2394 |
2395 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, | |
2396 VariableMode mode, | |
2397 FunctionLiteral* fun, | |
2398 Scope* scope) { | |
2399 VariableDeclaration* decl = | |
2400 new(zone_) VariableDeclaration(proxy, mode, fun, scope); | |
2401 VISIT_AND_RETURN(VariableDeclaration, decl) | |
2402 } | |
2403 | |
2371 Block* NewBlock(ZoneStringList* labels, | 2404 Block* NewBlock(ZoneStringList* labels, |
2372 int capacity, | 2405 int capacity, |
2373 bool is_initializer_block) { | 2406 bool is_initializer_block) { |
2374 Block* block = new(zone_) Block( | 2407 Block* block = new(zone_) Block( |
2375 isolate_, labels, capacity, is_initializer_block); | 2408 isolate_, labels, capacity, is_initializer_block); |
2376 VISIT_AND_RETURN(Block, block) | 2409 VISIT_AND_RETURN(Block, block) |
2377 } | 2410 } |
2378 | 2411 |
2379 Declaration* NewDeclaration(VariableProxy* proxy, | |
2380 VariableMode mode, | |
2381 FunctionLiteral* fun, | |
2382 Scope* scope) { | |
2383 Declaration* decl = new(zone_) Declaration(proxy, mode, fun, scope); | |
2384 VISIT_AND_RETURN(Declaration, decl) | |
2385 } | |
2386 | |
2387 #define STATEMENT_WITH_LABELS(NodeType) \ | 2412 #define STATEMENT_WITH_LABELS(NodeType) \ |
2388 NodeType* New##NodeType(ZoneStringList* labels) { \ | 2413 NodeType* New##NodeType(ZoneStringList* labels) { \ |
2389 NodeType* stmt = new(zone_) NodeType(isolate_, labels); \ | 2414 NodeType* stmt = new(zone_) NodeType(isolate_, labels); \ |
2390 VISIT_AND_RETURN(NodeType, stmt); \ | 2415 VISIT_AND_RETURN(NodeType, stmt); \ |
2391 } | 2416 } |
2392 STATEMENT_WITH_LABELS(DoWhileStatement) | 2417 STATEMENT_WITH_LABELS(DoWhileStatement) |
2393 STATEMENT_WITH_LABELS(WhileStatement) | 2418 STATEMENT_WITH_LABELS(WhileStatement) |
2394 STATEMENT_WITH_LABELS(ForStatement) | 2419 STATEMENT_WITH_LABELS(ForStatement) |
2395 STATEMENT_WITH_LABELS(ForInStatement) | 2420 STATEMENT_WITH_LABELS(ForInStatement) |
2396 STATEMENT_WITH_LABELS(SwitchStatement) | 2421 STATEMENT_WITH_LABELS(SwitchStatement) |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2648 private: | 2673 private: |
2649 Isolate* isolate_; | 2674 Isolate* isolate_; |
2650 Zone* zone_; | 2675 Zone* zone_; |
2651 Visitor visitor_; | 2676 Visitor visitor_; |
2652 }; | 2677 }; |
2653 | 2678 |
2654 | 2679 |
2655 } } // namespace v8::internal | 2680 } } // namespace v8::internal |
2656 | 2681 |
2657 #endif // V8_AST_H_ | 2682 #endif // V8_AST_H_ |
OLD | NEW |