clang 23.0.0git
HeaderSearch.h
Go to the documentation of this file.
1//===- HeaderSearch.h - Resolve Header File Locations -----------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the HeaderSearch interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
14#define LLVM_CLANG_LEX_HEADERSEARCH_H
15
20#include "clang/Lex/HeaderMap.h"
21#include "clang/Lex/ModuleMap.h"
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/MapVector.h"
25#include "llvm/ADT/SmallString.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/ADT/StringSet.h"
29#include "llvm/Support/Allocator.h"
30#include <cassert>
31#include <cstddef>
32#include <memory>
33#include <string>
34#include <utility>
35#include <vector>
36
37namespace llvm {
38
39class Triple;
40
41} // namespace llvm
42
43namespace clang {
44
46class DirectoryEntry;
48class FileEntry;
49class FileManager;
50class HeaderSearch;
52class IdentifierInfo;
53class LangOptions;
54class Module;
55class Preprocessor;
56class TargetInfo;
57
58/// The preprocessor keeps track of this information for each
59/// file that is \#included.
61 // TODO: Whether the file was included is not a property of the file itself.
62 // It's a preprocessor state, move it there.
63 /// True if this file has been included (or imported) **locally**.
64 LLVM_PREFERRED_TYPE(bool)
66
67 // TODO: Whether the file was imported is not a property of the file itself.
68 // It's a preprocessor state, move it there.
69 /// True if this is a \#import'd file.
70 LLVM_PREFERRED_TYPE(bool)
71 unsigned isImport : 1;
72
73 /// True if this is a \#pragma once file.
74 LLVM_PREFERRED_TYPE(bool)
75 unsigned isPragmaOnce : 1;
76
77 /// Keep track of whether this is a system header, and if so,
78 /// whether it is C++ clean or not. This can be set by the include paths or
79 /// by \#pragma gcc system_header. This is an instance of
80 /// SrcMgr::CharacteristicKind.
81 LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)
82 unsigned DirInfo : 3;
83
84 /// Whether this header file info was supplied by an external source,
85 /// and has not changed since.
86 LLVM_PREFERRED_TYPE(bool)
87 unsigned External : 1;
88
89 /// Whether this header is part of and built with a module. i.e. it is listed
90 /// in a module map, and is not `excluded` or `textual`. (same meaning as
91 /// `ModuleMap::isModular()`).
92 LLVM_PREFERRED_TYPE(bool)
93 unsigned isModuleHeader : 1;
94
95 /// Whether this header is a `textual header` in a module. If a header is
96 /// textual in one module and normal in another module, this bit will not be
97 /// set, only `isModuleHeader`.
98 LLVM_PREFERRED_TYPE(bool)
100
101 /// Whether this header is part of the module that we are building, even if it
102 /// doesn't build with the module. i.e. this will include `excluded` and
103 /// `textual` headers as well as normal headers.
104 LLVM_PREFERRED_TYPE(bool)
106
107 /// Whether this structure is considered to already have been
108 /// "resolved", meaning that it was loaded from the external source.
109 LLVM_PREFERRED_TYPE(bool)
110 unsigned Resolved : 1;
111
112 /// Whether this file has been looked up as a header.
113 LLVM_PREFERRED_TYPE(bool)
114 unsigned IsValid : 1;
115
116 /// If this file has a \#ifndef XXX (or equivalent) guard that
117 /// protects the entire contents of the file, this is the identifier
118 /// for the macro that controls whether or not it has any effect.
119 ///
120 /// Note: Most clients should use getControllingMacro() to access
121 /// the controlling macro of this header, since
122 /// getControllingMacro() is able to load a controlling macro from
123 /// external storage.
125
131
132 /// Retrieve the controlling macro for this header file, if
133 /// any.
134 const IdentifierInfo *
136
137 /// Update the module membership bits based on the header role.
138 ///
139 /// isModuleHeader will potentially be set, but not cleared.
140 /// isTextualModuleHeader will be set or cleared based on the role update.
142};
143
144static_assert(sizeof(HeaderFileInfo) <= 16);
145
146/// An external source of header file information, which may supply
147/// information about header files already included.
149public:
151
152 /// Retrieve the header file information for the given file entry.
153 ///
154 /// \returns Header file information for the given file entry, with the
155 /// \c External bit set. If the file entry is not known, return a
156 /// default-constructed \c HeaderFileInfo.
158};
159
160/// This structure is used to record entries in our framework cache.
162 /// The directory entry which should be used for the cached framework.
164
165 /// Whether this framework has been "user-specified" to be treated as if it
166 /// were a system framework (even if it was found outside a system framework
167 /// directory).
169};
170
171namespace detail {
172template <bool Const, typename T>
173using Qualified = std::conditional_t<Const, const T, T>;
174
175/// Forward iterator over the search directories of \c HeaderSearch.
176template <bool IsConst>
178 : llvm::iterator_facade_base<SearchDirIteratorImpl<IsConst>,
179 std::forward_iterator_tag,
180 Qualified<IsConst, DirectoryLookup>> {
181 /// Const -> non-const iterator conversion.
182 template <typename Enable = std::enable_if<IsConst, bool>>
185
187
189
190 bool operator==(const SearchDirIteratorImpl &RHS) const {
191 return HS == RHS.HS && Idx == RHS.Idx;
192 }
193
195 assert(*this && "Invalid iterator.");
196 ++Idx;
197 return *this;
198 }
199
201 assert(*this && "Invalid iterator.");
202 return HS->SearchDirs[Idx];
203 }
204
205 /// Creates an invalid iterator.
206 SearchDirIteratorImpl(std::nullptr_t) : HS(nullptr), Idx(0) {}
207
208 /// Checks whether the iterator is valid.
209 explicit operator bool() const { return HS != nullptr; }
210
211private:
212 /// The parent \c HeaderSearch. This is \c nullptr for invalid iterator.
214
215 /// The index of the current element.
216 size_t Idx;
217
218 /// The constructor that creates a valid iterator.
220 : HS(&HS), Idx(Idx) {}
221
222 /// Only HeaderSearch is allowed to instantiate valid iterators.
223 friend HeaderSearch;
224
225 /// Enables const -> non-const conversion.
226 friend SearchDirIteratorImpl<!IsConst>;
227};
228} // namespace detail
229
232
233using ConstSearchDirRange = llvm::iterator_range<ConstSearchDirIterator>;
234using SearchDirRange = llvm::iterator_range<SearchDirIterator>;
235
236/// Encapsulates the information needed to find the file referenced
237/// by a \#include or \#include_next, (sub-)framework lookup, etc.
239 friend class DirectoryLookup;
240
241 friend ConstSearchDirIterator;
242 friend SearchDirIterator;
243
244 /// Header-search options used to initialize this header search.
245 const HeaderSearchOptions &HSOpts;
246
247 /// Mapping from SearchDir to HeaderSearchOptions::UserEntries indices.
248 llvm::DenseMap<unsigned, unsigned> SearchDirToHSEntry;
249
250 DiagnosticsEngine &Diags;
251 FileManager &FileMgr;
252
253 /// \#include search path information. Requests for \#include "x" search the
254 /// directory of the \#including file first, then each directory in SearchDirs
255 /// consecutively. Requests for <x> search the current dir first, then each
256 /// directory in SearchDirs, starting at AngledDirIdx, consecutively.
257 std::vector<DirectoryLookup> SearchDirs;
258 /// Whether the DirectoryLookup at the corresponding index in SearchDirs has
259 /// been successfully used to lookup a file.
260 std::vector<bool> SearchDirsUsage;
261 unsigned AngledDirIdx = 0;
262 unsigned SystemDirIdx = 0;
263
264 /// Maps HeaderMap keys to SearchDir indices. When HeaderMaps are used
265 /// heavily, SearchDirs can start with thousands of HeaderMaps, so this Index
266 /// lets us avoid scanning them all to find a match.
267 llvm::StringMap<unsigned, llvm::BumpPtrAllocator> SearchDirHeaderMapIndex;
268
269 /// The index of the first SearchDir that isn't a header map.
270 unsigned FirstNonHeaderMapSearchDirIdx = 0;
271
272 /// \#include prefixes for which the 'system header' property is
273 /// overridden.
274 ///
275 /// For a \#include "x" or \#include <x> directive, the last string in this
276 /// list which is a prefix of 'x' determines whether the file is treated as
277 /// a system header.
278 std::vector<std::pair<std::string, bool>> SystemHeaderPrefixes;
279
280 /// The context hash used in SpecificModuleCachePath (unless suppressed).
281 std::string ContextHash;
282
283 /// The specific module cache path containing ContextHash (unless suppressed).
284 std::string SpecificModuleCachePath;
285
286 /// The length of the normalized module cache path at the start of \c
287 /// SpecificModuleCachePath.
288 size_t NormalizedModuleCachePathLen = 0;
289
290 /// All the preprocessor-specific data about files that are included.
291 mutable llvm::MapVector<FileEntryRef, HeaderFileInfo> FileInfo;
292
293 /// Keeps track of each lookup performed by LookupFile.
294 struct LookupFileCacheInfo {
295 // The requesting module for the lookup we cached.
296 const Module *RequestingModule = nullptr;
297
298 /// Starting search directory iterator that the cached search was performed
299 /// from. If there is a hit and this value doesn't match the current query,
300 /// the cache has to be ignored.
301 ConstSearchDirIterator StartIt = nullptr;
302
303 /// The search directory iterator that satisfied the query.
304 ConstSearchDirIterator HitIt = nullptr;
305
306 /// This is non-null if the original filename was mapped to a framework
307 /// include via a headermap.
308 const char *MappedName = nullptr;
309
310 /// Default constructor -- Initialize all members with zero.
311 LookupFileCacheInfo() = default;
312
313 void reset(const Module *NewRequestingModule,
314 ConstSearchDirIterator NewStartIt) {
315 RequestingModule = NewRequestingModule;
316 StartIt = NewStartIt;
317 MappedName = nullptr;
318 }
319 };
320 llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
321
322 /// Collection mapping a framework or subframework
323 /// name like "Carbon" to the Carbon.framework directory.
324 llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
325
326 /// Maps include file names (including the quotes or
327 /// angle brackets) to other include file names. This is used to support the
328 /// include_alias pragma for Microsoft compatibility.
329 using IncludeAliasMap =
330 llvm::StringMap<std::string, llvm::BumpPtrAllocator>;
331 std::unique_ptr<IncludeAliasMap> IncludeAliases;
332
333 /// This is a mapping from FileEntry -> HeaderMap, uniquing headermaps.
334 std::vector<std::pair<FileEntryRef, std::unique_ptr<HeaderMap>>> HeaderMaps;
335
336 /// The mapping between modules and headers.
337 mutable ModuleMap ModMap;
338
339 struct ModuleMapDirectoryState {
340 OptionalFileEntryRef ModuleMapFile;
341 OptionalFileEntryRef PrivateModuleMapFile;
342 enum {
343 Parsed,
344 Loaded,
345 Invalid,
346 } Status;
347
348 /// Relative header path -> list of module names
349 llvm::StringMap<llvm::SmallVector<StringRef, 1>> HeaderToModules{};
350 /// Relative dir path -> module name
351 llvm::SmallVector<std::pair<std::string, StringRef>, 2>
352 UmbrellaDirModules{};
353 /// List of module names with umbrella header decls
354 llvm::SmallVector<StringRef, 2> UmbrellaHeaderModules{};
355 };
356
357 /// Describes whether a given directory has a module map in it.
358 llvm::DenseMap<const DirectoryEntry *, ModuleMapDirectoryState>
359 DirectoryModuleMap;
360
361 /// Set of module map files we've already loaded, and a flag indicating
362 /// whether they were valid or not.
363 llvm::DenseMap<const FileEntry *, bool> LoadedModuleMaps;
364
365 /// Set of module map files we've already parsed, and a flag indicating
366 /// whether they were valid or not.
367 llvm::DenseMap<const FileEntry *, bool> ParsedModuleMaps;
368
369 // A map of discovered headers with their associated include file name.
370 llvm::DenseMap<const FileEntry *, llvm::SmallString<64>> IncludeNames;
371
372 /// Uniqued set of framework names, which is used to track which
373 /// headers were included as framework headers.
374 llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
375
376 /// Entity used to resolve the identifier IDs of controlling
377 /// macros into IdentifierInfo pointers, and keep the identifire up to date,
378 /// as needed.
379 ExternalPreprocessorSource *ExternalLookup = nullptr;
380
381 /// Entity used to look up stored header file information.
382 ExternalHeaderFileInfoSource *ExternalSource = nullptr;
383
384 /// Scan all of the header maps at the beginning of SearchDirs and
385 /// map their keys to the SearchDir index of their header map.
386 void indexInitialHeaderMaps();
387
388 /// Build the module map index for a directory's module map.
389 ///
390 /// This fills a ModuleMapDirectoryState with index information from its
391 /// directory's module map.
392 void buildModuleMapIndex(DirectoryEntryRef Dir,
393 ModuleMapDirectoryState &MMState);
394
395 void processModuleMapForIndex(const modulemap::ModuleMapFile &MMF,
396 DirectoryEntryRef MMDir, StringRef PathPrefix,
397 ModuleMapDirectoryState &MMState);
398
399 void processExternModuleDeclForIndex(const modulemap::ExternModuleDecl &EMD,
400 DirectoryEntryRef MMDir,
401 StringRef PathPrefix,
402 ModuleMapDirectoryState &MMState);
403
404 void processModuleDeclForIndex(const modulemap::ModuleDecl &MD,
405 StringRef ModuleName, DirectoryEntryRef MMDir,
406 StringRef PathPrefix,
407 ModuleMapDirectoryState &MMState);
408
409 void addToModuleMapIndex(StringRef RelPath, StringRef ModuleName,
410 StringRef PathPrefix,
411 ModuleMapDirectoryState &MMState);
412
413 /// Check if a relative path would be covered by the module map index.
414 /// Returns the module names that would cover this path.
415 SmallVector<StringRef, 1>
416 findMatchingModulesInIndex(StringRef RelativePath,
417 const ModuleMapDirectoryState &MMState) const;
418
419public:
420 HeaderSearch(const HeaderSearchOptions &HSOpts, SourceManager &SourceMgr,
421 DiagnosticsEngine &Diags, const LangOptions &LangOpts,
422 const TargetInfo *Target);
423 HeaderSearch(const HeaderSearch &) = delete;
425
426 /// Retrieve the header-search options with which this header search
427 /// was initialized.
428 const HeaderSearchOptions &getHeaderSearchOpts() const { return HSOpts; }
429
430 FileManager &getFileMgr() const { return FileMgr; }
431
432 DiagnosticsEngine &getDiags() const { return Diags; }
433
434 /// Interface for setting the file search paths.
435 void SetSearchPaths(std::vector<DirectoryLookup> dirs, unsigned angledDirIdx,
436 unsigned systemDirIdx,
437 llvm::DenseMap<unsigned, unsigned> searchDirToHSEntry);
438
439 /// Add an additional search path.
440 void AddSearchPath(const DirectoryLookup &dir, bool isAngled);
441
442 /// Add an additional system search path.
444 SearchDirs.push_back(dir);
445 SearchDirsUsage.push_back(false);
446 }
447
448 /// Set the list of system header prefixes.
449 void SetSystemHeaderPrefixes(ArrayRef<std::pair<std::string, bool>> P) {
450 SystemHeaderPrefixes.assign(P.begin(), P.end());
451 }
452
453 /// Checks whether the map exists or not.
454 bool HasIncludeAliasMap() const { return (bool)IncludeAliases; }
455
456 /// Map the source include name to the dest include name.
457 ///
458 /// The Source should include the angle brackets or quotes, the dest
459 /// should not. This allows for distinction between <> and "" headers.
460 void AddIncludeAlias(StringRef Source, StringRef Dest) {
461 if (!IncludeAliases)
462 IncludeAliases.reset(new IncludeAliasMap);
463 (*IncludeAliases)[Source] = std::string(Dest);
464 }
465
466 /// Maps one header file name to a different header
467 /// file name, for use with the include_alias pragma. Note that the source
468 /// file name should include the angle brackets or quotes. Returns StringRef
469 /// as null if the header cannot be mapped.
470 StringRef MapHeaderToIncludeAlias(StringRef Source) {
471 assert(IncludeAliases && "Trying to map headers when there's no map");
472
473 // Do any filename replacements before anything else
474 IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
475 if (Iter != IncludeAliases->end())
476 return Iter->second;
477 return {};
478 }
479
480 /// Initialize the module cache path.
481 void initializeModuleCachePath(std::string ContextHash);
482
483 /// Retrieve the specific module cache path. This is the normalized module
484 /// cache path plus the context hash (unless suppressed).
485 StringRef getSpecificModuleCachePath() const {
486 return SpecificModuleCachePath;
487 }
488
489 /// Retrieve the context hash.
490 StringRef getContextHash() const { return ContextHash; }
491
492 /// Retrieve the normalized module cache path. This is the path as provided on
493 /// the command line, but absolute, without './' components, and with
494 /// preferred path separators. Note that this does not have the context hash.
496 return getSpecificModuleCachePath().substr(0, NormalizedModuleCachePathLen);
497 }
498
499 /// Forget everything we know about headers so far.
501 FileInfo.clear();
502 }
503
505 ExternalLookup = EPS;
506 }
507
509 return ExternalLookup;
510 }
511
512 /// Set the external source of header information.
514 ExternalSource = ES;
515 }
516
518 StringRef Filename, OptionalFileEntryRef FE, bool &DiagnosedShadowing,
519 SourceLocation IncludeLoc, ConstSearchDirIterator FromDir,
520 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>> Includers,
521 bool isAngled, int IncluderLoopIndex, ConstSearchDirIterator MainLoopIt);
522
523 /// Set the target information for the header search, if not
524 /// already known.
525 void setTarget(const TargetInfo &Target);
526
527 /// Given a "foo" or <foo> reference, look up the indicated file,
528 /// return null on failure.
529 ///
530 /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member
531 /// the file was found in, or null if not applicable.
532 ///
533 /// \param IncludeLoc Used for diagnostics if valid.
534 ///
535 /// \param isAngled indicates whether the file reference is a <> reference.
536 ///
537 /// \param CurDir If non-null, the file was found in the specified directory
538 /// search location. This is used to implement \#include_next.
539 ///
540 /// \param Includers Indicates where the \#including file(s) are, in case
541 /// relative searches are needed. In reverse order of inclusion.
542 ///
543 /// \param SearchPath If non-null, will be set to the search path relative
544 /// to which the file was found. If the include path is absolute, SearchPath
545 /// will be set to an empty string.
546 ///
547 /// \param RelativePath If non-null, will be set to the path relative to
548 /// SearchPath at which the file was found. This only differs from the
549 /// Filename for framework includes.
550 ///
551 /// \param SuggestedModule If non-null, and the file found is semantically
552 /// part of a known module, this will be set to the module that should
553 /// be imported instead of preprocessing/parsing the file found.
554 ///
555 /// \param IsMapped If non-null, and the search involved header maps, set to
556 /// true.
557 ///
558 /// \param IsFrameworkFound If non-null, will be set to true if a framework is
559 /// found in any of searched SearchDirs. Will be set to false if a framework
560 /// is found only through header maps. Doesn't guarantee the requested file is
561 /// found.
563 StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
565 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>> Includers,
566 SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
567 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
568 bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false,
569 bool BuildSystemModule = false, bool OpenFile = true,
570 bool CacheFailures = true);
571
572 /// Look up a subframework for the specified \#include file.
573 ///
574 /// For example, if \#include'ing <HIToolbox/HIToolbox.h> from
575 /// within ".../Carbon.framework/Headers/Carbon.h", check to see if
576 /// HIToolbox is a subframework within Carbon.framework. If so, return
577 /// the FileEntry for the designated file, otherwise return null.
579 StringRef Filename, FileEntryRef ContextFileEnt,
580 SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
581 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule);
582
583 /// Look up the specified framework name in our framework cache.
584 /// \returns The DirectoryEntry it is in if we know, null otherwise.
586 return FrameworkMap[FWName];
587 }
588
589 /// Mark the specified file as a target of a \#include,
590 /// \#include_next, or \#import directive.
591 ///
592 /// \return false if \#including the file will have no effect or true
593 /// if we should include it.
594 ///
595 /// \param M The module to which `File` belongs (this should usually be the
596 /// SuggestedModule returned by LookupFile/LookupSubframeworkHeader)
598 bool isImport, bool ModulesEnabled, Module *M,
599 bool &IsFirstIncludeOfFile);
600
601 /// Return whether the specified file is a normal header,
602 /// a system header, or a C++ friendly system header.
608
609 /// Mark the specified file as a "once only" file due to
610 /// \#pragma once.
614
615 /// Mark the specified file as a system header, e.g. due to
616 /// \#pragma GCC system_header.
620
621 /// Mark the specified file as part of a module.
623 bool isCompilingModuleHeader);
624
625 /// Mark the specified file as having a controlling macro.
626 ///
627 /// This is used by the multiple-include optimization to eliminate
628 /// no-op \#includes.
630 const IdentifierInfo *ControllingMacro) {
631 getFileInfo(File).LazyControllingMacro = ControllingMacro;
632 }
633
634 /// Determine whether this file is intended to be safe from
635 /// multiple inclusions, e.g., it has \#pragma once or a controlling
636 /// macro.
637 ///
638 /// This routine does not consider the effect of \#import
640
641 /// Determine whether the given file is known to have ever been \#imported.
644 return FI && FI->isImport;
645 }
646
647 /// Determine which HeaderSearchOptions::UserEntries have been successfully
648 /// used so far and mark their index with 'true' in the resulting bit vector.
649 /// Note: implicit module maps don't contribute to entry usage.
650 std::vector<bool> computeUserEntryUsage() const;
651
652 /// Collect which HeaderSearchOptions::VFSOverlayFiles have been meaningfully
653 /// used so far and mark their index with 'true' in the resulting bit vector.
654 ///
655 /// Note: this ignores VFSs that redirect non-affecting files such as unused
656 /// modulemaps.
657 std::vector<bool> collectVFSUsageAndClear() const;
658
659 /// This method returns a HeaderMap for the specified
660 /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
662
663 /// Get filenames for all registered header maps.
665
666 /// Retrieve the name of the cached module file that should be used
667 /// to load the given module.
668 ///
669 /// \param Module The module whose module file name will be returned.
670 ///
671 /// \returns The name of the module file that corresponds to this module,
672 /// or an empty string if this module does not correspond to any module file.
674
675 /// Retrieve the name of the prebuilt module file that should be used
676 /// to load a module with the given name.
677 ///
678 /// \param ModuleName The module whose module file name will be returned.
679 ///
680 /// \param FileMapOnly If true, then only look in the explicit module name
681 // to file name map and skip the directory search.
682 ///
683 /// \returns The name of the module file that corresponds to this module,
684 /// or an empty string if this module does not correspond to any module file.
685 ModuleFileName getPrebuiltModuleFileName(StringRef ModuleName,
686 bool FileMapOnly = false);
687
688 /// Retrieve the name of the prebuilt module file that should be used
689 /// to load the given module.
690 ///
691 /// \param Module The module whose module file name will be returned.
692 ///
693 /// \returns The name of the module file that corresponds to this module,
694 /// or an empty string if this module does not correspond to any module file.
696
697 /// Retrieve the name of the (to-be-)cached module file that should
698 /// be used to load a module with the given name.
699 ///
700 /// \param ModuleName The module whose module file name will be returned.
701 ///
702 /// \param ModuleMapPath A path that when combined with \c ModuleName
703 /// uniquely identifies this module. See Module::ModuleMap.
704 ///
705 /// \returns The name of the module file that corresponds to this module,
706 /// or an empty string if this module does not correspond to any module file.
707 ModuleFileName getCachedModuleFileName(StringRef ModuleName,
708 StringRef ModuleMapPath);
709
710 /// Lookup a module Search for a module with the given name.
711 ///
712 /// \param ModuleName The name of the module we're looking for.
713 ///
714 /// \param ImportLoc Location of the module include/import.
715 ///
716 /// \param AllowSearch Whether we are allowed to search in the various
717 /// search directories to produce a module definition. If not, this lookup
718 /// will only return an already-known module.
719 ///
720 /// \param AllowExtraModuleMapSearch Whether we allow to search modulemaps
721 /// in subdirectories.
722 ///
723 /// \returns The module with the given name.
724 Module *lookupModule(StringRef ModuleName,
725 SourceLocation ImportLoc = SourceLocation(),
726 bool AllowSearch = true,
727 bool AllowExtraModuleMapSearch = false);
728
729 /// Try to find a module map file in the given directory, returning
730 /// \c nullopt if none is found.
732 bool IsFramework);
733
734 /// Determine whether there is a module map that may map the header
735 /// with the given file name to a (sub)module.
736 /// Always returns false if modules are disabled.
737 ///
738 /// \param Filename The name of the file.
739 ///
740 /// \param Root The "root" directory, at which we should stop looking for
741 /// module maps.
742 ///
743 /// \param IsSystem Whether the directories we're looking at are system
744 /// header directories.
745 bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root,
746 bool IsSystem);
747
748 /// Retrieve the module that corresponds to the given file, if any.
749 ///
750 /// \param File The header that we wish to map to a module.
751 /// \param AllowTextual Whether we want to find textual headers too.
753 bool AllowTextual = false,
754 bool AllowExcluded = false) const;
755
756 /// Retrieve all the modules corresponding to the given file.
757 ///
758 /// \ref findModuleForHeader should typically be used instead of this.
761
762 /// Like \ref findAllModulesForHeader, but do not attempt to infer module
763 /// ownership from umbrella headers if we've not already done so.
766
767 /// Read the contents of the given module map file.
768 ///
769 /// \param File The module map file.
770 /// \param IsSystem Whether this file is in a system header directory.
771 /// \param ImplicitlyDiscovered Whether this file was found by module map
772 /// search.
773 /// \param ID If the module map file is already mapped (perhaps as part of
774 /// processing a preprocessed module), the ID of the file.
775 /// \param Offset [inout] An offset within ID to start parsing. On exit,
776 /// filled by the end of the parsed contents (either EOF or the
777 /// location of an end-of-module-map pragma).
778 /// \param OriginalModuleMapFile The original path to the module map file,
779 /// used to resolve paths within the module (this is required when
780 /// building the module from preprocessed source).
781 /// \returns true if an error occurred, false otherwise.
782 bool parseAndLoadModuleMapFile(FileEntryRef File, bool IsSystem,
783 bool ImplicitlyDiscovered,
784 FileID ID = FileID(),
785 unsigned *Offset = nullptr,
786 StringRef OriginalModuleMapFile = StringRef());
787
788 /// Collect the set of all known, top-level modules.
789 ///
790 /// \param Modules Will be filled with the set of known, top-level modules.
792
793 /// Load all known, top-level system modules.
795
796private:
797 /// Lookup a module with the given module name and search-name.
798 ///
799 /// \param ModuleName The name of the module we're looking for.
800 ///
801 /// \param SearchName The "search-name" to derive filesystem paths from
802 /// when looking for the module map; this is usually equal to ModuleName,
803 /// but for compatibility with some buggy frameworks, additional attempts
804 /// may be made to find the module under a related-but-different search-name.
805 ///
806 /// \param ImportLoc Location of the module include/import.
807 ///
808 /// \param AllowExtraModuleMapSearch Whether we allow to search modulemaps
809 /// in subdirectories.
810 ///
811 /// \returns The module named ModuleName.
812 Module *lookupModule(StringRef ModuleName, StringRef SearchName,
813 SourceLocation ImportLoc,
814 bool AllowExtraModuleMapSearch = false);
815
816 /// Retrieve the name of the (to-be-)cached module file that should
817 /// be used to load a module with the given name.
818 ///
819 /// \param ModuleName The module whose module file name will be returned.
820 ///
821 /// \param ModuleMapPath A path that when combined with \c ModuleName
822 /// uniquely identifies this module. See Module::ModuleMap.
823 ///
824 /// \param NormalizedCachePath The normalized path to the module cache.
825 ///
826 /// \returns The name of the module file that corresponds to this module,
827 /// or an empty string if this module does not correspond to any module file.
828 ModuleFileName getCachedModuleFileNameImpl(StringRef ModuleName,
829 StringRef ModuleMapPath,
830 StringRef NormalizedCachePath);
831
832 /// Retrieve a module with the given name, which may be part of the
833 /// given framework.
834 ///
835 /// \param Name The name of the module to retrieve.
836 ///
837 /// \param Dir The framework directory (e.g., ModuleName.framework).
838 ///
839 /// \param IsSystem Whether the framework directory is part of the system
840 /// frameworks.
841 ///
842 /// \param ImplicitlyDiscovered Whether the framework was discovered by module
843 /// map search.
844 ///
845 /// \returns The module, if found; otherwise, null.
846 Module *loadFrameworkModule(StringRef Name, DirectoryEntryRef Dir,
847 bool IsSystem, bool ImplicitlyDiscovered);
848
849 /// Load all of the module maps within the immediate subdirectories
850 /// of the given search directory.
851 void loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir);
852
853 /// Diagnose headers that are a symlink and not covered by a module map.
854 void diagnoseUncoveredSymlink(FileEntryRef File,
856 const DirectoryEntry *Root);
857
858 /// Find and suggest a usable module for the given file.
859 ///
860 /// \return \c true if the file can be used, \c false if we are not permitted to
861 /// find this file due to requirements from \p RequestingModule.
862 bool findUsableModuleForHeader(FileEntryRef File, const DirectoryEntry *Root,
863 Module *RequestingModule,
864 ModuleMap::KnownHeader *SuggestedModule,
865 bool IsSystemHeaderDir);
866
867 /// Find and suggest a usable module for the given file, which is part of
868 /// the specified framework.
869 ///
870 /// \return \c true if the file can be used, \c false if we are not permitted to
871 /// find this file due to requirements from \p RequestingModule.
872 bool findUsableModuleForFrameworkHeader(
873 FileEntryRef File, StringRef FrameworkName, Module *RequestingModule,
874 ModuleMap::KnownHeader *SuggestedModule, bool IsSystemFramework);
875
876 /// Look up the file with the specified name and determine its owning
877 /// module.
879 getFileAndSuggestModule(StringRef FileName, SourceLocation IncludeLoc,
880 const DirectoryEntry *Dir, bool IsSystemHeaderDir,
881 Module *RequestingModule,
882 ModuleMap::KnownHeader *SuggestedModule,
883 bool OpenFile = true, bool CacheFailures = true);
884
885 /// Cache the result of a successful lookup at the given include location
886 /// using the search path at \c HitIt.
887 void cacheLookupSuccess(LookupFileCacheInfo &CacheLookup,
889 SourceLocation IncludeLoc);
890
891 /// Note that a lookup at the given include location was successful using the
892 /// search path at index `HitIdx`.
893 void noteLookupUsage(unsigned HitIdx, SourceLocation IncludeLoc);
894
895public:
896 /// Retrieve the module map.
897 ModuleMap &getModuleMap() { return ModMap; }
898
899 /// Retrieve the module map.
900 const ModuleMap &getModuleMap() const { return ModMap; }
901
902 /// Return the HeaderFileInfo structure for the specified FileEntry, in
903 /// preparation for updating it in some way.
905
906 /// Return the HeaderFileInfo structure for the specified FileEntry, if it has
907 /// ever been filled in (either locally or externally).
909
910 /// Iterate HeaderFileInfo structures and their corresponding FileEntryRef, if
911 /// they have ever been filled in locally.
913 llvm::function_ref<void(FileEntryRef, const HeaderFileInfo &)> Fn) const;
914
915 SearchDirIterator search_dir_begin() { return {*this, 0}; }
916 SearchDirIterator search_dir_end() { return {*this, SearchDirs.size()}; }
920
921 ConstSearchDirIterator search_dir_begin() const { return quoted_dir_begin(); }
922 ConstSearchDirIterator search_dir_nth(size_t n) const {
923 assert(n < SearchDirs.size());
924 return {*this, n};
925 }
926 ConstSearchDirIterator search_dir_end() const { return system_dir_end(); }
930
931 unsigned search_dir_size() const { return SearchDirs.size(); }
932
933 ConstSearchDirIterator quoted_dir_begin() const { return {*this, 0}; }
934 ConstSearchDirIterator quoted_dir_end() const { return angled_dir_begin(); }
935
936 ConstSearchDirIterator angled_dir_begin() const {
937 return {*this, AngledDirIdx};
938 }
939 ConstSearchDirIterator angled_dir_end() const { return system_dir_begin(); }
940
941 ConstSearchDirIterator system_dir_begin() const {
942 return {*this, SystemDirIdx};
943 }
944 ConstSearchDirIterator system_dir_end() const {
945 return {*this, SearchDirs.size()};
946 }
947
948 /// Get the index of the given search directory.
949 unsigned searchDirIdx(const DirectoryLookup &DL) const;
950
951 /// Retrieve a uniqued framework name.
952 StringRef getUniqueFrameworkName(StringRef Framework);
953
954 /// Retrieve the include name for the header.
955 ///
956 /// \param File The entry for a given header.
957 /// \returns The name of how the file was included when the header's location
958 /// was resolved.
959 StringRef getIncludeNameForHeader(const FileEntry *File) const;
960
961 /// Suggest a path by which the specified file could be found, for use in
962 /// diagnostics to suggest a #include. Returned path will only contain forward
963 /// slashes as separators. MainFile is the absolute path of the file that we
964 /// are generating the diagnostics for. It will try to shorten the path using
965 /// MainFile location, if none of the include search directories were prefix
966 /// of File.
967 ///
968 /// \param IsAngled If non-null, filled in to indicate whether the suggested
969 /// path should be referenced as <Header.h> instead of "Header.h".
971 llvm::StringRef MainFile,
972 bool *IsAngled = nullptr) const;
973
974 /// Suggest a path by which the specified file could be found, for use in
975 /// diagnostics to suggest a #include. Returned path will only contain forward
976 /// slashes as separators. MainFile is the absolute path of the file that we
977 /// are generating the diagnostics for. It will try to shorten the path using
978 /// MainFile location, if none of the include search directories were prefix
979 /// of File.
980 ///
981 /// \param WorkingDir If non-empty, this will be prepended to search directory
982 /// paths that are relative.
983 std::string suggestPathToFileForDiagnostics(llvm::StringRef File,
984 llvm::StringRef WorkingDir,
985 llvm::StringRef MainFile,
986 bool *IsAngled = nullptr) const;
987
988 void PrintStats();
989
990 size_t getTotalMemory() const;
991
992private:
993 /// Describes what happened when we tried to load or parse a module map file.
994 enum ModuleMapResult {
995 /// The module map file had already been processed.
996 MMR_AlreadyProcessed,
997
998 /// The module map file was processed by this invocation.
999 MMR_NewlyProcessed,
1000
1001 /// There is was directory with the given name.
1002 MMR_NoDirectory,
1003
1004 /// There was either no module map file or the module map file was
1005 /// invalid.
1006 MMR_InvalidModuleMap
1007 };
1008
1009 ModuleMapResult parseAndLoadModuleMapFileImpl(
1010 FileEntryRef File, bool IsSystem, bool ImplicitlyDiscovered,
1011 DirectoryEntryRef Dir, FileID ID = FileID(), unsigned *Offset = nullptr,
1012 bool DiagnosePrivMMap = false);
1013
1014 ModuleMapResult parseModuleMapFileImpl(FileEntryRef File, bool IsSystem,
1015 bool ImplicitlyDiscovered,
1016 DirectoryEntryRef Dir,
1017 FileID ID = FileID());
1018
1019 /// Try to load the module map file in the given directory.
1020 ///
1021 /// \param DirName The name of the directory where we will look for a module
1022 /// map file.
1023 /// \param IsSystem Whether this is a system header directory.
1024 /// \param IsFramework Whether this is a framework directory.
1025 ///
1026 /// \returns The result of attempting to load the module map file from the
1027 /// named directory.
1028 ModuleMapResult parseAndLoadModuleMapFile(StringRef DirName, bool IsSystem,
1029 bool ImplicitlyDiscovered,
1030 bool IsFramework);
1031
1032 /// Try to load the module map file in the given directory.
1033 ///
1034 /// \param Dir The directory where we will look for a module map file.
1035 /// \param IsSystem Whether this is a system header directory.
1036 /// \param IsFramework Whether this is a framework directory.
1037 ///
1038 /// \returns The result of attempting to load the module map file from the
1039 /// named directory.
1040 ModuleMapResult parseAndLoadModuleMapFile(DirectoryEntryRef Dir,
1041 bool IsSystem,
1042 bool ImplicitlyDiscovered,
1043 bool IsFramework);
1044
1045 ModuleMapResult parseModuleMapFile(StringRef DirName, bool IsSystem,
1046 bool ImplicitlyDiscovered,
1047 bool IsFramework);
1048 ModuleMapResult parseModuleMapFile(DirectoryEntryRef Dir, bool IsSystem,
1049 bool ImplicitlyDiscovered,
1050 bool IsFramework);
1051};
1052
1053/// Apply the header search options to get given HeaderSearch object.
1055 const HeaderSearchOptions &HSOpts,
1056 const LangOptions &Lang,
1057 const llvm::Triple &triple);
1058
1059void normalizeModuleCachePath(FileManager &FileMgr, StringRef Path,
1060 SmallVectorImpl<char> &NormalizedPath);
1061
1063 StringRef ModuleCachePath,
1064 bool DisableModuleHash,
1065 std::string ContextHash);
1066
1067} // namespace clang
1068
1069#endif // LLVM_CLANG_LEX_HEADERSEARCH_H
std::shared_ptr< TokenRole > Role
A token can have a special role that can carry extra information about the token's formatting.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:233
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 ...
An external source of header file information, which may supply information about header files alread...
virtual HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE)=0
Retrieve the header file information for the given file entry.
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...
Definition FileEntry.h:57
Cached information about one file (either on disk or in the virtual file system).
Definition FileEntry.h:273
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.
Definition FileManager.h:52
This class represents an Apple concept known as a 'header map'.
Definition HeaderMap.h:84
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
StringRef getUniqueFrameworkName(StringRef Framework)
Retrieve a uniqued framework name.
void SetExternalSource(ExternalHeaderFileInfoSource *ES)
Set the external source of header information.
HeaderSearch & operator=(const HeaderSearch &)=delete
unsigned search_dir_size() const
std::vector< bool > collectVFSUsageAndClear() const
Collect which HeaderSearchOptions::VFSOverlayFiles have been meaningfully used so far and mark their ...
SrcMgr::CharacteristicKind getFileDirFlavor(FileEntryRef File)
Return whether the specified file is a normal header, a system header, or a C++ friendly system heade...
FileManager & getFileMgr() const
void AddSearchPath(const DirectoryLookup &dir, bool isAngled)
Add an additional search path.
void diagnoseHeaderShadowing(StringRef Filename, OptionalFileEntryRef FE, bool &DiagnosedShadowing, SourceLocation IncludeLoc, ConstSearchDirIterator FromDir, ArrayRef< std::pair< OptionalFileEntryRef, DirectoryEntryRef > > Includers, bool isAngled, int IncluderLoopIndex, ConstSearchDirIterator MainLoopIt)
ConstSearchDirIterator angled_dir_end() const
Module * lookupModule(StringRef ModuleName, SourceLocation ImportLoc=SourceLocation(), bool AllowSearch=true, bool AllowExtraModuleMapSearch=false)
Lookup a module Search for a module with the given name.
void SetFileControllingMacro(FileEntryRef File, const IdentifierInfo *ControllingMacro)
Mark the specified file as having a controlling macro.
DiagnosticsEngine & getDiags() const
void MarkFileIncludeOnce(FileEntryRef File)
Mark the specified file as a "once only" file due to #pragma once.
ConstSearchDirIterator system_dir_begin() const
HeaderSearch(const HeaderSearch &)=delete
friend class DirectoryLookup
bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root, bool IsSystem)
Determine whether there is a module map that may map the header with the given file name to a (sub)mo...
std::string suggestPathToFileForDiagnostics(FileEntryRef File, llvm::StringRef MainFile, bool *IsAngled=nullptr) const
Suggest a path by which the specified file could be found, for use in diagnostics to suggest a includ...
ConstSearchDirIterator search_dir_end() const
OptionalFileEntryRef LookupFile(StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, ArrayRef< std::pair< OptionalFileEntryRef, DirectoryEntryRef > > Includers, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false, bool BuildSystemModule=false, bool OpenFile=true, bool CacheFailures=true)
Given a "foo" or <foo> reference, look up the indicated file, return null on failure.
void getHeaderMapFileNames(SmallVectorImpl< std::string > &Names) const
Get filenames for all registered header maps.
void MarkFileSystemHeader(FileEntryRef File)
Mark the specified file as a system header, e.g.
StringRef getIncludeNameForHeader(const FileEntry *File) const
Retrieve the include name for the header.
ConstSearchDirIterator angled_dir_begin() const
void SetSystemHeaderPrefixes(ArrayRef< std::pair< std::string, bool > > P)
Set the list of system header prefixes.
ArrayRef< ModuleMap::KnownHeader > findAllModulesForHeader(FileEntryRef File) const
Retrieve all the modules corresponding to the given file.
ConstSearchDirRange search_dir_range() const
bool hasFileBeenImported(FileEntryRef File) const
Determine whether the given file is known to have ever been #imported.
ModuleFileName getPrebuiltModuleFileName(StringRef ModuleName, bool FileMapOnly=false)
Retrieve the name of the prebuilt module file that should be used to load a module with the given nam...
unsigned searchDirIdx(const DirectoryLookup &DL) const
Get the index of the given search directory.
bool isFileMultipleIncludeGuarded(FileEntryRef File) const
Determine whether this file is intended to be safe from multiple inclusions, e.g.,...
StringRef getNormalizedModuleCachePath() const
Retrieve the normalized module cache path.
ConstSearchDirIterator quoted_dir_begin() const
ExternalPreprocessorSource * getExternalLookup() const
ModuleFileName getPrebuiltImplicitModuleFileName(Module *Module)
Retrieve the name of the prebuilt module file that should be used to load the given module.
ConstSearchDirIterator search_dir_nth(size_t n) const
void loadTopLevelSystemModules()
Load all known, top-level system modules.
SearchDirIterator search_dir_end()
FrameworkCacheEntry & LookupFrameworkCache(StringRef FWName)
Look up the specified framework name in our framework cache.
std::vector< bool > computeUserEntryUsage() const
Determine which HeaderSearchOptions::UserEntries have been successfully used so far and mark their in...
ConstSearchDirIterator quoted_dir_end() const
ArrayRef< ModuleMap::KnownHeader > findResolvedModulesForHeader(FileEntryRef File) const
Like findAllModulesForHeader, but do not attempt to infer module ownership from umbrella headers if w...
ModuleFileName getCachedModuleFileName(Module *Module)
Retrieve the name of the cached module file that should be used to load the given module.
void SetSearchPaths(std::vector< DirectoryLookup > dirs, unsigned angledDirIdx, unsigned systemDirIdx, llvm::DenseMap< unsigned, unsigned > searchDirToHSEntry)
Interface for setting the file search paths.
const ModuleMap & getModuleMap() const
Retrieve the module map.
void setTarget(const TargetInfo &Target)
Set the target information for the header search, if not already known.
const HeaderMap * CreateHeaderMap(FileEntryRef FE)
This method returns a HeaderMap for the specified FileEntry, uniquing them through the 'HeaderMaps' d...
ModuleMap::KnownHeader findModuleForHeader(FileEntryRef File, bool AllowTextual=false, bool AllowExcluded=false) const
Retrieve the module that corresponds to the given file, if any.
const HeaderSearchOptions & getHeaderSearchOpts() const
Retrieve the header-search options with which this header search was initialized.
SearchDirRange search_dir_range()
void collectAllModules(SmallVectorImpl< Module * > &Modules)
Collect the set of all known, top-level modules.
void MarkFileModuleHeader(FileEntryRef FE, ModuleMap::ModuleHeaderRole Role, bool isCompilingModuleHeader)
Mark the specified file as part of a module.
const HeaderFileInfo * getExistingFileInfo(FileEntryRef FE) const
Return the HeaderFileInfo structure for the specified FileEntry, if it has ever been filled in (eithe...
OptionalFileEntryRef LookupSubframeworkHeader(StringRef Filename, FileEntryRef ContextFileEnt, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule)
Look up a subframework for the specified #include file.
HeaderFileInfo & getFileInfo(FileEntryRef FE)
Return the HeaderFileInfo structure for the specified FileEntry, in preparation for updating it in so...
void SetExternalLookup(ExternalPreprocessorSource *EPS)
StringRef getSpecificModuleCachePath() const
Retrieve the specific module cache path.
OptionalFileEntryRef lookupModuleMapFile(DirectoryEntryRef Dir, bool IsFramework)
Try to find a module map file in the given directory, returning nullopt if none is found.
bool ShouldEnterIncludeFile(Preprocessor &PP, FileEntryRef File, bool isImport, bool ModulesEnabled, Module *M, bool &IsFirstIncludeOfFile)
Mark the specified file as a target of a #include, #include_next, or #import directive.
void forEachExistingLocalFileInfo(llvm::function_ref< void(FileEntryRef, const HeaderFileInfo &)> Fn) const
Iterate HeaderFileInfo structures and their corresponding FileEntryRef, if they have ever been filled...
size_t getTotalMemory() const
ModuleMap & getModuleMap()
Retrieve the module map.
bool parseAndLoadModuleMapFile(FileEntryRef File, bool IsSystem, bool ImplicitlyDiscovered, FileID ID=FileID(), unsigned *Offset=nullptr, StringRef OriginalModuleMapFile=StringRef())
Read the contents of the given module map file.
bool HasIncludeAliasMap() const
Checks whether the map exists or not.
HeaderSearch(const HeaderSearchOptions &HSOpts, SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target)
ConstSearchDirIterator system_dir_end() const
void ClearFileInfo()
Forget everything we know about headers so far.
ConstSearchDirIterator search_dir_begin() const
void AddIncludeAlias(StringRef Source, StringRef Dest)
Map the source include name to the dest include name.
StringRef MapHeaderToIncludeAlias(StringRef Source)
Maps one header file name to a different header file name, for use with the include_alias pragma.
StringRef getContextHash() const
Retrieve the context hash.
SearchDirIterator search_dir_begin()
void AddSystemSearchPath(const DirectoryLookup &dir)
Add an additional system search path.
void initializeModuleCachePath(std::string ContextHash)
Initialize the module cache path.
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Identifies a module file to be loaded.
Definition Module.h:109
A header that is known to reside within a given module, whether it was included or excluded.
Definition ModuleMap.h:158
ModuleHeaderRole
Flags describing the role of a module header.
Definition ModuleMap.h:126
Describes a module or submodule.
Definition Module.h:340
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.
Definition TargetInfo.h:227
Public enums and private classes that are part of the SourceManager implementation.
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.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition FileEntry.h:196
void ApplyHeaderSearchOptions(HeaderSearch &HS, const HeaderSearchOptions &HSOpts, const LangOptions &Lang, const llvm::Triple &triple)
Apply the header search options to get given HeaderSearch object.
detail::SearchDirIteratorImpl< true > ConstSearchDirIterator
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
detail::SearchDirIteratorImpl< false > SearchDirIterator
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
Definition Linkage.h:58
llvm::iterator_range< ConstSearchDirIterator > ConstSearchDirRange
std::string createSpecificModuleCachePath(FileManager &FileMgr, StringRef ModuleCachePath, bool DisableModuleHash, std::string ContextHash)
void normalizeModuleCachePath(FileManager &FileMgr, StringRef Path, SmallVectorImpl< char > &NormalizedPath)
llvm::iterator_range< SearchDirIterator > SearchDirRange
CustomizableOptional< DirectoryEntryRef > OptionalDirectoryEntryRef
@ Other
Other implicit parameter.
Definition Decl.h:1763
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
#define false
Definition stdbool.h:26
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.
The preprocessor keeps track of this information for each file that is #included.
void mergeModuleMembership(ModuleMap::ModuleHeaderRole Role)
Update the module membership bits based on the header role.
LazyIdentifierInfoPtr LazyControllingMacro
If this file has a #ifndef XXX (or equivalent) guard that protects the entire contents of the file,...
unsigned DirInfo
Keep track of whether this is a system header, and if so, whether it is C++ clean or not.
unsigned isModuleHeader
Whether this header is part of and built with a module.
const IdentifierInfo * getControllingMacro(ExternalPreprocessorSource *External)
Retrieve the controlling macro for this header file, if any.
unsigned isTextualModuleHeader
Whether this header is a textual header in a module.
unsigned isPragmaOnce
True if this is a #pragma once file.
unsigned Resolved
Whether this structure is considered to already have been "resolved", meaning that it was loaded from...
unsigned isCompilingModuleHeader
Whether this header is part of the module that we are building, even if it doesn't build with the mod...
unsigned IsValid
Whether this file has been looked up as a header.
unsigned isImport
True if this is a #import'd file.
unsigned IsLocallyIncluded
True if this file has been included (or imported) locally.
unsigned External
Whether this header file info was supplied by an external source, and has not changed since.
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