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-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); | 1422 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); |
1423 return slots_[offset]; | 1423 return slots_[offset]; |
1424 } | 1424 } |
1425 void SetSlot(FeedbackVectorSlot slot, int offset = 0) { | 1425 void SetSlot(FeedbackVectorSlot slot, int offset = 0) { |
1426 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); | 1426 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); |
1427 slots_[offset] = slot; | 1427 slots_[offset] = slot; |
1428 } | 1428 } |
1429 | 1429 |
1430 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } | 1430 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } |
1431 | 1431 |
1432 bool NeedsSetFunctionName() const { | 1432 bool NeedsSetFunctionName() const; |
1433 return is_computed_name_ && value_->IsAnonymousFunctionDefinition(); | |
1434 } | |
1435 | 1433 |
1436 protected: | 1434 protected: |
1437 friend class AstNodeFactory; | 1435 friend class AstNodeFactory; |
1438 | 1436 |
1439 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, | 1437 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, |
1440 bool is_static, bool is_computed_name); | 1438 bool is_static, bool is_computed_name); |
1441 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, | 1439 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, |
1442 Expression* value, bool is_static, | 1440 Expression* value, bool is_static, |
1443 bool is_computed_name); | 1441 bool is_computed_name); |
1444 | 1442 |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 Expression* exception_; | 2566 Expression* exception_; |
2569 }; | 2567 }; |
2570 | 2568 |
2571 | 2569 |
2572 class FunctionLiteral final : public Expression { | 2570 class FunctionLiteral final : public Expression { |
2573 public: | 2571 public: |
2574 enum FunctionType { | 2572 enum FunctionType { |
2575 kAnonymousExpression, | 2573 kAnonymousExpression, |
2576 kNamedExpression, | 2574 kNamedExpression, |
2577 kDeclaration, | 2575 kDeclaration, |
2578 kGlobalOrEval | 2576 kAccessorOrMethod |
2579 }; | 2577 }; |
2580 | 2578 |
2581 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters }; | 2579 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters }; |
2582 | 2580 |
2583 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; | 2581 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; |
2584 | 2582 |
2585 enum ArityRestriction { kNormalArity, kGetterArity, kSetterArity }; | |
2586 | |
2587 DECLARE_NODE_TYPE(FunctionLiteral) | 2583 DECLARE_NODE_TYPE(FunctionLiteral) |
2588 | 2584 |
2589 Handle<String> name() const { return raw_name_->string(); } | 2585 Handle<String> name() const { return raw_name_->string(); } |
2590 const AstString* raw_name() const { return raw_name_; } | 2586 const AstString* raw_name() const { return raw_name_; } |
2591 void set_raw_name(const AstString* name) { raw_name_ = name; } | 2587 void set_raw_name(const AstString* name) { raw_name_ = name; } |
2592 Scope* scope() const { return scope_; } | 2588 Scope* scope() const { return scope_; } |
2593 ZoneList<Statement*>* body() const { return body_; } | 2589 ZoneList<Statement*>* body() const { return body_; } |
2594 void set_function_token_position(int pos) { function_token_position_ = pos; } | 2590 void set_function_token_position(int pos) { function_token_position_ = pos; } |
2595 int function_token_position() const { return function_token_position_; } | 2591 int function_token_position() const { return function_token_position_; } |
2596 int start_position() const; | 2592 int start_position() const; |
2597 int end_position() const; | 2593 int end_position() const; |
2598 int SourceSize() const { return end_position() - start_position(); } | 2594 int SourceSize() const { return end_position() - start_position(); } |
2599 bool is_expression() const { return IsExpression::decode(bitfield_); } | 2595 bool is_declaration() const { return IsDeclaration::decode(bitfield_); } |
2600 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); } | 2596 bool is_named_expression() const { |
| 2597 return IsNamedExpression::decode(bitfield_); |
| 2598 } |
| 2599 bool is_anonymous_expression() const { |
| 2600 return IsAnonymousExpression::decode(bitfield_); |
| 2601 } |
2601 LanguageMode language_mode() const; | 2602 LanguageMode language_mode() const; |
2602 | 2603 |
2603 static bool NeedsHomeObject(Expression* expr); | 2604 static bool NeedsHomeObject(Expression* expr); |
2604 | 2605 |
2605 int materialized_literal_count() { return materialized_literal_count_; } | 2606 int materialized_literal_count() { return materialized_literal_count_; } |
2606 int expected_property_count() { return expected_property_count_; } | 2607 int expected_property_count() { return expected_property_count_; } |
2607 int parameter_count() { return parameter_count_; } | 2608 int parameter_count() { return parameter_count_; } |
2608 | 2609 |
2609 bool AllowsLazyCompilation(); | 2610 bool AllowsLazyCompilation(); |
2610 bool AllowsLazyCompilationWithoutContext(); | 2611 bool AllowsLazyCompilationWithoutContext(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2683 const FeedbackVectorSpec* feedback_vector_spec() const { | 2684 const FeedbackVectorSpec* feedback_vector_spec() const { |
2684 return ast_properties_.get_spec(); | 2685 return ast_properties_.get_spec(); |
2685 } | 2686 } |
2686 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } | 2687 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } |
2687 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } | 2688 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } |
2688 void set_dont_optimize_reason(BailoutReason reason) { | 2689 void set_dont_optimize_reason(BailoutReason reason) { |
2689 dont_optimize_reason_ = reason; | 2690 dont_optimize_reason_ = reason; |
2690 } | 2691 } |
2691 | 2692 |
2692 bool IsAnonymousFunctionDefinition() const final { | 2693 bool IsAnonymousFunctionDefinition() const final { |
2693 // TODO(adamk): This isn't quite accurate, as many non-expressions | 2694 return is_anonymous_expression(); |
2694 // (such as concise methods) are marked as anonymous, but it's | |
2695 // sufficient for the current callers. | |
2696 return is_anonymous(); | |
2697 } | 2695 } |
2698 | 2696 |
2699 protected: | 2697 protected: |
2700 FunctionLiteral(Zone* zone, const AstString* name, | 2698 FunctionLiteral(Zone* zone, const AstString* name, |
2701 AstValueFactory* ast_value_factory, Scope* scope, | 2699 AstValueFactory* ast_value_factory, Scope* scope, |
2702 ZoneList<Statement*>* body, int materialized_literal_count, | 2700 ZoneList<Statement*>* body, int materialized_literal_count, |
2703 int expected_property_count, int parameter_count, | 2701 int expected_property_count, int parameter_count, |
2704 FunctionType function_type, | 2702 FunctionType function_type, |
2705 ParameterFlag has_duplicate_parameters, | 2703 ParameterFlag has_duplicate_parameters, |
2706 EagerCompileHint eager_compile_hint, FunctionKind kind, | 2704 EagerCompileHint eager_compile_hint, FunctionKind kind, |
2707 int position) | 2705 int position, bool is_function) |
2708 : Expression(zone, position), | 2706 : Expression(zone, position), |
2709 raw_name_(name), | 2707 raw_name_(name), |
2710 scope_(scope), | 2708 scope_(scope), |
2711 body_(body), | 2709 body_(body), |
2712 raw_inferred_name_(ast_value_factory->empty_string()), | 2710 raw_inferred_name_(ast_value_factory->empty_string()), |
2713 ast_properties_(zone), | 2711 ast_properties_(zone), |
2714 dont_optimize_reason_(kNoReason), | 2712 dont_optimize_reason_(kNoReason), |
2715 materialized_literal_count_(materialized_literal_count), | 2713 materialized_literal_count_(materialized_literal_count), |
2716 expected_property_count_(expected_property_count), | 2714 expected_property_count_(expected_property_count), |
2717 parameter_count_(parameter_count), | 2715 parameter_count_(parameter_count), |
2718 function_token_position_(RelocInfo::kNoPosition) { | 2716 function_token_position_(RelocInfo::kNoPosition) { |
2719 bitfield_ = | 2717 bitfield_ = |
2720 IsExpression::encode(function_type != kDeclaration) | | 2718 IsDeclaration::encode(function_type == kDeclaration) | |
2721 IsAnonymous::encode(function_type == kAnonymousExpression) | | 2719 IsNamedExpression::encode(function_type == kNamedExpression) | |
| 2720 IsAnonymousExpression::encode(function_type == kAnonymousExpression) | |
2722 Pretenure::encode(false) | | 2721 Pretenure::encode(false) | |
2723 HasDuplicateParameters::encode(has_duplicate_parameters == | 2722 HasDuplicateParameters::encode(has_duplicate_parameters == |
2724 kHasDuplicateParameters) | | 2723 kHasDuplicateParameters) | |
2725 IsFunction::encode(function_type != kGlobalOrEval) | | 2724 IsFunction::encode(is_function) | |
2726 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | | 2725 ShouldEagerCompile::encode(eager_compile_hint == kShouldEagerCompile) | |
2727 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false); | 2726 FunctionKindBits::encode(kind) | ShouldBeUsedOnceHint::encode(false); |
2728 DCHECK(IsValidFunctionKind(kind)); | 2727 DCHECK(IsValidFunctionKind(kind)); |
2729 } | 2728 } |
2730 | 2729 |
2731 private: | 2730 private: |
2732 class IsExpression : public BitField16<bool, 0, 1> {}; | 2731 class IsDeclaration : public BitField16<bool, 0, 1> {}; |
2733 class IsAnonymous : public BitField16<bool, 1, 1> {}; | 2732 class IsNamedExpression : public BitField16<bool, 1, 1> {}; |
2734 class Pretenure : public BitField16<bool, 2, 1> {}; | 2733 class IsAnonymousExpression : public BitField16<bool, 2, 1> {}; |
2735 class HasDuplicateParameters : public BitField16<bool, 3, 1> {}; | 2734 class Pretenure : public BitField16<bool, 3, 1> {}; |
2736 class IsFunction : public BitField16<bool, 4, 1> {}; | 2735 class HasDuplicateParameters : public BitField16<bool, 4, 1> {}; |
2737 class ShouldEagerCompile : public BitField16<bool, 5, 1> {}; | 2736 class IsFunction : public BitField16<bool, 5, 1> {}; |
2738 class FunctionKindBits : public BitField16<FunctionKind, 6, 8> {}; | 2737 class ShouldEagerCompile : public BitField16<bool, 6, 1> {}; |
2739 class ShouldBeUsedOnceHint : public BitField16<bool, 15, 1> {}; | 2738 class ShouldBeUsedOnceHint : public BitField16<bool, 7, 1> {}; |
| 2739 class FunctionKindBits : public BitField16<FunctionKind, 8, 8> {}; |
2740 | 2740 |
2741 // Start with 16-bit field, which should get packed together | 2741 // Start with 16-bit field, which should get packed together |
2742 // with Expression's trailing 16-bit field. | 2742 // with Expression's trailing 16-bit field. |
2743 uint16_t bitfield_; | 2743 uint16_t bitfield_; |
2744 | 2744 |
2745 const AstString* raw_name_; | 2745 const AstString* raw_name_; |
2746 Scope* scope_; | 2746 Scope* scope_; |
2747 ZoneList<Statement*>* body_; | 2747 ZoneList<Statement*>* body_; |
2748 const AstString* raw_inferred_name_; | 2748 const AstString* raw_inferred_name_; |
2749 Handle<String> inferred_name_; | 2749 Handle<String> inferred_name_; |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3406 int materialized_literal_count, int expected_property_count, | 3406 int materialized_literal_count, int expected_property_count, |
3407 int parameter_count, | 3407 int parameter_count, |
3408 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3408 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3409 FunctionLiteral::FunctionType function_type, | 3409 FunctionLiteral::FunctionType function_type, |
3410 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, | 3410 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, |
3411 int position) { | 3411 int position) { |
3412 return new (parser_zone_) FunctionLiteral( | 3412 return new (parser_zone_) FunctionLiteral( |
3413 parser_zone_, name, ast_value_factory_, scope, body, | 3413 parser_zone_, name, ast_value_factory_, scope, body, |
3414 materialized_literal_count, expected_property_count, parameter_count, | 3414 materialized_literal_count, expected_property_count, parameter_count, |
3415 function_type, has_duplicate_parameters, eager_compile_hint, kind, | 3415 function_type, has_duplicate_parameters, eager_compile_hint, kind, |
3416 position); | 3416 position, true); |
| 3417 } |
| 3418 |
| 3419 // Creates a FunctionLiteral representing a top-level script, the |
| 3420 // result of an eval (top-level or otherwise), or the result of calling |
| 3421 // the Function constructor. |
| 3422 FunctionLiteral* NewScriptOrEvalFunctionLiteral( |
| 3423 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, |
| 3424 int expected_property_count) { |
| 3425 return new (parser_zone_) FunctionLiteral( |
| 3426 parser_zone_, ast_value_factory_->empty_string(), ast_value_factory_, |
| 3427 scope, body, materialized_literal_count, expected_property_count, 0, |
| 3428 FunctionLiteral::kAnonymousExpression, |
| 3429 FunctionLiteral::kNoDuplicateParameters, |
| 3430 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, |
| 3431 false); |
3417 } | 3432 } |
3418 | 3433 |
3419 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy, | 3434 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy, |
3420 Expression* extends, | 3435 Expression* extends, |
3421 FunctionLiteral* constructor, | 3436 FunctionLiteral* constructor, |
3422 ZoneList<ObjectLiteral::Property*>* properties, | 3437 ZoneList<ObjectLiteral::Property*>* properties, |
3423 int start_position, int end_position) { | 3438 int start_position, int end_position) { |
3424 return new (parser_zone_) | 3439 return new (parser_zone_) |
3425 ClassLiteral(parser_zone_, scope, proxy, extends, constructor, | 3440 ClassLiteral(parser_zone_, scope, proxy, extends, constructor, |
3426 properties, start_position, end_position); | 3441 properties, start_position, end_position); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3490 // the parser-level zone. | 3505 // the parser-level zone. |
3491 Zone* parser_zone_; | 3506 Zone* parser_zone_; |
3492 AstValueFactory* ast_value_factory_; | 3507 AstValueFactory* ast_value_factory_; |
3493 }; | 3508 }; |
3494 | 3509 |
3495 | 3510 |
3496 } // namespace internal | 3511 } // namespace internal |
3497 } // namespace v8 | 3512 } // namespace v8 |
3498 | 3513 |
3499 #endif // V8_AST_AST_H_ | 3514 #endif // V8_AST_AST_H_ |
OLD | NEW |