| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 #define CALL_NODE_LIST(V) \ | 81 #define CALL_NODE_LIST(V) \ |
| 82 V(Call) \ | 82 V(Call) \ |
| 83 V(CallNew) | 83 V(CallNew) |
| 84 | 84 |
| 85 #define EXPRESSION_NODE_LIST(V) \ | 85 #define EXPRESSION_NODE_LIST(V) \ |
| 86 LITERAL_NODE_LIST(V) \ | 86 LITERAL_NODE_LIST(V) \ |
| 87 PROPERTY_NODE_LIST(V) \ | 87 PROPERTY_NODE_LIST(V) \ |
| 88 CALL_NODE_LIST(V) \ | 88 CALL_NODE_LIST(V) \ |
| 89 V(FunctionLiteral) \ | 89 V(FunctionLiteral) \ |
| 90 V(ClassLiteral) \ | |
| 91 V(NativeFunctionLiteral) \ | 90 V(NativeFunctionLiteral) \ |
| 92 V(Conditional) \ | 91 V(Conditional) \ |
| 93 V(VariableProxy) \ | 92 V(VariableProxy) \ |
| 94 V(Literal) \ | 93 V(Literal) \ |
| 95 V(Yield) \ | 94 V(Yield) \ |
| 96 V(Throw) \ | 95 V(Throw) \ |
| 97 V(CallRuntime) \ | 96 V(CallRuntime) \ |
| 98 V(UnaryOperation) \ | 97 V(UnaryOperation) \ |
| 99 V(BinaryOperation) \ | 98 V(BinaryOperation) \ |
| 100 V(CompareOperation) \ | 99 V(CompareOperation) \ |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 471 |
| 473 | 472 |
| 474 class DoExpression final : public Expression { | 473 class DoExpression final : public Expression { |
| 475 public: | 474 public: |
| 476 DECLARE_NODE_TYPE(DoExpression) | 475 DECLARE_NODE_TYPE(DoExpression) |
| 477 | 476 |
| 478 Block* block() { return block_; } | 477 Block* block() { return block_; } |
| 479 void set_block(Block* b) { block_ = b; } | 478 void set_block(Block* b) { block_ = b; } |
| 480 VariableProxy* result() { return result_; } | 479 VariableProxy* result() { return result_; } |
| 481 void set_result(VariableProxy* v) { result_ = v; } | 480 void set_result(VariableProxy* v) { result_ = v; } |
| 481 FunctionLiteral* represented_function() { return represented_function_; } |
| 482 void set_represented_function(FunctionLiteral* f) { |
| 483 represented_function_ = f; |
| 484 } |
| 485 |
| 486 bool IsAnonymousFunctionDefinition() const; |
| 482 | 487 |
| 483 protected: | 488 protected: |
| 484 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) | 489 DoExpression(Zone* zone, Block* block, VariableProxy* result, int pos) |
| 485 : Expression(zone, pos), block_(block), result_(result) { | 490 : Expression(zone, pos), |
| 491 block_(block), |
| 492 result_(result), |
| 493 represented_function_(nullptr) { |
| 486 DCHECK_NOT_NULL(block_); | 494 DCHECK_NOT_NULL(block_); |
| 487 DCHECK_NOT_NULL(result_); | 495 DCHECK_NOT_NULL(result_); |
| 488 } | 496 } |
| 489 static int parent_num_ids() { return Expression::num_ids(); } | 497 static int parent_num_ids() { return Expression::num_ids(); } |
| 490 | 498 |
| 491 private: | 499 private: |
| 492 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 500 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 493 | 501 |
| 494 Block* block_; | 502 Block* block_; |
| 495 VariableProxy* result_; | 503 VariableProxy* result_; |
| 504 FunctionLiteral* represented_function_; |
| 496 }; | 505 }; |
| 497 | 506 |
| 498 | 507 |
| 499 class Declaration : public AstNode { | 508 class Declaration : public AstNode { |
| 500 public: | 509 public: |
| 501 VariableProxy* proxy() const { return proxy_; } | 510 VariableProxy* proxy() const { return proxy_; } |
| 502 VariableMode mode() const { return mode_; } | 511 VariableMode mode() const { return mode_; } |
| 503 Scope* scope() const { return scope_; } | 512 Scope* scope() const { return scope_; } |
| 504 InitializationFlag initialization() const; | 513 InitializationFlag initialization() const; |
| 505 | 514 |
| (...skipping 2222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2728 BailoutReason dont_optimize_reason_; | 2737 BailoutReason dont_optimize_reason_; |
| 2729 | 2738 |
| 2730 int materialized_literal_count_; | 2739 int materialized_literal_count_; |
| 2731 int expected_property_count_; | 2740 int expected_property_count_; |
| 2732 int parameter_count_; | 2741 int parameter_count_; |
| 2733 int function_token_position_; | 2742 int function_token_position_; |
| 2734 int yield_count_; | 2743 int yield_count_; |
| 2735 }; | 2744 }; |
| 2736 | 2745 |
| 2737 | 2746 |
| 2738 class ClassLiteral final : public Expression { | |
| 2739 public: | |
| 2740 typedef ObjectLiteralProperty Property; | |
| 2741 | |
| 2742 DECLARE_NODE_TYPE(ClassLiteral) | |
| 2743 | |
| 2744 Scope* scope() const { return scope_; } | |
| 2745 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } | |
| 2746 Expression* extends() const { return extends_; } | |
| 2747 void set_extends(Expression* e) { extends_ = e; } | |
| 2748 FunctionLiteral* constructor() const { return constructor_; } | |
| 2749 void set_constructor(FunctionLiteral* f) { constructor_ = f; } | |
| 2750 ZoneList<Property*>* properties() const { return properties_; } | |
| 2751 int start_position() const { return position(); } | |
| 2752 int end_position() const { return end_position_; } | |
| 2753 | |
| 2754 BailoutId EntryId() const { return BailoutId(local_id(0)); } | |
| 2755 BailoutId DeclsId() const { return BailoutId(local_id(1)); } | |
| 2756 BailoutId ExitId() { return BailoutId(local_id(2)); } | |
| 2757 BailoutId CreateLiteralId() const { return BailoutId(local_id(3)); } | |
| 2758 BailoutId PrototypeId() { return BailoutId(local_id(4)); } | |
| 2759 | |
| 2760 // Return an AST id for a property that is used in simulate instructions. | |
| 2761 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 5)); } | |
| 2762 | |
| 2763 // Unlike other AST nodes, this number of bailout IDs allocated for an | |
| 2764 // ClassLiteral can vary, so num_ids() is not a static method. | |
| 2765 int num_ids() const { return parent_num_ids() + 5 + properties()->length(); } | |
| 2766 | |
| 2767 // Object literals need one feedback slot for each non-trivial value, as well | |
| 2768 // as some slots for home objects. | |
| 2769 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | |
| 2770 FeedbackVectorSlotCache* cache); | |
| 2771 | |
| 2772 bool NeedsProxySlot() const { | |
| 2773 return class_variable_proxy() != nullptr && | |
| 2774 class_variable_proxy()->var()->IsUnallocated(); | |
| 2775 } | |
| 2776 | |
| 2777 FeedbackVectorSlot PrototypeSlot() const { return prototype_slot_; } | |
| 2778 FeedbackVectorSlot ProxySlot() const { return proxy_slot_; } | |
| 2779 | |
| 2780 bool IsAnonymousFunctionDefinition() const { | |
| 2781 return constructor()->raw_name()->length() == 0; | |
| 2782 } | |
| 2783 | |
| 2784 protected: | |
| 2785 ClassLiteral(Zone* zone, Scope* scope, VariableProxy* class_variable_proxy, | |
| 2786 Expression* extends, FunctionLiteral* constructor, | |
| 2787 ZoneList<Property*>* properties, int start_position, | |
| 2788 int end_position) | |
| 2789 : Expression(zone, start_position), | |
| 2790 scope_(scope), | |
| 2791 class_variable_proxy_(class_variable_proxy), | |
| 2792 extends_(extends), | |
| 2793 constructor_(constructor), | |
| 2794 properties_(properties), | |
| 2795 end_position_(end_position) {} | |
| 2796 | |
| 2797 static int parent_num_ids() { return Expression::num_ids(); } | |
| 2798 | |
| 2799 private: | |
| 2800 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | |
| 2801 | |
| 2802 Scope* scope_; | |
| 2803 VariableProxy* class_variable_proxy_; | |
| 2804 Expression* extends_; | |
| 2805 FunctionLiteral* constructor_; | |
| 2806 ZoneList<Property*>* properties_; | |
| 2807 int end_position_; | |
| 2808 FeedbackVectorSlot prototype_slot_; | |
| 2809 FeedbackVectorSlot proxy_slot_; | |
| 2810 }; | |
| 2811 | |
| 2812 | |
| 2813 class NativeFunctionLiteral final : public Expression { | 2747 class NativeFunctionLiteral final : public Expression { |
| 2814 public: | 2748 public: |
| 2815 DECLARE_NODE_TYPE(NativeFunctionLiteral) | 2749 DECLARE_NODE_TYPE(NativeFunctionLiteral) |
| 2816 | 2750 |
| 2817 Handle<String> name() const { return name_->string(); } | 2751 Handle<String> name() const { return name_->string(); } |
| 2818 v8::Extension* extension() const { return extension_; } | 2752 v8::Extension* extension() const { return extension_; } |
| 2819 | 2753 |
| 2820 protected: | 2754 protected: |
| 2821 NativeFunctionLiteral(Zone* zone, const AstRawString* name, | 2755 NativeFunctionLiteral(Zone* zone, const AstRawString* name, |
| 2822 v8::Extension* extension, int pos) | 2756 v8::Extension* extension, int pos) |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3425 int expected_property_count) { | 3359 int expected_property_count) { |
| 3426 return new (parser_zone_) FunctionLiteral( | 3360 return new (parser_zone_) FunctionLiteral( |
| 3427 parser_zone_, ast_value_factory_->empty_string(), ast_value_factory_, | 3361 parser_zone_, ast_value_factory_->empty_string(), ast_value_factory_, |
| 3428 scope, body, materialized_literal_count, expected_property_count, 0, | 3362 scope, body, materialized_literal_count, expected_property_count, 0, |
| 3429 FunctionLiteral::kAnonymousExpression, | 3363 FunctionLiteral::kAnonymousExpression, |
| 3430 FunctionLiteral::kNoDuplicateParameters, | 3364 FunctionLiteral::kNoDuplicateParameters, |
| 3431 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, | 3365 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, |
| 3432 false); | 3366 false); |
| 3433 } | 3367 } |
| 3434 | 3368 |
| 3435 ClassLiteral* NewClassLiteral(Scope* scope, VariableProxy* proxy, | |
| 3436 Expression* extends, | |
| 3437 FunctionLiteral* constructor, | |
| 3438 ZoneList<ObjectLiteral::Property*>* properties, | |
| 3439 int start_position, int end_position) { | |
| 3440 return new (parser_zone_) | |
| 3441 ClassLiteral(parser_zone_, scope, proxy, extends, constructor, | |
| 3442 properties, start_position, end_position); | |
| 3443 } | |
| 3444 | |
| 3445 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, | 3369 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, |
| 3446 v8::Extension* extension, | 3370 v8::Extension* extension, |
| 3447 int pos) { | 3371 int pos) { |
| 3448 return new (parser_zone_) | 3372 return new (parser_zone_) |
| 3449 NativeFunctionLiteral(parser_zone_, name, extension, pos); | 3373 NativeFunctionLiteral(parser_zone_, name, extension, pos); |
| 3450 } | 3374 } |
| 3451 | 3375 |
| 3452 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) { | 3376 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) { |
| 3453 VariableProxy* result = NewVariableProxy(result_var, pos); | 3377 VariableProxy* result = NewVariableProxy(result_var, pos); |
| 3454 return new (parser_zone_) DoExpression(parser_zone_, block, result, pos); | 3378 return new (parser_zone_) DoExpression(parser_zone_, block, result, pos); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3546 : NULL; \ | 3470 : NULL; \ |
| 3547 } | 3471 } |
| 3548 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3472 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 3549 #undef DECLARE_NODE_FUNCTIONS | 3473 #undef DECLARE_NODE_FUNCTIONS |
| 3550 | 3474 |
| 3551 | 3475 |
| 3552 } // namespace internal | 3476 } // namespace internal |
| 3553 } // namespace v8 | 3477 } // namespace v8 |
| 3554 | 3478 |
| 3555 #endif // V8_AST_AST_H_ | 3479 #endif // V8_AST_AST_H_ |
| OLD | NEW |