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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 LocalScope* owner_scope = new LocalScope(NULL, 0, 0); | 595 LocalScope* owner_scope = new LocalScope(NULL, 0, 0); |
596 owner_scope->set_context_level(context_scope.ContextLevelAt(i)); | 596 owner_scope->set_context_level(context_scope.ContextLevelAt(i)); |
597 owner_scope->AddVariable(variable); | 597 owner_scope->AddVariable(variable); |
598 outer_scope->AddVariable(variable); // As alias. | 598 outer_scope->AddVariable(variable); // As alias. |
599 ASSERT(variable->owner() == owner_scope); | 599 ASSERT(variable->owner() == owner_scope); |
600 } | 600 } |
601 return outer_scope; | 601 return outer_scope; |
602 } | 602 } |
603 | 603 |
604 | 604 |
| 605 void LocalScope::RecursivelyCaptureAllVariables() { |
| 606 bool found = false; |
| 607 for (intptr_t i = 0; i < num_variables(); i++) { |
| 608 if ((VariableAt(i)->name().raw() == Symbols::StackTraceVar().raw()) || |
| 609 (VariableAt(i)->name().raw() == Symbols::ExceptionVar().raw()) || |
| 610 (VariableAt(i)->name().raw() == Symbols::SavedTryContextVar().raw())) { |
| 611 // Don't capture those variables because the VM expects them to be on the |
| 612 // stack. |
| 613 continue; |
| 614 } |
| 615 found = CaptureVariable(VariableAt(i)->name()); |
| 616 // Also manually set the variable as captured as CaptureVariable() does not |
| 617 // handle capturing variables on the same scope level. |
| 618 VariableAt(i)->set_is_captured(); |
| 619 ASSERT(found); |
| 620 } |
| 621 if (sibling() != NULL) { sibling()->RecursivelyCaptureAllVariables(); } |
| 622 if (child() != NULL) { child()->RecursivelyCaptureAllVariables(); } |
| 623 } |
| 624 |
| 625 |
605 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) { | 626 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) { |
606 static const intptr_t kNumCapturedVars = 1; | 627 static const intptr_t kNumCapturedVars = 1; |
607 | 628 |
608 // Create a ContextScope with space for kNumCapturedVars descriptors. | 629 // Create a ContextScope with space for kNumCapturedVars descriptors. |
609 const ContextScope& context_scope = | 630 const ContextScope& context_scope = |
610 ContextScope::Handle(ContextScope::New(kNumCapturedVars)); | 631 ContextScope::Handle(ContextScope::New(kNumCapturedVars)); |
611 | 632 |
612 // Create a descriptor for 'this' variable. | 633 // Create a descriptor for 'this' variable. |
613 context_scope.SetTokenIndexAt(0, func.token_pos()); | 634 context_scope.SetTokenIndexAt(0, func.token_pos()); |
614 context_scope.SetNameAt(0, Symbols::This()); | 635 context_scope.SetNameAt(0, Symbols::This()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 669 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
649 } else { | 670 } else { |
650 // Shift negative indexes so that the lowest one is 0 (they are still | 671 // Shift negative indexes so that the lowest one is 0 (they are still |
651 // non-positive). | 672 // non-positive). |
652 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 673 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
653 } | 674 } |
654 } | 675 } |
655 | 676 |
656 | 677 |
657 } // namespace dart | 678 } // namespace dart |
OLD | NEW |