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

Side by Side Diff: runtime/vm/ast.h

Issue 484933003: Await it! (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/ast_printer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_AST_H_ 5 #ifndef VM_AST_H_
6 #define VM_AST_H_ 6 #define VM_AST_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 #include "vm/scopes.h" 11 #include "vm/scopes.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/native_entry.h" 13 #include "vm/native_entry.h"
14 #include "vm/token.h" 14 #include "vm/token.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 #define FOR_EACH_NODE(V) \ 18 #define FOR_EACH_NODE(V) \
19 V(Await) \ 19 V(Await) \
20 V(AwaitMarker) \
20 V(Return) \ 21 V(Return) \
21 V(Literal) \ 22 V(Literal) \
22 V(Type) \ 23 V(Type) \
23 V(Assignable) \ 24 V(Assignable) \
24 V(BinaryOp) \ 25 V(BinaryOp) \
25 V(BinaryOpWithMask32) \ 26 V(BinaryOpWithMask32) \
26 V(Comparison) \ 27 V(Comparison) \
27 V(UnaryOp) \ 28 V(UnaryOp) \
28 V(ConditionalExpr) \ 29 V(ConditionalExpr) \
29 V(If) \ 30 V(If) \
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 162
162 DECLARE_COMMON_NODE_FUNCTIONS(AwaitNode); 163 DECLARE_COMMON_NODE_FUNCTIONS(AwaitNode);
163 164
164 private: 165 private:
165 AstNode* expr_; 166 AstNode* expr_;
166 167
167 DISALLOW_COPY_AND_ASSIGN(AwaitNode); 168 DISALLOW_COPY_AND_ASSIGN(AwaitNode);
168 }; 169 };
169 170
170 171
172 // AwaitMarker nodes are used to generate markers that the FlowGraphBuilder
173 // relies on. They can occur in two kinds:
174 // 1) kNewContinuationState: A marker indicating that a new await state needs to
175 // be added to a function preamble. This type also triggers storing of the
176 // current context.
177 // 2) kTargetForContinuation: A marker indicating an entry point for the most
178 // recent generated state.
179 //
180 // In general it is expected (ASSERT) that the different kinds of markers reach
181 // the FlowGraphBuilder in alternating order. That is:
182 // <new state> -> <other nodes> -> <target> -> <other nodes> ->
183 // <new state> -> ...
184 class AwaitMarkerNode : public AstNode {
185 public:
186 enum MarkerType {
187 kNewContinuationState,
188 kTargetForContinuation,
189 };
190
191 explicit AwaitMarkerNode(MarkerType marker_type)
192 : AstNode(Scanner::kNoSourcePos),
193 marker_type_(marker_type) { }
194
195 void VisitChildren(AstNodeVisitor* visitor) const { }
196
197 MarkerType marker_type() const {
198 return marker_type_;
199 }
200
201 LocalScope* scope() const { return scope_; }
202 void set_scope(LocalScope* scope) { scope_ = scope; }
203
204 DECLARE_COMMON_NODE_FUNCTIONS(AwaitMarkerNode);
205
206 private:
207 MarkerType marker_type_;
208 LocalScope* scope_;
209
210 DISALLOW_COPY_AND_ASSIGN(AwaitMarkerNode);
211 };
212
213
171 class SequenceNode : public AstNode { 214 class SequenceNode : public AstNode {
172 public: 215 public:
173 SequenceNode(intptr_t token_pos, LocalScope* scope) 216 SequenceNode(intptr_t token_pos, LocalScope* scope)
174 : AstNode(token_pos), 217 : AstNode(token_pos),
175 scope_(scope), 218 scope_(scope),
176 nodes_(4), 219 nodes_(4),
177 label_(NULL) { 220 label_(NULL) {
178 } 221 }
179 222
180 LocalScope* scope() const { return scope_; } 223 LocalScope* scope() const { return scope_; }
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 572
530 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode); 573 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode);
531 574
532 private: 575 private:
533 const Object& primary_; 576 const Object& primary_;
534 bool is_deferred_reference_; 577 bool is_deferred_reference_;
535 578
536 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode); 579 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode);
537 }; 580 };
538 581
539 582 // Return nodes can be of different types:
540 // TODO(mlippautz): Implement return nodes that are used to return from a 583 // * A regular return node that in the case of async functions gets replaced
541 // continuation. 584 // with appropriate completer calls. This kind is generated by dart code.
585 // * A continuation return that just returns from a function. This kind is
586 // generated by AST transformers.
542 class ReturnNode : public AstNode { 587 class ReturnNode : public AstNode {
543 public: 588 public:
589 enum ReturnType {
590 kRegular,
591 kContinuation,
592 };
593
544 // Return from a void function returns the null object. 594 // Return from a void function returns the null object.
545 explicit ReturnNode(intptr_t token_pos) 595 explicit ReturnNode(intptr_t token_pos)
546 : AstNode(token_pos), 596 : AstNode(token_pos),
547 value_(new LiteralNode(token_pos, Instance::ZoneHandle())), 597 value_(new LiteralNode(token_pos, Instance::ZoneHandle())),
548 inlined_finally_list_(), 598 inlined_finally_list_(),
549 is_regular_return_(true) { } 599 return_type_(kRegular) { }
550 // Return from a non-void function. 600 // Return from a non-void function.
551 ReturnNode(intptr_t token_pos, 601 ReturnNode(intptr_t token_pos,
552 AstNode* value) 602 AstNode* value)
553 : AstNode(token_pos), 603 : AstNode(token_pos),
554 value_(value), 604 value_(value),
555 inlined_finally_list_(), 605 inlined_finally_list_(),
556 is_regular_return_(true) { 606 return_type_(kRegular) {
557 ASSERT(value_ != NULL); 607 ASSERT(value_ != NULL);
558 } 608 }
559 609
560 AstNode* value() const { return value_; } 610 AstNode* value() const { return value_; }
561 611
562 intptr_t inlined_finally_list_length() const { 612 intptr_t inlined_finally_list_length() const {
563 return inlined_finally_list_.length(); 613 return inlined_finally_list_.length();
564 } 614 }
565 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const { 615 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const {
566 return inlined_finally_list_[index]; 616 return inlined_finally_list_[index];
567 } 617 }
568 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) { 618 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) {
569 inlined_finally_list_.Add(finally_node); 619 inlined_finally_list_.Add(finally_node);
570 } 620 }
571 621
572 virtual void VisitChildren(AstNodeVisitor* visitor) const { 622 virtual void VisitChildren(AstNodeVisitor* visitor) const {
573 if (value() != NULL) { 623 if (value() != NULL) {
574 value()->Visit(visitor); 624 value()->Visit(visitor);
575 } 625 }
576 } 626 }
577 627
578 void set_scope(LocalScope* scope) { scope_ = scope; } 628 void set_scope(LocalScope* scope) { scope_ = scope; }
579 LocalScope* scope() const { return scope_; } 629 LocalScope* scope() const { return scope_; }
580 630
581 // Returns false if the return node is used to return from a continuation. 631 ReturnType return_type() const { return return_type_; }
582 bool is_regular_return() const { return is_regular_return_; } 632 void set_return_type(ReturnType type) { return_type_ = type; }
583 633
584 DECLARE_COMMON_NODE_FUNCTIONS(ReturnNode); 634 DECLARE_COMMON_NODE_FUNCTIONS(ReturnNode);
585 635
586 private: 636 private:
587 AstNode* value_; 637 AstNode* value_;
588 GrowableArray<InlinedFinallyNode*> inlined_finally_list_; 638 GrowableArray<InlinedFinallyNode*> inlined_finally_list_;
589 LocalScope* scope_; 639 LocalScope* scope_;
590 bool is_regular_return_; 640 ReturnType return_type_;
591 641
592 DISALLOW_COPY_AND_ASSIGN(ReturnNode); 642 DISALLOW_COPY_AND_ASSIGN(ReturnNode);
593 }; 643 };
594 644
595 645
596 class ComparisonNode : public AstNode { 646 class ComparisonNode : public AstNode {
597 public: 647 public:
598 ComparisonNode(intptr_t token_pos, 648 ComparisonNode(intptr_t token_pos,
599 Token::Kind kind, 649 Token::Kind kind,
600 AstNode* left, 650 AstNode* left,
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 const intptr_t try_index_; 1898 const intptr_t try_index_;
1849 1899
1850 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1900 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1851 }; 1901 };
1852 1902
1853 } // namespace dart 1903 } // namespace dart
1854 1904
1855 #undef DECLARE_COMMON_NODE_FUNCTIONS 1905 #undef DECLARE_COMMON_NODE_FUNCTIONS
1856 1906
1857 #endif // VM_AST_H_ 1907 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast_printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698