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-types.h" | 8 #include "src/ast/ast-types.h" |
9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
(...skipping 2605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 dont_optimize_reason_ = reason; | 2616 dont_optimize_reason_ = reason; |
2617 } | 2617 } |
2618 | 2618 |
2619 bool IsAnonymousFunctionDefinition() const { | 2619 bool IsAnonymousFunctionDefinition() const { |
2620 return is_anonymous_expression(); | 2620 return is_anonymous_expression(); |
2621 } | 2621 } |
2622 | 2622 |
2623 int yield_count() { return yield_count_; } | 2623 int yield_count() { return yield_count_; } |
2624 void set_yield_count(int yield_count) { yield_count_ = yield_count; } | 2624 void set_yield_count(int yield_count) { yield_count_ = yield_count; } |
2625 | 2625 |
| 2626 bool requires_class_field_init() { |
| 2627 return RequiresClassFieldInit::decode(bitfield_); |
| 2628 } |
| 2629 void set_requires_class_field_init(bool requires_class_field_init) { |
| 2630 bitfield_ = |
| 2631 RequiresClassFieldInit::update(bitfield_, requires_class_field_init); |
| 2632 } |
| 2633 bool is_class_field_initializer() { |
| 2634 return IsClassFieldInitializer::decode(bitfield_); |
| 2635 } |
| 2636 void set_is_class_field_initializer(bool is_class_field_initializer) { |
| 2637 bitfield_ = |
| 2638 IsClassFieldInitializer::update(bitfield_, is_class_field_initializer); |
| 2639 } |
| 2640 |
2626 private: | 2641 private: |
2627 friend class AstNodeFactory; | 2642 friend class AstNodeFactory; |
2628 | 2643 |
2629 FunctionLiteral(Zone* zone, const AstString* name, | 2644 FunctionLiteral(Zone* zone, const AstString* name, |
2630 AstValueFactory* ast_value_factory, DeclarationScope* scope, | 2645 AstValueFactory* ast_value_factory, DeclarationScope* scope, |
2631 ZoneList<Statement*>* body, int materialized_literal_count, | 2646 ZoneList<Statement*>* body, int materialized_literal_count, |
2632 int expected_property_count, int parameter_count, | 2647 int expected_property_count, int parameter_count, |
2633 FunctionType function_type, | 2648 FunctionType function_type, |
2634 ParameterFlag has_duplicate_parameters, | 2649 ParameterFlag has_duplicate_parameters, |
2635 EagerCompileHint eager_compile_hint, FunctionKind kind, | 2650 EagerCompileHint eager_compile_hint, FunctionKind kind, |
2636 int position, bool is_function) | 2651 int position, bool is_function) |
2637 : Expression(position, kFunctionLiteral), | 2652 : Expression(position, kFunctionLiteral), |
2638 dont_optimize_reason_(kNoReason), | 2653 dont_optimize_reason_(kNoReason), |
2639 materialized_literal_count_(materialized_literal_count), | 2654 materialized_literal_count_(materialized_literal_count), |
2640 expected_property_count_(expected_property_count), | 2655 expected_property_count_(expected_property_count), |
2641 parameter_count_(parameter_count), | 2656 parameter_count_(parameter_count), |
2642 function_token_position_(kNoSourcePosition), | 2657 function_token_position_(kNoSourcePosition), |
2643 yield_count_(0), | 2658 yield_count_(0), |
2644 raw_name_(name), | 2659 raw_name_(name), |
2645 scope_(scope), | 2660 scope_(scope), |
2646 body_(body), | 2661 body_(body), |
2647 raw_inferred_name_(ast_value_factory->empty_string()), | 2662 raw_inferred_name_(ast_value_factory->empty_string()), |
2648 ast_properties_(zone) { | 2663 ast_properties_(zone) { |
2649 bitfield_ = | 2664 bitfield_ = |
2650 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | | 2665 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | |
2651 HasDuplicateParameters::encode(has_duplicate_parameters == | 2666 HasDuplicateParameters::encode(has_duplicate_parameters == |
2652 kHasDuplicateParameters) | | 2667 kHasDuplicateParameters) | |
2653 IsFunction::encode(is_function) | | 2668 IsFunction::encode(is_function) | |
2654 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | | 2669 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | |
| 2670 RequiresClassFieldInit::encode(false) | |
| 2671 IsClassFieldInitializer::encode(false) | |
2655 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false); | 2672 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false); |
2656 DCHECK(IsValidFunctionKind(kind)); | 2673 DCHECK(IsValidFunctionKind(kind)); |
2657 } | 2674 } |
2658 | 2675 |
2659 class FunctionTypeBits : public BitField16<FunctionType, 0, 2> {}; | 2676 class FunctionTypeBits : public BitField<FunctionType, 0, 2> {}; |
2660 class Pretenure : public BitField16<bool, 2, 1> {}; | 2677 class Pretenure : public BitField<bool, 2, 1> {}; |
2661 class HasDuplicateParameters : public BitField16<bool, 3, 1> {}; | 2678 class HasDuplicateParameters : public BitField<bool, 3, 1> {}; |
2662 class IsFunction : public BitField16<bool, 4, 1> {}; | 2679 class IsFunction : public BitField<bool, 4, 1> {}; |
2663 class ShouldEagerCompile : public BitField16<bool, 5, 1> {}; | 2680 class ShouldEagerCompile : public BitField<bool, 5, 1> {}; |
2664 class ShouldBeUsedOnceHint : public BitField16<bool, 6, 1> {}; | 2681 class ShouldBeUsedOnceHint : public BitField<bool, 6, 1> {}; |
2665 class FunctionKindBits : public BitField16<FunctionKind, 7, 9> {}; | 2682 class RequiresClassFieldInit : public BitField<bool, 7, 1> {}; |
| 2683 class IsClassFieldInitializer : public BitField<bool, 8, 1> {}; |
| 2684 class FunctionKindBits : public BitField<FunctionKind, 9, 9> {}; |
2666 | 2685 |
2667 // Start with 16-bit field, which should get packed together | 2686 uint32_t bitfield_; |
2668 // with Expression's trailing 16-bit field. | |
2669 uint16_t bitfield_; | |
2670 | 2687 |
2671 BailoutReason dont_optimize_reason_; | 2688 BailoutReason dont_optimize_reason_; |
2672 | 2689 |
2673 int materialized_literal_count_; | 2690 int materialized_literal_count_; |
2674 int expected_property_count_; | 2691 int expected_property_count_; |
2675 int parameter_count_; | 2692 int parameter_count_; |
2676 int function_token_position_; | 2693 int function_token_position_; |
2677 int yield_count_; | 2694 int yield_count_; |
2678 | 2695 |
2679 const AstString* raw_name_; | 2696 const AstString* raw_name_; |
2680 DeclarationScope* scope_; | 2697 DeclarationScope* scope_; |
2681 ZoneList<Statement*>* body_; | 2698 ZoneList<Statement*>* body_; |
2682 const AstString* raw_inferred_name_; | 2699 const AstString* raw_inferred_name_; |
2683 Handle<String> inferred_name_; | 2700 Handle<String> inferred_name_; |
2684 AstProperties ast_properties_; | 2701 AstProperties ast_properties_; |
2685 }; | 2702 }; |
2686 | 2703 |
2687 // Property is used for passing information | 2704 // Property is used for passing information |
2688 // about a class literal's properties from the parser to the code generator. | 2705 // about a class literal's properties from the parser to the code generator. |
2689 class ClassLiteralProperty final : public LiteralProperty { | 2706 class ClassLiteralProperty final : public LiteralProperty { |
2690 public: | 2707 public: |
2691 enum Kind : uint8_t { METHOD, GETTER, SETTER }; | 2708 enum Kind : uint8_t { METHOD, GETTER, SETTER, FIELD }; |
2692 | 2709 |
2693 Kind kind() const { return kind_; } | 2710 Kind kind() const { return kind_; } |
2694 | 2711 |
2695 bool is_static() const { return is_static_; } | 2712 bool is_static() const { return is_static_; } |
2696 | 2713 |
2697 private: | 2714 private: |
2698 friend class AstNodeFactory; | 2715 friend class AstNodeFactory; |
2699 | 2716 |
2700 ClassLiteralProperty(Expression* key, Expression* value, Kind kind, | 2717 ClassLiteralProperty(Expression* key, Expression* value, Kind kind, |
2701 bool is_static, bool is_computed_name); | 2718 bool is_static, bool is_computed_name); |
2702 | 2719 |
2703 Kind kind_; | 2720 Kind kind_; |
2704 bool is_static_; | 2721 bool is_static_; |
2705 }; | 2722 }; |
2706 | 2723 |
2707 class ClassLiteral final : public Expression { | 2724 class ClassLiteral final : public Expression { |
2708 public: | 2725 public: |
2709 typedef ClassLiteralProperty Property; | 2726 typedef ClassLiteralProperty Property; |
2710 | 2727 |
2711 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } | 2728 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } |
2712 Expression* extends() const { return extends_; } | 2729 Expression* extends() const { return extends_; } |
2713 void set_extends(Expression* e) { extends_ = e; } | 2730 void set_extends(Expression* e) { extends_ = e; } |
2714 FunctionLiteral* constructor() const { return constructor_; } | 2731 FunctionLiteral* constructor() const { return constructor_; } |
2715 void set_constructor(FunctionLiteral* f) { constructor_ = f; } | 2732 void set_constructor(FunctionLiteral* f) { constructor_ = f; } |
2716 ZoneList<Property*>* properties() const { return properties_; } | 2733 ZoneList<Property*>* properties() const { return properties_; } |
2717 int start_position() const { return position(); } | 2734 int start_position() const { return position(); } |
2718 int end_position() const { return end_position_; } | 2735 int end_position() const { return end_position_; } |
2719 | 2736 |
| 2737 VariableProxy* static_initializer_proxy() const { |
| 2738 return static_initializer_proxy_; |
| 2739 } |
| 2740 void set_static_initializer_proxy(VariableProxy* proxy) { |
| 2741 static_initializer_proxy_ = proxy; |
| 2742 } |
| 2743 |
2720 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 2744 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
2721 BailoutId PrototypeId() { return BailoutId(local_id(1)); } | 2745 BailoutId PrototypeId() { return BailoutId(local_id(1)); } |
2722 | 2746 |
2723 // Return an AST id for a property that is used in simulate instructions. | 2747 // Return an AST id for a property that is used in simulate instructions. |
2724 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 2)); } | 2748 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 2)); } |
2725 | 2749 |
2726 // Unlike other AST nodes, this number of bailout IDs allocated for an | 2750 // Unlike other AST nodes, this number of bailout IDs allocated for an |
2727 // ClassLiteral can vary, so num_ids() is not a static method. | 2751 // ClassLiteral can vary, so num_ids() is not a static method. |
2728 int num_ids() const { return parent_num_ids() + 2 + properties()->length(); } | 2752 int num_ids() const { return parent_num_ids() + 2 + properties()->length(); } |
2729 | 2753 |
(...skipping 14 matching lines...) Expand all Loading... |
2744 friend class AstNodeFactory; | 2768 friend class AstNodeFactory; |
2745 | 2769 |
2746 ClassLiteral(VariableProxy* class_variable_proxy, Expression* extends, | 2770 ClassLiteral(VariableProxy* class_variable_proxy, Expression* extends, |
2747 FunctionLiteral* constructor, ZoneList<Property*>* properties, | 2771 FunctionLiteral* constructor, ZoneList<Property*>* properties, |
2748 int start_position, int end_position) | 2772 int start_position, int end_position) |
2749 : Expression(start_position, kClassLiteral), | 2773 : Expression(start_position, kClassLiteral), |
2750 end_position_(end_position), | 2774 end_position_(end_position), |
2751 class_variable_proxy_(class_variable_proxy), | 2775 class_variable_proxy_(class_variable_proxy), |
2752 extends_(extends), | 2776 extends_(extends), |
2753 constructor_(constructor), | 2777 constructor_(constructor), |
2754 properties_(properties) {} | 2778 properties_(properties), |
| 2779 static_initializer_proxy_(nullptr) {} |
2755 | 2780 |
2756 static int parent_num_ids() { return Expression::num_ids(); } | 2781 static int parent_num_ids() { return Expression::num_ids(); } |
2757 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2782 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
2758 | 2783 |
2759 int end_position_; | 2784 int end_position_; |
2760 FeedbackVectorSlot prototype_slot_; | 2785 FeedbackVectorSlot prototype_slot_; |
2761 FeedbackVectorSlot proxy_slot_; | 2786 FeedbackVectorSlot proxy_slot_; |
2762 VariableProxy* class_variable_proxy_; | 2787 VariableProxy* class_variable_proxy_; |
2763 Expression* extends_; | 2788 Expression* extends_; |
2764 FunctionLiteral* constructor_; | 2789 FunctionLiteral* constructor_; |
2765 ZoneList<Property*>* properties_; | 2790 ZoneList<Property*>* properties_; |
| 2791 VariableProxy* static_initializer_proxy_; |
2766 }; | 2792 }; |
2767 | 2793 |
2768 | 2794 |
2769 class NativeFunctionLiteral final : public Expression { | 2795 class NativeFunctionLiteral final : public Expression { |
2770 public: | 2796 public: |
2771 Handle<String> name() const { return name_->string(); } | 2797 Handle<String> name() const { return name_->string(); } |
2772 v8::Extension* extension() const { return extension_; } | 2798 v8::Extension* extension() const { return extension_; } |
2773 | 2799 |
2774 private: | 2800 private: |
2775 friend class AstNodeFactory; | 2801 friend class AstNodeFactory; |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3495 : NULL; \ | 3521 : NULL; \ |
3496 } | 3522 } |
3497 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3523 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3498 #undef DECLARE_NODE_FUNCTIONS | 3524 #undef DECLARE_NODE_FUNCTIONS |
3499 | 3525 |
3500 | 3526 |
3501 } // namespace internal | 3527 } // namespace internal |
3502 } // namespace v8 | 3528 } // namespace v8 |
3503 | 3529 |
3504 #endif // V8_AST_AST_H_ | 3530 #endif // V8_AST_AST_H_ |
OLD | NEW |