forked from OSchip/llvm-project
clang/Modules: Rename CompilerInstance::ModuleManager, NFC
Fix the confusing naming of `CompilerInstance::ModuleManager`. This is actually an instance of `ASTReader`, which contains an instance of `ModuleManager`. I have to assume there was a point in the past where they were just one class, but it's been pretty confusing for a while. I think it's time to fix it. The new name is `TheASTReader`; the annoying `The` prefix is so that we don't shadow the `ASTReader` class. I tried out `ASTRdr` but that seemed less clear, and this choice matches `ThePCHContainerOperations` just a couple of declarations below. Also rename `CompilerInstance::getModuleManager` and `CompilerInstance::createModuleManager` to `*ASTReader`, making some cases of `getModuleManager().getModuleManager()` a little more clear. https://reviews.llvm.org/D70583
This commit is contained in:
parent
5cca622310
commit
20d51b2f14
|
@ -106,7 +106,7 @@ void ExpandModularHeadersPPCallbacks::handleModuleFile(
|
|||
|
||||
// Visit all the input files of this module and mark them to record their
|
||||
// contents later.
|
||||
Compiler.getModuleManager()->visitInputFiles(
|
||||
Compiler.getASTReader()->visitInputFiles(
|
||||
*MF, true, false,
|
||||
[this](const serialization::InputFile &IF, bool /*IsSystem*/) {
|
||||
Recorder->addNecessaryFile(IF.getFile());
|
||||
|
@ -153,7 +153,7 @@ void ExpandModularHeadersPPCallbacks::InclusionDirective(
|
|||
const Module *Imported, SrcMgr::CharacteristicKind FileType) {
|
||||
if (Imported) {
|
||||
serialization::ModuleFile *MF =
|
||||
Compiler.getModuleManager()->getModuleManager().lookup(
|
||||
Compiler.getASTReader()->getModuleManager().lookup(
|
||||
Imported->getASTFile());
|
||||
handleModuleFile(MF);
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ class CompilerInstance : public ModuleLoader {
|
|||
std::unique_ptr<llvm::Timer> FrontendTimer;
|
||||
|
||||
/// The ASTReader, if one exists.
|
||||
IntrusiveRefCntPtr<ASTReader> ModuleManager;
|
||||
IntrusiveRefCntPtr<ASTReader> TheASTReader;
|
||||
|
||||
/// The module dependency collector for crashdumps
|
||||
std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
|
||||
|
@ -514,7 +514,7 @@ public:
|
|||
/// @name Module Management
|
||||
/// {
|
||||
|
||||
IntrusiveRefCntPtr<ASTReader> getModuleManager() const;
|
||||
IntrusiveRefCntPtr<ASTReader> getASTReader() const;
|
||||
void setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader);
|
||||
|
||||
std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const;
|
||||
|
@ -782,7 +782,7 @@ public:
|
|||
}
|
||||
|
||||
// Create module manager.
|
||||
void createModuleManager();
|
||||
void createASTReader();
|
||||
|
||||
bool loadModuleFile(StringRef FileName);
|
||||
|
||||
|
|
|
@ -1457,7 +1457,7 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
|
|||
CI.setFileManager(nullptr);
|
||||
if (CI.hasTarget())
|
||||
Target = &CI.getTarget();
|
||||
Reader = CI.getModuleManager();
|
||||
Reader = CI.getASTReader();
|
||||
HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure();
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ void CompilerInstance::setInvocation(
|
|||
|
||||
bool CompilerInstance::shouldBuildGlobalModuleIndex() const {
|
||||
return (BuildGlobalModuleIndex ||
|
||||
(ModuleManager && ModuleManager->isGlobalIndexUnavailable() &&
|
||||
(TheASTReader && TheASTReader->isGlobalIndexUnavailable() &&
|
||||
getFrontendOpts().GenerateGlobalModuleIndex)) &&
|
||||
!ModuleBuildFailed;
|
||||
}
|
||||
|
@ -135,13 +135,13 @@ std::unique_ptr<Sema> CompilerInstance::takeSema() {
|
|||
return std::move(TheSema);
|
||||
}
|
||||
|
||||
IntrusiveRefCntPtr<ASTReader> CompilerInstance::getModuleManager() const {
|
||||
return ModuleManager;
|
||||
IntrusiveRefCntPtr<ASTReader> CompilerInstance::getASTReader() const {
|
||||
return TheASTReader;
|
||||
}
|
||||
void CompilerInstance::setModuleManager(IntrusiveRefCntPtr<ASTReader> Reader) {
|
||||
assert(ModuleCache.get() == &Reader->getModuleManager().getModuleCache() &&
|
||||
"Expected ASTReader to use the same PCM cache");
|
||||
ModuleManager = std::move(Reader);
|
||||
TheASTReader = std::move(Reader);
|
||||
}
|
||||
|
||||
std::shared_ptr<ModuleDependencyCollector>
|
||||
|
@ -380,7 +380,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
|
|||
const PreprocessorOptions &PPOpts = getPreprocessorOpts();
|
||||
|
||||
// The module manager holds a reference to the old preprocessor (if any).
|
||||
ModuleManager.reset();
|
||||
TheASTReader.reset();
|
||||
|
||||
// Create the Preprocessor.
|
||||
HeaderSearch *HeaderInfo =
|
||||
|
@ -494,7 +494,7 @@ void CompilerInstance::createPCHExternalASTSource(
|
|||
StringRef Path, bool DisablePCHValidation, bool AllowPCHWithCompilerErrors,
|
||||
void *DeserializationListener, bool OwnDeserializationListener) {
|
||||
bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
|
||||
ModuleManager = createPCHExternalASTSource(
|
||||
TheASTReader = createPCHExternalASTSource(
|
||||
Path, getHeaderSearchOpts().Sysroot, DisablePCHValidation,
|
||||
AllowPCHWithCompilerErrors, getPreprocessor(), getModuleCache(),
|
||||
getASTContext(), getPCHContainerReader(),
|
||||
|
@ -1313,7 +1313,7 @@ static bool compileModuleAndReadAST(CompilerInstance &ImportingInstance,
|
|||
|
||||
// Try to read the module file, now that we've compiled it.
|
||||
ASTReader::ASTReadResult ReadResult =
|
||||
ImportingInstance.getModuleManager()->ReadAST(
|
||||
ImportingInstance.getASTReader()->ReadAST(
|
||||
ModuleFileName, serialization::MK_ImplicitModule, ImportLoc,
|
||||
ModuleLoadCapabilities);
|
||||
|
||||
|
@ -1477,8 +1477,8 @@ static void pruneModuleCache(const HeaderSearchOptions &HSOpts) {
|
|||
}
|
||||
}
|
||||
|
||||
void CompilerInstance::createModuleManager() {
|
||||
if (ModuleManager)
|
||||
void CompilerInstance::createASTReader() {
|
||||
if (TheASTReader)
|
||||
return;
|
||||
|
||||
if (!hasASTContext())
|
||||
|
@ -1501,29 +1501,28 @@ void CompilerInstance::createModuleManager() {
|
|||
ReadTimer = std::make_unique<llvm::Timer>("reading_modules",
|
||||
"Reading modules",
|
||||
*FrontendTimerGroup);
|
||||
ModuleManager = new ASTReader(
|
||||
TheASTReader = new ASTReader(
|
||||
getPreprocessor(), getModuleCache(), &getASTContext(),
|
||||
getPCHContainerReader(), getFrontendOpts().ModuleFileExtensions,
|
||||
Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation,
|
||||
/*AllowASTWithCompilerErrors=*/false,
|
||||
/*AllowConfigurationMismatch=*/false,
|
||||
HSOpts.ModulesValidateSystemHeaders,
|
||||
/*AllowConfigurationMismatch=*/false, HSOpts.ModulesValidateSystemHeaders,
|
||||
HSOpts.ValidateASTInputFilesContent,
|
||||
getFrontendOpts().UseGlobalModuleIndex, std::move(ReadTimer));
|
||||
if (hasASTConsumer()) {
|
||||
ModuleManager->setDeserializationListener(
|
||||
getASTConsumer().GetASTDeserializationListener());
|
||||
TheASTReader->setDeserializationListener(
|
||||
getASTConsumer().GetASTDeserializationListener());
|
||||
getASTContext().setASTMutationListener(
|
||||
getASTConsumer().GetASTMutationListener());
|
||||
}
|
||||
getASTContext().setExternalSource(ModuleManager);
|
||||
getASTContext().setExternalSource(TheASTReader);
|
||||
if (hasSema())
|
||||
ModuleManager->InitializeSema(getSema());
|
||||
TheASTReader->InitializeSema(getSema());
|
||||
if (hasASTConsumer())
|
||||
ModuleManager->StartTranslationUnit(&getASTConsumer());
|
||||
TheASTReader->StartTranslationUnit(&getASTConsumer());
|
||||
|
||||
for (auto &Listener : DependencyCollectors)
|
||||
Listener->attachToASTReader(*ModuleManager);
|
||||
Listener->attachToASTReader(*TheASTReader);
|
||||
}
|
||||
|
||||
bool CompilerInstance::loadModuleFile(StringRef FileName) {
|
||||
|
@ -1580,8 +1579,8 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
|
|||
};
|
||||
|
||||
// If we don't already have an ASTReader, create one now.
|
||||
if (!ModuleManager)
|
||||
createModuleManager();
|
||||
if (!TheASTReader)
|
||||
createASTReader();
|
||||
|
||||
// If -Wmodule-file-config-mismatch is mapped as an error or worse, allow the
|
||||
// ASTReader to diagnose it, since it can produce better errors that we can.
|
||||
|
@ -1592,11 +1591,11 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
|
|||
|
||||
auto Listener = std::make_unique<ReadModuleNames>(*this);
|
||||
auto &ListenerRef = *Listener;
|
||||
ASTReader::ListenerScope ReadModuleNamesListener(*ModuleManager,
|
||||
ASTReader::ListenerScope ReadModuleNamesListener(*TheASTReader,
|
||||
std::move(Listener));
|
||||
|
||||
// Try to load the module file.
|
||||
switch (ModuleManager->ReadAST(
|
||||
switch (TheASTReader->ReadAST(
|
||||
FileName, serialization::MK_ExplicitModule, SourceLocation(),
|
||||
ConfigMismatchIsRecoverable ? ASTReader::ARR_ConfigurationMismatch : 0)) {
|
||||
case ASTReader::Success:
|
||||
|
@ -1696,8 +1695,8 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
|
|||
}
|
||||
|
||||
// Create an ASTReader on demand.
|
||||
if (!getModuleManager())
|
||||
createModuleManager();
|
||||
if (!getASTReader())
|
||||
createASTReader();
|
||||
|
||||
// Time how long it takes to load the module.
|
||||
llvm::Timer Timer;
|
||||
|
@ -1714,13 +1713,13 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST(
|
|||
: Source == MS_PrebuiltModulePath
|
||||
? 0
|
||||
: ASTReader::ARR_ConfigurationMismatch;
|
||||
switch (getModuleManager()->ReadAST(
|
||||
ModuleFilename,
|
||||
Source == MS_PrebuiltModulePath
|
||||
? serialization::MK_PrebuiltModule
|
||||
: Source == MS_ModuleBuildPragma ? serialization::MK_ExplicitModule
|
||||
: serialization::MK_ImplicitModule,
|
||||
ImportLoc, ARRFlags)) {
|
||||
switch (getASTReader()->ReadAST(ModuleFilename,
|
||||
Source == MS_PrebuiltModulePath
|
||||
? serialization::MK_PrebuiltModule
|
||||
: Source == MS_ModuleBuildPragma
|
||||
? serialization::MK_ExplicitModule
|
||||
: serialization::MK_ImplicitModule,
|
||||
ImportLoc, ARRFlags)) {
|
||||
case ASTReader::Success: {
|
||||
if (M)
|
||||
return M;
|
||||
|
@ -1848,8 +1847,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
|
|||
if (ImportLoc.isValid() && LastModuleImportLoc == ImportLoc) {
|
||||
// Make the named module visible.
|
||||
if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule)
|
||||
ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility,
|
||||
ImportLoc);
|
||||
TheASTReader->makeModuleVisible(LastModuleImportResult, Visibility,
|
||||
ImportLoc);
|
||||
return LastModuleImportResult;
|
||||
}
|
||||
|
||||
|
@ -2008,7 +2007,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
|
|||
return ModuleLoadResult();
|
||||
}
|
||||
|
||||
ModuleManager->makeModuleVisible(Module, Visibility, ImportLoc);
|
||||
TheASTReader->makeModuleVisible(Module, Visibility, ImportLoc);
|
||||
}
|
||||
|
||||
// Check for any configuration macros that have changed.
|
||||
|
@ -2085,27 +2084,27 @@ void CompilerInstance::createModuleFromSource(SourceLocation ImportLoc,
|
|||
void CompilerInstance::makeModuleVisible(Module *Mod,
|
||||
Module::NameVisibilityKind Visibility,
|
||||
SourceLocation ImportLoc) {
|
||||
if (!ModuleManager)
|
||||
createModuleManager();
|
||||
if (!ModuleManager)
|
||||
if (!TheASTReader)
|
||||
createASTReader();
|
||||
if (!TheASTReader)
|
||||
return;
|
||||
|
||||
ModuleManager->makeModuleVisible(Mod, Visibility, ImportLoc);
|
||||
TheASTReader->makeModuleVisible(Mod, Visibility, ImportLoc);
|
||||
}
|
||||
|
||||
GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
|
||||
SourceLocation TriggerLoc) {
|
||||
if (getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty())
|
||||
return nullptr;
|
||||
if (!ModuleManager)
|
||||
createModuleManager();
|
||||
if (!TheASTReader)
|
||||
createASTReader();
|
||||
// Can't do anything if we don't have the module manager.
|
||||
if (!ModuleManager)
|
||||
if (!TheASTReader)
|
||||
return nullptr;
|
||||
// Get an existing global index. This loads it if not already
|
||||
// loaded.
|
||||
ModuleManager->loadGlobalIndex();
|
||||
GlobalModuleIndex *GlobalIndex = ModuleManager->getGlobalIndex();
|
||||
TheASTReader->loadGlobalIndex();
|
||||
GlobalModuleIndex *GlobalIndex = TheASTReader->getGlobalIndex();
|
||||
// If the global index doesn't exist, create it.
|
||||
if (!GlobalIndex && shouldBuildGlobalModuleIndex() && hasFileManager() &&
|
||||
hasPreprocessor()) {
|
||||
|
@ -2121,9 +2120,9 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
|
|||
consumeError(std::move(Err));
|
||||
return nullptr;
|
||||
}
|
||||
ModuleManager->resetForReload();
|
||||
ModuleManager->loadGlobalIndex();
|
||||
GlobalIndex = ModuleManager->getGlobalIndex();
|
||||
TheASTReader->resetForReload();
|
||||
TheASTReader->loadGlobalIndex();
|
||||
GlobalIndex = TheASTReader->getGlobalIndex();
|
||||
}
|
||||
// For finding modules needing to be imported for fixit messages,
|
||||
// we need to make the global index cover all modules, so we do that here.
|
||||
|
@ -2152,9 +2151,9 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
|
|||
consumeError(std::move(Err));
|
||||
return nullptr;
|
||||
}
|
||||
ModuleManager->resetForReload();
|
||||
ModuleManager->loadGlobalIndex();
|
||||
GlobalIndex = ModuleManager->getGlobalIndex();
|
||||
TheASTReader->resetForReload();
|
||||
TheASTReader->loadGlobalIndex();
|
||||
GlobalIndex = TheASTReader->getGlobalIndex();
|
||||
}
|
||||
HaveFullGlobalModuleIndex = true;
|
||||
}
|
||||
|
|
|
@ -871,9 +871,9 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
|
|||
// extended by an external source.
|
||||
if (CI.getLangOpts().Modules || !CI.hasASTContext() ||
|
||||
!CI.getASTContext().getExternalSource()) {
|
||||
CI.createModuleManager();
|
||||
CI.getModuleManager()->setDeserializationListener(DeserialListener,
|
||||
DeleteDeserialListener);
|
||||
CI.createASTReader();
|
||||
CI.getASTReader()->setDeserializationListener(DeserialListener,
|
||||
DeleteDeserialListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -892,7 +892,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
|
|||
} else {
|
||||
// FIXME: If this is a problem, recover from it by creating a multiplex
|
||||
// source.
|
||||
assert((!CI.getLangOpts().Modules || CI.getModuleManager()) &&
|
||||
assert((!CI.getLangOpts().Modules || CI.getASTReader()) &&
|
||||
"modules enabled but created an external source that "
|
||||
"doesn't support modules");
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@ public:
|
|||
return;
|
||||
|
||||
serialization::ModuleFile *MF =
|
||||
CI.getModuleManager()->getModuleManager().lookup(*File);
|
||||
CI.getASTReader()->getModuleManager().lookup(*File);
|
||||
assert(MF && "missing module file for loaded module?");
|
||||
|
||||
// Not interested in PCH / preambles.
|
||||
|
@ -293,8 +293,8 @@ bool RewriteIncludesAction::BeginSourceFileAction(CompilerInstance &CI) {
|
|||
// If we're rewriting imports, set up a listener to track when we import
|
||||
// module files.
|
||||
if (CI.getPreprocessorOutputOpts().RewriteImports) {
|
||||
CI.createModuleManager();
|
||||
CI.getModuleManager()->addListener(
|
||||
CI.createASTReader();
|
||||
CI.getASTReader()->addListener(
|
||||
std::make_unique<RewriteImportsListener>(CI, OutputStream));
|
||||
}
|
||||
|
||||
|
|
|
@ -97,9 +97,8 @@ void ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
|
|||
MD.ModulePCMPath = M->getASTFile()->getName();
|
||||
MD.ContextHash = MDC.ContextHash;
|
||||
serialization::ModuleFile *MF =
|
||||
MDC.Instance.getModuleManager()->getModuleManager().lookup(
|
||||
M->getASTFile());
|
||||
MDC.Instance.getModuleManager()->visitInputFiles(
|
||||
MDC.Instance.getASTReader()->getModuleManager().lookup(M->getASTFile());
|
||||
MDC.Instance.getASTReader()->visitInputFiles(
|
||||
*MF, true, true, [&](const serialization::InputFile &IF, bool isSystem) {
|
||||
MD.FileDeps.insert(IF.getFile()->getName());
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue