16 #ifndef LLVM_CLANG_BASIC_MODULE_H 17 #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/PointerUnion.h" 26 #include "llvm/ADT/SetVector.h" 27 #include "llvm/ADT/SmallVector.h" 28 #include "llvm/ADT/STLExtras.h" 29 #include "llvm/ADT/StringMap.h" 30 #include "llvm/ADT/StringRef.h" 31 #include "llvm/ADT/iterator_range.h" 57 : std::array<uint32_t, 5>(std::move(S)) {}
59 explicit operator bool()
const {
60 return *
this != std::array<uint32_t, 5>({{0}});
103 llvm::PointerUnion<const DirectoryEntry *, const FileEntry *>
Umbrella;
117 std::vector<Module *> SubModules;
121 llvm::StringMap<unsigned> SubModuleIndex;
131 std::vector<std::string> TopHeaderNames;
137 unsigned VisibilityID;
147 static const int NumHeaderKinds = HK_Excluded + 1;
155 explicit operator bool() {
return Entry; }
164 explicit operator bool() {
return Entry; }
176 bool IsUmbrella =
false;
177 bool HasBuiltinHeader =
false;
315 : Library(Library), IsFramework(IsFramework) {}
324 bool IsFramework =
false;
362 bool IsFramework,
bool IsExplicit,
unsigned VisibilityID);
391 bool isSubModuleOf(
const Module *Other)
const;
398 if (Mod->IsFramework)
415 Parent->SubModuleIndex[Name] = Parent->SubModules.size();
416 Parent->SubModules.push_back(
this);
423 std::string getFullModuleName(
bool AllowStringLiterals =
false)
const;
434 return const_cast<Module *
>(
435 const_cast<const Module *
>(
this)->getTopLevelModule());
440 const Module *getTopLevelModule()
const;
444 return getTopLevelModule()->
Name;
449 return getTopLevelModule()->ASTFile;
454 assert((File ==
nullptr || getASTFile() ==
nullptr ||
455 getASTFile() == File) &&
"file path changed");
456 getTopLevelModule()->ASTFile = File;
466 if (
auto *E = Umbrella.dyn_cast<
const FileEntry *>())
467 return Header{UmbrellaAsWritten, E};
480 TopHeaders.insert(File);
485 TopHeaderNames.push_back(Filename);
493 bool directlyUses(
const Module *Requested)
const;
509 void addRequirement(StringRef Feature,
bool RequiredState,
514 void markUnavailable(
bool MissingRequirement =
false);
519 Module *findSubmodule(StringRef Name)
const;
528 if (VisibleModulesCache.empty())
529 buildVisibleModulesCache();
530 return VisibleModulesCache.count(M);
544 return llvm::make_range(submodule_begin(), submodule_end());
546 llvm::iterator_range<submodule_const_iterator>
submodules()
const {
547 return llvm::make_range(submodule_begin(), submodule_end());
557 return "<module-includes>";
561 void print(raw_ostream &OS,
unsigned Indent = 0)
const;
567 void buildVisibleModulesCache()
const;
575 : ImportLocs(
std::move(O.ImportLocs)), Generation(O.Generation ? 1 : 0) {
576 O.ImportLocs.clear();
583 ImportLocs = std::move(O.ImportLocs);
584 O.ImportLocs.clear();
596 return getImportLoc(M).isValid();
614 llvm::function_ref<void(ArrayRef<Module *> Path,
Module *Conflict,
626 std::vector<SourceLocation> ImportLocs;
629 unsigned Generation = 0;
634 #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
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
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.
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...
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
SmallVector< std::pair< std::string, SourceLocation >, 2 > ModuleId
Describes the name of a module.
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++ Modules TS 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.
SourceLocation DefinitionLoc
The location of the module definition.
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.