clang  3.9.0
Classes | Public Types | Public Member Functions | Friends | List of all members
clang::ModuleMap Class Reference

#include <ModuleMap.h>

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 }
 Flags describing the role of a module header. More...
 
typedef llvm::SmallPtrSet
< const FileEntry *, 1 > 
AdditionalModMapsSet
 
typedef llvm::StringMap
< Module * >::const_iterator 
module_iterator
 

Public Member Functions

 ModuleMap (SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target, HeaderSearch &HeaderInfo)
 Construct a new module map. More...
 
 ~ModuleMap ()
 Destroy the module map. More...
 
void setTarget (const TargetInfo &Target)
 Set the target information. More...
 
void setBuiltinIncludeDir (const DirectoryEntry *Dir)
 Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath.h. More...
 
void addModuleMapCallbacks (std::unique_ptr< ModuleMapCallbacks > Callback)
 Add a module map callback. More...
 
KnownHeader findModuleForHeader (const FileEntry *File)
 Retrieve the module that owns the given header file, if any. More...
 
ArrayRef< KnownHeaderfindAllModulesForHeader (const FileEntry *File) const
 Retrieve all the modules that contain the given header file. More...
 
void diagnoseHeaderInclusion (Module *RequestingModule, bool RequestingModuleIsModuleInterface, SourceLocation FilenameLoc, StringRef Filename, const FileEntry *File)
 Reports errors if a module must not include a specific file. More...
 
bool isHeaderInUnavailableModule (const FileEntry *Header) const
 Determine whether the given header is part of a module marked 'unavailable'. More...
 
bool isHeaderUnavailableInModule (const FileEntry *Header, const Module *RequestingModule) const
 Determine whether the given header is unavailable as part of the specified module. More...
 
ModulefindModule (StringRef Name) const
 Retrieve a module with the given name. More...
 
ModulelookupModuleUnqualified (StringRef Name, Module *Context) const
 Retrieve a module with the given name using lexical name lookup, starting at the given context. More...
 
ModulelookupModuleQualified (StringRef Name, Module *Context) const
 Retrieve a module with the given name within the given context, using direct (qualified) name lookup. More...
 
