Add ModuleDecl::ReverseFullNameIterator

Package up the logic that generates a full Clang module name, so that
(a) we don't have to deal with clang::Module in quite as many places
in the /Swift/ compiler, and (b) we can avoid the cost of a temporary
string in a few places.

The main places where this is /not/ adopted is where we don't just
want to know the parent module name, but actually the module itself.
This is mostly indexing-related queries, which use the very similar
ModuleEntity class also defined in Module.h. I didn't quite see an
obvious way to unify these, but that might be where we want to go.

No functionality change.
This commit is contained in:
Jordan Rose
2018-09-06 19:47:25 -07:00
parent d6133f408d
commit 37ec248823
7 changed files with 113 additions and 61 deletions

View File

@@ -416,21 +416,9 @@ static bool initDocEntityInfo(const Decl *D,
case DeclContextKind::FileUnit: {
if (auto *CD = D->getClangDecl()) {
if (auto *M = CD->getImportedOwningModule()) {
const clang::Module *Root = M->getTopLevelModule();
// If Root differs from the owning module, then the owning module is
// a sub-module.
if (M != Root) {
if (M->isSubModule()) {
llvm::raw_svector_ostream OS(Info.SubModuleName);
llvm::SmallVector<StringRef, 4> Names;
// Climb up and collect sub-module names.
for (auto Current = M; Current != Root; Current = Current->Parent) {
Names.insert(Names.begin(), Current->Name);
}
OS << Root->Name;
std::for_each(Names.begin(), Names.end(),
[&](StringRef N) { OS << "." << N; });
ModuleDecl::ReverseFullNameIterator(M).printForward(OS);
}
}
}