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

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

Issue 2277253003: [modules] Partial scope info support of modules (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@modules-refactor
Patch Set: This is so much fun. Created 4 years, 3 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/ast/variables.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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 157
158 ModuleScope::ModuleScope(DeclarationScope* script_scope, 158 ModuleScope::ModuleScope(DeclarationScope* script_scope,
159 AstValueFactory* ast_value_factory) 159 AstValueFactory* ast_value_factory)
160 : DeclarationScope(ast_value_factory->zone(), script_scope, MODULE_SCOPE) { 160 : DeclarationScope(ast_value_factory->zone(), script_scope, MODULE_SCOPE) {
161 Zone* zone = ast_value_factory->zone(); 161 Zone* zone = ast_value_factory->zone();
162 module_descriptor_ = new (zone) ModuleDescriptor(zone); 162 module_descriptor_ = new (zone) ModuleDescriptor(zone);
163 set_language_mode(STRICT); 163 set_language_mode(STRICT);
164 DeclareThis(ast_value_factory); 164 DeclareThis(ast_value_factory);
165 } 165 }
166 166
167 ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
168 AstValueFactory* avfactory)
169 : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) {
170 Zone* zone = avfactory->zone();
171 ModuleInfo* module_info = scope_info->ModuleDescriptorInfo();
172
173 set_language_mode(STRICT);
174 module_descriptor_ = new (zone) ModuleDescriptor(zone);
175
176 // Deserialize special exports.
177 Handle<FixedArray> special_exports = handle(module_info->special_exports());
178 for (int i = 0, n = special_exports->length(); i < n; ++i) {
179 Handle<FixedArray> serialized_entry(
180 FixedArray::cast(special_exports->get(i)), isolate);
181 module_descriptor_->AddSpecialExport(
182 ModuleDescriptor::Entry::Deserialize(isolate, avfactory,
183 serialized_entry),
184 avfactory->zone());
185 }
186
187 // Deserialize regular exports.
188 Handle<FixedArray> regular_exports = handle(module_info->regular_exports());
189 for (int i = 0, n = regular_exports->length(); i < n; ++i) {
190 Handle<FixedArray> serialized_entry(
191 FixedArray::cast(regular_exports->get(i)), isolate);
192 module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize(
193 isolate, avfactory, serialized_entry));
194 }
195 }
196
167 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) 197 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info)
168 : zone_(zone), 198 : zone_(zone),
169 outer_scope_(nullptr), 199 outer_scope_(nullptr),
170 variables_(zone), 200 variables_(zone),
171 locals_(0, zone), 201 locals_(0, zone),
172 decls_(0, zone), 202 decls_(0, zone),
173 scope_info_(scope_info), 203 scope_info_(scope_info),
174 scope_type_(scope_type) { 204 scope_type_(scope_type) {
175 DCHECK(!scope_info.is_null()); 205 DCHECK(!scope_info.is_null());
176 SetDefaults(); 206 SetDefaults();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 outer_scope->AsDeclarationScope()->set_asm_module(); 351 outer_scope->AsDeclarationScope()->set_asm_module();
322 } else if (context->IsBlockContext()) { 352 } else if (context->IsBlockContext()) {
323 Handle<ScopeInfo> scope_info(context->scope_info(), isolate); 353 Handle<ScopeInfo> scope_info(context->scope_info(), isolate);
324 DCHECK_EQ(scope_info->scope_type(), BLOCK_SCOPE); 354 DCHECK_EQ(scope_info->scope_type(), BLOCK_SCOPE);
325 if (scope_info->is_declaration_scope()) { 355 if (scope_info->is_declaration_scope()) {
326 outer_scope = 356 outer_scope =
327 new (zone) DeclarationScope(zone, BLOCK_SCOPE, scope_info); 357 new (zone) DeclarationScope(zone, BLOCK_SCOPE, scope_info);
328 } else { 358 } else {
329 outer_scope = new (zone) Scope(zone, BLOCK_SCOPE, scope_info); 359 outer_scope = new (zone) Scope(zone, BLOCK_SCOPE, scope_info);
330 } 360 }
361 } else if (context->IsModuleContext()) {
362 ScopeInfo* scope_info = context->closure()->shared()->scope_info();
363 DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE);
364 outer_scope = new (zone) ModuleScope(
365 isolate, Handle<ScopeInfo>(scope_info), ast_value_factory);
331 } else { 366 } else {
332 DCHECK(context->IsCatchContext()); 367 DCHECK(context->IsCatchContext());
333 String* name = context->catch_name(); 368 String* name = context->catch_name();
334 outer_scope = new (zone) 369 outer_scope = new (zone)
335 Scope(zone, ast_value_factory->GetString(handle(name, isolate))); 370 Scope(zone, ast_value_factory->GetString(handle(name, isolate)));
336 } 371 }
337 if (current_scope != nullptr) { 372 if (current_scope != nullptr) {
338 outer_scope->AddInnerScope(current_scope); 373 outer_scope->AddInnerScope(current_scope);
339 } 374 }
340 current_scope = outer_scope; 375 current_scope = outer_scope;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 DeclarationScope* scope = info->literal()->scope(); 456 DeclarationScope* scope = info->literal()->scope();
422 457
423 // We are compiling one of three cases: 458 // We are compiling one of three cases:
424 // 1) top-level code, 459 // 1) top-level code,
425 // 2) a function/eval/module on the top-level 460 // 2) a function/eval/module on the top-level
426 // 3) a function/eval in a scope that was already resolved. 461 // 3) a function/eval in a scope that was already resolved.
427 DCHECK(scope->scope_type() == SCRIPT_SCOPE || 462 DCHECK(scope->scope_type() == SCRIPT_SCOPE ||
428 scope->outer_scope()->scope_type() == SCRIPT_SCOPE || 463 scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
429 scope->outer_scope()->already_resolved_); 464 scope->outer_scope()->already_resolved_);
430 465
466 // For modules, we want to start variable allocation at the surrounding script
467 // scope.
468 if (scope->is_module_scope()) {
469 scope = scope->outer_scope()->AsDeclarationScope();
470 }
471
431 scope->AllocateVariables(info, mode); 472 scope->AllocateVariables(info, mode);
432 473
433 #ifdef DEBUG 474 #ifdef DEBUG
434 if (info->script_is_native() ? FLAG_print_builtin_scopes 475 if (info->script_is_native() ? FLAG_print_builtin_scopes
435 : FLAG_print_scopes) { 476 : FLAG_print_scopes) {
436 scope->Print(); 477 scope->Print();
437 } 478 }
438 scope->CheckScopePositions(); 479 scope->CheckScopePositions();
439 scope->CheckZones(); 480 scope->CheckZones();
440 #endif 481 #endif
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 651
611 VariableMode mode; 652 VariableMode mode;
612 InitializationFlag init_flag; 653 InitializationFlag init_flag;
613 MaybeAssignedFlag maybe_assigned_flag; 654 MaybeAssignedFlag maybe_assigned_flag;
614 655
615 VariableLocation location = VariableLocation::CONTEXT; 656 VariableLocation location = VariableLocation::CONTEXT;
616 int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode, 657 int index = ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode,
617 &init_flag, &maybe_assigned_flag); 658 &init_flag, &maybe_assigned_flag);
618 if (index < 0 && scope_type() == MODULE_SCOPE) { 659 if (index < 0 && scope_type() == MODULE_SCOPE) {
619 location = VariableLocation::MODULE; 660 location = VariableLocation::MODULE;
620 index = -1; // TODO(neis): Find module variables in scope info. 661 index = scope_info_->ModuleIndex(name_handle, &mode, &init_flag,
662 &maybe_assigned_flag);
621 } 663 }
622 if (index < 0) return nullptr; // Nowhere found. 664 if (index < 0) return nullptr; // Nowhere found.
623 665
624 Variable::Kind kind = Variable::NORMAL; 666 Variable::Kind kind = Variable::NORMAL;
625 if (location == VariableLocation::CONTEXT && 667 if (location == VariableLocation::CONTEXT &&
626 index == scope_info_->ReceiverContextSlotIndex()) { 668 index == scope_info_->ReceiverContextSlotIndex()) {
627 kind = Variable::THIS; 669 kind = Variable::THIS;
628 } 670 }
629 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and 671 // TODO(marja, rossberg): Correctly declare FUNCTION, CLASS, NEW_TARGET, and
630 // ARGUMENTS bindings as their corresponding Variable::Kind. 672 // ARGUMENTS bindings as their corresponding Variable::Kind.
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 Variable* function = 1698 Variable* function =
1657 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1699 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1658 bool is_function_var_in_context = 1700 bool is_function_var_in_context =
1659 function != nullptr && function->IsContextSlot(); 1701 function != nullptr && function->IsContextSlot();
1660 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1702 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1661 (is_function_var_in_context ? 1 : 0); 1703 (is_function_var_in_context ? 1 : 0);
1662 } 1704 }
1663 1705
1664 } // namespace internal 1706 } // namespace internal
1665 } // namespace v8 1707 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/ast/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698