9#ifndef LLVM_CLANG_DEPENDENCYSCANNING_MODULEDEPCOLLECTOR_H
10#define LLVM_CLANG_DEPENDENCYSCANNING_MODULEDEPCOLLECTOR_H
21#include "llvm/ADT/DenseMap.h"
22#include "llvm/ADT/Hashing.h"
23#include "llvm/ADT/StringSet.h"
24#include "llvm/Support/raw_ostream.h"
27#include <unordered_map>
45 PCMFile(M->getASTFile()->getName()),
64 const llvm::StringSet<> &
getVFS()
const {
return VFSMap; }
85 llvm::StringSet<> VFSMap;
86 bool IsInStableDirs =
true;
87 std::set<StringRef> ModuleFileDependents;
108 std::tie(
Other.ModuleName,
Other.ContextHash);
113 std::tie(
Other.ModuleName,
Other.ContextHash);
193 void forEachFileDep(llvm::function_ref<
void(StringRef)> Cb)
const;
204 std::string FileDepsBaseDir;
208 std::vector<std::string> FileDeps;
211 std::vector<std::string>>
232 StringRef RelativePath,
const Module *SuggestedModule,
236 const Module *Imported)
override;
244 void handleImport(
const Module *Imported);
250 llvm::DenseSet<const Module *> &SeenSubmodules);
252 llvm::DenseSet<const Module *> &SeenSubmodules);
258 std::optional<ModuleID> handleTopLevelModule(
const Module *M);
260 llvm::DenseSet<const Module *> &AddedModules);
262 llvm::DenseSet<const Module *> &AddedModules);
268 llvm::DenseSet<const Module *> &AddedModules);
270 llvm::DenseSet<const Module *> &AddedModules);
281 std::unique_ptr<DependencyOutputOptions> Opts,
315 std::string MainFile;
318 std::vector<std::string> FileDeps;
320 llvm::MapVector<const Module *, std::unique_ptr<ModuleDeps>> ModularDeps;
323 llvm::DenseMap<ModuleID, ModuleDeps *> ModuleDepsByID;
325 llvm::MapVector<const Module *, PrebuiltModuleDep> DirectPrebuiltModularDeps;
327 llvm::SetVector<const Module *> DirectModularDeps;
331 llvm::StringSet<> VisibleModules;
334 std::unique_ptr<DependencyOutputOptions> Opts;
341 std::optional<P1689ModuleInfo> ProvidedStdCXXModule;
342 std::vector<P1689ModuleInfo> RequiredStdCXXModules;
350 bool isPrebuiltModule(
const Module *M);
353 void addVisibleModules();
356 void addFileDep(StringRef Path);
358 void addFileDep(
ModuleDeps &MD, StringRef Path);
367 llvm::DenseSet<const FileEntry *>
398 const StringRef Input);
413 return hash_combine(ID.ModuleName, ID.ContextHash);
416template <>
struct DenseMapInfo<
clang::dependencies::ModuleID> {
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
llvm::MachO::FileType FileType
Defines the clang::Module class, which describes a module in the source code.
Defines the PPCallbacks interface.
Defines the SourceManager interface.
Reads an AST files chain containing the contents of a translation unit.
Represents a character-granular source range.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Helper class for holding the data necessary to invoke the compiler.
Same as CompilerInvocation, but with copy-on-write optimization.
An interface for collecting the dependencies of a compilation.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Describes a module or submodule.
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
Token - This structure provides full information about a lexed token.
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
The dependency scanning service contains shared configuration and state that is used by the individua...
Callback that records textual includes and direct modular includes/imports during preprocessing.
void EndOfMainFile() override
Callback invoked when the end of the main file is reached.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule, bool ModuleImported, SrcMgr::CharacteristicKind FileType) override
Callback invoked whenever an inclusion directive of any kind (#include, #import, etc....
ModuleDepCollectorPP(ModuleDepCollector &MDC)
void LexedFileChanged(FileID FID, LexedFileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID, SourceLocation Loc) override
Callback invoked whenever the Lexer moves to a different file for lexing.
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override
Callback invoked whenever there was an explicit module-import syntax.
Collects modular and non-modular dependencies of the main file by attaching ModuleDepCollectorPP to t...
ModuleDepCollector(DependencyScanningService &Service, std::unique_ptr< DependencyOutputOptions > Opts, CompilerInstance &ScanInstance, DependencyConsumer &C, DependencyActionController &Controller, CompilerInvocation OriginalCI, const PrebuiltModulesAttrsMap PrebuiltModulesASTMap, const ArrayRef< StringRef > StableDirs)
void applyDiscoveredDependencies(CompilerInvocation &CI)
Apply any changes implied by the discovered dependencies to the given invocation, (e....
PPCallbacks * getPPCallbacks()
void attachToPreprocessor(Preprocessor &PP) override
void attachToASTReader(ASTReader &R) override
void updateDependentsNotInStableDirs(PrebuiltModulesAttrsMap &PrebuiltModulesMap)
When a module is discovered to not be in stable directories, traverse & update all modules that depen...
void setVFS(llvm::StringSet<> &&VFS)
Update the VFSMap to the one discovered from serializing the AST file.
bool isInStableDir() const
Read-only access to whether the module is made up of dependencies in stable directories.
void addDependent(StringRef ModuleFile)
Add a direct dependent module file, so it can be updated if the current module is from stable directo...
void setInStableDir(bool V=false)
Update whether the prebuilt module resolves entirely in a stable directories.
const llvm::StringSet & getVFS() const
Read-only access to vfs map files.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
bool areOptionsInStableDir(const ArrayRef< StringRef > Directories, const HeaderSearchOptions &HSOpts)
Determine if options collected from a module's compilation can safely be considered as stable.
@ VFS
Remove unused -ivfsoverlay arguments.
@ IgnoreCWD
Ignore the compiler's working directory if it is safe.
ModuleOutputKind
An output from a module compilation, such as the path of the module file.
@ DiagnosticSerializationFile
The path of the serialized diagnostic file (.dia), if any.
@ DependencyFile
The path of the dependency file (.d), if any.
@ DependencyTargets
The null-separated list of names to use as the targets in the dependency file, if any.
@ ModuleFile
The module file (.pcm). Required.
llvm::StringMap< PrebuiltModuleASTAttrs > PrebuiltModulesAttrsMap
Attributes loaded from AST files of prebuilt modules collected prior to ModuleDepCollector creation.
bool isPathInStableDir(const ArrayRef< StringRef > Directories, const StringRef Input)
Determine if Input can be resolved within a stable directory.
void resetBenignCodeGenOptions(frontend::ActionKind ProgramAction, const LangOptions &LangOpts, CodeGenOptions &CGOpts)
Resets codegen options that don't affect modules/PCH.
The JSON file list parser is used to communicate input to InstallAPI.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
ArrayRef< IdentifierLoc > ModuleIdPath
A sequence of identifier/location pairs used to describe a particular module or submodule,...
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
hash_code hash_value(const clang::dependencies::ModuleID &ID)
friend class ModuleDepCollectorPP
std::vector< std::string > ModuleMapFileDeps
A collection of absolute paths to module map files that this module needs to know about.
bool IsInStableDirectories
Whether this module is fully composed of file & module inputs from locations likely to stay the same ...
ModuleID ID
The identifier of the module.
void forEachFileDep(llvm::function_ref< void(StringRef)> Cb) const
Invokes Cb for all file dependencies of this module.
std::vector< PrebuiltModuleDep > PrebuiltModuleDeps
A collection of prebuilt modular dependencies this module directly depends on, not including transiti...
llvm::SmallVector< Module::LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used.
friend class ModuleDepCollector
std::vector< ModuleID > ClangModuleDeps
A list of module identifiers this module directly depends on, not including transitive dependencies.
const std::vector< std::string > & getBuildArguments() const
Get (or compute) the compiler invocation that can be used to build this module.
std::string ClangModuleMapFile
The path to the modulemap file which defines this module.
bool IsSystem
Whether this is a "system" module.
This is used to identify a specific module.
bool operator==(const ModuleID &Other) const
std::string ModuleName
The name of the module.
std::string ContextHash
The context hash of a module represents the compiler options that affect the resulting command-line i...
bool operator<(const ModuleID &Other) const
P1689ModuleInfo - Represents the needed information of standard C++20 modules for P1689 format.
std::string SourcePath
Optional. The source path to the module.
bool IsStdCXXModuleInterface
If this module is a standard c++ interface unit.
std::string ModuleName
The name of the module. This may include : for partitions.
PrebuiltModuleDep(const Module *M)
std::string ModuleMapFile
static bool isEqual(const ModuleID &LHS, const ModuleID &RHS)
static ModuleID getTombstoneKey()
static ModuleID getEmptyKey()
static unsigned getHashValue(const ModuleID &ID)
clang::dependencies::ModuleID ModuleID