OLD | NEW |
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/object_store.h" | 7 #include "vm/object_store.h" |
8 #include "vm/parser.h" | 8 #include "vm/parser.h" |
9 #include "vm/thread.h" | 9 #include "vm/thread.h" |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 void AwaitTransformer::VisitLiteralNode(LiteralNode* node) { | 100 void AwaitTransformer::VisitLiteralNode(LiteralNode* node) { |
101 result_ = node; | 101 result_ = node; |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 void AwaitTransformer::VisitTypeNode(TypeNode* node) { | 105 void AwaitTransformer::VisitTypeNode(TypeNode* node) { |
106 result_ = new(Z) TypeNode(node->token_pos(), node->type()); | 106 result_ = new(Z) TypeNode(node->token_pos(), node->type()); |
107 } | 107 } |
108 | 108 |
109 | 109 |
110 // Restore the currently relevant :saved_try_context_var on the stack | |
111 // from the captured :async_saved_try_ctx_var_<try_index>. | |
112 AstNode* AwaitTransformer::RestoreSavedTryContext(Zone* zone, | |
113 LocalScope* scope, | |
114 int16_t try_index) { | |
115 LocalVariable* saved_try_ctx = | |
116 scope->LocalLookupVariable(Symbols::SavedTryContextVar()); | |
117 ASSERT((saved_try_ctx != NULL) && !saved_try_ctx->is_captured()); | |
118 const String& async_saved_try_ctx_name = String::ZoneHandle(zone, | |
119 Symbols::New(String::Handle(zone, | |
120 String::NewFormatted("%s%d", | |
121 Symbols::AsyncSavedTryCtxVarPrefix().ToCString(), | |
122 try_index)))); | |
123 LocalVariable* async_saved_try_ctx = | |
124 scope->LocalLookupVariable(async_saved_try_ctx_name); | |
125 ASSERT(async_saved_try_ctx != NULL); | |
126 ASSERT(async_saved_try_ctx->is_captured()); | |
127 return new (zone) StoreLocalNode( | |
128 Scanner::kNoSourcePos, | |
129 saved_try_ctx, | |
130 new (zone) LoadLocalNode(Scanner::kNoSourcePos, async_saved_try_ctx)); | |
131 } | |
132 | |
133 | |
134 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { | 110 void AwaitTransformer::VisitAwaitNode(AwaitNode* node) { |
135 // Await transformation: | 111 // Await transformation: |
136 // | 112 // |
137 // :await_temp_var_X = <expr>; | 113 // :await_temp_var_X = <expr>; |
138 // :result_param = :await_temp_var_X; | 114 // :result_param = :await_temp_var_X; |
139 // if (:result_param is !Future) { | 115 // if (:result_param is !Future) { |
140 // :result_param = Future.value(:result_param); | 116 // :result_param = Future.value(:result_param); |
141 // } | 117 // } |
142 // AwaitMarker(kNewContinuationState); | 118 // AwaitMarker(kNewContinuationState); |
143 // :result_param = :result_param.then(:async_op); | 119 // :result_param = :result_param.then(:async_op); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 Scanner::kNoSourcePos, | 205 Scanner::kNoSourcePos, |
230 async_catch_helper, | 206 async_catch_helper, |
231 catch_helper_args)); | 207 catch_helper_args)); |
232 ReturnNode* continuation_return = new(Z) ReturnNode(Scanner::kNoSourcePos); | 208 ReturnNode* continuation_return = new(Z) ReturnNode(Scanner::kNoSourcePos); |
233 continuation_return->set_return_type(ReturnNode::kContinuationTarget); | 209 continuation_return->set_return_type(ReturnNode::kContinuationTarget); |
234 preamble_->Add(continuation_return); | 210 preamble_->Add(continuation_return); |
235 | 211 |
236 // If this expression is part of a try block, also append the code for | 212 // If this expression is part of a try block, also append the code for |
237 // restoring the saved try context that lives on the stack and possibly the | 213 // restoring the saved try context that lives on the stack and possibly the |
238 // saved try context of the outer try block. | 214 // saved try context of the outer try block. |
239 if (node->try_scope() != NULL) { | 215 if (node->saved_try_ctx() != NULL) { |
240 preamble_->Add(RestoreSavedTryContext(Z, | 216 preamble_->Add(new (Z) StoreLocalNode( |
241 node->try_scope(), | 217 Scanner::kNoSourcePos, |
242 node->try_index())); | 218 node->saved_try_ctx(), |
243 if (node->outer_try_scope() != NULL) { | 219 new (Z) LoadLocalNode(Scanner::kNoSourcePos, |
244 preamble_->Add(RestoreSavedTryContext(Z, | 220 node->async_saved_try_ctx()))); |
245 node->outer_try_scope(), | 221 if (node->outer_saved_try_ctx() != NULL) { |
246 node->outer_try_index())); | 222 preamble_->Add(new (Z) StoreLocalNode( |
| 223 Scanner::kNoSourcePos, |
| 224 node->outer_saved_try_ctx(), |
| 225 new (Z) LoadLocalNode(Scanner::kNoSourcePos, |
| 226 node->outer_async_saved_try_ctx()))); |
247 } | 227 } |
248 } else { | 228 } else { |
249 ASSERT(node->outer_try_scope() == NULL); | 229 ASSERT(node->outer_saved_try_ctx() == NULL); |
250 } | 230 } |
251 | 231 |
252 LoadLocalNode* load_error_param = new (Z) LoadLocalNode( | 232 LoadLocalNode* load_error_param = new (Z) LoadLocalNode( |
253 Scanner::kNoSourcePos, error_param); | 233 Scanner::kNoSourcePos, error_param); |
254 LoadLocalNode* load_stack_trace_param = new (Z) LoadLocalNode( | 234 LoadLocalNode* load_stack_trace_param = new (Z) LoadLocalNode( |
255 Scanner::kNoSourcePos, stack_trace_param); | 235 Scanner::kNoSourcePos, stack_trace_param); |
256 SequenceNode* error_ne_null_branch = new (Z) SequenceNode( | 236 SequenceNode* error_ne_null_branch = new (Z) SequenceNode( |
257 Scanner::kNoSourcePos, ChainNewScope(preamble_->scope())); | 237 Scanner::kNoSourcePos, ChainNewScope(preamble_->scope())); |
258 error_ne_null_branch->Add(new (Z) ThrowNode( | 238 error_ne_null_branch->Add(new (Z) ThrowNode( |
259 Scanner::kNoSourcePos, | 239 Scanner::kNoSourcePos, |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 | 603 |
624 | 604 |
625 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { | 605 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { |
626 AstNode* new_exception = Transform(node->exception()); | 606 AstNode* new_exception = Transform(node->exception()); |
627 result_ = new(Z) ThrowNode(node->token_pos(), | 607 result_ = new(Z) ThrowNode(node->token_pos(), |
628 new_exception, | 608 new_exception, |
629 node->stacktrace()); | 609 node->stacktrace()); |
630 } | 610 } |
631 | 611 |
632 } // namespace dart | 612 } // namespace dart |
OLD | NEW |