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 // Tranlate an AstNode containing an expression (that contains one or more | |
srdjan
2014/08/13 18:41:06
s/Tranlate/Translate/
Michael Lippautz (Google)
2014/08/13 20:32:23
Done.
| |
16 // awaits) into a sequential representation that evaluation one subexpression | |
srdjan
2014/08/13 18:41:06
fix sentence.
Michael Lippautz (Google)
2014/08/13 20:32:24
Holy crap. It should now be an actual english sent
| |
17 // after another into intermediates. Intermediates are stored within a context. | |
18 // | |
19 // This allows a function to be suspended and continue from within evaluating an | |
20 // expression. The evaluation is split among a so called preamble and the | |
srdjan
2014/08/13 18:41:06
s/so called/so-called/
Michael Lippautz (Google)
2014/08/13 20:32:24
Done.
| |
21 // evaluation of the resulting expression (which is only a single load). | |
22 // | |
23 // Example (minimalisitc): | |
srdjan
2014/08/13 18:41:06
s/minimalisitc/minimalistic/
Michael Lippautz (Google)
2014/08/13 20:32:23
Done.
| |
24 // | |
25 // var a = (await bar()) + foo(); | |
26 // | |
27 // This translates to a premable similar to: | |
28 // | |
29 // var t_1, t_2, t_3, t_4; // All stored in a context. | |
30 // t_1 = bar(); | |
31 // :result_param = t_1; | |
32 // <continuation logic> | |
33 // t_2 = :result_param; | |
34 // t_3 = foo(); | |
35 // t_4 = t_2.operator+(t_3); | |
36 // | |
37 // and a resulting expression of a load of t_4. | |
38 // | |
39 class AwaitTransformer : public AstNodeVisitor { | |
40 public: | |
41 explicit AwaitTransformer(SequenceNode* preamble, | |
srdjan
2014/08/13 18:41:06
No explicit
Michael Lippautz (Google)
2014/08/13 20:32:23
Done.
| |
42 const Library& library, | |
43 ParsedFunction* const parsed_function) | |
44 : preamble_(preamble), | |
45 temp_cnt_(0), | |
46 library_(library), | |
47 parsed_function_(parsed_function), | |
48 isolate_(Isolate::Current()) {} | |
49 | |
50 #define DECLARE_VISIT(BaseName) \ | |
51 virtual void Visit##BaseName##Node(BaseName##Node* node); | |
52 | |
53 FOR_EACH_NODE(DECLARE_VISIT) | |
54 #undef DECLARE_VISIT | |
55 | |
56 void Transform(AstNode* expr); | |
57 AstNode* Result() const { return result_; } | |
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_ | |
OLD | NEW |