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

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: Comment 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
Index: src/ast/scopes.cc
diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc
index dfa66609b15c5340299dbc507c00f398e4c27c0e..a97725a4bf583232e597d5f0d99d40817c7c4be9 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -767,6 +767,7 @@ bool Scope::AllocateVariables(ParseInfo* info, AstNodeFactory* factory) {
if (!ResolveVariablesRecursively(info, factory)) return false;
// 3) Allocate variables.
+ if (info->is_module()) AllocateModuleVariables();
AllocateVariablesRecursively(info->ast_value_factory());
return true;
@@ -857,6 +858,12 @@ Scope* Scope::ClosureScope() {
return scope;
}
+Scope* Scope::ModuleScope() {
+ Scope* scope = this;
+ while (!scope->is_script_scope()) scope = scope->outer_scope();
+ scope = scope->inner_scope();
adamk 2016/08/02 16:34:31 Why not just walk up till you hit the module scope
neis 2016/08/03 09:16:30 Because "this" may already be the script scope. Se
adamk 2016/08/03 17:51:26 But we'll walk _down_ the scope tree as part of an
+ return (scope == nullptr || !scope->is_module_scope()) ? nullptr : scope;
+}
Scope* Scope::ReceiverScope() {
Scope* scope = this;
@@ -979,6 +986,9 @@ static void PrintLocation(Variable* var) {
case VariableLocation::LOOKUP:
PrintF("lookup");
break;
+ case VariableLocation::MODULE:
+ PrintF("module");
+ break;
}
}
@@ -1588,6 +1598,23 @@ void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(
}
}
+void Scope::AllocateModuleVariables() {
+ Scope* module_scope = ModuleScope();
adamk 2016/08/02 16:34:31 Does this need to walk up to the ModuleScope? I wo
neis 2016/08/03 09:16:30 I'm calling AllocateModuleVariables inside Allocat
adamk 2016/08/03 17:51:26 See above, I was imagining that we'd check is_modu
+ ModuleDescriptor* mod = module_scope->module();
+ for (auto entry : mod->imports()) {
+ if (entry->local_name == nullptr) continue;
+ if (entry->import_name == nullptr) continue; // Namespace import.
+ Variable* var = module_scope->LookupLocal(entry->local_name);
+ // TODO(neis): Use a meaningful index.
+ var->AllocateTo(VariableLocation::MODULE, 42);
adamk 2016/08/02 16:34:31 For imports, I think we want to check Scope::MustA
neis 2016/08/03 09:16:30 Not sure I understand. Setting the VariableLocatio
adamk 2016/08/03 17:51:26 My understanding may be wrong, but I thought that
+ }
+ for (auto entry : mod->exports()) {
+ if (entry->local_name == nullptr) continue;
+ Variable* var = module_scope->LookupLocal(entry->local_name);
+ var->AllocateTo(VariableLocation::MODULE, 42);
+ }
+}
+
void Scope::AllocateVariablesRecursively(AstValueFactory* ast_value_factory) {
if (!already_resolved()) {
num_stack_slots_ = 0;

Powered by Google App Engine
This is Rietveld 408576698