OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_AST_AST_H_ | 5 #ifndef V8_AST_AST_H_ |
6 #define V8_AST_AST_H_ | 6 #define V8_AST_AST_H_ |
7 | 7 |
8 #include "src/ast/ast-value-factory.h" | 8 #include "src/ast/ast-value-factory.h" |
9 #include "src/ast/modules.h" | 9 #include "src/ast/modules.h" |
10 #include "src/ast/variables.h" | 10 #include "src/ast/variables.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 // allocation and constant-time deallocation of the entire syntax | 32 // allocation and constant-time deallocation of the entire syntax |
33 // tree. | 33 // tree. |
34 | 34 |
35 | 35 |
36 // ---------------------------------------------------------------------------- | 36 // ---------------------------------------------------------------------------- |
37 // Nodes of the abstract syntax tree. Only concrete classes are | 37 // Nodes of the abstract syntax tree. Only concrete classes are |
38 // enumerated here. | 38 // enumerated here. |
39 | 39 |
40 #define DECLARATION_NODE_LIST(V) \ | 40 #define DECLARATION_NODE_LIST(V) \ |
41 V(VariableDeclaration) \ | 41 V(VariableDeclaration) \ |
42 V(FunctionDeclaration) \ | 42 V(FunctionDeclaration) |
43 V(ImportDeclaration) | |
44 | 43 |
45 #define ITERATION_NODE_LIST(V) \ | 44 #define ITERATION_NODE_LIST(V) \ |
46 V(DoWhileStatement) \ | 45 V(DoWhileStatement) \ |
47 V(WhileStatement) \ | 46 V(WhileStatement) \ |
48 V(ForStatement) \ | 47 V(ForStatement) \ |
49 V(ForInStatement) \ | 48 V(ForInStatement) \ |
50 V(ForOfStatement) | 49 V(ForOfStatement) |
51 | 50 |
52 #define BREAKABLE_NODE_LIST(V) \ | 51 #define BREAKABLE_NODE_LIST(V) \ |
53 V(Block) \ | 52 V(Block) \ |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 fun_(fun) { | 545 fun_(fun) { |
547 DCHECK(mode == VAR || mode == LET || mode == CONST); | 546 DCHECK(mode == VAR || mode == LET || mode == CONST); |
548 DCHECK(fun != NULL); | 547 DCHECK(fun != NULL); |
549 } | 548 } |
550 | 549 |
551 private: | 550 private: |
552 FunctionLiteral* fun_; | 551 FunctionLiteral* fun_; |
553 }; | 552 }; |
554 | 553 |
555 | 554 |
556 class ImportDeclaration final : public Declaration { | |
557 public: | |
558 DECLARE_NODE_TYPE(ImportDeclaration) | |
559 | |
560 const AstRawString* import_name() const { return import_name_; } | |
561 const AstRawString* module_specifier() const { return module_specifier_; } | |
562 void set_module_specifier(const AstRawString* module_specifier) { | |
563 DCHECK(module_specifier_ == NULL); | |
564 module_specifier_ = module_specifier; | |
565 } | |
566 InitializationFlag initialization() const { return kNeedsInitialization; } | |
567 | |
568 protected: | |
569 ImportDeclaration(Zone* zone, VariableProxy* proxy, | |
570 const AstRawString* import_name, | |
571 const AstRawString* module_specifier, Scope* scope, int pos) | |
572 : Declaration(zone, proxy, CONST, scope, pos, kImportDeclaration), | |
573 import_name_(import_name), | |
574 module_specifier_(module_specifier) {} | |
575 | |
576 private: | |
577 const AstRawString* import_name_; | |
578 const AstRawString* module_specifier_; | |
579 }; | |
580 | |
581 class Module final : public AstNode { | |
582 public: | |
583 ModuleDescriptor* descriptor() const { return descriptor_; } | |
584 Block* body() const { return body_; } | |
585 | |
586 protected: | |
587 Module(Zone* zone, int pos) | |
588 : AstNode(pos, kModule), | |
589 descriptor_(ModuleDescriptor::New(zone)), | |
590 body_(NULL) {} | |
591 Module(Zone* zone, ModuleDescriptor* descriptor, int pos, Block* body = NULL) | |
592 : AstNode(pos, kModule), descriptor_(descriptor), body_(body) {} | |
593 | |
594 private: | |
595 ModuleDescriptor* descriptor_; | |
596 Block* body_; | |
597 }; | |
598 | |
599 | |
600 class IterationStatement : public BreakableStatement { | 555 class IterationStatement : public BreakableStatement { |
601 public: | 556 public: |
602 Statement* body() const { return body_; } | 557 Statement* body() const { return body_; } |
603 void set_body(Statement* s) { body_ = s; } | 558 void set_body(Statement* s) { body_ = s; } |
604 | 559 |
605 int yield_count() const { return yield_count_; } | 560 int yield_count() const { return yield_count_; } |
606 int first_yield_id() const { return first_yield_id_; } | 561 int first_yield_id() const { return first_yield_id_; } |
607 void set_yield_count(int yield_count) { yield_count_ = yield_count; } | 562 void set_yield_count(int yield_count) { yield_count_ = yield_count; } |
608 void set_first_yield_id(int first_yield_id) { | 563 void set_first_yield_id(int first_yield_id) { |
609 first_yield_id_ = first_yield_id; | 564 first_yield_id_ = first_yield_id; |
(...skipping 2514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3124 | 3079 |
3125 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, | 3080 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, |
3126 VariableMode mode, | 3081 VariableMode mode, |
3127 FunctionLiteral* fun, | 3082 FunctionLiteral* fun, |
3128 Scope* scope, | 3083 Scope* scope, |
3129 int pos) { | 3084 int pos) { |
3130 return new (parser_zone_) | 3085 return new (parser_zone_) |
3131 FunctionDeclaration(parser_zone_, proxy, mode, fun, scope, pos); | 3086 FunctionDeclaration(parser_zone_, proxy, mode, fun, scope, pos); |
3132 } | 3087 } |
3133 | 3088 |
3134 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy, | |
3135 const AstRawString* import_name, | |
3136 const AstRawString* module_specifier, | |
3137 Scope* scope, int pos) { | |
3138 return new (parser_zone_) ImportDeclaration( | |
3139 parser_zone_, proxy, import_name, module_specifier, scope, pos); | |
3140 } | |
3141 | |
3142 Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, | 3089 Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, |
3143 bool ignore_completion_value, int pos) { | 3090 bool ignore_completion_value, int pos) { |
3144 return new (local_zone_) | 3091 return new (local_zone_) |
3145 Block(local_zone_, labels, capacity, ignore_completion_value, pos); | 3092 Block(local_zone_, labels, capacity, ignore_completion_value, pos); |
3146 } | 3093 } |
3147 | 3094 |
3148 #define STATEMENT_WITH_LABELS(NodeType) \ | 3095 #define STATEMENT_WITH_LABELS(NodeType) \ |
3149 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \ | 3096 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \ |
3150 return new (local_zone_) NodeType(local_zone_, labels, pos); \ | 3097 return new (local_zone_) NodeType(local_zone_, labels, pos); \ |
3151 } | 3098 } |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3593 : NULL; \ | 3540 : NULL; \ |
3594 } | 3541 } |
3595 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3542 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3596 #undef DECLARE_NODE_FUNCTIONS | 3543 #undef DECLARE_NODE_FUNCTIONS |
3597 | 3544 |
3598 | 3545 |
3599 } // namespace internal | 3546 } // namespace internal |
3600 } // namespace v8 | 3547 } // namespace v8 |
3601 | 3548 |
3602 #endif // V8_AST_AST_H_ | 3549 #endif // V8_AST_AST_H_ |
OLD | NEW |