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 | |
srdjan
2014/08/26 15:54:33
two instead of three empty lines
Michael Lippautz (Google)
2014/08/26 16:45:48
Done.
| |
626 | |
605 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) { | 627 RawContextScope* LocalScope::CreateImplicitClosureScope(const Function& func) { |
606 static const intptr_t kNumCapturedVars = 1; | 628 static const intptr_t kNumCapturedVars = 1; |
607 | 629 |
608 // Create a ContextScope with space for kNumCapturedVars descriptors. | 630 // Create a ContextScope with space for kNumCapturedVars descriptors. |
609 const ContextScope& context_scope = | 631 const ContextScope& context_scope = |
610 ContextScope::Handle(ContextScope::New(kNumCapturedVars)); | 632 ContextScope::Handle(ContextScope::New(kNumCapturedVars)); |
611 | 633 |
612 // Create a descriptor for 'this' variable. | 634 // Create a descriptor for 'this' variable. |
613 context_scope.SetTokenIndexAt(0, func.token_pos()); | 635 context_scope.SetTokenIndexAt(0, func.token_pos()); |
614 context_scope.SetNameAt(0, Symbols::This()); | 636 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); | 670 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
649 } else { | 671 } else { |
650 // Shift negative indexes so that the lowest one is 0 (they are still | 672 // Shift negative indexes so that the lowest one is 0 (they are still |
651 // non-positive). | 673 // non-positive). |
652 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 674 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
653 } | 675 } |
654 } | 676 } |
655 | 677 |
656 | 678 |
657 } // namespace dart | 679 } // namespace dart |
OLD | NEW |