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 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 | 2565 |
2566 class FunctionLiteral final : public Expression { | 2566 class FunctionLiteral final : public Expression { |
2567 public: | 2567 public: |
2568 enum FunctionType { | 2568 enum FunctionType { |
2569 kAnonymousExpression, | 2569 kAnonymousExpression, |
2570 kNamedExpression, | 2570 kNamedExpression, |
2571 kDeclaration, | 2571 kDeclaration, |
2572 kAccessorOrMethod | 2572 kAccessorOrMethod |
2573 }; | 2573 }; |
2574 | 2574 |
| 2575 enum IdType { kIdTypeInvalid = -1, kIdTypeTopLevel = 0 }; |
| 2576 |
2575 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters }; | 2577 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters }; |
2576 | 2578 |
2577 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; | 2579 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; |
2578 | 2580 |
2579 Handle<String> name() const { return raw_name_->string(); } | 2581 Handle<String> name() const { return raw_name_->string(); } |
2580 const AstString* raw_name() const { return raw_name_; } | 2582 const AstString* raw_name() const { return raw_name_; } |
2581 void set_raw_name(const AstString* name) { raw_name_ = name; } | 2583 void set_raw_name(const AstString* name) { raw_name_ = name; } |
2582 DeclarationScope* scope() const { return scope_; } | 2584 DeclarationScope* scope() const { return scope_; } |
2583 ZoneList<Statement*>* body() const { return body_; } | 2585 ZoneList<Statement*>* body() const { return body_; } |
2584 void set_function_token_position(int pos) { function_token_position_ = pos; } | 2586 void set_function_token_position(int pos) { function_token_position_ = pos; } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2704 } | 2706 } |
2705 void set_is_class_field_initializer(bool is_class_field_initializer) { | 2707 void set_is_class_field_initializer(bool is_class_field_initializer) { |
2706 bit_field_ = | 2708 bit_field_ = |
2707 IsClassFieldInitializer::update(bit_field_, is_class_field_initializer); | 2709 IsClassFieldInitializer::update(bit_field_, is_class_field_initializer); |
2708 } | 2710 } |
2709 | 2711 |
2710 int return_position() { | 2712 int return_position() { |
2711 return std::max(start_position(), end_position() - (has_braces_ ? 1 : 0)); | 2713 return std::max(start_position(), end_position() - (has_braces_ ? 1 : 0)); |
2712 } | 2714 } |
2713 | 2715 |
| 2716 int function_literal_id() const { return function_literal_id_; } |
| 2717 void set_function_literal_id(int function_literal_id) { |
| 2718 function_literal_id_ = function_literal_id; |
| 2719 } |
| 2720 |
2714 private: | 2721 private: |
2715 friend class AstNodeFactory; | 2722 friend class AstNodeFactory; |
2716 | 2723 |
2717 FunctionLiteral(Zone* zone, const AstString* name, | 2724 FunctionLiteral(Zone* zone, const AstString* name, |
2718 AstValueFactory* ast_value_factory, DeclarationScope* scope, | 2725 AstValueFactory* ast_value_factory, DeclarationScope* scope, |
2719 ZoneList<Statement*>* body, int materialized_literal_count, | 2726 ZoneList<Statement*>* body, int materialized_literal_count, |
2720 int expected_property_count, int parameter_count, | 2727 int expected_property_count, int parameter_count, |
2721 int function_length, FunctionType function_type, | 2728 int function_length, FunctionType function_type, |
2722 ParameterFlag has_duplicate_parameters, | 2729 ParameterFlag has_duplicate_parameters, |
2723 EagerCompileHint eager_compile_hint, int position, | 2730 EagerCompileHint eager_compile_hint, int position, |
2724 bool is_function, bool has_braces) | 2731 bool is_function, bool has_braces, int function_literal_id) |
2725 : Expression(position, kFunctionLiteral), | 2732 : Expression(position, kFunctionLiteral), |
2726 materialized_literal_count_(materialized_literal_count), | 2733 materialized_literal_count_(materialized_literal_count), |
2727 expected_property_count_(expected_property_count), | 2734 expected_property_count_(expected_property_count), |
2728 parameter_count_(parameter_count), | 2735 parameter_count_(parameter_count), |
2729 function_length_(function_length), | 2736 function_length_(function_length), |
2730 function_token_position_(kNoSourcePosition), | 2737 function_token_position_(kNoSourcePosition), |
2731 yield_count_(0), | 2738 yield_count_(0), |
2732 has_braces_(has_braces), | 2739 has_braces_(has_braces), |
2733 raw_name_(name), | 2740 raw_name_(name), |
2734 scope_(scope), | 2741 scope_(scope), |
2735 body_(body), | 2742 body_(body), |
2736 raw_inferred_name_(ast_value_factory->empty_string()), | 2743 raw_inferred_name_(ast_value_factory->empty_string()), |
2737 ast_properties_(zone) { | 2744 ast_properties_(zone), |
| 2745 function_literal_id_(function_literal_id) { |
2738 bit_field_ |= | 2746 bit_field_ |= |
2739 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | | 2747 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | |
2740 HasDuplicateParameters::encode(has_duplicate_parameters == | 2748 HasDuplicateParameters::encode(has_duplicate_parameters == |
2741 kHasDuplicateParameters) | | 2749 kHasDuplicateParameters) | |
2742 IsFunction::encode(is_function) | | 2750 IsFunction::encode(is_function) | |
2743 RequiresClassFieldInit::encode(false) | | 2751 RequiresClassFieldInit::encode(false) | |
2744 ShouldNotBeUsedOnceHintField::encode(false) | | 2752 ShouldNotBeUsedOnceHintField::encode(false) | |
2745 DontOptimizeReasonField::encode(kNoReason) | | 2753 DontOptimizeReasonField::encode(kNoReason) | |
2746 IsClassFieldInitializer::encode(false); | 2754 IsClassFieldInitializer::encode(false); |
2747 if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile(); | 2755 if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile(); |
(...skipping 20 matching lines...) Expand all Loading... |
2768 int function_token_position_; | 2776 int function_token_position_; |
2769 int yield_count_; | 2777 int yield_count_; |
2770 bool has_braces_; | 2778 bool has_braces_; |
2771 | 2779 |
2772 const AstString* raw_name_; | 2780 const AstString* raw_name_; |
2773 DeclarationScope* scope_; | 2781 DeclarationScope* scope_; |
2774 ZoneList<Statement*>* body_; | 2782 ZoneList<Statement*>* body_; |
2775 const AstString* raw_inferred_name_; | 2783 const AstString* raw_inferred_name_; |
2776 Handle<String> inferred_name_; | 2784 Handle<String> inferred_name_; |
2777 AstProperties ast_properties_; | 2785 AstProperties ast_properties_; |
| 2786 int function_literal_id_; |
2778 }; | 2787 }; |
2779 | 2788 |
2780 // Property is used for passing information | 2789 // Property is used for passing information |
2781 // about a class literal's properties from the parser to the code generator. | 2790 // about a class literal's properties from the parser to the code generator. |
2782 class ClassLiteralProperty final : public LiteralProperty { | 2791 class ClassLiteralProperty final : public LiteralProperty { |
2783 public: | 2792 public: |
2784 enum Kind : uint8_t { METHOD, GETTER, SETTER, FIELD }; | 2793 enum Kind : uint8_t { METHOD, GETTER, SETTER, FIELD }; |
2785 | 2794 |
2786 Kind kind() const { return kind_; } | 2795 Kind kind() const { return kind_; } |
2787 | 2796 |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3457 return new (zone_) Throw(exception, pos); | 3466 return new (zone_) Throw(exception, pos); |
3458 } | 3467 } |
3459 | 3468 |
3460 FunctionLiteral* NewFunctionLiteral( | 3469 FunctionLiteral* NewFunctionLiteral( |
3461 const AstRawString* name, DeclarationScope* scope, | 3470 const AstRawString* name, DeclarationScope* scope, |
3462 ZoneList<Statement*>* body, int materialized_literal_count, | 3471 ZoneList<Statement*>* body, int materialized_literal_count, |
3463 int expected_property_count, int parameter_count, int function_length, | 3472 int expected_property_count, int parameter_count, int function_length, |
3464 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3473 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3465 FunctionLiteral::FunctionType function_type, | 3474 FunctionLiteral::FunctionType function_type, |
3466 FunctionLiteral::EagerCompileHint eager_compile_hint, int position, | 3475 FunctionLiteral::EagerCompileHint eager_compile_hint, int position, |
3467 bool has_braces) { | 3476 bool has_braces, int function_literal_id) { |
3468 return new (zone_) FunctionLiteral( | 3477 return new (zone_) FunctionLiteral( |
3469 zone_, name, ast_value_factory_, scope, body, | 3478 zone_, name, ast_value_factory_, scope, body, |
3470 materialized_literal_count, expected_property_count, parameter_count, | 3479 materialized_literal_count, expected_property_count, parameter_count, |
3471 function_length, function_type, has_duplicate_parameters, | 3480 function_length, function_type, has_duplicate_parameters, |
3472 eager_compile_hint, position, true, has_braces); | 3481 eager_compile_hint, position, true, has_braces, function_literal_id); |
3473 } | 3482 } |
3474 | 3483 |
3475 // Creates a FunctionLiteral representing a top-level script, the | 3484 // Creates a FunctionLiteral representing a top-level script, the |
3476 // result of an eval (top-level or otherwise), or the result of calling | 3485 // result of an eval (top-level or otherwise), or the result of calling |
3477 // the Function constructor. | 3486 // the Function constructor. |
3478 FunctionLiteral* NewScriptOrEvalFunctionLiteral( | 3487 FunctionLiteral* NewScriptOrEvalFunctionLiteral( |
3479 DeclarationScope* scope, ZoneList<Statement*>* body, | 3488 DeclarationScope* scope, ZoneList<Statement*>* body, |
3480 int materialized_literal_count, int expected_property_count, | 3489 int materialized_literal_count, int expected_property_count, |
3481 int parameter_count) { | 3490 int parameter_count) { |
3482 return new (zone_) FunctionLiteral( | 3491 return new (zone_) FunctionLiteral( |
3483 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, | 3492 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, |
3484 body, materialized_literal_count, expected_property_count, | 3493 body, materialized_literal_count, expected_property_count, |
3485 parameter_count, parameter_count, FunctionLiteral::kAnonymousExpression, | 3494 parameter_count, parameter_count, FunctionLiteral::kAnonymousExpression, |
3486 FunctionLiteral::kNoDuplicateParameters, | 3495 FunctionLiteral::kNoDuplicateParameters, |
3487 FunctionLiteral::kShouldLazyCompile, 0, false, true); | 3496 FunctionLiteral::kShouldLazyCompile, 0, false, true, |
| 3497 FunctionLiteral::kIdTypeTopLevel); |
3488 } | 3498 } |
3489 | 3499 |
3490 ClassLiteral::Property* NewClassLiteralProperty( | 3500 ClassLiteral::Property* NewClassLiteralProperty( |
3491 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, | 3501 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, |
3492 bool is_static, bool is_computed_name) { | 3502 bool is_static, bool is_computed_name) { |
3493 return new (zone_) | 3503 return new (zone_) |
3494 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); | 3504 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); |
3495 } | 3505 } |
3496 | 3506 |
3497 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, | 3507 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3603 : NULL; \ | 3613 : NULL; \ |
3604 } | 3614 } |
3605 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3615 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3606 #undef DECLARE_NODE_FUNCTIONS | 3616 #undef DECLARE_NODE_FUNCTIONS |
3607 | 3617 |
3608 | 3618 |
3609 } // namespace internal | 3619 } // namespace internal |
3610 } // namespace v8 | 3620 } // namespace v8 |
3611 | 3621 |
3612 #endif // V8_AST_AST_H_ | 3622 #endif // V8_AST_AST_H_ |
OLD | NEW |