Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: src/scopes.cc

Issue 7399023: Pass isolate to AST ID functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: A bit less ugly Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scopes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 if (is_catch_scope()) { 297 if (is_catch_scope()) {
298 ASSERT(outer_scope() != NULL); 298 ASSERT(outer_scope() != NULL);
299 receiver_ = outer_scope()->receiver(); 299 receiver_ = outer_scope()->receiver();
300 } else { 300 } else {
301 Variable* var = 301 Variable* var =
302 variables_.Declare(this, 302 variables_.Declare(this,
303 isolate_->factory()->this_symbol(), 303 isolate_->factory()->this_symbol(),
304 Variable::VAR, 304 Variable::VAR,
305 false, 305 false,
306 Variable::THIS); 306 Variable::THIS);
307 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::PARAMETER, -1)); 307 var->set_rewrite(NewSlot(var, Slot::PARAMETER, -1));
308 receiver_ = var; 308 receiver_ = var;
309 } 309 }
310 310
311 if (is_function_scope()) { 311 if (is_function_scope()) {
312 // Declare 'arguments' variable which exists in all functions. 312 // Declare 'arguments' variable which exists in all functions.
313 // Note that it might never be accessed, in which case it won't be 313 // Note that it might never be accessed, in which case it won't be
314 // allocated during variable allocation. 314 // allocated during variable allocation.
315 variables_.Declare(this, 315 variables_.Declare(this,
316 isolate_->factory()->arguments_symbol(), 316 isolate_->factory()->arguments_symbol(),
317 Variable::VAR, 317 Variable::VAR,
(...skipping 25 matching lines...) Expand all
343 index = scope_info_->ParameterIndex(*name); 343 index = scope_info_->ParameterIndex(*name);
344 if (index < 0) { 344 if (index < 0) {
345 // Check the function name. 345 // Check the function name.
346 index = scope_info_->FunctionContextSlotIndex(*name); 346 index = scope_info_->FunctionContextSlotIndex(*name);
347 if (index < 0) return NULL; 347 if (index < 0) return NULL;
348 } 348 }
349 } 349 }
350 350
351 Variable* var = 351 Variable* var =
352 variables_.Declare(this, name, mode, true, Variable::NORMAL); 352 variables_.Declare(this, name, mode, true, Variable::NORMAL);
353 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::CONTEXT, index)); 353 var->set_rewrite(NewSlot(var, Slot::CONTEXT, index));
354 return var; 354 return var;
355 } 355 }
356 356
357 357
358 Variable* Scope::Lookup(Handle<String> name) { 358 Variable* Scope::Lookup(Handle<String> name) {
359 for (Scope* scope = this; 359 for (Scope* scope = this;
360 scope != NULL; 360 scope != NULL;
361 scope = scope->outer_scope()) { 361 scope = scope->outer_scope()) {
362 Variable* var = scope->LocalLookup(name); 362 Variable* var = scope->LocalLookup(name);
363 if (var != NULL) return var; 363 if (var != NULL) return var;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 400 }
401 401
402 402
403 VariableProxy* Scope::NewUnresolved(Handle<String> name, 403 VariableProxy* Scope::NewUnresolved(Handle<String> name,
404 bool inside_with, 404 bool inside_with,
405 int position) { 405 int position) {
406 // Note that we must not share the unresolved variables with 406 // Note that we must not share the unresolved variables with
407 // the same name because they may be removed selectively via 407 // the same name because they may be removed selectively via
408 // RemoveUnresolved(). 408 // RemoveUnresolved().
409 ASSERT(!already_resolved()); 409 ASSERT(!already_resolved());
410 VariableProxy* proxy = 410 VariableProxy* proxy = new(isolate_->zone()) VariableProxy(
411 new(isolate_->zone()) VariableProxy(name, false, inside_with, position); 411 isolate_, name, false, inside_with, position);
412 unresolved_.Add(proxy); 412 unresolved_.Add(proxy);
413 return proxy; 413 return proxy;
414 } 414 }
415 415
416 416
417 void Scope::RemoveUnresolved(VariableProxy* var) { 417 void Scope::RemoveUnresolved(VariableProxy* var) {
418 // Most likely (always?) any variable we want to remove 418 // Most likely (always?) any variable we want to remove
419 // was just added before, so we search backwards. 419 // was just added before, so we search backwards.
420 for (int i = unresolved_.length(); i-- > 0;) { 420 for (int i = unresolved_.length(); i-- > 0;) {
421 if (unresolved_[i] == var) { 421 if (unresolved_[i] == var) {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 701
702 702
703 Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) { 703 Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) {
704 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart(); 704 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart();
705 VariableMap* map = dynamics_->GetMap(mode); 705 VariableMap* map = dynamics_->GetMap(mode);
706 Variable* var = map->Lookup(name); 706 Variable* var = map->Lookup(name);
707 if (var == NULL) { 707 if (var == NULL) {
708 // Declare a new non-local. 708 // Declare a new non-local.
709 var = map->Declare(NULL, name, mode, true, Variable::NORMAL); 709 var = map->Declare(NULL, name, mode, true, Variable::NORMAL);
710 // Allocate it by giving it a dynamic lookup. 710 // Allocate it by giving it a dynamic lookup.
711 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::LOOKUP, -1)); 711 var->set_rewrite(NewSlot(var, Slot::LOOKUP, -1));
712 } 712 }
713 return var; 713 return var;
714 } 714 }
715 715
716 716
717 // Lookup a variable starting with this scope. The result is either 717 // Lookup a variable starting with this scope. The result is either
718 // the statically resolved variable belonging to an outer scope, or 718 // the statically resolved variable belonging to an outer scope, or
719 // NULL. It may be NULL because a) we couldn't find a variable, or b) 719 // NULL. It may be NULL because a) we couldn't find a variable, or b)
720 // because the variable is just a guess (and may be shadowed by 720 // because the variable is just a guess (and may be shadowed by
721 // another variable that is introduced dynamically via an 'eval' call 721 // another variable that is introduced dynamically via an 'eval' call
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 if (params_[i]->name().is_identical_to( 957 if (params_[i]->name().is_identical_to(
958 isolate_->factory()->arguments_symbol())) { 958 isolate_->factory()->arguments_symbol())) {
959 return true; 959 return true;
960 } 960 }
961 } 961 }
962 return false; 962 return false;
963 } 963 }
964 964
965 965
966 void Scope::AllocateStackSlot(Variable* var) { 966 void Scope::AllocateStackSlot(Variable* var) {
967 var->set_rewrite( 967 var->set_rewrite(NewSlot(var, Slot::LOCAL, num_stack_slots_++));
968 new(isolate_->zone()) Slot(var, Slot::LOCAL, num_stack_slots_++));
969 } 968 }
970 969
971 970
972 void Scope::AllocateHeapSlot(Variable* var) { 971 void Scope::AllocateHeapSlot(Variable* var) {
973 var->set_rewrite( 972 var->set_rewrite(NewSlot(var, Slot::CONTEXT, num_heap_slots_++));
974 new(isolate_->zone()) Slot(var, Slot::CONTEXT, num_heap_slots_++));
975 } 973 }
976 974
977 975
978 void Scope::AllocateParameterLocals() { 976 void Scope::AllocateParameterLocals() {
979 ASSERT(is_function_scope()); 977 ASSERT(is_function_scope());
980 Variable* arguments = LocalLookup(isolate_->factory()->arguments_symbol()); 978 Variable* arguments = LocalLookup(isolate_->factory()->arguments_symbol());
981 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly 979 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly
982 980
983 bool uses_nonstrict_arguments = false; 981 bool uses_nonstrict_arguments = false;
984 982
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 1015
1018 if (MustAllocate(var)) { 1016 if (MustAllocate(var)) {
1019 if (MustAllocateInContext(var)) { 1017 if (MustAllocateInContext(var)) {
1020 ASSERT(var->rewrite() == NULL || var->IsContextSlot()); 1018 ASSERT(var->rewrite() == NULL || var->IsContextSlot());
1021 if (var->rewrite() == NULL) { 1019 if (var->rewrite() == NULL) {
1022 AllocateHeapSlot(var); 1020 AllocateHeapSlot(var);
1023 } 1021 }
1024 } else { 1022 } else {
1025 ASSERT(var->rewrite() == NULL || var->IsParameter()); 1023 ASSERT(var->rewrite() == NULL || var->IsParameter());
1026 if (var->rewrite() == NULL) { 1024 if (var->rewrite() == NULL) {
1027 var->set_rewrite(new(isolate_->zone()) Slot(var, Slot::PARAMETER, i)); 1025 var->set_rewrite(NewSlot(var, Slot::PARAMETER, i));
1028 } 1026 }
1029 } 1027 }
1030 } 1028 }
1031 } 1029 }
1032 } 1030 }
1033 1031
1034 1032
1035 void Scope::AllocateNonParameterLocal(Variable* var) { 1033 void Scope::AllocateNonParameterLocal(Variable* var) {
1036 ASSERT(var->scope() == this); 1034 ASSERT(var->scope() == this);
1037 ASSERT(var->rewrite() == NULL || 1035 ASSERT(var->rewrite() == NULL ||
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 1103 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
1106 !must_have_local_context) { 1104 !must_have_local_context) {
1107 num_heap_slots_ = 0; 1105 num_heap_slots_ = 0;
1108 } 1106 }
1109 1107
1110 // Allocation done. 1108 // Allocation done.
1111 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1109 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1112 } 1110 }
1113 1111
1114 } } // namespace v8::internal 1112 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698