[ModuleInterface] Print imports (including '@_exported')

Part of preserving enough information to reconstitute a textual
interface back to a binary module.
This commit is contained in:
Jordan Rose
2018-09-06 11:43:51 -07:00
parent 737a405596
commit f6ee9f6dc9
14 changed files with 150 additions and 38 deletions

View File

@@ -1005,6 +1005,33 @@ bool ModuleDecl::isSameAccessPath(AccessPathTy lhs, AccessPathTy rhs) {
});
}
void
ModuleDecl::removeDuplicateImports(SmallVectorImpl<ImportedModule> &imports) {
std::sort(imports.begin(), imports.end(),
[](const ImportedModule &lhs, const ImportedModule &rhs) -> bool {
// Arbitrarily sort by name to get a deterministic order.
// FIXME: Submodules don't get sorted properly here.
if (lhs.second != rhs.second)
return lhs.second->getName().str() < rhs.second->getName().str();
using AccessPathElem = std::pair<Identifier, SourceLoc>;
return std::lexicographical_compare(lhs.first.begin(), lhs.first.end(),
rhs.first.begin(), rhs.first.end(),
[](const AccessPathElem &lElem,
const AccessPathElem &rElem) {
return lElem.first.str() < rElem.first.str();
});
});
auto last = std::unique(imports.begin(), imports.end(),
[](const ImportedModule &lhs,
const ImportedModule &rhs) -> bool {
if (lhs.second != rhs.second)
return false;
return ModuleDecl::isSameAccessPath(lhs.first, rhs.first);
});
imports.erase(last, imports.end());
}
StringRef ModuleDecl::getModuleFilename() const {
// FIXME: Audit uses of this function and figure out how to migrate them to
// per-file names. Modules can consist of more than one file.