| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 if (label->owner() == NULL) { | 74 if (label->owner() == NULL) { |
| 75 // Labels must be added to their owner scope first. Subsequent calls | 75 // Labels must be added to their owner scope first. Subsequent calls |
| 76 // to 'add' treat the label as an alias. | 76 // to 'add' treat the label as an alias. |
| 77 label->set_owner(this); | 77 label->set_owner(this); |
| 78 } | 78 } |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 NameReference* LocalScope::FindReference(const String& name) const { | 83 NameReference* LocalScope::FindReference(const String& name) const { |
| 84 ASSERT(name.IsSymbol()); |
| 84 intptr_t num_references = referenced_.length(); | 85 intptr_t num_references = referenced_.length(); |
| 85 for (intptr_t i = 0; i < num_references; i++) { | 86 for (intptr_t i = 0; i < num_references; i++) { |
| 86 if (name.Equals(referenced_[i]->name())) { | 87 if (name.raw() == referenced_[i]->name().raw()) { |
| 87 return referenced_[i]; | 88 return referenced_[i]; |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 return NULL; | 91 return NULL; |
| 91 } | 92 } |
| 92 | 93 |
| 93 | 94 |
| 94 void LocalScope::AddReferencedName(intptr_t token_pos, | 95 void LocalScope::AddReferencedName(intptr_t token_pos, |
| 95 const String& name) { | 96 const String& name) { |
| 96 if (LocalLookupVariable(name) != NULL) { | 97 if (LocalLookupVariable(name) != NULL) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 ASSERT(var->owner()->context_level() >= 0); | 294 ASSERT(var->owner()->context_level() >= 0); |
| 294 desc.info.scope_id = var->owner()->context_level(); | 295 desc.info.scope_id = var->owner()->context_level(); |
| 295 } else { | 296 } else { |
| 296 desc.info.kind = RawLocalVarDescriptors::kStackVar; | 297 desc.info.kind = RawLocalVarDescriptors::kStackVar; |
| 297 desc.info.scope_id = *scope_id; | 298 desc.info.scope_id = *scope_id; |
| 298 } | 299 } |
| 299 desc.info.begin_pos = var->token_pos(); | 300 desc.info.begin_pos = var->token_pos(); |
| 300 desc.info.end_pos = var->owner()->end_token_pos(); | 301 desc.info.end_pos = var->owner()->end_token_pos(); |
| 301 desc.info.index = var->index(); | 302 desc.info.index = var->index(); |
| 302 vars->Add(desc); | 303 vars->Add(desc); |
| 303 } else if (var->name().Equals(Symbols::SavedEntryContextVar())) { | 304 } else if (var->name().raw() == Symbols::SavedEntryContextVar().raw()) { |
| 304 // This is the local variable in which the function saves the | 305 // This is the local variable in which the function saves the |
| 305 // caller's chain of closure contexts (caller's CTX register). | 306 // caller's chain of closure contexts (caller's CTX register). |
| 306 VarDesc desc; | 307 VarDesc desc; |
| 307 desc.name = &var->name(); | 308 desc.name = &var->name(); |
| 308 desc.info.kind = RawLocalVarDescriptors::kSavedEntryContext; | 309 desc.info.kind = RawLocalVarDescriptors::kSavedEntryContext; |
| 309 desc.info.scope_id = 0; | 310 desc.info.scope_id = 0; |
| 310 desc.info.begin_pos = 0; | 311 desc.info.begin_pos = 0; |
| 311 desc.info.end_pos = 0; | 312 desc.info.end_pos = 0; |
| 312 desc.info.index = var->index(); | 313 desc.info.index = var->index(); |
| 313 vars->Add(desc); | 314 vars->Add(desc); |
| 314 } else if (var->name().Equals(Symbols::SavedCurrentContextVar())) { | 315 } else if (var->name().raw() == Symbols::SavedCurrentContextVar().raw()) { |
| 315 // This is the local variable in which the function saves its | 316 // This is the local variable in which the function saves its |
| 316 // own context before calling a closure function. | 317 // own context before calling a closure function. |
| 317 VarDesc desc; | 318 VarDesc desc; |
| 318 desc.name = &var->name(); | 319 desc.name = &var->name(); |
| 319 desc.info.kind = RawLocalVarDescriptors::kSavedCurrentContext; | 320 desc.info.kind = RawLocalVarDescriptors::kSavedCurrentContext; |
| 320 desc.info.scope_id = 0; | 321 desc.info.scope_id = 0; |
| 321 desc.info.begin_pos = 0; | 322 desc.info.begin_pos = 0; |
| 322 desc.info.end_pos = 0; | 323 desc.info.end_pos = 0; |
| 323 desc.info.index = var->index(); | 324 desc.info.index = var->index(); |
| 324 vars->Add(desc); | 325 vars->Add(desc); |
| 325 } | 326 } |
| 326 } | 327 } |
| 327 } | 328 } |
| 328 LocalScope* child = this->child(); | 329 LocalScope* child = this->child(); |
| 329 while (child != NULL) { | 330 while (child != NULL) { |
| 330 child->CollectLocalVariables(vars, scope_id); | 331 child->CollectLocalVariables(vars, scope_id); |
| 331 child = child->sibling(); | 332 child = child->sibling(); |
| 332 } | 333 } |
| 333 } | 334 } |
| 334 | 335 |
| 335 | 336 |
| 336 SourceLabel* LocalScope::LocalLookupLabel(const String& name) const { | 337 SourceLabel* LocalScope::LocalLookupLabel(const String& name) const { |
| 338 ASSERT(name.IsSymbol()); |
| 337 for (intptr_t i = 0; i < labels_.length(); i++) { | 339 for (intptr_t i = 0; i < labels_.length(); i++) { |
| 338 SourceLabel* label = labels_[i]; | 340 SourceLabel* label = labels_[i]; |
| 339 if (label->name().Equals(name)) { | 341 if (label->name().raw() == name.raw()) { |
| 340 return label; | 342 return label; |
| 341 } | 343 } |
| 342 } | 344 } |
| 343 return NULL; | 345 return NULL; |
| 344 } | 346 } |
| 345 | 347 |
| 346 | 348 |
| 347 LocalVariable* LocalScope::LocalLookupVariable(const String& name) const { | 349 LocalVariable* LocalScope::LocalLookupVariable(const String& name) const { |
| 348 ASSERT(name.IsSymbol()); | 350 ASSERT(name.IsSymbol()); |
| 349 for (intptr_t i = 0; i < variables_.length(); i++) { | 351 for (intptr_t i = 0; i < variables_.length(); i++) { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 627 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
| 626 } else { | 628 } else { |
| 627 // Shift negative indexes so that the lowest one is 0 (they are still | 629 // Shift negative indexes so that the lowest one is 0 (they are still |
| 628 // non-positive). | 630 // non-positive). |
| 629 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 631 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
| 630 } | 632 } |
| 631 } | 633 } |
| 632 | 634 |
| 633 | 635 |
| 634 } // namespace dart | 636 } // namespace dart |
| OLD | NEW |