Chromium Code Reviews| Index: runtime/vm/ast.h |
| diff --git a/runtime/vm/ast.h b/runtime/vm/ast.h |
| index 7c1279b4fa58df4e01c3b4a5025664d3e6afa18f..9fc9a34b46d8b416451f92286777e39a0c0ddea3 100644 |
| --- a/runtime/vm/ast.h |
| +++ b/runtime/vm/ast.h |
| @@ -17,6 +17,7 @@ namespace dart { |
| #define FOR_EACH_NODE(V) \ |
| V(Await) \ |
| + V(AwaitMarker) \ |
| V(Return) \ |
| V(Literal) \ |
| V(Type) \ |
| @@ -168,6 +169,45 @@ class AwaitNode : public AstNode { |
| }; |
| +// AwaitMarker nodes are used to generate markers that the FlowGraphBuilder |
| +// relies on. They can occur in two kinds: |
| +// 1) kNewContinuationState: A marker indicating that a new await state needs to |
| +// be added to a function preamble. This type also triggers storing of the |
| +// current context. |
| +// 2) kTargetForContinuation: A marker indicating an entry point for the last |
|
hausner
2014/08/20 21:42:52
Last as in "most recent" or "previous".
Michael Lippautz (Google)
2014/08/21 16:39:14
done: most recent
|
| +// generated state. |
| +// |
| +// In general it is expected (ASSERT) that the different kinds of markers reach |
| +// the FlowGraphBuilder in alternating order. That is: |
| +// <new state> -> <other nodes> -> <target> -> <other nodes> -> |
| +// <new state> -> ... |
| +class AwaitMarkerNode : public AstNode { |
| + public: |
| + enum Type { |
| + kNewContinuationState, |
| + kTargetForContinuation, |
| + }; |
| + |
| + explicit AwaitMarkerNode(Type type) |
| + : AstNode(Scanner::kNoSourcePos), type_(type) { } |
| + |
| + void VisitChildren(AstNodeVisitor* visitor) const { } |
| + |
| + Type type() const { return type_; } |
| + |
| + LocalScope* scope() const { return scope_; } |
| + void set_scope(LocalScope* scope) { scope_ = scope; } |
| + |
| + DECLARE_COMMON_NODE_FUNCTIONS(AwaitMarkerNode); |
| + |
| + private: |
| + Type type_; |
| + LocalScope* scope_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AwaitMarkerNode); |
| +}; |
| + |
| + |
| class SequenceNode : public AstNode { |
| public: |
| SequenceNode(intptr_t token_pos, LocalScope* scope) |
| @@ -536,24 +576,31 @@ class PrimaryNode : public AstNode { |
| DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode); |
| }; |
| - |
| -// TODO(mlippautz): Implement return nodes that are used to return from a |
| -// continuation. |
| +// Return nodes can be of different types: |
| +// * A regular return node that in the case of async functions gets replaced |
| +// with appropriate completer calls. This kind is generated by dart code. |
| +// * A continuation return that just returns from a function. This kind is |
| +// generated by AST transformers. |
| class ReturnNode : public AstNode { |
| public: |
| + enum Type { |
|
srdjan
2014/08/20 23:08:42
I would rename the enum since we have a class Type
Michael Lippautz (Google)
2014/08/21 16:39:14
Done.
|
| + kRegular, |
| + kContinuation, |
| + }; |
| + |
| // Return from a void function returns the null object. |
| explicit ReturnNode(intptr_t token_pos) |
| : AstNode(token_pos), |
| value_(new LiteralNode(token_pos, Instance::ZoneHandle())), |
| inlined_finally_list_(), |
| - is_regular_return_(true) { } |
| + type_(kRegular) { } |
| // Return from a non-void function. |
| ReturnNode(intptr_t token_pos, |
| AstNode* value) |
| : AstNode(token_pos), |
| value_(value), |
| inlined_finally_list_(), |
| - is_regular_return_(true) { |
| + type_(kRegular) { |
| ASSERT(value_ != NULL); |
| } |
| @@ -578,8 +625,8 @@ class ReturnNode : public AstNode { |
| void set_scope(LocalScope* scope) { scope_ = scope; } |
| LocalScope* scope() const { return scope_; } |
| - // Returns false if the return node is used to return from a continuation. |
| - bool is_regular_return() const { return is_regular_return_; } |
| + Type type() const { return type_; } |
| + void set_type(Type type) { type_ = type; } |
| DECLARE_COMMON_NODE_FUNCTIONS(ReturnNode); |
| @@ -587,7 +634,7 @@ class ReturnNode : public AstNode { |
| AstNode* value_; |
| GrowableArray<InlinedFinallyNode*> inlined_finally_list_; |
| LocalScope* scope_; |
| - bool is_regular_return_; |
| + Type type_; |
|
srdjan
2014/08/20 23:08:42
Add printing of type to ReturnNode printing.
Michael Lippautz (Google)
2014/08/21 16:39:14
Done.
|
| DISALLOW_COPY_AND_ASSIGN(ReturnNode); |
| }; |