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/ast.h" | 7 #include "vm/ast.h" |
8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/parser.h" | 10 #include "vm/parser.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 335 } |
336 } | 336 } |
337 return var; | 337 return var; |
338 } | 338 } |
339 current_scope = current_scope->parent(); | 339 current_scope = current_scope->parent(); |
340 } | 340 } |
341 return NULL; | 341 return NULL; |
342 } | 342 } |
343 | 343 |
344 | 344 |
345 void LocalScope::CaptureVariable(const String& name) { | 345 bool LocalScope::CaptureVariable(const String& name) { |
346 ASSERT(name.IsSymbol()); | 346 ASSERT(name.IsSymbol()); |
347 LocalScope* current_scope = this; | 347 LocalScope* current_scope = this; |
348 while (current_scope != NULL) { | 348 while (current_scope != NULL) { |
349 LocalVariable* var = current_scope->LocalLookupVariable(name); | 349 LocalVariable* var = current_scope->LocalLookupVariable(name); |
350 if (var != NULL) { | 350 if (var != NULL) { |
351 if (var->owner()->function_level() != function_level()) { | 351 if (var->owner()->function_level() != function_level()) { |
352 var->set_is_captured(); | 352 var->set_is_captured(); |
353 } | 353 } |
354 // Insert aliases of the variable in intermediate scopes. | 354 // Insert aliases of the variable in intermediate scopes. |
355 LocalScope* intermediate_scope = this; | 355 LocalScope* intermediate_scope = this; |
356 while (intermediate_scope != current_scope) { | 356 while (intermediate_scope != current_scope) { |
357 intermediate_scope->variables_.Add(var); | 357 intermediate_scope->variables_.Add(var); |
358 ASSERT(var->owner() != intermediate_scope); // Item is an alias. | 358 ASSERT(var->owner() != intermediate_scope); // Item is an alias. |
359 intermediate_scope = intermediate_scope->parent(); | 359 intermediate_scope = intermediate_scope->parent(); |
360 } | 360 } |
361 return; | 361 return true; |
362 } | 362 } |
363 current_scope = current_scope->parent(); | 363 current_scope = current_scope->parent(); |
364 } | 364 } |
| 365 return false; |
365 } | 366 } |
366 | 367 |
367 | 368 |
368 SourceLabel* LocalScope::LookupLabel(const String& name) { | 369 SourceLabel* LocalScope::LookupLabel(const String& name) { |
369 LocalScope* current_scope = this; | 370 LocalScope* current_scope = this; |
370 while (current_scope != NULL) { | 371 while (current_scope != NULL) { |
371 SourceLabel* label = current_scope->LocalLookupLabel(name); | 372 SourceLabel* label = current_scope->LocalLookupLabel(name); |
372 if (label != NULL) { | 373 if (label != NULL) { |
373 return label; | 374 return label; |
374 } | 375 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 600 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
600 } else { | 601 } else { |
601 // Shift negative indexes so that the lowest one is 0 (they are still | 602 // Shift negative indexes so that the lowest one is 0 (they are still |
602 // non-positive). | 603 // non-positive). |
603 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 604 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
604 } | 605 } |
605 } | 606 } |
606 | 607 |
607 | 608 |
608 } // namespace dart | 609 } // namespace dart |
OLD | NEW |