Author: Jan Svoboda Date: 2021-10-13T18:09:52+02:00 New Revision: aae776a5341ccf90a2c0a4e2e952ae4ec5ffb422
URL: https://github.com/llvm/llvm-project/commit/aae776a5341ccf90a2c0a4e2e952ae4ec5ffb422 DIFF: https://github.com/llvm/llvm-project/commit/aae776a5341ccf90a2c0a4e2e952ae4ec5ffb422.diff LOG: [clang] NFC: Move class to make it reusable This is a prep patch for D111560. Added: Modified: clang/lib/Frontend/CompilerInstance.cpp Removed: ################################################################################ diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 3e0a0f312c55c..634b120284b66 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -559,6 +559,54 @@ void CompilerInstance::createASTContext() { // ExternalASTSource +namespace { +// Helper to recursively read the module names for all modules we're adding. +// We mark these as known and redirect any attempt to load that module to +// the files we were handed. +struct ReadModuleNames : ASTReaderListener { + CompilerInstance &CI; + llvm::SmallVector<IdentifierInfo*, 8> LoadedModules; + + ReadModuleNames(CompilerInstance &CI) : CI(CI) {} + + void ReadModuleName(StringRef ModuleName) override { + LoadedModules.push_back( + CI.getPreprocessor().getIdentifierInfo(ModuleName)); + } + + void registerAll() { + ModuleMap &MM = CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(); + for (auto *II : LoadedModules) + MM.cacheModuleLoad(*II, MM.findModule(II->getName())); + LoadedModules.clear(); + } + + void markAllUnavailable() { + for (auto *II : LoadedModules) { + if (Module *M = CI.getPreprocessor() + .getHeaderSearchInfo() + .getModuleMap() + .findModule(II->getName())) { + M->HasIncompatibleModuleFile = true; + + // Mark module as available if the only reason it was unavailable + // was missing headers. + SmallVector<Module *, 2> Stack; + Stack.push_back(M); + while (!Stack.empty()) { + Module *Current = Stack.pop_back_val(); + if (Current->IsUnimportable) continue; + Current->IsAvailable = true; + Stack.insert(Stack.end(), + Current->submodule_begin(), Current->submodule_end()); + } + } + } + LoadedModules.clear(); + } +}; +} // namespace + void CompilerInstance::createPCHExternalASTSource( StringRef Path, DisableValidationForModuleKind DisableValidation, bool AllowPCHWithCompilerErrors, void *DeserializationListener, @@ -1634,52 +1682,6 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) { *FrontendTimerGroup); llvm::TimeRegion TimeLoading(FrontendTimerGroup ? &Timer : nullptr); - // Helper to recursively read the module names for all modules we're adding. - // We mark these as known and redirect any attempt to load that module to - // the files we were handed. - struct ReadModuleNames : ASTReaderListener { - CompilerInstance &CI; - llvm::SmallVector<IdentifierInfo*, 8> LoadedModules; - - ReadModuleNames(CompilerInstance &CI) : CI(CI) {} - - void ReadModuleName(StringRef ModuleName) override { - LoadedModules.push_back( - CI.getPreprocessor().getIdentifierInfo(ModuleName)); - } - - void registerAll() { - ModuleMap &MM = CI.getPreprocessor().getHeaderSearchInfo().getModuleMap(); - for (auto *II : LoadedModules) - MM.cacheModuleLoad(*II, MM.findModule(II->getName())); - LoadedModules.clear(); - } - - void markAllUnavailable() { - for (auto *II : LoadedModules) { - if (Module *M = CI.getPreprocessor() - .getHeaderSearchInfo() - .getModuleMap() - .findModule(II->getName())) { - M->HasIncompatibleModuleFile = true; - - // Mark module as available if the only reason it was unavailable - // was missing headers. - SmallVector<Module *, 2> Stack; - Stack.push_back(M); - while (!Stack.empty()) { - Module *Current = Stack.pop_back_val(); - if (Current->IsUnimportable) continue; - Current->IsAvailable = true; - Stack.insert(Stack.end(), - Current->submodule_begin(), Current->submodule_end()); - } - } - } - LoadedModules.clear(); - } - }; - // If we don't already have an ASTReader, create one now. if (!TheASTReader) createASTReader(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits