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-types.h" | 8 #include "src/ast/ast-types.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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 V(CallRuntime) \ | 95 V(CallRuntime) \ |
96 V(UnaryOperation) \ | 96 V(UnaryOperation) \ |
97 V(BinaryOperation) \ | 97 V(BinaryOperation) \ |
98 V(CompareOperation) \ | 98 V(CompareOperation) \ |
99 V(Spread) \ | 99 V(Spread) \ |
100 V(ThisFunction) \ | 100 V(ThisFunction) \ |
101 V(SuperPropertyReference) \ | 101 V(SuperPropertyReference) \ |
102 V(SuperCallReference) \ | 102 V(SuperCallReference) \ |
103 V(CaseClause) \ | 103 V(CaseClause) \ |
104 V(EmptyParentheses) \ | 104 V(EmptyParentheses) \ |
| 105 V(InternalVariable) \ |
105 V(GetIterator) \ | 106 V(GetIterator) \ |
106 V(DoExpression) \ | 107 V(DoExpression) \ |
107 V(RewritableExpression) | 108 V(RewritableExpression) |
108 | 109 |
109 #define AST_NODE_LIST(V) \ | 110 #define AST_NODE_LIST(V) \ |
110 DECLARATION_NODE_LIST(V) \ | 111 DECLARATION_NODE_LIST(V) \ |
111 STATEMENT_NODE_LIST(V) \ | 112 STATEMENT_NODE_LIST(V) \ |
112 EXPRESSION_NODE_LIST(V) | 113 EXPRESSION_NODE_LIST(V) |
113 | 114 |
114 // Forward declarations | 115 // Forward declarations |
(...skipping 2392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2507 : public BitField<bool, Expression::kNextBitFieldIndex, 1> {}; | 2508 : public BitField<bool, Expression::kNextBitFieldIndex, 1> {}; |
2508 }; | 2509 }; |
2509 | 2510 |
2510 // Our Yield is different from the JS yield in that it "returns" its argument as | 2511 // Our Yield is different from the JS yield in that it "returns" its argument as |
2511 // is, without wrapping it in an iterator result object. Such wrapping, if | 2512 // is, without wrapping it in an iterator result object. Such wrapping, if |
2512 // desired, must be done beforehand (see the parser). | 2513 // desired, must be done beforehand (see the parser). |
2513 class Yield final : public Expression { | 2514 class Yield final : public Expression { |
2514 public: | 2515 public: |
2515 enum OnException { kOnExceptionThrow, kOnExceptionRethrow }; | 2516 enum OnException { kOnExceptionThrow, kOnExceptionRethrow }; |
2516 | 2517 |
2517 Expression* generator_object() const { return generator_object_; } | 2518 enum YieldType { kNormal, kAwait }; |
| 2519 |
2518 Expression* expression() const { return expression_; } | 2520 Expression* expression() const { return expression_; } |
2519 OnException on_exception() const { | 2521 OnException on_exception() const { |
2520 return OnExceptionField::decode(bit_field_); | 2522 return OnExceptionField::decode(bit_field_); |
2521 } | 2523 } |
2522 bool rethrow_on_exception() const { | 2524 bool rethrow_on_exception() const { |
2523 return on_exception() == kOnExceptionRethrow; | 2525 return on_exception() == kOnExceptionRethrow; |
2524 } | 2526 } |
2525 int yield_id() const { return yield_id_; } | 2527 int yield_id() const { return yield_id_; } |
| 2528 YieldType yield_type() const { return YieldTypeField::decode(bit_field_); } |
2526 | 2529 |
2527 void set_generator_object(Expression* e) { generator_object_ = e; } | |
2528 void set_expression(Expression* e) { expression_ = e; } | 2530 void set_expression(Expression* e) { expression_ = e; } |
2529 void set_yield_id(int yield_id) { yield_id_ = yield_id; } | 2531 void set_yield_id(int yield_id) { yield_id_ = yield_id; } |
2530 | 2532 |
2531 private: | 2533 private: |
2532 friend class AstNodeFactory; | 2534 friend class AstNodeFactory; |
2533 | 2535 |
2534 Yield(Expression* generator_object, Expression* expression, int pos, | 2536 Yield(Expression* expression, int pos, OnException on_exception, |
2535 OnException on_exception) | 2537 YieldType yield_type) |
2536 : Expression(pos, kYield), | 2538 : Expression(pos, kYield), yield_id_(-1), expression_(expression) { |
2537 yield_id_(-1), | 2539 bit_field_ |= OnExceptionField::encode(on_exception) | |
2538 generator_object_(generator_object), | 2540 YieldTypeField::encode(yield_type); |
2539 expression_(expression) { | |
2540 bit_field_ |= OnExceptionField::encode(on_exception); | |
2541 } | 2541 } |
2542 | 2542 |
2543 int yield_id_; | 2543 int yield_id_; |
2544 Expression* generator_object_; | |
2545 Expression* expression_; | 2544 Expression* expression_; |
2546 | 2545 |
2547 class OnExceptionField | 2546 class OnExceptionField |
2548 : public BitField<OnException, Expression::kNextBitFieldIndex, 1> {}; | 2547 : public BitField<OnException, Expression::kNextBitFieldIndex, 1> {}; |
| 2548 class YieldTypeField |
| 2549 : public BitField<YieldType, OnExceptionField::kNext, 1> {}; |
2549 }; | 2550 }; |
2550 | 2551 |
2551 | 2552 |
2552 class Throw final : public Expression { | 2553 class Throw final : public Expression { |
2553 public: | 2554 public: |
2554 Expression* exception() const { return exception_; } | 2555 Expression* exception() const { return exception_; } |
2555 void set_exception(Expression* e) { exception_ = e; } | 2556 void set_exception(Expression* e) { exception_ = e; } |
2556 | 2557 |
2557 private: | 2558 private: |
2558 friend class AstNodeFactory; | 2559 friend class AstNodeFactory; |
(...skipping 17 matching lines...) Expand all Loading... |
2576 enum IdType { kIdTypeInvalid = -1, kIdTypeTopLevel = 0 }; | 2577 enum IdType { kIdTypeInvalid = -1, kIdTypeTopLevel = 0 }; |
2577 | 2578 |
2578 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters }; | 2579 enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters }; |
2579 | 2580 |
2580 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; | 2581 enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile }; |
2581 | 2582 |
2582 Handle<String> name() const { return raw_name_->string(); } | 2583 Handle<String> name() const { return raw_name_->string(); } |
2583 const AstString* raw_name() const { return raw_name_; } | 2584 const AstString* raw_name() const { return raw_name_; } |
2584 void set_raw_name(const AstString* name) { raw_name_ = name; } | 2585 void set_raw_name(const AstString* name) { raw_name_ = name; } |
2585 DeclarationScope* scope() const { return scope_; } | 2586 DeclarationScope* scope() const { return scope_; } |
| 2587 |
| 2588 // AST desugaring of initialization of non-simple parameters. If non-null, |
| 2589 // forces Ignition/TF pipeline. |
| 2590 Block* parameter_init_block() const { return parameter_init_block_; } |
| 2591 void set_parameter_init_block(Block* block) { parameter_init_block_ = block; } |
| 2592 |
2586 ZoneList<Statement*>* body() const { return body_; } | 2593 ZoneList<Statement*>* body() const { return body_; } |
2587 void set_function_token_position(int pos) { function_token_position_ = pos; } | 2594 void set_function_token_position(int pos) { function_token_position_ = pos; } |
2588 int function_token_position() const { return function_token_position_; } | 2595 int function_token_position() const { return function_token_position_; } |
2589 int start_position() const; | 2596 int start_position() const; |
2590 int end_position() const; | 2597 int end_position() const; |
2591 int SourceSize() const { return end_position() - start_position(); } | 2598 int SourceSize() const { return end_position() - start_position(); } |
2592 bool is_declaration() const { return function_type() == kDeclaration; } | 2599 bool is_declaration() const { return function_type() == kDeclaration; } |
2593 bool is_named_expression() const { | 2600 bool is_named_expression() const { |
2594 return function_type() == kNamedExpression; | 2601 return function_type() == kNamedExpression; |
2595 } | 2602 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2725 : Expression(position, kFunctionLiteral), | 2732 : Expression(position, kFunctionLiteral), |
2726 materialized_literal_count_(materialized_literal_count), | 2733 materialized_literal_count_(materialized_literal_count), |
2727 expected_property_count_(expected_property_count), | 2734 expected_property_count_(expected_property_count), |
2728 parameter_count_(parameter_count), | 2735 parameter_count_(parameter_count), |
2729 function_length_(function_length), | 2736 function_length_(function_length), |
2730 function_token_position_(kNoSourcePosition), | 2737 function_token_position_(kNoSourcePosition), |
2731 yield_count_(0), | 2738 yield_count_(0), |
2732 has_braces_(has_braces), | 2739 has_braces_(has_braces), |
2733 raw_name_(name), | 2740 raw_name_(name), |
2734 scope_(scope), | 2741 scope_(scope), |
| 2742 parameter_init_block_(nullptr), |
2735 body_(body), | 2743 body_(body), |
2736 raw_inferred_name_(ast_value_factory->empty_string()), | 2744 raw_inferred_name_(ast_value_factory->empty_string()), |
2737 ast_properties_(zone), | 2745 ast_properties_(zone), |
2738 function_literal_id_(function_literal_id) { | 2746 function_literal_id_(function_literal_id) { |
2739 bit_field_ |= FunctionTypeBits::encode(function_type) | | 2747 bit_field_ |= FunctionTypeBits::encode(function_type) | |
2740 Pretenure::encode(false) | | 2748 Pretenure::encode(false) | |
2741 HasDuplicateParameters::encode(has_duplicate_parameters == | 2749 HasDuplicateParameters::encode(has_duplicate_parameters == |
2742 kHasDuplicateParameters) | | 2750 kHasDuplicateParameters) | |
2743 ShouldNotBeUsedOnceHintField::encode(false) | | 2751 ShouldNotBeUsedOnceHintField::encode(false) | |
2744 DontOptimizeReasonField::encode(kNoReason); | 2752 DontOptimizeReasonField::encode(kNoReason); |
(...skipping 13 matching lines...) Expand all Loading... |
2758 int materialized_literal_count_; | 2766 int materialized_literal_count_; |
2759 int expected_property_count_; | 2767 int expected_property_count_; |
2760 int parameter_count_; | 2768 int parameter_count_; |
2761 int function_length_; | 2769 int function_length_; |
2762 int function_token_position_; | 2770 int function_token_position_; |
2763 int yield_count_; | 2771 int yield_count_; |
2764 bool has_braces_; | 2772 bool has_braces_; |
2765 | 2773 |
2766 const AstString* raw_name_; | 2774 const AstString* raw_name_; |
2767 DeclarationScope* scope_; | 2775 DeclarationScope* scope_; |
| 2776 Block* parameter_init_block_; |
2768 ZoneList<Statement*>* body_; | 2777 ZoneList<Statement*>* body_; |
2769 const AstString* raw_inferred_name_; | 2778 const AstString* raw_inferred_name_; |
2770 Handle<String> inferred_name_; | 2779 Handle<String> inferred_name_; |
2771 AstProperties ast_properties_; | 2780 AstProperties ast_properties_; |
2772 int function_literal_id_; | 2781 int function_literal_id_; |
2773 FeedbackVectorSlot literal_feedback_slot_; | 2782 FeedbackVectorSlot literal_feedback_slot_; |
2774 }; | 2783 }; |
2775 | 2784 |
2776 // Property is used for passing information | 2785 // Property is used for passing information |
2777 // about a class literal's properties from the parser to the code generator. | 2786 // about a class literal's properties from the parser to the code generator. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2949 | 2958 |
2950 // This class is produced when parsing the () in arrow functions without any | 2959 // This class is produced when parsing the () in arrow functions without any |
2951 // arguments and is not actually a valid expression. | 2960 // arguments and is not actually a valid expression. |
2952 class EmptyParentheses final : public Expression { | 2961 class EmptyParentheses final : public Expression { |
2953 private: | 2962 private: |
2954 friend class AstNodeFactory; | 2963 friend class AstNodeFactory; |
2955 | 2964 |
2956 explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) {} | 2965 explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) {} |
2957 }; | 2966 }; |
2958 | 2967 |
| 2968 class InternalVariable final : public Expression { |
| 2969 public: |
| 2970 enum Type { kGeneratorObject }; |
| 2971 |
| 2972 Type type() const { return type_; } |
| 2973 |
| 2974 const char* name() const; |
| 2975 |
| 2976 private: |
| 2977 friend class AstNodeFactory; |
| 2978 |
| 2979 explicit InternalVariable(Type type) |
| 2980 : Expression(kNoSourcePosition, kInternalVariable), type_(type) {} |
| 2981 |
| 2982 Type type_; |
| 2983 }; |
| 2984 |
2959 // Represents the spec operation `GetIterator()` | 2985 // Represents the spec operation `GetIterator()` |
2960 // (defined at https://tc39.github.io/ecma262/#sec-getiterator). Ignition | 2986 // (defined at https://tc39.github.io/ecma262/#sec-getiterator). Ignition |
2961 // desugars this into a LoadIC / JSLoadNamed, CallIC, and a type-check to | 2987 // desugars this into a LoadIC / JSLoadNamed, CallIC, and a type-check to |
2962 // validate return value of the Symbol.iterator() call. | 2988 // validate return value of the Symbol.iterator() call. |
2963 class GetIterator final : public Expression { | 2989 class GetIterator final : public Expression { |
2964 public: | 2990 public: |
2965 Expression* iterable() const { return iterable_; } | 2991 Expression* iterable() const { return iterable_; } |
2966 void set_iterable(Expression* iterable) { iterable_ = iterable; } | 2992 void set_iterable(Expression* iterable) { iterable_ = iterable; } |
2967 | 2993 |
2968 static int num_ids() { return parent_num_ids(); } | 2994 static int num_ids() { return parent_num_ids(); } |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3468 } | 3494 } |
3469 | 3495 |
3470 Assignment* assign = new (zone_) Assignment(op, target, value, pos); | 3496 Assignment* assign = new (zone_) Assignment(op, target, value, pos); |
3471 if (assign->is_compound()) { | 3497 if (assign->is_compound()) { |
3472 assign->binary_operation_ = | 3498 assign->binary_operation_ = |
3473 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); | 3499 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); |
3474 } | 3500 } |
3475 return assign; | 3501 return assign; |
3476 } | 3502 } |
3477 | 3503 |
3478 Yield* NewYield(Expression* generator_object, Expression* expression, int pos, | 3504 Yield* NewYield(Expression* expression, int pos, |
3479 Yield::OnException on_exception) { | 3505 Yield::OnException on_exception, Yield::YieldType type) { |
3480 if (!expression) expression = NewUndefinedLiteral(pos); | 3506 if (!expression) expression = NewUndefinedLiteral(pos); |
3481 return new (zone_) Yield(generator_object, expression, pos, on_exception); | 3507 return new (zone_) Yield(expression, pos, on_exception, type); |
3482 } | 3508 } |
3483 | 3509 |
3484 Throw* NewThrow(Expression* exception, int pos) { | 3510 Throw* NewThrow(Expression* exception, int pos) { |
3485 return new (zone_) Throw(exception, pos); | 3511 return new (zone_) Throw(exception, pos); |
3486 } | 3512 } |
3487 | 3513 |
3488 FunctionLiteral* NewFunctionLiteral( | 3514 FunctionLiteral* NewFunctionLiteral( |
3489 const AstRawString* name, DeclarationScope* scope, | 3515 const AstRawString* name, DeclarationScope* scope, |
3490 ZoneList<Statement*>* body, int materialized_literal_count, | 3516 ZoneList<Statement*>* body, int materialized_literal_count, |
3491 int expected_property_count, int parameter_count, int function_length, | 3517 int expected_property_count, int parameter_count, int function_length, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3560 VariableProxy* this_function_var, | 3586 VariableProxy* this_function_var, |
3561 int pos) { | 3587 int pos) { |
3562 return new (zone_) | 3588 return new (zone_) |
3563 SuperCallReference(this_var, new_target_var, this_function_var, pos); | 3589 SuperCallReference(this_var, new_target_var, this_function_var, pos); |
3564 } | 3590 } |
3565 | 3591 |
3566 EmptyParentheses* NewEmptyParentheses(int pos) { | 3592 EmptyParentheses* NewEmptyParentheses(int pos) { |
3567 return new (zone_) EmptyParentheses(pos); | 3593 return new (zone_) EmptyParentheses(pos); |
3568 } | 3594 } |
3569 | 3595 |
| 3596 InternalVariable* NewInternalVariable(InternalVariable::Type type) { |
| 3597 return new (zone_) InternalVariable(type); |
| 3598 } |
| 3599 |
3570 GetIterator* NewGetIterator(Expression* iterable, int pos) { | 3600 GetIterator* NewGetIterator(Expression* iterable, int pos) { |
3571 return new (zone_) GetIterator(iterable, pos); | 3601 return new (zone_) GetIterator(iterable, pos); |
3572 } | 3602 } |
3573 | 3603 |
3574 Zone* zone() const { return zone_; } | 3604 Zone* zone() const { return zone_; } |
3575 void set_zone(Zone* zone) { zone_ = zone; } | 3605 void set_zone(Zone* zone) { zone_ = zone; } |
3576 | 3606 |
3577 // Handles use of temporary zones when parsing inner function bodies. | 3607 // Handles use of temporary zones when parsing inner function bodies. |
3578 class BodyScope { | 3608 class BodyScope { |
3579 public: | 3609 public: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3639 : NULL; \ | 3669 : NULL; \ |
3640 } | 3670 } |
3641 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3671 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3642 #undef DECLARE_NODE_FUNCTIONS | 3672 #undef DECLARE_NODE_FUNCTIONS |
3643 | 3673 |
3644 | 3674 |
3645 } // namespace internal | 3675 } // namespace internal |
3646 } // namespace v8 | 3676 } // namespace v8 |
3647 | 3677 |
3648 #endif // V8_AST_AST_H_ | 3678 #endif // V8_AST_AST_H_ |
OLD | NEW |