| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/scopes.h" | 5 #include "vm/scopes.h" |
| 6 | 6 |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/stack_frame.h" | 8 #include "vm/stack_frame.h" |
| 9 #include "vm/symbols.h" | 9 #include "vm/symbols.h" |
| 10 | 10 |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 return NULL; | 424 return NULL; |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 bool LocalScope::CaptureVariable(const String& name) { | 428 bool LocalScope::CaptureVariable(const String& name) { |
| 429 ASSERT(name.IsSymbol()); | 429 ASSERT(name.IsSymbol()); |
| 430 LocalScope* current_scope = this; | 430 LocalScope* current_scope = this; |
| 431 while (current_scope != NULL) { | 431 while (current_scope != NULL) { |
| 432 LocalVariable* var = current_scope->LocalLookupVariable(name); | 432 LocalVariable* var = current_scope->LocalLookupVariable(name); |
| 433 if (var != NULL) { | 433 if (var != NULL) { |
| 434 if (var->owner()->function_level() != function_level()) { | 434 var->set_is_captured(); |
| 435 var->set_is_captured(); | |
| 436 } | |
| 437 // Insert aliases of the variable in intermediate scopes. | 435 // Insert aliases of the variable in intermediate scopes. |
| 438 LocalScope* intermediate_scope = this; | 436 LocalScope* intermediate_scope = this; |
| 439 while (intermediate_scope != current_scope) { | 437 while (intermediate_scope != current_scope) { |
| 440 intermediate_scope->variables_.Add(var); | 438 intermediate_scope->variables_.Add(var); |
| 441 ASSERT(var->owner() != intermediate_scope); // Item is an alias. | 439 ASSERT(var->owner() != intermediate_scope); // Item is an alias. |
| 442 intermediate_scope = intermediate_scope->parent(); | 440 intermediate_scope = intermediate_scope->parent(); |
| 443 } | 441 } |
| 444 return true; | 442 return true; |
| 445 } | 443 } |
| 446 current_scope = current_scope->parent(); | 444 current_scope = current_scope->parent(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 bool found = false; | 624 bool found = false; |
| 627 for (intptr_t i = 0; i < num_variables(); i++) { | 625 for (intptr_t i = 0; i < num_variables(); i++) { |
| 628 if ((VariableAt(i)->name().raw() == Symbols::StackTraceVar().raw()) || | 626 if ((VariableAt(i)->name().raw() == Symbols::StackTraceVar().raw()) || |
| 629 (VariableAt(i)->name().raw() == Symbols::ExceptionVar().raw()) || | 627 (VariableAt(i)->name().raw() == Symbols::ExceptionVar().raw()) || |
| 630 (VariableAt(i)->name().raw() == Symbols::SavedTryContextVar().raw())) { | 628 (VariableAt(i)->name().raw() == Symbols::SavedTryContextVar().raw())) { |
| 631 // Don't capture those variables because the VM expects them to be on the | 629 // Don't capture those variables because the VM expects them to be on the |
| 632 // stack. | 630 // stack. |
| 633 continue; | 631 continue; |
| 634 } | 632 } |
| 635 found = CaptureVariable(VariableAt(i)->name()); | 633 found = CaptureVariable(VariableAt(i)->name()); |
| 636 // Also manually set the variable as captured as CaptureVariable() does not | |
| 637 // handle capturing variables on the same scope level. | |
| 638 VariableAt(i)->set_is_captured(); | |
| 639 ASSERT(found); | 634 ASSERT(found); |
| 640 } | 635 } |
| 641 if (sibling() != NULL) { sibling()->RecursivelyCaptureAllVariables(); } | 636 if (sibling() != NULL) { sibling()->RecursivelyCaptureAllVariables(); } |
| 642 if (child() != NULL) { child()->RecursivelyCaptureAllVariables(); } | 637 if (child() != NULL) { child()->RecursivelyCaptureAllVariables(); } |
| 643 } | 638 } |
| 644 | 639 |
| 645 | 640 |
| 646 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) { | 641 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) { |
| 647 static const intptr_t kNumCapturedVars = 1; | 642 static const intptr_t kNumCapturedVars = 1; |
| 648 | 643 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 684 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
| 690 } else { | 685 } else { |
| 691 // Shift negative indexes so that the lowest one is 0 (they are still | 686 // Shift negative indexes so that the lowest one is 0 (they are still |
| 692 // non-positive). | 687 // non-positive). |
| 693 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 688 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
| 694 } | 689 } |
| 695 } | 690 } |
| 696 | 691 |
| 697 | 692 |
| 698 } // namespace dart | 693 } // namespace dart |
| OLD | NEW |