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

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

Issue 1566053002: Clean up FunctionLiteral AST node cruft (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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/parsing/parser.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/assembler.h" 8 #include "src/assembler.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 2543 matching lines...) Expand 10 before | Expand all | Expand 10 after
2554 : Expression(zone, pos), exception_(exception) {} 2554 : Expression(zone, pos), exception_(exception) {}
2555 2555
2556 private: 2556 private:
2557 Expression* exception_; 2557 Expression* exception_;
2558 }; 2558 };
2559 2559
2560 2560
2561 class FunctionLiteral final : public Expression { 2561 class FunctionLiteral final : public Expression {
2562 public: 2562 public:
2563 enum FunctionType { 2563 enum FunctionType {
2564 ANONYMOUS_EXPRESSION, 2564 kAnonymousExpression,
2565 NAMED_EXPRESSION, 2565 kNamedExpression,
2566 DECLARATION 2566 kDeclaration,
2567 kGlobalOrEval
2567 }; 2568 };
2568 2569
2569 enum ParameterFlag { 2570 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters };
2570 kNoDuplicateParameters = 0,
2571 kHasDuplicateParameters = 1
2572 };
2573
2574 enum IsFunctionFlag {
2575 kGlobalOrEval,
2576 kIsFunction
2577 };
2578 2571
2579 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; 2572 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
2580 2573
2581 enum ShouldBeUsedOnceHint { kShouldBeUsedOnce, kDontKnowIfShouldBeUsedOnce }; 2574 enum ArityRestriction { kNormalArity, kGetterArity, kSetterArity };
2582
2583 enum ArityRestriction {
2584 NORMAL_ARITY,
2585 GETTER_ARITY,
2586 SETTER_ARITY
2587 };
2588 2575
2589 DECLARE_NODE_TYPE(FunctionLiteral) 2576 DECLARE_NODE_TYPE(FunctionLiteral)
2590 2577
2591 Handle<String> name() const { return raw_name_->string(); } 2578 Handle<String> name() const { return raw_name_->string(); }
2592 const AstString* raw_name() const { return raw_name_; } 2579 const AstString* raw_name() const { return raw_name_; }
2593 void set_raw_name(const AstString* name) { raw_name_ = name; } 2580 void set_raw_name(const AstString* name) { raw_name_ = name; }
2594 Scope* scope() const { return scope_; } 2581 Scope* scope() const { return scope_; }
2595 ZoneList<Statement*>* body() const { return body_; } 2582 ZoneList<Statement*>* body() const { return body_; }
2596 void set_function_token_position(int pos) { function_token_position_ = pos; } 2583 void set_function_token_position(int pos) { function_token_position_ = pos; }
2597 int function_token_position() const { return function_token_position_; } 2584 int function_token_position() const { return function_token_position_; }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 raw_inferred_name_ = NULL; 2625 raw_inferred_name_ = NULL;
2639 } 2626 }
2640 2627
2641 void set_raw_inferred_name(const AstString* raw_inferred_name) { 2628 void set_raw_inferred_name(const AstString* raw_inferred_name) {
2642 DCHECK(raw_inferred_name != NULL); 2629 DCHECK(raw_inferred_name != NULL);
2643 raw_inferred_name_ = raw_inferred_name; 2630 raw_inferred_name_ = raw_inferred_name;
2644 DCHECK(inferred_name_.is_null()); 2631 DCHECK(inferred_name_.is_null());
2645 inferred_name_ = Handle<String>(); 2632 inferred_name_ = Handle<String>();
2646 } 2633 }
2647 2634
2648 bool pretenure() { return Pretenure::decode(bitfield_); } 2635 bool pretenure() const { return Pretenure::decode(bitfield_); }
2649 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } 2636 void set_pretenure() { bitfield_ = Pretenure::update(bitfield_, true); }
2650 2637
2651 bool has_duplicate_parameters() { 2638 bool has_duplicate_parameters() const {
2652 return HasDuplicateParameters::decode(bitfield_); 2639 return HasDuplicateParameters::decode(bitfield_);
2653 } 2640 }
2654 2641
2655 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; } 2642 bool is_function() const { return IsFunction::decode(bitfield_); }
2656 2643
2657 // This is used as a heuristic on when to eagerly compile a function 2644 // This is used as a heuristic on when to eagerly compile a function
2658 // literal. We consider the following constructs as hints that the 2645 // literal. We consider the following constructs as hints that the
2659 // function will be called immediately: 2646 // function will be called immediately:
2660 // - (function() { ... })(); 2647 // - (function() { ... })();
2661 // - var x = function() { ... }(); 2648 // - var x = function() { ... }();
2662 bool should_eager_compile() const { 2649 bool should_eager_compile() const {
2663 return EagerCompileHintBit::decode(bitfield_) == kShouldEagerCompile; 2650 return ShouldEagerCompile::decode(bitfield_);
2664 } 2651 }
2665 void set_should_eager_compile() { 2652 void set_should_eager_compile() {
2666 bitfield_ = EagerCompileHintBit::update(bitfield_, kShouldEagerCompile); 2653 bitfield_ = ShouldEagerCompile::update(bitfield_, true);
2667 } 2654 }
2668 2655
2669 // A hint that we expect this function to be called (exactly) once, 2656 // A hint that we expect this function to be called (exactly) once,
2670 // i.e. we suspect it's an initialization function. 2657 // i.e. we suspect it's an initialization function.
2671 bool should_be_used_once_hint() const { 2658 bool should_be_used_once_hint() const {
2672 return ShouldBeUsedOnceHintBit::decode(bitfield_) == kShouldBeUsedOnce; 2659 return ShouldBeUsedOnceHint::decode(bitfield_);
2673 } 2660 }
2674 void set_should_be_used_once_hint() { 2661 void set_should_be_used_once_hint() {
2675 bitfield_ = ShouldBeUsedOnceHintBit::update(bitfield_, kShouldBeUsedOnce); 2662 bitfield_ = ShouldBeUsedOnceHint::update(bitfield_, true);
2676 } 2663 }
2677 2664
2678 FunctionKind kind() const { return FunctionKindBits::decode(bitfield_); } 2665 FunctionKind kind() const { return FunctionKindBits::decode(bitfield_); }
2679 2666
2680 int ast_node_count() { return ast_properties_.node_count(); } 2667 int ast_node_count() { return ast_properties_.node_count(); }
2681 AstProperties::Flags flags() const { return ast_properties_.flags(); } 2668 AstProperties::Flags flags() const { return ast_properties_.flags(); }
2682 void set_ast_properties(AstProperties* ast_properties) { 2669 void set_ast_properties(AstProperties* ast_properties) {
2683 ast_properties_ = *ast_properties; 2670 ast_properties_ = *ast_properties;
2684 } 2671 }
2685 const FeedbackVectorSpec* feedback_vector_spec() const { 2672 const FeedbackVectorSpec* feedback_vector_spec() const {
2686 return ast_properties_.get_spec(); 2673 return ast_properties_.get_spec();
2687 } 2674 }
2688 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } 2675 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2689 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } 2676 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2690 void set_dont_optimize_reason(BailoutReason reason) { 2677 void set_dont_optimize_reason(BailoutReason reason) {
2691 dont_optimize_reason_ = reason; 2678 dont_optimize_reason_ = reason;
2692 } 2679 }
2693 2680
2694 protected: 2681 protected:
2695 FunctionLiteral(Zone* zone, const AstString* name, 2682 FunctionLiteral(Zone* zone, const AstString* name,
2696 AstValueFactory* ast_value_factory, Scope* scope, 2683 AstValueFactory* ast_value_factory, Scope* scope,
2697 ZoneList<Statement*>* body, int materialized_literal_count, 2684 ZoneList<Statement*>* body, int materialized_literal_count,
2698 int expected_property_count, int parameter_count, 2685 int expected_property_count, int parameter_count,
2699 FunctionType function_type, 2686 FunctionType function_type,
2700 ParameterFlag has_duplicate_parameters, 2687 ParameterFlag has_duplicate_parameters,
2701 IsFunctionFlag is_function,
2702 EagerCompileHint eager_compile_hint, FunctionKind kind, 2688 EagerCompileHint eager_compile_hint, FunctionKind kind,
2703 int position) 2689 int position)
2704 : Expression(zone, position), 2690 : Expression(zone, position),
2705 raw_name_(name), 2691 raw_name_(name),
2706 scope_(scope), 2692 scope_(scope),
2707 body_(body), 2693 body_(body),
2708 raw_inferred_name_(ast_value_factory->empty_string()), 2694 raw_inferred_name_(ast_value_factory->empty_string()),
2709 ast_properties_(zone), 2695 ast_properties_(zone),
2710 dont_optimize_reason_(kNoReason), 2696 dont_optimize_reason_(kNoReason),
2711 materialized_literal_count_(materialized_literal_count), 2697 materialized_literal_count_(materialized_literal_count),
2712 expected_property_count_(expected_property_count), 2698 expected_property_count_(expected_property_count),
2713 parameter_count_(parameter_count), 2699 parameter_count_(parameter_count),
2714 function_token_position_(RelocInfo::kNoPosition) { 2700 function_token_position_(RelocInfo::kNoPosition) {
2715 bitfield_ = IsExpression::encode(function_type != DECLARATION) | 2701 bitfield_ =
2716 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | 2702 IsExpression::encode(function_type != kDeclaration) |
2717 Pretenure::encode(false) | 2703 IsAnonymous::encode(function_type == kAnonymousExpression) |
2718 HasDuplicateParameters::encode(has_duplicate_parameters) | 2704 Pretenure::encode(false) |
2719 IsFunction::encode(is_function) | 2705 HasDuplicateParameters::encode(has_duplicate_parameters ==
2720 EagerCompileHintBit::encode(eager_compile_hint) | 2706 kHasDuplicateParameters) |
2721 FunctionKindBits::encode(kind) | 2707 IsFunction::encode(function_type != kGlobalOrEval) |
2722 ShouldBeUsedOnceHintBit::encode(kDontKnowIfShouldBeUsedOnce); 2708 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) |
2709 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false);
2723 DCHECK(IsValidFunctionKind(kind)); 2710 DCHECK(IsValidFunctionKind(kind));
2724 } 2711 }
2725 2712
2726 private: 2713 private:
2714 class IsExpression : public BitField16<bool, 0, 1> {};
2715 class IsAnonymous : public BitField16<bool, 1, 1> {};
2716 class Pretenure : public BitField16<bool, 2, 1> {};
2717 class HasDuplicateParameters : public BitField16<bool, 3, 1> {};
2718 class IsFunction : public BitField16<bool, 4, 1> {};
2719 class ShouldEagerCompile : public BitField16<bool, 5, 1> {};
2720 class FunctionKindBits : public BitField16<FunctionKind, 6, 8> {};
2721 class ShouldBeUsedOnceHint : public BitField16<bool, 15, 1> {};
2722
2723 // Start with 16-bit field, which should get packed together
2724 // with Expression's trailing 16-bit field.
2725 uint16_t bitfield_;
2726
2727 const AstString* raw_name_; 2727 const AstString* raw_name_;
2728 Handle<String> name_;
2729 Scope* scope_; 2728 Scope* scope_;
2730 ZoneList<Statement*>* body_; 2729 ZoneList<Statement*>* body_;
2731 const AstString* raw_inferred_name_; 2730 const AstString* raw_inferred_name_;
2732 Handle<String> inferred_name_; 2731 Handle<String> inferred_name_;
2733 AstProperties ast_properties_; 2732 AstProperties ast_properties_;
2734 BailoutReason dont_optimize_reason_; 2733 BailoutReason dont_optimize_reason_;
2735 2734
2736 int materialized_literal_count_; 2735 int materialized_literal_count_;
2737 int expected_property_count_; 2736 int expected_property_count_;
2738 int parameter_count_; 2737 int parameter_count_;
2739 int function_token_position_; 2738 int function_token_position_;
2740
2741 unsigned bitfield_;
2742 class IsExpression : public BitField<bool, 0, 1> {};
2743 class IsAnonymous : public BitField<bool, 1, 1> {};
2744 class Pretenure : public BitField<bool, 2, 1> {};
2745 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2746 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2747 class EagerCompileHintBit : public BitField<EagerCompileHint, 5, 1> {};
2748 class FunctionKindBits : public BitField<FunctionKind, 6, 8> {};
2749 class ShouldBeUsedOnceHintBit : public BitField<ShouldBeUsedOnceHint, 15, 1> {
2750 };
2751 }; 2739 };
2752 2740
2753 2741
2754 class ClassLiteral final : public Expression { 2742 class ClassLiteral final : public Expression {
2755 public: 2743 public:
2756 typedef ObjectLiteralProperty Property; 2744 typedef ObjectLiteralProperty Property;
2757 2745
2758 DECLARE_NODE_TYPE(ClassLiteral) 2746 DECLARE_NODE_TYPE(ClassLiteral)
2759 2747
2760 Handle<String> name() const { return raw_name_->string(); } 2748 Handle<String> name() const { return raw_name_->string(); }
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
3673 if (!expression) expression = NewUndefinedLiteral(pos); 3661 if (!expression) expression = NewUndefinedLiteral(pos);
3674 return new (local_zone_) 3662 return new (local_zone_)
3675 Yield(local_zone_, generator_object, expression, yield_kind, pos); 3663 Yield(local_zone_, generator_object, expression, yield_kind, pos);
3676 } 3664 }
3677 3665
3678 Throw* NewThrow(Expression* exception, int pos) { 3666 Throw* NewThrow(Expression* exception, int pos) {
3679 return new (local_zone_) Throw(local_zone_, exception, pos); 3667 return new (local_zone_) Throw(local_zone_, exception, pos);
3680 } 3668 }
3681 3669
3682 FunctionLiteral* NewFunctionLiteral( 3670 FunctionLiteral* NewFunctionLiteral(
3683 const AstRawString* name, AstValueFactory* ast_value_factory, 3671 const AstRawString* name, Scope* scope, ZoneList<Statement*>* body,
3684 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, 3672 int materialized_literal_count, int expected_property_count,
3685 int expected_property_count, int parameter_count, 3673 int parameter_count,
3686 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3674 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3687 FunctionLiteral::FunctionType function_type, 3675 FunctionLiteral::FunctionType function_type,
3688 FunctionLiteral::IsFunctionFlag is_function,
3689 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, 3676 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
3690 int position) { 3677 int position) {
3691 return new (parser_zone_) FunctionLiteral( 3678 return new (parser_zone_) FunctionLiteral(
3692 parser_zone_, name, ast_value_factory, scope, body, 3679 parser_zone_, name, ast_value_factory_, scope, body,
3693 materialized_literal_count, expected_property_count, parameter_count, 3680 materialized_literal_count, expected_property_count, parameter_count,
3694 function_type, has_duplicate_parameters, is_function, 3681 function_type, has_duplicate_parameters, eager_compile_hint, kind,
3695 eager_compile_hint, kind, position); 3682 position);
3696 } 3683 }
3697 3684
3698 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope, 3685 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope,
3699 VariableProxy* proxy, Expression* extends, 3686 VariableProxy* proxy, Expression* extends,
3700 FunctionLiteral* constructor, 3687 FunctionLiteral* constructor,
3701 ZoneList<ObjectLiteral::Property*>* properties, 3688 ZoneList<ObjectLiteral::Property*>* properties,
3702 int start_position, int end_position) { 3689 int start_position, int end_position) {
3703 return new (parser_zone_) 3690 return new (parser_zone_)
3704 ClassLiteral(parser_zone_, name, scope, proxy, extends, constructor, 3691 ClassLiteral(parser_zone_, name, scope, proxy, extends, constructor,
3705 properties, start_position, end_position); 3692 properties, start_position, end_position);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3769 // the parser-level zone. 3756 // the parser-level zone.
3770 Zone* parser_zone_; 3757 Zone* parser_zone_;
3771 AstValueFactory* ast_value_factory_; 3758 AstValueFactory* ast_value_factory_;
3772 }; 3759 };
3773 3760
3774 3761
3775 } // namespace internal 3762 } // namespace internal
3776 } // namespace v8 3763 } // namespace v8
3777 3764
3778 #endif // V8_AST_AST_H_ 3765 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698