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() { return requires_class_field_init_; } | |
2627 void set_requires_class_field_init(bool requires_class_field_init) { | |
2628 requires_class_field_init_ = requires_class_field_init; | |
2629 } | |
2630 bool is_class_field_initializer() { return is_class_field_initializer_; } | |
2631 void set_is_class_field_initializer(bool is_class_field_initializer) { | |
2632 is_class_field_initializer_ = is_class_field_initializer; | |
2633 } | |
2634 | |
2626 private: | 2635 private: |
2627 friend class AstNodeFactory; | 2636 friend class AstNodeFactory; |
2628 | 2637 |
2629 FunctionLiteral(Zone* zone, const AstString* name, | 2638 FunctionLiteral(Zone* zone, const AstString* name, |
2630 AstValueFactory* ast_value_factory, DeclarationScope* scope, | 2639 AstValueFactory* ast_value_factory, DeclarationScope* scope, |
2631 ZoneList<Statement*>* body, int materialized_literal_count, | 2640 ZoneList<Statement*>* body, int materialized_literal_count, |
2632 int expected_property_count, int parameter_count, | 2641 int expected_property_count, int parameter_count, |
2633 FunctionType function_type, | 2642 FunctionType function_type, |
2634 ParameterFlag has_duplicate_parameters, | 2643 ParameterFlag has_duplicate_parameters, |
2635 EagerCompileHint eager_compile_hint, FunctionKind kind, | 2644 EagerCompileHint eager_compile_hint, FunctionKind kind, |
2636 int position, bool is_function) | 2645 int position, bool is_function) |
2637 : Expression(position, kFunctionLiteral), | 2646 : Expression(position, kFunctionLiteral), |
2638 dont_optimize_reason_(kNoReason), | 2647 dont_optimize_reason_(kNoReason), |
2639 materialized_literal_count_(materialized_literal_count), | 2648 materialized_literal_count_(materialized_literal_count), |
2640 expected_property_count_(expected_property_count), | 2649 expected_property_count_(expected_property_count), |
2641 parameter_count_(parameter_count), | 2650 parameter_count_(parameter_count), |
2642 function_token_position_(kNoSourcePosition), | 2651 function_token_position_(kNoSourcePosition), |
2643 yield_count_(0), | 2652 yield_count_(0), |
2644 raw_name_(name), | 2653 raw_name_(name), |
2645 scope_(scope), | 2654 scope_(scope), |
2646 body_(body), | 2655 body_(body), |
2647 raw_inferred_name_(ast_value_factory->empty_string()), | 2656 raw_inferred_name_(ast_value_factory->empty_string()), |
2648 ast_properties_(zone) { | 2657 ast_properties_(zone), |
2658 requires_class_field_init_(false), | |
2659 is_class_field_initializer_(false) { | |
2649 bitfield_ = | 2660 bitfield_ = |
2650 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | | 2661 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | |
2651 HasDuplicateParameters::encode(has_duplicate_parameters == | 2662 HasDuplicateParameters::encode(has_duplicate_parameters == |
2652 kHasDuplicateParameters) | | 2663 kHasDuplicateParameters) | |
2653 IsFunction::encode(is_function) | | 2664 IsFunction::encode(is_function) | |
2654 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | | 2665 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | |
2655 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false); | 2666 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false); |
2656 DCHECK(IsValidFunctionKind(kind)); | 2667 DCHECK(IsValidFunctionKind(kind)); |
2657 } | 2668 } |
2658 | 2669 |
(...skipping 16 matching lines...) Expand all Loading... | |
2675 int parameter_count_; | 2686 int parameter_count_; |
2676 int function_token_position_; | 2687 int function_token_position_; |
2677 int yield_count_; | 2688 int yield_count_; |
2678 | 2689 |
2679 const AstString* raw_name_; | 2690 const AstString* raw_name_; |
2680 DeclarationScope* scope_; | 2691 DeclarationScope* scope_; |
2681 ZoneList<Statement*>* body_; | 2692 ZoneList<Statement*>* body_; |
2682 const AstString* raw_inferred_name_; | 2693 const AstString* raw_inferred_name_; |
2683 Handle<String> inferred_name_; | 2694 Handle<String> inferred_name_; |
2684 AstProperties ast_properties_; | 2695 AstProperties ast_properties_; |
2696 | |
2697 bool requires_class_field_init_; // TODO(bakkot) this should be a bitfield | |
2698 bool is_class_field_initializer_; // TODO(bakkot) this should be a bitfield | |
Dan Ehrenberg
2016/09/06 23:55:59
As we discussed offline, it'd be nice to find thes
bakkot
2016/09/07 19:30:12
I ended up just expanding the bitfield in Function
| |
2685 }; | 2699 }; |
2686 | 2700 |
2687 // Property is used for passing information | 2701 // Property is used for passing information |
2688 // about a class literal's properties from the parser to the code generator. | 2702 // about a class literal's properties from the parser to the code generator. |
2689 class ClassLiteralProperty final : public LiteralProperty { | 2703 class ClassLiteralProperty final : public LiteralProperty { |
2690 public: | 2704 public: |
2691 enum Kind : uint8_t { METHOD, GETTER, SETTER }; | 2705 enum Kind : uint8_t { METHOD, GETTER, SETTER, FIELD }; |
2692 | 2706 |
2693 Kind kind() const { return kind_; } | 2707 Kind kind() const { return kind_; } |
2694 | 2708 |
2695 bool is_static() const { return is_static_; } | 2709 bool is_static() const { return is_static_; } |
2696 | 2710 |
2697 private: | 2711 private: |
2698 friend class AstNodeFactory; | 2712 friend class AstNodeFactory; |
2699 | 2713 |
2700 ClassLiteralProperty(Expression* key, Expression* value, Kind kind, | 2714 ClassLiteralProperty(Expression* key, Expression* value, Kind kind, |
2701 bool is_static, bool is_computed_name); | 2715 bool is_static, bool is_computed_name); |
2702 | 2716 |
2703 Kind kind_; | 2717 Kind kind_; |
2704 bool is_static_; | 2718 bool is_static_; |
2705 }; | 2719 }; |
2706 | 2720 |
2707 class ClassLiteral final : public Expression { | 2721 class ClassLiteral final : public Expression { |
2708 public: | 2722 public: |
2709 typedef ClassLiteralProperty Property; | 2723 typedef ClassLiteralProperty Property; |
2710 | 2724 |
2711 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } | 2725 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } |
2712 Expression* extends() const { return extends_; } | 2726 Expression* extends() const { return extends_; } |
2713 void set_extends(Expression* e) { extends_ = e; } | 2727 void set_extends(Expression* e) { extends_ = e; } |
2714 FunctionLiteral* constructor() const { return constructor_; } | 2728 FunctionLiteral* constructor() const { return constructor_; } |
2715 void set_constructor(FunctionLiteral* f) { constructor_ = f; } | 2729 void set_constructor(FunctionLiteral* f) { constructor_ = f; } |
2716 ZoneList<Property*>* properties() const { return properties_; } | 2730 ZoneList<Property*>* properties() const { return properties_; } |
2717 int start_position() const { return position(); } | 2731 int start_position() const { return position(); } |
2718 int end_position() const { return end_position_; } | 2732 int end_position() const { return end_position_; } |
2719 | 2733 |
2734 VariableProxy* static_initializer_proxy() const { | |
2735 return static_initializer_proxy_; | |
2736 } | |
2737 void set_static_initializer_proxy(VariableProxy* proxy) { | |
2738 static_initializer_proxy_ = proxy; | |
2739 } | |
2740 | |
2720 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 2741 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
2721 BailoutId PrototypeId() { return BailoutId(local_id(1)); } | 2742 BailoutId PrototypeId() { return BailoutId(local_id(1)); } |
2722 | 2743 |
2723 // Return an AST id for a property that is used in simulate instructions. | 2744 // Return an AST id for a property that is used in simulate instructions. |
2724 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 2)); } | 2745 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 2)); } |
2725 | 2746 |
2726 // Unlike other AST nodes, this number of bailout IDs allocated for an | 2747 // Unlike other AST nodes, this number of bailout IDs allocated for an |
2727 // ClassLiteral can vary, so num_ids() is not a static method. | 2748 // ClassLiteral can vary, so num_ids() is not a static method. |
2728 int num_ids() const { return parent_num_ids() + 2 + properties()->length(); } | 2749 int num_ids() const { return parent_num_ids() + 2 + properties()->length(); } |
2729 | 2750 |
(...skipping 14 matching lines...) Expand all Loading... | |
2744 friend class AstNodeFactory; | 2765 friend class AstNodeFactory; |
2745 | 2766 |
2746 ClassLiteral(VariableProxy* class_variable_proxy, Expression* extends, | 2767 ClassLiteral(VariableProxy* class_variable_proxy, Expression* extends, |
2747 FunctionLiteral* constructor, ZoneList<Property*>* properties, | 2768 FunctionLiteral* constructor, ZoneList<Property*>* properties, |
2748 int start_position, int end_position) | 2769 int start_position, int end_position) |
2749 : Expression(start_position, kClassLiteral), | 2770 : Expression(start_position, kClassLiteral), |
2750 end_position_(end_position), | 2771 end_position_(end_position), |
2751 class_variable_proxy_(class_variable_proxy), | 2772 class_variable_proxy_(class_variable_proxy), |
2752 extends_(extends), | 2773 extends_(extends), |
2753 constructor_(constructor), | 2774 constructor_(constructor), |
2754 properties_(properties) {} | 2775 properties_(properties), |
2776 static_initializer_proxy_(nullptr) {} | |
2755 | 2777 |
2756 static int parent_num_ids() { return Expression::num_ids(); } | 2778 static int parent_num_ids() { return Expression::num_ids(); } |
2757 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2779 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
2758 | 2780 |
2759 int end_position_; | 2781 int end_position_; |
2760 FeedbackVectorSlot prototype_slot_; | 2782 FeedbackVectorSlot prototype_slot_; |
2761 FeedbackVectorSlot proxy_slot_; | 2783 FeedbackVectorSlot proxy_slot_; |
2762 VariableProxy* class_variable_proxy_; | 2784 VariableProxy* class_variable_proxy_; |
2763 Expression* extends_; | 2785 Expression* extends_; |
2764 FunctionLiteral* constructor_; | 2786 FunctionLiteral* constructor_; |
2765 ZoneList<Property*>* properties_; | 2787 ZoneList<Property*>* properties_; |
2788 VariableProxy* static_initializer_proxy_; // TODO(bakkot) initialize inline | |
Dan Ehrenberg
2016/09/06 23:55:59
What do you mean by this TODO?
bakkot
2016/09/07 19:30:12
Sorry, that's stale. I was originally going to hav
| |
2766 }; | 2789 }; |
2767 | 2790 |
2768 | 2791 |
2769 class NativeFunctionLiteral final : public Expression { | 2792 class NativeFunctionLiteral final : public Expression { |
2770 public: | 2793 public: |
2771 Handle<String> name() const { return name_->string(); } | 2794 Handle<String> name() const { return name_->string(); } |
2772 v8::Extension* extension() const { return extension_; } | 2795 v8::Extension* extension() const { return extension_; } |
2773 | 2796 |
2774 private: | 2797 private: |
2775 friend class AstNodeFactory; | 2798 friend class AstNodeFactory; |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3495 : NULL; \ | 3518 : NULL; \ |
3496 } | 3519 } |
3497 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3520 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3498 #undef DECLARE_NODE_FUNCTIONS | 3521 #undef DECLARE_NODE_FUNCTIONS |
3499 | 3522 |
3500 | 3523 |
3501 } // namespace internal | 3524 } // namespace internal |
3502 } // namespace v8 | 3525 } // namespace v8 |
3503 | 3526 |
3504 #endif // V8_AST_AST_H_ | 3527 #endif // V8_AST_AST_H_ |
OLD | NEW |