OLD | NEW |
---|---|
(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 continue from within evaluating an | |
hausner
2014/08/15 18:09:31
'continued', or maybe 'resumed'
Michael Lippautz (Google)
2014/08/18 18:39:30
Done.
| |
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 void Transform(AstNode* expr); | |
58 AstNode* Result() const { return result_; } | |
59 | |
60 private: | |
61 LocalVariable* EnsureCurrentTempVar(); | |
62 LocalVariable* AddToPreambleNewTempVar(AstNode* node); | |
63 ArgumentListNode* TransformArguments(ArgumentListNode* node); | |
64 AstNode* LazyTransform(const Token::Kind kind, | |
65 AstNode* new_left, | |
66 AstNode* right); | |
67 | |
68 void NextTempVar() { temp_cnt_++; } | |
69 | |
70 Isolate* isolate() const { return isolate_; } | |
71 | |
72 SequenceNode* preamble_; | |
73 int temp_cnt_; | |
74 AstNode* result_; | |
75 const Library& library_; | |
76 ParsedFunction* const parsed_function_; | |
77 | |
78 Isolate* isolate_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(AwaitTransformer); | |
81 }; | |
82 | |
83 } // namespace dart | |
84 | |
85 #endif // VM_AST_TRANSFORMER_H_ | |
OLD | NEW |