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_H_ | 5 #ifndef V8_AST_H_ |
6 #define V8_AST_H_ | 6 #define V8_AST_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/assembler.h" | 10 #include "src/assembler.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 #define DECLARATION_NODE_LIST(V) \ | 42 #define DECLARATION_NODE_LIST(V) \ |
43 V(VariableDeclaration) \ | 43 V(VariableDeclaration) \ |
44 V(FunctionDeclaration) \ | 44 V(FunctionDeclaration) \ |
45 V(ModuleDeclaration) \ | 45 V(ModuleDeclaration) \ |
46 V(ImportDeclaration) \ | 46 V(ImportDeclaration) \ |
47 V(ExportDeclaration) | 47 V(ExportDeclaration) |
48 | 48 |
49 #define MODULE_NODE_LIST(V) \ | 49 #define MODULE_NODE_LIST(V) \ |
50 V(ModuleLiteral) \ | 50 V(ModuleLiteral) \ |
51 V(ModuleVariable) \ | |
52 V(ModulePath) \ | 51 V(ModulePath) \ |
53 V(ModuleUrl) | 52 V(ModuleUrl) |
54 | 53 |
55 #define STATEMENT_NODE_LIST(V) \ | 54 #define STATEMENT_NODE_LIST(V) \ |
56 V(Block) \ | 55 V(Block) \ |
57 V(ModuleStatement) \ | 56 V(ModuleStatement) \ |
58 V(ExpressionStatement) \ | 57 V(ExpressionStatement) \ |
59 V(EmptyStatement) \ | 58 V(EmptyStatement) \ |
60 V(IfStatement) \ | 59 V(IfStatement) \ |
61 V(ContinueStatement) \ | 60 V(ContinueStatement) \ |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 class ModuleDeclaration FINAL : public Declaration { | 590 class ModuleDeclaration FINAL : public Declaration { |
592 public: | 591 public: |
593 DECLARE_NODE_TYPE(ModuleDeclaration) | 592 DECLARE_NODE_TYPE(ModuleDeclaration) |
594 | 593 |
595 Module* module() const { return module_; } | 594 Module* module() const { return module_; } |
596 InitializationFlag initialization() const OVERRIDE { | 595 InitializationFlag initialization() const OVERRIDE { |
597 return kCreatedInitialized; | 596 return kCreatedInitialized; |
598 } | 597 } |
599 | 598 |
600 protected: | 599 protected: |
601 ModuleDeclaration(Zone* zone, | 600 ModuleDeclaration(Zone* zone, VariableProxy* proxy, Module* module, |
602 VariableProxy* proxy, | 601 Scope* scope, int pos) |
603 Module* module, | 602 : Declaration(zone, proxy, CONST, scope, pos), module_(module) {} |
604 Scope* scope, | |
605 int pos) | |
606 : Declaration(zone, proxy, MODULE, scope, pos), | |
607 module_(module) { | |
608 } | |
609 | 603 |
610 private: | 604 private: |
611 Module* module_; | 605 Module* module_; |
612 }; | 606 }; |
613 | 607 |
614 | 608 |
615 class ImportDeclaration FINAL : public Declaration { | 609 class ImportDeclaration FINAL : public Declaration { |
616 public: | 610 public: |
617 DECLARE_NODE_TYPE(ImportDeclaration) | 611 DECLARE_NODE_TYPE(ImportDeclaration) |
618 | 612 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 class ModuleLiteral FINAL : public Module { | 668 class ModuleLiteral FINAL : public Module { |
675 public: | 669 public: |
676 DECLARE_NODE_TYPE(ModuleLiteral) | 670 DECLARE_NODE_TYPE(ModuleLiteral) |
677 | 671 |
678 protected: | 672 protected: |
679 ModuleLiteral(Zone* zone, Block* body, Interface* interface, int pos) | 673 ModuleLiteral(Zone* zone, Block* body, Interface* interface, int pos) |
680 : Module(zone, interface, pos, body) {} | 674 : Module(zone, interface, pos, body) {} |
681 }; | 675 }; |
682 | 676 |
683 | 677 |
684 class ModuleVariable FINAL : public Module { | |
685 public: | |
686 DECLARE_NODE_TYPE(ModuleVariable) | |
687 | |
688 VariableProxy* proxy() const { return proxy_; } | |
689 | |
690 protected: | |
691 inline ModuleVariable(Zone* zone, VariableProxy* proxy, int pos); | |
692 | |
693 private: | |
694 VariableProxy* proxy_; | |
695 }; | |
696 | |
697 | |
698 class ModulePath FINAL : public Module { | 678 class ModulePath FINAL : public Module { |
699 public: | 679 public: |
700 DECLARE_NODE_TYPE(ModulePath) | 680 DECLARE_NODE_TYPE(ModulePath) |
701 | 681 |
702 Module* module() const { return module_; } | 682 Module* module() const { return module_; } |
703 Handle<String> name() const { return name_->string(); } | 683 Handle<String> name() const { return name_->string(); } |
704 | 684 |
705 protected: | 685 protected: |
706 ModulePath(Zone* zone, Module* module, const AstRawString* name, int pos) | 686 ModulePath(Zone* zone, Module* module, const AstRawString* name, int pos) |
707 : Module(zone, pos), module_(module), name_(name) {} | 687 : Module(zone, pos), module_(module), name_(name) {} |
(...skipping 17 matching lines...) Expand all Loading... |
725 | 705 |
726 private: | 706 private: |
727 Handle<String> url_; | 707 Handle<String> url_; |
728 }; | 708 }; |
729 | 709 |
730 | 710 |
731 class ModuleStatement FINAL : public Statement { | 711 class ModuleStatement FINAL : public Statement { |
732 public: | 712 public: |
733 DECLARE_NODE_TYPE(ModuleStatement) | 713 DECLARE_NODE_TYPE(ModuleStatement) |
734 | 714 |
735 VariableProxy* proxy() const { return proxy_; } | |
736 Block* body() const { return body_; } | 715 Block* body() const { return body_; } |
737 | 716 |
738 protected: | 717 protected: |
739 ModuleStatement(Zone* zone, VariableProxy* proxy, Block* body, int pos) | 718 ModuleStatement(Zone* zone, Block* body, int pos) |
740 : Statement(zone, pos), | 719 : Statement(zone, pos), body_(body) {} |
741 proxy_(proxy), | |
742 body_(body) { | |
743 } | |
744 | 720 |
745 private: | 721 private: |
746 VariableProxy* proxy_; | |
747 Block* body_; | 722 Block* body_; |
748 }; | 723 }; |
749 | 724 |
750 | 725 |
751 class IterationStatement : public BreakableStatement { | 726 class IterationStatement : public BreakableStatement { |
752 public: | 727 public: |
753 // Type testing & conversion. | 728 // Type testing & conversion. |
754 IterationStatement* AsIterationStatement() FINAL { return this; } | 729 IterationStatement* AsIterationStatement() FINAL { return this; } |
755 | 730 |
756 Statement* body() const { return body_; } | 731 Statement* body() const { return body_; } |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 bool is_assigned() const { return IsAssignedField::decode(bit_field_); } | 1629 bool is_assigned() const { return IsAssignedField::decode(bit_field_); } |
1655 void set_is_assigned() { | 1630 void set_is_assigned() { |
1656 bit_field_ = IsAssignedField::update(bit_field_, true); | 1631 bit_field_ = IsAssignedField::update(bit_field_, true); |
1657 } | 1632 } |
1658 | 1633 |
1659 bool is_resolved() const { return IsResolvedField::decode(bit_field_); } | 1634 bool is_resolved() const { return IsResolvedField::decode(bit_field_); } |
1660 void set_is_resolved() { | 1635 void set_is_resolved() { |
1661 bit_field_ = IsResolvedField::update(bit_field_, true); | 1636 bit_field_ = IsResolvedField::update(bit_field_, true); |
1662 } | 1637 } |
1663 | 1638 |
1664 Interface* interface() const { return interface_; } | 1639 // Bind this proxy to the variable var. |
1665 | |
1666 // Bind this proxy to the variable var. Interfaces must match. | |
1667 void BindTo(Variable* var); | 1640 void BindTo(Variable* var); |
1668 | 1641 |
1669 bool UsesVariableFeedbackSlot() const { | 1642 bool UsesVariableFeedbackSlot() const { |
1670 return FLAG_vector_ics && (var()->IsUnallocated() || var()->IsLookupSlot()); | 1643 return FLAG_vector_ics && (var()->IsUnallocated() || var()->IsLookupSlot()); |
1671 } | 1644 } |
1672 | 1645 |
1673 virtual FeedbackVectorRequirements ComputeFeedbackRequirements( | 1646 virtual FeedbackVectorRequirements ComputeFeedbackRequirements( |
1674 Isolate* isolate) OVERRIDE { | 1647 Isolate* isolate) OVERRIDE { |
1675 return FeedbackVectorRequirements(0, UsesVariableFeedbackSlot() ? 1 : 0); | 1648 return FeedbackVectorRequirements(0, UsesVariableFeedbackSlot() ? 1 : 0); |
1676 } | 1649 } |
1677 | 1650 |
1678 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { | 1651 void SetFirstFeedbackICSlot(FeedbackVectorICSlot slot) OVERRIDE { |
1679 variable_feedback_slot_ = slot; | 1652 variable_feedback_slot_ = slot; |
1680 } | 1653 } |
1681 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; } | 1654 Code::Kind FeedbackICSlotKind(int index) OVERRIDE { return Code::LOAD_IC; } |
1682 FeedbackVectorICSlot VariableFeedbackSlot() { | 1655 FeedbackVectorICSlot VariableFeedbackSlot() { |
1683 DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid()); | 1656 DCHECK(!UsesVariableFeedbackSlot() || !variable_feedback_slot_.IsInvalid()); |
1684 return variable_feedback_slot_; | 1657 return variable_feedback_slot_; |
1685 } | 1658 } |
1686 | 1659 |
1687 protected: | 1660 protected: |
1688 VariableProxy(Zone* zone, Variable* var, int position); | 1661 VariableProxy(Zone* zone, Variable* var, int position); |
1689 | 1662 |
1690 VariableProxy(Zone* zone, const AstRawString* name, bool is_this, | 1663 VariableProxy(Zone* zone, const AstRawString* name, bool is_this, |
1691 Interface* interface, int position); | 1664 int position); |
1692 | 1665 |
1693 class IsThisField : public BitField8<bool, 0, 1> {}; | 1666 class IsThisField : public BitField8<bool, 0, 1> {}; |
1694 class IsAssignedField : public BitField8<bool, 1, 1> {}; | 1667 class IsAssignedField : public BitField8<bool, 1, 1> {}; |
1695 class IsResolvedField : public BitField8<bool, 2, 1> {}; | 1668 class IsResolvedField : public BitField8<bool, 2, 1> {}; |
1696 | 1669 |
1697 // Start with 16-bit (or smaller) field, which should get packed together | 1670 // Start with 16-bit (or smaller) field, which should get packed together |
1698 // with Expression's trailing 16-bit field. | 1671 // with Expression's trailing 16-bit field. |
1699 uint8_t bit_field_; | 1672 uint8_t bit_field_; |
1700 FeedbackVectorICSlot variable_feedback_slot_; | 1673 FeedbackVectorICSlot variable_feedback_slot_; |
1701 union { | 1674 union { |
1702 const AstRawString* raw_name_; // if !is_resolved_ | 1675 const AstRawString* raw_name_; // if !is_resolved_ |
1703 Variable* var_; // if is_resolved_ | 1676 Variable* var_; // if is_resolved_ |
1704 }; | 1677 }; |
1705 Interface* interface_; | |
1706 }; | 1678 }; |
1707 | 1679 |
1708 | 1680 |
1709 class Property FINAL : public Expression { | 1681 class Property FINAL : public Expression { |
1710 public: | 1682 public: |
1711 DECLARE_NODE_TYPE(Property) | 1683 DECLARE_NODE_TYPE(Property) |
1712 | 1684 |
1713 bool IsValidReferenceExpression() const OVERRIDE { return true; } | 1685 bool IsValidReferenceExpression() const OVERRIDE { return true; } |
1714 | 1686 |
1715 Expression* obj() const { return obj_; } | 1687 Expression* obj() const { return obj_; } |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3094 virtual RegExpNode* ToNode(RegExpCompiler* compiler, | 3066 virtual RegExpNode* ToNode(RegExpCompiler* compiler, |
3095 RegExpNode* on_success) OVERRIDE; | 3067 RegExpNode* on_success) OVERRIDE; |
3096 RegExpEmpty* AsEmpty() OVERRIDE; | 3068 RegExpEmpty* AsEmpty() OVERRIDE; |
3097 bool IsEmpty() OVERRIDE; | 3069 bool IsEmpty() OVERRIDE; |
3098 int min_match() OVERRIDE { return 0; } | 3070 int min_match() OVERRIDE { return 0; } |
3099 int max_match() OVERRIDE { return 0; } | 3071 int max_match() OVERRIDE { return 0; } |
3100 }; | 3072 }; |
3101 | 3073 |
3102 | 3074 |
3103 // ---------------------------------------------------------------------------- | 3075 // ---------------------------------------------------------------------------- |
3104 // Out-of-line inline constructors (to side-step cyclic dependencies). | |
3105 | |
3106 inline ModuleVariable::ModuleVariable(Zone* zone, VariableProxy* proxy, int pos) | |
3107 : Module(zone, proxy->interface(), pos), | |
3108 proxy_(proxy) { | |
3109 } | |
3110 | |
3111 | |
3112 // ---------------------------------------------------------------------------- | |
3113 // Basic visitor | 3076 // Basic visitor |
3114 // - leaf node visitors are abstract. | 3077 // - leaf node visitors are abstract. |
3115 | 3078 |
3116 class AstVisitor BASE_EMBEDDED { | 3079 class AstVisitor BASE_EMBEDDED { |
3117 public: | 3080 public: |
3118 AstVisitor() {} | 3081 AstVisitor() {} |
3119 virtual ~AstVisitor() {} | 3082 virtual ~AstVisitor() {} |
3120 | 3083 |
3121 // Stack overflow check and dynamic dispatch. | 3084 // Stack overflow check and dynamic dispatch. |
3122 virtual void Visit(AstNode* node) = 0; | 3085 virtual void Visit(AstNode* node) = 0; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3207 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, | 3170 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, |
3208 Scope* scope, | 3171 Scope* scope, |
3209 int pos) { | 3172 int pos) { |
3210 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos); | 3173 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos); |
3211 } | 3174 } |
3212 | 3175 |
3213 ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface, int pos) { | 3176 ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface, int pos) { |
3214 return new (zone_) ModuleLiteral(zone_, body, interface, pos); | 3177 return new (zone_) ModuleLiteral(zone_, body, interface, pos); |
3215 } | 3178 } |
3216 | 3179 |
3217 ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) { | |
3218 return new (zone_) ModuleVariable(zone_, proxy, pos); | |
3219 } | |
3220 | |
3221 ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) { | 3180 ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) { |
3222 return new (zone_) ModulePath(zone_, origin, name, pos); | 3181 return new (zone_) ModulePath(zone_, origin, name, pos); |
3223 } | 3182 } |
3224 | 3183 |
3225 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) { | 3184 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) { |
3226 return new (zone_) ModuleUrl(zone_, url, pos); | 3185 return new (zone_) ModuleUrl(zone_, url, pos); |
3227 } | 3186 } |
3228 | 3187 |
3229 Block* NewBlock(ZoneList<const AstRawString*>* labels, | 3188 Block* NewBlock(ZoneList<const AstRawString*>* labels, |
3230 int capacity, | 3189 int capacity, |
(...skipping 21 matching lines...) Expand all Loading... |
3252 return new (zone_) ForInStatement(zone_, labels, pos); | 3211 return new (zone_) ForInStatement(zone_, labels, pos); |
3253 } | 3212 } |
3254 case ForEachStatement::ITERATE: { | 3213 case ForEachStatement::ITERATE: { |
3255 return new (zone_) ForOfStatement(zone_, labels, pos); | 3214 return new (zone_) ForOfStatement(zone_, labels, pos); |
3256 } | 3215 } |
3257 } | 3216 } |
3258 UNREACHABLE(); | 3217 UNREACHABLE(); |
3259 return NULL; | 3218 return NULL; |
3260 } | 3219 } |
3261 | 3220 |
3262 ModuleStatement* NewModuleStatement( | 3221 ModuleStatement* NewModuleStatement(Block* body, int pos) { |
3263 VariableProxy* proxy, Block* body, int pos) { | 3222 return new (zone_) ModuleStatement(zone_, body, pos); |
3264 return new (zone_) ModuleStatement(zone_, proxy, body, pos); | |
3265 } | 3223 } |
3266 | 3224 |
3267 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { | 3225 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { |
3268 return new (zone_) ExpressionStatement(zone_, expression, pos); | 3226 return new (zone_) ExpressionStatement(zone_, expression, pos); |
3269 } | 3227 } |
3270 | 3228 |
3271 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { | 3229 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { |
3272 return new (zone_) ContinueStatement(zone_, target, pos); | 3230 return new (zone_) ContinueStatement(zone_, target, pos); |
3273 } | 3231 } |
3274 | 3232 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3399 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos); | 3357 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos); |
3400 } | 3358 } |
3401 | 3359 |
3402 VariableProxy* NewVariableProxy(Variable* var, | 3360 VariableProxy* NewVariableProxy(Variable* var, |
3403 int pos = RelocInfo::kNoPosition) { | 3361 int pos = RelocInfo::kNoPosition) { |
3404 return new (zone_) VariableProxy(zone_, var, pos); | 3362 return new (zone_) VariableProxy(zone_, var, pos); |
3405 } | 3363 } |
3406 | 3364 |
3407 VariableProxy* NewVariableProxy(const AstRawString* name, | 3365 VariableProxy* NewVariableProxy(const AstRawString* name, |
3408 bool is_this, | 3366 bool is_this, |
3409 Interface* interface = Interface::NewValue(), | |
3410 int position = RelocInfo::kNoPosition) { | 3367 int position = RelocInfo::kNoPosition) { |
3411 return new (zone_) VariableProxy(zone_, name, is_this, interface, position); | 3368 return new (zone_) VariableProxy(zone_, name, is_this, position); |
3412 } | 3369 } |
3413 | 3370 |
3414 Property* NewProperty(Expression* obj, Expression* key, int pos) { | 3371 Property* NewProperty(Expression* obj, Expression* key, int pos) { |
3415 return new (zone_) Property(zone_, obj, key, pos); | 3372 return new (zone_) Property(zone_, obj, key, pos); |
3416 } | 3373 } |
3417 | 3374 |
3418 Call* NewCall(Expression* expression, | 3375 Call* NewCall(Expression* expression, |
3419 ZoneList<Expression*>* arguments, | 3376 ZoneList<Expression*>* arguments, |
3420 int pos) { | 3377 int pos) { |
3421 return new (zone_) Call(zone_, expression, arguments, pos); | 3378 return new (zone_) Call(zone_, expression, arguments, pos); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3538 | 3495 |
3539 private: | 3496 private: |
3540 Zone* zone_; | 3497 Zone* zone_; |
3541 AstValueFactory* ast_value_factory_; | 3498 AstValueFactory* ast_value_factory_; |
3542 }; | 3499 }; |
3543 | 3500 |
3544 | 3501 |
3545 } } // namespace v8::internal | 3502 } } // namespace v8::internal |
3546 | 3503 |
3547 #endif // V8_AST_H_ | 3504 #endif // V8_AST_H_ |
OLD | NEW |