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

Unified 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: Undo 'git cl format' screwup and fix order of writes. 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 1aaf5c5321b46403c08fc32effe192070f407e80..16e7add1f1a01870fb962111696e455ed13e72bc 100644
--- a/src/ast/scopes.cc
+++ b/src/ast/scopes.cc
@@ -144,6 +144,36 @@ ModuleScope::ModuleScope(DeclarationScope* script_scope,
DeclareThis(ast_value_factory);
}
+ModuleScope::ModuleScope(Isolate* isolate, Handle<ScopeInfo> scope_info,
+ AstValueFactory* avfactory)
+ : DeclarationScope(avfactory->zone(), MODULE_SCOPE, scope_info) {
+ Zone* zone = avfactory->zone();
+ ModuleInfo* module_info = scope_info->ModuleDescriptorInfo();
+
+ set_language_mode(STRICT);
+ module_descriptor_ = new (zone) ModuleDescriptor(zone);
+
+ // Deserialize special exports.
+ Handle<FixedArray> special_exports = handle(module_info->special_exports());
+ for (int i = 0, n = special_exports->length(); i < n; ++i) {
+ Handle<FixedArray> serialized_entry(
+ FixedArray::cast(special_exports->get(i)), isolate);
+ module_descriptor_->AddSpecialExport(
+ ModuleDescriptor::Entry::Deserialize(isolate, avfactory,
+ serialized_entry),
+ avfactory->zone());
+ }
+
+ // Deserialize regular exports.
+ Handle<FixedArray> regular_exports = handle(module_info->regular_exports());
+ for (int i = 0, n = regular_exports->length(); i < n; ++i) {
+ Handle<FixedArray> serialized_entry(
+ FixedArray::cast(regular_exports->get(i)), isolate);
+ module_descriptor_->AddRegularExport(ModuleDescriptor::Entry::Deserialize(
+ isolate, avfactory, serialized_entry));
+ }
+}
+
Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info)
: zone_(zone),
outer_scope_(nullptr),
@@ -300,6 +330,11 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
} else {
outer_scope = new (zone) Scope(zone, BLOCK_SCOPE, scope_info);
}
+ } else if (context->IsModuleContext()) {
+ ScopeInfo* scope_info = context->closure()->shared()->scope_info();
+ DCHECK_EQ(scope_info->scope_type(), MODULE_SCOPE);
+ outer_scope = new (zone) ModuleScope(
+ isolate, Handle<ScopeInfo>(scope_info), ast_value_factory);
} else {
DCHECK(context->IsCatchContext());
String* name = context->catch_name();
@@ -427,6 +462,12 @@ void Scope::Analyze(ParseInfo* info) {
scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->already_resolved_);
+ // For modules, we want to start variable allocation at the surrounding script
+ // scope.
+ if (scope->is_module_scope()) {
+ scope = scope->outer_scope()->AsDeclarationScope();
+ }
+
scope->AllocateVariables(info);
#ifdef DEBUG
@@ -627,7 +668,8 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name) {
}
if (index < 0 && scope_type() == MODULE_SCOPE) {
location = VariableLocation::MODULE;
- index = -1; // TODO(neis): Find module variables in scope info.
+ index = ScopeInfo::ModuleIndex(scope_info_, name_handle, &mode, &init_flag,
+ &maybe_assigned_flag);
}
if (index < 0) return nullptr; // Nowhere found.
@@ -807,10 +849,12 @@ Declaration* Scope::CheckLexDeclarationsConflictingWith(
void Scope::CollectVariables(ZoneList<Variable*>* stack_locals,
ZoneList<Variable*>* context_locals,
- ZoneList<Variable*>* context_globals) {
+ ZoneList<Variable*>* context_globals,
+ ZoneList<Variable*>* module_vars) {
DCHECK(stack_locals != NULL);
DCHECK(context_locals != NULL);
DCHECK(context_globals != NULL);
+ DCHECK(module_vars != NULL || scope_type() != MODULE_SCOPE);
// Collect temporaries which are always allocated on the stack, unless the
// context as a whole has forced context allocation.
@@ -819,13 +863,17 @@ void Scope::CollectVariables(ZoneList<Variable*>* stack_locals,
for (int i = 0; i < temps->length(); i++) {
adamk 2016/08/26 16:54:44 I think this loop is gone if you merge to ToT.
Variable* var = (*temps)[i];
if (var->is_used()) {
- if (var->IsContextSlot()) {
- DCHECK(has_forced_context_allocation());
- context_locals->Add(var, zone());
- } else if (var->IsStackLocal()) {
- stack_locals->Add(var, zone());
- } else {
- DCHECK(var->IsParameter());
+ switch (var->location()) {
+ case VariableLocation::LOCAL:
+ stack_locals->Add(var, zone());
+ break;
+ case VariableLocation::CONTEXT:
+ DCHECK(has_forced_context_allocation());
+ context_locals->Add(var, zone());
+ break;
+ default:
+ DCHECK(var->IsParameter());
+ break;
}
}
}
@@ -833,12 +881,21 @@ void Scope::CollectVariables(ZoneList<Variable*>* stack_locals,
for (int i = 0; i < ordered_variables_.length(); i++) {
Variable* var = ordered_variables_[i];
- if (var->IsStackLocal()) {
- stack_locals->Add(var, zone());
- } else if (var->IsContextSlot()) {
- context_locals->Add(var, zone());
- } else if (var->IsGlobalSlot()) {
- context_globals->Add(var, zone());
+ switch (var->location()) {
+ case VariableLocation::LOCAL:
+ stack_locals->Add(var, zone());
+ break;
+ case VariableLocation::CONTEXT:
+ context_locals->Add(var, zone());
+ break;
+ case VariableLocation::GLOBAL:
+ context_globals->Add(var, zone());
+ break;
+ case VariableLocation::MODULE:
+ module_vars->Add(var, zone());
+ break;
+ default:
+ break;
}
}
}

Powered by Google App Engine
This is Rietveld 408576698