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

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

Issue 447003003: Introduce await (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 6 years, 4 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 | « runtime/vm/ast_printer.cc ('k') | runtime/vm/ast_transformer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 #ifndef VM_AST_TRANSFORMER_H_
6 #define VM_AST_TRANSFORMER_H_
7
8 #include "platform/assert.h"
9 #include "vm/ast.h"
10
11 namespace dart {
12
13 class ParsedFunction;
14
15 // Translate an AstNode containing an expression (that itself contains one or
16 // more awaits) into a sequential representation where subexpressions are
17 // evaluated sequentially into intermediates. Those intermediates are stored
18 // within a context.
19 //
20 // This allows a function to be suspended and resumed from within evaluating an
21 // expression. The evaluation is split among a so-called preamble and the
22 // evaluation of the resulting expression (which is only a single load).
23 //
24 // Example (minimalistic):
25 //
26 // var a = (await bar()) + foo();
27 //
28 // This translates to a premable similar to:
29 //
30 // var t_1, t_2, t_3, t_4; // All stored in a context.
31 // t_1 = bar();
32 // :result_param = t_1;
33 // <continuation logic>
34 // t_2 = :result_param;
35 // t_3 = foo();
36 // t_4 = t_2.operator+(t_3);
37 //
38 // and a resulting expression of a load of t_4.
39 //
40 class AwaitTransformer : public AstNodeVisitor {
41 public:
42 AwaitTransformer(SequenceNode* preamble,
43 const Library& library,
44 ParsedFunction* const parsed_function)
45 : preamble_(preamble),
46 temp_cnt_(0),
47 library_(library),
48 parsed_function_(parsed_function),
49 isolate_(Isolate::Current()) {}
50
51 #define DECLARE_VISIT(BaseName) \
52 virtual void Visit##BaseName##Node(BaseName##Node* node);
53
54 FOR_EACH_NODE(DECLARE_VISIT)
55 #undef DECLARE_VISIT
56
57 AstNode* Transform(AstNode* expr);
58
59 private:
60 LocalVariable* EnsureCurrentTempVar();
61 LocalVariable* AddToPreambleNewTempVar(AstNode* node);
62 ArgumentListNode* TransformArguments(ArgumentListNode* node);
63 AstNode* LazyTransform(const Token::Kind kind,
64 AstNode* new_left,
65 AstNode* right);
66
67 void NextTempVar() { temp_cnt_++; }
68
69 Isolate* isolate() const { return isolate_; }
70
71 SequenceNode* preamble_;
72 int temp_cnt_;
73 AstNode* result_;
74 const Library& library_;
75 ParsedFunction* const parsed_function_;
76
77 Isolate* isolate_;
78
79 DISALLOW_COPY_AND_ASSIGN(AwaitTransformer);
80 };
81
82 } // namespace dart
83
84 #endif // VM_AST_TRANSFORMER_H_
OLDNEW
« no previous file with comments | « runtime/vm/ast_printer.cc ('k') | runtime/vm/ast_transformer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698