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

Unified Diff: src/ast/modules.h

Issue 2353633002: [modules] Explicitly keep track of module requests. (Closed)
Patch Set: Address comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/ast/modules.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/modules.h
diff --git a/src/ast/modules.h b/src/ast/modules.h
index bdc31b24e630c288fc6eb1f732270797f85f7ee9..563c1259374d5f5188ccbaa89efef0558e8312a4 100644
--- a/src/ast/modules.h
+++ b/src/ast/modules.h
@@ -19,7 +19,8 @@ class ModuleInfoEntry;
class ModuleDescriptor : public ZoneObject {
public:
explicit ModuleDescriptor(Zone* zone)
- : special_exports_(1, zone),
+ : module_requests_(zone),
+ special_exports_(1, zone),
special_imports_(1, zone),
regular_exports_(zone),
regular_imports_(zone) {}
@@ -78,7 +79,11 @@ class ModuleDescriptor : public ZoneObject {
const AstRawString* export_name;
const AstRawString* local_name;
const AstRawString* import_name;
- const AstRawString* module_request;
+ // The module_request value records the order in which modules are
+ // requested. It also functions as an index into the ModuleInfo's array of
+ // module specifiers and into the Module's array of requested modules. A
+ // negative value means no module request.
+ int module_request;
// TODO(neis): Remove local_name component?
explicit Entry(Scanner::Location loc)
@@ -86,7 +91,7 @@ class ModuleDescriptor : public ZoneObject {
export_name(nullptr),
local_name(nullptr),
import_name(nullptr),
- module_request(nullptr) {}
+ module_request(-1) {}
// (De-)serialization support.
// Note that the location value is not preserved as it's only needed by the
@@ -96,6 +101,11 @@ class ModuleDescriptor : public ZoneObject {
Handle<ModuleInfoEntry> entry);
};
+ // Module requests.
+ const ZoneMap<const AstRawString*, int>& module_requests() const {
+ return module_requests_;
+ }
+
// Empty imports and namespace imports.
const ZoneList<const Entry*>& special_imports() const {
return special_imports_;
@@ -120,32 +130,34 @@ class ModuleDescriptor : public ZoneObject {
DCHECK_NOT_NULL(entry->export_name);
DCHECK_NOT_NULL(entry->local_name);
DCHECK_NULL(entry->import_name);
+ DCHECK_LT(entry->module_request, 0);
regular_exports_.insert(std::make_pair(entry->local_name, entry));
}
void AddSpecialExport(const Entry* entry, Zone* zone) {
- DCHECK_NOT_NULL(entry->module_request);
+ DCHECK_LE(0, entry->module_request);
special_exports_.Add(entry, zone);
}
void AddRegularImport(const Entry* entry) {
DCHECK_NOT_NULL(entry->import_name);
DCHECK_NOT_NULL(entry->local_name);
- DCHECK_NOT_NULL(entry->module_request);
DCHECK_NULL(entry->export_name);
+ DCHECK_LE(0, entry->module_request);
regular_imports_.insert(std::make_pair(entry->local_name, entry));
// We don't care if there's already an entry for this local name, as in that
// case we will report an error when declaring the variable.
}
void AddSpecialImport(const Entry* entry, Zone* zone) {
- DCHECK_NOT_NULL(entry->module_request);
DCHECK_NULL(entry->export_name);
+ DCHECK_LE(0, entry->module_request);
special_imports_.Add(entry, zone);
}
private:
// TODO(neis): Use STL datastructure instead of ZoneList?
+ ZoneMap<const AstRawString*, int> module_requests_;
ZoneList<const Entry*> special_exports_;
ZoneList<const Entry*> special_imports_;
ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
@@ -172,6 +184,14 @@ class ModuleDescriptor : public ZoneObject {
// import {a as b} from "X"; export {a as c} from "X";
// (The import entry is never deleted.)
void MakeIndirectExportsExplicit(Zone* zone);
+
+ int AddModuleRequest(const AstRawString* specifier) {
+ DCHECK_NOT_NULL(specifier);
+ auto it = module_requests_
+ .insert(std::make_pair(specifier, module_requests_.size()))
+ .first;
+ return it->second;
+ }
};
} // namespace internal
« no previous file with comments | « no previous file | src/ast/modules.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698