Go to the documentation of this file.
15 #ifndef LLVM_CLANG_BASIC_MODULE_H
16 #define LLVM_CLANG_BASIC_MODULE_H
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseSet.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/PointerIntPair.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/SetVector.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/StringMap.h"
29 #include "llvm/ADT/StringRef.h"
30 #include "llvm/ADT/iterator_range.h"
57 using BaseT = std::array<uint8_t, 20>;
59 static constexpr
size_t size = std::tuple_size<BaseT>::value;
63 explicit operator bool()
const {
return *
this !=
BaseT({{0}}); }
68 static_assert(
sizeof(*
this) >=
sizeof(
uint64_t),
"No need to truncate.");
69 for (
unsigned I = 0; I <
sizeof(
uint64_t); ++I)
84 template <
typename InputIt>
87 "Wrong amount of bytes to create an ASTFileSignature");
90 std::copy(
First,
Last, Signature.begin());
145 llvm::PointerUnion<const FileEntry *, const DirectoryEntry *>
Umbrella;
177 std::vector<Module *> SubModules;
181 llvm::StringMap<unsigned> SubModuleIndex;
191 std::vector<std::string> TopHeaderNames;
197 unsigned VisibilityID;
488 UnresolvedHeaderDirective &MissingHeader,
507 if (Mod->IsFramework)
525 Parent->SubModules.push_back(
this);
557 auto pos =
Name.find(
':');
558 return StringRef(
Name.data(), pos);
582 return const_cast<Module *
>(
603 "file path changed");
675 if (VisibleModulesCache.empty())
676 buildVisibleModulesCache();
677 return VisibleModulesCache.count(M);
693 llvm::iterator_range<submodule_const_iterator>
submodules()
const {
704 return "<module-includes>";
708 void print(raw_ostream &OS,
unsigned Indent = 0,
bool Dump =
false)
const;
714 void buildVisibleModulesCache()
const;
722 : ImportLocs(
std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
723 O.ImportLocs.clear();
730 ImportLocs = std::move(O.ImportLocs);
731 O.ImportLocs.clear();
773 std::vector<SourceLocation> ImportLocs;
776 unsigned Generation = 0;
783 StringRef PCHModuleName;
787 Module *ClangModule =
nullptr;
793 : PCHModuleName(
std::move(Name)), Path(
std::move(Path)),
794 ASTFile(
std::move(ASTFile)), Signature(Signature) {}
807 #endif // LLVM_CLANG_BASIC_MODULE_H
SmallVector< Module *, 2 > DirectUses
The directly used modules.
std::pair< std::string, bool > Requirement
An individual requirement: a feature name and a flag indicating the required state of that feature.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
LinkLibrary(const std::string &Library, bool IsFramework)
YAML serialization mapping.
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
static ASTFileSignature create(InputIt First, InputIt Last)
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
unsigned HasIncompatibleModuleFile
Whether we tried and failed to load a module file for this module.
Encodes a location in the source.
bool Wildcard
Whether this export declaration ends in a wildcard, indicating that all of its submodules should be e...
Module * Other
The module that this module conflicts with.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
ModuleId Id
The (unresolved) module id.
bool hasUmbrellaDir() const
Determine whether this module has an umbrella directory that is not based on an umbrella header.
submodule_iterator submodule_begin()
void setParent(Module *M)
Set the parent of this module.
const DirectoryEntry * Entry
Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
Exposes information about the current target.
NameVisibilityKind
Describes the visibility of the various names within a particular module.
std::string Name
The name of this module.
@ ModuleMapModule
This is a module that was defined by a module map and built out of header files.
bool isModulePartition() const
Is this a module partition.
Wrapper around Optional<FileEntryRef> that degrades to 'const FileEntry*', facilitating incremental p...
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
llvm::iterator_range< submodule_const_iterator > submodules() const
Module * findSubmodule(StringRef Name) const
Find the submodule with the given name.
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
bool isVisible(const Module *M) const
Determine whether a module is visible.
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
SourceLocation InferredSubmoduleLoc
The location of the inferred submodule.
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
std::string Message
The message provided to the user when there is a conflict.
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
ASTFileSignature Signature
The module signature.
bool isModuleVisible(const Module *M) const
Determine whether the specified module would be visible to a lookup at the end of this module.
submodule_const_iterator submodule_end() const
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
ArrayRef< const FileEntry * > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
std::vector< Module * >::const_iterator submodule_const_iterator
bool isUnimportable() const
Determine whether this module has been declared unimportable.
unsigned getVisibilityID() const
Describes a module or submodule.
@ Hidden
All of the names in this module are hidden.
Module * findOrInferSubmodule(StringRef Name)
@ ModulePartitionInterface
This is a C++ 20 module partition interface.
SourceLocation ExportLoc
The location of the 'export' keyword in the module map file.
SourceLocation getImportLoc(const Module *M) const
Get the location at which the import of a module was triggered.
bool isSubModule() const
Determine whether this module is a submodule.
Cached information about one directory (either on disk or in the virtual file system).
Module * getModuleOrNull() const
uint64_t truncatedValue() const
Returns the value truncated to the size of an uint64_t.
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
static const int NumHeaderKinds
ASTFileSignature getSignature() const
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
VisibleModuleSet()=default
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
unsigned IsFramework
Whether this is a framework module.
A library or framework to link against when an entity from this module is used.
A set of visible modules.
static ASTFileSignature create(std::array< uint8_t, 20 > Bytes)
@ GlobalModuleFragment
This is a fragment of the global module within some C++ module.
@ ModuleHeaderUnit
This is a C++ 20 header unit.
SourceLocation DefinitionLoc
The location of the module definition.
@ AllVisible
All of the names in this module are visible.
std::vector< Conflict > Conflicts
The list of conflicts.
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
bool isPrivateModule() const
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
unsigned getGeneration() const
Get the current visibility generation.
bool isPartOfFramework() const
Determine whether this module is a part of a framework, either because it is a framework module or be...
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system.
StringRef getPath() const
unsigned IsExplicit
Whether this is an explicit submodule.
OptionalFileEntryRefDegradesToFileEntryPtr getASTFile() const
The serialized AST file for this module, if one was created.
The signature of a module, which is a hash of the AST content.
void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})
Make a specific module visible.
Cached information about one file (either on disk or in the virtual file system).
bool IsFramework
Whether this is a framework rather than a library.
std::string getModuleName() const
Module * Parent
The parent of this module.
bool isModuleMapModule() const
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
llvm::iterator_range< submodule_iterator > submodules()
std::vector< Module * >::iterator submodule_iterator
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
bool isInterfaceOrPartition() const
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used.
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
std::string PathRelativeToRootModuleDirectory
const DirectoryEntry * Directory
The build directory of this module.
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
std::string Message
The message provided to the user when there is a conflict.
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
static ASTFileSignature createDISentinel()
llvm::PointerUnion< const FileEntry *, const DirectoryEntry * > Umbrella
The umbrella header or directory.
StringRef getASTFile() const
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
An unresolved conflict with another module.
std::array< uint8_t, 20 > BaseT
bool isModulePurview() const
Does this Module scope describe part of the purview of a named C++ module?
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
unsigned IsAvailable
Whether this module is available in the current translation unit.
llvm::function_ref< void(ArrayRef< Module * > Path, Module *Conflict, StringRef Message)> ConflictCallback
A callback to call when a module conflict is found.
A conflict between two modules.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
VisibleModuleSet(VisibleModuleSet &&O)
Information about a directory name as found in the module map file.
ModuleKind Kind
The kind of this module.
llvm::SmallSetVector< const Module *, 2 > UndeclaredUses
When NoUndeclaredIncludes is true, the set of modules this module tried to import but didn't because ...
bool isHeaderUnit() const
Is this module a header unit.
Implements support for file system lookup, file system caching, and directory search management.
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
VisibleModuleSet & operator=(VisibleModuleSet &&O)
Move from another visible modules set.
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
llvm::function_ref< void(Module *M)> VisibleCallback
A callback to call when a module is made visible (directly or indirectly) by a call to setVisible.
static StringRef getModuleInputBufferName()
float __ovld __cnfn distance(float, float)
Returns the distance between p0 and p1.
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
ASTSourceDescriptor()=default
void print(raw_ostream &OS, unsigned Indent=0, bool Dump=false) const
Print the module map for this module to the given stream.
ModuleId Id
The name of the module.
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile, ASTFileSignature Signature)
@ ModulePartitionImplementation
This is a C++ 20 module partition implementation.
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
bool isValid() const
Return true if this is a valid SourceLocation object.
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
void dump() const
Dump the contents of this module to the given output stream.
bool isModuleInterfaceUnit() const
std::string Library
The library to link against.
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
submodule_const_iterator submodule_begin() const
submodule_iterator submodule_end()
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
bool isSubFramework() const
Determine whether this module is a subframework of another framework.
void setASTFile(Optional< FileEntryRef > File)
Set the serialized AST file for the top-level module of this module.
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
void addRequirement(StringRef Feature, bool RequiredState, const LangOptions &LangOpts, const TargetInfo &Target)
Add the given feature requirement to the list of features required by this module.
void addTopHeader(const FileEntry *File)
Add a top-level header associated with this module.
bool directlyUses(const Module *Requested)
Determine whether this module has declared its intention to directly use another module.
Module * ShadowingModule
A module with the same name that shadows this module.
bool UseExportAsModuleLinkName
Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...
std::string UmbrellaRelativeToRootModuleDirectory
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
ASTFileSignature(BaseT S={{0}})
static constexpr size_t size
std::string NameAsWritten
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
SmallVector< UnresolvedHeaderDirective, 1 > UnresolvedHeaders
Headers that are mentioned in the module map file but that we have not yet attempted to resolve to a ...