14 #ifndef LLVM_CLANG_LEX_MODULEMAP_H 15 #define LLVM_CLANG_LEX_MODULEMAP_H 21 #include "llvm/ADT/ArrayRef.h" 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/PointerIntPair.h" 24 #include "llvm/ADT/SmallPtrSet.h" 25 #include "llvm/ADT/SmallVector.h" 26 #include "llvm/ADT/StringMap.h" 27 #include "llvm/ADT/StringRef.h" 28 #include "llvm/ADT/StringSet.h" 29 #include "llvm/ADT/TinyPtrVector.h" 30 #include "llvm/ADT/Twine.h" 38 class DiagnosticsEngine;
48 virtual void anchor();
95 Module *SourceModule =
nullptr;
102 llvm::StringMap<Module *> Modules;
106 llvm::DenseMap<const IdentifierInfo *, Module *> CachedModuleLoads;
112 unsigned NumCreatedModules = 0;
116 llvm::StringMap<llvm::StringSet<>> PendingLinkAsModule;
121 void resolveLinkAsDependencies(
Module *Mod);
125 void addLinkAsDependency(
Module *Mod);
156 llvm::PointerIntPair<Module *, 2, ModuleHeaderRole> Storage;
163 return A.Storage == B.Storage;
166 return A.Storage != B.Storage;
177 return getModule()->isAvailable();
182 return !(getRole() & PrivateHeader) ||
188 explicit operator bool()
const {
189 return Storage.getPointer() !=
nullptr;
199 llvm::DenseMap<const FileEntry *, SmallVector<KnownHeader, 1>>;
206 mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize;
209 mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>
210 LazyHeadersByModTime;
218 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
225 unsigned CurrentModuleScopeID = 0;
227 llvm::DenseMap<Module *, unsigned> ModuleScopeIDs;
232 unsigned IsSystem : 1;
235 unsigned IsExternC : 1;
238 unsigned IsExhaustive : 1;
242 unsigned NoUndeclaredIncludes : 1;
246 NoUndeclaredIncludes(
false) {}
250 struct InferredDirectory {
252 unsigned InferModules : 1;
265 InferredDirectory() : InferModules(
false) {}
270 llvm::DenseMap<const DirectoryEntry *, InferredDirectory> InferredDirectories;
274 llvm::DenseMap<const Module *, const FileEntry *> InferredModuleAllowedBy;
276 llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
280 llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap;
296 bool Complain)
const;
318 void addUnresolvedHeader(
Module *Mod,
320 bool &NeedsFramework);
334 bool &NeedsFramework);
343 bool &NeedsFramework);
348 bool resolveAsBuiltinHeader(
Module *M,
356 HeadersMap::iterator findKnownHeader(
const FileEntry *File);
373 bool isHeaderInUmbrellaDirs(
const FileEntry *File) {
375 return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs));
406 BuiltinIncludeDir = Dir;
411 return BuiltinIncludeDir;
415 static bool isBuiltinHeader(StringRef FileName);
419 Callbacks.push_back(std::move(Callback));
434 bool AllowTextual =
false);
448 void resolveHeaderDirectives(
const FileEntry *File)
const;
451 void resolveHeaderDirectives(
Module *Mod)
const;
467 void diagnoseHeaderInclusion(
Module *RequestingModule,
468 bool RequestingModuleIsModuleInterface,
474 bool isHeaderInUnavailableModule(
const FileEntry *Header)
const;
478 bool isHeaderUnavailableInModule(
const FileEntry *Header,
479 const Module *RequestingModule)
const;
486 Module *findModule(StringRef Name)
const;
497 Module *lookupModuleUnqualified(StringRef Name,
Module *Context)
const;
508 Module *lookupModuleQualified(StringRef Name,
Module *Context)
const;
524 std::pair<Module *, bool> findOrCreateModule(StringRef Name,
Module *
Parent,
536 Module *createPrivateModuleFragmentForInterfaceUnit(
Module *Parent,
555 bool IsSystem,
Module *Parent);
559 Module *createShadowedModule(StringRef Name,
bool IsFramework,
570 assert(!ExistingModule->
Parent &&
"expected top-level module");
571 assert(ModuleScopeIDs.count(ExistingModule) &&
"unknown module");
572 return ModuleScopeIDs[ExistingModule] < CurrentModuleScopeID;
593 const FileEntry *getModuleMapFileForUniquing(
const Module *M)
const;
595 void setInferredModuleAllowedBy(Module *M,
const FileEntry *ModMap);
602 auto I = AdditionalModMaps.find(M);
603 if (I == AdditionalModMaps.end())
609 AdditionalModMaps[M].insert(ModuleMap);
620 bool resolveExports(Module *Mod,
bool Complain);
630 bool resolveUses(Module *Mod,
bool Complain);
640 bool resolveConflicts(Module *Mod,
bool Complain);
644 void setUmbrellaHeader(Module *Mod,
const FileEntry *UmbrellaHeader,
645 Twine NameAsWritten);
649 void setUmbrellaDir(Module *Mod,
const DirectoryEntry *UmbrellaDir,
650 Twine NameAsWritten);
680 bool parseModuleMapFile(
const FileEntry *File,
bool IsSystem,
695 CachedModuleLoads[&II] = M;
700 auto I = CachedModuleLoads.find(&II);
701 if (I == CachedModuleLoads.end())
709 #endif // LLVM_CLANG_LEX_MODULEMAP_H
Implements support for file system lookup, file system caching, and directory search management...
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
llvm::StringMap< Module * >::const_iterator module_iterator
One of these records is kept for each identifier that is lexed.
void cacheModuleLoad(const IdentifierInfo &II, Module *M)
Cache a module load. M might be nullptr.
void finishModuleDeclarationScope()
Creates a new declaration scope for module names, allowing previously defined modules to shadow defin...
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.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Concrete class used by the front-end to report problems and issues.
Module * Parent
The parent of this module.
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
ModuleHeaderRole
Flags describing the role of a module header.
Exposes information about the current target.
Defines the clang::LangOptions interface.
virtual void moduleMapFileRead(SourceLocation FileStart, const FileEntry &File, bool IsSystem)
Called when a module map file has been read.
llvm::Optional< Module * > getCachedModuleLoad(const IdentifierInfo &II)
Return a cached module load.
llvm::SmallPtrSet< const FileEntry *, 1 > AdditionalModMapsSet
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
module_iterator module_begin() const
A mechanism to observe the actions of the module map parser as it reads module map files...
void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap)
const DirectoryEntry * getBuiltinDir() const
Get the directory that contains Clang-supplied include files.
void setBuiltinIncludeDir(const DirectoryEntry *Dir)
Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath...
Encodes a location in the source.
virtual void moduleMapAddUmbrellaHeader(FileManager *FileMgr, const FileEntry *Header)
Called when an umbrella header is added during module map parsing.
Cached information about one file (either on disk or in the virtual file system). ...
virtual void moduleMapAddHeader(StringRef Filename)
Called when a header is added during module map parsing.
Defines the clang::Module class, which describes a module in the source code.
module_iterator module_end() const
bool mayShadowNewModule(Module *ExistingModule)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
virtual ~ModuleMapCallbacks()=default
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
AdditionalModMapsSet * getAdditionalModuleMapFiles(const Module *M)
Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-le...
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
Cached information about one directory (either on disk or in the virtual file system).
Defines the clang::SourceLocation class and associated facilities.
This class handles loading and caching of source files into memory.