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