Go to the documentation of this file.
14 #include "llvm/Support/StringSaver.h"
16 using namespace clang;
17 using namespace tooling;
18 using namespace dependencies;
24 std::vector<HeaderSearchOptions::Entry> Entries = Opts.
UserEntries;
27 llvm::BitVector SearchPathUsage(Entries.size());
34 if (!Visited.contains(Import))
39 for (
auto Idx : SearchPathUsage.set_bits())
44 const ModuleDeps &Deps,
49 CI.getLangOpts()->resetNonModularOptions();
50 CI.getPreprocessorOpts().resetNonModularOptions();
55 CI.getFrontendOpts().Inputs.clear();
56 CI.getFrontendOpts().OutputFile.clear();
57 CI.getCodeGenOpts().MainFileName.clear();
58 CI.getCodeGenOpts().DwarfDebugFlags.clear();
61 CI.getLangOpts()->ModuleName = Deps.ID.ModuleName;
62 CI.getFrontendOpts().IsSystemModule = Deps.IsSystem;
64 CI.getLangOpts()->ImplicitModules =
false;
65 CI.getHeaderSearchOpts().ImplicitModuleMaps =
false;
66 CI.getHeaderSearchOpts().ModuleCachePath.clear();
69 for (
const auto &PrebuiltModule : Deps.PrebuiltModuleDeps)
70 CI.getFrontendOpts().ModuleFiles.push_back(PrebuiltModule.PCMFile);
72 CI.getFrontendOpts().ModuleMapFiles = Deps.ModuleMapFileDeps;
82 CI.getHeaderSearchOpts().ModulesStrictContextHash =
true;
87 static std::vector<std::string>
90 llvm::BumpPtrAllocator Alloc;
91 llvm::StringSaver Strings(Alloc);
92 auto SA = [&Strings](
const Twine &Arg) {
return Strings.save(Arg).data(); };
99 return std::vector<std::string>{Args.begin(), Args.end()};
103 std::function<StringRef(
ModuleID)> LookupPCMPath)
const {
108 InputKind::Format::ModuleMap);
113 FrontendOpts.
ModuleFiles.emplace_back(LookupPCMPath(MID));
118 std::vector<std::string>
132 if (MDC.ContextHash.empty()) {
143 SM.getNonBuiltinFilenameForID(
SM.getFileID(
SM.getExpansionLoc(Loc))))
144 MDC.FileDeps.push_back(
151 StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
153 if (!
File && !Imported) {
158 handleImport(Imported);
164 handleImport(Imported);
167 void ModuleDepCollectorPP::handleImport(
const Module *Imported) {
173 if (MDC.isPrebuiltModule(TopLevelModule))
174 DirectPrebuiltModularDeps.insert(TopLevelModule);
176 DirectModularDeps.insert(TopLevelModule);
186 MDC.FileDeps.push_back(
189 for (
const Module *M : DirectModularDeps) {
194 if (!M->getASTFile())
196 handleTopLevelModule(M);
201 for (
auto &&I : MDC.ModularDeps)
204 for (
auto &&I : MDC.FileDeps)
207 for (
auto &&I : DirectPrebuiltModularDeps)
211 ModuleID ModuleDepCollectorPP::handleTopLevelModule(
const Module *M) {
215 auto ModI = MDC.ModularDeps.insert({M,
ModuleDeps{}});
217 return ModI.first->second.ID;
219 ModuleDeps &MD = ModI.first->second;
222 MD.ImportedByMainFile = DirectModularDeps.contains(M);
232 StringRef Path =
ModuleMap->tryGetRealPathName();
239 MDC.ScanInstance.
getASTReader()->getModuleManager().lookup(
248 if (IF.
getFile()->getName().endswith(
"__inferred_module.map")) {
249 MD.FileDeps.insert(ModuleMap->getName());
252 MD.FileDeps.insert(IF.
getFile()->getName());
279 MDC.ScanInstance.
getASTReader()->visitTopLevelModuleMaps(
281 if (FE->
getName().endswith(
"__inferred_module.map"))
287 MD.ModuleMapFileDeps.push_back(FE->
getName().str());
295 addAllSubmodulePrebuiltDeps(M, MD, SeenModules);
297 MD.BuildInvocation = MDC.makeInvocationForModuleBuildWithoutPaths(
299 if (MDC.OptimizeArgs)
306 addAllSubmoduleDeps(M, MD, AddedModules);
311 void ModuleDepCollectorPP::addAllSubmodulePrebuiltDeps(
312 const Module *M, ModuleDeps &MD,
314 addModulePrebuiltDeps(M, MD, SeenSubmodules);
317 addAllSubmodulePrebuiltDeps(SubM, MD, SeenSubmodules);
320 void ModuleDepCollectorPP::addModulePrebuiltDeps(
321 const Module *M, ModuleDeps &MD,
330 void ModuleDepCollectorPP::addAllSubmoduleDeps(
331 const Module *M, ModuleDeps &MD,
333 addModuleDep(M, MD, AddedModules);
336 addAllSubmoduleDeps(SubM, MD, AddedModules);
339 void ModuleDepCollectorPP::addModuleDep(
340 const Module *M, ModuleDeps &MD,
344 !MDC.isPrebuiltModule(Import)) {
347 MD.ClangModuleDeps.push_back(ImportID);
353 std::unique_ptr<DependencyOutputOptions> Opts,
356 : ScanInstance(ScanInstance), Consumer(C), Opts(
std::move(Opts)),
357 OriginalInvocation(
std::move(OriginalCI)), OptimizeArgs(OptimizeArgs) {}
365 bool ModuleDepCollector::isPrebuiltModule(
const Module *M) {
367 const auto &PrebuiltModuleFiles =
369 auto PrebuiltModuleFileIt = PrebuiltModuleFiles.find(Name);
370 if (PrebuiltModuleFileIt == PrebuiltModuleFiles.end())
372 assert(
"Prebuilt module came from the expected AST file" &&
373 PrebuiltModuleFileIt->second == M->
getASTFile()->getName());
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
Encodes a location in the source.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
HeaderSearchOptions & getHeaderSearchOpts()
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Token - This structure provides full information about a lexed token.
This class handles loading and caching of source files into memory.
SmallVector< FrontendInputFile, 0 > Inputs
The input files and their types.
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Describes a module or submodule.
FrontendOptions & getFrontendOpts()
std::string OutputFile
The output file, if any.
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
FileID getMainFileID() const
Returns the FileID of the main source file.
FrontendOptions - Options for controlling the behavior of the frontend.
const FileEntry * getModuleMapFileForUniquing(const Module *M) const
Get the module map file that (along with the module name) uniquely identifies this module.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
InputKind DashX
The input kind, either specified via -x argument or deduced from the input file name.
OptionalFileEntryRefDegradesToFileEntryPtr getASTFile() const
The serialized AST file for this module, if one was created.
void generateCC1CommandLine(llvm::SmallVectorImpl< const char * > &Args, StringAllocator SA) const
Generate a cc1-compatible command line arguments from this instance.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Cached information about one file (either on disk or in the virtual file system).
PreprocessorOptions & getPreprocessorOpts()
llvm::iterator_range< submodule_iterator > submodules()
std::string getModuleHash() const
Retrieve a module hash string that is suitable for uniquely identifying the conditions under which th...
@ GenerateModule
Generate pre-compiled module from a module map.
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
llvm::BitVector SearchPathUsage
The bit vector denoting usage of each header search entry (true = used).
CompilerInvocation & getInvocation()
Represents a character-granular source range.
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Reads an AST files chain containing the contents of a translation unit.
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
llvm::SetVector< ModuleFile * > Imports
List of modules which this module depends on.
static void optimizeHeaderSearchOpts(HeaderSearchOptions &Opts, ASTReader &Reader, const serialization::ModuleFile &MF)
StringRef getName() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Helper class for holding the data necessary to invoke the compiler.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
static std::vector< std::string > serializeCompilerInvocation(const CompilerInvocation &CI)
IntrusiveRefCntPtr< ASTReader > getASTReader() const
SourceManager & getSourceManager() const
Return the current source manager.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
HeaderSearch & getHeaderSearchInfo() const
Information about a module that has been loaded by the ASTReader.
HeaderSearchOptions & getHeaderSearchOpts()
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.