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_H_ | 5 #ifndef V8_AST_H_ |
6 #define V8_AST_H_ | 6 #define V8_AST_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/assembler.h" | 10 #include "src/assembler.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 bool IsNullLiteral() const; | 365 bool IsNullLiteral() const; |
366 | 366 |
367 // True if we can prove that the expression is the undefined literal. | 367 // True if we can prove that the expression is the undefined literal. |
368 bool IsUndefinedLiteral(Isolate* isolate) const; | 368 bool IsUndefinedLiteral(Isolate* isolate) const; |
369 | 369 |
370 // Expression type bounds | 370 // Expression type bounds |
371 Bounds bounds() const { return bounds_; } | 371 Bounds bounds() const { return bounds_; } |
372 void set_bounds(Bounds bounds) { bounds_ = bounds; } | 372 void set_bounds(Bounds bounds) { bounds_ = bounds; } |
373 | 373 |
374 // Whether the expression is parenthesized | 374 // Whether the expression is parenthesized |
375 bool is_parenthesized() const { | 375 bool is_single_parenthesized() const { |
376 return IsParenthesizedField::decode(bit_field_); | 376 return IsSingleParenthesizedField::decode(bit_field_); |
377 } | 377 } |
378 bool is_multi_parenthesized() const { | 378 bool is_multi_parenthesized() const { |
379 return IsMultiParenthesizedField::decode(bit_field_); | 379 return IsMultiParenthesizedField::decode(bit_field_); |
380 } | 380 } |
381 void increase_parenthesization_level() { | 381 void increase_parenthesization_level() { |
382 bit_field_ = | 382 bit_field_ = IsMultiParenthesizedField::update(bit_field_, |
383 IsMultiParenthesizedField::update(bit_field_, is_parenthesized()); | 383 is_single_parenthesized()); |
384 bit_field_ = IsParenthesizedField::update(bit_field_, true); | 384 bit_field_ = IsSingleParenthesizedField::update(bit_field_, true); |
385 } | 385 } |
386 | 386 |
387 // Type feedback information for assignments and properties. | 387 // Type feedback information for assignments and properties. |
388 virtual bool IsMonomorphic() { | 388 virtual bool IsMonomorphic() { |
389 UNREACHABLE(); | 389 UNREACHABLE(); |
390 return false; | 390 return false; |
391 } | 391 } |
392 virtual SmallMapList* GetReceiverTypes() { | 392 virtual SmallMapList* GetReceiverTypes() { |
393 UNREACHABLE(); | 393 UNREACHABLE(); |
394 return NULL; | 394 return NULL; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 DCHECK(!BailoutId(base_id_).IsNone()); | 428 DCHECK(!BailoutId(base_id_).IsNone()); |
429 return base_id_; | 429 return base_id_; |
430 } | 430 } |
431 | 431 |
432 private: | 432 private: |
433 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 433 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
434 | 434 |
435 int base_id_; | 435 int base_id_; |
436 Bounds bounds_; | 436 Bounds bounds_; |
437 class ToBooleanTypesField : public BitField16<byte, 0, 8> {}; | 437 class ToBooleanTypesField : public BitField16<byte, 0, 8> {}; |
438 class IsParenthesizedField : public BitField16<bool, 8, 1> {}; | 438 class IsSingleParenthesizedField : public BitField16<bool, 8, 1> {}; |
439 class IsMultiParenthesizedField : public BitField16<bool, 9, 1> {}; | 439 class IsMultiParenthesizedField : public BitField16<bool, 9, 1> {}; |
440 uint16_t bit_field_; | 440 uint16_t bit_field_; |
441 // Ends with 16-bit field; deriving classes in turn begin with | 441 // Ends with 16-bit field; deriving classes in turn begin with |
442 // 16-bit fields for optimum packing efficiency. | 442 // 16-bit fields for optimum packing efficiency. |
443 }; | 443 }; |
444 | 444 |
445 | 445 |
446 class BreakableStatement : public Statement { | 446 class BreakableStatement : public Statement { |
447 public: | 447 public: |
448 enum BreakableType { | 448 enum BreakableType { |
(...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2497 enum ParameterFlag { | 2497 enum ParameterFlag { |
2498 kNoDuplicateParameters = 0, | 2498 kNoDuplicateParameters = 0, |
2499 kHasDuplicateParameters = 1 | 2499 kHasDuplicateParameters = 1 |
2500 }; | 2500 }; |
2501 | 2501 |
2502 enum IsFunctionFlag { | 2502 enum IsFunctionFlag { |
2503 kGlobalOrEval, | 2503 kGlobalOrEval, |
2504 kIsFunction | 2504 kIsFunction |
2505 }; | 2505 }; |
2506 | 2506 |
2507 enum IsParenthesizedFlag { | 2507 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; |
2508 kIsParenthesized, | |
2509 kNotParenthesized | |
2510 }; | |
2511 | 2508 |
2512 enum ArityRestriction { | 2509 enum ArityRestriction { |
2513 NORMAL_ARITY, | 2510 NORMAL_ARITY, |
2514 GETTER_ARITY, | 2511 GETTER_ARITY, |
2515 SETTER_ARITY | 2512 SETTER_ARITY |
2516 }; | 2513 }; |
2517 | 2514 |
2518 DECLARE_NODE_TYPE(FunctionLiteral) | 2515 DECLARE_NODE_TYPE(FunctionLiteral) |
2519 | 2516 |
2520 Handle<String> name() const { return raw_name_->string(); } | 2517 Handle<String> name() const { return raw_name_->string(); } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2590 return HasDuplicateParameters::decode(bitfield_); | 2587 return HasDuplicateParameters::decode(bitfield_); |
2591 } | 2588 } |
2592 | 2589 |
2593 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; } | 2590 bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; } |
2594 | 2591 |
2595 // This is used as a heuristic on when to eagerly compile a function | 2592 // This is used as a heuristic on when to eagerly compile a function |
2596 // literal. We consider the following constructs as hints that the | 2593 // literal. We consider the following constructs as hints that the |
2597 // function will be called immediately: | 2594 // function will be called immediately: |
2598 // - (function() { ... })(); | 2595 // - (function() { ... })(); |
2599 // - var x = function() { ... }(); | 2596 // - var x = function() { ... }(); |
2600 bool is_parenthesized() { | 2597 bool should_eager_compile() const { |
2601 return IsParenthesized::decode(bitfield_) == kIsParenthesized; | 2598 return EagerCompileHintBit::decode(bitfield_) == kShouldEagerCompile; |
2602 } | 2599 } |
2603 void set_parenthesized() { | 2600 void set_should_eager_compile() { |
2604 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); | 2601 bitfield_ = EagerCompileHintBit::update(bitfield_, kShouldEagerCompile); |
2605 } | 2602 } |
2606 | 2603 |
2607 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); } | 2604 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); } |
2608 | 2605 |
2609 int ast_node_count() { return ast_properties_.node_count(); } | 2606 int ast_node_count() { return ast_properties_.node_count(); } |
2610 AstProperties::Flags* flags() { return ast_properties_.flags(); } | 2607 AstProperties::Flags* flags() { return ast_properties_.flags(); } |
2611 void set_ast_properties(AstProperties* ast_properties) { | 2608 void set_ast_properties(AstProperties* ast_properties) { |
2612 ast_properties_ = *ast_properties; | 2609 ast_properties_ = *ast_properties; |
2613 } | 2610 } |
2614 const ZoneFeedbackVectorSpec* feedback_vector_spec() const { | 2611 const ZoneFeedbackVectorSpec* feedback_vector_spec() const { |
2615 return ast_properties_.get_spec(); | 2612 return ast_properties_.get_spec(); |
2616 } | 2613 } |
2617 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } | 2614 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } |
2618 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } | 2615 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } |
2619 void set_dont_optimize_reason(BailoutReason reason) { | 2616 void set_dont_optimize_reason(BailoutReason reason) { |
2620 dont_optimize_reason_ = reason; | 2617 dont_optimize_reason_ = reason; |
2621 } | 2618 } |
2622 | 2619 |
2623 protected: | 2620 protected: |
2624 FunctionLiteral(Zone* zone, const AstRawString* name, | 2621 FunctionLiteral(Zone* zone, const AstRawString* name, |
2625 AstValueFactory* ast_value_factory, Scope* scope, | 2622 AstValueFactory* ast_value_factory, Scope* scope, |
2626 ZoneList<Statement*>* body, int materialized_literal_count, | 2623 ZoneList<Statement*>* body, int materialized_literal_count, |
2627 int expected_property_count, int handler_count, | 2624 int expected_property_count, int handler_count, |
2628 int parameter_count, FunctionType function_type, | 2625 int parameter_count, FunctionType function_type, |
2629 ParameterFlag has_duplicate_parameters, | 2626 ParameterFlag has_duplicate_parameters, |
2630 IsFunctionFlag is_function, | 2627 IsFunctionFlag is_function, |
2631 IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 2628 EagerCompileHint eager_compile_hint, FunctionKind kind, |
2632 int position) | 2629 int position) |
2633 : Expression(zone, position), | 2630 : Expression(zone, position), |
2634 raw_name_(name), | 2631 raw_name_(name), |
2635 scope_(scope), | 2632 scope_(scope), |
2636 body_(body), | 2633 body_(body), |
2637 raw_inferred_name_(ast_value_factory->empty_string()), | 2634 raw_inferred_name_(ast_value_factory->empty_string()), |
2638 ast_properties_(zone), | 2635 ast_properties_(zone), |
2639 dont_optimize_reason_(kNoReason), | 2636 dont_optimize_reason_(kNoReason), |
2640 materialized_literal_count_(materialized_literal_count), | 2637 materialized_literal_count_(materialized_literal_count), |
2641 expected_property_count_(expected_property_count), | 2638 expected_property_count_(expected_property_count), |
2642 handler_count_(handler_count), | 2639 handler_count_(handler_count), |
2643 parameter_count_(parameter_count), | 2640 parameter_count_(parameter_count), |
2644 function_token_position_(RelocInfo::kNoPosition) { | 2641 function_token_position_(RelocInfo::kNoPosition) { |
2645 bitfield_ = IsExpression::encode(function_type != DECLARATION) | | 2642 bitfield_ = IsExpression::encode(function_type != DECLARATION) | |
2646 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | | 2643 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | |
2647 Pretenure::encode(false) | | 2644 Pretenure::encode(false) | |
2648 HasDuplicateParameters::encode(has_duplicate_parameters) | | 2645 HasDuplicateParameters::encode(has_duplicate_parameters) | |
2649 IsFunction::encode(is_function) | | 2646 IsFunction::encode(is_function) | |
2650 IsParenthesized::encode(is_parenthesized) | | 2647 EagerCompileHintBit::encode(eager_compile_hint) | |
2651 FunctionKindBits::encode(kind); | 2648 FunctionKindBits::encode(kind); |
2652 DCHECK(IsValidFunctionKind(kind)); | 2649 DCHECK(IsValidFunctionKind(kind)); |
2653 } | 2650 } |
2654 | 2651 |
2655 private: | 2652 private: |
2656 const AstRawString* raw_name_; | 2653 const AstRawString* raw_name_; |
2657 Handle<String> name_; | 2654 Handle<String> name_; |
2658 Handle<SharedFunctionInfo> shared_info_; | 2655 Handle<SharedFunctionInfo> shared_info_; |
2659 Scope* scope_; | 2656 Scope* scope_; |
2660 ZoneList<Statement*>* body_; | 2657 ZoneList<Statement*>* body_; |
2661 const AstString* raw_inferred_name_; | 2658 const AstString* raw_inferred_name_; |
2662 Handle<String> inferred_name_; | 2659 Handle<String> inferred_name_; |
2663 AstProperties ast_properties_; | 2660 AstProperties ast_properties_; |
2664 BailoutReason dont_optimize_reason_; | 2661 BailoutReason dont_optimize_reason_; |
2665 | 2662 |
2666 int materialized_literal_count_; | 2663 int materialized_literal_count_; |
2667 int expected_property_count_; | 2664 int expected_property_count_; |
2668 int handler_count_; | 2665 int handler_count_; |
2669 int parameter_count_; | 2666 int parameter_count_; |
2670 int function_token_position_; | 2667 int function_token_position_; |
2671 | 2668 |
2672 unsigned bitfield_; | 2669 unsigned bitfield_; |
2673 class IsExpression : public BitField<bool, 0, 1> {}; | 2670 class IsExpression : public BitField<bool, 0, 1> {}; |
2674 class IsAnonymous : public BitField<bool, 1, 1> {}; | 2671 class IsAnonymous : public BitField<bool, 1, 1> {}; |
2675 class Pretenure : public BitField<bool, 2, 1> {}; | 2672 class Pretenure : public BitField<bool, 2, 1> {}; |
2676 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; | 2673 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; |
2677 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; | 2674 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; |
2678 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {}; | 2675 class EagerCompileHintBit : public BitField<EagerCompileHint, 5, 1> {}; |
2679 class FunctionKindBits : public BitField<FunctionKind, 6, 8> {}; | 2676 class FunctionKindBits : public BitField<FunctionKind, 6, 8> {}; |
2680 }; | 2677 }; |
2681 | 2678 |
2682 | 2679 |
2683 class ClassLiteral final : public Expression { | 2680 class ClassLiteral final : public Expression { |
2684 public: | 2681 public: |
2685 typedef ObjectLiteralProperty Property; | 2682 typedef ObjectLiteralProperty Property; |
2686 | 2683 |
2687 DECLARE_NODE_TYPE(ClassLiteral) | 2684 DECLARE_NODE_TYPE(ClassLiteral) |
2688 | 2685 |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 return new (zone_) Throw(zone_, exception, pos); | 3549 return new (zone_) Throw(zone_, exception, pos); |
3553 } | 3550 } |
3554 | 3551 |
3555 FunctionLiteral* NewFunctionLiteral( | 3552 FunctionLiteral* NewFunctionLiteral( |
3556 const AstRawString* name, AstValueFactory* ast_value_factory, | 3553 const AstRawString* name, AstValueFactory* ast_value_factory, |
3557 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, | 3554 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, |
3558 int expected_property_count, int handler_count, int parameter_count, | 3555 int expected_property_count, int handler_count, int parameter_count, |
3559 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3556 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3560 FunctionLiteral::FunctionType function_type, | 3557 FunctionLiteral::FunctionType function_type, |
3561 FunctionLiteral::IsFunctionFlag is_function, | 3558 FunctionLiteral::IsFunctionFlag is_function, |
3562 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, | 3559 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, |
3563 int position) { | 3560 int position) { |
3564 return new (zone_) FunctionLiteral( | 3561 return new (zone_) FunctionLiteral( |
3565 zone_, name, ast_value_factory, scope, body, materialized_literal_count, | 3562 zone_, name, ast_value_factory, scope, body, materialized_literal_count, |
3566 expected_property_count, handler_count, parameter_count, function_type, | 3563 expected_property_count, handler_count, parameter_count, function_type, |
3567 has_duplicate_parameters, is_function, is_parenthesized, kind, | 3564 has_duplicate_parameters, is_function, eager_compile_hint, kind, |
3568 position); | 3565 position); |
3569 } | 3566 } |
3570 | 3567 |
3571 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope, | 3568 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope, |
3572 VariableProxy* proxy, Expression* extends, | 3569 VariableProxy* proxy, Expression* extends, |
3573 FunctionLiteral* constructor, | 3570 FunctionLiteral* constructor, |
3574 ZoneList<ObjectLiteral::Property*>* properties, | 3571 ZoneList<ObjectLiteral::Property*>* properties, |
3575 int start_position, int end_position) { | 3572 int start_position, int end_position) { |
3576 return new (zone_) | 3573 return new (zone_) |
3577 ClassLiteral(zone_, name, scope, proxy, extends, constructor, | 3574 ClassLiteral(zone_, name, scope, proxy, extends, constructor, |
(...skipping 16 matching lines...) Expand all Loading... |
3594 | 3591 |
3595 private: | 3592 private: |
3596 Zone* zone_; | 3593 Zone* zone_; |
3597 AstValueFactory* ast_value_factory_; | 3594 AstValueFactory* ast_value_factory_; |
3598 }; | 3595 }; |
3599 | 3596 |
3600 | 3597 |
3601 } } // namespace v8::internal | 3598 } } // namespace v8::internal |
3602 | 3599 |
3603 #endif // V8_AST_H_ | 3600 #endif // V8_AST_H_ |
OLD | NEW |