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

Unified Diff: src/ast/scopes.cc

Issue 2199283002: [modules] Introduce new VariableLocation for module imports/exports. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/ast/variables.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index a11689f67a6a261717f4d8011a6a4173a46e6deb..fb170f2740b93ec387e946836d0c0f48d1bf3990 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -1084,6 +1084,9 @@ static void PrintLocation(Variable* var) {
case VariableLocation::LOOKUP:
PrintF("lookup");
break;
+ case VariableLocation::MODULE:
+ PrintF("module");
+ break;
}
}
@@ -1492,6 +1495,7 @@ void Scope::PropagateScopeInfo(bool outer_scope_calls_sloppy_eval) {
bool Scope::MustAllocate(Variable* var) {
+ DCHECK(var->location() != VariableLocation::MODULE);
// Give var a read/write use if there is a chance it might be accessed
// via an eval() call. This is only possible if the variable has a
// visible name.
@@ -1711,6 +1715,21 @@ void DeclarationScope::AllocateLocals(AstValueFactory* ast_value_factory) {
}
}
+void DeclarationScope::AllocateModuleVariables() {
+ for (auto entry : module()->imports()) {
+ if (entry->local_name == nullptr) continue;
+ if (entry->import_name == nullptr) continue; // Namespace import.
+ Variable* var = LookupLocal(entry->local_name);
+ // TODO(neis): Use a meaningful index.
+ var->AllocateTo(VariableLocation::MODULE, 42);
+ }
+ for (auto entry : module()->exports()) {
+ if (entry->local_name == nullptr) continue;
+ Variable* var = LookupLocal(entry->local_name);
+ var->AllocateTo(VariableLocation::MODULE, 42);
+ }
+}
+
void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) {
if (!already_resolved()) {
num_stack_slots_ = 0;
@@ -1729,7 +1748,11 @@ void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) {
// Allocate variables for this scope.
// Parameters must be allocated first, if any.
if (is_declaration_scope()) {
- if (is_function_scope()) AsDeclarationScope()->AllocateParameterLocals();
+ if (is_module_scope()) {
+ AsDeclarationScope()->AllocateModuleVariables();
+ } else if (is_function_scope()) {
+ AsDeclarationScope()->AllocateParameterLocals();
+ }
AsDeclarationScope()->AllocateReceiver();
}
AllocateNonParameterLocalsAndDeclaredGlobals(ast_value_factory);
« no previous file with comments | « src/ast/scopes.h ('k') | src/ast/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698