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/SmallString.h"
24 #include "llvm/ADT/StringMap.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/ADT/StringSet.h"
27 #include "llvm/Support/Allocator.h"
43 class DiagnosticsEngine;
45 class ExternalPreprocessorSource;
49 class HeaderSearchOptions;
157 template <
bool Const,
typename T>
158 using Qualified = std::conditional_t<Const, const T, T>;
161 template <
bool IsConst>
163 : llvm::iterator_facade_base<SearchDirIteratorImpl<IsConst>,
164 std::forward_iterator_tag,
165 Qualified<IsConst, DirectoryLookup>> {
167 template <
typename Enable = std::enable_if<IsConst,
bool>>
169 : HS(Other.HS), Idx(Other.Idx) {}
176 return HS == RHS.HS && Idx == RHS.Idx;
180 assert(*
this &&
"Invalid iterator.");
186 assert(*
this &&
"Invalid iterator.");
187 return HS->SearchDirs[Idx];
194 explicit operator bool()
const {
return HS !=
nullptr; }
205 : HS(&HS), Idx(Idx) {}
211 friend SearchDirIteratorImpl<!IsConst>;
230 std::shared_ptr<HeaderSearchOptions> HSOpts;
233 llvm::DenseMap<unsigned, unsigned> SearchDirToHSEntry;
244 std::vector<DirectoryLookup> SearchDirs;
247 std::vector<bool> SearchDirsUsage;
248 unsigned AngledDirIdx = 0;
249 unsigned SystemDirIdx = 0;
250 bool NoCurDirSearch =
false;
258 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
268 mutable std::vector<HeaderFileInfo> FileInfo;
271 struct LookupFileCacheInfo {
282 const char *MappedName =
nullptr;
285 LookupFileCacheInfo() =
default;
288 StartIt = NewStartIt;
289 MappedName =
nullptr;
292 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
296 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
301 using IncludeAliasMap =
302 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
303 std::unique_ptr<IncludeAliasMap> IncludeAliases;
306 std::vector<std::pair<const FileEntry *, std::unique_ptr<HeaderMap>>> HeaderMaps;
309 mutable ModuleMap ModMap;
312 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
316 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
319 llvm::DenseMap<const FileEntry *, llvm::SmallString<64>> IncludeNames;
323 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
328 ExternalPreprocessorSource *ExternalLookup =
nullptr;
331 ExternalHeaderFileInfoSource *ExternalSource =
nullptr;
334 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
335 SourceManager &SourceMgr, DiagnosticsEngine &Diags,
336 const LangOptions &LangOpts,
const TargetInfo *Target);
349 void SetSearchPaths(std::vector<DirectoryLookup> dirs,
unsigned angledDirIdx,
350 unsigned systemDirIdx,
bool noCurDirSearch,
351 llvm::DenseMap<unsigned, unsigned> searchDirToHSEntry);
358 SearchDirs.push_back(dir);
359 SearchDirsUsage.push_back(
false);
364 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
376 IncludeAliases.reset(
new IncludeAliasMap);
385 assert(IncludeAliases &&
"Trying to map headers when there's no map");
388 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
389 if (Iter != IncludeAliases->end())
410 DirectoryHasModuleMap[Dir] =
true;
419 ExternalLookup = EPS;
423 return ExternalLookup;
473 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
476 bool *IsMapped,
bool *IsFrameworkFound,
bool SkipCache =
false,
477 bool BuildSystemModule =
false);
493 return FrameworkMap[FWName];
502 bool isImport,
bool ModulesEnabled,
Module *M,
503 bool &IsFirstIncludeOfFile);
527 bool isCompilingModuleHeader);
583 bool FileMapOnly =
false);
605 StringRef ModuleMapPath);
623 bool AllowSearch =
true,
624 bool AllowExtraModuleMapSearch =
false);
650 bool AllowTextual =
false)
const;
673 StringRef OriginalModuleMapFile = StringRef());
701 bool AllowExtraModuleMapSearch =
false);
715 std::string getCachedModuleFileNameImpl(StringRef ModuleName,
716 StringRef ModuleMapPath,
717 StringRef CachePath);
730 Module *loadFrameworkModule(StringRef Name,
742 bool findUsableModuleForHeader(
const FileEntry *File,
746 bool IsSystemHeaderDir);
753 bool findUsableModuleForFrameworkHeader(
754 const FileEntry *File, StringRef FrameworkName,
Module *RequestingModule,
760 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
767 void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
793 bool WantExternal =
true)
const;
813 return {*
this, AngledDirIdx};
818 return {*
this, SystemDirIdx};
821 return {*
this, SearchDirs.size()};
847 llvm::StringRef MainFile,
848 bool *IsSystem =
nullptr);
860 llvm::StringRef WorkingDir,
861 llvm::StringRef MainFile,
862 bool *IsSystem =
nullptr);
870 enum LoadModuleMapResult {
885 LoadModuleMapResult loadModuleMapFileImpl(
const FileEntry *File,
887 const DirectoryEntry *Dir,
888 FileID
ID = FileID(),
889 unsigned *
Offset =
nullptr);
912 bool IsSystem,
bool IsFramework);
917 const HeaderSearchOptions &HSOpts,
918 const LangOptions &Lang,
919 const llvm::Triple &triple);
923 #endif // LLVM_CLANG_LEX_HEADERSEARCH_H