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

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

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