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

Side by Side Diff: src/scopes.cc

Issue 10534006: Remove TLS access for current Zone. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review. Created 8 years, 6 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') | src/small-pointer-list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 static bool Match(void* key1, void* key2) { 51 static bool Match(void* key1, void* key2) {
52 String* name1 = *reinterpret_cast<String**>(key1); 52 String* name1 = *reinterpret_cast<String**>(key1);
53 String* name2 = *reinterpret_cast<String**>(key2); 53 String* name2 = *reinterpret_cast<String**>(key2);
54 ASSERT(name1->IsSymbol()); 54 ASSERT(name1->IsSymbol());
55 ASSERT(name2->IsSymbol()); 55 ASSERT(name2->IsSymbol());
56 return name1 == name2; 56 return name1 == name2;
57 } 57 }
58 58
59 59
60 VariableMap::VariableMap() : ZoneHashMap(Match, 8) {} 60 VariableMap::VariableMap(Zone* zone)
61 : ZoneHashMap(Match, 8, ZoneAllocationPolicy(zone)),
62 zone_(zone) {}
61 VariableMap::~VariableMap() {} 63 VariableMap::~VariableMap() {}
62 64
63 65
64 Variable* VariableMap::Declare( 66 Variable* VariableMap::Declare(
65 Scope* scope, 67 Scope* scope,
66 Handle<String> name, 68 Handle<String> name,
67 VariableMode mode, 69 VariableMode mode,
68 bool is_valid_lhs, 70 bool is_valid_lhs,
69 Variable::Kind kind, 71 Variable::Kind kind,
70 InitializationFlag initialization_flag, 72 InitializationFlag initialization_flag,
71 Interface* interface) { 73 Interface* interface) {
72 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), true); 74 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), true,
75 ZoneAllocationPolicy(zone()));
73 if (p->value == NULL) { 76 if (p->value == NULL) {
74 // The variable has not been declared yet -> insert it. 77 // The variable has not been declared yet -> insert it.
75 ASSERT(p->key == name.location()); 78 ASSERT(p->key == name.location());
76 p->value = new Variable(scope, 79 p->value = new(zone()) Variable(scope,
77 name, 80 name,
78 mode, 81 mode,
79 is_valid_lhs, 82 is_valid_lhs,
80 kind, 83 kind,
81 initialization_flag, 84 initialization_flag,
82 interface); 85 interface);
83 } 86 }
84 return reinterpret_cast<Variable*>(p->value); 87 return reinterpret_cast<Variable*>(p->value);
85 } 88 }
86 89
87 90
88 Variable* VariableMap::Lookup(Handle<String> name) { 91 Variable* VariableMap::Lookup(Handle<String> name) {
89 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), false); 92 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), false,
93 ZoneAllocationPolicy(NULL));
90 if (p != NULL) { 94 if (p != NULL) {
91 ASSERT(*reinterpret_cast<String**>(p->key) == *name); 95 ASSERT(*reinterpret_cast<String**>(p->key) == *name);
92 ASSERT(p->value != NULL); 96 ASSERT(p->value != NULL);
93 return reinterpret_cast<Variable*>(p->value); 97 return reinterpret_cast<Variable*>(p->value);
94 } 98 }
95 return NULL; 99 return NULL;
96 } 100 }
97 101
98 102
99 // ---------------------------------------------------------------------------- 103 // ----------------------------------------------------------------------------
100 // Implementation of Scope 104 // Implementation of Scope
101 105
102 Scope::Scope(Scope* outer_scope, ScopeType type) 106 Scope::Scope(Scope* outer_scope, ScopeType type, Zone* zone)
103 : isolate_(Isolate::Current()), 107 : isolate_(Isolate::Current()),
104 inner_scopes_(4), 108 inner_scopes_(4, zone),
105 variables_(), 109 variables_(zone),
106 temps_(4), 110 temps_(4, zone),
107 params_(4), 111 params_(4, zone),
108 unresolved_(16), 112 unresolved_(16, zone),
109 decls_(4), 113 decls_(4, zone),
110 interface_(FLAG_harmony_modules && 114 interface_(FLAG_harmony_modules &&
111 (type == MODULE_SCOPE || type == GLOBAL_SCOPE) 115 (type == MODULE_SCOPE || type == GLOBAL_SCOPE)
112 ? Interface::NewModule() : NULL), 116 ? Interface::NewModule(zone) : NULL),
113 already_resolved_(false) { 117 already_resolved_(false),
118 zone_(zone) {
114 SetDefaults(type, outer_scope, Handle<ScopeInfo>::null()); 119 SetDefaults(type, outer_scope, Handle<ScopeInfo>::null());
115 // At some point we might want to provide outer scopes to 120 // At some point we might want to provide outer scopes to
116 // eval scopes (by walking the stack and reading the scope info). 121 // eval scopes (by walking the stack and reading the scope info).
117 // In that case, the ASSERT below needs to be adjusted. 122 // In that case, the ASSERT below needs to be adjusted.
118 ASSERT_EQ(type == GLOBAL_SCOPE, outer_scope == NULL); 123 ASSERT_EQ(type == GLOBAL_SCOPE, outer_scope == NULL);
119 ASSERT(!HasIllegalRedeclaration()); 124 ASSERT(!HasIllegalRedeclaration());
120 } 125 }
121 126
122 127
123 Scope::Scope(Scope* inner_scope, 128 Scope::Scope(Scope* inner_scope,
124 ScopeType type, 129 ScopeType type,
125 Handle<ScopeInfo> scope_info) 130 Handle<ScopeInfo> scope_info,
131 Zone* zone)
126 : isolate_(Isolate::Current()), 132 : isolate_(Isolate::Current()),
127 inner_scopes_(4), 133 inner_scopes_(4, zone),
128 variables_(), 134 variables_(zone),
129 temps_(4), 135 temps_(4, zone),
130 params_(4), 136 params_(4, zone),
131 unresolved_(16), 137 unresolved_(16, zone),
132 decls_(4), 138 decls_(4, zone),
133 interface_(NULL), 139 interface_(NULL),
134 already_resolved_(true) { 140 already_resolved_(true),
141 zone_(zone) {
135 SetDefaults(type, NULL, scope_info); 142 SetDefaults(type, NULL, scope_info);
136 if (!scope_info.is_null()) { 143 if (!scope_info.is_null()) {
137 num_heap_slots_ = scope_info_->ContextLength(); 144 num_heap_slots_ = scope_info_->ContextLength();
138 } 145 }
139 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. 146 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
140 num_heap_slots_ = Max(num_heap_slots_, 147 num_heap_slots_ = Max(num_heap_slots_,
141 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); 148 static_cast<int>(Context::MIN_CONTEXT_SLOTS));
142 AddInnerScope(inner_scope); 149 AddInnerScope(inner_scope);
143 } 150 }
144 151
145 152
146 Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name) 153 Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name, Zone* zone)
147 : isolate_(Isolate::Current()), 154 : isolate_(Isolate::Current()),
148 inner_scopes_(1), 155 inner_scopes_(1, zone),
149 variables_(), 156 variables_(zone),
150 temps_(0), 157 temps_(0, zone),
151 params_(0), 158 params_(0, zone),
152 unresolved_(0), 159 unresolved_(0, zone),
153 decls_(0), 160 decls_(0, zone),
154 interface_(NULL), 161 interface_(NULL),
155 already_resolved_(true) { 162 already_resolved_(true),
163 zone_(zone) {
156 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); 164 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null());
157 AddInnerScope(inner_scope); 165 AddInnerScope(inner_scope);
158 ++num_var_or_const_; 166 ++num_var_or_const_;
159 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 167 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
160 Variable* variable = variables_.Declare(this, 168 Variable* variable = variables_.Declare(this,
161 catch_variable_name, 169 catch_variable_name,
162 VAR, 170 VAR,
163 true, // Valid left-hand side. 171 true, // Valid left-hand side.
164 Variable::NORMAL, 172 Variable::NORMAL,
165 kCreatedInitialized); 173 kCreatedInitialized);
(...skipping 27 matching lines...) Expand all
193 scope_info_ = scope_info; 201 scope_info_ = scope_info;
194 start_position_ = RelocInfo::kNoPosition; 202 start_position_ = RelocInfo::kNoPosition;
195 end_position_ = RelocInfo::kNoPosition; 203 end_position_ = RelocInfo::kNoPosition;
196 if (!scope_info.is_null()) { 204 if (!scope_info.is_null()) {
197 scope_calls_eval_ = scope_info->CallsEval(); 205 scope_calls_eval_ = scope_info->CallsEval();
198 language_mode_ = scope_info->language_mode(); 206 language_mode_ = scope_info->language_mode();
199 } 207 }
200 } 208 }
201 209
202 210
203 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope) { 211 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope,
212 Zone* zone) {
204 // Reconstruct the outer scope chain from a closure's context chain. 213 // Reconstruct the outer scope chain from a closure's context chain.
205 Scope* current_scope = NULL; 214 Scope* current_scope = NULL;
206 Scope* innermost_scope = NULL; 215 Scope* innermost_scope = NULL;
207 bool contains_with = false; 216 bool contains_with = false;
208 while (!context->IsGlobalContext()) { 217 while (!context->IsGlobalContext()) {
209 if (context->IsWithContext()) { 218 if (context->IsWithContext()) {
210 Scope* with_scope = new Scope(current_scope, 219 Scope* with_scope = new(zone) Scope(current_scope,
211 WITH_SCOPE, 220 WITH_SCOPE,
212 Handle<ScopeInfo>::null()); 221 Handle<ScopeInfo>::null(),
222 zone);
213 current_scope = with_scope; 223 current_scope = with_scope;
214 // All the inner scopes are inside a with. 224 // All the inner scopes are inside a with.
215 contains_with = true; 225 contains_with = true;
216 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) { 226 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) {
217 s->scope_inside_with_ = true; 227 s->scope_inside_with_ = true;
218 } 228 }
219 } else if (context->IsFunctionContext()) { 229 } else if (context->IsFunctionContext()) {
220 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); 230 ScopeInfo* scope_info = context->closure()->shared()->scope_info();
221 current_scope = new Scope(current_scope, 231 current_scope = new(zone) Scope(current_scope,
222 FUNCTION_SCOPE, 232 FUNCTION_SCOPE,
223 Handle<ScopeInfo>(scope_info)); 233 Handle<ScopeInfo>(scope_info),
234 zone);
224 } else if (context->IsBlockContext()) { 235 } else if (context->IsBlockContext()) {
225 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); 236 ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
226 current_scope = new Scope(current_scope, 237 current_scope = new(zone) Scope(current_scope,
227 BLOCK_SCOPE, 238 BLOCK_SCOPE,
228 Handle<ScopeInfo>(scope_info)); 239 Handle<ScopeInfo>(scope_info),
240 zone);
229 } else { 241 } else {
230 ASSERT(context->IsCatchContext()); 242 ASSERT(context->IsCatchContext());
231 String* name = String::cast(context->extension()); 243 String* name = String::cast(context->extension());
232 current_scope = new Scope(current_scope, Handle<String>(name)); 244 current_scope = new(zone) Scope(
245 current_scope, Handle<String>(name), zone);
233 } 246 }
234 if (contains_with) current_scope->RecordWithStatement(); 247 if (contains_with) current_scope->RecordWithStatement();
235 if (innermost_scope == NULL) innermost_scope = current_scope; 248 if (innermost_scope == NULL) innermost_scope = current_scope;
236 249
237 // Forget about a with when we move to a context for a different function. 250 // Forget about a with when we move to a context for a different function.
238 if (context->previous()->closure() != context->closure()) { 251 if (context->previous()->closure() != context->closure()) {
239 contains_with = false; 252 contains_with = false;
240 } 253 }
241 context = context->previous(); 254 context = context->previous();
242 } 255 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 info->SetScope(scope); 311 info->SetScope(scope);
299 return true; 312 return true;
300 } 313 }
301 314
302 315
303 void Scope::Initialize() { 316 void Scope::Initialize() {
304 ASSERT(!already_resolved()); 317 ASSERT(!already_resolved());
305 318
306 // Add this scope as a new inner scope of the outer scope. 319 // Add this scope as a new inner scope of the outer scope.
307 if (outer_scope_ != NULL) { 320 if (outer_scope_ != NULL) {
308 outer_scope_->inner_scopes_.Add(this); 321 outer_scope_->inner_scopes_.Add(this, zone());
309 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); 322 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope();
310 } else { 323 } else {
311 scope_inside_with_ = is_with_scope(); 324 scope_inside_with_ = is_with_scope();
312 } 325 }
313 326
314 // Declare convenience variables. 327 // Declare convenience variables.
315 // Declare and allocate receiver (even for the global scope, and even 328 // Declare and allocate receiver (even for the global scope, and even
316 // if naccesses_ == 0). 329 // if naccesses_ == 0).
317 // NOTE: When loading parameters in the global scope, we must take 330 // NOTE: When loading parameters in the global scope, we must take
318 // care not to access them as properties of the global object, but 331 // care not to access them as properties of the global object, but
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 376 }
364 } 377 }
365 378
366 // Reparent inner scopes. 379 // Reparent inner scopes.
367 for (int i = 0; i < inner_scopes_.length(); i++) { 380 for (int i = 0; i < inner_scopes_.length(); i++) {
368 outer_scope()->AddInnerScope(inner_scopes_[i]); 381 outer_scope()->AddInnerScope(inner_scopes_[i]);
369 } 382 }
370 383
371 // Move unresolved variables 384 // Move unresolved variables
372 for (int i = 0; i < unresolved_.length(); i++) { 385 for (int i = 0; i < unresolved_.length(); i++) {
373 outer_scope()->unresolved_.Add(unresolved_[i]); 386 outer_scope()->unresolved_.Add(unresolved_[i], zone());
374 } 387 }
375 388
376 return NULL; 389 return NULL;
377 } 390 }
378 391
379 392
380 Variable* Scope::LocalLookup(Handle<String> name) { 393 Variable* Scope::LocalLookup(Handle<String> name) {
381 Variable* result = variables_.Lookup(name); 394 Variable* result = variables_.Lookup(name);
382 if (result != NULL || scope_info_.is_null()) { 395 if (result != NULL || scope_info_.is_null()) {
383 return result; 396 return result;
(...skipping 10 matching lines...) Expand all
394 if (index < 0) { 407 if (index < 0) {
395 // Check parameters. 408 // Check parameters.
396 index = scope_info_->ParameterIndex(*name); 409 index = scope_info_->ParameterIndex(*name);
397 if (index < 0) return NULL; 410 if (index < 0) return NULL;
398 411
399 mode = DYNAMIC; 412 mode = DYNAMIC;
400 location = Variable::LOOKUP; 413 location = Variable::LOOKUP;
401 init_flag = kCreatedInitialized; 414 init_flag = kCreatedInitialized;
402 } 415 }
403 416
404 Variable* var = 417 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL,
405 variables_.Declare(this, 418 init_flag);
406 name,
407 mode,
408 true,
409 Variable::NORMAL,
410 init_flag);
411 var->AllocateTo(location, index); 419 var->AllocateTo(location, index);
412 return var; 420 return var;
413 } 421 }
414 422
415 423
416 Variable* Scope::LookupFunctionVar(Handle<String> name, 424 Variable* Scope::LookupFunctionVar(Handle<String> name,
417 AstNodeFactory<AstNullVisitor>* factory) { 425 AstNodeFactory<AstNullVisitor>* factory) {
418 if (function_ != NULL && function_->proxy()->name().is_identical_to(name)) { 426 if (function_ != NULL && function_->proxy()->name().is_identical_to(name)) {
419 return function_->proxy()->var(); 427 return function_->proxy()->var();
420 } else if (!scope_info_.is_null()) { 428 } else if (!scope_info_.is_null()) {
421 // If we are backed by a scope info, try to lookup the variable there. 429 // If we are backed by a scope info, try to lookup the variable there.
422 VariableMode mode; 430 VariableMode mode;
423 int index = scope_info_->FunctionContextSlotIndex(*name, &mode); 431 int index = scope_info_->FunctionContextSlotIndex(*name, &mode);
424 if (index < 0) return NULL; 432 if (index < 0) return NULL;
425 Variable* var = new Variable( 433 Variable* var = new(zone()) Variable(
426 this, name, mode, true /* is valid LHS */, 434 this, name, mode, true /* is valid LHS */,
427 Variable::NORMAL, kCreatedInitialized); 435 Variable::NORMAL, kCreatedInitialized);
428 VariableProxy* proxy = factory->NewVariableProxy(var); 436 VariableProxy* proxy = factory->NewVariableProxy(var);
429 VariableDeclaration* declaration = 437 VariableDeclaration* declaration =
430 factory->NewVariableDeclaration(proxy, mode, this); 438 factory->NewVariableDeclaration(proxy, mode, this);
431 DeclareFunctionVar(declaration); 439 DeclareFunctionVar(declaration);
432 var->AllocateTo(Variable::CONTEXT, index); 440 var->AllocateTo(Variable::CONTEXT, index);
433 return var; 441 return var;
434 } else { 442 } else {
435 return NULL; 443 return NULL;
436 } 444 }
437 } 445 }
438 446
439 447
440 Variable* Scope::Lookup(Handle<String> name) { 448 Variable* Scope::Lookup(Handle<String> name) {
441 for (Scope* scope = this; 449 for (Scope* scope = this;
442 scope != NULL; 450 scope != NULL;
443 scope = scope->outer_scope()) { 451 scope = scope->outer_scope()) {
444 Variable* var = scope->LocalLookup(name); 452 Variable* var = scope->LocalLookup(name);
445 if (var != NULL) return var; 453 if (var != NULL) return var;
446 } 454 }
447 return NULL; 455 return NULL;
448 } 456 }
449 457
450 458
451 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { 459 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) {
452 ASSERT(!already_resolved()); 460 ASSERT(!already_resolved());
453 ASSERT(is_function_scope()); 461 ASSERT(is_function_scope());
454 Variable* var = variables_.Declare( 462 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL,
455 this, name, mode, true, Variable::NORMAL, kCreatedInitialized); 463 kCreatedInitialized);
456 params_.Add(var); 464 params_.Add(var, zone());
457 } 465 }
458 466
459 467
460 Variable* Scope::DeclareLocal(Handle<String> name, 468 Variable* Scope::DeclareLocal(Handle<String> name,
461 VariableMode mode, 469 VariableMode mode,
462 InitializationFlag init_flag, 470 InitializationFlag init_flag,
463 Interface* interface) { 471 Interface* interface) {
464 ASSERT(!already_resolved()); 472 ASSERT(!already_resolved());
465 // This function handles VAR and CONST modes. DYNAMIC variables are 473 // This function handles VAR and CONST modes. DYNAMIC variables are
466 // introduces during variable allocation, INTERNAL variables are allocated 474 // introduces during variable allocation, INTERNAL variables are allocated
(...skipping 26 matching lines...) Expand all
493 if (unresolved_[i] == var) { 501 if (unresolved_[i] == var) {
494 unresolved_.Remove(i); 502 unresolved_.Remove(i);
495 return; 503 return;
496 } 504 }
497 } 505 }
498 } 506 }
499 507
500 508
501 Variable* Scope::NewTemporary(Handle<String> name) { 509 Variable* Scope::NewTemporary(Handle<String> name) {
502 ASSERT(!already_resolved()); 510 ASSERT(!already_resolved());
503 Variable* var = new Variable(this, 511 Variable* var = new(zone()) Variable(this,
504 name, 512 name,
505 TEMPORARY, 513 TEMPORARY,
506 true, 514 true,
507 Variable::NORMAL, 515 Variable::NORMAL,
508 kCreatedInitialized); 516 kCreatedInitialized);
509 temps_.Add(var); 517 temps_.Add(var, zone());
510 return var; 518 return var;
511 } 519 }
512 520
513 521
514 void Scope::AddDeclaration(Declaration* declaration) { 522 void Scope::AddDeclaration(Declaration* declaration) {
515 decls_.Add(declaration); 523 decls_.Add(declaration, zone());
516 } 524 }
517 525
518 526
519 void Scope::SetIllegalRedeclaration(Expression* expression) { 527 void Scope::SetIllegalRedeclaration(Expression* expression) {
520 // Record only the first illegal redeclaration. 528 // Record only the first illegal redeclaration.
521 if (!HasIllegalRedeclaration()) { 529 if (!HasIllegalRedeclaration()) {
522 illegal_redecl_ = expression; 530 illegal_redecl_ = expression;
523 } 531 }
524 ASSERT(HasIllegalRedeclaration()); 532 ASSERT(HasIllegalRedeclaration());
525 } 533 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, 589 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals,
582 ZoneList<Variable*>* context_locals) { 590 ZoneList<Variable*>* context_locals) {
583 ASSERT(stack_locals != NULL); 591 ASSERT(stack_locals != NULL);
584 ASSERT(context_locals != NULL); 592 ASSERT(context_locals != NULL);
585 593
586 // Collect temporaries which are always allocated on the stack. 594 // Collect temporaries which are always allocated on the stack.
587 for (int i = 0; i < temps_.length(); i++) { 595 for (int i = 0; i < temps_.length(); i++) {
588 Variable* var = temps_[i]; 596 Variable* var = temps_[i];
589 if (var->is_used()) { 597 if (var->is_used()) {
590 ASSERT(var->IsStackLocal()); 598 ASSERT(var->IsStackLocal());
591 stack_locals->Add(var); 599 stack_locals->Add(var, zone());
592 } 600 }
593 } 601 }
594 602
595 // Collect declared local variables. 603 // Collect declared local variables.
596 for (VariableMap::Entry* p = variables_.Start(); 604 for (VariableMap::Entry* p = variables_.Start();
597 p != NULL; 605 p != NULL;
598 p = variables_.Next(p)) { 606 p = variables_.Next(p)) {
599 Variable* var = reinterpret_cast<Variable*>(p->value); 607 Variable* var = reinterpret_cast<Variable*>(p->value);
600 if (var->is_used()) { 608 if (var->is_used()) {
601 if (var->IsStackLocal()) { 609 if (var->IsStackLocal()) {
602 stack_locals->Add(var); 610 stack_locals->Add(var, zone());
603 } else if (var->IsContextSlot()) { 611 } else if (var->IsContextSlot()) {
604 context_locals->Add(var); 612 context_locals->Add(var, zone());
605 } 613 }
606 } 614 }
607 } 615 }
608 } 616 }
609 617
610 618
611 bool Scope::AllocateVariables(CompilationInfo* info, 619 bool Scope::AllocateVariables(CompilationInfo* info,
612 AstNodeFactory<AstNullVisitor>* factory) { 620 AstNodeFactory<AstNullVisitor>* factory) {
613 // 1) Propagate scope information. 621 // 1) Propagate scope information.
614 bool outer_scope_calls_non_strict_eval = false; 622 bool outer_scope_calls_non_strict_eval = false;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 Scope* scope = this; 700 Scope* scope = this;
693 while (!scope->is_declaration_scope()) { 701 while (!scope->is_declaration_scope()) {
694 scope = scope->outer_scope(); 702 scope = scope->outer_scope();
695 } 703 }
696 return scope; 704 return scope;
697 } 705 }
698 706
699 707
700 Handle<ScopeInfo> Scope::GetScopeInfo() { 708 Handle<ScopeInfo> Scope::GetScopeInfo() {
701 if (scope_info_.is_null()) { 709 if (scope_info_.is_null()) {
702 scope_info_ = ScopeInfo::Create(this); 710 scope_info_ = ScopeInfo::Create(this, zone());
703 } 711 }
704 return scope_info_; 712 return scope_info_;
705 } 713 }
706 714
707 715
708 void Scope::GetNestedScopeChain( 716 void Scope::GetNestedScopeChain(
709 List<Handle<ScopeInfo> >* chain, 717 List<Handle<ScopeInfo> >* chain,
710 int position) { 718 int position) {
711 if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo())); 719 if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo()));
712 720
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 inner_scopes_[i]->Print(n1); 886 inner_scopes_[i]->Print(n1);
879 } 887 }
880 } 888 }
881 889
882 Indent(n0, "}\n"); 890 Indent(n0, "}\n");
883 } 891 }
884 #endif // DEBUG 892 #endif // DEBUG
885 893
886 894
887 Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) { 895 Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) {
888 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart(); 896 if (dynamics_ == NULL) dynamics_ = new(zone()) DynamicScopePart(zone());
889 VariableMap* map = dynamics_->GetMap(mode); 897 VariableMap* map = dynamics_->GetMap(mode);
890 Variable* var = map->Lookup(name); 898 Variable* var = map->Lookup(name);
891 if (var == NULL) { 899 if (var == NULL) {
892 // Declare a new non-local. 900 // Declare a new non-local.
893 InitializationFlag init_flag = (mode == VAR) 901 InitializationFlag init_flag = (mode == VAR)
894 ? kCreatedInitialized : kNeedsInitialization; 902 ? kCreatedInitialized : kNeedsInitialization;
895 var = map->Declare(NULL, 903 var = map->Declare(NULL,
896 name, 904 name,
897 mode, 905 mode,
898 true, 906 true,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 1020
1013 ASSERT(var != NULL); 1021 ASSERT(var != NULL);
1014 proxy->BindTo(var); 1022 proxy->BindTo(var);
1015 1023
1016 if (FLAG_harmony_modules) { 1024 if (FLAG_harmony_modules) {
1017 bool ok; 1025 bool ok;
1018 #ifdef DEBUG 1026 #ifdef DEBUG
1019 if (FLAG_print_interface_details) 1027 if (FLAG_print_interface_details)
1020 PrintF("# Resolve %s:\n", var->name()->ToAsciiArray()); 1028 PrintF("# Resolve %s:\n", var->name()->ToAsciiArray());
1021 #endif 1029 #endif
1022 proxy->interface()->Unify(var->interface(), &ok); 1030 proxy->interface()->Unify(var->interface(), zone(), &ok);
1023 if (!ok) { 1031 if (!ok) {
1024 #ifdef DEBUG 1032 #ifdef DEBUG
1025 if (FLAG_print_interfaces) { 1033 if (FLAG_print_interfaces) {
1026 PrintF("SCOPES TYPE ERROR\n"); 1034 PrintF("SCOPES TYPE ERROR\n");
1027 PrintF("proxy: "); 1035 PrintF("proxy: ");
1028 proxy->interface()->Print(); 1036 proxy->interface()->Print();
1029 PrintF("var: "); 1037 PrintF("var: ");
1030 var->interface()->Print(); 1038 var->interface()->Print();
1031 } 1039 }
1032 #endif 1040 #endif
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 } 1292 }
1285 1293
1286 1294
1287 int Scope::ContextLocalCount() const { 1295 int Scope::ContextLocalCount() const {
1288 if (num_heap_slots() == 0) return 0; 1296 if (num_heap_slots() == 0) return 0;
1289 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1297 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1290 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1298 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1291 } 1299 }
1292 1300
1293 } } // namespace v8::internal 1301 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/small-pointer-list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698