| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/ast.h" | 7 #include "vm/ast.h" |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 ASSERT(variable->is_captured()); | 84 ASSERT(variable->is_captured()); |
| 85 ASSERT(variable->owner()->loop_level() == loop_level()); | 85 ASSERT(variable->owner()->loop_level() == loop_level()); |
| 86 if (num_context_variables_ == 0) { | 86 if (num_context_variables_ == 0) { |
| 87 // This scope will allocate and chain a new context. | 87 // This scope will allocate and chain a new context. |
| 88 int new_context_level = ((*context_owner) == NULL) ? | 88 int new_context_level = ((*context_owner) == NULL) ? |
| 89 1 : (*context_owner)->context_level() + 1; | 89 1 : (*context_owner)->context_level() + 1; |
| 90 // This scope becomes the current context owner. | 90 // This scope becomes the current context owner. |
| 91 *context_owner = this; | 91 *context_owner = this; |
| 92 set_context_level(new_context_level); | 92 set_context_level(new_context_level); |
| 93 } | 93 } |
| 94 // The context level in the owner scope of a captured variable indicates at |
| 95 // code generation time how far to walk up the context chain in order to |
| 96 // access the variable from the current context level. |
| 94 if (!variable->owner()->HasContextLevel()) { | 97 if (!variable->owner()->HasContextLevel()) { |
| 95 ASSERT(variable->owner() != this); | 98 ASSERT(variable->owner() != this); |
| 96 variable->owner()->set_context_level(context_level()); | 99 variable->owner()->set_context_level(context_level()); |
| 100 } else { |
| 101 ASSERT(variable->owner()->context_level() == context_level()); |
| 97 } | 102 } |
| 98 variable->set_index(num_context_variables_++); | 103 variable->set_index(num_context_variables_++); |
| 99 } | 104 } |
| 100 | 105 |
| 101 | 106 |
| 102 int LocalScope::AllocateVariables(int first_parameter_index, | 107 int LocalScope::AllocateVariables(int first_parameter_index, |
| 103 int num_parameters, | 108 int num_parameters, |
| 104 int first_frame_index, | 109 int first_frame_index, |
| 105 LocalScope* loop_owner, | 110 LocalScope* loop_owner, |
| 106 LocalScope** context_owner) { | 111 LocalScope** context_owner) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 frame_index, | 163 frame_index, |
| 159 loop_owner, | 164 loop_owner, |
| 160 &child_context_owner); | 165 &child_context_owner); |
| 161 if (child_frame_index < min_frame_index) { | 166 if (child_frame_index < min_frame_index) { |
| 162 min_frame_index = child_frame_index; | 167 min_frame_index = child_frame_index; |
| 163 } | 168 } |
| 164 // A context allocated at a deeper loop level than the current loop level is | 169 // A context allocated at a deeper loop level than the current loop level is |
| 165 // not shared between children. | 170 // not shared between children. |
| 166 if ((child_context_owner != *context_owner) && | 171 if ((child_context_owner != *context_owner) && |
| 167 (child_context_owner->loop_level() <= loop_owner->loop_level())) { | 172 (child_context_owner->loop_level() <= loop_owner->loop_level())) { |
| 168 *context_owner = child_context_owner; | 173 *context_owner = child_context_owner; // Share context between siblings. |
| 169 } | 174 } |
| 170 child = child->sibling(); | 175 child = child->sibling(); |
| 171 } | 176 } |
| 172 return min_frame_index; | 177 return min_frame_index; |
| 173 } | 178 } |
| 174 | 179 |
| 175 | 180 |
| 176 RawLocalVarDescriptors* LocalScope::GetVarDescriptors() { | 181 RawLocalVarDescriptors* LocalScope::GetVarDescriptors() { |
| 177 GrowableArray<LocalVariable*> vars(8); | 182 GrowableArray<LocalVariable*> vars(8); |
| 178 // Variables of each scope are guaranteed to be consecutive elements | 183 // Variables of each scope are guaranteed to be consecutive elements |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 } | 468 } |
| 464 if (owner()->context_level() == other.owner()->context_level()) { | 469 if (owner()->context_level() == other.owner()->context_level()) { |
| 465 return true; | 470 return true; |
| 466 } | 471 } |
| 467 } | 472 } |
| 468 } | 473 } |
| 469 return false; | 474 return false; |
| 470 } | 475 } |
| 471 | 476 |
| 472 } // namespace dart | 477 } // namespace dart |
| OLD | NEW |