15 #ifndef LLVM_CLANG_LEX_MODULEMAP_H
16 #define LLVM_CLANG_LEX_MODULEMAP_H
22 #include "llvm/ADT/ArrayRef.h"
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/PointerIntPair.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/StringMap.h"
28 #include "llvm/ADT/StringRef.h"
29 #include "llvm/ADT/TinyPtrVector.h"
30 #include "llvm/ADT/Twine.h"
41 class DiagnosticConsumer;
42 class DiagnosticsEngine;
44 class ModuleMapParser;
97 llvm::StringMap<Module *> Modules;
100 unsigned NumCreatedModules;
128 llvm::PointerIntPair<Module *, 2, ModuleHeaderRole> Storage;
135 return A.Storage == B.Storage;
138 return A.Storage != B.Storage;
160 explicit operator bool()
const {
161 return Storage.getPointer() !=
nullptr;
168 typedef llvm::DenseMap<const FileEntry *, SmallVector<KnownHeader, 1>>
176 mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize;
178 mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>
179 LazyHeadersByModTime;
187 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
192 : IsSystem(), IsExternC(), IsExhaustive(), NoUndeclaredIncludes() {}
195 unsigned IsSystem : 1;
198 unsigned IsExternC : 1;
201 unsigned IsExhaustive : 1;
205 unsigned NoUndeclaredIncludes : 1;
209 struct InferredDirectory {
210 InferredDirectory() : InferModules() {}
213 unsigned InferModules : 1;
220 const FileEntry *ModuleMapFile;
224 SmallVector<std::string, 2> ExcludedModules;
229 llvm::DenseMap<const DirectoryEntry *, InferredDirectory> InferredDirectories;
233 llvm::DenseMap<const Module *, const FileEntry *> InferredModuleAllowedBy;
235 llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
239 llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap;
257 bool Complain)
const;
273 void addUnresolvedHeader(
Module *Mod,
288 void resolveHeader(
Module *M,
294 bool resolveAsBuiltinHeader(
Module *M,
302 HeadersMap::iterator findKnownHeader(
const FileEntry *File);
319 bool isHeaderInUmbrellaDirs(
const FileEntry *File) {
321 return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs));
325 Attributes Attrs,
Module *Parent);
353 BuiltinIncludeDir = Dir;
358 return BuiltinIncludeDir;
366 Callbacks.push_back(std::move(Callback));
381 bool AllowTextual =
false);
415 bool RequestingModuleIsModuleInterface,
426 const Module *RequestingModule)
const;
487 bool IsSystem,
Module *Parent);
516 auto I = AdditionalModMaps.find(M);
517 if (
I == AdditionalModMaps.end())
523 AdditionalModMaps[M].insert(ModuleMap);
559 Twine NameAsWritten);
564 Twine NameAsWritten);
596 unsigned *
Offset =
nullptr,
609 #endif // LLVM_CLANG_LEX_MODULEMAP_H
ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target, HeaderSearch &HeaderInfo)
Construct a new module map.
Module * lookupModuleQualified(StringRef Name, Module *Context) const
Retrieve a module with the given name within the given context, using direct (qualified) name lookup...
This header is included but private.
module_iterator module_begin() const
Implements support for file system lookup, file system caching, and directory search management...
void dump()
Dump the contents of the module map, for debugging purposes.
Module * findModule(StringRef Name) const
Retrieve a module with the given name.
This header is part of the module (for layering purposes) but should be textually included...
bool isHeaderInUnavailableModule(const FileEntry *Header) const
Determine whether the given header is part of a module marked 'unavailable'.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Defines the SourceManager interface.
llvm::SmallPtrSet< const FileEntry *, 1 > AdditionalModMapsSet
Defines the clang::Module class, which describes a module in the source code.
void excludeHeader(Module *Mod, Module::Header Header)
Marks this header as being excluded from the given module.
bool resolveUses(Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
bool isHeaderUnavailableInModule(const FileEntry *Header, const Module *RequestingModule) const
Determine whether the given header is unavailable as part of the specified module.
bool resolveConflicts(Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, Twine NameAsWritten)
Sets the umbrella directory of the given module to the given directory.
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.
static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind)
Convert a header kind to a role. Requires Kind to not be HK_Excluded.
static bool isBuiltinHeader(StringRef FileName)
Is this a compiler builtin header?
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
ArrayRef< KnownHeader > findAllModulesForHeader(const FileEntry *File) const
Retrieve all the modules that contain the given header file.
Concrete class used by the front-end to report problems and issues.
module_iterator module_end() const
const FileEntry * getContainingModuleMapFile(const Module *Module) const
Retrieve the module map file containing the definition of the given module.
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
detail::InMemoryDirectory::const_iterator I
void setTarget(const TargetInfo &Target)
Set the target information.
llvm::StringMap< Module * >::const_iterator module_iterator
void resolveHeaderDirectives(const FileEntry *File) const
Resolve all lazy header directives for the specified file.
bool parseModuleMapFile(const FileEntry *File, bool IsSystem, const DirectoryEntry *HomeDir, FileID ID=FileID(), unsigned *Offset=nullptr, SourceLocation ExternModuleLoc=SourceLocation())
Parse the given module map file, and record any modules we encounter.
ModuleHeaderRole
Flags describing the role of a module header.
Exposes information about the current target.
void diagnoseHeaderInclusion(Module *RequestingModule, bool RequestingModuleIsModuleInterface, SourceLocation FilenameLoc, StringRef Filename, const FileEntry *File)
Reports errors if a module must not include a specific file.
Defines the clang::LangOptions interface.
MatchFinder::MatchCallback * Callback
Module * lookupModuleUnqualified(StringRef Name, Module *Context) const
Retrieve a module with the given name using lexical name lookup, starting at the given context...
virtual void moduleMapFileRead(SourceLocation FileStart, const FileEntry &File, bool IsSystem)
Called when a module map file has been read.
bool resolveExports(Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
SmallVector< std::pair< std::string, SourceLocation >, 2 > ModuleId
Describes the name of a module.
KnownHeader findModuleForHeader(const FileEntry *File, bool AllowTextual=false)
Retrieve the module that owns the given header file, if any.
void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, Twine NameAsWritten)
Sets the umbrella header of the given module to the given header.
A mechanism to observe the actions of the module map parser as it reads module map files...
const DirectoryEntry * getBuiltinDir() const
Get the directory that contains Clang-supplied include files.
void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap)
std::pair< Module *, bool > findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Find a new module or submodule, or create it if it does not already exist.
void setBuiltinIncludeDir(const DirectoryEntry *Dir)
Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath...
Encodes a location in the source.
virtual void moduleMapAddUmbrellaHeader(FileManager *FileMgr, const FileEntry *Header)
Called when an umbrella header is added during module map parsing.
Cached information about one file (either on disk or in the virtual file system). ...
virtual void moduleMapAddHeader(StringRef Filename)
Called when a header is added during module map parsing.
static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role)
Convert a header role to a kind.
This header is normally included in the module.
void addHeader(Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
Adds this header to the given module.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
virtual ~ModuleMapCallbacks()=default
Module * createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name)
Create a new module for a C++ Modules TS module interface unit.
const FileEntry * getModuleMapFileForUniquing(const Module *M) const
Get the module map file that (along with the module name) uniquely identifies this module...
AdditionalModMapsSet * getAdditionalModuleMapFiles(const Module *M)
Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-le...
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
Cached information about one directory (either on disk or in the virtual file system).
Defines the clang::SourceLocation class and associated facilities.
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
~ModuleMap()
Destroy the module map.
void setInferredModuleAllowedBy(Module *M, const FileEntry *ModuleMap)
This class handles loading and caching of source files into memory.