Chromium Code Reviews| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 preamble_->scope(), Symbols::AsyncOperation()); | 129 preamble_->scope(), Symbols::AsyncOperation()); |
| 130 LocalVariable* result_param = GetVariableInScope( | 130 LocalVariable* result_param = GetVariableInScope( |
| 131 preamble_->scope(), Symbols::AsyncOperationParam()); | 131 preamble_->scope(), Symbols::AsyncOperationParam()); |
| 132 LocalVariable* error_param = GetVariableInScope( | 132 LocalVariable* error_param = GetVariableInScope( |
| 133 preamble_->scope(), Symbols::AsyncOperationErrorParam()); | 133 preamble_->scope(), Symbols::AsyncOperationErrorParam()); |
| 134 LocalVariable* stack_trace_param = GetVariableInScope( | 134 LocalVariable* stack_trace_param = GetVariableInScope( |
| 135 preamble_->scope(), Symbols::AsyncOperationStackTraceParam()); | 135 preamble_->scope(), Symbols::AsyncOperationStackTraceParam()); |
| 136 | 136 |
| 137 AstNode* transformed_expr = Transform(node->expr()); | 137 AstNode* transformed_expr = Transform(node->expr()); |
| 138 preamble_->Add(new(Z) StoreLocalNode( | 138 preamble_->Add(new(Z) StoreLocalNode( |
| 139 Scanner::kNoSourcePos, result_param, transformed_expr)); | 139 node->token_pos(), result_param, transformed_expr)); |
| 140 | 140 |
| 141 LoadLocalNode* load_result_param = new(Z) LoadLocalNode( | 141 LoadLocalNode* load_result_param = new(Z) LoadLocalNode( |
| 142 Scanner::kNoSourcePos, result_param); | 142 node->token_pos(), result_param); |
| 143 | 143 |
| 144 const Class& future_cls = | 144 const Class& future_cls = |
| 145 Class::ZoneHandle(Z, thread()->isolate()->object_store()->future_class()); | 145 Class::ZoneHandle(Z, thread()->isolate()->object_store()->future_class()); |
| 146 ASSERT(!future_cls.IsNull()); | 146 ASSERT(!future_cls.IsNull()); |
| 147 const AbstractType& future_type = | 147 const AbstractType& future_type = |
| 148 AbstractType::ZoneHandle(Z, future_cls.RareType()); | 148 AbstractType::ZoneHandle(Z, future_cls.RareType()); |
| 149 ASSERT(!future_type.IsNull()); | 149 ASSERT(!future_type.IsNull()); |
| 150 | 150 |
| 151 LocalScope* is_not_future_scope = ChainNewScope(preamble_->scope()); | 151 LocalScope* is_not_future_scope = ChainNewScope(preamble_->scope()); |
| 152 SequenceNode* is_not_future_branch = | 152 SequenceNode* is_not_future_branch = |
| 153 new (Z) SequenceNode(Scanner::kNoSourcePos, is_not_future_scope); | 153 new (Z) SequenceNode(node->token_pos(), is_not_future_scope); |
|
hausner
2015/02/12 17:18:44
The reason why all these nodes that have no equiva
| |
| 154 | 154 |
| 155 // if (:result_param is !Future) { | 155 // if (:result_param is !Future) { |
| 156 // :result_param = Future.value(:result_param); | 156 // :result_param = Future.value(:result_param); |
| 157 // } | 157 // } |
| 158 const Function& value_ctor = Function::ZoneHandle( | 158 const Function& value_ctor = Function::ZoneHandle( |
| 159 Z, future_cls.LookupFunction(Symbols::FutureValue())); | 159 Z, future_cls.LookupFunction(Symbols::FutureValue())); |
| 160 ASSERT(!value_ctor.IsNull()); | 160 ASSERT(!value_ctor.IsNull()); |
| 161 ArgumentListNode* ctor_args = new (Z) ArgumentListNode(Scanner::kNoSourcePos); | 161 ArgumentListNode* ctor_args = new (Z) ArgumentListNode(node->token_pos()); |
| 162 ctor_args->Add(new (Z) LoadLocalNode(Scanner::kNoSourcePos, result_param)); | 162 ctor_args->Add(new (Z) LoadLocalNode(node->token_pos(), result_param)); |
| 163 ConstructorCallNode* ctor_call = | 163 ConstructorCallNode* ctor_call = |
| 164 new (Z) ConstructorCallNode(Scanner::kNoSourcePos, | 164 new (Z) ConstructorCallNode(node->token_pos(), |
| 165 TypeArguments::ZoneHandle(Z), | 165 TypeArguments::ZoneHandle(Z), |
| 166 value_ctor, | 166 value_ctor, |
| 167 ctor_args); | 167 ctor_args); |
| 168 is_not_future_branch->Add(new (Z) StoreLocalNode( | 168 is_not_future_branch->Add(new (Z) StoreLocalNode( |
| 169 Scanner::kNoSourcePos, result_param, ctor_call)); | 169 node->token_pos(), result_param, ctor_call)); |
| 170 AstNode* is_not_future_test = new (Z) ComparisonNode( | 170 AstNode* is_not_future_test = new (Z) ComparisonNode( |
| 171 Scanner::kNoSourcePos, | 171 node->token_pos(), |
| 172 Token::kISNOT, | 172 Token::kISNOT, |
| 173 load_result_param, | 173 load_result_param, |
| 174 new (Z) TypeNode(Scanner::kNoSourcePos, future_type)); | 174 new (Z) TypeNode(node->token_pos(), future_type)); |
| 175 preamble_->Add(new(Z) IfNode(Scanner::kNoSourcePos, | 175 preamble_->Add(new(Z) IfNode(node->token_pos(), |
| 176 is_not_future_test, | 176 is_not_future_test, |
| 177 is_not_future_branch, | 177 is_not_future_branch, |
| 178 NULL)); | 178 NULL)); |
| 179 | 179 |
| 180 AwaitMarkerNode* await_marker = new (Z) AwaitMarkerNode(); | 180 AwaitMarkerNode* await_marker = new (Z) AwaitMarkerNode(); |
| 181 await_marker->set_scope(preamble_->scope()); | 181 await_marker->set_scope(preamble_->scope()); |
| 182 preamble_->Add(await_marker); | 182 preamble_->Add(await_marker); |
| 183 ArgumentListNode* args = new(Z) ArgumentListNode(Scanner::kNoSourcePos); | 183 ArgumentListNode* args = new(Z) ArgumentListNode(node->token_pos()); |
| 184 | 184 |
| 185 args->Add(new(Z) LoadLocalNode(Scanner::kNoSourcePos, async_op)); | 185 args->Add(new(Z) LoadLocalNode(node->token_pos(), async_op)); |
| 186 preamble_->Add(new (Z) StoreLocalNode( | 186 preamble_->Add(new (Z) StoreLocalNode( |
| 187 Scanner::kNoSourcePos, | 187 node->token_pos(), |
| 188 result_param, | 188 result_param, |
| 189 new(Z) InstanceCallNode(Scanner::kNoSourcePos, | 189 new(Z) InstanceCallNode(node->token_pos(), |
|
Florian Schneider
2015/02/13 10:25:27
To fix the bug it would be enough to record it her
| |
| 190 load_result_param, | 190 load_result_param, |
| 191 Symbols::FutureThen(), | 191 Symbols::FutureThen(), |
| 192 args))); | 192 args))); |
| 193 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | 193 const Library& core_lib = Library::Handle(Library::CoreLibrary()); |
| 194 const Function& async_catch_helper = Function::ZoneHandle( | 194 const Function& async_catch_helper = Function::ZoneHandle( |
| 195 Z, core_lib.LookupFunctionAllowPrivate(Symbols::AsyncCatchHelper())); | 195 Z, core_lib.LookupFunctionAllowPrivate(Symbols::AsyncCatchHelper())); |
| 196 ASSERT(!async_catch_helper.IsNull()); | 196 ASSERT(!async_catch_helper.IsNull()); |
| 197 ArgumentListNode* catch_helper_args = new (Z) ArgumentListNode( | 197 ArgumentListNode* catch_helper_args = new (Z) ArgumentListNode( |
| 198 Scanner::kNoSourcePos); | 198 node->token_pos()); |
| 199 InstanceGetterNode* catch_error_getter = new (Z) InstanceGetterNode( | 199 InstanceGetterNode* catch_error_getter = new (Z) InstanceGetterNode( |
| 200 Scanner::kNoSourcePos, | 200 node->token_pos(), |
| 201 load_result_param, | 201 load_result_param, |
| 202 Symbols::FutureCatchError()); | 202 Symbols::FutureCatchError()); |
| 203 catch_helper_args->Add(catch_error_getter); | 203 catch_helper_args->Add(catch_error_getter); |
| 204 catch_helper_args->Add(new (Z) LoadLocalNode( | 204 catch_helper_args->Add(new (Z) LoadLocalNode( |
| 205 Scanner::kNoSourcePos, async_op)); | 205 node->token_pos(), async_op)); |
| 206 preamble_->Add(new (Z) StaticCallNode( | 206 preamble_->Add(new (Z) StaticCallNode( |
| 207 Scanner::kNoSourcePos, | 207 node->token_pos(), |
| 208 async_catch_helper, | 208 async_catch_helper, |
| 209 catch_helper_args)); | 209 catch_helper_args)); |
| 210 ReturnNode* continuation_return = new(Z) ReturnNode(Scanner::kNoSourcePos); | 210 ReturnNode* continuation_return = new(Z) ReturnNode(node->token_pos()); |
| 211 continuation_return->set_return_type(ReturnNode::kContinuationTarget); | 211 continuation_return->set_return_type(ReturnNode::kContinuationTarget); |
| 212 preamble_->Add(continuation_return); | 212 preamble_->Add(continuation_return); |
| 213 | 213 |
| 214 // If this expression is part of a try block, also append the code for | 214 // If this expression is part of a try block, also append the code for |
| 215 // restoring the saved try context that lives on the stack. | 215 // restoring the saved try context that lives on the stack. |
| 216 const String& async_saved_try_ctx_name = | 216 const String& async_saved_try_ctx_name = |
| 217 String::Handle(Z, parsed_function_.async_saved_try_ctx_name()); | 217 String::Handle(Z, parsed_function_.async_saved_try_ctx_name()); |
| 218 if (!async_saved_try_ctx_name.IsNull()) { | 218 if (!async_saved_try_ctx_name.IsNull()) { |
| 219 LocalVariable* async_saved_try_ctx = | 219 LocalVariable* async_saved_try_ctx = |
| 220 GetVariableInScope(preamble_->scope(), async_saved_try_ctx_name); | 220 GetVariableInScope(preamble_->scope(), async_saved_try_ctx_name); |
| 221 preamble_->Add(new (Z) StoreLocalNode( | 221 preamble_->Add(new (Z) StoreLocalNode( |
| 222 Scanner::kNoSourcePos, | 222 node->token_pos(), |
| 223 parsed_function_.saved_try_ctx(), | 223 parsed_function_.saved_try_ctx(), |
| 224 new (Z) LoadLocalNode(Scanner::kNoSourcePos, async_saved_try_ctx))); | 224 new (Z) LoadLocalNode(node->token_pos(), async_saved_try_ctx))); |
| 225 } | 225 } |
| 226 | 226 |
| 227 LoadLocalNode* load_error_param = new (Z) LoadLocalNode( | 227 LoadLocalNode* load_error_param = new (Z) LoadLocalNode( |
| 228 Scanner::kNoSourcePos, error_param); | 228 node->token_pos(), error_param); |
| 229 LoadLocalNode* load_stack_trace_param = new (Z) LoadLocalNode( | 229 LoadLocalNode* load_stack_trace_param = new (Z) LoadLocalNode( |
| 230 Scanner::kNoSourcePos, stack_trace_param); | 230 node->token_pos(), stack_trace_param); |
| 231 SequenceNode* error_ne_null_branch = new (Z) SequenceNode( | 231 SequenceNode* error_ne_null_branch = new (Z) SequenceNode( |
| 232 Scanner::kNoSourcePos, ChainNewScope(preamble_->scope())); | 232 node->token_pos(), ChainNewScope(preamble_->scope())); |
| 233 error_ne_null_branch->Add(new (Z) ThrowNode( | 233 error_ne_null_branch->Add(new (Z) ThrowNode( |
| 234 Scanner::kNoSourcePos, | 234 node->token_pos(), |
| 235 load_error_param, | 235 load_error_param, |
| 236 load_stack_trace_param)); | 236 load_stack_trace_param)); |
| 237 preamble_->Add(new (Z) IfNode( | 237 preamble_->Add(new (Z) IfNode( |
| 238 Scanner::kNoSourcePos, | 238 node->token_pos(), |
| 239 new (Z) ComparisonNode( | 239 new (Z) ComparisonNode( |
| 240 Scanner::kNoSourcePos, | 240 node->token_pos(), |
| 241 Token::kNE, | 241 Token::kNE, |
| 242 load_error_param, | 242 load_error_param, |
| 243 new (Z) LiteralNode(Scanner::kNoSourcePos, | 243 new (Z) LiteralNode(node->token_pos(), |
| 244 Object::null_instance())), | 244 Object::null_instance())), |
| 245 error_ne_null_branch, | 245 error_ne_null_branch, |
| 246 NULL)); | 246 NULL)); |
| 247 | 247 |
| 248 LocalVariable* result = AddToPreambleNewTempVar(new(Z) LoadLocalNode( | 248 LocalVariable* result = AddToPreambleNewTempVar(new(Z) LoadLocalNode( |
| 249 Scanner::kNoSourcePos, result_param)); | 249 node->token_pos(), result_param)); |
|
hausner
2015/02/12 17:18:44
This is a good example of code that will most like
Florian Schneider
2015/02/13 10:21:06
I can only assign the tokenposition to the call in
| |
| 250 result_ = new(Z) LoadLocalNode(Scanner::kNoSourcePos, result); | 250 result_ = new(Z) LoadLocalNode(node->token_pos(), result); |
| 251 } | 251 } |
| 252 | 252 |
| 253 | 253 |
| 254 // Transforms boolean expressions into a sequence of evaluatons that only lazily | 254 // Transforms boolean expressions into a sequence of evaluatons that only lazily |
| 255 // evaluate subexpressions. | 255 // evaluate subexpressions. |
| 256 // | 256 // |
| 257 // Example: | 257 // Example: |
| 258 // | 258 // |
| 259 // (a || b) only evaluates b if a is false | 259 // (a || b) only evaluates b if a is false |
| 260 // | 260 // |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { | 599 void AwaitTransformer::VisitThrowNode(ThrowNode* node) { |
| 600 // TODO(mlippautz): Check if relevant. | 600 // TODO(mlippautz): Check if relevant. |
| 601 AstNode* new_exception = Transform(node->exception()); | 601 AstNode* new_exception = Transform(node->exception()); |
| 602 AstNode* new_stacktrace = Transform(node->stacktrace()); | 602 AstNode* new_stacktrace = Transform(node->stacktrace()); |
| 603 result_ = new(Z) ThrowNode(node->token_pos(), | 603 result_ = new(Z) ThrowNode(node->token_pos(), |
| 604 new_exception, | 604 new_exception, |
| 605 new_stacktrace); | 605 new_stacktrace); |
| 606 } | 606 } |
| 607 | 607 |
| 608 } // namespace dart | 608 } // namespace dart |
| OLD | NEW |