OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/ast/scopeinfo.h" | 8 #include "src/ast/scopeinfo.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 params_(0, zone), | 134 params_(0, zone), |
135 unresolved_(0, zone), | 135 unresolved_(0, zone), |
136 decls_(0, zone), | 136 decls_(0, zone), |
137 module_descriptor_(NULL), | 137 module_descriptor_(NULL), |
138 sloppy_block_function_map_(zone), | 138 sloppy_block_function_map_(zone), |
139 already_resolved_(true), | 139 already_resolved_(true), |
140 ast_value_factory_(value_factory), | 140 ast_value_factory_(value_factory), |
141 zone_(zone) { | 141 zone_(zone) { |
142 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); | 142 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); |
143 AddInnerScope(inner_scope); | 143 AddInnerScope(inner_scope); |
144 ++num_var_or_const_; | 144 ++num_var_; |
145 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 145 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
146 Variable* variable = variables_.Declare(this, | 146 Variable* variable = variables_.Declare(this, |
147 catch_variable_name, | 147 catch_variable_name, |
148 VAR, | 148 VAR, |
149 Variable::NORMAL, | 149 Variable::NORMAL, |
150 kCreatedInitialized); | 150 kCreatedInitialized); |
151 AllocateHeapSlot(variable); | 151 AllocateHeapSlot(variable); |
152 } | 152 } |
153 | 153 |
154 | 154 |
(...skipping 23 matching lines...) Expand all Loading... | |
178 language_mode_ = | 178 language_mode_ = |
179 is_module_scope() | 179 is_module_scope() |
180 ? STRICT | 180 ? STRICT |
181 : (outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY); | 181 : (outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY); |
182 outer_scope_calls_sloppy_eval_ = false; | 182 outer_scope_calls_sloppy_eval_ = false; |
183 inner_scope_calls_eval_ = false; | 183 inner_scope_calls_eval_ = false; |
184 scope_nonlinear_ = false; | 184 scope_nonlinear_ = false; |
185 force_eager_compilation_ = false; | 185 force_eager_compilation_ = false; |
186 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) | 186 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) |
187 ? outer_scope->has_forced_context_allocation() : false; | 187 ? outer_scope->has_forced_context_allocation() : false; |
188 num_var_or_const_ = 0; | 188 num_var_ = 0; |
189 num_stack_slots_ = 0; | 189 num_stack_slots_ = 0; |
190 num_heap_slots_ = 0; | 190 num_heap_slots_ = 0; |
191 num_global_slots_ = 0; | 191 num_global_slots_ = 0; |
192 arity_ = 0; | 192 arity_ = 0; |
193 has_simple_parameters_ = true; | 193 has_simple_parameters_ = true; |
194 rest_parameter_ = NULL; | 194 rest_parameter_ = NULL; |
195 rest_index_ = -1; | 195 rest_index_ = -1; |
196 scope_info_ = scope_info; | 196 scope_info_ = scope_info; |
197 start_position_ = kNoSourcePosition; | 197 start_position_ = kNoSourcePosition; |
198 end_position_ = kNoSourcePosition; | 198 end_position_ = kNoSourcePosition; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 } | 332 } |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
336 | 336 |
337 Scope* Scope::FinalizeBlockScope() { | 337 Scope* Scope::FinalizeBlockScope() { |
338 DCHECK(is_block_scope()); | 338 DCHECK(is_block_scope()); |
339 DCHECK(temps_.is_empty()); | 339 DCHECK(temps_.is_empty()); |
340 DCHECK(params_.is_empty()); | 340 DCHECK(params_.is_empty()); |
341 | 341 |
342 if (num_var_or_const() > 0 || | 342 if (num_var() > 0 || (is_declaration_scope() && calls_sloppy_eval())) { |
343 (is_declaration_scope() && calls_sloppy_eval())) { | |
344 return this; | 343 return this; |
345 } | 344 } |
346 | 345 |
347 // Remove this scope from outer scope. | 346 // Remove this scope from outer scope. |
348 outer_scope()->RemoveInnerScope(this); | 347 outer_scope()->RemoveInnerScope(this); |
349 | 348 |
350 // Reparent inner scopes. | 349 // Reparent inner scopes. |
351 for (int i = 0; i < inner_scopes_.length(); i++) { | 350 for (int i = 0; i < inner_scopes_.length(); i++) { |
352 outer_scope()->AddInnerScope(inner_scopes_[i]); | 351 outer_scope()->AddInnerScope(inner_scopes_[i]); |
353 } | 352 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 } | 504 } |
506 | 505 |
507 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 506 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
508 InitializationFlag init_flag, Variable::Kind kind, | 507 InitializationFlag init_flag, Variable::Kind kind, |
509 MaybeAssignedFlag maybe_assigned_flag) { | 508 MaybeAssignedFlag maybe_assigned_flag) { |
510 DCHECK(!already_resolved()); | 509 DCHECK(!already_resolved()); |
511 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are | 510 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are |
512 // introduced during variable allocation, and TEMPORARY variables are | 511 // introduced during variable allocation, and TEMPORARY variables are |
513 // allocated via NewTemporary(). | 512 // allocated via NewTemporary(). |
514 DCHECK(IsDeclaredVariableMode(mode)); | 513 DCHECK(IsDeclaredVariableMode(mode)); |
515 ++num_var_or_const_; | 514 ++num_var_; |
516 return variables_.Declare(this, name, mode, kind, init_flag, | 515 return variables_.Declare(this, name, mode, kind, init_flag, |
517 maybe_assigned_flag); | 516 maybe_assigned_flag); |
518 } | 517 } |
519 | 518 |
520 | 519 |
521 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { | 520 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { |
522 DCHECK(is_script_scope()); | 521 DCHECK(is_script_scope()); |
523 return variables_.Declare(this, | 522 return variables_.Declare(this, |
524 name, | 523 name, |
525 DYNAMIC_GLOBAL, | 524 DYNAMIC_GLOBAL, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 if (other_var != NULL && IsLexicalVariableMode(other_var->mode())) { | 603 if (other_var != NULL && IsLexicalVariableMode(other_var->mode())) { |
605 return decl; | 604 return decl; |
606 } | 605 } |
607 previous = current; | 606 previous = current; |
608 current = current->outer_scope_; | 607 current = current->outer_scope_; |
609 } while (!previous->is_declaration_scope()); | 608 } while (!previous->is_declaration_scope()); |
610 } | 609 } |
611 return NULL; | 610 return NULL; |
612 } | 611 } |
613 | 612 |
613 Declaration* Scope::CheckLexDeclarationsConflictingWith( | |
adamk
2016/07/01 19:14:03
Is this only called on block scopes? Can you add a
| |
614 ZoneList<const AstRawString*>* names) { | |
615 int length = names->length(); | |
adamk
2016/07/01 19:14:04
Nit: should be no need to hoist this.
| |
616 for (int i = 0; i < length; ++i) { | |
617 Variable* var = LookupLocal(names->at(i)); | |
618 if (var != nullptr && IsLexicalVariableMode(var->mode())) { | |
adamk
2016/07/01 19:14:03
If my DCHECK suggestion above is correct, then can
| |
619 // Conflict; find and return its declaration. | |
620 const AstRawString* name = names->at(i); | |
621 int decls_length = decls_.length(); | |
adamk
2016/07/01 19:14:04
Again, no need to hoist this out of the loop.
| |
622 for (int j = 0; j < decls_length; ++j) { | |
623 if (decls_[j]->proxy()->raw_name() == name) { | |
624 return decls_[j]; | |
625 } | |
626 } | |
627 DCHECK(false); | |
628 } | |
629 } | |
630 return nullptr; | |
631 } | |
614 | 632 |
615 class VarAndOrder { | 633 class VarAndOrder { |
616 public: | 634 public: |
617 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } | 635 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } |
618 Variable* var() const { return var_; } | 636 Variable* var() const { return var_; } |
619 int order() const { return order_; } | 637 int order() const { return order_; } |
620 static int Compare(const VarAndOrder* a, const VarAndOrder* b) { | 638 static int Compare(const VarAndOrder* a, const VarAndOrder* b) { |
621 return a->order_ - b->order_; | 639 return a->order_ - b->order_; |
622 } | 640 } |
623 | 641 |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1535 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1518 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1536 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1519 (is_function_var_in_context ? 1 : 0); | 1537 (is_function_var_in_context ? 1 : 0); |
1520 } | 1538 } |
1521 | 1539 |
1522 | 1540 |
1523 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1541 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1524 | 1542 |
1525 } // namespace internal | 1543 } // namespace internal |
1526 } // namespace v8 | 1544 } // namespace v8 |
OLD | NEW |