Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Side by Side Diff: src/ast/scopes.cc

Issue 2252223002: Introduce ModuleScope subclass of DeclarationScope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/globals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, 105 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
106 ScopeType scope_type, 106 ScopeType scope_type,
107 FunctionKind function_kind) 107 FunctionKind function_kind)
108 : Scope(zone, outer_scope, scope_type), 108 : Scope(zone, outer_scope, scope_type),
109 function_kind_(function_kind), 109 function_kind_(function_kind),
110 temps_(4, zone), 110 temps_(4, zone),
111 params_(4, zone), 111 params_(4, zone),
112 sloppy_block_function_map_(zone) { 112 sloppy_block_function_map_(zone) {
113 SetDefaults(); 113 SetDefaults();
114 if (scope_type == MODULE_SCOPE) { 114 }
115 module_descriptor_ = new (zone) ModuleDescriptor(zone); 115
116 language_mode_ = STRICT; 116 ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope,
117 } 117 AstValueFactory* ast_value_factory)
118 : DeclarationScope(zone, script_scope, MODULE_SCOPE) {
119 module_descriptor_ = new (zone) ModuleDescriptor(zone);
120 set_language_mode(STRICT);
121 DeclareThis(ast_value_factory);
118 } 122 }
119 123
120 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, 124 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
121 Handle<ScopeInfo> scope_info) 125 Handle<ScopeInfo> scope_info)
122 : zone_(zone), 126 : zone_(zone),
123 outer_scope_(nullptr), 127 outer_scope_(nullptr),
124 variables_(zone), 128 variables_(zone),
125 decls_(0, zone), 129 decls_(0, zone),
126 scope_info_(scope_info), 130 scope_info_(scope_info),
127 scope_type_(scope_type) { 131 scope_type_(scope_type) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 is_declaration_scope_ = true; 178 is_declaration_scope_ = true;
175 has_simple_parameters_ = true; 179 has_simple_parameters_ = true;
176 receiver_ = nullptr; 180 receiver_ = nullptr;
177 new_target_ = nullptr; 181 new_target_ = nullptr;
178 function_ = nullptr; 182 function_ = nullptr;
179 arguments_ = nullptr; 183 arguments_ = nullptr;
180 this_function_ = nullptr; 184 this_function_ = nullptr;
181 arity_ = 0; 185 arity_ = 0;
182 rest_parameter_ = nullptr; 186 rest_parameter_ = nullptr;
183 rest_index_ = -1; 187 rest_index_ = -1;
184 module_descriptor_ = nullptr;
185 } 188 }
186 189
187 void Scope::SetDefaults() { 190 void Scope::SetDefaults() {
188 #ifdef DEBUG 191 #ifdef DEBUG
189 scope_name_ = nullptr; 192 scope_name_ = nullptr;
190 already_resolved_ = false; 193 already_resolved_ = false;
191 #endif 194 #endif
192 inner_scope_ = nullptr; 195 inner_scope_ = nullptr;
193 sibling_ = nullptr; 196 sibling_ = nullptr;
194 unresolved_ = nullptr; 197 unresolved_ = nullptr;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 DeclarationScope* Scope::AsDeclarationScope() { 362 DeclarationScope* Scope::AsDeclarationScope() {
360 DCHECK(is_declaration_scope()); 363 DCHECK(is_declaration_scope());
361 return static_cast<DeclarationScope*>(this); 364 return static_cast<DeclarationScope*>(this);
362 } 365 }
363 366
364 const DeclarationScope* Scope::AsDeclarationScope() const { 367 const DeclarationScope* Scope::AsDeclarationScope() const {
365 DCHECK(is_declaration_scope()); 368 DCHECK(is_declaration_scope());
366 return static_cast<const DeclarationScope*>(this); 369 return static_cast<const DeclarationScope*>(this);
367 } 370 }
368 371
372 ModuleScope* Scope::AsModuleScope() {
373 DCHECK(is_module_scope());
374 return static_cast<ModuleScope*>(this);
375 }
376
377 const ModuleScope* Scope::AsModuleScope() const {
378 DCHECK(is_module_scope());
379 return static_cast<const ModuleScope*>(this);
380 }
381
369 int Scope::num_parameters() const { 382 int Scope::num_parameters() const {
370 return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0; 383 return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0;
371 } 384 }
372 385
373 void Scope::Analyze(ParseInfo* info) { 386 void Scope::Analyze(ParseInfo* info) {
374 DCHECK(info->literal() != NULL); 387 DCHECK(info->literal() != NULL);
375 DeclarationScope* scope = info->literal()->scope(); 388 DeclarationScope* scope = info->literal()->scope();
376 389
377 // We are compiling one of three cases: 390 // We are compiling one of three cases:
378 // 1) top-level code, 391 // 1) top-level code,
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 1696
1684 if (new_target_ != nullptr && !MustAllocate(new_target_)) { 1697 if (new_target_ != nullptr && !MustAllocate(new_target_)) {
1685 new_target_ = nullptr; 1698 new_target_ = nullptr;
1686 } 1699 }
1687 1700
1688 if (this_function_ != nullptr && !MustAllocate(this_function_)) { 1701 if (this_function_ != nullptr && !MustAllocate(this_function_)) {
1689 this_function_ = nullptr; 1702 this_function_ = nullptr;
1690 } 1703 }
1691 } 1704 }
1692 1705
1693 void DeclarationScope::AllocateModuleVariables() { 1706 void ModuleScope::AllocateModuleVariables() {
1694 for (auto it = module()->regular_imports().begin(); 1707 for (auto it = module()->regular_imports().begin();
1695 it != module()->regular_imports().end(); ++it) { 1708 it != module()->regular_imports().end(); ++it) {
1696 Variable* var = LookupLocal(it->second->local_name); 1709 Variable* var = LookupLocal(it->second->local_name);
1697 // TODO(neis): Use a meaningful index. 1710 // TODO(neis): Use a meaningful index.
1698 var->AllocateTo(VariableLocation::MODULE, 42); 1711 var->AllocateTo(VariableLocation::MODULE, 42);
1699 } 1712 }
1700 1713
1701 for (auto entry : module()->exports()) { 1714 for (auto entry : module()->exports()) {
1702 if (entry->local_name == nullptr) continue; 1715 if (entry->local_name == nullptr) continue;
1703 Variable* var = LookupLocal(entry->local_name); 1716 Variable* var = LookupLocal(entry->local_name);
(...skipping 10 matching lines...) Expand all
1714 scope->AllocateVariablesRecursively(); 1727 scope->AllocateVariablesRecursively();
1715 } 1728 }
1716 1729
1717 DCHECK(!already_resolved_); 1730 DCHECK(!already_resolved_);
1718 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); 1731 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, num_heap_slots_);
1719 1732
1720 // Allocate variables for this scope. 1733 // Allocate variables for this scope.
1721 // Parameters must be allocated first, if any. 1734 // Parameters must be allocated first, if any.
1722 if (is_declaration_scope()) { 1735 if (is_declaration_scope()) {
1723 if (is_module_scope()) { 1736 if (is_module_scope()) {
1724 AsDeclarationScope()->AllocateModuleVariables(); 1737 AsModuleScope()->AllocateModuleVariables();
1725 } else if (is_function_scope()) { 1738 } else if (is_function_scope()) {
1726 AsDeclarationScope()->AllocateParameterLocals(); 1739 AsDeclarationScope()->AllocateParameterLocals();
1727 } 1740 }
1728 AsDeclarationScope()->AllocateReceiver(); 1741 AsDeclarationScope()->AllocateReceiver();
1729 } 1742 }
1730 AllocateNonParameterLocalsAndDeclaredGlobals(); 1743 AllocateNonParameterLocalsAndDeclaredGlobals();
1731 1744
1732 // Force allocation of a context for this scope if necessary. For a 'with' 1745 // Force allocation of a context for this scope if necessary. For a 'with'
1733 // scope and for a function scope that makes an 'eval' call we need a context, 1746 // scope and for a function scope that makes an 'eval' call we need a context,
1734 // even if no local variables were statically allocated in the scope. 1747 // even if no local variables were statically allocated in the scope.
(...skipping 30 matching lines...) Expand all
1765 function != nullptr && function->IsContextSlot(); 1778 function != nullptr && function->IsContextSlot();
1766 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1779 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1767 (is_function_var_in_context ? 1 : 0); 1780 (is_function_var_in_context ? 1 : 0);
1768 } 1781 }
1769 1782
1770 1783
1771 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1784 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1772 1785
1773 } // namespace internal 1786 } // namespace internal
1774 } // namespace v8 1787 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698