Skip to content

Commit 2d86f23

Browse files
Merge pull request #26682 from adrian-prantl/loadmodule
Move ClangImporter::loadModuleClang() into ClangImporter::Implementation
2 parents 2ae8420 + 787b6cb commit 2d86f23

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class ClangImporter final : public ClangModuleLoader {
108108
DependencyTracker *tracker,
109109
DWARFImporterDelegate *dwarfImporterDelegate);
110110

111-
ModuleDecl *loadModuleClang(SourceLoc importLoc,
112-
ArrayRef<std::pair<Identifier, SourceLoc>> path);
113111
public:
114112
/// Create a new Clang importer that can import a suitable Clang
115113
/// module into the given ASTContext.

lib/ClangImporter/ClangImporter.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,11 +1573,10 @@ bool ClangImporter::canImportModule(std::pair<Identifier, SourceLoc> moduleID) {
15731573
return clangModule->isAvailable(ctx.getLangOpts(), getTargetInfo(), r, mh, m);
15741574
}
15751575

1576-
ModuleDecl *ClangImporter::loadModuleClang(
1577-
SourceLoc importLoc,
1578-
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
1579-
auto &clangContext = Impl.getClangASTContext();
1580-
auto &clangHeaderSearch = Impl.getClangPreprocessor().getHeaderSearchInfo();
1576+
ModuleDecl *ClangImporter::Implementation::loadModuleClang(
1577+
SourceLoc importLoc, ArrayRef<std::pair<Identifier, SourceLoc>> path) {
1578+
auto &clangContext = getClangASTContext();
1579+
auto &clangHeaderSearch = getClangPreprocessor().getHeaderSearchInfo();
15811580

15821581
// Look up the top-level module first, to see if it exists at all.
15831582
clang::Module *clangModule = clangHeaderSearch.lookupModule(
@@ -1588,47 +1587,47 @@ ModuleDecl *ClangImporter::loadModuleClang(
15881587

15891588
// Convert the Swift import path over to a Clang import path.
15901589
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4>
1591-
clangPath;
1590+
clangPath;
15921591
for (auto component : path) {
1593-
clangPath.push_back({ &clangContext.Idents.get(component.first.str()),
1594-
Impl.exportSourceLoc(component.second) } );
1592+
clangPath.push_back({&clangContext.Idents.get(component.first.str()),
1593+
exportSourceLoc(component.second)});
15951594
}
15961595

1597-
auto &rawDiagClient = Impl.Instance->getDiagnosticClient();
1596+
auto &rawDiagClient = Instance->getDiagnosticClient();
15981597
auto &diagClient = static_cast<ClangDiagnosticConsumer &>(rawDiagClient);
15991598

16001599
auto loadModule = [&](clang::ModuleIdPath path,
16011600
bool makeVisible) -> clang::ModuleLoadResult {
16021601
clang::Module::NameVisibilityKind visibility =
1603-
makeVisible ? clang::Module::AllVisible : clang::Module::Hidden;
1602+
makeVisible ? clang::Module::AllVisible : clang::Module::Hidden;
16041603

1605-
auto importRAII = diagClient.handleImport(clangPath.front().first,
1606-
importLoc);
1604+
auto importRAII =
1605+
diagClient.handleImport(clangPath.front().first, importLoc);
16071606

16081607
std::string preservedIndexStorePathOption;
1609-
auto &clangFEOpts = Impl.Instance->getFrontendOpts();
1608+
auto &clangFEOpts = Instance->getFrontendOpts();
16101609
if (!clangFEOpts.IndexStorePath.empty()) {
16111610
StringRef moduleName = path[0].first->getName();
16121611
// Ignore the SwiftShims module for the index data.
1613-
if (moduleName == Impl.SwiftContext.SwiftShimsModuleName.str()) {
1612+
if (moduleName == SwiftContext.SwiftShimsModuleName.str()) {
16141613
preservedIndexStorePathOption = clangFEOpts.IndexStorePath;
16151614
clangFEOpts.IndexStorePath.clear();
16161615
}
16171616
}
16181617

1619-
clang::SourceLocation clangImportLoc = Impl.getNextIncludeLoc();
1618+
clang::SourceLocation clangImportLoc = getNextIncludeLoc();
16201619

16211620
clang::ModuleLoadResult result =
1622-
Impl.Instance->loadModule(clangImportLoc, path, visibility,
1623-
/*IsInclusionDirective=*/false);
1621+
Instance->loadModule(clangImportLoc, path, visibility,
1622+
/*IsInclusionDirective=*/false);
16241623

16251624
if (!preservedIndexStorePathOption.empty()) {
16261625
// Restore the -index-store-path option.
16271626
clangFEOpts.IndexStorePath = preservedIndexStorePathOption;
16281627
}
16291628

16301629
if (result && makeVisible)
1631-
Impl.getClangPreprocessor().makeModuleVisible(result, clangImportLoc);
1630+
getClangPreprocessor().makeModuleVisible(result, clangImportLoc);
16321631
return result;
16331632
};
16341633

@@ -1663,13 +1662,13 @@ ModuleDecl *ClangImporter::loadModuleClang(
16631662
if (!clangModule)
16641663
return nullptr;
16651664

1666-
return Impl.finishLoadingClangModule(clangModule, /*preferOverlay=*/false);
1665+
return finishLoadingClangModule(clangModule, /*preferOverlay=*/false);
16671666
}
16681667

16691668
ModuleDecl *ClangImporter::loadModule(
16701669
SourceLoc importLoc,
16711670
ArrayRef<std::pair<Identifier, SourceLoc>> path) {
1672-
ModuleDecl *MD = loadModuleClang(importLoc, path);
1671+
ModuleDecl *MD = Impl.loadModuleClang(importLoc, path);
16731672
if (!MD)
16741673
MD = Impl.loadModuleDWARF(importLoc, path);
16751674
return MD;

lib/ClangImporter/ImporterImpl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,11 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
614614
/// The list of Clang modules found in the debug info.
615615
llvm::DenseMap<Identifier, LoadedFile *> DWARFModuleUnits;
616616
public:
617-
/// "Import" a module from debug info. Because debug info types are read on
617+
/// Load a module using the clang::CompilerInstance.
618+
ModuleDecl *loadModuleClang(SourceLoc importLoc,
619+
ArrayRef<std::pair<Identifier, SourceLoc>> path);
620+
621+
/// "Load" a module from debug info. Because debug info types are read on
618622
/// demand, this doesn't really do any work.
619623
ModuleDecl *loadModuleDWARF(SourceLoc importLoc,
620624
ArrayRef<std::pair<Identifier, SourceLoc>> path);

0 commit comments

Comments
 (0)