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,
279 unsigned angledDirIdx,
unsigned systemDirIdx,
280 bool noCurDirSearch) {
281 assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
282 "Directory indices are unordered");
284 AngledDirIdx = angledDirIdx;
285 SystemDirIdx = systemDirIdx;
286 NoCurDirSearch = noCurDirSearch;
292 unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
293 SearchDirs.insert(SearchDirs.begin() + idx, dir);
301 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
313 IncludeAliases.reset(
new IncludeAliasMap);
314 (*IncludeAliases)[Source] = Dest;
322 assert(IncludeAliases &&
"Trying to map headers when there's no map");
325 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
326 if (Iter != IncludeAliases->end())
333 ModuleCachePath = CachePath;
341 DirectoryHasModuleMap[Dir] =
true;
350 ExternalLookup = EPS;
354 return ExternalLookup;
399 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
402 bool *IsMapped,
bool SkipCache =
false,
bool BuildSystemModule =
false);
410 const FileEntry *LookupSubframeworkHeader(
411 StringRef Filename,
const FileEntry *RelativeFileEnt,
418 return FrameworkMap[FWName];
428 Module *CorrespondingModule);
451 void MarkFileModuleHeader(
const FileEntry *File,
453 bool IsCompiledModuleHeader);
458 ++getFileInfo(File).NumIncludes;
472 return getFileInfo(File).NumIncludes == 1;
480 bool isFileMultipleIncludeGuarded(
const FileEntry *File);
508 std::string getPrebuiltModuleFileName(StringRef ModuleName,
509 bool FileMapOnly =
false);
521 std::string getCachedModuleFileName(StringRef ModuleName,
522 StringRef ModuleMapPath);
536 Module *lookupModule(StringRef ModuleName,
bool AllowSearch =
true,
537 bool AllowExtraModuleMapSearch =
false);
565 bool AllowTextual =
false)
const;
580 bool loadModuleMapFile(
const FileEntry *File,
bool IsSystem,
582 StringRef OriginalModuleMapFile = StringRef());
590 void loadTopLevelSystemModules();
606 Module *lookupModule(StringRef ModuleName, StringRef SearchName,
607 bool AllowExtraModuleMapSearch =
false);
620 Module *loadFrameworkModule(StringRef Name,
632 bool findUsableModuleForHeader(
const FileEntry *File,
634 Module *RequestingModule,
636 bool IsSystemHeaderDir);
643 bool findUsableModuleForFrameworkHeader(
644 const FileEntry *File, StringRef FrameworkDir, Module *RequestingModule,
650 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
652 Module *RequestingModule,
673 bool WantExternal =
true)
const;
683 return SearchDirs.begin();
687 return SearchDirs.begin() + AngledDirIdx;
691 return SearchDirs.begin() + AngledDirIdx;
695 return SearchDirs.begin() + SystemDirIdx;
699 return SearchDirs.begin() + SystemDirIdx;
705 StringRef getUniqueFrameworkName(StringRef
Framework);
712 std::string suggestPathToFileForDiagnostics(
const FileEntry *File,
713 bool *IsSystem =
nullptr);
720 std::string suggestPathToFileForDiagnostics(llvm::StringRef File,
721 llvm::StringRef WorkingDir,
722 bool *IsSystem =
nullptr);
726 size_t getTotalMemory()
const;
730 enum LoadModuleMapResult {
745 LoadModuleMapResult loadModuleMapFileImpl(
const FileEntry *File,
749 unsigned *
Offset =
nullptr);
760 LoadModuleMapResult loadModuleMapFile(StringRef DirName,
bool IsSystem,
772 bool IsSystem,
bool IsFramework);
777 #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.