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 {
281 const Module *RequestingModule =
nullptr;
293 const char *MappedName =
nullptr;
296 LookupFileCacheInfo() =
default;
298 void reset(
const Module *NewRequestingModule,
300 RequestingModule = NewRequestingModule;
301 StartIt = NewStartIt;
302 MappedName =
nullptr;
305 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
309 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
314 using IncludeAliasMap =
315 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
316 std::unique_ptr<IncludeAliasMap> IncludeAliases;
319 std::vector<std::pair<FileEntryRef, std::unique_ptr<HeaderMap>>> HeaderMaps;
322 mutable ModuleMap ModMap;
325 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
329 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
332 llvm::DenseMap<const FileEntry *, llvm::SmallString<64>> IncludeNames;
336 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
341 ExternalPreprocessorSource *ExternalLookup =
nullptr;
344 ExternalHeaderFileInfoSource *ExternalSource =
nullptr;
348 void indexInitialHeaderMaps();
351 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
352 SourceManager &SourceMgr, DiagnosticsEngine &Diags,
353 const LangOptions &LangOpts,
const TargetInfo *
Target);
366 void SetSearchPaths(std::vector<DirectoryLookup> dirs,
unsigned angledDirIdx,
367 unsigned systemDirIdx,
bool noCurDirSearch,
368 llvm::DenseMap<unsigned, unsigned> searchDirToHSEntry);
375 SearchDirs.push_back(dir);
376 SearchDirsUsage.push_back(
false);
381 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
393 IncludeAliases.reset(
new IncludeAliasMap);
394 (*IncludeAliases)[Source] = std::string(Dest);
402 assert(IncludeAliases &&
"Trying to map headers when there's no map");
405 IncludeAliasMap::const_iterator
Iter = IncludeAliases->find(Source);
406 if (
Iter != IncludeAliases->end())
416 ModuleCachePath = std::string(CachePath);
427 DirectoryHasModuleMap[Dir] =
true;
436 ExternalLookup = EPS;
440 return ExternalLookup;
490 ArrayRef<std::pair<const FileEntry *, DirectoryEntryRef>> Includers,
493 bool *IsMapped,
bool *IsFrameworkFound,
bool SkipCache =
false,
494 bool BuildSystemModule =
false,
bool OpenFile =
true,
495 bool CacheFailures =
true);
511 return FrameworkMap[FWName];
520 bool isImport,
bool ModulesEnabled,
Module *M,
521 bool &IsFirstIncludeOfFile);
545 bool isCompilingModuleHeader);
601 bool FileMapOnly =
false);
623 StringRef ModuleMapPath);
641 bool AllowSearch =
true,
642 bool AllowExtraModuleMapSearch =
false);
668 bool AllowTextual =
false,
669 bool AllowExcluded =
false)
const;
696 unsigned *Offset =
nullptr,
697 StringRef OriginalModuleMapFile = StringRef());
725 bool AllowExtraModuleMapSearch =
false);
739 std::string getCachedModuleFileNameImpl(StringRef ModuleName,
740 StringRef ModuleMapPath,
741 StringRef CachePath);
768 bool IsSystemHeaderDir);
775 bool findUsableModuleForFrameworkHeader(
782 getFileAndSuggestModule(StringRef FileName,
SourceLocation IncludeLoc,
786 bool OpenFile =
true,
bool CacheFailures =
true);
790 void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
816 bool WantExternal =
true)
const;
826 assert(n < SearchDirs.size());
840 return {*
this, AngledDirIdx};
845 return {*
this, SystemDirIdx};
848 return {*
this, SearchDirs.size()};
874 llvm::StringRef MainFile,
875 bool *IsAngled =
nullptr)
const;
887 llvm::StringRef WorkingDir,
888 llvm::StringRef MainFile,
889 bool *IsAngled =
nullptr)
const;
897 enum LoadModuleMapResult {
912 LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef
File,
bool IsSystem,
913 DirectoryEntryRef Dir,
914 FileID
ID = FileID(),
915 unsigned *Offset =
nullptr);
943 const HeaderSearchOptions &HSOpts,
944 const LangOptions &Lang,
945 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.
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
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