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 2689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2700 RequiresClassFieldInit::update(bit_field_, requires_class_field_init); | 2700 RequiresClassFieldInit::update(bit_field_, requires_class_field_init); |
2701 } | 2701 } |
2702 bool is_class_field_initializer() { | 2702 bool is_class_field_initializer() { |
2703 return IsClassFieldInitializer::decode(bit_field_); | 2703 return IsClassFieldInitializer::decode(bit_field_); |
2704 } | 2704 } |
2705 void set_is_class_field_initializer(bool is_class_field_initializer) { | 2705 void set_is_class_field_initializer(bool is_class_field_initializer) { |
2706 bit_field_ = | 2706 bit_field_ = |
2707 IsClassFieldInitializer::update(bit_field_, is_class_field_initializer); | 2707 IsClassFieldInitializer::update(bit_field_, is_class_field_initializer); |
2708 } | 2708 } |
2709 | 2709 |
| 2710 int return_position() { |
| 2711 return std::max(start_position(), end_position() - (has_braces_ ? 1 : 0)); |
| 2712 } |
| 2713 |
2710 private: | 2714 private: |
2711 friend class AstNodeFactory; | 2715 friend class AstNodeFactory; |
2712 | 2716 |
2713 FunctionLiteral(Zone* zone, const AstString* name, | 2717 FunctionLiteral(Zone* zone, const AstString* name, |
2714 AstValueFactory* ast_value_factory, DeclarationScope* scope, | 2718 AstValueFactory* ast_value_factory, DeclarationScope* scope, |
2715 ZoneList<Statement*>* body, int materialized_literal_count, | 2719 ZoneList<Statement*>* body, int materialized_literal_count, |
2716 int expected_property_count, int parameter_count, | 2720 int expected_property_count, int parameter_count, |
2717 int function_length, FunctionType function_type, | 2721 int function_length, FunctionType function_type, |
2718 ParameterFlag has_duplicate_parameters, | 2722 ParameterFlag has_duplicate_parameters, |
2719 EagerCompileHint eager_compile_hint, int position, | 2723 EagerCompileHint eager_compile_hint, int position, |
2720 bool is_function) | 2724 bool is_function, bool has_braces) |
2721 : Expression(position, kFunctionLiteral), | 2725 : Expression(position, kFunctionLiteral), |
2722 materialized_literal_count_(materialized_literal_count), | 2726 materialized_literal_count_(materialized_literal_count), |
2723 expected_property_count_(expected_property_count), | 2727 expected_property_count_(expected_property_count), |
2724 parameter_count_(parameter_count), | 2728 parameter_count_(parameter_count), |
2725 function_length_(function_length), | 2729 function_length_(function_length), |
2726 function_token_position_(kNoSourcePosition), | 2730 function_token_position_(kNoSourcePosition), |
2727 yield_count_(0), | 2731 yield_count_(0), |
| 2732 has_braces_(has_braces), |
2728 raw_name_(name), | 2733 raw_name_(name), |
2729 scope_(scope), | 2734 scope_(scope), |
2730 body_(body), | 2735 body_(body), |
2731 raw_inferred_name_(ast_value_factory->empty_string()), | 2736 raw_inferred_name_(ast_value_factory->empty_string()), |
2732 ast_properties_(zone) { | 2737 ast_properties_(zone) { |
2733 bit_field_ |= | 2738 bit_field_ |= |
2734 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | | 2739 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | |
2735 HasDuplicateParameters::encode(has_duplicate_parameters == | 2740 HasDuplicateParameters::encode(has_duplicate_parameters == |
2736 kHasDuplicateParameters) | | 2741 kHasDuplicateParameters) | |
2737 IsFunction::encode(is_function) | | 2742 IsFunction::encode(is_function) | |
(...skipping 17 matching lines...) Expand all Loading... |
2755 : public BitField<bool, RequiresClassFieldInit::kNext, 1> {}; | 2760 : public BitField<bool, RequiresClassFieldInit::kNext, 1> {}; |
2756 class DontOptimizeReasonField | 2761 class DontOptimizeReasonField |
2757 : public BitField<BailoutReason, IsClassFieldInitializer::kNext, 8> {}; | 2762 : public BitField<BailoutReason, IsClassFieldInitializer::kNext, 8> {}; |
2758 | 2763 |
2759 int materialized_literal_count_; | 2764 int materialized_literal_count_; |
2760 int expected_property_count_; | 2765 int expected_property_count_; |
2761 int parameter_count_; | 2766 int parameter_count_; |
2762 int function_length_; | 2767 int function_length_; |
2763 int function_token_position_; | 2768 int function_token_position_; |
2764 int yield_count_; | 2769 int yield_count_; |
| 2770 bool has_braces_; |
2765 | 2771 |
2766 const AstString* raw_name_; | 2772 const AstString* raw_name_; |
2767 DeclarationScope* scope_; | 2773 DeclarationScope* scope_; |
2768 ZoneList<Statement*>* body_; | 2774 ZoneList<Statement*>* body_; |
2769 const AstString* raw_inferred_name_; | 2775 const AstString* raw_inferred_name_; |
2770 Handle<String> inferred_name_; | 2776 Handle<String> inferred_name_; |
2771 AstProperties ast_properties_; | 2777 AstProperties ast_properties_; |
2772 }; | 2778 }; |
2773 | 2779 |
2774 // Property is used for passing information | 2780 // Property is used for passing information |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3450 Throw* NewThrow(Expression* exception, int pos) { | 3456 Throw* NewThrow(Expression* exception, int pos) { |
3451 return new (zone_) Throw(exception, pos); | 3457 return new (zone_) Throw(exception, pos); |
3452 } | 3458 } |
3453 | 3459 |
3454 FunctionLiteral* NewFunctionLiteral( | 3460 FunctionLiteral* NewFunctionLiteral( |
3455 const AstRawString* name, DeclarationScope* scope, | 3461 const AstRawString* name, DeclarationScope* scope, |
3456 ZoneList<Statement*>* body, int materialized_literal_count, | 3462 ZoneList<Statement*>* body, int materialized_literal_count, |
3457 int expected_property_count, int parameter_count, int function_length, | 3463 int expected_property_count, int parameter_count, int function_length, |
3458 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3464 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3459 FunctionLiteral::FunctionType function_type, | 3465 FunctionLiteral::FunctionType function_type, |
3460 FunctionLiteral::EagerCompileHint eager_compile_hint, int position) { | 3466 FunctionLiteral::EagerCompileHint eager_compile_hint, int position, |
| 3467 bool has_braces) { |
3461 return new (zone_) FunctionLiteral( | 3468 return new (zone_) FunctionLiteral( |
3462 zone_, name, ast_value_factory_, scope, body, | 3469 zone_, name, ast_value_factory_, scope, body, |
3463 materialized_literal_count, expected_property_count, parameter_count, | 3470 materialized_literal_count, expected_property_count, parameter_count, |
3464 function_length, function_type, has_duplicate_parameters, | 3471 function_length, function_type, has_duplicate_parameters, |
3465 eager_compile_hint, position, true); | 3472 eager_compile_hint, position, true, has_braces); |
3466 } | 3473 } |
3467 | 3474 |
3468 // Creates a FunctionLiteral representing a top-level script, the | 3475 // Creates a FunctionLiteral representing a top-level script, the |
3469 // result of an eval (top-level or otherwise), or the result of calling | 3476 // result of an eval (top-level or otherwise), or the result of calling |
3470 // the Function constructor. | 3477 // the Function constructor. |
3471 FunctionLiteral* NewScriptOrEvalFunctionLiteral( | 3478 FunctionLiteral* NewScriptOrEvalFunctionLiteral( |
3472 DeclarationScope* scope, ZoneList<Statement*>* body, | 3479 DeclarationScope* scope, ZoneList<Statement*>* body, |
3473 int materialized_literal_count, int expected_property_count, | 3480 int materialized_literal_count, int expected_property_count, |
3474 int parameter_count) { | 3481 int parameter_count) { |
3475 return new (zone_) FunctionLiteral( | 3482 return new (zone_) FunctionLiteral( |
3476 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, | 3483 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, |
3477 body, materialized_literal_count, expected_property_count, | 3484 body, materialized_literal_count, expected_property_count, |
3478 parameter_count, parameter_count, FunctionLiteral::kAnonymousExpression, | 3485 parameter_count, parameter_count, FunctionLiteral::kAnonymousExpression, |
3479 FunctionLiteral::kNoDuplicateParameters, | 3486 FunctionLiteral::kNoDuplicateParameters, |
3480 FunctionLiteral::kShouldLazyCompile, 0, false); | 3487 FunctionLiteral::kShouldLazyCompile, 0, false, true); |
3481 } | 3488 } |
3482 | 3489 |
3483 ClassLiteral::Property* NewClassLiteralProperty( | 3490 ClassLiteral::Property* NewClassLiteralProperty( |
3484 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, | 3491 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, |
3485 bool is_static, bool is_computed_name) { | 3492 bool is_static, bool is_computed_name) { |
3486 return new (zone_) | 3493 return new (zone_) |
3487 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); | 3494 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); |
3488 } | 3495 } |
3489 | 3496 |
3490 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, | 3497 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3596 : NULL; \ | 3603 : NULL; \ |
3597 } | 3604 } |
3598 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3605 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3599 #undef DECLARE_NODE_FUNCTIONS | 3606 #undef DECLARE_NODE_FUNCTIONS |
3600 | 3607 |
3601 | 3608 |
3602 } // namespace internal | 3609 } // namespace internal |
3603 } // namespace v8 | 3610 } // namespace v8 |
3604 | 3611 |
3605 #endif // V8_AST_AST_H_ | 3612 #endif // V8_AST_AST_H_ |
OLD | NEW |