clang  15.0.0git
ModuleDepCollector.cpp
Go to the documentation of this file.
1 //===- ModuleDepCollector.cpp - Callbacks to collect deps -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
12 #include "clang/Lex/Preprocessor.h"
14 #include "llvm/Support/StringSaver.h"
15 
16 using namespace clang;
17 using namespace tooling;
18 using namespace dependencies;
19 
21  ASTReader &Reader,
22  const serialization::ModuleFile &MF) {
23  // Only preserve search paths that were used during the dependency scan.
24  std::vector<HeaderSearchOptions::Entry> Entries = Opts.UserEntries;
25  Opts.UserEntries.clear();
26 
27  llvm::BitVector SearchPathUsage(Entries.size());
29  std::function<void(const serialization::ModuleFile *)> VisitMF =
30  [&](const serialization::ModuleFile *MF) {
31  SearchPathUsage |= MF->SearchPathUsage;
32  Visited.insert(MF);
33  for (const serialization::ModuleFile *Import : MF->Imports)
34  if (!Visited.contains(Import))
35  VisitMF(Import);
36  };
37  VisitMF(&MF);
38 
39  for (auto Idx : SearchPathUsage.set_bits())
40  Opts.UserEntries.push_back(Entries[Idx]);
41 }
42 
43 CompilerInvocation ModuleDepCollector::makeInvocationForModuleBuildWithoutPaths(
44  const ModuleDeps &Deps,
45  llvm::function_ref<void(CompilerInvocation &)> Optimize) const {
46  // Make a deep copy of the original Clang invocation.
47  CompilerInvocation CI(OriginalInvocation);
48 
49  CI.getLangOpts()->resetNonModularOptions();
50  CI.getPreprocessorOpts().resetNonModularOptions();
51 
52  // Remove options incompatible with explicit module build or are likely to
53  // differ between identical modules discovered from different translation
54  // units.
55  CI.getFrontendOpts().Inputs.clear();
56  CI.getFrontendOpts().OutputFile.clear();
57  CI.getCodeGenOpts().MainFileName.clear();
58  CI.getCodeGenOpts().DwarfDebugFlags.clear();
59 
60  CI.getFrontendOpts().ProgramAction = frontend::GenerateModule;
61  CI.getLangOpts()->ModuleName = Deps.ID.ModuleName;
62  CI.getFrontendOpts().IsSystemModule = Deps.IsSystem;
63 
64  CI.getLangOpts()->ImplicitModules = false;
65  CI.getHeaderSearchOpts().ImplicitModuleMaps = false;
66  CI.getHeaderSearchOpts().ModuleCachePath.clear();
67 
68  // Report the prebuilt modules this module uses.
69  for (const auto &PrebuiltModule : Deps.PrebuiltModuleDeps)
70  CI.getFrontendOpts().ModuleFiles.push_back(PrebuiltModule.PCMFile);
71 
72  CI.getFrontendOpts().ModuleMapFiles = Deps.ModuleMapFileDeps;
73 
74  Optimize(CI);
75 
76  // The original invocation probably didn't have strict context hash enabled.
77  // We will use the context hash of this invocation to distinguish between
78  // multiple incompatible versions of the same module and will use it when
79  // reporting dependencies to the clients. Let's make sure we're using
80  // **strict** context hash in order to prevent accidental sharing of
81  // incompatible modules (e.g. with differences in search paths).
82  CI.getHeaderSearchOpts().ModulesStrictContextHash = true;
83 
84  return CI;
85 }
86 
87 static std::vector<std::string>
89  // Set up string allocator.
90  llvm::BumpPtrAllocator Alloc;
91  llvm::StringSaver Strings(Alloc);
92  auto SA = [&Strings](const Twine &Arg) { return Strings.save(Arg).data(); };
93 
94  // Synthesize full command line from the CompilerInvocation, including "-cc1".
95  SmallVector<const char *, 32> Args{"-cc1"};
96  CI.generateCC1CommandLine(Args, SA);
97 
98  // Convert arguments to the return type.
99  return std::vector<std::string>{Args.begin(), Args.end()};
100 }
101 
102 std::vector<std::string> ModuleDeps::getCanonicalCommandLine(
103  std::function<StringRef(ModuleID)> LookupPCMPath) const {
105  FrontendOptions &FrontendOpts = CI.getFrontendOpts();
106 
107  InputKind ModuleMapInputKind(FrontendOpts.DashX.getLanguage(),
108  InputKind::Format::ModuleMap);
109  FrontendOpts.Inputs.emplace_back(ClangModuleMapFile, ModuleMapInputKind);
110  FrontendOpts.OutputFile = std::string(LookupPCMPath(ID));
111 
112  for (ModuleID MID : ClangModuleDeps)
113  FrontendOpts.ModuleFiles.emplace_back(LookupPCMPath(MID));
114 
115  return serializeCompilerInvocation(CI);
116 }
117 
118 std::vector<std::string>
121 }
122 
124  FileChangeReason Reason,
126  FileID PrevFID) {
127  if (Reason != PPCallbacks::EnterFile)
128  return;
129 
130  // This has to be delayed as the context hash can change at the start of
131  // `CompilerInstance::ExecuteAction`.
132  if (MDC.ContextHash.empty()) {
133  MDC.ContextHash = MDC.ScanInstance.getInvocation().getModuleHash();
134  MDC.Consumer.handleContextHash(MDC.ContextHash);
135  }
136 
137  SourceManager &SM = MDC.ScanInstance.getSourceManager();
138 
139  // Dependency generation really does want to go all the way to the
140  // file entry for a source location to find out what is depended on.
141  // We do not want #line markers to affect dependency generation!
143  SM.getNonBuiltinFilenameForID(SM.getFileID(SM.getExpansionLoc(Loc))))
144  MDC.FileDeps.push_back(
145  std::string(llvm::sys::path::remove_leading_dotslash(*Filename)));
146 }
147 
149  SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
150  bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
151  StringRef SearchPath, StringRef RelativePath, const Module *Imported,
152  SrcMgr::CharacteristicKind FileType) {
153  if (!File && !Imported) {
154  // This is a non-modular include that HeaderSearch failed to find. Add it
155  // here as `FileChanged` will never see it.
156  MDC.FileDeps.push_back(std::string(FileName));
157  }
158  handleImport(Imported);
159 }
160 
162  ModuleIdPath Path,
163  const Module *Imported) {
164  handleImport(Imported);
165 }
166 
167 void ModuleDepCollectorPP::handleImport(const Module *Imported) {
168  if (!Imported)
169  return;
170 
171  const Module *TopLevelModule = Imported->getTopLevelModule();
172 
173  if (MDC.isPrebuiltModule(TopLevelModule))
174  DirectPrebuiltModularDeps.insert(TopLevelModule);
175  else
176  DirectModularDeps.insert(TopLevelModule);
177 }
178 
180  FileID MainFileID = MDC.ScanInstance.getSourceManager().getMainFileID();
181  MDC.MainFile = std::string(MDC.ScanInstance.getSourceManager()
182  .getFileEntryForID(MainFileID)
183  ->getName());
184 
185  if (!MDC.ScanInstance.getPreprocessorOpts().ImplicitPCHInclude.empty())
186  MDC.FileDeps.push_back(
187  MDC.ScanInstance.getPreprocessorOpts().ImplicitPCHInclude);
188 
189  for (const Module *M : DirectModularDeps) {
190  // A top-level module might not be actually imported as a module when
191  // -fmodule-name is used to compile a translation unit that imports this
192  // module. In that case it can be skipped. The appropriate header
193  // dependencies will still be reported as expected.
194  if (!M->getASTFile())
195  continue;
196  handleTopLevelModule(M);
197  }
198 
199  MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts);
200 
201  for (auto &&I : MDC.ModularDeps)
202  MDC.Consumer.handleModuleDependency(I.second);
203 
204  for (auto &&I : MDC.FileDeps)
205  MDC.Consumer.handleFileDependency(I);
206 
207  for (auto &&I : DirectPrebuiltModularDeps)
209 }
210 
211 ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
212  assert(M == M->getTopLevelModule() && "Expected top level module!");
213 
214  // If this module has been handled already, just return its ID.
215  auto ModI = MDC.ModularDeps.insert({M, ModuleDeps{}});
216  if (!ModI.second)
217  return ModI.first->second.ID;
218 
219  ModuleDeps &MD = ModI.first->second;
220 
221  MD.ID.ModuleName = M->getFullModuleName();
222  MD.ImportedByMainFile = DirectModularDeps.contains(M);
223  MD.ImplicitModulePCMPath = std::string(M->getASTFile()->getName());
224  MD.IsSystem = M->IsSystem;
225 
226  const FileEntry *ModuleMap = MDC.ScanInstance.getPreprocessor()
228  .getModuleMap()
230 
231  if (ModuleMap) {
232  StringRef Path = ModuleMap->tryGetRealPathName();
233  if (Path.empty())
234  Path = ModuleMap->getName();
235  MD.ClangModuleMapFile = std::string(Path);
236  }
237 
239  MDC.ScanInstance.getASTReader()->getModuleManager().lookup(
240  M->getASTFile());
241  MDC.ScanInstance.getASTReader()->visitInputFiles(
242  *MF, true, true, [&](const serialization::InputFile &IF, bool isSystem) {
243  // __inferred_module.map is the result of the way in which an implicit
244  // module build handles inferred modules. It adds an overlay VFS with
245  // this file in the proper directory and relies on the rest of Clang to
246  // handle it like normal. With explicitly built modules we don't need
247  // to play VFS tricks, so replace it with the correct module map.
248  if (IF.getFile()->getName().endswith("__inferred_module.map")) {
249  MD.FileDeps.insert(ModuleMap->getName());
250  return;
251  }
252  MD.FileDeps.insert(IF.getFile()->getName());
253  });
254 
255  // We usually don't need to list the module map files of our dependencies when
256  // building a module explicitly: their semantics will be deserialized from PCM
257  // files.
258  //
259  // However, some module maps loaded implicitly during the dependency scan can
260  // describe anti-dependencies. That happens when this module, let's call it
261  // M1, is marked as '[no_undeclared_includes]' and tries to access a header
262  // "M2/M2.h" from another module, M2, but doesn't have a 'use M2;'
263  // declaration. The explicit build needs the module map for M2 so that it
264  // knows that textually including "M2/M2.h" is not allowed.
265  // E.g., '__has_include("M2/M2.h")' should return false, but without M2's
266  // module map the explicit build would return true.
267  //
268  // An alternative approach would be to tell the explicit build what its
269  // textual dependencies are, instead of having it re-discover its
270  // anti-dependencies. For example, we could create and use an `-ivfs-overlay`
271  // with `fall-through: false` that explicitly listed the dependencies.
272  // However, that's more complicated to implement and harder to reason about.
273  if (M->NoUndeclaredIncludes) {
274  // We don't have a good way to determine which module map described the
275  // anti-dependency (let alone what's the corresponding top-level module
276  // map). We simply specify all the module maps in the order they were loaded
277  // during the implicit build during scan.
278  // TODO: Resolve this by serializing and only using Module::UndeclaredUses.
279  MDC.ScanInstance.getASTReader()->visitTopLevelModuleMaps(
280  *MF, [&](const FileEntry *FE) {
281  if (FE->getName().endswith("__inferred_module.map"))
282  return;
283  // The top-level modulemap of this module will be the input file. We
284  // don't need to specify it as a module map.
285  if (FE == ModuleMap)
286  return;
287  MD.ModuleMapFileDeps.push_back(FE->getName().str());
288  });
289  }
290 
291  // Add direct prebuilt module dependencies now, so that we can use them when
292  // creating a CompilerInvocation and computing context hash for this
293  // ModuleDeps instance.
294  llvm::DenseSet<const Module *> SeenModules;
295  addAllSubmodulePrebuiltDeps(M, MD, SeenModules);
296 
297  MD.BuildInvocation = MDC.makeInvocationForModuleBuildWithoutPaths(
298  MD, [&](CompilerInvocation &BuildInvocation) {
299  if (MDC.OptimizeArgs)
301  *MDC.ScanInstance.getASTReader(), *MF);
302  });
303  MD.ID.ContextHash = MD.BuildInvocation.getModuleHash();
304 
305  llvm::DenseSet<const Module *> AddedModules;
306  addAllSubmoduleDeps(M, MD, AddedModules);
307 
308  return MD.ID;
309 }
310 
311 void ModuleDepCollectorPP::addAllSubmodulePrebuiltDeps(
312  const Module *M, ModuleDeps &MD,
313  llvm::DenseSet<const Module *> &SeenSubmodules) {
314  addModulePrebuiltDeps(M, MD, SeenSubmodules);
315 
316  for (const Module *SubM : M->submodules())
317  addAllSubmodulePrebuiltDeps(SubM, MD, SeenSubmodules);
318 }
319 
320 void ModuleDepCollectorPP::addModulePrebuiltDeps(
321  const Module *M, ModuleDeps &MD,
322  llvm::DenseSet<const Module *> &SeenSubmodules) {
323  for (const Module *Import : M->Imports)
324  if (Import->getTopLevelModule() != M->getTopLevelModule())
325  if (MDC.isPrebuiltModule(Import->getTopLevelModule()))
326  if (SeenSubmodules.insert(Import->getTopLevelModule()).second)
327  MD.PrebuiltModuleDeps.emplace_back(Import->getTopLevelModule());
328 }
329 
330 void ModuleDepCollectorPP::addAllSubmoduleDeps(
331  const Module *M, ModuleDeps &MD,
332  llvm::DenseSet<const Module *> &AddedModules) {
333  addModuleDep(M, MD, AddedModules);
334 
335  for (const Module *SubM : M->submodules())
336  addAllSubmoduleDeps(SubM, MD, AddedModules);
337 }
338 
339 void ModuleDepCollectorPP::addModuleDep(
340  const Module *M, ModuleDeps &MD,
341  llvm::DenseSet<const Module *> &AddedModules) {
342  for (const Module *Import : M->Imports) {
343  if (Import->getTopLevelModule() != M->getTopLevelModule() &&
344  !MDC.isPrebuiltModule(Import)) {
345  ModuleID ImportID = handleTopLevelModule(Import->getTopLevelModule());
346  if (AddedModules.insert(Import->getTopLevelModule()).second)
347  MD.ClangModuleDeps.push_back(ImportID);
348  }
349  }
350 }
351 
353  std::unique_ptr<DependencyOutputOptions> Opts,
354  CompilerInstance &ScanInstance, DependencyConsumer &C,
355  CompilerInvocation &&OriginalCI, bool OptimizeArgs)
356  : ScanInstance(ScanInstance), Consumer(C), Opts(std::move(Opts)),
357  OriginalInvocation(std::move(OriginalCI)), OptimizeArgs(OptimizeArgs) {}
358 
360  PP.addPPCallbacks(std::make_unique<ModuleDepCollectorPP>(*this));
361 }
362 
364 
365 bool ModuleDepCollector::isPrebuiltModule(const Module *M) {
367  const auto &PrebuiltModuleFiles =
369  auto PrebuiltModuleFileIt = PrebuiltModuleFiles.find(Name);
370  if (PrebuiltModuleFileIt == PrebuiltModuleFiles.end())
371  return false;
372  assert("Prebuilt module came from the expected AST file" &&
373  PrebuiltModuleFileIt->second == M->getASTFile()->getName());
374  return true;
375 }
clang::Module::getTopLevelModule
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:575
clang::serialization::InputFile::getFile
OptionalFileEntryRefDegradesToFileEntryPtr getFile() const
Definition: ModuleFile.h:94
clang::tooling::dependencies::DependencyConsumer::handlePrebuiltModuleDependency
virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD)=0
clang::DeclaratorContext::File
@ File
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::tooling::dependencies::DependencyConsumer
Definition: DependencyScanningWorker.h:32
llvm::SmallVector
Definition: LLVM.h:38
clang::if
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
Definition: RecursiveASTVisitor.h:1098
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::Module::getFullModuleName
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:219
clang::tooling::dependencies::ModuleDepCollector::ModuleDepCollector
ModuleDepCollector(std::unique_ptr< DependencyOutputOptions > Opts, CompilerInstance &ScanInstance, DependencyConsumer &C, CompilerInvocation &&OriginalCI, bool OptimizeArgs)
Definition: ModuleDepCollector.cpp:352
Filename
StringRef Filename
Definition: Format.cpp:2551
clang::tooling::dependencies::ModuleDeps::getCanonicalCommandLine
std::vector< std::string > getCanonicalCommandLine(std::function< StringRef(ModuleID)> LookupPCMPath) const
Gets the canonical command line suitable for passing to clang.
Definition: ModuleDepCollector.cpp:102
clang::tooling::dependencies::DependencyConsumer::handleModuleDependency
virtual void handleModuleDependency(ModuleDeps MD)=0
clang::PPCallbacks::EnterFile
@ EnterFile
Definition: PPCallbacks.h:40
llvm::Optional
Definition: LLVM.h:40
clang::CompilerInvocationRefBase::getHeaderSearchOpts
HeaderSearchOptions & getHeaderSearchOpts()
Definition: CompilerInvocation.h:112
clang::SrcMgr::CharacteristicKind
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:79
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::InputKind
The kind of a file that we've been handed as an input.
Definition: FrontendOptions.h:151
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:627
clang::FrontendOptions::Inputs
SmallVector< FrontendInputFile, 0 > Inputs
The input files and their types.
Definition: FrontendOptions.h:426
Preprocessor.h
clang::tooling::dependencies::ModuleDepCollector::attachToPreprocessor
void attachToPreprocessor(Preprocessor &PP) override
Definition: ModuleDepCollector.cpp:359
clang::Module::NoUndeclaredIncludes
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition: Module.h:321
clang::tooling::dependencies::ModuleDeps::ID
ModuleID ID
The identifier of the module.
Definition: ModuleDepCollector.h:70
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::CompilerInvocationValueBase::getFrontendOpts
FrontendOptions & getFrontendOpts()
Definition: CompilerInvocation.h:176
clang::FrontendOptions::OutputFile
std::string OutputFile
The output file, if any.
Definition: FrontendOptions.h:433
clang::tooling::dependencies::PrebuiltModuleDep
Modular dependency that has already been built prior to the dependency scan.
Definition: ModuleDepCollector.h:32
clang::serialization::InputFile
The input file that has been loaded from this AST file, along with bools indicating whether this was ...
Definition: ModuleFile.h:65
clang::Module::getTopLevelModuleName
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition: Module.h:585
clang::SourceManager::getMainFileID
FileID getMainFileID() const
Returns the FileID of the main source file.
Definition: SourceManager.h:841
clang::FrontendOptions
FrontendOptions - Options for controlling the behavior of the frontend.
Definition: FrontendOptions.h:268
clang::tooling::dependencies::ModuleDeps::getCanonicalCommandLineWithoutModulePaths
std::vector< std::string > getCanonicalCommandLineWithoutModulePaths() const
Gets the canonical command line suitable for passing to clang, excluding "-fmodule-file=" and "-o" ar...
Definition: ModuleDepCollector.cpp:119
clang::InputKind::getLanguage
Language getLanguage() const
Definition: FrontendOptions.h:182
clang::ModuleMap::getModuleMapFileForUniquing
const FileEntry * getModuleMapFileForUniquing(const Module *M) const
Get the module map file that (along with the module name) uniquely identifies this module.
Definition: ModuleMap.cpp:1284
llvm::DenseSet
Definition: Sema.h:77
clang::CompilerInstance::getPreprocessor
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Definition: CompilerInstance.h:442
clang::FrontendOptions::DashX
InputKind DashX
The input kind, either specified via -x argument or deduced from the input file name.
Definition: FrontendOptions.h:423
DependencyScanningWorker.h
clang::Module::getASTFile
OptionalFileEntryRefDegradesToFileEntryPtr getASTFile() const
The serialized AST file for this module, if one was created.
Definition: Module.h:590
clang::CompilerInvocation::generateCC1CommandLine
void generateCC1CommandLine(llvm::SmallVectorImpl< const char * > &Args, StringAllocator SA) const
Generate a cc1-compatible command line arguments from this instance.
Definition: CompilerInvocation.cpp:4639
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:72
clang::HeaderSearchOptions::PrebuiltModuleFiles
std::map< std::string, std::string, std::less<> > PrebuiltModuleFiles
The mapping of module names to prebuilt module files.
Definition: HeaderSearchOptions.h:119
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:330
clang::ModuleMap
Definition: ModuleMap.h:75
clang::CompilerInstance::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts()
Definition: CompilerInstance.h:306
clang::Module::submodules
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:684
ModuleDepCollector.h
clang::PPCallbacks::FileChangeReason
FileChangeReason
Definition: PPCallbacks.h:39
clang::CompilerInvocation::getModuleHash
std::string getModuleHash() const
Retrieve a module hash string that is suitable for uniquely identifying the conditions under which th...
Definition: CompilerInvocation.cpp:4543
clang::frontend::GenerateModule
@ GenerateModule
Generate pre-compiled module from a module map.
Definition: FrontendOptions.h:85
clang::Module::IsSystem
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition: Module.h:288
clang::serialization::ModuleFile::SearchPathUsage
llvm::BitVector SearchPathUsage
The bit vector denoting usage of each header search entry (true = used).
Definition: ModuleFile.h:178
llvm::ArrayRef
Definition: LLVM.h:34
clang::CompilerInstance::getInvocation
CompilerInvocation & getInvocation()
Definition: CompilerInstance.h:229
clang::tooling::dependencies::ModuleDepCollector::attachToASTReader
void attachToASTReader(ASTReader &R) override
Definition: ModuleDepCollector.cpp:363
clang::tooling::dependencies::ModuleDeps
Definition: ModuleDepCollector.h:68
clang::tooling::dependencies::ModuleDepCollectorPP::EndOfMainFile
void EndOfMainFile() override
Callback invoked when the end of the main file is reached.
Definition: ModuleDepCollector.cpp:179
clang::tooling::dependencies::ModuleDeps::ClangModuleMapFile
std::string ClangModuleMapFile
The path to the modulemap file which defines this module.
Definition: ModuleDepCollector.h:79
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:253
clang::tooling::dependencies::ModuleDepCollectorPP::InclusionDirective
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, Optional< FileEntryRef > File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override
Callback invoked whenever an inclusion directive of any kind (#include, #import, etc....
Definition: ModuleDepCollector.cpp:148
clang::tooling::dependencies::ModuleDepCollectorPP::moduleImport
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
Callback invoked whenever there was an explicit module-import syntax.
Definition: ModuleDepCollector.cpp:161
clang::Module::Imports
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition: Module.h:344
clang::HeaderSearchOptions::UserEntries
std::vector< Entry > UserEntries
User specified include entries.
Definition: HeaderSearchOptions.h:103
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:341
std
Definition: Format.h:4296
clang::FrontendOptions::ModuleFiles
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input.
Definition: FrontendOptions.h:471
clang
Definition: CalledOnceCheck.h:17
clang::Preprocessor::addPPCallbacks
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
Definition: Preprocessor.h:1092
clang::serialization::ModuleFile::Imports
llvm::SetVector< ModuleFile * > Imports
List of modules which this module depends on.
Definition: ModuleFile.h:498
optimizeHeaderSearchOpts
static void optimizeHeaderSearchOpts(HeaderSearchOptions &Opts, ASTReader &Reader, const serialization::ModuleFile &MF)
Definition: ModuleDepCollector.cpp:20
clang::FileEntry::getName
StringRef getName() const
Definition: FileEntry.h:361
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::CompilerInvocation
Helper class for holding the data necessary to invoke the compiler.
Definition: CompilerInvocation.h:193
clang::tooling::dependencies::DependencyConsumer::handleContextHash
virtual void handleContextHash(std::string Hash)=0
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:1035
clang::SrcMgr::isSystem
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
Definition: SourceManager.h:88
serializeCompilerInvocation
static std::vector< std::string > serializeCompilerInvocation(const CompilerInvocation &CI)
Definition: ModuleDepCollector.cpp:88
clang::tooling::dependencies::ModuleDeps::BuildInvocation
CompilerInvocation BuildInvocation
Compiler invocation that can be used to build this module (without paths).
Definition: ModuleDepCollector.h:108
CompilerInstance.h
clang::tooling::dependencies::ModuleDepCollectorPP::FileChanged
void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID) override
Callback invoked whenever a source file is entered or exited.
Definition: ModuleDepCollector.cpp:123
clang::CompilerInstance::getASTReader
IntrusiveRefCntPtr< ASTReader > getASTReader() const
Definition: CompilerInstance.cpp:200
clang::CompilerInstance::getSourceManager
SourceManager & getSourceManager() const
Return the current source manager.
Definition: CompilerInstance.h:422
clang::tooling::dependencies::ModuleID
This is used to identify a specific module.
Definition: ModuleDepCollector.h:44
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:131
clang::tooling::dependencies::ModuleDeps::ClangModuleDeps
std::vector< ModuleID > ClangModuleDeps
A list of module identifiers this module directly depends on, not including transitive dependencies.
Definition: ModuleDepCollector.h:101
SM
#define SM(sm)
Definition: Cuda.cpp:81
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:999
clang::tooling::dependencies::DependencyConsumer::handleFileDependency
virtual void handleFileDependency(StringRef Filename)=0
clang::tooling::dependencies::DependencyConsumer::handleDependencyOutputOpts
virtual void handleDependencyOutputOpts(const DependencyOutputOptions &Opts)=0
clang::HeaderSearch::getModuleMap
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:777
clang::serialization::ModuleFile
Information about a module that has been loaded by the ASTReader.
Definition: ModuleFile.h:111
clang::CompilerInstance::getHeaderSearchOpts
HeaderSearchOptions & getHeaderSearchOpts()
Definition: CompilerInstance.h:289
clang::PreprocessorOptions::ImplicitPCHInclude
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
Definition: PreprocessorOptions.h:96
clang::HeaderSearchOptions
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Definition: HeaderSearchOptions.h:68