14 #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H 15 #define LLVM_CLANG_LEX_HEADERSEARCH_H 22 #include "llvm/ADT/ArrayRef.h" 23 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/ADT/StringMap.h" 25 #include "llvm/ADT/StringSet.h" 26 #include "llvm/ADT/StringRef.h" 27 #include "llvm/Support/Allocator.h" 37 class DiagnosticsEngine;
39 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;
230 std::vector<std::pair<const FileEntry *, std::unique_ptr<HeaderMap>>> HeaderMaps;
236 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
240 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
244 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
255 unsigned NumIncluded = 0;
256 unsigned NumMultiIncludeFileOptzn = 0;
257 unsigned NumFrameworkLookups = 0;
258 unsigned NumSubFrameworkLookups = 0;
261 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
277 unsigned angledDirIdx,
unsigned systemDirIdx,
278 bool noCurDirSearch) {
279 assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
280 "Directory indices 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 *ContextFileEnt,
416 return FrameworkMap[FWName];
449 void MarkFileModuleHeader(
const FileEntry *FE,
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);
534 Module *lookupModule(StringRef ModuleName,
bool AllowSearch =
true,
535 bool AllowExtraModuleMapSearch =
false);
563 bool AllowTextual =
false)
const;
578 bool loadModuleMapFile(
const FileEntry *File,
bool IsSystem,
580 StringRef OriginalModuleMapFile = StringRef());
588 void loadTopLevelSystemModules();
604 Module *lookupModule(StringRef ModuleName, StringRef SearchName,
605 bool AllowExtraModuleMapSearch =
false);
618 Module *loadFrameworkModule(StringRef Name,
630 bool findUsableModuleForHeader(
const FileEntry *File,
632 Module *RequestingModule,
634 bool IsSystemHeaderDir);
641 bool findUsableModuleForFrameworkHeader(
642 const FileEntry *File, StringRef FrameworkName, Module *RequestingModule,
648 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
650 Module *RequestingModule,
671 bool WantExternal =
true)
const;
681 return SearchDirs.begin();
685 return SearchDirs.begin() + AngledDirIdx;
689 return SearchDirs.begin() + AngledDirIdx;
693 return SearchDirs.begin() + SystemDirIdx;
697 return SearchDirs.begin() + SystemDirIdx;
703 StringRef getUniqueFrameworkName(StringRef
Framework);
710 std::string suggestPathToFileForDiagnostics(
const FileEntry *File,
711 bool *IsSystem =
nullptr);
718 std::string suggestPathToFileForDiagnostics(llvm::StringRef File,
719 llvm::StringRef WorkingDir,
720 bool *IsSystem =
nullptr);
724 size_t getTotalMemory()
const;
728 enum LoadModuleMapResult {
743 LoadModuleMapResult loadModuleMapFileImpl(
const FileEntry *File,
747 unsigned *
Offset =
nullptr);
758 LoadModuleMapResult loadModuleMapFile(StringRef DirName,
bool IsSystem,
770 bool IsSystem,
bool IsFramework);
775 #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.