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"
43class DiagnosticsEngine;
45class ExternalPreprocessorSource;
49class HeaderSearchOptions;
157template <
bool Const,
typename T>
161template <
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;
255 llvm::StringMap<unsigned, llvm::BumpPtrAllocator> SearchDirHeaderMapIndex;
258 unsigned FirstNonHeaderMapSearchDirIdx = 0;
266 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
269 std::string ModuleHash;
272 std::string ModuleCachePath;
276 mutable std::vector<HeaderFileInfo> FileInfo;
279 struct LookupFileCacheInfo {
290 const char *MappedName =
nullptr;
293 LookupFileCacheInfo() =
default;
296 StartIt = NewStartIt;
297 MappedName =
nullptr;
300 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
304 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
309 using IncludeAliasMap =
310 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
311 std::unique_ptr<IncludeAliasMap> IncludeAliases;
314 std::vector<std::pair<const FileEntry *, std::unique_ptr<HeaderMap>>> HeaderMaps;
317 mutable ModuleMap ModMap;
320 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
324 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
327 llvm::DenseMap<const FileEntry *, llvm::SmallString<64>> IncludeNames;
331 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
336 ExternalPreprocessorSource *ExternalLookup =
nullptr;
339 ExternalHeaderFileInfoSource *ExternalSource =
nullptr;
343 void indexInitialHeaderMaps();
346 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
347 SourceManager &SourceMgr, DiagnosticsEngine &Diags,
348 const LangOptions &LangOpts,
const TargetInfo *
Target);
361 void SetSearchPaths(std::vector<DirectoryLookup> dirs,
unsigned angledDirIdx,
362 unsigned systemDirIdx,
bool noCurDirSearch,
363 llvm::DenseMap<unsigned, unsigned> searchDirToHSEntry);
370 SearchDirs.push_back(dir);
371 SearchDirsUsage.push_back(
false);
376 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
388 IncludeAliases.reset(
new IncludeAliasMap);
389 (*IncludeAliases)[Source] = std::string(Dest);
397 assert(IncludeAliases &&
"Trying to map headers when there's no map");
400 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
401 if (Iter != IncludeAliases->end())
411 ModuleCachePath = std::string(CachePath);
422 DirectoryHasModuleMap[Dir] =
true;
431 ExternalLookup = EPS;
435 return ExternalLookup;
485 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
488 bool *IsMapped,
bool *IsFrameworkFound,
bool SkipCache =
false,
489 bool BuildSystemModule =
false,
bool OpenFile =
true,
490 bool CacheFailures =
true);
506 return FrameworkMap[FWName];
515 bool isImport,
bool ModulesEnabled,
Module *M,
516 bool &IsFirstIncludeOfFile);
540 bool isCompilingModuleHeader);
596 bool FileMapOnly =
false);
618 StringRef ModuleMapPath);
636 bool AllowSearch =
true,
637 bool AllowExtraModuleMapSearch =
false);
663 bool AllowTextual =
false,
664 bool AllowExcluded =
false)
const;
687 StringRef OriginalModuleMapFile = StringRef());
715 bool AllowExtraModuleMapSearch =
false);
729 std::string getCachedModuleFileNameImpl(StringRef ModuleName,
730 StringRef ModuleMapPath,
731 StringRef CachePath);
759 bool IsSystemHeaderDir);
766 bool findUsableModuleForFrameworkHeader(
773 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
777 bool OpenFile =
true,
bool CacheFailures =
true);
781 void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
807 bool WantExternal =
true)
const;
817 assert(n < SearchDirs.size());
831 return {*
this, AngledDirIdx};
836 return {*
this, SystemDirIdx};
839 return {*
this, SearchDirs.size()};
865 llvm::StringRef MainFile,
866 bool *IsSystem =
nullptr);
878 llvm::StringRef WorkingDir,
879 llvm::StringRef MainFile,
880 bool *IsSystem =
nullptr);
888 enum LoadModuleMapResult {
903 LoadModuleMapResult loadModuleMapFileImpl(
const FileEntry *
File,
905 DirectoryEntryRef Dir,
906 FileID ID = FileID(),
907 unsigned *
Offset =
nullptr);
935 const HeaderSearchOptions &HSOpts,
936 const LangOptions &Lang,
937 const llvm::Triple &triple);
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Concrete class used by the front-end to report problems and issues.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
Cached information about one directory (either on disk or in the virtual file system).
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
Abstract interface for external sources of preprocessor information.
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...
Implements support for file system lookup, file system caching, and directory search management.
One of these records is kept for each identifier that is lexed.
ModuleHeaderRole
Flags describing the role of a module header.
Describes a module or submodule.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
Exposes information about the current target.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
std::conditional_t< Const, const T, T > Qualified
void ApplyHeaderSearchOptions(HeaderSearch &HS, const HeaderSearchOptions &HSOpts, const LangOptions &Lang, const llvm::Triple &triple)
Apply the header search options to get given HeaderSearch object.
llvm::iterator_range< SearchDirIterator > SearchDirRange
llvm::iterator_range< ConstSearchDirIterator > ConstSearchDirRange
YAML serialization mapping.
This structure is used to record entries in our framework cache.
bool IsUserSpecifiedSystemFramework
Whether this framework has been "user-specified" to be treated as if it were a system framework (even...
OptionalDirectoryEntryRef Directory
The directory entry which should be used for the cached framework.
Forward iterator over the search directories of HeaderSearch.
SearchDirIteratorImpl(std::nullptr_t)
Creates an invalid iterator.
Qualified< IsConst, DirectoryLookup > & operator*() const
bool operator==(const SearchDirIteratorImpl &RHS) const
SearchDirIteratorImpl(const SearchDirIteratorImpl< false > &Other)
Const -> non-const iterator conversion.
SearchDirIteratorImpl & operator++()
SearchDirIteratorImpl & operator=(const SearchDirIteratorImpl &)=default
SearchDirIteratorImpl(const SearchDirIteratorImpl &)=default