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 <set> | 7 #include <set> |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 193 } |
194 | 194 |
195 void DeclarationScope::SetDefaults() { | 195 void DeclarationScope::SetDefaults() { |
196 is_declaration_scope_ = true; | 196 is_declaration_scope_ = true; |
197 has_simple_parameters_ = true; | 197 has_simple_parameters_ = true; |
198 asm_module_ = false; | 198 asm_module_ = false; |
199 asm_function_ = false; | 199 asm_function_ = false; |
200 force_eager_compilation_ = false; | 200 force_eager_compilation_ = false; |
201 has_arguments_parameter_ = false; | 201 has_arguments_parameter_ = false; |
202 scope_uses_super_property_ = false; | 202 scope_uses_super_property_ = false; |
| 203 has_rest_ = false; |
203 receiver_ = nullptr; | 204 receiver_ = nullptr; |
204 new_target_ = nullptr; | 205 new_target_ = nullptr; |
205 function_ = nullptr; | 206 function_ = nullptr; |
206 arguments_ = nullptr; | 207 arguments_ = nullptr; |
207 this_function_ = nullptr; | 208 this_function_ = nullptr; |
208 arity_ = 0; | 209 arity_ = 0; |
209 rest_index_ = -1; | |
210 } | 210 } |
211 | 211 |
212 void Scope::SetDefaults() { | 212 void Scope::SetDefaults() { |
213 #ifdef DEBUG | 213 #ifdef DEBUG |
214 scope_name_ = nullptr; | 214 scope_name_ = nullptr; |
215 already_resolved_ = false; | 215 already_resolved_ = false; |
216 #endif | 216 #endif |
217 inner_scope_ = nullptr; | 217 inner_scope_ = nullptr; |
218 sibling_ = nullptr; | 218 sibling_ = nullptr; |
219 unresolved_ = nullptr; | 219 unresolved_ = nullptr; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 if (var != NULL) return var; | 674 if (var != NULL) return var; |
675 } | 675 } |
676 return NULL; | 676 return NULL; |
677 } | 677 } |
678 | 678 |
679 Variable* DeclarationScope::DeclareParameter( | 679 Variable* DeclarationScope::DeclareParameter( |
680 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, | 680 const AstRawString* name, VariableMode mode, bool is_optional, bool is_rest, |
681 bool* is_duplicate, AstValueFactory* ast_value_factory) { | 681 bool* is_duplicate, AstValueFactory* ast_value_factory) { |
682 DCHECK(!already_resolved_); | 682 DCHECK(!already_resolved_); |
683 DCHECK(is_function_scope()); | 683 DCHECK(is_function_scope()); |
| 684 DCHECK(!has_rest_parameter()); |
684 DCHECK(!is_optional || !is_rest); | 685 DCHECK(!is_optional || !is_rest); |
685 Variable* var; | 686 Variable* var; |
686 if (mode == TEMPORARY) { | 687 if (mode == TEMPORARY) { |
687 var = NewTemporary(name); | 688 var = NewTemporary(name); |
688 } else { | 689 } else { |
689 var = Declare(zone(), this, name, mode, Variable::NORMAL, | 690 var = Declare(zone(), this, name, mode, Variable::NORMAL, |
690 kCreatedInitialized); | 691 kCreatedInitialized); |
691 // TODO(wingo): Avoid O(n^2) check. | 692 // TODO(wingo): Avoid O(n^2) check. |
692 *is_duplicate = IsDeclaredParameter(name); | 693 *is_duplicate = IsDeclaredParameter(name); |
693 } | 694 } |
694 if (!is_optional && !is_rest && arity_ == params_.length()) { | 695 if (!is_optional && !is_rest && arity_ == params_.length()) { |
695 ++arity_; | 696 ++arity_; |
696 } | 697 } |
697 if (is_rest) rest_index_ = num_parameters(); | 698 has_rest_ = is_rest; |
698 params_.Add(var, zone()); | 699 params_.Add(var, zone()); |
699 if (name == ast_value_factory->arguments_string()) { | 700 if (name == ast_value_factory->arguments_string()) { |
700 has_arguments_parameter_ = true; | 701 has_arguments_parameter_ = true; |
701 } | 702 } |
702 return var; | 703 return var; |
703 } | 704 } |
704 | 705 |
705 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, | 706 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, |
706 InitializationFlag init_flag, Variable::Kind kind, | 707 InitializationFlag init_flag, Variable::Kind kind, |
707 MaybeAssignedFlag maybe_assigned_flag) { | 708 MaybeAssignedFlag maybe_assigned_flag) { |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 } | 1492 } |
1492 | 1493 |
1493 } else { | 1494 } else { |
1494 DCHECK(is_arrow_scope()); | 1495 DCHECK(is_arrow_scope()); |
1495 } | 1496 } |
1496 | 1497 |
1497 // The same parameter may occur multiple times in the parameters_ list. | 1498 // The same parameter may occur multiple times in the parameters_ list. |
1498 // If it does, and if it is not copied into the context object, it must | 1499 // If it does, and if it is not copied into the context object, it must |
1499 // receive the highest parameter index for that parameter; thus iteration | 1500 // receive the highest parameter index for that parameter; thus iteration |
1500 // order is relevant! | 1501 // order is relevant! |
1501 for (int i = params_.length() - 1; i >= 0; --i) { | 1502 for (int i = num_parameters() - 1; i >= 0; --i) { |
1502 if (i == rest_index_) continue; | |
1503 Variable* var = params_[i]; | 1503 Variable* var = params_[i]; |
1504 | 1504 DCHECK(!has_rest_parameter() || var != rest_parameter()); |
1505 DCHECK(var->scope() == this); | 1505 DCHECK_EQ(this, var->scope()); |
1506 if (uses_sloppy_arguments) { | 1506 if (uses_sloppy_arguments) { |
1507 var->ForceContextAllocation(); | 1507 var->ForceContextAllocation(); |
1508 } | 1508 } |
1509 AllocateParameter(var, i); | 1509 AllocateParameter(var, i); |
1510 } | 1510 } |
1511 } | 1511 } |
1512 | 1512 |
1513 void DeclarationScope::AllocateParameter(Variable* var, int index) { | 1513 void DeclarationScope::AllocateParameter(Variable* var, int index) { |
1514 if (MustAllocate(var)) { | 1514 if (MustAllocate(var)) { |
1515 if (MustAllocateInContext(var)) { | 1515 if (MustAllocateInContext(var)) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 | 1587 |
1588 void DeclarationScope::AllocateLocals() { | 1588 void DeclarationScope::AllocateLocals() { |
1589 // For now, function_ must be allocated at the very end. If it gets | 1589 // For now, function_ must be allocated at the very end. If it gets |
1590 // allocated in the context, it must be the last slot in the context, | 1590 // allocated in the context, it must be the last slot in the context, |
1591 // because of the current ScopeInfo implementation (see | 1591 // because of the current ScopeInfo implementation (see |
1592 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). | 1592 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). |
1593 if (function_ != nullptr) { | 1593 if (function_ != nullptr) { |
1594 AllocateNonParameterLocal(function_); | 1594 AllocateNonParameterLocal(function_); |
1595 } | 1595 } |
1596 | 1596 |
1597 DCHECK(!has_rest_parameter() || !MustAllocate(params_[rest_index_]) || | 1597 DCHECK(!has_rest_parameter() || !MustAllocate(rest_parameter()) || |
1598 !params_[rest_index_]->IsUnallocated()); | 1598 !rest_parameter()->IsUnallocated()); |
1599 | 1599 |
1600 if (new_target_ != nullptr && !MustAllocate(new_target_)) { | 1600 if (new_target_ != nullptr && !MustAllocate(new_target_)) { |
1601 new_target_ = nullptr; | 1601 new_target_ = nullptr; |
1602 } | 1602 } |
1603 | 1603 |
1604 if (this_function_ != nullptr && !MustAllocate(this_function_)) { | 1604 if (this_function_ != nullptr && !MustAllocate(this_function_)) { |
1605 this_function_ = nullptr; | 1605 this_function_ = nullptr; |
1606 } | 1606 } |
1607 } | 1607 } |
1608 | 1608 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 function != nullptr && function->IsContextSlot(); | 1681 function != nullptr && function->IsContextSlot(); |
1682 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1682 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1683 (is_function_var_in_context ? 1 : 0); | 1683 (is_function_var_in_context ? 1 : 0); |
1684 } | 1684 } |
1685 | 1685 |
1686 | 1686 |
1687 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1687 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1688 | 1688 |
1689 } // namespace internal | 1689 } // namespace internal |
1690 } // namespace v8 | 1690 } // namespace v8 |
OLD | NEW |