Commit a45d106d authored by neis's avatar neis Committed by Commit bot

[modules] Rename ModuleDescriptor::ModuleEntry to ModuleDescriptor::Entry.

R=adamk@chromium.org
BUG=v8:1569

Review-Url: https://codereview.chromium.org/2278973002
Cr-Commit-Position: refs/heads/master@{#38924}
parent 96886dc7
......@@ -15,7 +15,7 @@ void ModuleDescriptor::AddImport(
DCHECK_NOT_NULL(import_name);
DCHECK_NOT_NULL(local_name);
DCHECK_NOT_NULL(module_request);
ModuleEntry* entry = new (zone) ModuleEntry(loc);
Entry* entry = new (zone) Entry(loc);
entry->local_name = local_name;
entry->import_name = import_name;
entry->module_request = module_request;
......@@ -30,7 +30,7 @@ void ModuleDescriptor::AddStarImport(
Scanner::Location loc, Zone* zone) {
DCHECK_NOT_NULL(local_name);
DCHECK_NOT_NULL(module_request);
ModuleEntry* entry = new (zone) ModuleEntry(loc);
Entry* entry = new (zone) Entry(loc);
entry->local_name = local_name;
entry->module_request = module_request;
special_imports_.Add(entry, zone);
......@@ -40,7 +40,7 @@ void ModuleDescriptor::AddStarImport(
void ModuleDescriptor::AddEmptyImport(
const AstRawString* module_request, Scanner::Location loc, Zone* zone) {
DCHECK_NOT_NULL(module_request);
ModuleEntry* entry = new (zone) ModuleEntry(loc);
Entry* entry = new (zone) Entry(loc);
entry->module_request = module_request;
special_imports_.Add(entry, zone);
}
......@@ -51,7 +51,7 @@ void ModuleDescriptor::AddExport(
Scanner::Location loc, Zone* zone) {
DCHECK_NOT_NULL(local_name);
DCHECK_NOT_NULL(export_name);
ModuleEntry* entry = new (zone) ModuleEntry(loc);
Entry* entry = new (zone) Entry(loc);
entry->export_name = export_name;
entry->local_name = local_name;
regular_exports_.insert(std::make_pair(entry->local_name, entry));
......@@ -64,7 +64,7 @@ void ModuleDescriptor::AddExport(
DCHECK_NOT_NULL(import_name);
DCHECK_NOT_NULL(export_name);
DCHECK_NOT_NULL(module_request);
ModuleEntry* entry = new (zone) ModuleEntry(loc);
Entry* entry = new (zone) Entry(loc);
entry->export_name = export_name;
entry->import_name = import_name;
entry->module_request = module_request;
......@@ -75,14 +75,14 @@ void ModuleDescriptor::AddExport(
void ModuleDescriptor::AddStarExport(
const AstRawString* module_request, Scanner::Location loc, Zone* zone) {
DCHECK_NOT_NULL(module_request);
ModuleEntry* entry = new (zone) ModuleEntry(loc);
Entry* entry = new (zone) Entry(loc);
entry->module_request = module_request;
special_exports_.Add(entry, zone);
}
void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
for (auto it = regular_exports_.begin(); it != regular_exports_.end();) {
ModuleEntry* entry = it->second;
Entry* entry = it->second;
DCHECK_NOT_NULL(entry->local_name);
auto import = regular_imports_.find(entry->local_name);
if (import != regular_imports_.end()) {
......@@ -103,11 +103,11 @@ void ModuleDescriptor::MakeIndirectExportsExplicit(Zone* zone) {
}
}
const ModuleDescriptor::ModuleEntry* ModuleDescriptor::FindDuplicateExport(
const ModuleDescriptor::Entry* ModuleDescriptor::FindDuplicateExport(
Zone* zone) const {
ZoneSet<const AstRawString*> export_names(zone);
for (const auto& it : regular_exports_) {
const ModuleEntry* entry = it.second;
const Entry* entry = it.second;
DCHECK_NOT_NULL(entry->export_name);
if (!export_names.insert(entry->export_name).second) return entry;
}
......@@ -126,7 +126,7 @@ bool ModuleDescriptor::Validate(ModuleScope* module_scope,
// Report error iff there are duplicate exports.
{
const ModuleEntry* entry = FindDuplicateExport(zone);
const Entry* entry = FindDuplicateExport(zone);
if (entry != nullptr) {
error_handler->ReportMessageAt(
entry->location.beg_pos, entry->location.end_pos,
......@@ -137,7 +137,7 @@ bool ModuleDescriptor::Validate(ModuleScope* module_scope,
// Report error iff there are exports of non-existent local names.
for (const auto& it : regular_exports_) {
const ModuleEntry* entry = it.second;
const Entry* entry = it.second;
DCHECK_NOT_NULL(entry->local_name);
if (module_scope->LookupLocal(entry->local_name) == nullptr) {
error_handler->ReportMessageAt(
......
......@@ -70,14 +70,14 @@ class ModuleDescriptor : public ZoneObject {
bool Validate(ModuleScope* module_scope,
PendingCompilationErrorHandler* error_handler, Zone* zone);
struct ModuleEntry : public ZoneObject {
struct Entry : public ZoneObject {
const Scanner::Location location;
const AstRawString* export_name;
const AstRawString* local_name;
const AstRawString* import_name;
const AstRawString* module_request;
explicit ModuleEntry(Scanner::Location loc)
explicit Entry(Scanner::Location loc)
: location(loc),
export_name(nullptr),
local_name(nullptr),
......@@ -86,37 +86,35 @@ class ModuleDescriptor : public ZoneObject {
};
// Empty imports and namespace imports.
const ZoneList<const ModuleEntry*>& special_imports() const {
const ZoneList<const Entry*>& special_imports() const {
return special_imports_;
}
// All the remaining imports, indexed by local name.
const ZoneMap<const AstRawString*, const ModuleEntry*>& regular_imports()
const {
const ZoneMap<const AstRawString*, const Entry*>& regular_imports() const {
return regular_imports_;
}
// Star exports and explicitly indirect exports.
const ZoneList<const ModuleEntry*>& special_exports() const {
const ZoneList<const Entry*>& special_exports() const {
return special_exports_;
}
// All the remaining exports, indexed by local name.
const ZoneMultimap<const AstRawString*, ModuleEntry*>& regular_exports()
const {
const ZoneMultimap<const AstRawString*, Entry*>& regular_exports() const {
return regular_exports_;
}
private:
// TODO(neis): Use STL datastructure instead of ZoneList?
ZoneList<const ModuleEntry*> special_exports_;
ZoneList<const ModuleEntry*> special_imports_;
ZoneMultimap<const AstRawString*, ModuleEntry*> regular_exports_;
ZoneMap<const AstRawString*, const ModuleEntry*> regular_imports_;
ZoneList<const Entry*> special_exports_;
ZoneList<const Entry*> special_imports_;
ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
ZoneMap<const AstRawString*, const Entry*> regular_imports_;
// If there are multiple export entries with the same export name, return one
// of them. Otherwise return nullptr.
const ModuleEntry* FindDuplicateExport(Zone* zone) const;
const Entry* FindDuplicateExport(Zone* zone) const;
// Find any implicitly indirect exports and make them explicit.
//
......
......@@ -5845,9 +5845,9 @@ TEST(EnumReserved) {
RunModuleParserSyncTest(context_data, kErrorSources, kError);
}
static void CheckModuleEntry(const i::ModuleDescriptor::ModuleEntry* entry,
const char* export_name, const char* local_name, const char* import_name,
const char* module_request) {
static void CheckEntry(const i::ModuleDescriptor::Entry* entry,
const char* export_name, const char* local_name,
const char* import_name, const char* module_request) {
CHECK_NOT_NULL(entry);
if (export_name == nullptr) {
CHECK_NULL(entry->export_name);
......@@ -5914,7 +5914,7 @@ TEST(ModuleParsingInternals) {
CHECK(outer_scope->is_script_scope());
CHECK_NULL(outer_scope->outer_scope());
CHECK(module_scope->is_module_scope());
const i::ModuleDescriptor::ModuleEntry* entry;
const i::ModuleDescriptor::Entry* entry;
i::ZoneList<i::Declaration*>* declarations = module_scope->declarations();
CHECK_EQ(13, declarations->length());
......@@ -6001,74 +6001,73 @@ TEST(ModuleParsingInternals) {
CHECK_NOT_NULL(descriptor);
CHECK_EQ(3, descriptor->special_exports().length());
CheckModuleEntry(descriptor->special_exports().at(0), "b", nullptr, "a",
"m.js");
CheckModuleEntry(descriptor->special_exports().at(1), nullptr, nullptr,
nullptr, "p.js");
CheckModuleEntry(descriptor->special_exports().at(2), "bb", nullptr, "aa",
"m.js"); // !!!
CheckEntry(descriptor->special_exports().at(0), "b", nullptr, "a", "m.js");
CheckEntry(descriptor->special_exports().at(1), nullptr, nullptr, nullptr,
"p.js");
CheckEntry(descriptor->special_exports().at(2), "bb", nullptr, "aa",
"m.js"); // !!!
CHECK_EQ(8, descriptor->regular_exports().size());
entry = descriptor->regular_exports()
.find(declarations->at(3)->proxy()->raw_name())
->second;
CheckModuleEntry(entry, "foo", "foo", nullptr, nullptr);
CheckEntry(entry, "foo", "foo", nullptr, nullptr);
entry = descriptor->regular_exports()
.find(declarations->at(4)->proxy()->raw_name())
->second;
CheckModuleEntry(entry, "goo", "goo", nullptr, nullptr);
CheckEntry(entry, "goo", "goo", nullptr, nullptr);
entry = descriptor->regular_exports()
.find(declarations->at(5)->proxy()->raw_name())
->second;
CheckModuleEntry(entry, "hoo", "hoo", nullptr, nullptr);
CheckEntry(entry, "hoo", "hoo", nullptr, nullptr);
entry = descriptor->regular_exports()
.find(declarations->at(6)->proxy()->raw_name())
->second;
CheckModuleEntry(entry, "joo", "joo", nullptr, nullptr);
CheckEntry(entry, "joo", "joo", nullptr, nullptr);
entry = descriptor->regular_exports()
.find(declarations->at(7)->proxy()->raw_name())
->second;
CheckModuleEntry(entry, "default", "*default*", nullptr, nullptr);
CheckEntry(entry, "default", "*default*", nullptr, nullptr);
entry = descriptor->regular_exports()
.find(declarations->at(12)->proxy()->raw_name())
->second;
CheckModuleEntry(entry, "foob", "foob", nullptr, nullptr);
CheckEntry(entry, "foob", "foob", nullptr, nullptr);
// TODO(neis): The next lines are terrible. Find a better way.
auto name_x = declarations->at(0)->proxy()->raw_name();
CHECK_EQ(2, descriptor->regular_exports().count(name_x));
auto it = descriptor->regular_exports().equal_range(name_x).first;
entry = it->second;
if (entry->export_name->IsOneByteEqualTo("y")) {
CheckModuleEntry(entry, "y", "x", nullptr, nullptr);
CheckEntry(entry, "y", "x", nullptr, nullptr);
entry = (++it)->second;
CheckModuleEntry(entry, "x", "x", nullptr, nullptr);
CheckEntry(entry, "x", "x", nullptr, nullptr);
} else {
CheckModuleEntry(entry, "x", "x", nullptr, nullptr);
CheckEntry(entry, "x", "x", nullptr, nullptr);
entry = (++it)->second;
CheckModuleEntry(entry, "y", "x", nullptr, nullptr);
CheckEntry(entry, "y", "x", nullptr, nullptr);
}
CHECK_EQ(3, descriptor->special_imports().length());
CheckModuleEntry(
descriptor->special_imports().at(0), nullptr, nullptr, nullptr, "q.js");
CheckModuleEntry(
descriptor->special_imports().at(1), nullptr, "loo", nullptr, "bar.js");
CheckModuleEntry(
descriptor->special_imports().at(2), nullptr, "foob", nullptr, "bar.js");
CheckEntry(descriptor->special_imports().at(0), nullptr, nullptr, nullptr,
"q.js");
CheckEntry(descriptor->special_imports().at(1), nullptr, "loo", nullptr,
"bar.js");
CheckEntry(descriptor->special_imports().at(2), nullptr, "foob", nullptr,
"bar.js");
CHECK_EQ(4, descriptor->regular_imports().size());
entry = descriptor->regular_imports().find(
declarations->at(1)->proxy()->raw_name())->second;
CheckModuleEntry(entry, nullptr, "z", "q", "m.js");
CheckEntry(entry, nullptr, "z", "q", "m.js");
entry = descriptor->regular_imports().find(
declarations->at(2)->proxy()->raw_name())->second;
CheckModuleEntry(entry, nullptr, "n", "default", "n.js");
CheckEntry(entry, nullptr, "n", "default", "n.js");
entry = descriptor->regular_imports().find(
declarations->at(9)->proxy()->raw_name())->second;
CheckModuleEntry(entry, nullptr, "mm", "m", "m.js");
CheckEntry(entry, nullptr, "mm", "m", "m.js");
entry = descriptor->regular_imports().find(
declarations->at(10)->proxy()->raw_name())->second;
CheckModuleEntry(entry, nullptr, "aa", "aa", "m.js");
CheckEntry(entry, nullptr, "aa", "aa", "m.js");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment