Skip to content

Commit febdba9

Browse files
committed
[clang] NFC: Move class to make it reusable
This is a prep patch for D111560.
1 parent 819fb84 commit febdba9

File tree

1 file changed

+48
-46
lines changed

1 file changed

+48
-46
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,54 @@ void CompilerInstance::createASTContext() {
560560

561561
// ExternalASTSource
562562

563+
namespace {
564+
// Helper to recursively read the module names for all modules we're adding.
565+
// We mark these as known and redirect any attempt to load that module to
566+
// the files we were handed.
567+
struct ReadModuleNames : ASTReaderListener {
568+
CompilerInstance &CI;
569+
llvm::SmallVector<IdentifierInfo*, 8> LoadedModules;
570+
571+
ReadModuleNames(CompilerInstance &CI) : CI(CI) {}
572+
573+
void ReadModuleName(StringRef ModuleName) override {
574+
LoadedModules.push_back(
575+
CI.getPreprocessor().getIdentifierInfo(ModuleName));
576+
}
577+
578+
void registerAll() {
579+
ModuleMap &MM = CI.getPreprocessor().getHeaderSearchInfo().getModuleMap();
580+
for (auto *II : LoadedModules)
581+
MM.cacheModuleLoad(*II, MM.findModule(II->getName()));
582+
LoadedModules.clear();
583+
}
584+
585+
void markAllUnavailable() {
586+
for (auto *II : LoadedModules) {
587+
if (Module *M = CI.getPreprocessor()
588+
.getHeaderSearchInfo()
589+
.getModuleMap()
590+
.findModule(II->getName())) {
591+
M->HasIncompatibleModuleFile = true;
592+
593+
// Mark module as available if the only reason it was unavailable
594+
// was missing headers.
595+
SmallVector<Module *, 2> Stack;
596+
Stack.push_back(M);
597+
while (!Stack.empty()) {
598+
Module *Current = Stack.pop_back_val();
599+
if (Current->IsUnimportable) continue;
600+
Current->IsAvailable = true;
601+
Stack.insert(Stack.end(),
602+
Current->submodule_begin(), Current->submodule_end());
603+
}
604+
}
605+
}
606+
LoadedModules.clear();
607+
}
608+
};
609+
} // namespace
610+
563611
void CompilerInstance::createPCHExternalASTSource(
564612
StringRef Path, DisableValidationForModuleKind DisableValidation,
565613
bool AllowPCHWithCompilerErrors, void *DeserializationListener,
@@ -1647,52 +1695,6 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
16471695
*FrontendTimerGroup);
16481696
llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr);
16491697

1650-
// Helper to recursively read the module names for all modules we're adding.
1651-
// We mark these as known and redirect any attempt to load that module to
1652-
// the files we were handed.
1653-
struct ReadModuleNames : ASTReaderListener {
1654-
CompilerInstance &CI;
1655-
llvm::SmallVector<IdentifierInfo*, 8> LoadedModules;
1656-
1657-
ReadModuleNames(CompilerInstance &CI) : CI(CI) {}
1658-
1659-
void ReadModuleName(StringRef ModuleName) override {
1660-
LoadedModules.push_back(
1661-
CI.getPreprocessor().getIdentifierInfo(ModuleName));
1662-
}
1663-
1664-
void registerAll() {
1665-
ModuleMap &MM = CI.getPreprocessor().getHeaderSearchInfo().getModuleMap();
1666-
for (auto *II : LoadedModules)
1667-
MM.cacheModuleLoad(*II, MM.findModule(II->getName()));
1668-
LoadedModules.clear();
1669-
}
1670-
1671-
void markAllUnavailable() {
1672-
for (auto *II : LoadedModules) {
1673-
if (Module *M = CI.getPreprocessor()
1674-
.getHeaderSearchInfo()
1675-
.getModuleMap()
1676-
.findModule(II->getName())) {
1677-
M->HasIncompatibleModuleFile = true;
1678-
1679-
// Mark module as available if the only reason it was unavailable
1680-
// was missing headers.
1681-
SmallVector<Module *, 2> Stack;
1682-
Stack.push_back(M);
1683-
while (!Stack.empty()) {
1684-
Module *Current = Stack.pop_back_val();
1685-
if (Current->IsUnimportable) continue;
1686-
Current->IsAvailable = true;
1687-
Stack.insert(Stack.end(),
1688-
Current->submodule_begin(), Current->submodule_end());
1689-
}
1690-
}
1691-
}
1692-
LoadedModules.clear();
1693-
}
1694-
};
1695-
16961698
// If we don't already have an ASTReader, create one now.
16971699
if (!TheASTReader)
16981700
createASTReader();

0 commit comments

Comments
 (0)