Index: src/ast/modules.h |
diff --git a/src/ast/modules.h b/src/ast/modules.h |
index bdc31b24e630c288fc6eb1f732270797f85f7ee9..8ab33ab3b0e6453fd58245c541fdad10dad6d168 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,7 @@ class ModuleDescriptor : public ZoneObject { |
const AstRawString* export_name; |
const AstRawString* local_name; |
const AstRawString* import_name; |
- const AstRawString* module_request; |
+ int module_request; |
// TODO(neis): Remove local_name component? |
explicit Entry(Scanner::Location loc) |
@@ -86,7 +87,7 @@ class ModuleDescriptor : public ZoneObject { |
export_name(nullptr), |
local_name(nullptr), |
import_name(nullptr), |
- module_request(nullptr) {} |
+ module_request(-1) {} |
adamk
2016/09/19 19:57:20
Would be good to document somewhere that "-1" mean
neis
2016/09/19 21:13:46
I added a comment. Negative means no module reque
|
// (De-)serialization support. |
// Note that the location value is not preserved as it's only needed by the |
@@ -96,6 +97,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 +126,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 +180,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 |