std::pair< Module *, boolfindOrCreateModule (StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
 Find a new module or submodule, or create it if it does not already exist. More...
 
ModuleinferFrameworkModule (const DirectoryEntry *FrameworkDir, bool IsSystem, Module *Parent)
 Infer the contents of a framework module map from the given framework directory. More...
 
const FileEntrygetContainingModuleMapFile (const Module *Module) const
 Retrieve the module map file containing the definition of the given module. More...
 
const FileEntrygetModuleMapFileForUniquing (const Module *M) const
 Get the module map file that (along with the module name) uniquely identifies this module. More...
 
void setInferredModuleAllowedBy (Module *M, const FileEntry *ModuleMap)
 
AdditionalModMapsSetgetAdditionalModuleMapFiles (const Module *M)
 Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-level module M. More...
 
void addAdditionalModuleMapFile (const Module *M, const FileEntry *ModuleMap)
 
bool resolveExports (Module *Mod, bool Complain)
 Resolve all of the unresolved exports in the given module. More...
 
bool resolveUses (Module *Mod, bool Complain)
 Resolve all of the unresolved uses in the given module. More...
 
bool resolveConflicts (Module *Mod, bool Complain)
 Resolve all of the unresolved conflicts in the given module. More...
 
ModuleinferModuleFromLocation (FullSourceLoc Loc)
 Infers the (sub)module based on the given source location and source manager. More...
 
void setUmbrellaHeader (Module *Mod, const FileEntry *UmbrellaHeader, Twine NameAsWritten)
 Sets the umbrella header of the given module to the given header. More...
 
void setUmbrellaDir (Module *Mod, const DirectoryEntry *UmbrellaDir, Twine NameAsWritten)
 Sets the umbrella directory of the given module to the given directory. More...
 
void addHeader (Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
 Adds this header to the given module. More...
 
void excludeHeader (Module *Mod, Module::Header Header)
 Marks this header as being excluded from the given module. More...
 
bool parseModuleMapFile (const FileEntry *File, bool IsSystem, const DirectoryEntry *HomeDir, SourceLocation ExternModuleLoc=SourceLocation())
 Parse the given module map file, and record any modules we encounter. More...
 
void dump ()
 Dump the contents of the module map, for debugging purposes. More...
 
module_iterator module_begin () const
 
module_iterator module_end () const
 

Friends

class ModuleMapParser
 

Detailed Description

Definition at line 67 of file ModuleMap.h.

Member Typedef Documentation

typedef llvm::SmallPtrSet<const FileEntry *, 1> clang::ModuleMap::AdditionalModMapsSet

Definition at line 153 of file ModuleMap.h.

typedef llvm::StringMap<Module *>::const_iterator clang::ModuleMap::module_iterator

Definition at line 527 of file ModuleMap.h.

Member Enumeration Documentation

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.

Definition at line 97 of file ModuleMap.h.

Constructor & Destructor Documentation

ModuleMap::ModuleMap ( SourceManager SourceMgr,
DiagnosticsEngine Diags,
const LangOptions LangOpts,
const TargetInfo Target,
HeaderSearch HeaderInfo 
)

Construct a new module map.

Parameters
SourceMgrThe 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.
DiagsA diagnostic engine used for diagnostics.
LangOptsLanguage options for this translation unit.
TargetThe target for this translation unit.

Definition at line 87 of file ModuleMap.cpp.

ModuleMap::~ModuleMap ( )

Destroy the module map.

Definition at line 96 of file ModuleMap.cpp.

Member Function Documentation

void clang::ModuleMap::addAdditionalModuleMapFile ( const Module M,
const FileEntry ModuleMap 
)
inline

Definition at line 443 of file ModuleMap.h.

void ModuleMap::addHeader ( Module Mod,
Module::Header  Header,
ModuleHeaderRole  Role,
bool  Imported = false 
)

Adds this header to the given module.

Parameters
RoleThe role of the header wrt the module.

Definition at line 792 of file ModuleMap.cpp.

References clang::Module::Header::Entry, clang::FileEntry::getName(), clang::Module::getTopLevelModule(), headerRoleToKind(), clang::Module::Headers, and clang::HeaderSearch::MarkFileModuleHeader().

Referenced by clang::serialization::reader::HeaderFileInfoTrait::ReadData().

void clang::ModuleMap::addModuleMapCallbacks ( std::unique_ptr< ModuleMapCallbacks Callback)
inline
void ModuleMap::diagnoseHeaderInclusion ( Module RequestingModule,
bool  RequestingModuleIsModuleInterface,
SourceLocation  FilenameLoc,
StringRef  Filename,
const FileEntry File 
)

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

Parameters
RequestingModuleThe module including a file.
RequestingModuleIsModuleInterfacetrue 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.
FilenameLocThe location of the inclusion's filename.
FilenameThe included filename as written.
FileThe included file.

Definition at line 237 of file ModuleMap.cpp.

References clang::Module::directlyUses(), Filename, clang::Module::getFullModuleName(), clang::ModuleMap::KnownHeader::getModule(), clang::Module::getTopLevelModule(), getTopLevelOrNull(), clang::Module::IsFramework, clang::DiagnosticsEngine::Report(), resolveUses(), and violatesPrivateInclude().

Referenced by clang::Preprocessor::LookupFile().

LLVM_DUMP_METHOD void ModuleMap::dump ( )

Dump the contents of the module map, for debugging purposes.

Definition at line 853 of file ModuleMap.cpp.

References E, and I.

void ModuleMap::excludeHeader ( Module Mod,
Module::Header  Header 
)

Marks this header as being excluded from the given module.

Definition at line 821 of file ModuleMap.cpp.

References clang::Module::Header::Entry, clang::Module::Headers, and clang::Module::HK_Excluded.

ArrayRef< ModuleMap::KnownHeader > ModuleMap::findAllModulesForHeader ( const FileEntry File) const

Retrieve all the modules that contain the given header file.

This may not include umbrella modules, nor information from external sources, if they have not yet been inferred / loaded.

Typically, findModuleForHeader should be used instead, as it picks the preferred module for the header.

Definition at line 425 of file ModuleMap.cpp.

References clang::None.

Referenced by clang::Preprocessor::getModuleHeaderToIncludeForDiagnostics().

Module * ModuleMap::findModule ( StringRef  Name) const

Retrieve a module with the given name.

Parameters
NameThe name of the module to look up.
Returns
The named module, if known; otherwise, returns null.

Definition at line 518 of file ModuleMap.cpp.

Referenced by clang::CompilerInstance::loadModuleFile(), clang::HeaderSearch::lookupModule(), lookupModuleQualified(), lookupModuleUnqualified(), and clang::serialization::ModuleManager::removeModules().

ModuleMap::KnownHeader ModuleMap::findModuleForHeader ( const FileEntry File)

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

Parameters
FileThe header file that is likely to be included.
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 328 of file ModuleMap.cpp.

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

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

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
NameThe name of the module to find or create.
ParentThe module that will act as the parent of this submodule, or NULL to indicate that this is a top-level module.
IsFrameworkWhether this is a framework module.
IsExplicitWhether 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 544 of file ModuleMap.cpp.

References clang::LangOptions::CurrentModule, lookupModuleQualified(), clang::Name, and clang::Result.

AdditionalModMapsSet* clang::ModuleMap::getAdditionalModuleMapFiles ( const Module M)
inline

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 436 of file ModuleMap.h.

References I.

const FileEntry * ModuleMap::getContainingModuleMapFile ( const Module Module) const

Retrieve the module map file containing the definition of the given module.

Parameters
ModuleThe module whose module map file will be returned, if known.
Returns
The file entry for the module map file containing the given module, or NULL if the module definition was inferred.

Definition at line 832 of file ModuleMap.cpp.

References clang::Module::DefinitionLoc, clang::SourceManager::getFileEntryForID(), clang::SourceManager::getFileID(), and clang::SourceLocation::isInvalid().

Referenced by compileModuleImpl(), and getModuleMapFileForUniquing().

const FileEntry * ModuleMap::getModuleMapFileForUniquing ( const Module M) const

Get the module map file that (along with the module name) uniquely identifies this module.

The particular module that Name refers to may depend on how the module was found in header search. However, the combination of Name and this module map will be globally unique for top-level modules. In the case of inferred modules, returns the module map that allowed the inference (e.g. contained 'module *'). Otherwise, returns getContainingModuleMapFile().

Definition at line 840 of file ModuleMap.cpp.

References getContainingModuleMapFile(), and clang::Module::IsInferred.

Referenced by compileModuleImpl(), and clang::HeaderSearch::getModuleFileName().

Module * ModuleMap::inferFrameworkModule ( const DirectoryEntry FrameworkDir,
bool  IsSystem,
Module Parent 
)

Infer the contents of a framework module map from the given framework directory.

Definition at line 587 of file ModuleMap.cpp.

References clang::Module::IsSystem.

Module * ModuleMap::inferModuleFromLocation ( FullSourceLoc  Loc)

Infers the (sub)module based on the given source location and source manager.

Parameters
LocThe location within the source that we are querying, along with its source manager.
Returns
The module that owns this source location, or null if no module owns this source location.

Definition at line 916 of file ModuleMap.cpp.

References findModuleForHeader(), clang::FullSourceLoc::getExpansionLoc(), clang::SourceManager::getFileEntryForID(), clang::FullSourceLoc::getFileID(), clang::SourceManager::getFileID(), clang::SourceManager::getIncludeLoc(), clang::FullSourceLoc::getManager(), clang::ModuleMap::KnownHeader::getModule(), clang::SourceLocation::isFileID(), and clang::SourceLocation::isInvalid().

Referenced by clang::Preprocessor::getModuleContainingLocation(), and clang::ASTWriter::inferSubmoduleIDFromLocation().

bool ModuleMap::isHeaderInUnavailableModule ( const FileEntry Header) const

Determine whether the given header is part of a module marked 'unavailable'.

Definition at line 432 of file ModuleMap.cpp.

References isHeaderUnavailableInModule().

Referenced by clang::Preprocessor::HandleEndOfFile().

bool ModuleMap::isHeaderUnavailableInModule ( const FileEntry Header,
const Module RequestingModule 
) const
Module * ModuleMap::lookupModuleQualified ( StringRef  Name,
Module Context 
) const

Retrieve a module with the given name within the given context, using direct (qualified) name lookup.

Parameters
NameThe name of the module to look up.
ContextThe module for which we will look for a submodule. If null, we will look for a top-level module.
Returns
The named submodule, if known; otherwose, returns null.

Definition at line 536 of file ModuleMap.cpp.

References findModule(), and clang::Module::findSubmodule().

Referenced by findOrCreateModule(), isHeaderUnavailableInModule(), and 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
NameThe name of the module to look up.
ContextThe module context, from which we will perform lexical name lookup.
Returns
The named module, if known; otherwise, returns null.

Definition at line 526 of file ModuleMap.cpp.

References Context, findModule(), lookupModuleQualified(), and clang::Module::Parent.

module_iterator clang::ModuleMap::module_begin ( ) const
inline
module_iterator clang::ModuleMap::module_end ( ) const
inline
bool ModuleMap::parseModuleMapFile ( const FileEntry File,
bool  IsSystem,
const DirectoryEntry HomeDir,
SourceLocation  ExternModuleLoc = SourceLocation() 
)

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

Parameters
FileThe file to be parsed.
IsSystemWhether this module map file is in a system header directory, and therefore should be considered a system module.
HomeDirThe directory in which relative paths within this module map file will be resolved.
ExternModuleLocThe 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 2440 of file ModuleMap.cpp.

References Buffer, clang::SrcMgr::C_System, clang::SrcMgr::C_User, clang::SourceManager::createFileID(), clang::SourceManager::getBuffer(), ID, clang::ModuleMapParser::parseModuleMapFile(), and clang::Result.

bool ModuleMap::resolveConflicts ( Module Mod,
bool  Complain 
)

Resolve all of the unresolved conflicts in the given module.

Parameters
ModThe module whose conflicts should be resolved.
ComplainWhether to emit diagnostics for failures.
Returns
true if any errors were encountered while resolving conflicts, false otherwise.

Definition at line 901 of file ModuleMap.cpp.

References clang::Module::Conflicts, clang::Module::Conflict::Message, clang::Module::Conflict::Other, and clang::Module::UnresolvedConflicts.

Referenced by clang::Sema::ActOnEndOfTranslationUnit().

bool ModuleMap::resolveExports ( Module Mod,
bool  Complain 
)

Resolve all of the unresolved exports in the given module.

Parameters
ModThe module whose exports should be resolved.
ComplainWhether to emit diagnostics for failures.
Returns
true if any errors were encountered while resolving exports, false otherwise.

Definition at line 875 of file ModuleMap.cpp.

References clang::Module::Exports, and clang::Module::UnresolvedExports.

Referenced by clang::Sema::ActOnEndOfTranslationUnit().

bool ModuleMap::resolveUses ( Module Mod,
bool  Complain 
)

Resolve all of the unresolved uses in the given module.

Parameters
ModThe module whose uses should be resolved.
ComplainWhether to emit diagnostics for failures.
Returns
true if any errors were encountered while resolving uses, false otherwise.

Definition at line 888 of file ModuleMap.cpp.

References clang::Module::DirectUses, and clang::Module::UnresolvedDirectUses.

Referenced by clang::Sema::ActOnEndOfTranslationUnit(), and diagnoseHeaderInclusion().

void clang::ModuleMap::setBuiltinIncludeDir ( const DirectoryEntry Dir)
inline

Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath.h.

Definition at line 304 of file ModuleMap.h.

Referenced by clang::ApplyHeaderSearchOptions().

void ModuleMap::setInferredModuleAllowedBy ( Module M,
const FileEntry ModuleMap 
)
void ModuleMap::setTarget ( const TargetInfo Target)

Set the target information.

Definition at line 101 of file ModuleMap.cpp.

Referenced by clang::HeaderSearch::setTarget().

void ModuleMap::setUmbrellaDir ( Module Mod,
const DirectoryEntry UmbrellaDir,
Twine  NameAsWritten 
)

Sets the umbrella directory of the given module to the given directory.

Definition at line 771 of file ModuleMap.cpp.

References clang::Module::Umbrella, and clang::Module::UmbrellaAsWritten.

void ModuleMap::setUmbrellaHeader ( Module Mod,
const FileEntry UmbrellaHeader,
Twine  NameAsWritten 
)

Sets the umbrella header of the given module to the given header.

Definition at line 759 of file ModuleMap.cpp.

References clang::FileEntry::getDir(), clang::SourceManager::getFileManager(), NormalHeader, clang::Module::Umbrella, and clang::Module::UmbrellaAsWritten.

Friends And Related Function Documentation

friend class ModuleMapParser
friend

Definition at line 218 of file ModuleMap.h.


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