clang: clang::ModuleMap Class Reference (original) (raw)

#include "[clang/Lex/ModuleMap.h](ModuleMap%5F8h%5Fsource.html)"

Classes
class KnownHeader
A header that is known to reside within a given module, whether it was included or excluded. More...
Public Types
enum ModuleHeaderRole { NormalHeader = 0x0 , PrivateHeader = 0x1 , TextualHeader = 0x2 , ExcludedHeader = 0x4 }
Flags describing the role of a module header. More...
using AdditionalModMapsSet = llvm::DenseSet< FileEntryRef >
using module_iterator = llvm::StringMap< Module * >::const_iterator
Public Member Functions
void resolveLinkAsDependencies (Module *Mod)
Use PendingLinkAsModule information to mark top level link names that are going to be replaced by export_as aliases.
void addLinkAsDependency (Module *Mod)
Make module to use export_as as the link dependency name if enough information is available or add it to a pending list otherwise.
ModuleMap (SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target, HeaderSearch &HeaderInfo)
Construct a new module map.
~ModuleMap ()
Destroy the module map.
void setTarget (const TargetInfo &Target)
Set the target information.
void setBuiltinIncludeDir (DirectoryEntryRef Dir)
Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath.h.
OptionalDirectoryEntryRef getBuiltinDir () const
Get the directory that contains Clang-supplied include files.
bool isBuiltinHeader (FileEntryRef File)
Is this a compiler builtin header?
bool shouldImportRelativeToBuiltinIncludeDir (StringRef FileName, Module *Module) const
void addModuleMapCallbacks (std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
KnownHeader findModuleForHeader (FileEntryRef File, bool AllowTextual=false, bool AllowExcluded=false)
Retrieve the module that owns the given header file, if any.
ArrayRef< KnownHeader > findAllModulesForHeader (FileEntryRef File)
Retrieve all the modules that contain the given header file.
ArrayRef< KnownHeader > findResolvedModulesForHeader (FileEntryRef File) const
Like findAllModulesForHeader, but do not attempt to infer module ownership from umbrella headers if we've not already done so.
void resolveHeaderDirectives (const FileEntry *File) const
Resolve all lazy header directives for the specified file.
void resolveHeaderDirectives (Module *Mod, std::optional< const FileEntry * > File) const
Resolve lazy header directives for the specified module.
void diagnoseHeaderInclusion (Module *RequestingModule, bool RequestingModuleIsModuleInterface, SourceLocation FilenameLoc, StringRef Filename, FileEntryRef File)
Reports errors if a module must not include a specific file.
bool isHeaderInUnavailableModule (FileEntryRef Header) const
Determine whether the given header is part of a module marked 'unavailable'.
bool isHeaderUnavailableInModule (FileEntryRef Header, const Module *RequestingModule) const
Determine whether the given header is unavailable as part of the specified module.
Module * findModule (StringRef Name) const
Retrieve a module with the given name.
Module * findOrInferSubmodule (Module *Parent, StringRef Name)
Module * lookupModuleUnqualified (StringRef Name, Module *Context) const
Retrieve a module with the given name using lexical name lookup, starting at the given context.
Module * lookupModuleQualified (StringRef Name, Module *Context) const
Retrieve a module with the given name within the given context, using direct (qualified) name lookup.
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.
Module * findOrCreateModuleFirst (StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Call ModuleMap::findOrCreateModule and throw away the information whether the module was found or created.
Module * createModule (StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Create new submodule, assuming it does not exist.
Module * createGlobalModuleFragmentForModuleUnit (SourceLocation Loc, Module *Parent=nullptr)
Create a global module fragment for a C++ module unit.
Module * createImplicitGlobalModuleFragmentForModuleUnit (SourceLocation Loc, Module *Parent)
Module * createPrivateModuleFragmentForInterfaceUnit (Module *Parent, SourceLocation Loc)
Create a global module fragment for a C++ module interface unit.
Module * createModuleUnitWithKind (SourceLocation Loc, StringRef Name, Module::ModuleKind Kind)
Create a new C++ module with the specified kind, and reparent any pending global module fragment(s) to it.
Module * createModuleForInterfaceUnit (SourceLocation Loc, StringRef Name)
Create a new module for a C++ module interface unit.
Module * createModuleForImplementationUnit (SourceLocation Loc, StringRef Name)
Create a new module for a C++ module implementation unit.
Module * createHeaderUnit (SourceLocation Loc, StringRef Name, Module::Header H)
Create a C++20 header unit.
Module * inferFrameworkModule (DirectoryEntryRef FrameworkDir, bool IsSystem, Module *Parent)
Infer the contents of a framework module map from the given framework directory.
Module * createShadowedModule (StringRef Name, bool IsFramework, Module *ShadowingModule)
Create a new top-level module that is shadowed by ShadowingModule.
void finishModuleDeclarationScope ()
Creates a new declaration scope for module names, allowing previously defined modules to shadow definitions from the new scope.
bool mayShadowNewModule (Module *ExistingModule)
bool canInferFrameworkModule (const DirectoryEntry *Dir) const
Check whether a framework module can be inferred in the given directory.
FileID getContainingModuleMapFileID (const Module *Module) const
Retrieve the module map file containing the definition of the given module.
OptionalFileEntryRef getContainingModuleMapFile (const Module *Module) const
FileID getModuleMapFileIDForUniquing (const Module *M) const
Get the module map file that (along with the module name) uniquely identifies this module.
OptionalFileEntryRef getModuleMapFileForUniquing (const Module *M) const
void setInferredModuleAllowedBy (Module *M, FileID ModMapFID)
std::error_code canonicalizeModuleMapPath (SmallVectorImpl< char > &Path)
Canonicalize Path in a manner suitable for a module map file.
AdditionalModMapsSet * getAdditionalModuleMapFiles (const Module *M)
Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-level module M.
void addAdditionalModuleMapFile (const Module *M, FileEntryRef ModuleMap)
bool resolveExports (Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
bool resolveUses (Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
bool resolveConflicts (Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
void setUmbrellaHeaderAsWritten (Module *Mod, FileEntryRef UmbrellaHeader, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)
Sets the umbrella header of the given module to the given header.
void setUmbrellaDirAsWritten (Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)
Sets the umbrella directory of the given module to the given directory.
void addHeader (Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
Adds this header to the given module.
bool parseModuleMapFile (FileEntryRef File, bool IsSystem, DirectoryEntryRef HomeDir, FileID ID=FileID(), unsigned *Offset=nullptr, SourceLocation ExternModuleLoc=SourceLocation())
Parse the given module map file, and record any modules we encounter.
void dump ()
Dump the contents of the module map, for debugging purposes.
module_iterator module_begin () const
module_iterator module_end () const
llvm::iterator_range< module_iterator > modules () const
void cacheModuleLoad (const IdentifierInfo &II, Module *M)
Cache a module load. M might be nullptr.
std::optional< Module * > getCachedModuleLoad (const IdentifierInfo &II)
Return a cached module load.
Static Public Member Functions
static ModuleHeaderRole headerKindToRole (Module::HeaderKind Kind)
Convert a header kind to a role. Requires Kind to not be HK_Excluded.
static Module::HeaderKind headerRoleToKind (ModuleHeaderRole Role)
Convert a header role to a kind.
static bool isModular (ModuleHeaderRole Role)
Check if the header with the given role is a modular one.

Definition at line 74 of file ModuleMap.h.

AdditionalModMapsSet

module_iterator

ModuleHeaderRole

Flags describing the role of a module header.

Enumerator
NormalHeader This header is normally included in the module.
PrivateHeader This header is included but private.
TextualHeader This header is part of the module (for layering purposes) but should be textually included.
ExcludedHeader This header is explicitly excluded from the module.

Definition at line 130 of file ModuleMap.h.

Construct a new module map.

Parameters

SourceMgr The source manager used to find module files and headers. This source manager should be shared with the header-search mechanism, since they will refer to the same headers.
Diags A diagnostic engine used for diagnostics.
LangOpts Language options for this translation unit.
Target The target for this translation unit.

Definition at line 355 of file ModuleMap.cpp.

~ModuleMap()

ModuleMap::~ModuleMap ( ) default

Destroy the module map.

addAdditionalModuleMapFile()

addHeader()

addLinkAsDependency()

void ModuleMap::addLinkAsDependency ( Module * Mod )

addModuleMapCallbacks()

void clang::ModuleMap::addModuleMapCallbacks ( std::unique_ptr< ModuleMapCallbacks > Callback) inline

cacheModuleLoad()

canInferFrameworkModule()

canonicalizeModuleMapPath()

std::error_code ModuleMap::canonicalizeModuleMapPath ( SmallVectorImpl< char > & Path )

createGlobalModuleFragmentForModuleUnit()

Create a global module fragment for a C++ module unit.

We model the global module fragment as a submodule of the module interface unit. Unfortunately, we can't create the module interface unit's Module until later, because we don't know what it will be called usually. See C++20 [module.unit]/7.2 for the case we could know its parent.

Definition at line 888 of file ModuleMap.cpp.

References clang::Module::ExplicitGlobalModuleFragment, Loc, Parent, and clang::Result.

createHeaderUnit()

createImplicitGlobalModuleFragmentForModuleUnit()

createModule()

Module * ModuleMap::createModule ( StringRef Name,
Module * Parent,
bool IsFramework,
bool IsExplicit
)

createModuleForImplementationUnit()

createModuleForInterfaceUnit()

createModuleUnitWithKind()

createPrivateModuleFragmentForInterfaceUnit()

createShadowedModule()

Module * ModuleMap::createShadowedModule ( StringRef Name,
bool IsFramework,
Module * ShadowingModule
)

diagnoseHeaderInclusion()

Reports errors if a module must not include a specific file.

Parameters

RequestingModule The module including a file.
RequestingModuleIsModuleInterface true if the inclusion is in the interface of RequestingModule, false if it's in the implementation of RequestingModule. Value is ignored and meaningless if RequestingModule is nullptr.
FilenameLoc The location of the inclusion's filename.
Filename The included filename as written.
File The included file.

Definition at line 489 of file ModuleMap.cpp.

References clang::Module::directlyUses(), ExcludedHeader, clang::File, Filename, clang::Module::getFullModuleName(), clang::ModuleMap::KnownHeader::getModule(), clang::ModuleMap::KnownHeader::getRole(), clang::Module::getTopLevelModule(), getTopLevelOrNull(), clang::LangOptions::isCompilingModule(), clang::Module::IsFramework, clang::Module::Name, clang::Private, clang::DiagnosticsEngine::Report(), resolveHeaderDirectives(), resolveUses(), and violatesPrivateInclude().

dump()

LLVM_DUMP_METHOD void ModuleMap::dump ( )

findAllModulesForHeader()

findModule()

Module * ModuleMap::findModule ( StringRef Name ) const

findModuleForHeader()

Retrieve the module that owns the given header file, if any.

Note that this does not implicitly load module maps, except for builtin headers, and does not consult the external source. (Those checks are the responsibility of HeaderSearch.)

Parameters

File The header file that is likely to be included.
AllowTextual If true and File is a textual header, return its owning module. Otherwise, no KnownHeader will be returned if the file is only known as a textual header.

Returns

The module KnownHeader, which provides the module that owns the given header file. The KnownHeader is default constructed to indicate that no module owns this header file.

Definition at line 599 of file ModuleMap.cpp.

References ExcludedHeader, clang::File, clang::ModuleMap::KnownHeader::getModule(), clang::ModuleMap::KnownHeader::getRole(), clang::Module::getTopLevelModule(), isBetterKnownHeader(), clang::Result, and TextualHeader.

Referenced by clang::HeaderSearch::findModuleForHeader(), and clang::Preprocessor::getModuleForLocation().

findOrCreateModule()

std::pair< Module *, bool > ModuleMap::findOrCreateModule ( StringRef Name,
Module * Parent,
bool IsFramework,
bool IsExplicit
)

Find a new module or submodule, or create it if it does not already exist.

Parameters

Name The name of the module to find or create.
Parent The module that will act as the parent of this submodule, or nullptr to indicate that this is a top-level module.
IsFramework Whether this is a framework module.
IsExplicit Whether this is an explicit submodule.

Returns

The found or newly-created module, along with a boolean value that will be true if the module is newly-created.

Definition at line 858 of file ModuleMap.cpp.

References createModule(), lookupModuleQualified(), and Parent.

Referenced by findOrCreateModuleFirst().

findOrCreateModuleFirst()

Module * clang::ModuleMap::findOrCreateModuleFirst ( StringRef Name, Module * Parent, bool IsFramework, bool IsExplicit ) inline

findOrInferSubmodule()

Module * ModuleMap::findOrInferSubmodule ( Module * Parent,
StringRef Name
)

findResolvedModulesForHeader()

finishModuleDeclarationScope()

void clang::ModuleMap::finishModuleDeclarationScope ( ) inline

Creates a new declaration scope for module names, allowing previously defined modules to shadow definitions from the new scope.

Note

Module names from earlier scopes will shadow names from the new scope, which is the opposite of how shadowing works for variables.

Definition at line 617 of file ModuleMap.h.

Referenced by clang::FrontendAction::BeginSourceFile().

getAdditionalModuleMapFiles()

Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-level module M.

This is cheaper than getting the module map file for each submodule individually, since the expected number of results is very small.

Definition at line 668 of file ModuleMap.h.

getBuiltinDir()

getCachedModuleLoad()

getContainingModuleMapFile()

getContainingModuleMapFileID()

FileID ModuleMap::getContainingModuleMapFileID ( const Module * Module ) const

getModuleMapFileForUniquing()

getModuleMapFileIDForUniquing()

FileID ModuleMap::getModuleMapFileIDForUniquing ( const Module * M ) const

headerKindToRole()

headerRoleToKind()

inferFrameworkModule()

isBuiltinHeader()

isHeaderInUnavailableModule()

isHeaderUnavailableInModule()

Determine whether the given header is unavailable as part of the specified module.

Definition at line 723 of file ModuleMap.cpp.

References E, ExcludedHeader, clang::Found, clang::FileEntryRef::getDir(), clang::Module::getEffectiveUmbrellaDir(), clang::SourceManager::getFileManager(), clang::DirectoryEntryRef::getName(), clang::FileEntryRef::getName(), clang::FileManager::getOptionalDirectoryRef(), clang::if(), clang::Module::InferSubmodules, clang::Module::isAvailable(), clang::Module::isSubModuleOf(), lookupModuleQualified(), clang::Module::Parent, resolveHeaderDirectives(), sanitizeFilenameAsIdentifier(), and TextualHeader.

Referenced by collectModuleHeaderIncludes(), and isHeaderInUnavailableModule().

isModular()

lookupModuleQualified()

Module * ModuleMap::lookupModuleQualified ( StringRef Name,
Module * Context
) const

lookupModuleUnqualified()

Module * ModuleMap::lookupModuleUnqualified ( StringRef Name,
Module * Context
) const

Retrieve a module with the given name using lexical name lookup, starting at the given context.

Parameters

Name The name of the module to look up.
Context The module context, from which we will perform lexical name lookup.

Returns

The named module, if known; otherwise, returns null.

Definition at line 841 of file ModuleMap.cpp.

References findModule(), and lookupModuleQualified().

mayShadowNewModule()

bool clang::ModuleMap::mayShadowNewModule ( Module * ExistingModule) inline

module_begin()

module_end()

modules()

llvm::iterator_range< module_iterator > clang::ModuleMap::modules ( ) const inline

parseModuleMapFile()

Parse the given module map file, and record any modules we encounter.

Parameters

File The file to be parsed.
IsSystem Whether this module map file is in a system header directory, and therefore should be considered a system module.
HomeDir The directory in which relative paths within this module map file will be resolved.
ID The FileID of the file to process, if we've already entered it.
Offset [inout] On input the offset at which to start parsing. On output, the offset at which the module map terminated.
ExternModuleLoc The location of the "extern module" declaration that caused us to load this module map file, if any.

Returns

true if an error occurred, false otherwise.

Definition at line 3136 of file ModuleMap.cpp.

References clang::SrcMgr::C_System_ModuleMap, clang::SrcMgr::C_User_ModuleMap, clang::SourceManager::createFileID(), clang::File, clang::SourceManager::getBufferOrNone(), clang::SourceManager::getDecomposedLoc(), clang::SourceManager::getLocForStartOfFile(), clang::Lexer::getSourceLocation(), Loc, and clang::Result.

resolveConflicts()

resolveExports()

resolveHeaderDirectives() [1/2]

void ModuleMap::resolveHeaderDirectives ( const FileEntry * File ) const

resolveHeaderDirectives() [2/2]

void ModuleMap::resolveHeaderDirectives ( Module * Mod,
std::optional< const FileEntry * > File
) const

resolveLinkAsDependencies()

void ModuleMap::resolveLinkAsDependencies ( Module * Mod )

resolveUses()

setBuiltinIncludeDir()

setInferredModuleAllowedBy()

void ModuleMap::setInferredModuleAllowedBy ( Module * M,
FileID ModMapFID
)

setTarget()

void ModuleMap::setTarget ( const TargetInfo & Target )

setUmbrellaDirAsWritten()

void ModuleMap::setUmbrellaDirAsWritten ( Module * Mod,
DirectoryEntryRef UmbrellaDir,
const Twine & NameAsWritten,
const Twine & PathRelativeToRootModuleDirectory
)

setUmbrellaHeaderAsWritten()

void ModuleMap::setUmbrellaHeaderAsWritten ( Module * Mod,
FileEntryRef UmbrellaHeader,
const Twine & NameAsWritten,
const Twine & PathRelativeToRootModuleDirectory
)

shouldImportRelativeToBuiltinIncludeDir()

bool ModuleMap::shouldImportRelativeToBuiltinIncludeDir ( StringRef FileName,
Module * Module
) const

ModuleMapParser


The documentation for this class was generated from the following files: