Chromium Code Reviews| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 if ((child_context_owner != *context_owner) && | 166 if ((child_context_owner != *context_owner) && |
| 167 (child_context_owner->loop_level() <= loop_owner->loop_level())) { | 167 (child_context_owner->loop_level() <= loop_owner->loop_level())) { |
| 168 *context_owner = child_context_owner; | 168 *context_owner = child_context_owner; |
| 169 } | 169 } |
| 170 child = child->sibling(); | 170 child = child->sibling(); |
| 171 } | 171 } |
| 172 return min_frame_index; | 172 return min_frame_index; |
| 173 } | 173 } |
| 174 | 174 |
| 175 | 175 |
| 176 static int CompareVariableRanges( | |
| 177 LocalVariable* const* a, LocalVariable* const* b) { | |
| 178 if ((*a)->token_index() < (*b)->token_index()) return -1; | |
| 179 if ((*a)->token_index() > (*b)->token_index()) return 1; | |
| 180 return 0; | |
| 181 } | |
| 182 | |
| 183 | |
| 184 RawLocalVarDescriptors* LocalScope::GetVarDescriptors() { | 176 RawLocalVarDescriptors* LocalScope::GetVarDescriptors() { |
| 185 GrowableArray<LocalVariable*> vars(8); | 177 GrowableArray<LocalVariable*> vars(8); |
| 186 CollectLocalVariables(&vars); | 178 CollectLocalVariables(&vars); |
| 187 vars.Sort(&CompareVariableRanges); | |
| 188 const LocalVarDescriptors& var_desc = | 179 const LocalVarDescriptors& var_desc = |
| 189 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); | 180 LocalVarDescriptors::Handle(LocalVarDescriptors::New(vars.length())); |
| 181 intptr_t scope_id = -1; | |
| 182 LocalScope* current_scope = NULL; | |
| 190 for (int i = 0; i < vars.length(); i++) { | 183 for (int i = 0; i < vars.length(); i++) { |
| 191 LocalVariable* var = vars[i]; | 184 LocalVariable* var = vars[i]; |
| 185 if (current_scope != var->owner()) { | |
| 186 current_scope = var->owner(); | |
| 187 scope_id += 1; | |
| 188 } | |
|
siva
2012/01/05 02:01:45
This seems kind of fragile as it assumes that all
hausner
2012/01/05 22:33:21
True. CollectLocalVariables() function below makes
| |
| 192 var_desc.SetVar(i, var->name(), var->index(), | 189 var_desc.SetVar(i, var->name(), var->index(), |
| 193 var->token_index(), var->owner()->end_token_index()); | 190 scope_id, var->token_index(), var->owner()->end_token_index()); |
| 194 } | 191 } |
| 195 return var_desc.raw(); | 192 return var_desc.raw(); |
| 196 } | 193 } |
| 197 | 194 |
| 198 | 195 |
| 199 void LocalScope::CollectLocalVariables(GrowableArray<LocalVariable*>* vars) { | 196 void LocalScope::CollectLocalVariables(GrowableArray<LocalVariable*>* vars) { |
| 200 for (int i = 0; i < this->variables_.length(); i++) { | 197 for (int i = 0; i < this->variables_.length(); i++) { |
| 201 LocalVariable* var = variables_[i]; | 198 LocalVariable* var = variables_[i]; |
| 202 if ((var->owner() == this) && Scanner::IsIdent(var->name())) { | 199 if ((var->owner() == this) && Scanner::IsIdent(var->name())) { |
| 203 vars->Add(this->variables_[i]); | 200 vars->Add(this->variables_[i]); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 456 } |
| 460 if (owner()->context_level() == other.owner()->context_level()) { | 457 if (owner()->context_level() == other.owner()->context_level()) { |
| 461 return true; | 458 return true; |
| 462 } | 459 } |
| 463 } | 460 } |
| 464 } | 461 } |
| 465 return false; | 462 return false; |
| 466 } | 463 } |
| 467 | 464 |
| 468 } // namespace dart | 465 } // namespace dart |
| OLD | NEW |