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

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

Issue 2622833002: WIP [esnext] implement async iteration proposal (Closed)
Patch Set: Fix minor parsing bug, add some local test262 tests 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, kDelegate };
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, 2> {};
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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
2934 2944
2935 explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) {} 2945 explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) {}
2936 }; 2946 };
2937 2947
2938 // Represents the spec operation `GetIterator()` 2948 // Represents the spec operation `GetIterator()`
2939 // (defined at https://tc39.github.io/ecma262/#sec-getiterator). Ignition 2949 // (defined at https://tc39.github.io/ecma262/#sec-getiterator). Ignition
2940 // desugars this into a LoadIC / JSLoadNamed, CallIC, and a type-check to 2950 // desugars this into a LoadIC / JSLoadNamed, CallIC, and a type-check to
2941 // validate return value of the Symbol.iterator() call. 2951 // validate return value of the Symbol.iterator() call.
2942 class GetIterator final : public Expression { 2952 class GetIterator final : public Expression {
2943 public: 2953 public:
2954 enum Hint { kNormal, kAsync };
2955
2956 Hint hint() const { return hint_; }
2957
2944 Expression* iterable() const { return iterable_; } 2958 Expression* iterable() const { return iterable_; }
2945 void set_iterable(Expression* iterable) { iterable_ = iterable; } 2959 void set_iterable(Expression* iterable) { iterable_ = iterable; }
2946 2960
2947 static int num_ids() { return parent_num_ids(); } 2961 static int num_ids() { return parent_num_ids(); }
2948 2962
2949 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, 2963 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec,
2950 FeedbackVectorSlotCache* cache) { 2964 FeedbackVectorSlotCache* cache) {
2951 iterator_property_feedback_slot_ = 2965 iterator_property_feedback_slot_ =
2952 spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC); 2966 spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC);
2953 iterator_call_feedback_slot_ = 2967 iterator_call_feedback_slot_ =
2954 spec->AddSlot(FeedbackVectorSlotKind::CALL_IC); 2968 spec->AddSlot(FeedbackVectorSlotKind::CALL_IC);
2969 if (hint() == kAsync) {
2970 // Can we just re-use the other slots?
2971 async_iterator_property_feedback_slot_ =
2972 spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC);
2973 async_iterator_call_feedback_slot_ =
2974 spec->AddSlot(FeedbackVectorSlotKind::CALL_IC);
2975 }
2955 } 2976 }
2956 2977
2957 FeedbackVectorSlot IteratorPropertyFeedbackSlot() const { 2978 FeedbackVectorSlot IteratorPropertyFeedbackSlot() const {
2958 return iterator_property_feedback_slot_; 2979 return iterator_property_feedback_slot_;
2959 } 2980 }
2960 2981
2961 FeedbackVectorSlot IteratorCallFeedbackSlot() const { 2982 FeedbackVectorSlot IteratorCallFeedbackSlot() const {
2962 return iterator_call_feedback_slot_; 2983 return iterator_call_feedback_slot_;
2963 } 2984 }
2964 2985
2986 FeedbackVectorSlot AsyncIteratorPropertyFeedbackSlot() const {
2987 return async_iterator_property_feedback_slot_;
2988 }
2989
2990 FeedbackVectorSlot AsyncIteratorCallFeedbackSlot() const {
2991 return async_iterator_call_feedback_slot_;
2992 }
2993
2965 private: 2994 private:
2966 friend class AstNodeFactory; 2995 friend class AstNodeFactory;
2967 2996
2968 explicit GetIterator(Expression* iterable, int pos) 2997 explicit GetIterator(Expression* iterable, int pos)
2969 : Expression(pos, kGetIterator), iterable_(iterable) {} 2998 : Expression(pos, kGetIterator), iterable_(iterable), hint_(kNormal) {}
2999
3000 explicit GetIterator(Expression* iterable, Hint hint, int pos)
3001 : Expression(pos, kGetIterator), iterable_(iterable), hint_(hint) {}
2970 3002
2971 Expression* iterable_; 3003 Expression* iterable_;
3004 Hint hint_;
2972 FeedbackVectorSlot iterator_property_feedback_slot_; 3005 FeedbackVectorSlot iterator_property_feedback_slot_;
2973 FeedbackVectorSlot iterator_call_feedback_slot_; 3006 FeedbackVectorSlot iterator_call_feedback_slot_;
3007 FeedbackVectorSlot async_iterator_property_feedback_slot_;
3008 FeedbackVectorSlot async_iterator_call_feedback_slot_;
2974 }; 3009 };
2975 3010
2976 // ---------------------------------------------------------------------------- 3011 // ----------------------------------------------------------------------------
2977 // Basic visitor 3012 // Basic visitor
2978 // Sub-class should parametrize AstVisitor with itself, e.g.: 3013 // Sub-class should parametrize AstVisitor with itself, e.g.:
2979 // class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... } 3014 // class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... }
2980 3015
2981 template <class Subclass> 3016 template <class Subclass>
2982 class AstVisitor BASE_EMBEDDED { 3017 class AstVisitor BASE_EMBEDDED {
2983 public: 3018 public:
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
3171 STATEMENT_WITH_LABELS(SwitchStatement) 3206 STATEMENT_WITH_LABELS(SwitchStatement)
3172 #undef STATEMENT_WITH_LABELS 3207 #undef STATEMENT_WITH_LABELS
3173 3208
3174 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, 3209 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3175 ZoneList<const AstRawString*>* labels, 3210 ZoneList<const AstRawString*>* labels,
3176 int pos) { 3211 int pos) {
3177 switch (visit_mode) { 3212 switch (visit_mode) {
3178 case ForEachStatement::ENUMERATE: { 3213 case ForEachStatement::ENUMERATE: {
3179 return new (zone_) ForInStatement(labels, pos); 3214 return new (zone_) ForInStatement(labels, pos);
3180 } 3215 }
3181 case ForEachStatement::ITERATE: { 3216 case ForEachStatement::ITERATE:
3217 case ForEachStatement::ASYNC_ITERATE: {
3182 return new (zone_) ForOfStatement(labels, pos); 3218 return new (zone_) ForOfStatement(labels, pos);
3183 } 3219 }
3184 } 3220 }
3185 UNREACHABLE(); 3221 UNREACHABLE();
3186 return NULL; 3222 return NULL;
3187 } 3223 }
3188 3224
3189 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { 3225 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3190 return new (zone_) ExpressionStatement(expression, pos); 3226 return new (zone_) ExpressionStatement(expression, pos);
3191 } 3227 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
3451 3487
3452 Assignment* assign = new (zone_) Assignment(op, target, value, pos); 3488 Assignment* assign = new (zone_) Assignment(op, target, value, pos);
3453 if (assign->is_compound()) { 3489 if (assign->is_compound()) {
3454 assign->binary_operation_ = 3490 assign->binary_operation_ =
3455 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); 3491 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3456 } 3492 }
3457 return assign; 3493 return assign;
3458 } 3494 }
3459 3495
3460 Yield* NewYield(Expression* generator_object, Expression* expression, int pos, 3496 Yield* NewYield(Expression* generator_object, Expression* expression, int pos,
3461 Yield::OnException on_exception) { 3497 Yield::OnException on_exception,
3498 Yield::YieldType type = Yield::kNormal) {
3462 if (!expression) expression = NewUndefinedLiteral(pos); 3499 if (!expression) expression = NewUndefinedLiteral(pos);
3463 return new (zone_) Yield(generator_object, expression, pos, on_exception); 3500 return new (zone_)
3501 Yield(generator_object, expression, pos, on_exception, type);
3464 } 3502 }
3465 3503
3466 Throw* NewThrow(Expression* exception, int pos) { 3504 Throw* NewThrow(Expression* exception, int pos) {
3467 return new (zone_) Throw(exception, pos); 3505 return new (zone_) Throw(exception, pos);
3468 } 3506 }
3469 3507
3470 FunctionLiteral* NewFunctionLiteral( 3508 FunctionLiteral* NewFunctionLiteral(
3471 const AstRawString* name, DeclarationScope* scope, 3509 const AstRawString* name, DeclarationScope* scope,
3472 ZoneList<Statement*>* body, int materialized_literal_count, 3510 ZoneList<Statement*>* body, int materialized_literal_count,
3473 int expected_property_count, int parameter_count, int function_length, 3511 int expected_property_count, int parameter_count, int function_length,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 } 3584 }
3547 3585
3548 EmptyParentheses* NewEmptyParentheses(int pos) { 3586 EmptyParentheses* NewEmptyParentheses(int pos) {
3549 return new (zone_) EmptyParentheses(pos); 3587 return new (zone_) EmptyParentheses(pos);
3550 } 3588 }
3551 3589
3552 GetIterator* NewGetIterator(Expression* iterable, int pos) { 3590 GetIterator* NewGetIterator(Expression* iterable, int pos) {
3553 return new (zone_) GetIterator(iterable, pos); 3591 return new (zone_) GetIterator(iterable, pos);
3554 } 3592 }
3555 3593
3594 GetIterator* NewGetIterator(Expression* iterable, GetIterator::Hint hint,
3595 int pos) {
3596 return new (zone_) GetIterator(iterable, hint, pos);
3597 }
3598
3556 Zone* zone() const { return zone_; } 3599 Zone* zone() const { return zone_; }
3557 void set_zone(Zone* zone) { zone_ = zone; } 3600 void set_zone(Zone* zone) { zone_ = zone; }
3558 3601
3559 // Handles use of temporary zones when parsing inner function bodies. 3602 // Handles use of temporary zones when parsing inner function bodies.
3560 class BodyScope { 3603 class BodyScope {
3561 public: 3604 public:
3562 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone) 3605 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone)
3563 : factory_(factory), prev_zone_(factory->zone_) { 3606 : factory_(factory), prev_zone_(factory->zone_) {
3564 if (use_temp_zone) { 3607 if (use_temp_zone) {
3565 factory->zone_ = temp_zone; 3608 factory->zone_ = temp_zone;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3621 : NULL; \ 3664 : NULL; \
3622 } 3665 }
3623 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3666 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3624 #undef DECLARE_NODE_FUNCTIONS 3667 #undef DECLARE_NODE_FUNCTIONS
3625 3668
3626 3669
3627 } // namespace internal 3670 } // namespace internal
3628 } // namespace v8 3671 } // namespace v8
3629 3672
3630 #endif // V8_AST_AST_H_ 3673 #endif // V8_AST_AST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698