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/PointerIntPair.h"
24#include "llvm/ADT/STLExtras.h"
25#include "llvm/ADT/SetVector.h"
26#include "llvm/ADT/SmallVector.h"
27#include "llvm/ADT/StringMap.h"
28#include "llvm/ADT/StringRef.h"
29#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)
70 Value |=
static_cast<uint64_t
>((*
this)[I]) << (I * 8);
84 template <
typename InputIt>
87 "Wrong amount of bytes to create an ASTFileSignature");
90 std::copy(
First,
Last, Signature.begin());
153 llvm::PointerUnion<const FileEntryRef::MapEntry *, const DirectoryEntry *>
195 std::vector<Module *> SubModules;
199 llvm::StringMap<unsigned> SubModuleIndex;
209 std::vector<std::string> TopHeaderNames;
215 unsigned VisibilityID;
513 UnresolvedHeaderDirective &MissingHeader,
532 if (Mod->IsFramework)
550 Parent->SubModules.push_back(
this);
587 auto pos =
Name.find(
':');
588 return StringRef(
Name.data(), pos);
612 return const_cast<Module *
>(
660 TopHeaderNames.push_back(std::string(
Filename));
716 if (VisibleModulesCache.empty())
717 buildVisibleModulesCache();
718 return VisibleModulesCache.count(M);
734 llvm::iterator_range<submodule_const_iterator>
submodules()
const {
745 return "<module-includes>";
749 void print(raw_ostream &OS,
unsigned Indent = 0,
bool Dump =
false)
const;
755 void buildVisibleModulesCache()
const;
763 : ImportLocs(
std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
764 O.ImportLocs.clear();
771 ImportLocs = std::move(O.ImportLocs);
772 O.ImportLocs.clear();
814 std::vector<SourceLocation> ImportLocs;
817 unsigned Generation = 0;
824 StringRef PCHModuleName;
828 Module *ClangModule =
nullptr;
834 : PCHModuleName(
std::move(Name)), Path(
std::move(Path)),
835 ASTFile(
std::move(ASTFile)), Signature(Signature) {}
Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Defines the clang::SourceLocation class and associated facilities.
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
Module * getModuleOrNull() const
ASTFileSignature getSignature() const
std::string getModuleName() const
ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile, ASTFileSignature Signature)
StringRef getASTFile() const
ASTSourceDescriptor()=default
StringRef getPath() const
constexpr bool has_value() const
Cached information about one directory (either on disk or in the virtual file system).
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
llvm::StringMapEntry< llvm::ErrorOr< MapValue > > MapEntry
Type used in the StringMap.
Cached information about one file (either on disk or in the virtual file system).
Implements support for file system lookup, file system caching, and directory search management.
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.
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
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.
unsigned IsExplicit
Whether this is an explicit submodule.
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
bool isForBuilding(const LangOptions &LangOpts) const
Determine whether this module can be built in this compilation.
Module * findOrInferSubmodule(StringRef Name)
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
llvm::PointerUnion< const FileEntryRef::MapEntry *, const DirectoryEntry * > Umbrella
The umbrella header or directory.
Module * findSubmodule(StringRef Name) const
Find the submodule with the given name.
static const int NumHeaderKinds
bool directlyUses(const Module *Requested)
Determine whether this module has declared its intention to directly use another module.
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
SourceLocation InferredSubmoduleLoc
The location of the inferred submodule.
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
bool isInterfaceOrPartition() const
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
NameVisibilityKind
Describes the visibility of the various names within a particular module.
@ Hidden
All of the names in this module are hidden.
@ AllVisible
All of the names in this module are visible.
void print(raw_ostream &OS, unsigned Indent=0, bool Dump=false) const
Print the module map for this module to the given stream.
SourceLocation DefinitionLoc
The location of the module definition.
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system.
Module * Parent
The parent of this module.
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
SmallVector< UnresolvedHeaderDirective, 1 > UnresolvedHeaders
Headers that are mentioned in the module map file but that we have not yet attempted to resolve to a ...
ModuleKind Kind
The kind of this module.
bool isPrivateModule() const
submodule_const_iterator submodule_end() const
bool isModulePurview() const
Does this Module scope describe part of the purview of a standard named C++ module?
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
bool isUnimportable() const
Determine whether this module has been declared unimportable.
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
void setASTFile(OptionalFileEntryRef File)
Set the serialized AST file for the top-level module of this module.
Module * getGlobalModuleFragment()
Get the Global Module Fragment (sub-module) for this module, it there is one.
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
bool isModuleVisible(const Module *M) const
Determine whether the specified module would be visible to a lookup at the end of this module.
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
bool hasUmbrellaDir() const
Determine whether this module has an umbrella directory that is not based on an umbrella header.
bool isModuleInterfaceUnit() const
static StringRef getModuleInputBufferName()
std::string Name
The name of this module.
bool isSubFramework() const
Determine whether this module is a subframework of another framework.
llvm::iterator_range< submodule_iterator > submodules()
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
bool isModuleMapModule() const
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used.
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
ArrayRef< const FileEntry * > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
void setParent(Module *M)
Set the parent of this module.
unsigned getVisibilityID() const
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
llvm::SmallSetVector< const Module *, 2 > UndeclaredUses
When NoUndeclaredIncludes is true, the set of modules this module tried to import but didn't because ...
std::string UmbrellaRelativeToRootModuleDirectory
std::vector< Module * >::iterator submodule_iterator
llvm::iterator_range< submodule_const_iterator > submodules() const
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
const DirectoryEntry * Directory
The build directory of this module.
void addTopHeader(const FileEntry *File)
Add a top-level header associated with this module.
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
StringRef getPrimaryModuleInterfaceName() const
Get the primary module interface name from a partition.
bool isModulePartition() const
Is this a module partition.
llvm::SmallSetVector< Module *, 2 > AffectingClangModules
The set of top-level modules that affected the compilation of this module, but were not imported.
SmallVector< Module *, 2 > DirectUses
The directly used modules.
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
submodule_iterator submodule_begin()
ASTFileSignature Signature
The module signature.
bool isExplicitGlobalModule() const
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
bool isSubModule() const
Determine whether this module is a submodule.
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
std::pair< std::string, bool > Requirement
An individual requirement: a feature name and a flag indicating the required state of that feature.
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Module * getPrivateModuleFragment()
Get the Private Module Fragment (sub-module) for this module, it there is one.
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
bool isPartOfFramework() const
Determine whether this module is a part of a framework, either because it is a framework module or be...
OptionalFileEntryRefDegradesToFileEntryPtr getASTFile() const
The serialized AST file for this module, if one was created.
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
unsigned HasIncompatibleModuleFile
Whether we tried and failed to load a module file for this module.
bool isImplicitGlobalModule() const
bool isHeaderUnit() const
Is this module a header unit.
@ ModuleMapModule
This is a module that was defined by a module map and built out of header files.
@ ImplicitGlobalModuleFragment
This is an implicit fragment of the global module which contains only language linkage declarations (...
@ ModulePartitionInterface
This is a C++ 20 module partition interface.
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
@ ModuleHeaderUnit
This is a C++ 20 header unit.
@ ModulePartitionImplementation
This is a C++ 20 module partition implementation.
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
@ ExplicitGlobalModuleFragment
This is the explicit Global Module Fragment of a modular TU.
void dump() const
Dump the contents of this module to the given output stream.
Module * ShadowingModule
A module with the same name that shadows this module.
unsigned IsFramework
Whether this is a framework module.
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
std::vector< Module * >::const_iterator submodule_const_iterator
unsigned IsAvailable
Whether this module is available in the current translation unit.
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
submodule_const_iterator submodule_begin() const
submodule_iterator submodule_end()
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
bool UseExportAsModuleLinkName
Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...
std::vector< Conflict > Conflicts
The list of conflicts.
Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*', facilitating incremental pat...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Exposes information about the current target.
A set of visible modules.
llvm::function_ref< void(ArrayRef< Module * > Path, Module *Conflict, StringRef Message)> ConflictCallback
A callback to call when a module conflict is found.
VisibleModuleSet()=default
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.
SourceLocation getImportLoc(const Module *M) const
Get the location at which the import of a module was triggered.
bool isVisible(const Module *M) const
Determine whether a module is visible.
unsigned getGeneration() const
Get the current visibility generation.
VisibleModuleSet & operator=(VisibleModuleSet &&O)
Move from another visible modules set.
VisibleModuleSet(VisibleModuleSet &&O)
void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})
Make a specific module visible.
YAML serialization mapping.
The signature of a module, which is a hash of the AST content.
uint64_t truncatedValue() const
Returns the value truncated to the size of an uint64_t.
static constexpr size_t size
static ASTFileSignature create(std::array< uint8_t, 20 > Bytes)
ASTFileSignature(BaseT S={{0}})
std::array< uint8_t, 20 > BaseT
static ASTFileSignature createDISentinel()
static ASTFileSignature create(InputIt First, InputIt Last)
A conflict between two modules.
Module * Other
The module that this module conflicts with.
std::string Message
The message provided to the user when there is a conflict.
Information about a directory name as found in the module map file.
const DirectoryEntry * Entry
std::string PathRelativeToRootModuleDirectory
std::string NameAsWritten
A library or framework to link against when an entity from this module is used.
bool IsFramework
Whether this is a framework rather than a library.
LinkLibrary(const std::string &Library, bool IsFramework)
std::string Library
The library to link against.
An unresolved conflict with another module.
std::string Message
The message provided to the user when there is a conflict.
ModuleId Id
The (unresolved) module id.
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
bool Wildcard
Whether this export declaration ends in a wildcard, indicating that all of its submodules should be e...
ModuleId Id
The name of the module.
SourceLocation ExportLoc
The location of the 'export' keyword in the module map file.