Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: src/ast/ast.h

Issue 2369293003: [ast] Make FunctionLiteral delegate to its Scope for FunctionKind (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2650 matching lines...) Expand 10 before | Expand all | Expand 10 after
2661 bool should_be_used_once_hint() const { 2661 bool should_be_used_once_hint() const {
2662 return ShouldNotBeUsedOnceHintField::decode(bit_field_); 2662 return ShouldNotBeUsedOnceHintField::decode(bit_field_);
2663 } 2663 }
2664 void set_should_be_used_once_hint() { 2664 void set_should_be_used_once_hint() {
2665 bit_field_ = ShouldNotBeUsedOnceHintField::update(bit_field_, true); 2665 bit_field_ = ShouldNotBeUsedOnceHintField::update(bit_field_, true);
2666 } 2666 }
2667 2667
2668 FunctionType function_type() const { 2668 FunctionType function_type() const {
2669 return FunctionTypeBits::decode(bit_field_); 2669 return FunctionTypeBits::decode(bit_field_);
2670 } 2670 }
2671 FunctionKind kind() const { return FunctionKindBits::decode(bit_field_); } 2671 FunctionKind kind() const;
2672 2672
2673 int ast_node_count() { return ast_properties_.node_count(); } 2673 int ast_node_count() { return ast_properties_.node_count(); }
2674 AstProperties::Flags flags() const { return ast_properties_.flags(); } 2674 AstProperties::Flags flags() const { return ast_properties_.flags(); }
2675 void set_ast_properties(AstProperties* ast_properties) { 2675 void set_ast_properties(AstProperties* ast_properties) {
2676 ast_properties_ = *ast_properties; 2676 ast_properties_ = *ast_properties;
2677 } 2677 }
2678 const FeedbackVectorSpec* feedback_vector_spec() const { 2678 const FeedbackVectorSpec* feedback_vector_spec() const {
2679 return ast_properties_.get_spec(); 2679 return ast_properties_.get_spec();
2680 } 2680 }
2681 bool dont_optimize() { return dont_optimize_reason() != kNoReason; } 2681 bool dont_optimize() { return dont_optimize_reason() != kNoReason; }
2682 BailoutReason dont_optimize_reason() { 2682 BailoutReason dont_optimize_reason() {
2683 return DontOptimizeReasonField::decode(bit_field_2_); 2683 return DontOptimizeReasonField::decode(bit_field_);
2684 } 2684 }
2685 void set_dont_optimize_reason(BailoutReason reason) { 2685 void set_dont_optimize_reason(BailoutReason reason) {
2686 bit_field_2_ = DontOptimizeReasonField::update(bit_field_2_, reason); 2686 bit_field_ = DontOptimizeReasonField::update(bit_field_, reason);
2687 } 2687 }
2688 2688
2689 bool IsAnonymousFunctionDefinition() const { 2689 bool IsAnonymousFunctionDefinition() const {
2690 return is_anonymous_expression(); 2690 return is_anonymous_expression();
2691 } 2691 }
2692 2692
2693 int yield_count() { return yield_count_; } 2693 int yield_count() { return yield_count_; }
2694 void set_yield_count(int yield_count) { yield_count_ = yield_count; } 2694 void set_yield_count(int yield_count) { yield_count_ = yield_count; }
2695 2695
2696 bool requires_class_field_init() { 2696 bool requires_class_field_init() {
2697 return RequiresClassFieldInit::decode(bit_field_); 2697 return RequiresClassFieldInit::decode(bit_field_);
2698 } 2698 }
2699 void set_requires_class_field_init(bool requires_class_field_init) { 2699 void set_requires_class_field_init(bool requires_class_field_init) {
2700 bit_field_ = 2700 bit_field_ =
2701 RequiresClassFieldInit::update(bit_field_, requires_class_field_init); 2701 RequiresClassFieldInit::update(bit_field_, requires_class_field_init);
2702 } 2702 }
2703 bool is_class_field_initializer() { 2703 bool is_class_field_initializer() {
2704 return IsClassFieldInitializer::decode(bit_field_2_); 2704 return IsClassFieldInitializer::decode(bit_field_);
2705 } 2705 }
2706 void set_is_class_field_initializer(bool is_class_field_initializer) { 2706 void set_is_class_field_initializer(bool is_class_field_initializer) {
2707 bit_field_ = IsClassFieldInitializer::update(bit_field_2_, 2707 bit_field_ =
2708 is_class_field_initializer); 2708 IsClassFieldInitializer::update(bit_field_, is_class_field_initializer);
2709 } 2709 }
2710 2710
2711 private: 2711 private:
2712 friend class AstNodeFactory; 2712 friend class AstNodeFactory;
2713 2713
2714 FunctionLiteral(Zone* zone, const AstString* name, 2714 FunctionLiteral(Zone* zone, const AstString* name,
2715 AstValueFactory* ast_value_factory, DeclarationScope* scope, 2715 AstValueFactory* ast_value_factory, DeclarationScope* scope,
2716 ZoneList<Statement*>* body, int materialized_literal_count, 2716 ZoneList<Statement*>* body, int materialized_literal_count,
2717 int expected_property_count, int parameter_count, 2717 int expected_property_count, int parameter_count,
2718 FunctionType function_type, 2718 FunctionType function_type,
2719 ParameterFlag has_duplicate_parameters, 2719 ParameterFlag has_duplicate_parameters,
2720 EagerCompileHint eager_compile_hint, FunctionKind kind, 2720 EagerCompileHint eager_compile_hint, int position,
2721 int position, bool is_function) 2721 bool is_function)
2722 : Expression(position, kFunctionLiteral), 2722 : Expression(position, kFunctionLiteral),
2723 materialized_literal_count_(materialized_literal_count), 2723 materialized_literal_count_(materialized_literal_count),
2724 expected_property_count_(expected_property_count), 2724 expected_property_count_(expected_property_count),
2725 parameter_count_(parameter_count), 2725 parameter_count_(parameter_count),
2726 function_token_position_(kNoSourcePosition), 2726 function_token_position_(kNoSourcePosition),
2727 yield_count_(0), 2727 yield_count_(0),
2728 raw_name_(name), 2728 raw_name_(name),
2729 scope_(scope), 2729 scope_(scope),
2730 body_(body), 2730 body_(body),
2731 raw_inferred_name_(ast_value_factory->empty_string()), 2731 raw_inferred_name_(ast_value_factory->empty_string()),
2732 ast_properties_(zone) { 2732 ast_properties_(zone) {
2733 bit_field_ |= 2733 bit_field_ |=
2734 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) | 2734 FunctionTypeBits::encode(function_type) | Pretenure::encode(false) |
2735 HasDuplicateParameters::encode(has_duplicate_parameters == 2735 HasDuplicateParameters::encode(has_duplicate_parameters ==
2736 kHasDuplicateParameters) | 2736 kHasDuplicateParameters) |
2737 IsFunction::encode(is_function) | 2737 IsFunction::encode(is_function) |
2738 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | 2738 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) |
2739 FunctionKindBits::encode(kind) | RequiresClassFieldInit::encode(false) | 2739 RequiresClassFieldInit::encode(false) |
2740 ShouldNotBeUsedOnceHintField::encode(false); 2740 ShouldNotBeUsedOnceHintField::encode(false) |
2741 2741 DontOptimizeReasonField::encode(kNoReason) |
2742 bit_field_2_ = DontOptimizeReasonField::encode(kNoReason) | 2742 IsClassFieldInitializer::encode(false);
2743 IsClassFieldInitializer::encode(false);
2744
2745 DCHECK(IsValidFunctionKind(kind));
2746 } 2743 }
2747 2744
2748 class FunctionTypeBits 2745 class FunctionTypeBits
2749 : public BitField<FunctionType, Expression::kNextBitFieldIndex, 2> {}; 2746 : public BitField<FunctionType, Expression::kNextBitFieldIndex, 2> {};
2750 class Pretenure : public BitField<bool, FunctionTypeBits::kNext, 1> {}; 2747 class Pretenure : public BitField<bool, FunctionTypeBits::kNext, 1> {};
2751 class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {}; 2748 class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {};
2752 class IsFunction : public BitField<bool, HasDuplicateParameters::kNext, 1> {}; 2749 class IsFunction : public BitField<bool, HasDuplicateParameters::kNext, 1> {};
2753 class ShouldEagerCompile : public BitField<bool, IsFunction::kNext, 1> {}; 2750 class ShouldEagerCompile : public BitField<bool, IsFunction::kNext, 1> {};
2754 class FunctionKindBits
2755 : public BitField<FunctionKind, ShouldEagerCompile::kNext, 9> {};
2756 class ShouldNotBeUsedOnceHintField 2751 class ShouldNotBeUsedOnceHintField
2757 : public BitField<bool, FunctionKindBits::kNext, 1> {}; 2752 : public BitField<bool, ShouldEagerCompile::kNext, 1> {};
2758 class RequiresClassFieldInit 2753 class RequiresClassFieldInit
2759 : public BitField<bool, ShouldNotBeUsedOnceHintField::kNext, 1> {}; 2754 : public BitField<bool, ShouldNotBeUsedOnceHintField::kNext, 1> {};
2760 2755 class IsClassFieldInitializer
2761 uint32_t bit_field_2_; 2756 : public BitField<bool, RequiresClassFieldInit::kNext, 1> {};
2762
2763 class IsClassFieldInitializer : public BitField<bool, 0, 1> {};
2764 class DontOptimizeReasonField 2757 class DontOptimizeReasonField
2765 : public BitField<BailoutReason, IsClassFieldInitializer::kNext, 8> {}; 2758 : public BitField<BailoutReason, IsClassFieldInitializer::kNext, 8> {};
2766 2759
2767 int materialized_literal_count_; 2760 int materialized_literal_count_;
2768 int expected_property_count_; 2761 int expected_property_count_;
2769 int parameter_count_; 2762 int parameter_count_;
2770 int function_token_position_; 2763 int function_token_position_;
2771 int yield_count_; 2764 int yield_count_;
2772 2765
2773 const AstString* raw_name_; 2766 const AstString* raw_name_;
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
3462 Throw* NewThrow(Expression* exception, int pos) { 3455 Throw* NewThrow(Expression* exception, int pos) {
3463 return new (zone_) Throw(exception, pos); 3456 return new (zone_) Throw(exception, pos);
3464 } 3457 }
3465 3458
3466 FunctionLiteral* NewFunctionLiteral( 3459 FunctionLiteral* NewFunctionLiteral(
3467 const AstRawString* name, DeclarationScope* scope, 3460 const AstRawString* name, DeclarationScope* scope,
3468 ZoneList<Statement*>* body, int materialized_literal_count, 3461 ZoneList<Statement*>* body, int materialized_literal_count,
3469 int expected_property_count, int parameter_count, 3462 int expected_property_count, int parameter_count,
3470 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3463 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3471 FunctionLiteral::FunctionType function_type, 3464 FunctionLiteral::FunctionType function_type,
3472 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, 3465 FunctionLiteral::EagerCompileHint eager_compile_hint, int position) {
3473 int position) { 3466 return new (zone_) FunctionLiteral(zone_, name, ast_value_factory_, scope,
3474 return new (zone_) FunctionLiteral( 3467 body, materialized_literal_count,
3475 zone_, name, ast_value_factory_, scope, body, 3468 expected_property_count, parameter_count,
3476 materialized_literal_count, expected_property_count, parameter_count, 3469 function_type, has_duplicate_parameters,
3477 function_type, has_duplicate_parameters, eager_compile_hint, kind, 3470 eager_compile_hint, position, true);
3478 position, true);
3479 } 3471 }
3480 3472
3481 // Creates a FunctionLiteral representing a top-level script, the 3473 // Creates a FunctionLiteral representing a top-level script, the
3482 // result of an eval (top-level or otherwise), or the result of calling 3474 // result of an eval (top-level or otherwise), or the result of calling
3483 // the Function constructor. 3475 // the Function constructor.
3484 FunctionLiteral* NewScriptOrEvalFunctionLiteral( 3476 FunctionLiteral* NewScriptOrEvalFunctionLiteral(
3485 DeclarationScope* scope, ZoneList<Statement*>* body, 3477 DeclarationScope* scope, ZoneList<Statement*>* body,
3486 int materialized_literal_count, int expected_property_count, 3478 int materialized_literal_count, int expected_property_count,
3487 int parameter_count) { 3479 int parameter_count) {
3488 return new (zone_) FunctionLiteral( 3480 return new (zone_) FunctionLiteral(
3489 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, 3481 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope,
3490 body, materialized_literal_count, expected_property_count, 3482 body, materialized_literal_count, expected_property_count,
3491 parameter_count, FunctionLiteral::kAnonymousExpression, 3483 parameter_count, FunctionLiteral::kAnonymousExpression,
3492 FunctionLiteral::kNoDuplicateParameters, 3484 FunctionLiteral::kNoDuplicateParameters,
3493 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, 3485 FunctionLiteral::kShouldLazyCompile, 0, false);
3494 false);
3495 } 3486 }
3496 3487
3497 ClassLiteral::Property* NewClassLiteralProperty( 3488 ClassLiteral::Property* NewClassLiteralProperty(
3498 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, 3489 Expression* key, Expression* value, ClassLiteralProperty::Kind kind,
3499 bool is_static, bool is_computed_name) { 3490 bool is_static, bool is_computed_name) {
3500 return new (zone_) 3491 return new (zone_)
3501 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); 3492 ClassLiteral::Property(key, value, kind, is_static, is_computed_name);
3502 } 3493 }
3503 3494
3504 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, 3495 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
3609 : NULL; \ 3600 : NULL; \
3610 } 3601 }
3611 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3602 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3612 #undef DECLARE_NODE_FUNCTIONS 3603 #undef DECLARE_NODE_FUNCTIONS
3613 3604
3614 3605
3615 } // namespace internal 3606 } // namespace internal
3616 } // namespace v8 3607 } // namespace v8
3617 3608
3618 #endif // V8_AST_AST_H_ 3609 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698