OLD | NEW |
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...) Loading... |
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)) {} |
61 VariableMap::~VariableMap() {} | 62 VariableMap::~VariableMap() {} |
62 | 63 |
63 | 64 |
64 Variable* VariableMap::Declare( | 65 Variable* VariableMap::Declare( |
65 Scope* scope, | 66 Scope* scope, |
66 Handle<String> name, | 67 Handle<String> name, |
67 VariableMode mode, | 68 VariableMode mode, |
68 bool is_valid_lhs, | 69 bool is_valid_lhs, |
69 Variable::Kind kind, | 70 Variable::Kind kind, |
70 InitializationFlag initialization_flag, | 71 InitializationFlag initialization_flag, |
| 72 Zone* zone, |
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, |
| 174 zone); |
166 AllocateHeapSlot(variable); | 175 AllocateHeapSlot(variable); |
167 } | 176 } |
168 | 177 |
169 | 178 |
170 void Scope::SetDefaults(ScopeType type, | 179 void Scope::SetDefaults(ScopeType type, |
171 Scope* outer_scope, | 180 Scope* outer_scope, |
172 Handle<ScopeInfo> scope_info) { | 181 Handle<ScopeInfo> scope_info) { |
173 outer_scope_ = outer_scope; | 182 outer_scope_ = outer_scope; |
174 type_ = type; | 183 type_ = type; |
175 scope_name_ = isolate_->factory()->empty_symbol(); | 184 scope_name_ = isolate_->factory()->empty_symbol(); |
(...skipping 17 matching lines...) Loading... |
193 scope_info_ = scope_info; | 202 scope_info_ = scope_info; |
194 start_position_ = RelocInfo::kNoPosition; | 203 start_position_ = RelocInfo::kNoPosition; |
195 end_position_ = RelocInfo::kNoPosition; | 204 end_position_ = RelocInfo::kNoPosition; |
196 if (!scope_info.is_null()) { | 205 if (!scope_info.is_null()) { |
197 scope_calls_eval_ = scope_info->CallsEval(); | 206 scope_calls_eval_ = scope_info->CallsEval(); |
198 language_mode_ = scope_info->language_mode(); | 207 language_mode_ = scope_info->language_mode(); |
199 } | 208 } |
200 } | 209 } |
201 | 210 |
202 | 211 |
203 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope) { | 212 Scope* Scope::DeserializeScopeChain(Context* context, Scope* global_scope, |
| 213 Zone* zone) { |
204 // Reconstruct the outer scope chain from a closure's context chain. | 214 // Reconstruct the outer scope chain from a closure's context chain. |
205 Scope* current_scope = NULL; | 215 Scope* current_scope = NULL; |
206 Scope* innermost_scope = NULL; | 216 Scope* innermost_scope = NULL; |
207 bool contains_with = false; | 217 bool contains_with = false; |
208 while (!context->IsGlobalContext()) { | 218 while (!context->IsGlobalContext()) { |
209 if (context->IsWithContext()) { | 219 if (context->IsWithContext()) { |
210 Scope* with_scope = new Scope(current_scope, | 220 Scope* with_scope = new(zone) Scope(current_scope, |
211 WITH_SCOPE, | 221 WITH_SCOPE, |
212 Handle<ScopeInfo>::null()); | 222 Handle<ScopeInfo>::null(), |
| 223 zone); |
213 current_scope = with_scope; | 224 current_scope = with_scope; |
214 // All the inner scopes are inside a with. | 225 // All the inner scopes are inside a with. |
215 contains_with = true; | 226 contains_with = true; |
216 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) { | 227 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) { |
217 s->scope_inside_with_ = true; | 228 s->scope_inside_with_ = true; |
218 } | 229 } |
219 } else if (context->IsFunctionContext()) { | 230 } else if (context->IsFunctionContext()) { |
220 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); | 231 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); |
221 current_scope = new Scope(current_scope, | 232 current_scope = new(zone) Scope(current_scope, |
222 FUNCTION_SCOPE, | 233 FUNCTION_SCOPE, |
223 Handle<ScopeInfo>(scope_info)); | 234 Handle<ScopeInfo>(scope_info), |
| 235 zone); |
224 } else if (context->IsBlockContext()) { | 236 } else if (context->IsBlockContext()) { |
225 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); | 237 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); |
226 current_scope = new Scope(current_scope, | 238 current_scope = new(zone) Scope(current_scope, |
227 BLOCK_SCOPE, | 239 BLOCK_SCOPE, |
228 Handle<ScopeInfo>(scope_info)); | 240 Handle<ScopeInfo>(scope_info), |
| 241 zone); |
229 } else { | 242 } else { |
230 ASSERT(context->IsCatchContext()); | 243 ASSERT(context->IsCatchContext()); |
231 String* name = String::cast(context->extension()); | 244 String* name = String::cast(context->extension()); |
232 current_scope = new Scope(current_scope, Handle<String>(name)); | 245 current_scope = new(zone) Scope( |
| 246 current_scope, Handle<String>(name), zone); |
233 } | 247 } |
234 if (contains_with) current_scope->RecordWithStatement(); | 248 if (contains_with) current_scope->RecordWithStatement(); |
235 if (innermost_scope == NULL) innermost_scope = current_scope; | 249 if (innermost_scope == NULL) innermost_scope = current_scope; |
236 | 250 |
237 // Forget about a with when we move to a context for a different function. | 251 // Forget about a with when we move to a context for a different function. |
238 if (context->previous()->closure() != context->closure()) { | 252 if (context->previous()->closure() != context->closure()) { |
239 contains_with = false; | 253 contains_with = false; |
240 } | 254 } |
241 context = context->previous(); | 255 context = context->previous(); |
242 } | 256 } |
(...skipping 55 matching lines...) Loading... |
298 info->SetScope(scope); | 312 info->SetScope(scope); |
299 return true; | 313 return true; |
300 } | 314 } |
301 | 315 |
302 | 316 |
303 void Scope::Initialize() { | 317 void Scope::Initialize() { |
304 ASSERT(!already_resolved()); | 318 ASSERT(!already_resolved()); |
305 | 319 |
306 // Add this scope as a new inner scope of the outer scope. | 320 // Add this scope as a new inner scope of the outer scope. |
307 if (outer_scope_ != NULL) { | 321 if (outer_scope_ != NULL) { |
308 outer_scope_->inner_scopes_.Add(this); | 322 outer_scope_->inner_scopes_.Add(this, zone()); |
309 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); | 323 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); |
310 } else { | 324 } else { |
311 scope_inside_with_ = is_with_scope(); | 325 scope_inside_with_ = is_with_scope(); |
312 } | 326 } |
313 | 327 |
314 // Declare convenience variables. | 328 // Declare convenience variables. |
315 // Declare and allocate receiver (even for the global scope, and even | 329 // Declare and allocate receiver (even for the global scope, and even |
316 // if naccesses_ == 0). | 330 // if naccesses_ == 0). |
317 // NOTE: When loading parameters in the global scope, we must take | 331 // NOTE: When loading parameters in the global scope, we must take |
318 // care not to access them as properties of the global object, but | 332 // care not to access them as properties of the global object, but |
319 // instead load them directly from the stack. Currently, the only | 333 // instead load them directly from the stack. Currently, the only |
320 // such parameter is 'this' which is passed on the stack when | 334 // such parameter is 'this' which is passed on the stack when |
321 // invoking scripts | 335 // invoking scripts |
322 if (is_declaration_scope()) { | 336 if (is_declaration_scope()) { |
323 Variable* var = | 337 Variable* var = |
324 variables_.Declare(this, | 338 variables_.Declare(this, |
325 isolate_->factory()->this_symbol(), | 339 isolate_->factory()->this_symbol(), |
326 VAR, | 340 VAR, |
327 false, | 341 false, |
328 Variable::THIS, | 342 Variable::THIS, |
329 kCreatedInitialized); | 343 kCreatedInitialized, |
| 344 zone()); |
330 var->AllocateTo(Variable::PARAMETER, -1); | 345 var->AllocateTo(Variable::PARAMETER, -1); |
331 receiver_ = var; | 346 receiver_ = var; |
332 } else { | 347 } else { |
333 ASSERT(outer_scope() != NULL); | 348 ASSERT(outer_scope() != NULL); |
334 receiver_ = outer_scope()->receiver(); | 349 receiver_ = outer_scope()->receiver(); |
335 } | 350 } |
336 | 351 |
337 if (is_function_scope()) { | 352 if (is_function_scope()) { |
338 // Declare 'arguments' variable which exists in all functions. | 353 // Declare 'arguments' variable which exists in all functions. |
339 // Note that it might never be accessed, in which case it won't be | 354 // Note that it might never be accessed, in which case it won't be |
340 // allocated during variable allocation. | 355 // allocated during variable allocation. |
341 variables_.Declare(this, | 356 variables_.Declare(this, |
342 isolate_->factory()->arguments_symbol(), | 357 isolate_->factory()->arguments_symbol(), |
343 VAR, | 358 VAR, |
344 true, | 359 true, |
345 Variable::ARGUMENTS, | 360 Variable::ARGUMENTS, |
346 kCreatedInitialized); | 361 kCreatedInitialized, |
| 362 zone()); |
347 } | 363 } |
348 } | 364 } |
349 | 365 |
350 | 366 |
351 Scope* Scope::FinalizeBlockScope() { | 367 Scope* Scope::FinalizeBlockScope() { |
352 ASSERT(is_block_scope()); | 368 ASSERT(is_block_scope()); |
353 ASSERT(temps_.is_empty()); | 369 ASSERT(temps_.is_empty()); |
354 ASSERT(params_.is_empty()); | 370 ASSERT(params_.is_empty()); |
355 | 371 |
356 if (num_var_or_const() > 0) return this; | 372 if (num_var_or_const() > 0) return this; |
357 | 373 |
358 // Remove this scope from outer scope. | 374 // Remove this scope from outer scope. |
359 for (int i = 0; i < outer_scope_->inner_scopes_.length(); i++) { | 375 for (int i = 0; i < outer_scope_->inner_scopes_.length(); i++) { |
360 if (outer_scope_->inner_scopes_[i] == this) { | 376 if (outer_scope_->inner_scopes_[i] == this) { |
361 outer_scope_->inner_scopes_.Remove(i); | 377 outer_scope_->inner_scopes_.Remove(i); |
362 break; | 378 break; |
363 } | 379 } |
364 } | 380 } |
365 | 381 |
366 // Reparent inner scopes. | 382 // Reparent inner scopes. |
367 for (int i = 0; i < inner_scopes_.length(); i++) { | 383 for (int i = 0; i < inner_scopes_.length(); i++) { |
368 outer_scope()->AddInnerScope(inner_scopes_[i]); | 384 outer_scope()->AddInnerScope(inner_scopes_[i]); |
369 } | 385 } |
370 | 386 |
371 // Move unresolved variables | 387 // Move unresolved variables |
372 for (int i = 0; i < unresolved_.length(); i++) { | 388 for (int i = 0; i < unresolved_.length(); i++) { |
373 outer_scope()->unresolved_.Add(unresolved_[i]); | 389 outer_scope()->unresolved_.Add(unresolved_[i], zone()); |
374 } | 390 } |
375 | 391 |
376 return NULL; | 392 return NULL; |
377 } | 393 } |
378 | 394 |
379 | 395 |
380 Variable* Scope::LocalLookup(Handle<String> name) { | 396 Variable* Scope::LocalLookup(Handle<String> name) { |
381 Variable* result = variables_.Lookup(name); | 397 Variable* result = variables_.Lookup(name); |
382 if (result != NULL || scope_info_.is_null()) { | 398 if (result != NULL || scope_info_.is_null()) { |
383 return result; | 399 return result; |
(...skipping 16 matching lines...) Loading... |
400 location = Variable::LOOKUP; | 416 location = Variable::LOOKUP; |
401 init_flag = kCreatedInitialized; | 417 init_flag = kCreatedInitialized; |
402 } | 418 } |
403 | 419 |
404 Variable* var = | 420 Variable* var = |
405 variables_.Declare(this, | 421 variables_.Declare(this, |
406 name, | 422 name, |
407 mode, | 423 mode, |
408 true, | 424 true, |
409 Variable::NORMAL, | 425 Variable::NORMAL, |
410 init_flag); | 426 init_flag, |
| 427 zone()); |
411 var->AllocateTo(location, index); | 428 var->AllocateTo(location, index); |
412 return var; | 429 return var; |
413 } | 430 } |
414 | 431 |
415 | 432 |
416 Variable* Scope::LookupFunctionVar(Handle<String> name, | 433 Variable* Scope::LookupFunctionVar(Handle<String> name, |
417 AstNodeFactory<AstNullVisitor>* factory) { | 434 AstNodeFactory<AstNullVisitor>* factory) { |
418 if (function_ != NULL && function_->proxy()->name().is_identical_to(name)) { | 435 if (function_ != NULL && function_->proxy()->name().is_identical_to(name)) { |
419 return function_->proxy()->var(); | 436 return function_->proxy()->var(); |
420 } else if (!scope_info_.is_null()) { | 437 } else if (!scope_info_.is_null()) { |
421 // If we are backed by a scope info, try to lookup the variable there. | 438 // If we are backed by a scope info, try to lookup the variable there. |
422 VariableMode mode; | 439 VariableMode mode; |
423 int index = scope_info_->FunctionContextSlotIndex(*name, &mode); | 440 int index = scope_info_->FunctionContextSlotIndex(*name, &mode); |
424 if (index < 0) return NULL; | 441 if (index < 0) return NULL; |
425 Variable* var = new Variable( | 442 Variable* var = new(zone()) Variable( |
426 this, name, mode, true /* is valid LHS */, | 443 this, name, mode, true /* is valid LHS */, |
427 Variable::NORMAL, kCreatedInitialized); | 444 Variable::NORMAL, kCreatedInitialized); |
428 VariableProxy* proxy = factory->NewVariableProxy(var); | 445 VariableProxy* proxy = factory->NewVariableProxy(var); |
429 VariableDeclaration* declaration = | 446 VariableDeclaration* declaration = |
430 factory->NewVariableDeclaration(proxy, mode, this); | 447 factory->NewVariableDeclaration(proxy, mode, this); |
431 DeclareFunctionVar(declaration); | 448 DeclareFunctionVar(declaration); |
432 var->AllocateTo(Variable::CONTEXT, index); | 449 var->AllocateTo(Variable::CONTEXT, index); |
433 return var; | 450 return var; |
434 } else { | 451 } else { |
435 return NULL; | 452 return NULL; |
436 } | 453 } |
437 } | 454 } |
438 | 455 |
439 | 456 |
440 Variable* Scope::Lookup(Handle<String> name) { | 457 Variable* Scope::Lookup(Handle<String> name) { |
441 for (Scope* scope = this; | 458 for (Scope* scope = this; |
442 scope != NULL; | 459 scope != NULL; |
443 scope = scope->outer_scope()) { | 460 scope = scope->outer_scope()) { |
444 Variable* var = scope->LocalLookup(name); | 461 Variable* var = scope->LocalLookup(name); |
445 if (var != NULL) return var; | 462 if (var != NULL) return var; |
446 } | 463 } |
447 return NULL; | 464 return NULL; |
448 } | 465 } |
449 | 466 |
450 | 467 |
451 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { | 468 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { |
452 ASSERT(!already_resolved()); | 469 ASSERT(!already_resolved()); |
453 ASSERT(is_function_scope()); | 470 ASSERT(is_function_scope()); |
454 Variable* var = variables_.Declare( | 471 Variable* var = variables_.Declare( |
455 this, name, mode, true, Variable::NORMAL, kCreatedInitialized); | 472 this, name, mode, true, Variable::NORMAL, kCreatedInitialized, zone()); |
456 params_.Add(var); | 473 params_.Add(var, zone()); |
457 } | 474 } |
458 | 475 |
459 | 476 |
460 Variable* Scope::DeclareLocal(Handle<String> name, | 477 Variable* Scope::DeclareLocal(Handle<String> name, |
461 VariableMode mode, | 478 VariableMode mode, |
462 InitializationFlag init_flag, | 479 InitializationFlag init_flag, |
463 Interface* interface) { | 480 Interface* interface) { |
464 ASSERT(!already_resolved()); | 481 ASSERT(!already_resolved()); |
465 // This function handles VAR and CONST modes. DYNAMIC variables are | 482 // This function handles VAR and CONST modes. DYNAMIC variables are |
466 // introduces during variable allocation, INTERNAL variables are allocated | 483 // introduces during variable allocation, INTERNAL variables are allocated |
467 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). | 484 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). |
468 ASSERT(mode == VAR || | 485 ASSERT(mode == VAR || |
469 mode == CONST || | 486 mode == CONST || |
470 mode == CONST_HARMONY || | 487 mode == CONST_HARMONY || |
471 mode == LET); | 488 mode == LET); |
472 ++num_var_or_const_; | 489 ++num_var_or_const_; |
473 return variables_.Declare( | 490 return variables_.Declare( |
474 this, name, mode, true, Variable::NORMAL, init_flag, interface); | 491 this, name, mode, true, Variable::NORMAL, init_flag, zone(), interface); |
475 } | 492 } |
476 | 493 |
477 | 494 |
478 Variable* Scope::DeclareGlobal(Handle<String> name) { | 495 Variable* Scope::DeclareGlobal(Handle<String> name) { |
479 ASSERT(is_global_scope()); | 496 ASSERT(is_global_scope()); |
480 return variables_.Declare(this, | 497 return variables_.Declare(this, |
481 name, | 498 name, |
482 DYNAMIC_GLOBAL, | 499 DYNAMIC_GLOBAL, |
483 true, | 500 true, |
484 Variable::NORMAL, | 501 Variable::NORMAL, |
485 kCreatedInitialized); | 502 kCreatedInitialized, |
| 503 zone()); |
486 } | 504 } |
487 | 505 |
488 | 506 |
489 void Scope::RemoveUnresolved(VariableProxy* var) { | 507 void Scope::RemoveUnresolved(VariableProxy* var) { |
490 // Most likely (always?) any variable we want to remove | 508 // Most likely (always?) any variable we want to remove |
491 // was just added before, so we search backwards. | 509 // was just added before, so we search backwards. |
492 for (int i = unresolved_.length(); i-- > 0;) { | 510 for (int i = unresolved_.length(); i-- > 0;) { |
493 if (unresolved_[i] == var) { | 511 if (unresolved_[i] == var) { |
494 unresolved_.Remove(i); | 512 unresolved_.Remove(i); |
495 return; | 513 return; |
496 } | 514 } |
497 } | 515 } |
498 } | 516 } |
499 | 517 |
500 | 518 |
501 Variable* Scope::NewTemporary(Handle<String> name) { | 519 Variable* Scope::NewTemporary(Handle<String> name) { |
502 ASSERT(!already_resolved()); | 520 ASSERT(!already_resolved()); |
503 Variable* var = new Variable(this, | 521 Variable* var = new(zone()) Variable(this, |
504 name, | 522 name, |
505 TEMPORARY, | 523 TEMPORARY, |
506 true, | 524 true, |
507 Variable::NORMAL, | 525 Variable::NORMAL, |
508 kCreatedInitialized); | 526 kCreatedInitialized); |
509 temps_.Add(var); | 527 temps_.Add(var, zone()); |
510 return var; | 528 return var; |
511 } | 529 } |
512 | 530 |
513 | 531 |
514 void Scope::AddDeclaration(Declaration* declaration) { | 532 void Scope::AddDeclaration(Declaration* declaration) { |
515 decls_.Add(declaration); | 533 decls_.Add(declaration, zone()); |
516 } | 534 } |
517 | 535 |
518 | 536 |
519 void Scope::SetIllegalRedeclaration(Expression* expression) { | 537 void Scope::SetIllegalRedeclaration(Expression* expression) { |
520 // Record only the first illegal redeclaration. | 538 // Record only the first illegal redeclaration. |
521 if (!HasIllegalRedeclaration()) { | 539 if (!HasIllegalRedeclaration()) { |
522 illegal_redecl_ = expression; | 540 illegal_redecl_ = expression; |
523 } | 541 } |
524 ASSERT(HasIllegalRedeclaration()); | 542 ASSERT(HasIllegalRedeclaration()); |
525 } | 543 } |
(...skipping 55 matching lines...) Loading... |
581 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, | 599 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, |
582 ZoneList<Variable*>* context_locals) { | 600 ZoneList<Variable*>* context_locals) { |
583 ASSERT(stack_locals != NULL); | 601 ASSERT(stack_locals != NULL); |
584 ASSERT(context_locals != NULL); | 602 ASSERT(context_locals != NULL); |
585 | 603 |
586 // Collect temporaries which are always allocated on the stack. | 604 // Collect temporaries which are always allocated on the stack. |
587 for (int i = 0; i < temps_.length(); i++) { | 605 for (int i = 0; i < temps_.length(); i++) { |
588 Variable* var = temps_[i]; | 606 Variable* var = temps_[i]; |
589 if (var->is_used()) { | 607 if (var->is_used()) { |
590 ASSERT(var->IsStackLocal()); | 608 ASSERT(var->IsStackLocal()); |
591 stack_locals->Add(var); | 609 stack_locals->Add(var, zone()); |
592 } | 610 } |
593 } | 611 } |
594 | 612 |
595 // Collect declared local variables. | 613 // Collect declared local variables. |
596 for (VariableMap::Entry* p = variables_.Start(); | 614 for (VariableMap::Entry* p = variables_.Start(); |
597 p != NULL; | 615 p != NULL; |
598 p = variables_.Next(p)) { | 616 p = variables_.Next(p)) { |
599 Variable* var = reinterpret_cast<Variable*>(p->value); | 617 Variable* var = reinterpret_cast<Variable*>(p->value); |
600 if (var->is_used()) { | 618 if (var->is_used()) { |
601 if (var->IsStackLocal()) { | 619 if (var->IsStackLocal()) { |
602 stack_locals->Add(var); | 620 stack_locals->Add(var, zone()); |
603 } else if (var->IsContextSlot()) { | 621 } else if (var->IsContextSlot()) { |
604 context_locals->Add(var); | 622 context_locals->Add(var, zone()); |
605 } | 623 } |
606 } | 624 } |
607 } | 625 } |
608 } | 626 } |
609 | 627 |
610 | 628 |
611 bool Scope::AllocateVariables(CompilationInfo* info, | 629 bool Scope::AllocateVariables(CompilationInfo* info, |
612 AstNodeFactory<AstNullVisitor>* factory) { | 630 AstNodeFactory<AstNullVisitor>* factory) { |
613 // 1) Propagate scope information. | 631 // 1) Propagate scope information. |
614 bool outer_scope_calls_non_strict_eval = false; | 632 bool outer_scope_calls_non_strict_eval = false; |
(...skipping 77 matching lines...) Loading... |
692 Scope* scope = this; | 710 Scope* scope = this; |
693 while (!scope->is_declaration_scope()) { | 711 while (!scope->is_declaration_scope()) { |
694 scope = scope->outer_scope(); | 712 scope = scope->outer_scope(); |
695 } | 713 } |
696 return scope; | 714 return scope; |
697 } | 715 } |
698 | 716 |
699 | 717 |
700 Handle<ScopeInfo> Scope::GetScopeInfo() { | 718 Handle<ScopeInfo> Scope::GetScopeInfo() { |
701 if (scope_info_.is_null()) { | 719 if (scope_info_.is_null()) { |
702 scope_info_ = ScopeInfo::Create(this); | 720 scope_info_ = ScopeInfo::Create(this, zone()); |
703 } | 721 } |
704 return scope_info_; | 722 return scope_info_; |
705 } | 723 } |
706 | 724 |
707 | 725 |
708 void Scope::GetNestedScopeChain( | 726 void Scope::GetNestedScopeChain( |
709 List<Handle<ScopeInfo> >* chain, | 727 List<Handle<ScopeInfo> >* chain, |
710 int position) { | 728 int position) { |
711 if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo())); | 729 if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo())); |
712 | 730 |
(...skipping 165 matching lines...) Loading... |
878 inner_scopes_[i]->Print(n1); | 896 inner_scopes_[i]->Print(n1); |
879 } | 897 } |
880 } | 898 } |
881 | 899 |
882 Indent(n0, "}\n"); | 900 Indent(n0, "}\n"); |
883 } | 901 } |
884 #endif // DEBUG | 902 #endif // DEBUG |
885 | 903 |
886 | 904 |
887 Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) { | 905 Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) { |
888 if (dynamics_ == NULL) dynamics_ = new DynamicScopePart(); | 906 if (dynamics_ == NULL) dynamics_ = new(zone()) DynamicScopePart(zone()); |
889 VariableMap* map = dynamics_->GetMap(mode); | 907 VariableMap* map = dynamics_->GetMap(mode); |
890 Variable* var = map->Lookup(name); | 908 Variable* var = map->Lookup(name); |
891 if (var == NULL) { | 909 if (var == NULL) { |
892 // Declare a new non-local. | 910 // Declare a new non-local. |
893 InitializationFlag init_flag = (mode == VAR) | 911 InitializationFlag init_flag = (mode == VAR) |
894 ? kCreatedInitialized : kNeedsInitialization; | 912 ? kCreatedInitialized : kNeedsInitialization; |
895 var = map->Declare(NULL, | 913 var = map->Declare(NULL, |
896 name, | 914 name, |
897 mode, | 915 mode, |
898 true, | 916 true, |
899 Variable::NORMAL, | 917 Variable::NORMAL, |
900 init_flag); | 918 init_flag, |
| 919 zone()); |
901 // Allocate it by giving it a dynamic lookup. | 920 // Allocate it by giving it a dynamic lookup. |
902 var->AllocateTo(Variable::LOOKUP, -1); | 921 var->AllocateTo(Variable::LOOKUP, -1); |
903 } | 922 } |
904 return var; | 923 return var; |
905 } | 924 } |
906 | 925 |
907 | 926 |
908 Variable* Scope::LookupRecursive(Handle<String> name, | 927 Variable* Scope::LookupRecursive(Handle<String> name, |
909 BindingKind* binding_kind, | 928 BindingKind* binding_kind, |
910 AstNodeFactory<AstNullVisitor>* factory) { | 929 AstNodeFactory<AstNullVisitor>* factory) { |
(...skipping 101 matching lines...) Loading... |
1012 | 1031 |
1013 ASSERT(var != NULL); | 1032 ASSERT(var != NULL); |
1014 proxy->BindTo(var); | 1033 proxy->BindTo(var); |
1015 | 1034 |
1016 if (FLAG_harmony_modules) { | 1035 if (FLAG_harmony_modules) { |
1017 bool ok; | 1036 bool ok; |
1018 #ifdef DEBUG | 1037 #ifdef DEBUG |
1019 if (FLAG_print_interface_details) | 1038 if (FLAG_print_interface_details) |
1020 PrintF("# Resolve %s:\n", var->name()->ToAsciiArray()); | 1039 PrintF("# Resolve %s:\n", var->name()->ToAsciiArray()); |
1021 #endif | 1040 #endif |
1022 proxy->interface()->Unify(var->interface(), &ok); | 1041 proxy->interface()->Unify(var->interface(), &ok, zone()); |
1023 if (!ok) { | 1042 if (!ok) { |
1024 #ifdef DEBUG | 1043 #ifdef DEBUG |
1025 if (FLAG_print_interfaces) { | 1044 if (FLAG_print_interfaces) { |
1026 PrintF("SCOPES TYPE ERROR\n"); | 1045 PrintF("SCOPES TYPE ERROR\n"); |
1027 PrintF("proxy: "); | 1046 PrintF("proxy: "); |
1028 proxy->interface()->Print(); | 1047 proxy->interface()->Print(); |
1029 PrintF("var: "); | 1048 PrintF("var: "); |
1030 var->interface()->Print(); | 1049 var->interface()->Print(); |
1031 } | 1050 } |
1032 #endif | 1051 #endif |
(...skipping 251 matching lines...) Loading... |
1284 } | 1303 } |
1285 | 1304 |
1286 | 1305 |
1287 int Scope::ContextLocalCount() const { | 1306 int Scope::ContextLocalCount() const { |
1288 if (num_heap_slots() == 0) return 0; | 1307 if (num_heap_slots() == 0) return 0; |
1289 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1308 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1290 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1309 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1291 } | 1310 } |
1292 | 1311 |
1293 } } // namespace v8::internal | 1312 } } // namespace v8::internal |
OLD | NEW |