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

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

Issue 508643004: Fix scope/context behavior in await transformer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: addressed comments 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 | « runtime/vm/ast_transformer.h ('k') | runtime/vm/parser.h » ('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) 2014, the Dart project authors. Please see the AUTHORS file 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 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 #include "vm/ast_transformer.h" 5 #include "vm/ast_transformer.h"
6 6
7 #include "vm/parser.h" 7 #include "vm/parser.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 FOR_EACH_UNREACHABLE_NODE(DEFINE_UNREACHABLE) 42 FOR_EACH_UNREACHABLE_NODE(DEFINE_UNREACHABLE)
43 #undef DEFINE_UNREACHABLE 43 #undef DEFINE_UNREACHABLE
44 44
45 45
46 AstNode* AwaitTransformer::Transform(AstNode* expr) { 46 AstNode* AwaitTransformer::Transform(AstNode* expr) {
47 expr->Visit(this); 47 expr->Visit(this);
48 return result_; 48 return result_;
49 } 49 }
50 50
51 51
52 LocalScope* AwaitTransformer::NewScope(LocalScope* parent) {
53 return new (I) LocalScope(
54 parent, parent->function_level(), parent->loop_level());
55 }
56
57
52 LocalVariable* AwaitTransformer::EnsureCurrentTempVar() { 58 LocalVariable* AwaitTransformer::EnsureCurrentTempVar() {
53 const char* await_temp_prefix = ":await_temp_var_"; 59 const char* await_temp_prefix = ":await_temp_var_";
54 const String& cnt_str = String::ZoneHandle( 60 const String& cnt_str = String::ZoneHandle(
55 I, String::NewFormatted("%s%d", await_temp_prefix, temp_cnt_)); 61 I, String::NewFormatted("%s%d", await_temp_prefix, temp_cnt_));
56 const String& symbol = String::ZoneHandle(I, Symbols::New(cnt_str)); 62 const String& symbol = String::ZoneHandle(I, Symbols::New(cnt_str));
57 ASSERT(!symbol.IsNull()); 63 ASSERT(!symbol.IsNull());
58 LocalVariable* await_tmp = 64 LocalVariable* await_tmp =
59 parsed_function_->await_temps_scope()->LookupVariable(symbol, false); 65 parsed_function_->await_temps_scope()->LookupVariable(symbol, false);
60 if (await_tmp == NULL) { 66 if (await_tmp == NULL) {
61 await_tmp = new(I) LocalVariable( 67 await_tmp = new(I) LocalVariable(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 LocalVariable* result_param = preamble_->scope()->LookupVariable( 112 LocalVariable* result_param = preamble_->scope()->LookupVariable(
107 Symbols::AsyncOperationParam(), false); 113 Symbols::AsyncOperationParam(), false);
108 ASSERT(result_param != NULL); 114 ASSERT(result_param != NULL);
109 115
110 node->expr()->Visit(this); 116 node->expr()->Visit(this);
111 preamble_->Add(new(I) StoreLocalNode( 117 preamble_->Add(new(I) StoreLocalNode(
112 Scanner::kNoSourcePos, result_param, result_)); 118 Scanner::kNoSourcePos, result_param, result_));
113 LoadLocalNode* load_result_param = new(I) LoadLocalNode( 119 LoadLocalNode* load_result_param = new(I) LoadLocalNode(
114 Scanner::kNoSourcePos, result_param); 120 Scanner::kNoSourcePos, result_param);
115 SequenceNode* is_future_branch = new(I) SequenceNode( 121 SequenceNode* is_future_branch = new(I) SequenceNode(
116 Scanner::kNoSourcePos, preamble_->scope()); 122 Scanner::kNoSourcePos, NewScope(preamble_->scope()));
117 AwaitMarkerNode* await_marker = 123 AwaitMarkerNode* await_marker =
118 new(I) AwaitMarkerNode(AwaitMarkerNode::kNewContinuationState); 124 new(I) AwaitMarkerNode(AwaitMarkerNode::kNewContinuationState);
119 await_marker->set_scope(preamble_->scope()); 125 await_marker->set_scope(preamble_->scope());
120 is_future_branch->Add(await_marker); 126 is_future_branch->Add(await_marker);
121 ArgumentListNode* args = new(I) ArgumentListNode(Scanner::kNoSourcePos); 127 ArgumentListNode* args = new(I) ArgumentListNode(Scanner::kNoSourcePos);
122 args->Add(new(I) LoadLocalNode(Scanner::kNoSourcePos, async_op)); 128 args->Add(new(I) LoadLocalNode(Scanner::kNoSourcePos, async_op));
123 is_future_branch->Add(new(I) InstanceCallNode( 129 is_future_branch->Add(new(I) InstanceCallNode(
124 Scanner::kNoSourcePos, load_result_param, Symbols::FutureThen(), args)); 130 Scanner::kNoSourcePos, load_result_param, Symbols::FutureThen(), args));
125 ReturnNode* continuation_return = new(I) ReturnNode(Scanner::kNoSourcePos); 131 ReturnNode* continuation_return = new(I) ReturnNode(Scanner::kNoSourcePos);
126 continuation_return->set_return_type(ReturnNode::kContinuation); 132 continuation_return->set_return_type(ReturnNode::kContinuation);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // t_3 = t_1 || t_2; // Compiler takes care that lazy evaluation takes place 179 // t_3 = t_1 || t_2; // Compiler takes care that lazy evaluation takes place
174 // on this level. 180 // on this level.
175 AstNode* AwaitTransformer::LazyTransform(const Token::Kind logical_op, 181 AstNode* AwaitTransformer::LazyTransform(const Token::Kind logical_op,
176 AstNode* new_left, 182 AstNode* new_left,
177 AstNode* right) { 183 AstNode* right) {
178 ASSERT(logical_op == Token::kAND || logical_op == Token::kOR); 184 ASSERT(logical_op == Token::kAND || logical_op == Token::kOR);
179 AstNode* result = NULL; 185 AstNode* result = NULL;
180 const Token::Kind compare_logical_op = (logical_op == Token::kAND) ? 186 const Token::Kind compare_logical_op = (logical_op == Token::kAND) ?
181 Token::kEQ : Token::kNE; 187 Token::kEQ : Token::kNE;
182 SequenceNode* eval = new(I) SequenceNode( 188 SequenceNode* eval = new(I) SequenceNode(
183 Scanner::kNoSourcePos, preamble_->scope()); 189 Scanner::kNoSourcePos, NewScope(preamble_->scope()));
184 SequenceNode* saved_preamble = preamble_; 190 SequenceNode* saved_preamble = preamble_;
185 preamble_ = eval; 191 preamble_ = eval;
186 result = Transform(right); 192 result = Transform(right);
187 preamble_ = saved_preamble; 193 preamble_ = saved_preamble;
188 IfNode* right_body = new(I) IfNode( 194 IfNode* right_body = new(I) IfNode(
189 Scanner::kNoSourcePos, 195 Scanner::kNoSourcePos,
190 new(I) ComparisonNode( 196 new(I) ComparisonNode(
191 Scanner::kNoSourcePos, 197 Scanner::kNoSourcePos,
192 compare_logical_op, 198 compare_logical_op,
193 new_left, 199 new_left,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 new(I) UnaryOpNode(node->token_pos(), node->kind(), new_operand)); 263 new(I) UnaryOpNode(node->token_pos(), node->kind(), new_operand));
258 result_ = new(I) LoadLocalNode(Scanner::kNoSourcePos, result); 264 result_ = new(I) LoadLocalNode(Scanner::kNoSourcePos, result);
259 } 265 }
260 266
261 267
262 // ::= (<condition>) ? <true-branch> : <false-branch> 268 // ::= (<condition>) ? <true-branch> : <false-branch>
263 // 269 //
264 void AwaitTransformer::VisitConditionalExprNode(ConditionalExprNode* node) { 270 void AwaitTransformer::VisitConditionalExprNode(ConditionalExprNode* node) {
265 AstNode* new_condition = Transform(node->condition()); 271 AstNode* new_condition = Transform(node->condition());
266 SequenceNode* new_true = new(I) SequenceNode( 272 SequenceNode* new_true = new(I) SequenceNode(
267 Scanner::kNoSourcePos, preamble_->scope()); 273 Scanner::kNoSourcePos, NewScope(preamble_->scope()));
268 SequenceNode* saved_preamble = preamble_; 274 SequenceNode* saved_preamble = preamble_;
269 preamble_ = new_true; 275 preamble_ = new_true;
270 AstNode* new_true_result = Transform(node->true_expr()); 276 AstNode* new_true_result = Transform(node->true_expr());
271 SequenceNode* new_false = new(I) SequenceNode( 277 SequenceNode* new_false = new(I) SequenceNode(
272 Scanner::kNoSourcePos, preamble_->scope()); 278 Scanner::kNoSourcePos, NewScope(preamble_->scope()));
273 preamble_ = new_false; 279 preamble_ = new_false;
274 AstNode* new_false_result = Transform(node->false_expr()); 280 AstNode* new_false_result = Transform(node->false_expr());
275 preamble_ = saved_preamble; 281 preamble_ = saved_preamble;
276 IfNode* new_if = new(I) IfNode(Scanner::kNoSourcePos, 282 IfNode* new_if = new(I) IfNode(Scanner::kNoSourcePos,
277 new_condition, 283 new_condition,
278 new_true, 284 new_true,
279 new_false); 285 new_false);
280 preamble_->Add(new_if); 286 preamble_->Add(new_if);
281 LocalVariable* result = AddToPreambleNewTempVar( 287 LocalVariable* result = AddToPreambleNewTempVar(
282 new(I) ConditionalExprNode(Scanner::kNoSourcePos, 288 new(I) ConditionalExprNode(Scanner::kNoSourcePos,
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { 511 void AwaitTransformer::VisitThrowNode(ThrowNode* node) {
506 // TODO(mlippautz): Check if relevant. 512 // TODO(mlippautz): Check if relevant.
507 AstNode* new_exception = Transform(node->exception()); 513 AstNode* new_exception = Transform(node->exception());
508 AstNode* new_stacktrace = Transform(node->stacktrace()); 514 AstNode* new_stacktrace = Transform(node->stacktrace());
509 result_ = new(I) ThrowNode(node->token_pos(), 515 result_ = new(I) ThrowNode(node->token_pos(),
510 new_exception, 516 new_exception,
511 new_stacktrace); 517 new_stacktrace);
512 } 518 }
513 519
514 } // namespace dart 520 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ast_transformer.h ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698