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"
58 using BaseT = std::array<uint8_t, 20>;
60 static constexpr size_t size = std::tuple_size<BaseT>::value;
64 explicit operator bool()
const {
return *
this !=
BaseT({{0}}); }
69 static_assert(
sizeof(*this) >=
sizeof(uint64_t),
"No need to truncate.");
70 for (
unsigned I = 0; I <
sizeof(uint64_t); ++I)
71 Value |=
static_cast<uint64_t
>((*
this)[I]) << (I * 8);
91 template <
typename InputIt>
94 "Wrong amount of bytes to create an ASTFileSignature");
97 std::copy(
First,
Last, Signature.begin());
166 std::variant<std::monostate, FileEntryRef, DirectoryEntryRef>
Umbrella;
216 std::vector<Module *> SubModules;
220 llvm::StringMap<unsigned> SubModuleIndex;
230 std::vector<std::string> TopHeaderNames;
233 mutable llvm::DenseSet<const Module*> VisibleModulesCache;
236 unsigned VisibilityID;
304 LLVM_PREFERRED_TYPE(
bool)
308 LLVM_PREFERRED_TYPE(
bool)
315 LLVM_PREFERRED_TYPE(
bool)
319 LLVM_PREFERRED_TYPE(
bool)
323 LLVM_PREFERRED_TYPE(
bool)
327 LLVM_PREFERRED_TYPE(
bool)
332 LLVM_PREFERRED_TYPE(
bool)
338 LLVM_PREFERRED_TYPE(
bool)
342 LLVM_PREFERRED_TYPE(
bool)
349 LLVM_PREFERRED_TYPE(
bool)
354 LLVM_PREFERRED_TYPE(
bool)
359 LLVM_PREFERRED_TYPE(
bool)
367 LLVM_PREFERRED_TYPE(
bool)
372 LLVM_PREFERRED_TYPE(
bool)
377 LLVM_PREFERRED_TYPE(
bool)
382 LLVM_PREFERRED_TYPE(
bool)
551 UnresolvedHeaderDirective &MissingHeader,
570 if (Mod->IsFramework)
588 Parent->SubModules.push_back(
this);
642 auto pos =
Name.find(
':');
643 return StringRef(
Name.data(), pos);
667 return const_cast<Module *
>(
693 if (
const auto *Dir = std::get_if<DirectoryEntryRef>(&
Umbrella))
701 if (
const auto *Hdr = std::get_if<FileEntryRef>(&
Umbrella))
717 TopHeaderNames.push_back(std::string(
Filename));
773 if (VisibleModulesCache.empty())
774 buildVisibleModulesCache();
775 return VisibleModulesCache.count(M);
784 return llvm::make_range(SubModules.begin(), SubModules.end());
786 llvm::iterator_range<submodule_const_iterator>
submodules()
const {
787 return llvm::make_range(SubModules.begin(), SubModules.end());
797 return "<module-includes>";
801 void print(raw_ostream &OS,
unsigned Indent = 0,
bool Dump =
false)
const;
807 void buildVisibleModulesCache()
const;
815 : ImportLocs(
std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
816 O.ImportLocs.clear();
823 ImportLocs = std::move(O.ImportLocs);
824 O.ImportLocs.clear();
865 std::vector<SourceLocation> ImportLocs;
868 unsigned Generation = 0;
Defines interfaces for clang::DirectoryEntry and clang::DirectoryEntryRef.
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
llvm::MachO::Target Target
Defines the clang::SourceLocation class and associated facilities.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
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.
std::variant< std::monostate, FileEntryRef, DirectoryEntryRef > Umbrella
The umbrella header or directory.
Module * findOrInferSubmodule(StringRef Name)
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
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.
bool isNamedModuleInterfaceHasInit() const
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.
bool isModulePartitionImplementation() const
Is this a module partition implementation unit.
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.
bool isNamedModuleUnit() const
Is this a C++20 named module unit.
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
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.
Module * getPrivateModuleFragment() const
Get the Private Module Fragment (sub-module) for this module, it there is one.
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.
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 isModuleInterfaceUnit() const
static StringRef getModuleInputBufferName()
std::string Name
The name of this module.
Module * getGlobalModuleFragment() const
Get the Global Module Fragment (sub-module) for this module, it there is one.
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.
void setParent(Module *M)
Set the parent of this module.
std::optional< Header > getUmbrellaHeaderAsWritten() const
Retrieve the umbrella header as written.
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.
bool isModuleImplementation() const
Is this a module implementation.
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
OptionalDirectoryEntryRef Directory
The build directory of this module.
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.
unsigned NamedModuleHasInit
Whether this C++20 named modules doesn't need an initializer.
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.
std::string APINotesFile
For the debug info, the path to this module's .apinotes file, if any.
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::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.
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...
ArrayRef< FileEntryRef > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
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.
std::optional< DirectoryName > getUmbrellaDirAsWritten() const
Retrieve the umbrella directory as written.
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.
@ ModuleImplementationUnit
This is a C++20 module implementation 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.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
void addTopHeader(FileEntryRef File)
Add a top-level header associated with this module.
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.
OptionalFileEntryRef getASTFile() const
The serialized AST file for this module, if one was created.
OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const
Get the effective umbrella directory for this module: either the one explicitly written in the 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.
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.
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
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}})
static ASTFileSignature createDummy()
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.
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.