19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringSwitch.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
28 bool IsFramework,
bool IsExplicit,
unsigned VisibilityID)
29 : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), Directory(),
30 Umbrella(), Signature(0), ASTFile(nullptr), VisibilityID(VisibilityID),
31 IsMissingRequirement(
false), HasIncompatibleModuleFile(
false),
32 IsAvailable(
true), IsFromModuleFile(
false), IsFramework(IsFramework),
33 IsExplicit(IsExplicit), IsSystem(
false), IsExternC(
false),
34 IsInferred(
false), InferSubmodules(
false), InferExplicitSubmodules(
false),
35 InferExportWildcard(
false), ConfigMacrosExhaustive(
false),
36 NameVisibility(Hidden) {
46 Parent->SubModuleIndex[
Name] = Parent->SubModules.size();
47 Parent->SubModules.push_back(
this);
62 bool HasFeature = llvm::StringSwitch<bool>(Feature)
63 .Case(
"altivec", LangOpts.AltiVec)
64 .Case(
"blocks", LangOpts.Blocks)
65 .Case(
"cplusplus", LangOpts.CPlusPlus)
66 .Case(
"cplusplus11", LangOpts.CPlusPlus11)
67 .Case(
"objc", LangOpts.ObjC1)
68 .Case(
"objc_arc", LangOpts.ObjCAutoRefCount)
69 .Case(
"opencl", LangOpts.OpenCL)
71 .Case(
"zvector", LangOpts.ZVector)
87 for (
unsigned I = 0, N =
Current->Requirements.size();
I != N; ++
I) {
94 if (!
Current->MissingHeaders.empty()) {
95 MissingHeader =
Current->MissingHeaders.front();
100 llvm_unreachable(
"could not find a reason why module is unavailable");
104 const Module *This =
this;
128 Names.push_back(M->Name);
145 if (nameParts.empty() || M->Name != nameParts.back())
147 nameParts = nameParts.drop_back();
149 return nameParts.empty();
154 return {
"", U.
Entry->getDir()};
160 if (!TopHeaderNames.empty()) {
162 I = TopHeaderNames.begin(),
E = TopHeaderNames.end();
I !=
E; ++
I) {
164 TopHeaders.insert(FE);
166 TopHeaderNames.clear();
169 return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
179 for (
auto *Use : Top->DirectUses)
191 if (
hasFeature(Feature, LangOpts, Target) == RequiredState)
198 auto needUpdate = [MissingRequirement](
Module *M) {
199 return M->IsAvailable || (!M->IsMissingRequirement && MissingRequirement);
202 if (!needUpdate(
this))
206 Stack.push_back(
this);
207 while (!Stack.empty()) {
211 if (!needUpdate(Current))
218 Sub != SubEnd; ++Sub) {
219 if (needUpdate(*Sub))
220 Stack.push_back(*Sub);
226 llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
227 if (Pos == SubModuleIndex.end())
230 return SubModules[Pos->getValue()];
234 for (
unsigned I = 0, N = Id.size();
I != N; ++
I) {
243 for (std::vector<Module *>::const_iterator
I = SubModules.begin(),
244 E = SubModules.end();
248 Exported.push_back(Mod);
252 bool AnyWildcard =
false;
253 bool UnrestrictedWildcard =
false;
255 for (
unsigned I = 0, N =
Exports.size();
I != N; ++
I) {
259 Exported.push_back(Mod);
267 if (UnrestrictedWildcard)
271 WildcardRestrictions.push_back(Restriction);
273 WildcardRestrictions.clear();
274 UnrestrictedWildcard =
true;
283 for (
unsigned I = 0, N =
Imports.size();
I != N; ++
I) {
285 bool Acceptable = UnrestrictedWildcard;
288 for (
unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) {
289 Module *Restriction = WildcardRestrictions[R];
300 Exported.push_back(Mod);
304 void Module::buildVisibleModulesCache()
const {
305 assert(VisibleModulesCache.empty() &&
"cache does not need building");
308 VisibleModulesCache.insert(
this);
312 while (!
Stack.empty()) {
316 if (VisibleModulesCache.insert(CurrModule).second)
327 OS <<
"module " <<
Name;
330 OS.indent(Indent + 2);
340 OS.indent(Indent + 2);
353 OS.indent(Indent + 2);
354 OS <<
"umbrella header \"";
355 OS.write_escaped(H.NameAsWritten);
358 OS.indent(Indent + 2);
360 OS.write_escaped(D.NameAsWritten);
365 OS.indent(Indent + 2);
366 OS <<
"config_macros ";
368 OS <<
"[exhaustive]";
386 for (
auto &K : Kinds) {
387 for (
auto &H :
Headers[K.Kind]) {
388 OS.indent(Indent + 2);
389 OS << K.Prefix <<
"header \"";
390 OS.write_escaped(H.NameAsWritten);
401 if (!(*MI)->IsInferred || (*MI)->IsFramework)
402 (*MI)->print(OS, Indent + 2);
404 for (
unsigned I = 0, N =
Exports.size();
I != N; ++
I) {
405 OS.indent(Indent + 2);
408 OS << Restriction->getFullModuleName();
418 OS.indent(Indent + 2);
427 OS.indent(Indent + 2);
434 OS.indent(Indent + 2);
441 OS.indent(Indent + 2);
451 OS.indent(Indent + 2);
459 for (
unsigned I = 0, N =
Conflicts.size();
I != N; ++
I) {
460 OS.indent(Indent + 2);
462 OS <<
Conflicts[
I].Other->getFullModuleName();
469 OS.indent(Indent + 2);
472 OS <<
"module * {\n";
474 OS.indent(Indent + 4);
477 OS.indent(Indent + 2);
491 assert(Loc.
isValid() &&
"setVisible expects a valid import location");
499 Visiting *ExportedBy;
502 std::function<void(Visiting)> VisitModule = [&](Visiting V) {
504 if (!V.M->isAvailable())
508 unsigned ID = V.M->getVisibilityID();
509 if (ImportLocs.size() <=
ID)
510 ImportLocs.resize(ID + 1);
511 else if (ImportLocs[ID].isValid())
514 ImportLocs[
ID] = Loc;
519 V.M->getExportedModules(Exports);
521 VisitModule({
E, &V});
523 for (
auto &C : V.M->Conflicts) {
524 if (isVisible(C.Other)) {
526 for (Visiting *
I = &V;
I;
I =
I->ExportedBy)
527 Path.push_back(
I->M);
528 Cb(Path, C.Other, C.Message);
532 VisitModule({M,
nullptr});
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.
std::string Name
The name of this module.
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Implements support for file system lookup, file system caching, and directory search management...
Defines the clang::FileManager interface and associated types.
submodule_iterator submodule_begin()
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "...
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Defines the clang::Module class, which describes a module in the source code.
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature...
unsigned IsFramework
Whether this is a framework 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.
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
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...
void markUnavailable(bool MissingRequirement=false)
Mark this module and all of its submodules as unavailable.
std::string getFullModuleName() const
Retrieve the full name of this module, including the path from its top-level module.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
static bool HasFeature(const Preprocessor &PP, StringRef Feature)
HasFeature - Return true if we recognize and implement the feature specified by the identifier as a s...
void dump() const
Dump the contents of this module to the given output stream.
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.
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.
bool directlyUses(const Module *Requested) const
Determine whether this module has declared its intention to directly use another module.
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e...
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
Module * Parent
The parent of this module.
submodule_iterator submodule_end()
detail::InMemoryDirectory::const_iterator I
std::vector< Module * >::iterator submodule_iterator
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Module * findSubmodule(StringRef Name) const
Find the submodule with the given name.
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
static void printModuleId(raw_ostream &OS, const ModuleId &Id)
std::vector< bool > & Stack
const DirectoryEntry * Entry
void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *){}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef){})
Make a specific module visible.
Exposes information about the current target.
Defines the clang::LangOptions interface.
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
ArrayRef< const FileEntry * > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used...
Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
SmallVector< std::pair< std::string, SourceLocation >, 2 > ModuleId
Describes the name of a module.
bool isSubModuleOf(const Module *Other) const
Determine whether this module is a submodule of the given other module.
std::vector< Module * >::const_iterator submodule_const_iterator
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
The result type of a method or function.
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
void print(raw_ostream &OS, unsigned Indent=0) const
Print the module map for this module to the given stream.
Encodes a location in the source.
const TemplateArgument * iterator
bool isValid() const
Return true if this is a valid SourceLocation object.
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). ...
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
unsigned IsMissingRequirement
Whether this module is missing a feature from Requirements.
llvm::PointerUnion< const DirectoryEntry *, const FileEntry * > Umbrella
The umbrella header or directory.
detail::InMemoryDirectory::const_iterator E
llvm::function_ref< void(ArrayRef< Module * > Path, Module *Conflict, StringRef Message)> ConflictCallback
A callback to call when a module conflict is found.
std::vector< Conflict > Conflicts
The list of conflicts.
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...
Cached information about one directory (either on disk or in the virtual file system).
bool isTLSSupported() const
Whether the target supports thread-local storage.
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Defines the clang::TargetInfo interface.
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
unsigned IsExplicit
Whether this is an explicit submodule.
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.