Skip to content

Commit 07b84fc

Browse files
committed
AST: Introduce ModuleDecl::isClangHeaderImportModule() convenience.
1 parent a2d9808 commit 07b84fc

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

include/swift/AST/ClangModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ClangModuleLoader : public ModuleLoader {
147147
virtual void dumpSwiftLookupTables() const = 0;
148148

149149
/// Returns the module that contains imports and declarations from all loaded
150-
/// Objective-C header files.
150+
/// header files.
151151
virtual ModuleDecl *getImportedHeaderModule() const = 0;
152152

153153
/// Retrieves the Swift wrapper for the given Clang module, creating

include/swift/AST/Module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ class ModuleDecl
614614
void findDeclaredCrossImportOverlaysTransitive(
615615
SmallVectorImpl<ModuleDecl *> &overlays);
616616

617+
/// Returns true if this module is the Clang header import module.
618+
bool isClangHeaderImportModule() const;
619+
617620
/// Convenience accessor for clients that know what kind of file they're
618621
/// dealing with.
619622
SourceFile &getMainSourceFile() const;

lib/AST/Module.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,14 @@ bool ModuleDecl::getRequiredBystandersIfCrossImportOverlay(
24712471
return false;
24722472
}
24732473

2474+
bool ModuleDecl::isClangHeaderImportModule() const {
2475+
auto importer = getASTContext().getClangModuleLoader();
2476+
if (!importer)
2477+
return false;
2478+
2479+
return this == importer->getImportedHeaderModule();
2480+
}
2481+
24742482
namespace {
24752483
struct OverlayFileContents {
24762484
struct Module {

lib/PrintAsClang/PrintAsClang.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
404404
if (bridgingHeader.empty())
405405
return import != &M && import->getName() == M.getName();
406406

407-
auto importer = static_cast<ClangImporter *>(
408-
import->getASTContext().getClangModuleLoader());
409-
return import == importer->getImportedHeaderModule();
407+
return import->isClangHeaderImportModule();
410408
};
411409

412410
clang::FileSystemOptions fileSystemOptions;

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,7 @@ IdentifierID Serializer::addContainingModuleRef(const DeclContext *DC,
744744
return CURRENT_MODULE_ID;
745745
if (M == this->M->getASTContext().TheBuiltinModule)
746746
return BUILTIN_MODULE_ID;
747-
748-
auto clangImporter =
749-
static_cast<ClangImporter *>(
750-
this->M->getASTContext().getClangModuleLoader());
751-
if (M == clangImporter->getImportedHeaderModule())
747+
if (M->isClangHeaderImportModule())
752748
return OBJC_HEADER_MODULE_ID;
753749

754750
auto exportedModuleName = file->getExportedModuleName();

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,6 @@ static void collectModuleDependencies(ModuleDecl *TopMod,
10431043
if (!TopMod)
10441044
return;
10451045

1046-
auto ClangModuleLoader = TopMod->getASTContext().getClangModuleLoader();
1047-
10481046
ModuleDecl::ImportFilter ImportFilter = {
10491047
ModuleDecl::ImportFilterKind::Exported,
10501048
ModuleDecl::ImportFilterKind::Default};
@@ -1061,8 +1059,7 @@ static void collectModuleDependencies(ModuleDecl *TopMod,
10611059
if (Mod->isSystemModule())
10621060
continue;
10631061
// FIXME: Setup dependencies on the included headers.
1064-
if (ClangModuleLoader &&
1065-
Mod == ClangModuleLoader->getImportedHeaderModule())
1062+
if (Mod->isClangHeaderImportModule())
10661063
continue;
10671064
bool NewVisit = Visited.insert(Mod).second;
10681065
if (!NewVisit)

0 commit comments

Comments
 (0)