15 #ifndef LLVM_CLANG_BASIC_MODULE_H 16 #define LLVM_CLANG_BASIC_MODULE_H 20 #include "llvm/ADT/ArrayRef.h" 21 #include "llvm/ADT/DenseSet.h" 22 #include "llvm/ADT/Optional.h" 23 #include "llvm/ADT/PointerIntPair.h" 24 #include "llvm/ADT/PointerUnion.h" 25 #include "llvm/ADT/SetVector.h" 26 #include "llvm/ADT/SmallVector.h" 27 #include "llvm/ADT/STLExtras.h" 28 #include "llvm/ADT/StringMap.h" 29 #include "llvm/ADT/StringRef.h" 30 #include "llvm/ADT/iterator_range.h" 56 : std::array<uint32_t, 5>(std::move(S)) {}
58 explicit operator bool()
const {
59 return *
this != std::array<uint32_t, 5>({{0}});
104 llvm::PointerUnion<const DirectoryEntry *, const FileEntry *>
Umbrella;
118 return Kind == ModuleInterfaceUnit || Kind == PrivateModuleFragment;
123 std::vector<Module *> SubModules;
127 llvm::StringMap<unsigned> SubModuleIndex;
137 std::vector<std::string> TopHeaderNames;
143 unsigned VisibilityID;
153 static const int NumHeaderKinds = HK_Excluded + 1;
161 explicit operator bool() {
return Entry; }
170 explicit operator bool() {
return Entry; }
182 bool IsUmbrella =
false;
183 bool HasBuiltinHeader =
false;
328 : Library(Library), IsFramework(IsFramework) {}
337 bool IsFramework =
false;
346 bool UseExportAsModuleLinkName =
false;
379 bool IsFramework,
bool IsExplicit,
unsigned VisibilityID);
408 Module *&ShadowingModule)
const;
415 bool isSubModuleOf(
const Module *Other)
const;
422 if (Mod->IsFramework)
439 Parent->SubModuleIndex[Name] = Parent->SubModules.size();
440 Parent->SubModules.push_back(
this);
447 std::string getFullModuleName(
bool AllowStringLiterals =
false)
const;
458 return const_cast<Module *
>(
459 const_cast<const Module *
>(
this)->getTopLevelModule());
464 const Module *getTopLevelModule()
const;
468 return getTopLevelModule()->
Name;
473 return getTopLevelModule()->ASTFile;
478 assert((File ==
nullptr || getASTFile() ==
nullptr ||
479 getASTFile() == File) &&
"file path changed");
480 getTopLevelModule()->ASTFile = File;
490 if (
auto *E = Umbrella.dyn_cast<
const FileEntry *>())
491 return Header{UmbrellaAsWritten, E};
504 TopHeaders.insert(File);
509 TopHeaderNames.push_back(Filename);
517 bool directlyUses(
const Module *Requested)
const;
533 void addRequirement(StringRef Feature,
bool RequiredState,
538 void markUnavailable(
bool MissingRequirement =
false);
543 Module *findSubmodule(StringRef Name)
const;
544 Module *findOrInferSubmodule(StringRef Name);
553 if (VisibleModulesCache.empty())
554 buildVisibleModulesCache();
555 return VisibleModulesCache.count(M);
569 return llvm::make_range(submodule_begin(), submodule_end());
571 llvm::iterator_range<submodule_const_iterator>
submodules()
const {
572 return llvm::make_range(submodule_begin(), submodule_end());
582 return "<module-includes>";
586 void print(raw_ostream &OS,
unsigned Indent = 0)
const;
592 void buildVisibleModulesCache()
const;
600 : ImportLocs(
std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
601 O.ImportLocs.clear();
608 ImportLocs = std::move(O.ImportLocs);
609 O.ImportLocs.clear();
621 return getImportLoc(M).isValid();
639 llvm::function_ref<void(ArrayRef<Module *> Path,
Module *Conflict,
651 std::vector<SourceLocation> ImportLocs;
654 unsigned Generation = 0;
659 #endif // LLVM_CLANG_BASIC_MODULE_H SourceLocation ExportLoc
The location of the 'export' keyword in the module map file.
unsigned IsAvailable
Whether this module is available in the current translation unit.
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
ASTFileSignature Signature
The module signature.
std::string Name
The name of this module.
A set of visible modules.
ASTFileSignature(std::array< uint32_t, 5 > S={{0}})
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system...
std::string Message
The message provided to the user when there is a conflict.
bool isSubFramework() const
Determine whether this module is a subframework of another framework.
std::vector< Module * >::iterator submodule_iterator
Implements support for file system lookup, file system caching, and directory search management...
Defines the clang::FileManager interface and associated types.
An unresolved conflict with another module.
unsigned getVisibilityID() const
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
submodule_iterator submodule_begin()
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
void addTopHeaderFilename(StringRef Filename)
Add a top-level header filename associated with this module.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
unsigned IsFramework
Whether this is a framework module.
SourceLocation getImportLoc(const Module *M) const
Get the location at which the import of a module was triggered.
const FileEntry * getASTFile() const
The serialized AST file for this module, if one was created.
bool hasUmbrellaDir() const
Determine whether this module has an umbrella directory that is not based on an umbrella header...
This is a module that was defined by a module map and built out of header files.
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
std::string PresumedModuleMapFile
The presumed file name for the module map defining this module.
bool isPartOfFramework() const
Determine whether this module is a part of a framework, either because it is a framework module or be...
This is the private module fragment within some C++ module.
A library or framework to link against when an entity from this module is used.
static StringRef getModuleInputBufferName()
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
bool isVisible(const Module *M) const
Determine whether a module is visible.
The signature of a module, which is a hash of the AST content.
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.
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e...
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
std::string Message
The message provided to the user when there is a conflict.
ModuleId Id
The (unresolved) module id.
Module * Parent
The parent of this module.
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
submodule_iterator submodule_end()
LinkLibrary(const std::string &Library, bool IsFramework)
VisibleModuleSet(VisibleModuleSet &&O)
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules...
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
void setParent(Module *M)
Set the parent of this module.
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
std::string Library
The library to link against.
const DirectoryEntry * Entry
Exposes information about the current target.
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
ModuleId Id
The name of the module.
VisibleModuleSet & operator=(VisibleModuleSet &&O)
Move from another visible modules set.
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used...
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
llvm::function_ref< void(ArrayRef< Module * > Path, Module *Conflict, StringRef Message)> ConflictCallback
A callback to call when a module conflict is found.
void setASTFile(const FileEntry *File)
Set the serialized AST file for the top-level module of this module.
Encodes a location in the source.
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed, for use in "private" modules.
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
All of the names in this module are hidden.
Information about a directory name as found in the module map file.
Cached information about one file (either on disk or in the virtual file system). ...
bool isModuleVisible(const Module *M) const
Determine whether the specified module would be visible to a lookup at the end of this module...
This is a fragment of the global module within some C++ module.
bool Wildcard
Whether this export declaration ends in a wildcard, indicating that all of its submodules should be e...
std::pair< std::string, bool > Requirement
An individual requirement: a feature name and a flag indicating the required state of that feature...
llvm::iterator_range< submodule_const_iterator > submodules() const
bool isSubModule() const
Determine whether this module is a submodule.
A conflict between two modules.
SmallVector< UnresolvedHeaderDirective, 1 > UnresolvedHeaders
Headers that are mentioned in the module map file but that we have not yet attempted to resolve to a ...
Dataflow Directional Tag Classes.
unsigned IsMissingRequirement
Whether this module is missing a feature from Requirements.
llvm::PointerUnion< const DirectoryEntry *, const FileEntry * > Umbrella
The umbrella header or directory.
SourceLocation InferredSubmoduleLoc
The location of the inferred submodule.
llvm::iterator_range< submodule_iterator > submodules()
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
void addTopHeader(const FileEntry *File)
Add a top-level header associated with this module.
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map...
SourceLocation DefinitionLoc
The location of the module definition.
bool isModulePurview() const
Does this Module scope describe part of the purview of a named C++ module?
std::vector< Conflict > Conflicts
The list of conflicts.
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
unsigned getGeneration() const
Get the current visibility generation.
std::string NameAsWritten
Cached information about one directory (either on disk or in the virtual file system).
submodule_const_iterator submodule_begin() const
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...
Defines the clang::SourceLocation class and associated facilities.
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
unsigned HasIncompatibleModuleFile
Whether we tried and failed to load a module file for this module.
NameVisibilityKind
Describes the visibility of the various names within a particular module.
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
submodule_const_iterator submodule_end() const
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
Module * Other
The module that this module conflicts with.
unsigned IsExplicit
Whether this is an explicit submodule.
std::vector< Module * >::const_iterator submodule_const_iterator
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
This is a C++ Modules TS module interface unit.