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;
62 LLVM_PREFERRED_TYPE(
bool)
66 LLVM_PREFERRED_TYPE(
bool)
73 LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)
78 LLVM_PREFERRED_TYPE(
bool)
82 LLVM_PREFERRED_TYPE(
bool)
86 LLVM_PREFERRED_TYPE(
bool)
91 LLVM_PREFERRED_TYPE(
bool)
101 LLVM_PREFERRED_TYPE(
bool)
105 LLVM_PREFERRED_TYPE(
bool)
166template <
bool Const,
typename T>
170template <
bool IsConst>
172 : llvm::iterator_facade_base<SearchDirIteratorImpl<IsConst>,
173 std::forward_iterator_tag,
174 Qualified<IsConst, DirectoryLookup>> {
176 template <
typename Enable = std::enable_if<IsConst,
bool>>
185 return HS == RHS.HS && Idx == RHS.Idx;
189 assert(*
this &&
"Invalid iterator.");
195 assert(*
this &&
"Invalid iterator.");
196 return HS->SearchDirs[Idx];
203 explicit operator bool()
const {
return HS !=
nullptr; }
214 : HS(&HS), Idx(Idx) {}
220 friend SearchDirIteratorImpl<!IsConst>;
239 std::shared_ptr<HeaderSearchOptions> HSOpts;
242 llvm::DenseMap<unsigned, unsigned> SearchDirToHSEntry;
251 std::vector<DirectoryLookup> SearchDirs;
254 std::vector<bool> SearchDirsUsage;
255 unsigned AngledDirIdx = 0;
256 unsigned SystemDirIdx = 0;
261 llvm::StringMap<unsigned, llvm::BumpPtrAllocator> SearchDirHeaderMapIndex;
264 unsigned FirstNonHeaderMapSearchDirIdx = 0;
272 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
275 std::string ModuleHash;
278 std::string ModuleCachePath;
282 mutable std::vector<HeaderFileInfo> FileInfo;
285 struct LookupFileCacheInfo {
287 const Module *RequestingModule =
nullptr;
299 const char *MappedName =
nullptr;
302 LookupFileCacheInfo() =
default;
304 void reset(
const Module *NewRequestingModule,
306 RequestingModule = NewRequestingModule;
307 StartIt = NewStartIt;
308 MappedName =
nullptr;
311 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
315 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
320 using IncludeAliasMap =
321 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
322 std::unique_ptr<IncludeAliasMap> IncludeAliases;
325 std::vector<std::pair<FileEntryRef, std::unique_ptr<HeaderMap>>> HeaderMaps;
328 mutable ModuleMap ModMap;
331 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
335 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
338 llvm::DenseMap<const FileEntry *, llvm::SmallString<64>> IncludeNames;
342 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
347 ExternalPreprocessorSource *ExternalLookup =
nullptr;
350 ExternalHeaderFileInfoSource *ExternalSource =
nullptr;
354 void indexInitialHeaderMaps();
357 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
358 SourceManager &SourceMgr, DiagnosticsEngine &Diags,
359 const LangOptions &LangOpts,
const TargetInfo *
Target);
372 void SetSearchPaths(std::vector<DirectoryLookup> dirs,
unsigned angledDirIdx,
373 unsigned systemDirIdx,
374 llvm::DenseMap<unsigned, unsigned> searchDirToHSEntry);
381 SearchDirs.push_back(dir);
382 SearchDirsUsage.push_back(
false);
387 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
399 IncludeAliases.reset(
new IncludeAliasMap);
400 (*IncludeAliases)[Source] = std::string(Dest);
408 assert(IncludeAliases &&
"Trying to map headers when there's no map");
411 IncludeAliasMap::const_iterator
Iter = IncludeAliases->find(Source);
412 if (
Iter != IncludeAliases->end())
422 ModuleCachePath = std::string(CachePath);
433 DirectoryHasModuleMap[Dir] =
true;
442 ExternalLookup = EPS;
446 return ExternalLookup;
496 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>> Includers,
499 bool *IsMapped,
bool *IsFrameworkFound,
bool SkipCache =
false,
500 bool BuildSystemModule =
false,
bool OpenFile =
true,
501 bool CacheFailures =
true);
517 return FrameworkMap[FWName];
526 bool isImport,
bool ModulesEnabled,
Module *M,
527 bool &IsFirstIncludeOfFile);
550 bool isCompilingModuleHeader);
613 bool FileMapOnly =
false);
635 StringRef ModuleMapPath);
653 bool AllowSearch =
true,
654 bool AllowExtraModuleMapSearch =
false);
680 bool AllowTextual =
false,
681 bool AllowExcluded =
false)
const;
708 unsigned *Offset =
nullptr,
709 StringRef OriginalModuleMapFile = StringRef());
737 bool AllowExtraModuleMapSearch =
false);
751 std::string getCachedModuleFileNameImpl(StringRef ModuleName,
752 StringRef ModuleMapPath,
753 StringRef CachePath);
780 bool IsSystemHeaderDir);
787 bool findUsableModuleForFrameworkHeader(
798 bool OpenFile =
true,
bool CacheFailures =
true);
802 void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
828 bool WantExternal =
true)
const;
838 assert(n < SearchDirs.size());
852 return {*
this, AngledDirIdx};
857 return {*
this, SystemDirIdx};
860 return {*
this, SearchDirs.size()};
886 llvm::StringRef MainFile,
887 bool *IsAngled =
nullptr)
const;
899 llvm::StringRef WorkingDir,
900 llvm::StringRef MainFile,
901 bool *IsAngled =
nullptr)
const;
909 enum LoadModuleMapResult {
924 LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef
File,
bool IsSystem,
925 DirectoryEntryRef Dir,
926 FileID
ID = FileID(),
927 unsigned *Offset =
nullptr);
955 const HeaderSearchOptions &HSOpts,
956 const LangOptions &Lang,
957 const llvm::Triple &triple);
llvm::MachO::Target Target
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.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
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
The JSON file list parser is used to communicate input to InstallAPI.
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
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ Other
Other implicit parameter.
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