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 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
270 unsigned angledDirIdx,
unsigned systemDirIdx,
271 bool noCurDirSearch) {
272 assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
273 "Directory indices are unordered");
275 AngledDirIdx = angledDirIdx;
276 SystemDirIdx = systemDirIdx;
277 NoCurDirSearch = noCurDirSearch;
283 unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
284 SearchDirs.insert(SearchDirs.begin() + idx, dir);
292 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
304 IncludeAliases.reset(
new IncludeAliasMap);
305 (*IncludeAliases)[Source] = Dest;
313 assert(IncludeAliases &&
"Trying to map headers when there's no map");
316 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
317 if (Iter != IncludeAliases->end())
324 ModuleCachePath = CachePath;
332 DirectoryHasModuleMap[Dir] =
true;
341 ExternalLookup = EPS;
345 return ExternalLookup;
395 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
398 bool *IsMapped,
bool *IsFrameworkFound,
bool SkipCache =
false,
399 bool BuildSystemModule =
false);
408 StringRef Filename,
const FileEntry *ContextFileEnt,
415 return FrameworkMap[FWName];
448 void MarkFileModuleHeader(
const FileEntry *FE,
455 ++getFileInfo(File).NumIncludes;
469 return getFileInfo(File).NumIncludes == 1;
477 bool isFileMultipleIncludeGuarded(
const FileEntry *File);
505 std::string getPrebuiltModuleFileName(StringRef ModuleName,
506 bool FileMapOnly =
false);
518 std::string getCachedModuleFileName(StringRef ModuleName,
519 StringRef ModuleMapPath);
533 Module *lookupModule(StringRef ModuleName,
bool AllowSearch =
true,
534 bool AllowExtraModuleMapSearch =
false);
560 bool AllowTextual =
false)
const;
575 bool loadModuleMapFile(
const FileEntry *File,
bool IsSystem,
577 StringRef OriginalModuleMapFile = StringRef());
585 void loadTopLevelSystemModules();
601 Module *lookupModule(StringRef ModuleName, StringRef SearchName,
602 bool AllowExtraModuleMapSearch =
false);
615 Module *loadFrameworkModule(StringRef Name,
627 bool findUsableModuleForHeader(
const FileEntry *File,
629 Module *RequestingModule,
631 bool IsSystemHeaderDir);
638 bool findUsableModuleForFrameworkHeader(
639 const FileEntry *File, StringRef FrameworkName, Module *RequestingModule,
645 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
647 Module *RequestingModule,
668 bool WantExternal =
true)
const;
678 return SearchDirs.begin();
682 return SearchDirs.begin() + AngledDirIdx;
686 return SearchDirs.begin() + AngledDirIdx;
690 return SearchDirs.begin() + SystemDirIdx;
694 return SearchDirs.begin() + SystemDirIdx;
700 StringRef getUniqueFrameworkName(StringRef
Framework);
711 std::string suggestPathToFileForDiagnostics(
const FileEntry *File,
712 llvm::StringRef MainFile,
713 bool *IsSystem =
nullptr);
724 std::string suggestPathToFileForDiagnostics(llvm::StringRef File,
725 llvm::StringRef WorkingDir,
726 llvm::StringRef MainFile,
727 bool *IsSystem =
nullptr);
731 size_t getTotalMemory()
const;
735 enum LoadModuleMapResult {
750 LoadModuleMapResult loadModuleMapFileImpl(
const FileEntry *File,
754 unsigned *
Offset =
nullptr);
765 LoadModuleMapResult loadModuleMapFile(StringRef DirName,
bool IsSystem,
777 bool IsSystem,
bool IsFramework);
782 #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.