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/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/ast/ast-types.h" | 9 #include "src/ast/ast-types.h" |
10 #include "src/ast/ast-value-factory.h" | 10 #include "src/ast/ast-value-factory.h" |
(...skipping 2611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2622 inferred_name_ = Handle<String>(); | 2622 inferred_name_ = Handle<String>(); |
2623 } | 2623 } |
2624 | 2624 |
2625 bool pretenure() const { return Pretenure::decode(bit_field_); } | 2625 bool pretenure() const { return Pretenure::decode(bit_field_); } |
2626 void set_pretenure() { bit_field_ = Pretenure::update(bit_field_, true); } | 2626 void set_pretenure() { bit_field_ = Pretenure::update(bit_field_, true); } |
2627 | 2627 |
2628 bool has_duplicate_parameters() const { | 2628 bool has_duplicate_parameters() const { |
2629 return HasDuplicateParameters::decode(bit_field_); | 2629 return HasDuplicateParameters::decode(bit_field_); |
2630 } | 2630 } |
2631 | 2631 |
2632 bool is_function() const { return IsFunction::decode(bit_field_); } | |
2633 | |
2634 // This is used as a heuristic on when to eagerly compile a function | 2632 // This is used as a heuristic on when to eagerly compile a function |
2635 // literal. We consider the following constructs as hints that the | 2633 // literal. We consider the following constructs as hints that the |
2636 // function will be called immediately: | 2634 // function will be called immediately: |
2637 // - (function() { ... })(); | 2635 // - (function() { ... })(); |
2638 // - var x = function() { ... }(); | 2636 // - var x = function() { ... }(); |
2639 bool ShouldEagerCompile() const; | 2637 bool ShouldEagerCompile() const; |
2640 void SetShouldEagerCompile(); | 2638 void SetShouldEagerCompile(); |
2641 | 2639 |
2642 // A hint that we expect this function to be called (exactly) once, | 2640 // A hint that we expect this function to be called (exactly) once, |
2643 // i.e. we suspect it's an initialization function. | 2641 // i.e. we suspect it's an initialization function. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2688 private: | 2686 private: |
2689 friend class AstNodeFactory; | 2687 friend class AstNodeFactory; |
2690 | 2688 |
2691 FunctionLiteral(Zone* zone, const AstString* name, | 2689 FunctionLiteral(Zone* zone, const AstString* name, |
2692 AstValueFactory* ast_value_factory, DeclarationScope* scope, | 2690 AstValueFactory* ast_value_factory, DeclarationScope* scope, |
2693 ZoneList<Statement*>* body, int materialized_literal_count, | 2691 ZoneList<Statement*>* body, int materialized_literal_count, |
2694 int expected_property_count, int parameter_count, | 2692 int expected_property_count, int parameter_count, |
2695 int function_length, FunctionType function_type, | 2693 int function_length, FunctionType function_type, |
2696 ParameterFlag has_duplicate_parameters, | 2694 ParameterFlag has_duplicate_parameters, |
2697 EagerCompileHint eager_compile_hint, int position, | 2695 EagerCompileHint eager_compile_hint, int position, |
2698 bool is_function, bool has_braces, int function_literal_id) | 2696 bool has_braces, int function_literal_id) |
2699 : Expression(position, kFunctionLiteral), | 2697 : Expression(position, kFunctionLiteral), |
2700 materialized_literal_count_(materialized_literal_count), | 2698 materialized_literal_count_(materialized_literal_count), |
2701 expected_property_count_(expected_property_count), | 2699 expected_property_count_(expected_property_count), |
2702 parameter_count_(parameter_count), | 2700 parameter_count_(parameter_count), |
2703 function_length_(function_length), | 2701 function_length_(function_length), |
2704 function_token_position_(kNoSourcePosition), | 2702 function_token_position_(kNoSourcePosition), |
2705 yield_count_(0), | 2703 yield_count_(0), |
2706 has_braces_(has_braces), | 2704 has_braces_(has_braces), |
2707 raw_name_(name), | 2705 raw_name_(name), |
2708 scope_(scope), | 2706 scope_(scope), |
2709 body_(body), | 2707 body_(body), |
2710 raw_inferred_name_(ast_value_factory->empty_string()), | 2708 raw_inferred_name_(ast_value_factory->empty_string()), |
2711 ast_properties_(zone), | 2709 ast_properties_(zone), |
2712 function_literal_id_(function_literal_id) { | 2710 function_literal_id_(function_literal_id) { |
2713 bit_field_ |= FunctionTypeBits::encode(function_type) | | 2711 bit_field_ |= FunctionTypeBits::encode(function_type) | |
2714 Pretenure::encode(false) | | 2712 Pretenure::encode(false) | |
2715 HasDuplicateParameters::encode(has_duplicate_parameters == | 2713 HasDuplicateParameters::encode(has_duplicate_parameters == |
2716 kHasDuplicateParameters) | | 2714 kHasDuplicateParameters) | |
2717 IsFunction::encode(is_function) | | |
2718 ShouldNotBeUsedOnceHintField::encode(false) | | 2715 ShouldNotBeUsedOnceHintField::encode(false) | |
2719 DontOptimizeReasonField::encode(kNoReason); | 2716 DontOptimizeReasonField::encode(kNoReason); |
2720 if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile(); | 2717 if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile(); |
2721 } | 2718 } |
2722 | 2719 |
2723 class FunctionTypeBits | 2720 class FunctionTypeBits |
2724 : public BitField<FunctionType, Expression::kNextBitFieldIndex, 2> {}; | 2721 : public BitField<FunctionType, Expression::kNextBitFieldIndex, 2> {}; |
2725 class Pretenure : public BitField<bool, FunctionTypeBits::kNext, 1> {}; | 2722 class Pretenure : public BitField<bool, FunctionTypeBits::kNext, 1> {}; |
2726 class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {}; | 2723 class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {}; |
2727 class IsFunction : public BitField<bool, HasDuplicateParameters::kNext, 1> {}; | |
2728 class ShouldNotBeUsedOnceHintField | 2724 class ShouldNotBeUsedOnceHintField |
2729 : public BitField<bool, IsFunction::kNext, 1> {}; | 2725 : public BitField<bool, HasDuplicateParameters::kNext, 1> {}; |
2730 class DontOptimizeReasonField | 2726 class DontOptimizeReasonField |
2731 : public BitField<BailoutReason, ShouldNotBeUsedOnceHintField::kNext, 8> { | 2727 : public BitField<BailoutReason, ShouldNotBeUsedOnceHintField::kNext, 8> { |
2732 }; | 2728 }; |
2733 | 2729 |
2734 int materialized_literal_count_; | 2730 int materialized_literal_count_; |
2735 int expected_property_count_; | 2731 int expected_property_count_; |
2736 int parameter_count_; | 2732 int parameter_count_; |
2737 int function_length_; | 2733 int function_length_; |
2738 int function_token_position_; | 2734 int function_token_position_; |
2739 int yield_count_; | 2735 int yield_count_; |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3472 ZoneList<Statement*>* body, int materialized_literal_count, | 3468 ZoneList<Statement*>* body, int materialized_literal_count, |
3473 int expected_property_count, int parameter_count, int function_length, | 3469 int expected_property_count, int parameter_count, int function_length, |
3474 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3470 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3475 FunctionLiteral::FunctionType function_type, | 3471 FunctionLiteral::FunctionType function_type, |
3476 FunctionLiteral::EagerCompileHint eager_compile_hint, int position, | 3472 FunctionLiteral::EagerCompileHint eager_compile_hint, int position, |
3477 bool has_braces, int function_literal_id) { | 3473 bool has_braces, int function_literal_id) { |
3478 return new (zone_) FunctionLiteral( | 3474 return new (zone_) FunctionLiteral( |
3479 zone_, name, ast_value_factory_, scope, body, | 3475 zone_, name, ast_value_factory_, scope, body, |
3480 materialized_literal_count, expected_property_count, parameter_count, | 3476 materialized_literal_count, expected_property_count, parameter_count, |
3481 function_length, function_type, has_duplicate_parameters, | 3477 function_length, function_type, has_duplicate_parameters, |
3482 eager_compile_hint, position, true, has_braces, function_literal_id); | 3478 eager_compile_hint, position, has_braces, function_literal_id); |
3483 } | 3479 } |
3484 | 3480 |
3485 // Creates a FunctionLiteral representing a top-level script, the | 3481 // Creates a FunctionLiteral representing a top-level script, the |
3486 // result of an eval (top-level or otherwise), or the result of calling | 3482 // result of an eval (top-level or otherwise), or the result of calling |
3487 // the Function constructor. | 3483 // the Function constructor. |
3488 FunctionLiteral* NewScriptOrEvalFunctionLiteral( | 3484 FunctionLiteral* NewScriptOrEvalFunctionLiteral( |
3489 DeclarationScope* scope, ZoneList<Statement*>* body, | 3485 DeclarationScope* scope, ZoneList<Statement*>* body, |
3490 int materialized_literal_count, int expected_property_count, | 3486 int materialized_literal_count, int expected_property_count, |
3491 int parameter_count) { | 3487 int parameter_count) { |
3492 return new (zone_) FunctionLiteral( | 3488 return new (zone_) FunctionLiteral( |
3493 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, | 3489 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, |
3494 body, materialized_literal_count, expected_property_count, | 3490 body, materialized_literal_count, expected_property_count, |
3495 parameter_count, parameter_count, FunctionLiteral::kAnonymousExpression, | 3491 parameter_count, parameter_count, FunctionLiteral::kAnonymousExpression, |
3496 FunctionLiteral::kNoDuplicateParameters, | 3492 FunctionLiteral::kNoDuplicateParameters, |
3497 FunctionLiteral::kShouldLazyCompile, 0, false, true, | 3493 FunctionLiteral::kShouldLazyCompile, 0, true, |
3498 FunctionLiteral::kIdTypeTopLevel); | 3494 FunctionLiteral::kIdTypeTopLevel); |
3499 } | 3495 } |
3500 | 3496 |
3501 ClassLiteral::Property* NewClassLiteralProperty( | 3497 ClassLiteral::Property* NewClassLiteralProperty( |
3502 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, | 3498 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, |
3503 bool is_static, bool is_computed_name) { | 3499 bool is_static, bool is_computed_name) { |
3504 return new (zone_) | 3500 return new (zone_) |
3505 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); | 3501 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); |
3506 } | 3502 } |
3507 | 3503 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3621 : NULL; \ | 3617 : NULL; \ |
3622 } | 3618 } |
3623 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3619 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3624 #undef DECLARE_NODE_FUNCTIONS | 3620 #undef DECLARE_NODE_FUNCTIONS |
3625 | 3621 |
3626 | 3622 |
3627 } // namespace internal | 3623 } // namespace internal |
3628 } // namespace v8 | 3624 } // namespace v8 |
3629 | 3625 |
3630 #endif // V8_AST_AST_H_ | 3626 #endif // V8_AST_AST_H_ |
OLD | NEW |