13#ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
14#define LLVM_CLANG_LEX_HEADERSEARCH_H
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/SmallString.h"
25#include "llvm/ADT/StringMap.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/ADT/StringSet.h"
28#include "llvm/Support/Allocator.h"
44class DiagnosticsEngine;
46class ExternalPreprocessorSource;
50class HeaderSearchOptions;
63 LLVM_PREFERRED_TYPE(
bool)
69 LLVM_PREFERRED_TYPE(
bool)
73 LLVM_PREFERRED_TYPE(
bool)
80 LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)
85 LLVM_PREFERRED_TYPE(
bool)
91 LLVM_PREFERRED_TYPE(
bool)
97 LLVM_PREFERRED_TYPE(
bool)
103 LLVM_PREFERRED_TYPE(
bool)
108 LLVM_PREFERRED_TYPE(
bool)
112 LLVM_PREFERRED_TYPE(
bool)
143static_assert(
sizeof(HeaderFileInfo) <= 16);
171template <
bool Const,
typename T>
175template <
bool IsConst>
177 : llvm::iterator_facade_base<SearchDirIteratorImpl<IsConst>,
178 std::forward_iterator_tag,
179 Qualified<IsConst, DirectoryLookup>> {
181 template <
typename Enable = std::enable_if<IsConst,
bool>>
190 return HS == RHS.HS && Idx == RHS.Idx;
194 assert(*
this &&
"Invalid iterator.");
200 assert(*
this &&
"Invalid iterator.");
201 return HS->SearchDirs[Idx];
208 explicit operator bool()
const {
return HS !=
nullptr; }
219 : HS(&HS), Idx(Idx) {}
225 friend SearchDirIteratorImpl<!IsConst>;
244 std::shared_ptr<HeaderSearchOptions> HSOpts;
247 llvm::DenseMap<unsigned, unsigned> SearchDirToHSEntry;
256 std::vector<DirectoryLookup> SearchDirs;
259 std::vector<bool> SearchDirsUsage;
260 unsigned AngledDirIdx = 0;
261 unsigned SystemDirIdx = 0;
266 llvm::StringMap<unsigned, llvm::BumpPtrAllocator> SearchDirHeaderMapIndex;
269 unsigned FirstNonHeaderMapSearchDirIdx = 0;
277 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
280 std::string ModuleHash;
283 std::string ModuleCachePath;
287 mutable std::vector<HeaderFileInfo> FileInfo;
290 struct LookupFileCacheInfo {
292 const Module *RequestingModule =
nullptr;
304 const char *MappedName =
nullptr;
307 LookupFileCacheInfo() =
default;
309 void reset(
const Module *NewRequestingModule,
311 RequestingModule = NewRequestingModule;
312 StartIt = NewStartIt;
313 MappedName =
nullptr;
316 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
320 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
325 using IncludeAliasMap =
326 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
327 std::unique_ptr<IncludeAliasMap> IncludeAliases;
330 std::vector<std::pair<FileEntryRef, std::unique_ptr<HeaderMap>>> HeaderMaps;
333 mutable ModuleMap ModMap;
336 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
340 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
343 llvm::DenseMap<const FileEntry *, llvm::SmallString<64>> IncludeNames;
347 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
352 ExternalPreprocessorSource *ExternalLookup =
nullptr;
355 ExternalHeaderFileInfoSource *ExternalSource =
nullptr;
359 void indexInitialHeaderMaps();
362 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
363 SourceManager &SourceMgr, DiagnosticsEngine &Diags,
364 const LangOptions &LangOpts,
const TargetInfo *
Target);
377 void SetSearchPaths(std::vector<DirectoryLookup> dirs,
unsigned angledDirIdx,
378 unsigned systemDirIdx,
379 llvm::DenseMap<unsigned, unsigned> searchDirToHSEntry);
386 SearchDirs.push_back(dir);
387 SearchDirsUsage.push_back(
false);
392 SystemHeaderPrefixes.assign(
P.begin(),
P.end());
404 IncludeAliases.reset(
new IncludeAliasMap);
405 (*IncludeAliases)[Source] = std::string(Dest);
413 assert(IncludeAliases &&
"Trying to map headers when there's no map");
416 IncludeAliasMap::const_iterator
Iter = IncludeAliases->find(Source);
417 if (
Iter != IncludeAliases->end())
427 ModuleCachePath = std::string(CachePath);
438 DirectoryHasModuleMap[Dir] =
true;
447 ExternalLookup = EPS;
451 return ExternalLookup;
501 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>> Includers,
504 bool *IsMapped,
bool *IsFrameworkFound,
bool SkipCache =
false,
505 bool BuildSystemModule =
false,
bool OpenFile =
true,
506 bool CacheFailures =
true);
522 return FrameworkMap[FWName];
534 bool isImport,
bool ModulesEnabled,
Module *M,
535 bool &IsFirstIncludeOfFile);
559 bool isCompilingModuleHeader);
622 bool FileMapOnly =
false);
644 StringRef ModuleMapPath);
662 bool AllowSearch =
true,
663 bool AllowExtraModuleMapSearch =
false);
689 bool AllowTextual =
false,
690 bool AllowExcluded =
false)
const;
717 unsigned *Offset =
nullptr,
718 StringRef OriginalModuleMapFile = StringRef());
746 bool AllowExtraModuleMapSearch =
false);
760 std::string getCachedModuleFileNameImpl(StringRef ModuleName,
761 StringRef ModuleMapPath,
762 StringRef CachePath);
789 bool IsSystemHeaderDir);
796 bool findUsableModuleForFrameworkHeader(
807 bool OpenFile =
true,
bool CacheFailures =
true);
811 void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
848 assert(n < SearchDirs.size());
862 return {*
this, AngledDirIdx};
867 return {*
this, SystemDirIdx};
870 return {*
this, SearchDirs.size()};
896 llvm::StringRef MainFile,
897 bool *IsAngled =
nullptr)
const;
909 llvm::StringRef WorkingDir,
910 llvm::StringRef MainFile,
911 bool *IsAngled =
nullptr)
const;
919 enum LoadModuleMapResult {
934 LoadModuleMapResult loadModuleMapFileImpl(FileEntryRef
File,
bool IsSystem,
935 DirectoryEntryRef Dir,
936 FileID
ID = FileID(),
937 unsigned *Offset =
nullptr);
965 const HeaderSearchOptions &HSOpts,
966 const LangOptions &Lang,
967 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
Diagnostic wrappers for TextAPI types for error reporting.
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