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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 } | 302 } |
303 return NULL; | 303 return NULL; |
304 } | 304 } |
305 | 305 |
306 | 306 |
307 LocalVariable* LocalScope::LocalLookupVariable(const String& name) const { | 307 LocalVariable* LocalScope::LocalLookupVariable(const String& name) const { |
308 ASSERT(name.IsSymbol()); | 308 ASSERT(name.IsSymbol()); |
309 for (intptr_t i = 0; i < variables_.length(); i++) { | 309 for (intptr_t i = 0; i < variables_.length(); i++) { |
310 LocalVariable* var = variables_[i]; | 310 LocalVariable* var = variables_[i]; |
311 ASSERT(var->name().IsSymbol()); | 311 ASSERT(var->name().IsSymbol()); |
312 if ((var->name().raw() == name.raw()) && !var->is_invisible_) { | 312 if (var->name().raw() == name.raw()) { |
313 return var; | 313 return var; |
314 } | 314 } |
315 } | 315 } |
316 return NULL; | 316 return NULL; |
317 } | 317 } |
318 | 318 |
319 | 319 |
320 LocalVariable* LocalScope::LookupVariable(const String& name, bool test_only) { | 320 LocalVariable* LocalScope::LookupVariable(const String& name, bool test_only) { |
321 LocalScope* current_scope = this; | 321 LocalScope* current_scope = this; |
322 while (current_scope != NULL) { | 322 while (current_scope != NULL) { |
323 LocalVariable* var = current_scope->LocalLookupVariable(name); | 323 LocalVariable* var = current_scope->LocalLookupVariable(name); |
324 if (var != NULL) { | 324 if ((var != NULL) && !var->is_invisible_) { |
regis
2013/08/07 18:28:26
As far as I understand, if a variable is marked in
hausner
2013/08/08 09:26:06
That may be a shortcut that works now, since we us
| |
325 if (!test_only) { | 325 if (!test_only) { |
326 if (var->owner()->function_level() != function_level()) { | 326 if (var->owner()->function_level() != function_level()) { |
327 var->set_is_captured(); | 327 var->set_is_captured(); |
328 } | 328 } |
329 // Insert aliases of the variable in intermediate scopes. | 329 // Insert aliases of the variable in intermediate scopes. |
330 LocalScope* intermediate_scope = this; | 330 LocalScope* intermediate_scope = this; |
331 while (intermediate_scope != current_scope) { | 331 while (intermediate_scope != current_scope) { |
332 intermediate_scope->variables_.Add(var); | 332 intermediate_scope->variables_.Add(var); |
333 ASSERT(var->owner() != intermediate_scope); // Item is an alias. | 333 ASSERT(var->owner() != intermediate_scope); // Item is an alias. |
334 intermediate_scope = intermediate_scope->parent(); | 334 intermediate_scope = intermediate_scope->parent(); |
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) { | |
regis
2013/08/07 18:28:26
I would still return the captured variable or a bo
hausner
2013/08/08 09:26:06
Ok, good point. will do in a follow-on CL.
| |
346 ASSERT(name.IsSymbol()); | |
347 LocalScope* current_scope = this; | |
348 while (current_scope != NULL) { | |
349 LocalVariable* var = current_scope->LocalLookupVariable(name); | |
350 if (var != NULL) { | |
351 if (var->owner()->function_level() != function_level()) { | |
352 var->set_is_captured(); | |
353 } | |
354 // Insert aliases of the variable in intermediate scopes. | |
355 LocalScope* intermediate_scope = this; | |
356 while (intermediate_scope != current_scope) { | |
357 intermediate_scope->variables_.Add(var); | |
358 ASSERT(var->owner() != intermediate_scope); // Item is an alias. | |
359 intermediate_scope = intermediate_scope->parent(); | |
360 } | |
361 return; | |
362 } | |
363 current_scope = current_scope->parent(); | |
364 } | |
365 } | |
366 | |
367 | |
345 SourceLabel* LocalScope::LookupLabel(const String& name) { | 368 SourceLabel* LocalScope::LookupLabel(const String& name) { |
346 LocalScope* current_scope = this; | 369 LocalScope* current_scope = this; |
347 while (current_scope != NULL) { | 370 while (current_scope != NULL) { |
348 SourceLabel* label = current_scope->LocalLookupLabel(name); | 371 SourceLabel* label = current_scope->LocalLookupLabel(name); |
349 if (label != NULL) { | 372 if (label != NULL) { |
350 return label; | 373 return label; |
351 } | 374 } |
352 current_scope = current_scope->parent(); | 375 current_scope = current_scope->parent(); |
353 } | 376 } |
354 return NULL; | 377 return NULL; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 return fixed_parameter_count - (index() - kParamEndSlotFromFp); | 599 return fixed_parameter_count - (index() - kParamEndSlotFromFp); |
577 } else { | 600 } else { |
578 // Shift negative indexes so that the lowest one is 0 (they are still | 601 // Shift negative indexes so that the lowest one is 0 (they are still |
579 // non-positive). | 602 // non-positive). |
580 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); | 603 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); |
581 } | 604 } |
582 } | 605 } |
583 | 606 |
584 | 607 |
585 } // namespace dart | 608 } // namespace dart |
OLD | NEW |