| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ModuleDescriptor(zone) | 120 ModuleDescriptor(zone) |
| 121 : NULL) { | 121 : NULL) { |
| 122 SetDefaults(); | 122 SetDefaults(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 125 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
| 126 Handle<ScopeInfo> scope_info) | 126 Handle<ScopeInfo> scope_info) |
| 127 : zone_(zone), | 127 : zone_(zone), |
| 128 outer_scope_(nullptr), | 128 outer_scope_(nullptr), |
| 129 variables_(zone), | 129 variables_(zone), |
| 130 decls_(4, zone), | 130 decls_(0, zone), |
| 131 scope_info_(scope_info), | 131 scope_info_(scope_info), |
| 132 scope_type_(scope_type), | 132 scope_type_(scope_type), |
| 133 already_resolved_(true) { | 133 already_resolved_(true) { |
| 134 SetDefaults(); | 134 SetDefaults(); |
| 135 if (!scope_info.is_null()) { | 135 if (!scope_info.is_null()) { |
| 136 scope_calls_eval_ = scope_info->CallsEval(); | 136 scope_calls_eval_ = scope_info->CallsEval(); |
| 137 language_mode_ = scope_info->language_mode(); | 137 language_mode_ = scope_info->language_mode(); |
| 138 num_heap_slots_ = scope_info_->ContextLength(); | 138 num_heap_slots_ = scope_info_->ContextLength(); |
| 139 } | 139 } |
| 140 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 140 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. |
| 141 num_heap_slots_ = Max(num_heap_slots_, | 141 num_heap_slots_ = Max(num_heap_slots_, |
| 142 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 142 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |
| 143 if (inner_scope != nullptr) AddInnerScope(inner_scope); | 143 if (inner_scope != nullptr) AddInnerScope(inner_scope); |
| 144 } | 144 } |
| 145 | 145 |
| 146 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, | 146 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, |
| 147 ScopeType scope_type, | 147 ScopeType scope_type, |
| 148 Handle<ScopeInfo> scope_info) | 148 Handle<ScopeInfo> scope_info) |
| 149 : Scope(zone, inner_scope, scope_type, scope_info), | 149 : Scope(zone, inner_scope, scope_type, scope_info), |
| 150 function_kind_(scope_info.is_null() ? kNormalFunction | 150 function_kind_(scope_info.is_null() ? kNormalFunction |
| 151 : scope_info->function_kind()), | 151 : scope_info->function_kind()), |
| 152 temps_(4, zone), | 152 temps_(0, zone), |
| 153 params_(4, zone), | 153 params_(0, zone), |
| 154 sloppy_block_function_map_(zone), | 154 sloppy_block_function_map_(zone), |
| 155 module_descriptor_(nullptr) { | 155 module_descriptor_(nullptr) { |
| 156 SetDefaults(); | 156 SetDefaults(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 Scope::Scope(Zone* zone, Scope* inner_scope, | 159 Scope::Scope(Zone* zone, Scope* inner_scope, |
| 160 const AstRawString* catch_variable_name) | 160 const AstRawString* catch_variable_name) |
| 161 : zone_(zone), | 161 : zone_(zone), |
| 162 outer_scope_(nullptr), | 162 outer_scope_(nullptr), |
| 163 variables_(zone), | 163 variables_(zone), |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 var->set_next_unresolved(nullptr); | 698 var->set_next_unresolved(nullptr); |
| 699 return true; | 699 return true; |
| 700 } | 700 } |
| 701 current = next; | 701 current = next; |
| 702 } | 702 } |
| 703 return false; | 703 return false; |
| 704 } | 704 } |
| 705 | 705 |
| 706 | 706 |
| 707 Variable* Scope::NewTemporary(const AstRawString* name) { | 707 Variable* Scope::NewTemporary(const AstRawString* name) { |
| 708 DCHECK(!already_resolved()); | |
| 709 DeclarationScope* scope = GetClosureScope(); | 708 DeclarationScope* scope = GetClosureScope(); |
| 710 Variable* var = new(zone()) Variable(scope, | 709 Variable* var = new(zone()) Variable(scope, |
| 711 name, | 710 name, |
| 712 TEMPORARY, | 711 TEMPORARY, |
| 713 Variable::NORMAL, | 712 Variable::NORMAL, |
| 714 kCreatedInitialized); | 713 kCreatedInitialized); |
| 715 scope->AddTemporary(var); | 714 scope->AddTemporary(var); |
| 716 return var; | 715 return var; |
| 717 } | 716 } |
| 718 | 717 |
| 719 int DeclarationScope::RemoveTemporary(Variable* var) { | 718 int DeclarationScope::RemoveTemporary(Variable* var) { |
| 719 DCHECK(!already_resolved()); |
| 720 DCHECK_NOT_NULL(var); | 720 DCHECK_NOT_NULL(var); |
| 721 // Temporaries are only placed in ClosureScopes. | 721 // Temporaries are only placed in ClosureScopes. |
| 722 DCHECK_EQ(GetClosureScope(), this); | 722 DCHECK_EQ(GetClosureScope(), this); |
| 723 DCHECK_EQ(var->scope()->GetClosureScope(), var->scope()); | 723 DCHECK_EQ(var->scope()->GetClosureScope(), var->scope()); |
| 724 // If the temporary is not here, return quickly. | 724 // If the temporary is not here, return quickly. |
| 725 if (var->scope() != this) return -1; | 725 if (var->scope() != this) return -1; |
| 726 // Most likely (always?) any temporary variable we want to remove | 726 // Most likely (always?) any temporary variable we want to remove |
| 727 // was just added before, so we search backwards. | 727 // was just added before, so we search backwards. |
| 728 for (int i = temps_.length(); i-- > 0;) { | 728 for (int i = temps_.length(); i-- > 0;) { |
| 729 if (temps_[i] == var) { | 729 if (temps_[i] == var) { |
| 730 // Don't shrink temps_, as callers of this method expect | 730 // Don't shrink temps_, as callers of this method expect |
| 731 // the returned indices to be unique per-scope. | 731 // the returned indices to be unique per-scope. |
| 732 temps_[i] = nullptr; | 732 temps_[i] = nullptr; |
| 733 return i; | 733 return i; |
| 734 } | 734 } |
| 735 } | 735 } |
| 736 return -1; | 736 return -1; |
| 737 } | 737 } |
| 738 | 738 |
| 739 | 739 |
| 740 void Scope::AddDeclaration(Declaration* declaration) { | 740 void Scope::AddDeclaration(Declaration* declaration) { |
| 741 DCHECK(!already_resolved()); |
| 741 decls_.Add(declaration, zone()); | 742 decls_.Add(declaration, zone()); |
| 742 } | 743 } |
| 743 | 744 |
| 744 | 745 |
| 745 Declaration* Scope::CheckConflictingVarDeclarations() { | 746 Declaration* Scope::CheckConflictingVarDeclarations() { |
| 746 int length = decls_.length(); | 747 int length = decls_.length(); |
| 747 for (int i = 0; i < length; i++) { | 748 for (int i = 0; i < length; i++) { |
| 748 Declaration* decl = decls_[i]; | 749 Declaration* decl = decls_[i]; |
| 749 // We don't create a separate scope to hold the function name of a function | 750 // We don't create a separate scope to hold the function name of a function |
| 750 // expression, so we have to make sure not to consider it when checking for | 751 // expression, so we have to make sure not to consider it when checking for |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 function != NULL && function->proxy()->var()->IsContextSlot(); | 1783 function != NULL && function->proxy()->var()->IsContextSlot(); |
| 1783 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1784 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1784 (is_function_var_in_context ? 1 : 0); | 1785 (is_function_var_in_context ? 1 : 0); |
| 1785 } | 1786 } |
| 1786 | 1787 |
| 1787 | 1788 |
| 1788 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1789 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1789 | 1790 |
| 1790 } // namespace internal | 1791 } // namespace internal |
| 1791 } // namespace v8 | 1792 } // namespace v8 |
| OLD | NEW |