OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "vm/kernel_to_il.h" | 9 #include "vm/kernel_to_il.h" |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 | 95 |
96 void ScopeBuilder::AddParameter(VariableDeclaration* declaration, | 96 void ScopeBuilder::AddParameter(VariableDeclaration* declaration, |
97 intptr_t pos) { | 97 intptr_t pos) { |
98 LocalVariable* variable = MakeVariable( | 98 LocalVariable* variable = MakeVariable( |
99 declaration->position(), declaration->position(), | 99 declaration->position(), declaration->position(), |
100 H.DartSymbol(declaration->name()), T.TranslateVariableType(declaration)); | 100 H.DartSymbol(declaration->name()), T.TranslateVariableType(declaration)); |
101 if (declaration->IsFinal()) { | 101 if (declaration->IsFinal()) { |
102 variable->set_is_final(); | 102 variable->set_is_final(); |
103 } | 103 } |
| 104 if (variable->name().raw() == Symbols::IteratorParameter().raw()) { |
| 105 variable->set_is_forced_stack(); |
| 106 } |
104 scope_->InsertParameterAt(pos, variable); | 107 scope_->InsertParameterAt(pos, variable); |
105 result_->locals.Insert(declaration->kernel_offset(), variable); | 108 result_->locals.Insert(declaration->kernel_offset(), variable); |
106 | 109 |
107 // The default value may contain 'let' bindings for which the constant | 110 // The default value may contain 'let' bindings for which the constant |
108 // evaluator needs scope bindings. | 111 // evaluator needs scope bindings. |
109 Expression* defaultValue = declaration->initializer(); | 112 Expression* defaultValue = declaration->initializer(); |
110 if (defaultValue != NULL) { | 113 if (defaultValue != NULL) { |
111 defaultValue->AcceptExpressionVisitor(this); | 114 defaultValue->AcceptExpressionVisitor(this); |
112 } | 115 } |
113 } | 116 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 enclosing_scope = LocalScope::RestoreOuterScope( | 299 enclosing_scope = LocalScope::RestoreOuterScope( |
297 ContextScope::Handle(Z, function.context_scope())); | 300 ContextScope::Handle(Z, function.context_scope())); |
298 } | 301 } |
299 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); | 302 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); |
300 scope_->set_begin_token_pos(function.token_pos()); | 303 scope_->set_begin_token_pos(function.token_pos()); |
301 scope_->set_end_token_pos(function.end_token_pos()); | 304 scope_->set_end_token_pos(function.end_token_pos()); |
302 | 305 |
303 LocalVariable* context_var = parsed_function->current_context_var(); | 306 LocalVariable* context_var = parsed_function->current_context_var(); |
304 context_var->set_is_forced_stack(); | 307 context_var->set_is_forced_stack(); |
305 scope_->AddVariable(context_var); | 308 scope_->AddVariable(context_var); |
306 scope_->AddVariable(parsed_function->EnsureExpressionTemp()); | |
307 | 309 |
308 parsed_function->SetNodeSequence( | 310 parsed_function->SetNodeSequence( |
309 new SequenceNode(TokenPosition::kNoSource, scope_)); | 311 new SequenceNode(TokenPosition::kNoSource, scope_)); |
310 | 312 |
311 switch (function.kind()) { | 313 switch (function.kind()) { |
312 case RawFunction::kClosureFunction: | 314 case RawFunction::kClosureFunction: |
313 case RawFunction::kRegularFunction: | 315 case RawFunction::kRegularFunction: |
314 case RawFunction::kGetterFunction: | 316 case RawFunction::kGetterFunction: |
315 case RawFunction::kSetterFunction: | 317 case RawFunction::kSetterFunction: |
316 case RawFunction::kConstructor: { | 318 case RawFunction::kConstructor: { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 TokenPosition::kNoSource, TokenPosition::kNoSource, | 438 TokenPosition::kNoSource, TokenPosition::kNoSource, |
437 dart::String::ZoneHandle(Z, function.ParameterNameAt(i)), | 439 dart::String::ZoneHandle(Z, function.ParameterNameAt(i)), |
438 AbstractType::dynamic_type()); | 440 AbstractType::dynamic_type()); |
439 scope_->InsertParameterAt(i, variable); | 441 scope_->InsertParameterAt(i, variable); |
440 } | 442 } |
441 break; | 443 break; |
442 case RawFunction::kSignatureFunction: | 444 case RawFunction::kSignatureFunction: |
443 case RawFunction::kIrregexpFunction: | 445 case RawFunction::kIrregexpFunction: |
444 UNREACHABLE(); | 446 UNREACHABLE(); |
445 } | 447 } |
446 | 448 if (needs_expr_temp_) { |
| 449 scope_->AddVariable(parsed_function_->EnsureExpressionTemp()); |
| 450 } |
447 parsed_function->AllocateVariables(); | 451 parsed_function->AllocateVariables(); |
448 | 452 |
449 return result_; | 453 return result_; |
450 } | 454 } |
451 | 455 |
452 | 456 |
453 void ScopeBuilder::VisitThisExpression(ThisExpression* node) { | 457 void ScopeBuilder::VisitThisExpression(ThisExpression* node) { |
454 HandleSpecialLoad(&result_->this_variable, Symbols::This()); | 458 HandleSpecialLoad(&result_->this_variable, Symbols::This()); |
455 } | 459 } |
456 | 460 |
(...skipping 21 matching lines...) Expand all Loading... |
478 LookupVariable(node->variable()); | 482 LookupVariable(node->variable()); |
479 } | 483 } |
480 | 484 |
481 | 485 |
482 void ScopeBuilder::VisitVariableSet(VariableSet* node) { | 486 void ScopeBuilder::VisitVariableSet(VariableSet* node) { |
483 LookupVariable(node->variable()); | 487 LookupVariable(node->variable()); |
484 node->VisitChildren(this); | 488 node->VisitChildren(this); |
485 } | 489 } |
486 | 490 |
487 | 491 |
| 492 void ScopeBuilder::VisitConditionalExpression(ConditionalExpression* node) { |
| 493 needs_expr_temp_ = true; |
| 494 node->VisitChildren(this); |
| 495 } |
| 496 |
| 497 |
| 498 void ScopeBuilder::VisitLogicalExpression(LogicalExpression* node) { |
| 499 needs_expr_temp_ = true; |
| 500 node->VisitChildren(this); |
| 501 } |
| 502 |
| 503 |
488 void ScopeBuilder::HandleLocalFunction(TreeNode* parent, | 504 void ScopeBuilder::HandleLocalFunction(TreeNode* parent, |
489 FunctionNode* function) { | 505 FunctionNode* function) { |
490 LocalScope* saved_function_scope = current_function_scope_; | 506 LocalScope* saved_function_scope = current_function_scope_; |
491 FunctionNode* saved_function_node = current_function_node_; | 507 FunctionNode* saved_function_node = current_function_node_; |
492 ScopeBuilder::DepthState saved_depth_state = depth_; | 508 ScopeBuilder::DepthState saved_depth_state = depth_; |
493 depth_ = DepthState(depth_.function_ + 1); | 509 depth_ = DepthState(depth_.function_ + 1); |
494 EnterScope(parent, function->position()); | 510 EnterScope(parent, function->position()); |
495 current_function_scope_ = scope_; | 511 current_function_scope_ = scope_; |
496 current_function_node_ = function; | 512 current_function_node_ = function; |
497 if (depth_.function_ == 1) { | 513 if (depth_.function_ == 1) { |
(...skipping 5989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6487 thread->clear_sticky_error(); | 6503 thread->clear_sticky_error(); |
6488 return error.raw(); | 6504 return error.raw(); |
6489 } | 6505 } |
6490 } | 6506 } |
6491 | 6507 |
6492 | 6508 |
6493 } // namespace kernel | 6509 } // namespace kernel |
6494 } // namespace dart | 6510 } // namespace dart |
6495 | 6511 |
6496 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6512 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |