14 #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H 15 #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;
42 class HeaderSearchOptions;
152 struct FrameworkCacheEntry {
159 bool IsUserSpecifiedSystemFramework;
163 std::shared_ptr<HeaderSearchOptions> HSOpts;
174 std::vector<DirectoryLookup> SearchDirs;
175 unsigned AngledDirIdx = 0;
176 unsigned SystemDirIdx = 0;
177 bool NoCurDirSearch =
false;
185 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
188 std::string ModuleCachePath;
192 mutable std::vector<HeaderFileInfo> FileInfo;
195 struct LookupFileCacheInfo {
199 unsigned StartIdx = 0;
206 const char *MappedName =
nullptr;
209 LookupFileCacheInfo() =
default;
211 void reset(
unsigned StartIdx) {
212 this->StartIdx = StartIdx;
213 this->MappedName =
nullptr;
216 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
220 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
225 using IncludeAliasMap =
226 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
227 std::unique_ptr<IncludeAliasMap> IncludeAliases;
231 std::vector<std::pair<const FileEntry *, const HeaderMap *>> HeaderMaps;
237 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
241 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
245 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
256 unsigned NumIncluded = 0;
257 unsigned NumMultiIncludeFileOptzn = 0;
258 unsigned NumFrameworkLookups = 0;
259 unsigned NumSubFrameworkLookups = 0;
262 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
277 unsigned angledDirIdx,
unsigned systemDirIdx,
278 bool noCurDirSearch) {
279 assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
280 "Directory indicies are unordered");
282 AngledDirIdx = angledDirIdx;
283 SystemDirIdx = systemDirIdx;
284 NoCurDirSearch = noCurDirSearch;
290 unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
291 SearchDirs.insert(SearchDirs.begin() + idx, dir);
299 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
311 IncludeAliases.reset(
new IncludeAliasMap);
312 (*IncludeAliases)[Source] = Dest;
320 assert(IncludeAliases &&
"Trying to map headers when there's no map");
323 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
324 if (Iter != IncludeAliases->end())
331 ModuleCachePath = CachePath;
339 DirectoryHasModuleMap[Dir] =
true;
348 ExternalLookup = EPS;
352 return ExternalLookup;
397 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
400 bool *IsMapped,
bool SkipCache =
false,
bool BuildSystemModule =
false);
408 const FileEntry *LookupSubframeworkHeader(
409 StringRef Filename,
const FileEntry *RelativeFileEnt,
416 return FrameworkMap[FWName];
426 Module *CorrespondingModule);
449 void MarkFileModuleHeader(
const FileEntry *File,
451 bool IsCompiledModuleHeader);
456 ++getFileInfo(File).NumIncludes;
470 return getFileInfo(File).NumIncludes == 1;
478 bool isFileMultipleIncludeGuarded(
const FileEntry *File);
506 std::string getPrebuiltModuleFileName(StringRef ModuleName,
507 bool FileMapOnly =
false);
519 std::string getCachedModuleFileName(StringRef ModuleName,
520 StringRef ModuleMapPath);
531 Module *lookupModule(StringRef ModuleName,
bool AllowSearch =
true);
559 bool AllowTextual =
false)
const;
574 bool loadModuleMapFile(
const FileEntry *File,
bool IsSystem,
576 StringRef OriginalModuleMapFile = StringRef());
584 void loadTopLevelSystemModules();
597 Module *lookupModule(StringRef ModuleName, StringRef SearchName);
610 Module *loadFrameworkModule(StringRef Name,
622 bool findUsableModuleForHeader(
const FileEntry *File,
624 Module *RequestingModule,
626 bool IsSystemHeaderDir);
633 bool findUsableModuleForFrameworkHeader(
634 const FileEntry *File, StringRef FrameworkDir, Module *RequestingModule,
640 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
642 Module *RequestingModule,
663 bool WantExternal =
true)
const;
673 return SearchDirs.begin();
677 return SearchDirs.begin() + AngledDirIdx;
681 return SearchDirs.begin() + AngledDirIdx;
685 return SearchDirs.begin() + SystemDirIdx;
689 return SearchDirs.begin() + SystemDirIdx;
695 StringRef getUniqueFrameworkName(StringRef
Framework);
702 std::string suggestPathToFileForDiagnostics(
const FileEntry *File,
703 bool *IsSystem =
nullptr);
707 size_t getTotalMemory()
const;
711 enum LoadModuleMapResult {
726 LoadModuleMapResult loadModuleMapFileImpl(
const FileEntry *File,
730 unsigned *
Offset =
nullptr);
741 LoadModuleMapResult loadModuleMapFile(StringRef DirName,
bool IsSystem,
753 bool IsSystem,
bool IsFramework);
758 #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.
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 ...
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 class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.