mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -2654,15 +2654,6 @@ public:
|
||||
return import == importer->getImportedHeaderModule();
|
||||
}
|
||||
|
||||
static void getClangSubmoduleReversePath(SmallVectorImpl<StringRef> &path,
|
||||
const clang::Module *module) {
|
||||
// FIXME: This should be an API on clang::Module.
|
||||
do {
|
||||
path.push_back(module->Name);
|
||||
module = module->Parent;
|
||||
} while (module);
|
||||
}
|
||||
|
||||
static int compareImportModulesByName(const ImportModuleTy *left,
|
||||
const ImportModuleTy *right) {
|
||||
auto *leftSwiftModule = left->dyn_cast<ModuleDecl *>();
|
||||
@@ -2692,10 +2683,10 @@ public:
|
||||
assert(rightClangModule->isSubModule() &&
|
||||
"top-level modules should use a normal swift::ModuleDecl");
|
||||
|
||||
SmallVector<StringRef, 8> leftReversePath;
|
||||
SmallVector<StringRef, 8> rightReversePath;
|
||||
getClangSubmoduleReversePath(leftReversePath, leftClangModule);
|
||||
getClangSubmoduleReversePath(rightReversePath, rightClangModule);
|
||||
SmallVector<StringRef, 8> leftReversePath(
|
||||
ModuleDecl::ReverseFullNameIterator(leftClangModule), {});
|
||||
SmallVector<StringRef, 8> rightReversePath(
|
||||
ModuleDecl::ReverseFullNameIterator(rightClangModule), {});
|
||||
|
||||
assert(leftReversePath != rightReversePath &&
|
||||
"distinct Clang modules should not have the same full name");
|
||||
@@ -2734,11 +2725,7 @@ public:
|
||||
assert(clangModule->isSubModule() &&
|
||||
"top-level modules should use a normal swift::ModuleDecl");
|
||||
out << "@import ";
|
||||
SmallVector<StringRef, 8> submoduleNames;
|
||||
getClangSubmoduleReversePath(submoduleNames, clangModule);
|
||||
interleave(submoduleNames.rbegin(), submoduleNames.rend(),
|
||||
[&out](StringRef next) { out << next; },
|
||||
[&out] { out << "."; });
|
||||
ModuleDecl::ReverseFullNameIterator(clangModule).printForward(out);
|
||||
out << ";\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user