Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: src/ast/ast.h

Issue 2622833002: WIP [esnext] implement async iteration proposal (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/assembler.h" 8 #include "src/assembler.h"
9 #include "src/ast/ast-types.h" 9 #include "src/ast/ast-types.h"
10 #include "src/ast/ast-value-factory.h" 10 #include "src/ast/ast-value-factory.h"
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 686
687 Statement* init_; 687 Statement* init_;
688 Expression* cond_; 688 Expression* cond_;
689 Statement* next_; 689 Statement* next_;
690 }; 690 };
691 691
692 692
693 class ForEachStatement : public IterationStatement { 693 class ForEachStatement : public IterationStatement {
694 public: 694 public:
695 enum VisitMode { 695 enum VisitMode {
696 ENUMERATE, // for (each in subject) body; 696 ENUMERATE, // for (each in subject) body;
697 ITERATE // for (each of subject) body; 697 ITERATE, // for (each of subject) body;
698 ASYNC_ITERATE, // for await (each of subject) body;
698 }; 699 };
699 700
700 using IterationStatement::Initialize; 701 using IterationStatement::Initialize;
701 702
702 static const char* VisitModeString(VisitMode mode) { 703 static const char* VisitModeString(VisitMode mode) {
703 return mode == ITERATE ? "for-of" : "for-in"; 704 static const char* kModeStrings[] = {"for-in", "for-of", "for-await-of"};
705 DCHECK(mode >= ENUMERATE && mode <= ASYNC_ITERATE);
706 return kModeStrings[mode];
704 } 707 }
705 708
706 protected: 709 protected:
707 ForEachStatement(ZoneList<const AstRawString*>* labels, int pos, 710 ForEachStatement(ZoneList<const AstRawString*>* labels, int pos,
708 NodeType type) 711 NodeType type)
709 : IterationStatement(labels, pos, type) {} 712 : IterationStatement(labels, pos, type) {}
710 }; 713 };
711 714
712 715
713 class ForInStatement final : public ForEachStatement { 716 class ForInStatement final : public ForEachStatement {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 result_done_(NULL), 832 result_done_(NULL),
830 assign_each_(NULL) {} 833 assign_each_(NULL) {}
831 834
832 Variable* iterator_; 835 Variable* iterator_;
833 Expression* assign_iterator_; 836 Expression* assign_iterator_;
834 Expression* next_result_; 837 Expression* next_result_;
835 Expression* result_done_; 838 Expression* result_done_;
836 Expression* assign_each_; 839 Expression* assign_each_;
837 }; 840 };
838 841
839
840 class ExpressionStatement final : public Statement { 842 class ExpressionStatement final : public Statement {
841 public: 843 public:
842 void set_expression(Expression* e) { expression_ = e; } 844 void set_expression(Expression* e) { expression_ = e; }
843 Expression* expression() const { return expression_; } 845 Expression* expression() const { return expression_; }
844 bool IsJump() const { return expression_->IsThrow(); } 846 bool IsJump() const { return expression_->IsThrow(); }
845 847
846 private: 848 private:
847 friend class AstNodeFactory; 849 friend class AstNodeFactory;
848 850
849 ExpressionStatement(Expression* expression, int pos) 851 ExpressionStatement(Expression* expression, int pos)
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 class IsRewrittenField 2477 class IsRewrittenField
2476 : public BitField<bool, Expression::kNextBitFieldIndex, 1> {}; 2478 : public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
2477 }; 2479 };
2478 2480
2479 // Our Yield is different from the JS yield in that it "returns" its argument as 2481 // Our Yield is different from the JS yield in that it "returns" its argument as
2480 // is, without wrapping it in an iterator result object. Such wrapping, if 2482 // is, without wrapping it in an iterator result object. Such wrapping, if
2481 // desired, must be done beforehand (see the parser). 2483 // desired, must be done beforehand (see the parser).
2482 class Yield final : public Expression { 2484 class Yield final : public Expression {
2483 public: 2485 public:
2484 enum OnException { kOnExceptionThrow, kOnExceptionRethrow }; 2486 enum OnException { kOnExceptionThrow, kOnExceptionRethrow };
2487 enum YieldType { kNormal, kAwait };
2485 2488
2486 Expression* generator_object() const { return generator_object_; } 2489 Expression* generator_object() const { return generator_object_; }
2487 Expression* expression() const { return expression_; } 2490 Expression* expression() const { return expression_; }
2488 OnException on_exception() const { 2491 OnException on_exception() const {
2489 return OnExceptionField::decode(bit_field_); 2492 return OnExceptionField::decode(bit_field_);
2490 } 2493 }
2491 bool rethrow_on_exception() const { 2494 bool rethrow_on_exception() const {
2492 return on_exception() == kOnExceptionRethrow; 2495 return on_exception() == kOnExceptionRethrow;
2493 } 2496 }
2494 int yield_id() const { return yield_id_; } 2497 int yield_id() const { return yield_id_; }
2498 YieldType yield_type() const { return YieldTypeField::decode(bit_field_); }
2495 2499
2496 void set_generator_object(Expression* e) { generator_object_ = e; } 2500 void set_generator_object(Expression* e) { generator_object_ = e; }
2497 void set_expression(Expression* e) { expression_ = e; } 2501 void set_expression(Expression* e) { expression_ = e; }
2498 void set_yield_id(int yield_id) { yield_id_ = yield_id; } 2502 void set_yield_id(int yield_id) { yield_id_ = yield_id; }
2503 void set_yield_type(YieldType type) {
2504 bit_field_ = YieldTypeField::update(bit_field_, type);
2505 }
2499 2506
2500 private: 2507 private:
2501 friend class AstNodeFactory; 2508 friend class AstNodeFactory;
2502 2509
2503 Yield(Expression* generator_object, Expression* expression, int pos, 2510 Yield(Expression* generator_object, Expression* expression, int pos,
2504 OnException on_exception) 2511 OnException on_exception, YieldType yield_type = kNormal)
2505 : Expression(pos, kYield), 2512 : Expression(pos, kYield),
2506 yield_id_(-1), 2513 yield_id_(-1),
2507 generator_object_(generator_object), 2514 generator_object_(generator_object),
2508 expression_(expression) { 2515 expression_(expression) {
2509 bit_field_ |= OnExceptionField::encode(on_exception); 2516 bit_field_ |= OnExceptionField::encode(on_exception) |
2517 YieldTypeField::encode(yield_type);
2510 } 2518 }
2511 2519
2512 int yield_id_; 2520 int yield_id_;
2513 Expression* generator_object_; 2521 Expression* generator_object_;
2514 Expression* expression_; 2522 Expression* expression_;
2515 2523
2516 class OnExceptionField 2524 class OnExceptionField
2517 : public BitField<OnException, Expression::kNextBitFieldIndex, 1> {}; 2525 : public BitField<OnException, Expression::kNextBitFieldIndex, 1> {};
2526 class YieldTypeField
2527 : public BitField<YieldType, OnExceptionField::kNext, 1> {};
2518 }; 2528 };
2519 2529
2520 2530
2521 class Throw final : public Expression { 2531 class Throw final : public Expression {
2522 public: 2532 public:
2523 Expression* exception() const { return exception_; } 2533 Expression* exception() const { return exception_; }
2524 void set_exception(Expression* e) { exception_ = e; } 2534 void set_exception(Expression* e) { exception_ = e; }
2525 2535
2526 private: 2536 private:
2527 friend class AstNodeFactory; 2537 friend class AstNodeFactory;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 2917
2908 explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) {} 2918 explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) {}
2909 }; 2919 };
2910 2920
2911 // Represents the spec operation `GetIterator()` 2921 // Represents the spec operation `GetIterator()`
2912 // (defined at https://tc39.github.io/ecma262/#sec-getiterator). Ignition 2922 // (defined at https://tc39.github.io/ecma262/#sec-getiterator). Ignition
2913 // desugars this into a LoadIC / JSLoadNamed, CallIC, and a type-check to 2923 // desugars this into a LoadIC / JSLoadNamed, CallIC, and a type-check to
2914 // validate return value of the Symbol.iterator() call. 2924 // validate return value of the Symbol.iterator() call.
2915 class GetIterator final : public Expression { 2925 class GetIterator final : public Expression {
2916 public: 2926 public:
2927 enum Hint { kNormal, kAsync };
2928
2929 Hint hint() const { return hint_; }
2930
2917 Expression* iterable() const { return iterable_; } 2931 Expression* iterable() const { return iterable_; }
2918 void set_iterable(Expression* iterable) { iterable_ = iterable; } 2932 void set_iterable(Expression* iterable) { iterable_ = iterable; }
2919 2933
2920 static int num_ids() { return parent_num_ids(); } 2934 static int num_ids() { return parent_num_ids(); }
2921 2935
2922 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 2936 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
2923 FeedbackVectorSlotCache* cache) { 2937 FeedbackVectorSlotCache* cache) {
2924 iterator_property_feedback_slot_ = 2938 iterator_property_feedback_slot_ =
2925 spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC); 2939 spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC);
2926 iterator_call_feedback_slot_ = 2940 iterator_call_feedback_slot_ =
2927 spec->AddSlot(FeedbackVectorSlotKind::CALL_IC); 2941 spec->AddSlot(FeedbackVectorSlotKind::CALL_IC);
2942 if (hint() == kAsync) {
2943 // Can we just re-use the other slots?
2944 async_iterator_property_feedback_slot_ =
2945 spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC);
2946 async_iterator_call_feedback_slot_ =
2947 spec->AddSlot(FeedbackVectorSlotKind::CALL_IC);
2948 }
2928 } 2949 }
2929 2950
2930 FeedbackVectorSlot IteratorPropertyFeedbackSlot() const { 2951 FeedbackVectorSlot IteratorPropertyFeedbackSlot() const {
2931 return iterator_property_feedback_slot_; 2952 return iterator_property_feedback_slot_;
2932 } 2953 }
2933 2954
2934 FeedbackVectorSlot IteratorCallFeedbackSlot() const { 2955 FeedbackVectorSlot IteratorCallFeedbackSlot() const {
2935 return iterator_call_feedback_slot_; 2956 return iterator_call_feedback_slot_;
2936 } 2957 }
2937 2958
2959 FeedbackVectorSlot AsyncIteratorPropertyFeedbackSlot() const {
2960 return async_iterator_property_feedback_slot_;
2961 }
2962
2963 FeedbackVectorSlot AsyncIteratorCallFeedbackSlot() const {
2964 return async_iterator_call_feedback_slot_;
2965 }
2966
2938 private: 2967 private:
2939 friend class AstNodeFactory; 2968 friend class AstNodeFactory;
2940 2969
2941 explicit GetIterator(Expression* iterable, int pos) 2970 explicit GetIterator(Expression* iterable, int pos)
2942 : Expression(pos, kGetIterator), iterable_(iterable) {} 2971 : Expression(pos, kGetIterator), iterable_(iterable), hint_(kNormal) {}
2972
2973 explicit GetIterator(Expression* iterable, Hint hint, int pos)
2974 : Expression(pos, kGetIterator), iterable_(iterable), hint_(hint) {}
2943 2975
2944 Expression* iterable_; 2976 Expression* iterable_;
2977 Hint hint_;
2945 FeedbackVectorSlot iterator_property_feedback_slot_; 2978 FeedbackVectorSlot iterator_property_feedback_slot_;
2946 FeedbackVectorSlot iterator_call_feedback_slot_; 2979 FeedbackVectorSlot iterator_call_feedback_slot_;
2980 FeedbackVectorSlot async_iterator_property_feedback_slot_;
2981 FeedbackVectorSlot async_iterator_call_feedback_slot_;
2947 }; 2982 };
2948 2983
2949 // ---------------------------------------------------------------------------- 2984 // ----------------------------------------------------------------------------
2950 // Basic visitor 2985 // Basic visitor
2951 // Sub-class should parametrize AstVisitor with itself, e.g.: 2986 // Sub-class should parametrize AstVisitor with itself, e.g.:
2952 // class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... } 2987 // class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... }
2953 2988
2954 template <class Subclass> 2989 template <class Subclass>
2955 class AstVisitor BASE_EMBEDDED { 2990 class AstVisitor BASE_EMBEDDED {
2956 public: 2991 public:
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
3144 STATEMENT_WITH_LABELS(SwitchStatement) 3179 STATEMENT_WITH_LABELS(SwitchStatement)
3145 #undef STATEMENT_WITH_LABELS 3180 #undef STATEMENT_WITH_LABELS
3146 3181
3147 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, 3182 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3148 ZoneList<const AstRawString*>* labels, 3183 ZoneList<const AstRawString*>* labels,
3149 int pos) { 3184 int pos) {
3150 switch (visit_mode) { 3185 switch (visit_mode) {
3151 case ForEachStatement::ENUMERATE: { 3186 case ForEachStatement::ENUMERATE: {
3152 return new (zone_) ForInStatement(labels, pos); 3187 return new (zone_) ForInStatement(labels, pos);
3153 } 3188 }
3154 case ForEachStatement::ITERATE: { 3189 case ForEachStatement::ITERATE:
3190 case ForEachStatement::ASYNC_ITERATE: {
3155 return new (zone_) ForOfStatement(labels, pos); 3191 return new (zone_) ForOfStatement(labels, pos);
3156 } 3192 }
3157 } 3193 }
3158 UNREACHABLE(); 3194 UNREACHABLE();
3159 return NULL; 3195 return NULL;
3160 } 3196 }
3161 3197
3162 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { 3198 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3163 return new (zone_) ExpressionStatement(expression, pos); 3199 return new (zone_) ExpressionStatement(expression, pos);
3164 } 3200 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
3424 3460
3425 Assignment* assign = new (zone_) Assignment(op, target, value, pos); 3461 Assignment* assign = new (zone_) Assignment(op, target, value, pos);
3426 if (assign->is_compound()) { 3462 if (assign->is_compound()) {
3427 assign->binary_operation_ = 3463 assign->binary_operation_ =
3428 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); 3464 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3429 } 3465 }
3430 return assign; 3466 return assign;
3431 } 3467 }
3432 3468
3433 Yield* NewYield(Expression* generator_object, Expression* expression, int pos, 3469 Yield* NewYield(Expression* generator_object, Expression* expression, int pos,
3434 Yield::OnException on_exception) { 3470 Yield::OnException on_exception,
3471 Yield::YieldType type = Yield::kNormal) {
3435 if (!expression) expression = NewUndefinedLiteral(pos); 3472 if (!expression) expression = NewUndefinedLiteral(pos);
3436 return new (zone_) Yield(generator_object, expression, pos, on_exception); 3473 return new (zone_)
3474 Yield(generator_object, expression, pos, on_exception, type);
3437 } 3475 }
3438 3476
3439 Throw* NewThrow(Expression* exception, int pos) { 3477 Throw* NewThrow(Expression* exception, int pos) {
3440 return new (zone_) Throw(exception, pos); 3478 return new (zone_) Throw(exception, pos);
3441 } 3479 }
3442 3480
3443 FunctionLiteral* NewFunctionLiteral( 3481 FunctionLiteral* NewFunctionLiteral(
3444 const AstRawString* name, DeclarationScope* scope, 3482 const AstRawString* name, DeclarationScope* scope,
3445 ZoneList<Statement*>* body, int materialized_literal_count, 3483 ZoneList<Statement*>* body, int materialized_literal_count,
3446 int expected_property_count, int parameter_count, int function_length, 3484 int expected_property_count, int parameter_count, int function_length,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
3519 } 3557 }
3520 3558
3521 EmptyParentheses* NewEmptyParentheses(int pos) { 3559 EmptyParentheses* NewEmptyParentheses(int pos) {
3522 return new (zone_) EmptyParentheses(pos); 3560 return new (zone_) EmptyParentheses(pos);
3523 } 3561 }
3524 3562
3525 GetIterator* NewGetIterator(Expression* iterable, int pos) { 3563 GetIterator* NewGetIterator(Expression* iterable, int pos) {
3526 return new (zone_) GetIterator(iterable, pos); 3564 return new (zone_) GetIterator(iterable, pos);
3527 } 3565 }
3528 3566
3567 GetIterator* NewGetIterator(Expression* iterable, GetIterator::Hint hint,
3568 int pos) {
3569 return new (zone_) GetIterator(iterable, hint, pos);
3570 }
3571
3529 Zone* zone() const { return zone_; } 3572 Zone* zone() const { return zone_; }
3530 void set_zone(Zone* zone) { zone_ = zone; } 3573 void set_zone(Zone* zone) { zone_ = zone; }
3531 3574
3532 // Handles use of temporary zones when parsing inner function bodies. 3575 // Handles use of temporary zones when parsing inner function bodies.
3533 class BodyScope { 3576 class BodyScope {
3534 public: 3577 public:
3535 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone) 3578 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone)
3536 : factory_(factory), prev_zone_(factory->zone_) { 3579 : factory_(factory), prev_zone_(factory->zone_) {
3537 if (use_temp_zone) { 3580 if (use_temp_zone) {
3538 factory->zone_ = temp_zone; 3581 factory->zone_ = temp_zone;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3594 : NULL; \ 3637 : NULL; \
3595 } 3638 }
3596 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3639 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3597 #undef DECLARE_NODE_FUNCTIONS 3640 #undef DECLARE_NODE_FUNCTIONS
3598 3641
3599 3642
3600 } // namespace internal 3643 } // namespace internal
3601 } // namespace v8 3644 } // namespace v8
3602 3645
3603 #endif // V8_AST_AST_H_ 3646 #endif // V8_AST_AST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698