13 #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H 14 #define LLVM_CLANG_LEX_HEADERSEARCH_H 21 #include "llvm/ADT/ArrayRef.h" 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/StringMap.h" 24 #include "llvm/ADT/StringSet.h" 25 #include "llvm/ADT/StringRef.h" 26 #include "llvm/Support/Allocator.h" 36 class DiagnosticsEngine;
38 class ExternalPreprocessorSource;
41 class HeaderSearchOptions;
162 std::shared_ptr<HeaderSearchOptions> HSOpts;
173 std::vector<DirectoryLookup> SearchDirs;
174 unsigned AngledDirIdx = 0;
175 unsigned SystemDirIdx = 0;
176 bool NoCurDirSearch =
false;
184 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
187 std::string ModuleCachePath;
191 mutable std::vector<HeaderFileInfo> FileInfo;
194 struct LookupFileCacheInfo {
198 unsigned StartIdx = 0;
205 const char *MappedName =
nullptr;
208 LookupFileCacheInfo() =
default;
210 void reset(
unsigned StartIdx) {
211 this->StartIdx = StartIdx;
212 this->MappedName =
nullptr;
215 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
219 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
224 using IncludeAliasMap =
225 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
226 std::unique_ptr<IncludeAliasMap> IncludeAliases;
229 std::vector<std::pair<const FileEntry *, std::unique_ptr<HeaderMap>>> HeaderMaps;
235 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
239 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
243 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
254 unsigned NumIncluded = 0;
255 unsigned NumMultiIncludeFileOptzn = 0;
256 unsigned NumFrameworkLookups = 0;
257 unsigned NumSubFrameworkLookups = 0;
260 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
276 unsigned angledDirIdx,
unsigned systemDirIdx,
277 bool noCurDirSearch) {
278 assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
279 "Directory indices are unordered");
281 AngledDirIdx = angledDirIdx;
282 SystemDirIdx = systemDirIdx;
283 NoCurDirSearch = noCurDirSearch;
289 unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
290 SearchDirs.insert(SearchDirs.begin() + idx, dir);
298 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
310 IncludeAliases.reset(
new IncludeAliasMap);
311 (*IncludeAliases)[Source] = Dest;
319 assert(IncludeAliases &&
"Trying to map headers when there's no map");
322 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
323 if (Iter != IncludeAliases->end())
330 ModuleCachePath = CachePath;
338 DirectoryHasModuleMap[Dir] =
true;
347 ExternalLookup = EPS;
351 return ExternalLookup;
401 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
404 bool *IsMapped,
bool *IsFrameworkFound,
bool SkipCache =
false,
405 bool BuildSystemModule =
false);
413 const FileEntry *LookupSubframeworkHeader(
414 StringRef Filename,
const FileEntry *ContextFileEnt,
421 return FrameworkMap[FWName];
454 void MarkFileModuleHeader(
const FileEntry *FE,
461 ++getFileInfo(File).NumIncludes;
475 return getFileInfo(File).NumIncludes == 1;
483 bool isFileMultipleIncludeGuarded(
const FileEntry *File);
511 std::string getPrebuiltModuleFileName(StringRef ModuleName,
512 bool FileMapOnly =
false);
524 std::string getCachedModuleFileName(StringRef ModuleName,
525 StringRef ModuleMapPath);
539 Module *lookupModule(StringRef ModuleName,
bool AllowSearch =
true,
540 bool AllowExtraModuleMapSearch =
false);
568 bool AllowTextual =
false)
const;
583 bool loadModuleMapFile(
const FileEntry *File,
bool IsSystem,
585 StringRef OriginalModuleMapFile = StringRef());
593 void loadTopLevelSystemModules();
609 Module *lookupModule(StringRef ModuleName, StringRef SearchName,
610 bool AllowExtraModuleMapSearch =
false);
623 Module *loadFrameworkModule(StringRef Name,
635 bool findUsableModuleForHeader(
const FileEntry *File,
637 Module *RequestingModule,
639 bool IsSystemHeaderDir);
646 bool findUsableModuleForFrameworkHeader(
647 const FileEntry *File, StringRef FrameworkName, Module *RequestingModule,
653 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
655 Module *RequestingModule,
676 bool WantExternal =
true)
const;
686 return SearchDirs.begin();
690 return SearchDirs.begin() + AngledDirIdx;
694 return SearchDirs.begin() + AngledDirIdx;
698 return SearchDirs.begin() + SystemDirIdx;
702 return SearchDirs.begin() + SystemDirIdx;
708 StringRef getUniqueFrameworkName(StringRef
Framework);
719 std::string suggestPathToFileForDiagnostics(
const FileEntry *File,
720 llvm::StringRef MainFile,
721 bool *IsSystem =
nullptr);
732 std::string suggestPathToFileForDiagnostics(llvm::StringRef File,
733 llvm::StringRef WorkingDir,
734 llvm::StringRef MainFile,
735 bool *IsSystem =
nullptr);
739 size_t getTotalMemory()
const;
743 enum LoadModuleMapResult {
758 LoadModuleMapResult loadModuleMapFileImpl(
const FileEntry *File,
762 unsigned *
Offset =
nullptr);
773 LoadModuleMapResult loadModuleMapFile(StringRef DirName,
bool IsSystem,
785 bool IsSystem,
bool IsFramework);
790 #endif // LLVM_CLANG_LEX_HEADERSEARCH_H
Implements support for file system lookup, file system caching, and directory search management...
Defines the SourceManager interface.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
One of these records is kept for each identifier that is lexed.
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 IsUserSpecifiedSystemFramework
Whether this framework has been "user-specified" to be treated as if it were a system framework (even...
Concrete class used by the front-end to report problems and issues.
ModuleHeaderRole
Flags describing the role of a module header.
Exposes information about the current target.
Abstract interface for external sources of preprocessor information.
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
const DirectoryEntry * Directory
The directory entry which should be used for the cached framework.
Encodes a location in the source.
Cached information about one file (either on disk or in the virtual file system). ...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
Cached information about one directory (either on disk or in the virtual file system).
Defines the clang::SourceLocation class and associated facilities.
This structure is used to record entries in our framework cache.
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.