1 //===- HeaderSearch.h - Resolve Header File Locations -----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the HeaderSearch interface.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
14 #define LLVM_CLANG_LEX_HEADERSEARCH_H
16 #include "clang/Basic/SourceLocation.h"
17 #include "clang/Basic/SourceManager.h"
18 #include "clang/Lex/DirectoryLookup.h"
19 #include "clang/Lex/HeaderMap.h"
20 #include "clang/Lex/ModuleMap.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringSet.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Support/Allocator.h"
36 class DiagnosticsEngine;
38 class ExternalPreprocessorSource;
41 class HeaderSearchOptions;
48 /// The preprocessor keeps track of this information for each
49 /// file that is \#included.
50 struct HeaderFileInfo {
51 /// True if this is a \#import'd or \#pragma once file.
52 unsigned isImport : 1;
54 /// True if this is a \#pragma once file.
55 unsigned isPragmaOnce : 1;
57 /// Keep track of whether this is a system header, and if so,
58 /// whether it is C++ clean or not. This can be set by the include paths or
59 /// by \#pragma gcc system_header. This is an instance of
60 /// SrcMgr::CharacteristicKind.
63 /// Whether this header file info was supplied by an external source,
64 /// and has not changed since.
65 unsigned External : 1;
67 /// Whether this header is part of a module.
68 unsigned isModuleHeader : 1;
70 /// Whether this header is part of the module that we are building.
71 unsigned isCompilingModuleHeader : 1;
73 /// Whether this structure is considered to already have been
74 /// "resolved", meaning that it was loaded from the external source.
75 unsigned Resolved : 1;
77 /// Whether this is a header inside a framework that is currently
80 /// When a framework is being built, the headers have not yet been placed
81 /// into the appropriate framework subdirectories, and therefore are
82 /// provided via a header map. This bit indicates when this is one of
83 /// those framework headers.
84 unsigned IndexHeaderMapHeader : 1;
86 /// Whether this file has been looked up as a header.
89 /// The number of times the file has been included already.
90 unsigned short NumIncludes = 0;
92 /// The ID number of the controlling macro.
94 /// This ID number will be non-zero when there is a controlling
95 /// macro whose IdentifierInfo may not yet have been loaded from
97 unsigned ControllingMacroID = 0;
99 /// If this file has a \#ifndef XXX (or equivalent) guard that
100 /// protects the entire contents of the file, this is the identifier
101 /// for the macro that controls whether or not it has any effect.
103 /// Note: Most clients should use getControllingMacro() to access
104 /// the controlling macro of this header, since
105 /// getControllingMacro() is able to load a controlling macro from
106 /// external storage.
107 const IdentifierInfo *ControllingMacro = nullptr;
109 /// If this header came from a framework include, this is the name
110 /// of the framework.
114 : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User),
115 External(false), isModuleHeader(false), isCompilingModuleHeader(false),
116 Resolved(false), IndexHeaderMapHeader(false), IsValid(false) {}
118 /// Retrieve the controlling macro for this header file, if
120 const IdentifierInfo *
121 getControllingMacro(ExternalPreprocessorSource *External);
123 /// Determine whether this is a non-default header file info, e.g.,
124 /// it corresponds to an actual header we've included or tried to include.
125 bool isNonDefault() const {
126 return isImport || isPragmaOnce || NumIncludes || ControllingMacro ||
131 /// An external source of header file information, which may supply
132 /// information about header files already included.
133 class ExternalHeaderFileInfoSource {
135 virtual ~ExternalHeaderFileInfoSource();
137 /// Retrieve the header file information for the given file entry.
139 /// \returns Header file information for the given file entry, with the
140 /// \c External bit set. If the file entry is not known, return a
141 /// default-constructed \c HeaderFileInfo.
142 virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0;
145 /// This structure is used to record entries in our framework cache.
146 struct FrameworkCacheEntry {
147 /// The directory entry which should be used for the cached framework.
148 const DirectoryEntry *Directory;
150 /// Whether this framework has been "user-specified" to be treated as if it
151 /// were a system framework (even if it was found outside a system framework
153 bool IsUserSpecifiedSystemFramework;
156 /// Encapsulates the information needed to find the file referenced
157 /// by a \#include or \#include_next, (sub-)framework lookup, etc.
159 friend class DirectoryLookup;
161 /// Header-search options used to initialize this header search.
162 std::shared_ptr<HeaderSearchOptions> HSOpts;
164 DiagnosticsEngine &Diags;
165 FileManager &FileMgr;
167 /// \#include search path information. Requests for \#include "x" search the
168 /// directory of the \#including file first, then each directory in SearchDirs
169 /// consecutively. Requests for <x> search the current dir first, then each
170 /// directory in SearchDirs, starting at AngledDirIdx, consecutively. If
171 /// NoCurDirSearch is true, then the check for the file in the current
172 /// directory is suppressed.
173 std::vector<DirectoryLookup> SearchDirs;
174 unsigned AngledDirIdx = 0;
175 unsigned SystemDirIdx = 0;
176 bool NoCurDirSearch = false;
178 /// \#include prefixes for which the 'system header' property is
181 /// For a \#include "x" or \#include \<x> directive, the last string in this
182 /// list which is a prefix of 'x' determines whether the file is treated as
184 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
186 /// The path to the module cache.
187 std::string ModuleCachePath;
189 /// All of the preprocessor-specific data about files that are
190 /// included, indexed by the FileEntry's UID.
191 mutable std::vector<HeaderFileInfo> FileInfo;
193 /// Keeps track of each lookup performed by LookupFile.
194 struct LookupFileCacheInfo {
195 /// Starting index in SearchDirs that the cached search was performed from.
196 /// If there is a hit and this value doesn't match the current query, the
197 /// cache has to be ignored.
198 unsigned StartIdx = 0;
200 /// The entry in SearchDirs that satisfied the query.
203 /// This is non-null if the original filename was mapped to a framework
204 /// include via a headermap.
205 const char *MappedName = nullptr;
207 /// Default constructor -- Initialize all members with zero.
208 LookupFileCacheInfo() = default;
210 void reset(unsigned StartIdx) {
211 this->StartIdx = StartIdx;
212 this->MappedName = nullptr;
215 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
217 /// Collection mapping a framework or subframework
218 /// name like "Carbon" to the Carbon.framework directory.
219 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
221 /// Maps include file names (including the quotes or
222 /// angle brackets) to other include file names. This is used to support the
223 /// include_alias pragma for Microsoft compatibility.
224 using IncludeAliasMap =
225 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
226 std::unique_ptr<IncludeAliasMap> IncludeAliases;
228 /// This is a mapping from FileEntry -> HeaderMap, uniquing headermaps.
229 std::vector<std::pair<const FileEntry *, std::unique_ptr<HeaderMap>>> HeaderMaps;
231 /// The mapping between modules and headers.
232 mutable ModuleMap ModMap;
234 /// Describes whether a given directory has a module map in it.
235 llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
237 /// Set of module map files we've already loaded, and a flag indicating
238 /// whether they were valid or not.
239 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
241 /// Uniqued set of framework names, which is used to track which
242 /// headers were included as framework headers.
243 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
245 /// Entity used to resolve the identifier IDs of controlling
246 /// macros into IdentifierInfo pointers, and keep the identifire up to date,
248 ExternalPreprocessorSource *ExternalLookup = nullptr;
250 /// Entity used to look up stored header file information.
251 ExternalHeaderFileInfoSource *ExternalSource = nullptr;
253 // Various statistics we track for performance analysis.
254 unsigned NumIncluded = 0;
255 unsigned NumMultiIncludeFileOptzn = 0;
256 unsigned NumFrameworkLookups = 0;
257 unsigned NumSubFrameworkLookups = 0;
260 HeaderSearch(std::shared_ptr<HeaderSearchOptions> HSOpts,
261 SourceManager &SourceMgr, DiagnosticsEngine &Diags,
262 const LangOptions &LangOpts, const TargetInfo *Target);
263 HeaderSearch(const HeaderSearch &) = delete;
264 HeaderSearch &operator=(const HeaderSearch &) = delete;
266 /// Retrieve the header-search options with which this header search
268 HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; }
270 FileManager &getFileMgr() const { return FileMgr; }
272 DiagnosticsEngine &getDiags() const { return Diags; }
274 /// Interface for setting the file search paths.
275 void SetSearchPaths(const std::vector<DirectoryLookup> &dirs,
276 unsigned angledDirIdx, unsigned systemDirIdx,
277 bool noCurDirSearch) {
278 assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
279 "Directory indices are unordered");
281 AngledDirIdx = angledDirIdx;
282 SystemDirIdx = systemDirIdx;
283 NoCurDirSearch = noCurDirSearch;
284 //LookupFileCache.clear();
287 /// Add an additional search path.
288 void AddSearchPath(const DirectoryLookup &dir, bool isAngled) {
289 unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
290 SearchDirs.insert(SearchDirs.begin() + idx, dir);
296 /// Set the list of system header prefixes.
297 void SetSystemHeaderPrefixes(ArrayRef<std::pair<std::string, bool>> P) {
298 SystemHeaderPrefixes.assign(P.begin(), P.end());
301 /// Checks whether the map exists or not.
302 bool HasIncludeAliasMap() const { return (bool)IncludeAliases; }
304 /// Map the source include name to the dest include name.
306 /// The Source should include the angle brackets or quotes, the dest
307 /// should not. This allows for distinction between <> and "" headers.
308 void AddIncludeAlias(StringRef Source, StringRef Dest) {
310 IncludeAliases.reset(new IncludeAliasMap);
311 (*IncludeAliases)[Source] = Dest;
314 /// Maps one header file name to a different header
315 /// file name, for use with the include_alias pragma. Note that the source
316 /// file name should include the angle brackets or quotes. Returns StringRef
317 /// as null if the header cannot be mapped.
318 StringRef MapHeaderToIncludeAlias(StringRef Source) {
319 assert(IncludeAliases && "Trying to map headers when there's no map");
321 // Do any filename replacements before anything else
322 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
323 if (Iter != IncludeAliases->end())
328 /// Set the path to the module cache.
329 void setModuleCachePath(StringRef CachePath) {
330 ModuleCachePath = CachePath;
333 /// Retrieve the path to the module cache.
334 StringRef getModuleCachePath() const { return ModuleCachePath; }
336 /// Consider modules when including files from this directory.
337 void setDirectoryHasModuleMap(const DirectoryEntry* Dir) {
338 DirectoryHasModuleMap[Dir] = true;
341 /// Forget everything we know about headers so far.
342 void ClearFileInfo() {
346 void SetExternalLookup(ExternalPreprocessorSource *EPS) {
347 ExternalLookup = EPS;
350 ExternalPreprocessorSource *getExternalLookup() const {
351 return ExternalLookup;
354 /// Set the external source of header information.
355 void SetExternalSource(ExternalHeaderFileInfoSource *ES) {
359 /// Set the target information for the header search, if not
361 void setTarget(const TargetInfo &Target);
363 /// Given a "foo" or \<foo> reference, look up the indicated file,
364 /// return null on failure.
366 /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member
367 /// the file was found in, or null if not applicable.
369 /// \param IncludeLoc Used for diagnostics if valid.
371 /// \param isAngled indicates whether the file reference is a <> reference.
373 /// \param CurDir If non-null, the file was found in the specified directory
374 /// search location. This is used to implement \#include_next.
376 /// \param Includers Indicates where the \#including file(s) are, in case
377 /// relative searches are needed. In reverse order of inclusion.
379 /// \param SearchPath If non-null, will be set to the search path relative
380 /// to which the file was found. If the include path is absolute, SearchPath
381 /// will be set to an empty string.
383 /// \param RelativePath If non-null, will be set to the path relative to
384 /// SearchPath at which the file was found. This only differs from the
385 /// Filename for framework includes.
387 /// \param SuggestedModule If non-null, and the file found is semantically
388 /// part of a known module, this will be set to the module that should
389 /// be imported instead of preprocessing/parsing the file found.
391 /// \param IsMapped If non-null, and the search involved header maps, set to
394 /// \param IsFrameworkFound If non-null, will be set to true if a framework is
395 /// found in any of searched SearchDirs. Will be set to false if a framework
396 /// is found only through header maps. Doesn't guarantee the requested file is
398 const FileEntry *LookupFile(
399 StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
400 const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir,
401 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
402 SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
403 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
404 bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false,
405 bool BuildSystemModule = false);
407 /// Look up a subframework for the specified \#include file.
409 /// For example, if \#include'ing <HIToolbox/HIToolbox.h> from
410 /// within ".../Carbon.framework/Headers/Carbon.h", check to see if
411 /// HIToolbox is a subframework within Carbon.framework. If so, return
412 /// the FileEntry for the designated file, otherwise return null.
413 const FileEntry *LookupSubframeworkHeader(
414 StringRef Filename, const FileEntry *ContextFileEnt,
415 SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
416 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule);
418 /// Look up the specified framework name in our framework cache.
419 /// \returns The DirectoryEntry it is in if we know, null otherwise.
420 FrameworkCacheEntry &LookupFrameworkCache(StringRef FWName) {
421 return FrameworkMap[FWName];
424 /// Mark the specified file as a target of a \#include,
425 /// \#include_next, or \#import directive.
427 /// \return false if \#including the file will have no effect or true
428 /// if we should include it.
429 bool ShouldEnterIncludeFile(Preprocessor &PP, const FileEntry *File,
430 bool isImport, bool ModulesEnabled,
433 /// Return whether the specified file is a normal header,
434 /// a system header, or a C++ friendly system header.
435 SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File) {
436 return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo;
439 /// Mark the specified file as a "once only" file, e.g. due to
441 void MarkFileIncludeOnce(const FileEntry *File) {
442 HeaderFileInfo &FI = getFileInfo(File);
444 FI.isPragmaOnce = true;
447 /// Mark the specified file as a system header, e.g. due to
448 /// \#pragma GCC system_header.
449 void MarkFileSystemHeader(const FileEntry *File) {
450 getFileInfo(File).DirInfo = SrcMgr::C_System;
453 /// Mark the specified file as part of a module.
454 void MarkFileModuleHeader(const FileEntry *FE,
455 ModuleMap::ModuleHeaderRole Role,
456 bool isCompilingModuleHeader);
458 /// Increment the count for the number of times the specified
459 /// FileEntry has been entered.
460 void IncrementIncludeCount(const FileEntry *File) {
461 ++getFileInfo(File).NumIncludes;
464 /// Mark the specified file as having a controlling macro.
466 /// This is used by the multiple-include optimization to eliminate
467 /// no-op \#includes.
468 void SetFileControllingMacro(const FileEntry *File,
469 const IdentifierInfo *ControllingMacro) {
470 getFileInfo(File).ControllingMacro = ControllingMacro;
473 /// Return true if this is the first time encountering this header.
474 bool FirstTimeLexingFile(const FileEntry *File) {
475 return getFileInfo(File).NumIncludes == 1;
478 /// Determine whether this file is intended to be safe from
479 /// multiple inclusions, e.g., it has \#pragma once or a controlling
482 /// This routine does not consider the effect of \#import
483 bool isFileMultipleIncludeGuarded(const FileEntry *File);
485 /// This method returns a HeaderMap for the specified
486 /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
487 const HeaderMap *CreateHeaderMap(const FileEntry *FE);
489 /// Get filenames for all registered header maps.
490 void getHeaderMapFileNames(SmallVectorImpl<std::string> &Names) const;
492 /// Retrieve the name of the cached module file that should be used
493 /// to load the given module.
495 /// \param Module The module whose module file name will be returned.
497 /// \returns The name of the module file that corresponds to this module,
498 /// or an empty string if this module does not correspond to any module file.
499 std::string getCachedModuleFileName(Module *Module);
501 /// Retrieve the name of the prebuilt module file that should be used
502 /// to load a module with the given name.
504 /// \param ModuleName The module whose module file name will be returned.
506 /// \param FileMapOnly If true, then only look in the explicit module name
507 // to file name map and skip the directory search.
509 /// \returns The name of the module file that corresponds to this module,
510 /// or an empty string if this module does not correspond to any module file.
511 std::string getPrebuiltModuleFileName(StringRef ModuleName,
512 bool FileMapOnly = false);
514 /// Retrieve the name of the (to-be-)cached module file that should
515 /// be used to load a module with the given name.
517 /// \param ModuleName The module whose module file name will be returned.
519 /// \param ModuleMapPath A path that when combined with \c ModuleName
520 /// uniquely identifies this module. See Module::ModuleMap.
522 /// \returns The name of the module file that corresponds to this module,
523 /// or an empty string if this module does not correspond to any module file.
524 std::string getCachedModuleFileName(StringRef ModuleName,
525 StringRef ModuleMapPath);
527 /// Lookup a module Search for a module with the given name.
529 /// \param ModuleName The name of the module we're looking for.
531 /// \param AllowSearch Whether we are allowed to search in the various
532 /// search directories to produce a module definition. If not, this lookup
533 /// will only return an already-known module.
535 /// \param AllowExtraModuleMapSearch Whether we allow to search modulemaps
536 /// in subdirectories.
538 /// \returns The module with the given name.
539 Module *lookupModule(StringRef ModuleName, bool AllowSearch = true,
540 bool AllowExtraModuleMapSearch = false);
542 /// Try to find a module map file in the given directory, returning
543 /// \c nullptr if none is found.
544 const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir,
547 void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
549 /// Determine whether there is a module map that may map the header
550 /// with the given file name to a (sub)module.
551 /// Always returns false if modules are disabled.
553 /// \param Filename The name of the file.
555 /// \param Root The "root" directory, at which we should stop looking for
558 /// \param IsSystem Whether the directories we're looking at are system
559 /// header directories.
560 bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root,
563 /// Retrieve the module that corresponds to the given file, if any.
565 /// \param File The header that we wish to map to a module.
566 /// \param AllowTextual Whether we want to find textual headers too.
567 ModuleMap::KnownHeader findModuleForHeader(const FileEntry *File,
568 bool AllowTextual = false) const;
570 /// Read the contents of the given module map file.
572 /// \param File The module map file.
573 /// \param IsSystem Whether this file is in a system header directory.
574 /// \param ID If the module map file is already mapped (perhaps as part of
575 /// processing a preprocessed module), the ID of the file.
576 /// \param Offset [inout] An offset within ID to start parsing. On exit,
577 /// filled by the end of the parsed contents (either EOF or the
578 /// location of an end-of-module-map pragma).
579 /// \param OriginalModuleMapFile The original path to the module map file,
580 /// used to resolve paths within the module (this is required when
581 /// building the module from preprocessed source).
582 /// \returns true if an error occurred, false otherwise.
583 bool loadModuleMapFile(const FileEntry *File, bool IsSystem,
584 FileID ID = FileID(), unsigned *Offset = nullptr,
585 StringRef OriginalModuleMapFile = StringRef());
587 /// Collect the set of all known, top-level modules.
589 /// \param Modules Will be filled with the set of known, top-level modules.
590 void collectAllModules(SmallVectorImpl<Module *> &Modules);
592 /// Load all known, top-level system modules.
593 void loadTopLevelSystemModules();
596 /// Lookup a module with the given module name and search-name.
598 /// \param ModuleName The name of the module we're looking for.
600 /// \param SearchName The "search-name" to derive filesystem paths from
601 /// when looking for the module map; this is usually equal to ModuleName,
602 /// but for compatibility with some buggy frameworks, additional attempts
603 /// may be made to find the module under a related-but-different search-name.
605 /// \param AllowExtraModuleMapSearch Whether we allow to search modulemaps
606 /// in subdirectories.
608 /// \returns The module named ModuleName.
609 Module *lookupModule(StringRef ModuleName, StringRef SearchName,
610 bool AllowExtraModuleMapSearch = false);
612 /// Retrieve a module with the given name, which may be part of the
615 /// \param Name The name of the module to retrieve.
617 /// \param Dir The framework directory (e.g., ModuleName.framework).
619 /// \param IsSystem Whether the framework directory is part of the system
622 /// \returns The module, if found; otherwise, null.
623 Module *loadFrameworkModule(StringRef Name,
624 const DirectoryEntry *Dir,
627 /// Load all of the module maps within the immediate subdirectories
628 /// of the given search directory.
629 void loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir);
631 /// Find and suggest a usable module for the given file.
633 /// \return \c true if the file can be used, \c false if we are not permitted to
634 /// find this file due to requirements from \p RequestingModule.
635 bool findUsableModuleForHeader(const FileEntry *File,
636 const DirectoryEntry *Root,
637 Module *RequestingModule,
638 ModuleMap::KnownHeader *SuggestedModule,
639 bool IsSystemHeaderDir);
641 /// Find and suggest a usable module for the given file, which is part of
642 /// the specified framework.
644 /// \return \c true if the file can be used, \c false if we are not permitted to
645 /// find this file due to requirements from \p RequestingModule.
646 bool findUsableModuleForFrameworkHeader(
647 const FileEntry *File, StringRef FrameworkName, Module *RequestingModule,
648 ModuleMap::KnownHeader *SuggestedModule, bool IsSystemFramework);
650 /// Look up the file with the specified name and determine its owning
653 getFileAndSuggestModule(StringRef FileName, SourceLocation IncludeLoc,
654 const DirectoryEntry *Dir, bool IsSystemHeaderDir,
655 Module *RequestingModule,
656 ModuleMap::KnownHeader *SuggestedModule);
659 /// Retrieve the module map.
660 ModuleMap &getModuleMap() { return ModMap; }
662 /// Retrieve the module map.
663 const ModuleMap &getModuleMap() const { return ModMap; }
665 unsigned header_file_size() const { return FileInfo.size(); }
667 /// Return the HeaderFileInfo structure for the specified FileEntry,
668 /// in preparation for updating it in some way.
669 HeaderFileInfo &getFileInfo(const FileEntry *FE);
671 /// Return the HeaderFileInfo structure for the specified FileEntry,
672 /// if it has ever been filled in.
673 /// \param WantExternal Whether the caller wants purely-external header file
674 /// info (where \p External is true).
675 const HeaderFileInfo *getExistingFileInfo(const FileEntry *FE,
676 bool WantExternal = true) const;
678 // Used by external tools
679 using search_dir_iterator = std::vector<DirectoryLookup>::const_iterator;
681 search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); }
682 search_dir_iterator search_dir_end() const { return SearchDirs.end(); }
683 unsigned search_dir_size() const { return SearchDirs.size(); }
685 search_dir_iterator quoted_dir_begin() const {
686 return SearchDirs.begin();
689 search_dir_iterator quoted_dir_end() const {
690 return SearchDirs.begin() + AngledDirIdx;
693 search_dir_iterator angled_dir_begin() const {
694 return SearchDirs.begin() + AngledDirIdx;
697 search_dir_iterator angled_dir_end() const {
698 return SearchDirs.begin() + SystemDirIdx;
701 search_dir_iterator system_dir_begin() const {
702 return SearchDirs.begin() + SystemDirIdx;
705 search_dir_iterator system_dir_end() const { return SearchDirs.end(); }
707 /// Retrieve a uniqued framework name.
708 StringRef getUniqueFrameworkName(StringRef Framework);
710 /// Suggest a path by which the specified file could be found, for use in
711 /// diagnostics to suggest a #include. Returned path will only contain forward
712 /// slashes as separators. MainFile is the absolute path of the file that we
713 /// are generating the diagnostics for. It will try to shorten the path using
714 /// MainFile location, if none of the include search directories were prefix
717 /// \param IsSystem If non-null, filled in to indicate whether the suggested
718 /// path is relative to a system header directory.
719 std::string suggestPathToFileForDiagnostics(const FileEntry *File,
720 llvm::StringRef MainFile,
721 bool *IsSystem = nullptr);
723 /// Suggest a path by which the specified file could be found, for use in
724 /// diagnostics to suggest a #include. Returned path will only contain forward
725 /// slashes as separators. MainFile is the absolute path of the file that we
726 /// are generating the diagnostics for. It will try to shorten the path using
727 /// MainFile location, if none of the include search directories were prefix
730 /// \param WorkingDir If non-empty, this will be prepended to search directory
731 /// paths that are relative.
732 std::string suggestPathToFileForDiagnostics(llvm::StringRef File,
733 llvm::StringRef WorkingDir,
734 llvm::StringRef MainFile,
735 bool *IsSystem = nullptr);
739 size_t getTotalMemory() const;
742 /// Describes what happened when we tried to load a module map file.
743 enum LoadModuleMapResult {
744 /// The module map file had already been loaded.
747 /// The module map file was loaded by this invocation.
750 /// There is was directory with the given name.
753 /// There was either no module map file or the module map file was
758 LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File,
760 const DirectoryEntry *Dir,
761 FileID ID = FileID(),
762 unsigned *Offset = nullptr);
764 /// Try to load the module map file in the given directory.
766 /// \param DirName The name of the directory where we will look for a module
768 /// \param IsSystem Whether this is a system header directory.
769 /// \param IsFramework Whether this is a framework directory.
771 /// \returns The result of attempting to load the module map file from the
773 LoadModuleMapResult loadModuleMapFile(StringRef DirName, bool IsSystem,
776 /// Try to load the module map file in the given directory.
778 /// \param Dir The directory where we will look for a module map file.
779 /// \param IsSystem Whether this is a system header directory.
780 /// \param IsFramework Whether this is a framework directory.
782 /// \returns The result of attempting to load the module map file from the
784 LoadModuleMapResult loadModuleMapFile(const DirectoryEntry *Dir,
785 bool IsSystem, bool IsFramework);
790 #endif // LLVM_CLANG_LEX_HEADERSEARCH_H