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/ast/ast-value-factory.h" | 8 #include "src/ast/ast-value-factory.h" |
9 #include "src/ast/modules.h" | 9 #include "src/ast/modules.h" |
10 #include "src/ast/variables.h" | 10 #include "src/ast/variables.h" |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 467 |
468 | 468 |
469 class DoExpression final : public Expression { | 469 class DoExpression final : public Expression { |
470 public: | 470 public: |
471 DECLARE_NODE_TYPE(DoExpression) | 471 DECLARE_NODE_TYPE(DoExpression) |
472 | 472 |
473 Block* block() { return block_; } | 473 Block* block() { return block_; } |
474 void set_block(Block* b) { block_ = b; } | 474 void set_block(Block* b) { block_ = b; } |
475 VariableProxy* result() { return result_; } | 475 VariableProxy* result() { return result_; } |
476 void set_result(VariableProxy* v) { result_ = v; } | 476 void set_result(VariableProxy* v) { result_ = v; } |
| 477 FunctionLiteral* represented_function() { return represented_function_; } |
| 478 void set_represented_function(FunctionLiteral* f) { |
| 479 represented_function_ = f; |
| 480 } |
| 481 bool IsAnonymousFunctionDefinition() const; |
477 | 482 |
478 protected: | 483 protected: |
479 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) | 484 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) |
480 : Expression(zone, pos, kDoExpression), block_(block), result_(result) { | 485 : Expression(zone, pos, kDoExpression), |
| 486 block_(block), |
| 487 result_(result), |
| 488 represented_function_(nullptr) { |
481 DCHECK_NOT_NULL(block_); | 489 DCHECK_NOT_NULL(block_); |
482 DCHECK_NOT_NULL(result_); | 490 DCHECK_NOT_NULL(result_); |
483 } | 491 } |
484 static int parent_num_ids() { return Expression::num_ids(); } | 492 static int parent_num_ids() { return Expression::num_ids(); } |
485 | 493 |
486 private: | 494 private: |
487 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 495 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
488 | 496 |
489 Block* block_; | 497 Block* block_; |
490 VariableProxy* result_; | 498 VariableProxy* result_; |
| 499 FunctionLiteral* represented_function_; |
491 }; | 500 }; |
492 | 501 |
493 | 502 |
494 class Declaration : public AstNode { | 503 class Declaration : public AstNode { |
495 public: | 504 public: |
496 VariableProxy* proxy() const { return proxy_; } | 505 VariableProxy* proxy() const { return proxy_; } |
497 VariableMode mode() const { return mode_; } | 506 VariableMode mode() const { return mode_; } |
498 Scope* scope() const { return scope_; } | 507 Scope* scope() const { return scope_; } |
499 InitializationFlag initialization() const; | 508 InitializationFlag initialization() const; |
500 | 509 |
(...skipping 2207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 AstProperties ast_properties_; | 2717 AstProperties ast_properties_; |
2709 }; | 2718 }; |
2710 | 2719 |
2711 | 2720 |
2712 class ClassLiteral final : public Expression { | 2721 class ClassLiteral final : public Expression { |
2713 public: | 2722 public: |
2714 typedef ObjectLiteralProperty Property; | 2723 typedef ObjectLiteralProperty Property; |
2715 | 2724 |
2716 DECLARE_NODE_TYPE(ClassLiteral) | 2725 DECLARE_NODE_TYPE(ClassLiteral) |
2717 | 2726 |
2718 Scope* scope() const { return scope_; } | |
2719 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } | 2727 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } |
2720 Expression* extends() const { return extends_; } | 2728 Expression* extends() const { return extends_; } |
2721 void set_extends(Expression* e) { extends_ = e; } | 2729 void set_extends(Expression* e) { extends_ = e; } |
2722 FunctionLiteral* constructor() const { return constructor_; } | 2730 FunctionLiteral* constructor() const { return constructor_; } |
2723 void set_constructor(FunctionLiteral* f) { constructor_ = f; } | 2731 void set_constructor(FunctionLiteral* f) { constructor_ = f; } |
2724 ZoneList<Property*>* properties() const { return properties_; } | 2732 ZoneList<Property*>* properties() const { return properties_; } |
2725 int start_position() const { return position(); } | 2733 int start_position() const { return position(); } |
2726 int end_position() const { return end_position_; } | 2734 int end_position() const { return end_position_; } |
2727 | 2735 |
2728 BailoutId EntryId() const { return BailoutId(local_id(0)); } | 2736 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
2729 BailoutId DeclsId() const { return BailoutId(local_id(1)); } | 2737 BailoutId PrototypeId() { return BailoutId(local_id(1)); } |
2730 BailoutId ExitId() { return BailoutId(local_id(2)); } | |
2731 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); } | |
2732 BailoutId PrototypeId() { return BailoutId(local_id(4)); } | |
2733 | 2738 |
2734 // Return an AST id for a property that is used in simulate instructions. | 2739 // Return an AST id for a property that is used in simulate instructions. |
2735 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 5)); } | 2740 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 2)); } |
2736 | 2741 |
2737 // Unlike other AST nodes, this number of bailout IDs allocated for an | 2742 // Unlike other AST nodes, this number of bailout IDs allocated for an |
2738 // ClassLiteral can vary, so num_ids() is not a static method. | 2743 // ClassLiteral can vary, so num_ids() is not a static method. |
2739 int num_ids() const { return parent_num_ids() + 5 + properties()->length(); } | 2744 int num_ids() const { return parent_num_ids() + 2 + properties()->length(); } |
2740 | 2745 |
2741 // Object literals need one feedback slot for each non-trivial value, as well | 2746 // Object literals need one feedback slot for each non-trivial value, as well |
2742 // as some slots for home objects. | 2747 // as some slots for home objects. |
2743 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 2748 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
2744 FeedbackVectorSlotCache* cache); | 2749 FeedbackVectorSlotCache* cache); |
2745 | 2750 |
2746 bool NeedsProxySlot() const { | 2751 bool NeedsProxySlot() const { |
2747 return class_variable_proxy() != nullptr && | 2752 return class_variable_proxy() != nullptr && |
2748 class_variable_proxy()->var()->IsUnallocated(); | 2753 class_variable_proxy()->var()->IsUnallocated(); |
2749 } | 2754 } |
2750 | 2755 |
2751 FeedbackVectorSlot PrototypeSlot() const { return prototype_slot_; } | 2756 FeedbackVectorSlot PrototypeSlot() const { return prototype_slot_; } |
2752 FeedbackVectorSlot ProxySlot() const { return proxy_slot_; } | 2757 FeedbackVectorSlot ProxySlot() const { return proxy_slot_; } |
2753 | 2758 |
2754 bool IsAnonymousFunctionDefinition() const { | |
2755 return constructor()->raw_name()->length() == 0; | |
2756 } | |
2757 | 2759 |
2758 protected: | 2760 protected: |
2759 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy, | 2761 ClassLiteral(Zone* zone, VariableProxy* class_variable_proxy, |
2760 Expression* extends, FunctionLiteral* constructor, | 2762 Expression* extends, FunctionLiteral* constructor, |
2761 ZoneList<Property*>* properties, int start_position, | 2763 ZoneList<Property*>* properties, int start_position, |
2762 int end_position) | 2764 int end_position) |
2763 : Expression(zone, start_position, kClassLiteral), | 2765 : Expression(zone, start_position, kClassLiteral), |
2764 end_position_(end_position), | 2766 end_position_(end_position), |
2765 scope_(scope), | |
2766 class_variable_proxy_(class_variable_proxy), | 2767 class_variable_proxy_(class_variable_proxy), |
2767 extends_(extends), | 2768 extends_(extends), |
2768 constructor_(constructor), | 2769 constructor_(constructor), |
2769 properties_(properties) {} | 2770 properties_(properties) {} |
2770 | 2771 |
2771 static int parent_num_ids() { return Expression::num_ids(); } | 2772 static int parent_num_ids() { return Expression::num_ids(); } |
2772 | 2773 |
2773 private: | 2774 private: |
2774 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2775 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
2775 | 2776 |
2776 int end_position_; | 2777 int end_position_; |
2777 FeedbackVectorSlot prototype_slot_; | 2778 FeedbackVectorSlot prototype_slot_; |
2778 FeedbackVectorSlot proxy_slot_; | 2779 FeedbackVectorSlot proxy_slot_; |
2779 Scope* scope_; | |
2780 VariableProxy* class_variable_proxy_; | 2780 VariableProxy* class_variable_proxy_; |
2781 Expression* extends_; | 2781 Expression* extends_; |
2782 FunctionLiteral* constructor_; | 2782 FunctionLiteral* constructor_; |
2783 ZoneList<Property*>* properties_; | 2783 ZoneList<Property*>* properties_; |
2784 }; | 2784 }; |
2785 | 2785 |
2786 | 2786 |
2787 class NativeFunctionLiteral final : public Expression { | 2787 class NativeFunctionLiteral final : public Expression { |
2788 public: | 2788 public: |
2789 DECLARE_NODE_TYPE(NativeFunctionLiteral) | 2789 DECLARE_NODE_TYPE(NativeFunctionLiteral) |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3418 int expected_property_count) { | 3418 int expected_property_count) { |
3419 return new (local_zone_) FunctionLiteral( | 3419 return new (local_zone_) FunctionLiteral( |
3420 local_zone_, ast_value_factory_->empty_string(), ast_value_factory_, | 3420 local_zone_, ast_value_factory_->empty_string(), ast_value_factory_, |
3421 scope, body, materialized_literal_count, expected_property_count, 0, | 3421 scope, body, materialized_literal_count, expected_property_count, 0, |
3422 FunctionLiteral::kAnonymousExpression, | 3422 FunctionLiteral::kAnonymousExpression, |
3423 FunctionLiteral::kNoDuplicateParameters, | 3423 FunctionLiteral::kNoDuplicateParameters, |
3424 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, | 3424 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, |
3425 false); | 3425 false); |
3426 } | 3426 } |
3427 | 3427 |
3428 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy, | 3428 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, |
3429 Expression* extends, | |
3430 FunctionLiteral* constructor, | 3429 FunctionLiteral* constructor, |
3431 ZoneList<ObjectLiteral::Property*>* properties, | 3430 ZoneList<ObjectLiteral::Property*>* properties, |
3432 int start_position, int end_position) { | 3431 int start_position, int end_position) { |
3433 return new (local_zone_) | 3432 return new (local_zone_) |
3434 ClassLiteral(local_zone_, scope, proxy, extends, constructor, | 3433 ClassLiteral(local_zone_, proxy, extends, constructor, properties, |
3435 properties, start_position, end_position); | 3434 start_position, end_position); |
3436 } | 3435 } |
3437 | 3436 |
3438 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, | 3437 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, |
3439 v8::Extension* extension, | 3438 v8::Extension* extension, |
3440 int pos) { | 3439 int pos) { |
3441 return new (local_zone_) | 3440 return new (local_zone_) |
3442 NativeFunctionLiteral(local_zone_, name, extension, pos); | 3441 NativeFunctionLiteral(local_zone_, name, extension, pos); |
3443 } | 3442 } |
3444 | 3443 |
3445 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) { | 3444 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3539 : NULL; \ | 3538 : NULL; \ |
3540 } | 3539 } |
3541 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3540 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3542 #undef DECLARE_NODE_FUNCTIONS | 3541 #undef DECLARE_NODE_FUNCTIONS |
3543 | 3542 |
3544 | 3543 |
3545 } // namespace internal | 3544 } // namespace internal |
3546 } // namespace v8 | 3545 } // namespace v8 |
3547 | 3546 |
3548 #endif // V8_AST_AST_H_ | 3547 #endif // V8_AST_AST_H_ |
OLD | NEW |