[IDE] Make sure we don't print duplicate imports, due to getting imports for both a clang module and its overlay.

rdar://16608500

Swift SVN r23730
This commit is contained in:
Argyrios Kyrtzidis
2014-12-05 06:01:06 +00:00
parent 9d6e7cddc8
commit c1984e15e7
2 changed files with 31 additions and 1 deletions

View File

@@ -95,6 +95,18 @@ private:
};
} // unnamed namespace
static const clang::Module *
getUnderlyingClangModuleForImport(ImportDecl *Import) {
if (auto *ClangMod = Import->getClangModule())
return ClangMod;
if (auto Mod = Import->getModule())
if (auto *ClangMod = Mod->findUnderlyingClangModule())
return ClangMod;
return nullptr;
}
void swift::ide::printModuleInterface(Module *M,
ModuleTraversalOptions TraversalOptions,
ASTPrinter &Printer,
@@ -131,6 +143,7 @@ void swift::ide::printSubmoduleInterface(
const clang::Module *InterestingClangModule = nullptr;
SmallVector<ImportDecl *, 1> ImportDecls;
llvm::DenseSet<const clang::Module *> ClangModulesForImports;
SmallVector<Decl *, 1> SwiftDecls;
llvm::DenseMap<const clang::Module *,
SmallVector<std::pair<Decl *, clang::SourceLocation>, 1>>
@@ -210,8 +223,19 @@ void swift::ide::printSubmoduleInterface(
};
if (auto ID = dyn_cast<ImportDecl>(D)) {
if (ShouldPrintImport(ID))
if (ShouldPrintImport(ID)) {
if (ID->getImportKind() == ImportKind::Module) {
// Make sure we don't print duplicate imports, due to getting imports
// for both a clang module and its overlay.
if (auto *ClangMod = getUnderlyingClangModuleForImport(ID)) {
auto P = ClangModulesForImports.insert(ClangMod);
bool IsNew = P.second;
if (!IsNew)
continue;
}
}
ImportDecls.push_back(ID);
}
continue;
}