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_; | 144 ++num_var_or_const_; |
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_ = 0; | 188 num_var_or_const_ = 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() > 0 || (is_declaration_scope() && calls_sloppy_eval())) { | 342 if (num_var_or_const() > 0 || |
| 343 (is_declaration_scope() && calls_sloppy_eval())) { |
343 return this; | 344 return this; |
344 } | 345 } |
345 | 346 |
346 // Remove this scope from outer scope. | 347 // Remove this scope from outer scope. |
347 outer_scope()->RemoveInnerScope(this); | 348 outer_scope()->RemoveInnerScope(this); |
348 | 349 |
349 // Reparent inner scopes. | 350 // Reparent inner scopes. |
350 for (int i = 0; i < inner_scopes_.length(); i++) { | 351 for (int i = 0; i < inner_scopes_.length(); i++) { |
351 outer_scope()->AddInnerScope(inner_scopes_[i]); | 352 outer_scope()->AddInnerScope(inner_scopes_[i]); |
352 } | 353 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 505 } |
505 | 506 |
506 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 507 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
507 InitializationFlag init_flag, Variable::Kind kind, | 508 InitializationFlag init_flag, Variable::Kind kind, |
508 MaybeAssignedFlag maybe_assigned_flag) { | 509 MaybeAssignedFlag maybe_assigned_flag) { |
509 DCHECK(!already_resolved()); | 510 DCHECK(!already_resolved()); |
510 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are | 511 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are |
511 // introduced during variable allocation, and TEMPORARY variables are | 512 // introduced during variable allocation, and TEMPORARY variables are |
512 // allocated via NewTemporary(). | 513 // allocated via NewTemporary(). |
513 DCHECK(IsDeclaredVariableMode(mode)); | 514 DCHECK(IsDeclaredVariableMode(mode)); |
514 ++num_var_; | 515 ++num_var_or_const_; |
515 return variables_.Declare(this, name, mode, kind, init_flag, | 516 return variables_.Declare(this, name, mode, kind, init_flag, |
516 maybe_assigned_flag); | 517 maybe_assigned_flag); |
517 } | 518 } |
518 | 519 |
519 | 520 |
520 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { | 521 Variable* Scope::DeclareDynamicGlobal(const AstRawString* name) { |
521 DCHECK(is_script_scope()); | 522 DCHECK(is_script_scope()); |
522 return variables_.Declare(this, | 523 return variables_.Declare(this, |
523 name, | 524 name, |
524 DYNAMIC_GLOBAL, | 525 DYNAMIC_GLOBAL, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 if (other_var != NULL && IsLexicalVariableMode(other_var->mode())) { | 604 if (other_var != NULL && IsLexicalVariableMode(other_var->mode())) { |
604 return decl; | 605 return decl; |
605 } | 606 } |
606 previous = current; | 607 previous = current; |
607 current = current->outer_scope_; | 608 current = current->outer_scope_; |
608 } while (!previous->is_declaration_scope()); | 609 } while (!previous->is_declaration_scope()); |
609 } | 610 } |
610 return NULL; | 611 return NULL; |
611 } | 612 } |
612 | 613 |
613 Declaration* Scope::CheckLexDeclarationsConflictingWith( | |
614 ZoneList<const AstRawString*>* names) { | |
615 int length = names->length(); | |
616 for (int i = 0; i < length; ++i) { | |
617 Variable* var = LookupLocal(names->at(i)); | |
618 if (var != nullptr && IsLexicalVariableMode(var->mode())) { | |
619 // Conflict; find and return its declaration. | |
620 const AstRawString* name = names->at(i); | |
621 int decls_length = decls_.length(); | |
622 for (int j = 0; j < decls_length; ++j) { | |
623 if (decls_[i]->proxy()->raw_name() == name) { | |
624 return decls_[i]; | |
625 } | |
626 } | |
627 DCHECK(false); | |
628 } | |
629 } | |
630 return nullptr; | |
631 } | |
632 | 614 |
633 class VarAndOrder { | 615 class VarAndOrder { |
634 public: | 616 public: |
635 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } | 617 VarAndOrder(Variable* var, int order) : var_(var), order_(order) { } |
636 Variable* var() const { return var_; } | 618 Variable* var() const { return var_; } |
637 int order() const { return order_; } | 619 int order() const { return order_; } |
638 static int Compare(const VarAndOrder* a, const VarAndOrder* b) { | 620 static int Compare(const VarAndOrder* a, const VarAndOrder* b) { |
639 return a->order_ - b->order_; | 621 return a->order_ - b->order_; |
640 } | 622 } |
641 | 623 |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1517 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1536 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1518 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1537 (is_function_var_in_context ? 1 : 0); | 1519 (is_function_var_in_context ? 1 : 0); |
1538 } | 1520 } |
1539 | 1521 |
1540 | 1522 |
1541 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1523 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1542 | 1524 |
1543 } // namespace internal | 1525 } // namespace internal |
1544 } // namespace v8 | 1526 } // namespace v8 |
OLD | NEW |