clang  3.7.0
HeaderSearch.h
Go to the documentation of this file.
1 //===--- HeaderSearch.h - Resolve Header File Locations ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the HeaderSearch interface.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LEX_HEADERSEARCH_H
15 #define LLVM_CLANG_LEX_HEADERSEARCH_H
16 
18 #include "clang/Lex/ModuleMap.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/IntrusiveRefCntPtr.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringSet.h"
23 #include "llvm/Support/Allocator.h"
24 #include <memory>
25 #include <vector>
26 
27 namespace clang {
28 
29 class DiagnosticsEngine;
30 class ExternalPreprocessorSource;
31 class FileEntry;
32 class FileManager;
33 class HeaderSearchOptions;
34 class IdentifierInfo;
35 class Preprocessor;
36 
37 /// \brief The preprocessor keeps track of this information for each
38 /// file that is \#included.
40  /// \brief True if this is a \#import'd or \#pragma once file.
41  unsigned isImport : 1;
42 
43  /// \brief True if this is a \#pragma once file.
44  unsigned isPragmaOnce : 1;
45 
46  /// DirInfo - Keep track of whether this is a system header, and if so,
47  /// whether it is C++ clean or not. This can be set by the include paths or
48  /// by \#pragma gcc system_header. This is an instance of
49  /// SrcMgr::CharacteristicKind.
50  unsigned DirInfo : 2;
51 
52  /// \brief Whether this header file info was supplied by an external source.
53  unsigned External : 1;
54 
55  /// \brief Whether this header is part of a module.
56  unsigned isModuleHeader : 1;
57 
58  /// \brief Whether this header is part of the module that we are building.
60 
61  /// \brief Whether this header is part of the module that we are building.
62  /// This is an instance of ModuleMap::ModuleHeaderRole.
63  unsigned HeaderRole : 2;
64 
65  /// \brief Whether this structure is considered to already have been
66  /// "resolved", meaning that it was loaded from the external source.
67  unsigned Resolved : 1;
68 
69  /// \brief Whether this is a header inside a framework that is currently
70  /// being built.
71  ///
72  /// When a framework is being built, the headers have not yet been placed
73  /// into the appropriate framework subdirectories, and therefore are
74  /// provided via a header map. This bit indicates when this is one of
75  /// those framework headers.
76  unsigned IndexHeaderMapHeader : 1;
77 
78  /// \brief Whether this file had been looked up as a header.
79  unsigned IsValid : 1;
80 
81  /// \brief The number of times the file has been included already.
82  unsigned short NumIncludes;
83 
84  /// \brief The ID number of the controlling macro.
85  ///
86  /// This ID number will be non-zero when there is a controlling
87  /// macro whose IdentifierInfo may not yet have been loaded from
88  /// external storage.
90 
91  /// If this file has a \#ifndef XXX (or equivalent) guard that
92  /// protects the entire contents of the file, this is the identifier
93  /// for the macro that controls whether or not it has any effect.
94  ///
95  /// Note: Most clients should use getControllingMacro() to access
96  /// the controlling macro of this header, since
97  /// getControllingMacro() is able to load a controlling macro from
98  /// external storage.
100 
101  /// \brief If this header came from a framework include, this is the name
102  /// of the framework.
103  StringRef Framework;
104 
106  : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User),
108  HeaderRole(ModuleMap::NormalHeader),
111 
112  /// \brief Retrieve the controlling macro for this header file, if
113  /// any.
114  const IdentifierInfo *
116 
117  /// \brief Determine whether this is a non-default header file info, e.g.,
118  /// it corresponds to an actual header we've included or tried to include.
119  bool isNonDefault() const {
122  }
123 
124  /// \brief Get the HeaderRole properly typed.
126  return static_cast<ModuleMap::ModuleHeaderRole>(HeaderRole);
127  }
128 
129  /// \brief Set the HeaderRole properly typed.
131  HeaderRole = Role;
132  }
133 };
134 
135 /// \brief An external source of header file information, which may supply
136 /// information about header files already included.
138 public:
140 
141  /// \brief Retrieve the header file information for the given file entry.
142  ///
143  /// \returns Header file information for the given file entry, with the
144  /// \c External bit set. If the file entry is not known, return a
145  /// default-constructed \c HeaderFileInfo.
146  virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0;
147 };
148 
149 /// \brief Encapsulates the information needed to find the file referenced
150 /// by a \#include or \#include_next, (sub-)framework lookup, etc.
152  /// This structure is used to record entries in our framework cache.
153  struct FrameworkCacheEntry {
154  /// The directory entry which should be used for the cached framework.
155  const DirectoryEntry *Directory;
156 
157  /// Whether this framework has been "user-specified" to be treated as if it
158  /// were a system framework (even if it was found outside a system framework
159  /// directory).
160  bool IsUserSpecifiedSystemFramework;
161  };
162 
163  /// \brief Header-search options used to initialize this header search.
165 
166  DiagnosticsEngine &Diags;
167  FileManager &FileMgr;
168  /// \#include search path information. Requests for \#include "x" search the
169  /// directory of the \#including file first, then each directory in SearchDirs
170  /// consecutively. Requests for <x> search the current dir first, then each
171  /// directory in SearchDirs, starting at AngledDirIdx, consecutively. If
172  /// NoCurDirSearch is true, then the check for the file in the current
173  /// directory is suppressed.
174  std::vector<DirectoryLookup> SearchDirs;
175  unsigned AngledDirIdx;
176  unsigned SystemDirIdx;
177  bool NoCurDirSearch;
178 
179  /// \brief \#include prefixes for which the 'system header' property is
180  /// overridden.
181  ///
182  /// For a \#include "x" or \#include <x> directive, the last string in this
183  /// list which is a prefix of 'x' determines whether the file is treated as
184  /// a system header.
185  std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
186 
187  /// \brief The path to the module cache.
188  std::string ModuleCachePath;
189 
190  /// \brief All of the preprocessor-specific data about files that are
191  /// included, indexed by the FileEntry's UID.
192  std::vector<HeaderFileInfo> FileInfo;
193 
194  /// Keeps track of each lookup performed by LookupFile.
195  struct LookupFileCacheInfo {
196  /// Starting index in SearchDirs that the cached search was performed from.
197  /// If there is a hit and this value doesn't match the current query, the
198  /// cache has to be ignored.
199  unsigned StartIdx;
200  /// The entry in SearchDirs that satisfied the query.
201  unsigned HitIdx;
202  /// This is non-null if the original filename was mapped to a framework
203  /// include via a headermap.
204  const char *MappedName;
205 
206  /// Default constructor -- Initialize all members with zero.
207  LookupFileCacheInfo(): StartIdx(0), HitIdx(0), MappedName(nullptr) {}
208 
209  void reset(unsigned StartIdx) {
210  this->StartIdx = StartIdx;
211  this->MappedName = nullptr;
212  }
213  };
214  llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache;
215 
216  /// \brief Collection mapping a framework or subframework
217  /// name like "Carbon" to the Carbon.framework directory.
218  llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap;
219 
220  /// IncludeAliases - maps include file names (including the quotes or
221  /// angle brackets) to other include file names. This is used to support the
222  /// include_alias pragma for Microsoft compatibility.
223  typedef llvm::StringMap<std::string, llvm::BumpPtrAllocator>
224  IncludeAliasMap;
225  std::unique_ptr<IncludeAliasMap> IncludeAliases;
226 
227  /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing
228  /// headermaps. This vector owns the headermap.
229  std::vector<std::pair<const FileEntry*, const HeaderMap*> > HeaderMaps;
230 
231  /// \brief The mapping between modules and headers.
232  mutable ModuleMap ModMap;
233 
234  /// \brief Describes whether a given directory has a module map in it.
235  llvm::DenseMap<const DirectoryEntry *, bool> DirectoryHasModuleMap;
236 
237  /// \brief 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;
240 
241  /// \brief Uniqued set of framework names, which is used to track which
242  /// headers were included as framework headers.
243  llvm::StringSet<llvm::BumpPtrAllocator> FrameworkNames;
244 
245  /// \brief Entity used to resolve the identifier IDs of controlling
246  /// macros into IdentifierInfo pointers, and keep the identifire up to date,
247  /// as needed.
248  ExternalPreprocessorSource *ExternalLookup;
249 
250  /// \brief Entity used to look up stored header file information.
251  ExternalHeaderFileInfoSource *ExternalSource;
252 
253  // Various statistics we track for performance analysis.
254  unsigned NumIncluded;
255  unsigned NumMultiIncludeFileOptzn;
256  unsigned NumFrameworkLookups, NumSubFrameworkLookups;
257 
258  const LangOptions &LangOpts;
259 
260  // HeaderSearch doesn't support default or copy construction.
261  HeaderSearch(const HeaderSearch&) = delete;
262  void operator=(const HeaderSearch&) = delete;
263 
264  friend class DirectoryLookup;
265 
266 public:
269  const LangOptions &LangOpts, const TargetInfo *Target);
270  ~HeaderSearch();
271 
272  /// \brief Retrieve the header-search options with which this header search
273  /// was initialized.
274  HeaderSearchOptions &getHeaderSearchOpts() const { return *HSOpts; }
275 
276  FileManager &getFileMgr() const { return FileMgr; }
277 
278  /// \brief Interface for setting the file search paths.
279  void SetSearchPaths(const std::vector<DirectoryLookup> &dirs,
280  unsigned angledDirIdx, unsigned systemDirIdx,
281  bool noCurDirSearch) {
282  assert(angledDirIdx <= systemDirIdx && systemDirIdx <= dirs.size() &&
283  "Directory indicies are unordered");
284  SearchDirs = dirs;
285  AngledDirIdx = angledDirIdx;
286  SystemDirIdx = systemDirIdx;
287  NoCurDirSearch = noCurDirSearch;
288  //LookupFileCache.clear();
289  }
290 
291  /// \brief Add an additional search path.
292  void AddSearchPath(const DirectoryLookup &dir, bool isAngled) {
293  unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx;
294  SearchDirs.insert(SearchDirs.begin() + idx, dir);
295  if (!isAngled)
296  AngledDirIdx++;
297  SystemDirIdx++;
298  }
299 
300  /// \brief Set the list of system header prefixes.
301  void SetSystemHeaderPrefixes(ArrayRef<std::pair<std::string, bool> > P) {
302  SystemHeaderPrefixes.assign(P.begin(), P.end());
303  }
304 
305  /// \brief Checks whether the map exists or not.
306  bool HasIncludeAliasMap() const { return (bool)IncludeAliases; }
307 
308  /// \brief Map the source include name to the dest include name.
309  ///
310  /// The Source should include the angle brackets or quotes, the dest
311  /// should not. This allows for distinction between <> and "" headers.
312  void AddIncludeAlias(StringRef Source, StringRef Dest) {
313  if (!IncludeAliases)
314  IncludeAliases.reset(new IncludeAliasMap);
315  (*IncludeAliases)[Source] = Dest;
316  }
317 
318  /// MapHeaderToIncludeAlias - Maps one header file name to a different header
319  /// file name, for use with the include_alias pragma. Note that the source
320  /// file name should include the angle brackets or quotes. Returns StringRef
321  /// as null if the header cannot be mapped.
322  StringRef MapHeaderToIncludeAlias(StringRef Source) {
323  assert(IncludeAliases && "Trying to map headers when there's no map");
324 
325  // Do any filename replacements before anything else
326  IncludeAliasMap::const_iterator Iter = IncludeAliases->find(Source);
327  if (Iter != IncludeAliases->end())
328  return Iter->second;
329  return StringRef();
330  }
331 
332  /// \brief Set the path to the module cache.
333  void setModuleCachePath(StringRef CachePath) {
334  ModuleCachePath = CachePath;
335  }
336 
337  /// \brief Retrieve the path to the module cache.
338  StringRef getModuleCachePath() const { return ModuleCachePath; }
339 
340  /// \brief Consider modules when including files from this directory.
342  DirectoryHasModuleMap[Dir] = true;
343  }
344 
345  /// \brief Forget everything we know about headers so far.
346  void ClearFileInfo() {
347  FileInfo.clear();
348  }
349 
351  ExternalLookup = EPS;
352  }
353 
355  return ExternalLookup;
356  }
357 
358  /// \brief Set the external source of header information.
360  ExternalSource = ES;
361  }
362 
363  /// \brief Set the target information for the header search, if not
364  /// already known.
365  void setTarget(const TargetInfo &Target);
366 
367  /// \brief Given a "foo" or <foo> reference, look up the indicated file,
368  /// return null on failure.
369  ///
370  /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member
371  /// the file was found in, or null if not applicable.
372  ///
373  /// \param IncludeLoc Used for diagnostics if valid.
374  ///
375  /// \param isAngled indicates whether the file reference is a <> reference.
376  ///
377  /// \param CurDir If non-null, the file was found in the specified directory
378  /// search location. This is used to implement \#include_next.
379  ///
380  /// \param Includers Indicates where the \#including file(s) are, in case
381  /// relative searches are needed. In reverse order of inclusion.
382  ///
383  /// \param SearchPath If non-null, will be set to the search path relative
384  /// to which the file was found. If the include path is absolute, SearchPath
385  /// will be set to an empty string.
386  ///
387  /// \param RelativePath If non-null, will be set to the path relative to
388  /// SearchPath at which the file was found. This only differs from the
389  /// Filename for framework includes.
390  ///
391  /// \param SuggestedModule If non-null, and the file found is semantically
392  /// part of a known module, this will be set to the module that should
393  /// be imported instead of preprocessing/parsing the file found.
394  const FileEntry *LookupFile(
395  StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
396  const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir,
397  ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
398  SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
399  ModuleMap::KnownHeader *SuggestedModule, bool SkipCache = false);
400 
401  /// \brief Look up a subframework for the specified \#include file.
402  ///
403  /// For example, if \#include'ing <HIToolbox/HIToolbox.h> from
404  /// within ".../Carbon.framework/Headers/Carbon.h", check to see if
405  /// HIToolbox is a subframework within Carbon.framework. If so, return
406  /// the FileEntry for the designated file, otherwise return null.
408  StringRef Filename,
409  const FileEntry *RelativeFileEnt,
410  SmallVectorImpl<char> *SearchPath,
411  SmallVectorImpl<char> *RelativePath,
412  ModuleMap::KnownHeader *SuggestedModule);
413 
414  /// \brief Look up the specified framework name in our framework cache.
415  /// \returns The DirectoryEntry it is in if we know, null otherwise.
416  FrameworkCacheEntry &LookupFrameworkCache(StringRef FWName) {
417  return FrameworkMap[FWName];
418  }
419 
420  /// \brief Mark the specified file as a target of of a \#include,
421  /// \#include_next, or \#import directive.
422  ///
423  /// \return false if \#including the file will have no effect or true
424  /// if we should include it.
425  bool ShouldEnterIncludeFile(Preprocessor &PP, const FileEntry *File,
426  bool isImport, Module *CorrespondingModule);
427 
428  /// \brief Return whether the specified file is a normal header,
429  /// a system header, or a C++ friendly system header.
431  return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo;
432  }
433 
434  /// \brief Mark the specified file as a "once only" file, e.g. due to
435  /// \#pragma once.
436  void MarkFileIncludeOnce(const FileEntry *File) {
437  HeaderFileInfo &FI = getFileInfo(File);
438  FI.isImport = true;
439  FI.isPragmaOnce = true;
440  }
441 
442  /// \brief Mark the specified file as a system header, e.g. due to
443  /// \#pragma GCC system_header.
444  void MarkFileSystemHeader(const FileEntry *File) {
445  getFileInfo(File).DirInfo = SrcMgr::C_System;
446  }
447 
448  /// \brief Mark the specified file as part of a module.
449  void MarkFileModuleHeader(const FileEntry *File,
451  bool IsCompiledModuleHeader);
452 
453  /// \brief Increment the count for the number of times the specified
454  /// FileEntry has been entered.
455  void IncrementIncludeCount(const FileEntry *File) {
456  ++getFileInfo(File).NumIncludes;
457  }
458 
459  /// \brief Mark the specified file as having a controlling macro.
460  ///
461  /// This is used by the multiple-include optimization to eliminate
462  /// no-op \#includes.
464  const IdentifierInfo *ControllingMacro) {
465  getFileInfo(File).ControllingMacro = ControllingMacro;
466  }
467 
468  /// \brief Return true if this is the first time encountering this header.
469  bool FirstTimeLexingFile(const FileEntry *File) {
470  return getFileInfo(File).NumIncludes == 1;
471  }
472 
473  /// \brief Determine whether this file is intended to be safe from
474  /// multiple inclusions, e.g., it has \#pragma once or a controlling
475  /// macro.
476  ///
477  /// This routine does not consider the effect of \#import
478  bool isFileMultipleIncludeGuarded(const FileEntry *File);
479 
480  /// CreateHeaderMap - This method returns a HeaderMap for the specified
481  /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
482  const HeaderMap *CreateHeaderMap(const FileEntry *FE);
483 
484  /// \brief Retrieve the name of the module file that should be used to
485  /// load the given module.
486  ///
487  /// \param Module The module whose module file name will be returned.
488  ///
489  /// \returns The name of the module file that corresponds to this module,
490  /// or an empty string if this module does not correspond to any module file.
491  std::string getModuleFileName(Module *Module);
492 
493  /// \brief Retrieve the name of the module file that should be used to
494  /// load a module with the given name.
495  ///
496  /// \param ModuleName The module whose module file name will be returned.
497  ///
498  /// \param ModuleMapPath A path that when combined with \c ModuleName
499  /// uniquely identifies this module. See Module::ModuleMap.
500  ///
501  /// \returns The name of the module file that corresponds to this module,
502  /// or an empty string if this module does not correspond to any module file.
503  std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath);
504 
505  /// \brief Lookup a module Search for a module with the given name.
506  ///
507  /// \param ModuleName The name of the module we're looking for.
508  ///
509  /// \param AllowSearch Whether we are allowed to search in the various
510  /// search directories to produce a module definition. If not, this lookup
511  /// will only return an already-known module.
512  ///
513  /// \returns The module with the given name.
514  Module *lookupModule(StringRef ModuleName, bool AllowSearch = true);
515 
516  /// \brief Try to find a module map file in the given directory, returning
517  /// \c nullptr if none is found.
518  const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir,
519  bool IsFramework);
520 
521  void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
522 
523  /// \brief Determine whether there is a module map that may map the header
524  /// with the given file name to a (sub)module.
525  /// Always returns false if modules are disabled.
526  ///
527  /// \param Filename The name of the file.
528  ///
529  /// \param Root The "root" directory, at which we should stop looking for
530  /// module maps.
531  ///
532  /// \param IsSystem Whether the directories we're looking at are system
533  /// header directories.
534  bool hasModuleMap(StringRef Filename, const DirectoryEntry *Root,
535  bool IsSystem);
536 
537  /// \brief Retrieve the module that corresponds to the given file, if any.
538  ///
539  /// \param File The header that we wish to map to a module.
541 
542  /// \brief Read the contents of the given module map file.
543  ///
544  /// \param File The module map file.
545  /// \param IsSystem Whether this file is in a system header directory.
546  ///
547  /// \returns true if an error occurred, false otherwise.
548  bool loadModuleMapFile(const FileEntry *File, bool IsSystem);
549 
550  /// \brief Collect the set of all known, top-level modules.
551  ///
552  /// \param Modules Will be filled with the set of known, top-level modules.
554 
555  /// \brief Load all known, top-level system modules.
557 
558 private:
559  /// \brief Retrieve a module with the given name, which may be part of the
560  /// given framework.
561  ///
562  /// \param Name The name of the module to retrieve.
563  ///
564  /// \param Dir The framework directory (e.g., ModuleName.framework).
565  ///
566  /// \param IsSystem Whether the framework directory is part of the system
567  /// frameworks.
568  ///
569  /// \returns The module, if found; otherwise, null.
570  Module *loadFrameworkModule(StringRef Name,
571  const DirectoryEntry *Dir,
572  bool IsSystem);
573 
574  /// \brief Load all of the module maps within the immediate subdirectories
575  /// of the given search directory.
576  void loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir);
577 
578  /// \brief Return the HeaderFileInfo structure for the specified FileEntry.
579  const HeaderFileInfo &getFileInfo(const FileEntry *FE) const {
580  return const_cast<HeaderSearch*>(this)->getFileInfo(FE);
581  }
582 
583 public:
584  /// \brief Retrieve the module map.
585  ModuleMap &getModuleMap() { return ModMap; }
586 
587  unsigned header_file_size() const { return FileInfo.size(); }
588 
589  /// \brief Get a \c HeaderFileInfo structure for the specified \c FileEntry,
590  /// if one exists.
591  bool tryGetFileInfo(const FileEntry *FE, HeaderFileInfo &Result) const;
592 
593  // Used by external tools
594  typedef std::vector<DirectoryLookup>::const_iterator search_dir_iterator;
595  search_dir_iterator search_dir_begin() const { return SearchDirs.begin(); }
596  search_dir_iterator search_dir_end() const { return SearchDirs.end(); }
597  unsigned search_dir_size() const { return SearchDirs.size(); }
598 
600  return SearchDirs.begin();
601  }
603  return SearchDirs.begin() + AngledDirIdx;
604  }
605 
607  return SearchDirs.begin() + AngledDirIdx;
608  }
610  return SearchDirs.begin() + SystemDirIdx;
611  }
612 
614  return SearchDirs.begin() + SystemDirIdx;
615  }
616  search_dir_iterator system_dir_end() const { return SearchDirs.end(); }
617 
618  /// \brief Retrieve a uniqued framework name.
619  StringRef getUniqueFrameworkName(StringRef Framework);
620 
621  void PrintStats();
622 
623  size_t getTotalMemory() const;
624 
625  static std::string NormalizeDashIncludePath(StringRef File,
626  FileManager &FileMgr);
627 
628 private:
629  /// \brief Describes what happened when we tried to load a module map file.
630  enum LoadModuleMapResult {
631  /// \brief The module map file had already been loaded.
632  LMM_AlreadyLoaded,
633  /// \brief The module map file was loaded by this invocation.
634  LMM_NewlyLoaded,
635  /// \brief There is was directory with the given name.
636  LMM_NoDirectory,
637  /// \brief There was either no module map file or the module map file was
638  /// invalid.
639  LMM_InvalidModuleMap
640  };
641 
642  LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File,
643  bool IsSystem,
644  const DirectoryEntry *Dir);
645 
646  /// \brief Try to load the module map file in the given directory.
647  ///
648  /// \param DirName The name of the directory where we will look for a module
649  /// map file.
650  /// \param IsSystem Whether this is a system header directory.
651  /// \param IsFramework Whether this is a framework directory.
652  ///
653  /// \returns The result of attempting to load the module map file from the
654  /// named directory.
655  LoadModuleMapResult loadModuleMapFile(StringRef DirName, bool IsSystem,
656  bool IsFramework);
657 
658  /// \brief Try to load the module map file in the given directory.
659  ///
660  /// \param Dir The directory where we will look for a module map file.
661  /// \param IsSystem Whether this is a system header directory.
662  /// \param IsFramework Whether this is a framework directory.
663  ///
664  /// \returns The result of attempting to load the module map file from the
665  /// named directory.
666  LoadModuleMapResult loadModuleMapFile(const DirectoryEntry *Dir,
667  bool IsSystem, bool IsFramework);
668 
669  /// \brief Return the HeaderFileInfo structure for the specified FileEntry.
670  HeaderFileInfo &getFileInfo(const FileEntry *FE);
671 };
672 
673 } // end namespace clang
674 
675 #endif
unsigned HeaderRole
Whether this header is part of the module that we are building. This is an instance of ModuleMap::Mod...
Definition: HeaderSearch.h:63
search_dir_iterator search_dir_begin() const
Definition: HeaderSearch.h:595
search_dir_iterator quoted_dir_end() const
Definition: HeaderSearch.h:602
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:115
unsigned isPragmaOnce
True if this is a #pragma once file.
Definition: HeaderSearch.h:44
void loadTopLevelSystemModules()
Load all known, top-level system modules.
void SetSearchPaths(const std::vector< DirectoryLookup > &dirs, unsigned angledDirIdx, unsigned systemDirIdx, bool noCurDirSearch)
Interface for setting the file search paths.
Definition: HeaderSearch.h:279
std::string getModuleFileName(Module *Module)
Retrieve the name of the module file that should be used to load the given module.
bool isFileMultipleIncludeGuarded(const FileEntry *File)
Determine whether this file is intended to be safe from multiple inclusions, e.g., it has #pragma once or a controlling macro.
void MarkFileModuleHeader(const FileEntry *File, ModuleMap::ModuleHeaderRole Role, bool IsCompiledModuleHeader)
Mark the specified file as part of a module.
FrameworkCacheEntry & LookupFrameworkCache(StringRef FWName)
Look up the specified framework name in our framework cache.
Definition: HeaderSearch.h:416
const FileEntry * lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework)
Try to find a module map file in the given directory, returning nullptr if none is found...
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:78
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:585
unsigned isCompilingModuleHeader
Whether this header is part of the module that we are building.
Definition: HeaderSearch.h:59
unsigned isImport
True if this is a #import'd or #pragma once file.
Definition: HeaderSearch.h:41
void ClearFileInfo()
Forget everything we know about headers so far.
Definition: HeaderSearch.h:346
bool tryGetFileInfo(const FileEntry *FE, HeaderFileInfo &Result) const
Get a HeaderFileInfo structure for the specified FileEntry, if one exists.
search_dir_iterator system_dir_end() const
Definition: HeaderSearch.h:616
StringRef getModuleCachePath() const
Retrieve the path to the module cache.
Definition: HeaderSearch.h:338
bool HasIncludeAliasMap() const
Checks whether the map exists or not.
Definition: HeaderSearch.h:306
void setTarget(const TargetInfo &Target)
Set the target information for the header search, if not already known.
const IdentifierInfo * getControllingMacro(ExternalPreprocessorSource *External)
Retrieve the controlling macro for this header file, if any.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Describes a module or submodule.
Definition: Basic/Module.h:49
unsigned External
Whether this header file info was supplied by an external source.
Definition: HeaderSearch.h:53
search_dir_iterator angled_dir_end() const
Definition: HeaderSearch.h:609
void AddIncludeAlias(StringRef Source, StringRef Dest)
Map the source include name to the dest include name.
Definition: HeaderSearch.h:312
unsigned search_dir_size() const
Definition: HeaderSearch.h:597
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
unsigned short NumIncludes
The number of times the file has been included already.
Definition: HeaderSearch.h:82
void setHeaderRole(ModuleMap::ModuleHeaderRole Role)
Set the HeaderRole properly typed.
Definition: HeaderSearch.h:130
unsigned Resolved
Whether this structure is considered to already have been "resolved", meaning that it was loaded from...
Definition: HeaderSearch.h:67
search_dir_iterator angled_dir_begin() const
Definition: HeaderSearch.h:606
virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE)=0
Retrieve the header file information for the given file entry.
The preprocessor keeps track of this information for each file that is #included. ...
Definition: HeaderSearch.h:39
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:151
AnnotatingParser & P
size_t getTotalMemory() const
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:72
ModuleMap::KnownHeader findModuleForHeader(const FileEntry *File) const
Retrieve the module that corresponds to the given file, if any.
Exposes information about the current target.
void SetSystemHeaderPrefixes(ArrayRef< std::pair< std::string, bool > > P)
Set the list of system header prefixes.
Definition: HeaderSearch.h:301
Abstract interface for external sources of preprocessor information.
HeaderSearchOptions & getHeaderSearchOpts() const
Retrieve the header-search options with which this header search was initialized. ...
Definition: HeaderSearch.h:274
SourceManager & SourceMgr
Definition: Format.cpp:1205
bool loadModuleMapFile(const FileEntry *File, bool IsSystem)
Read the contents of the given module map file.
unsigned header_file_size() const
Definition: HeaderSearch.h:587
void IncrementIncludeCount(const FileEntry *File)
Increment the count for the number of times the specified FileEntry has been entered.
Definition: HeaderSearch.h:455
The result type of a method or function.
Module * lookupModule(StringRef ModuleName, bool AllowSearch=true)
Lookup a module Search for a module with the given name.
SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File)
Return whether the specified file is a normal header, a system header, or a C++ friendly system heade...
Definition: HeaderSearch.h:430
void collectAllModules(SmallVectorImpl< Module * > &Modules)
Collect the set of all known, top-level modules.
unsigned isModuleHeader
Whether this header is part of a module.
Definition: HeaderSearch.h:56
#define false
Definition: stdbool.h:33
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
ExternalPreprocessorSource * getExternalLookup() const
Definition: HeaderSearch.h:354
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
FileManager & getFileMgr() const
Definition: HeaderSearch.h:276
const IdentifierInfo * ControllingMacro
Definition: HeaderSearch.h:99
std::vector< DirectoryLookup >::const_iterator search_dir_iterator
Definition: HeaderSearch.h:594
search_dir_iterator system_dir_begin() const
Definition: HeaderSearch.h:613
unsigned ControllingMacroID
The ID number of the controlling macro.
Definition: HeaderSearch.h:89
An external source of header file information, which may supply information about header files alread...
Definition: HeaderSearch.h:137
void SetExternalSource(ExternalHeaderFileInfoSource *ES)
Set the external source of header information.
Definition: HeaderSearch.h:359
void IncrementFrameworkLookupCount()
Definition: HeaderSearch.h:521
bool isNonDefault() const
Determine whether this is a non-default header file info, e.g., it corresponds to an actual header we...
Definition: HeaderSearch.h:119
void AddSearchPath(const DirectoryLookup &dir, bool isAngled)
Add an additional search path.
Definition: HeaderSearch.h:292
Cached information about one directory (either on disk or in the virtual file system).
Definition: FileManager.h:40
StringRef Framework
If this header came from a framework include, this is the name of the framework.
Definition: HeaderSearch.h:103
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...
search_dir_iterator search_dir_end() const
Definition: HeaderSearch.h:596
bool ShouldEnterIncludeFile(Preprocessor &PP, const FileEntry *File, bool isImport, Module *CorrespondingModule)
Mark the specified file as a target of of a #include, #include_next, or #import directive.
void setDirectoryHasModuleMap(const DirectoryEntry *Dir)
Consider modules when including files from this directory.
Definition: HeaderSearch.h:341
const HeaderMap * CreateHeaderMap(const FileEntry *FE)
const FileEntry * LookupSubframeworkHeader(StringRef Filename, const FileEntry *RelativeFileEnt, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule)
Look up a subframework for the specified #include file.
search_dir_iterator quoted_dir_begin() const
Definition: HeaderSearch.h:599
StringRef MapHeaderToIncludeAlias(StringRef Source)
Definition: HeaderSearch.h:322
static std::string NormalizeDashIncludePath(StringRef File, FileManager &FileMgr)
bool FirstTimeLexingFile(const FileEntry *File)
Return true if this is the first time encountering this header.
Definition: HeaderSearch.h:469
void SetExternalLookup(ExternalPreprocessorSource *EPS)
Definition: HeaderSearch.h:350
unsigned IndexHeaderMapHeader
Whether this is a header inside a framework that is currently being built.
Definition: HeaderSearch.h:76
unsigned IsValid
Whether this file had been looked up as a header.
Definition: HeaderSearch.h:79
void MarkFileSystemHeader(const FileEntry *File)
Mark the specified file as a system header, e.g. due to #pragma GCC system_header.
Definition: HeaderSearch.h:444
A header that is known to reside within a given module, whether it was included or excluded...
Definition: ModuleMap.h:90
const FileEntry * LookupFile(StringRef Filename, SourceLocation IncludeLoc, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, ArrayRef< std::pair< const FileEntry *, const DirectoryEntry * >> Includers, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file, return null on failure.
void MarkFileIncludeOnce(const FileEntry *File)
Mark the specified file as a "once only" file, e.g. due to #pragma once.
Definition: HeaderSearch.h:436
void setModuleCachePath(StringRef CachePath)
Set the path to the module cache.
Definition: HeaderSearch.h:333
This class handles loading and caching of source files into memory.
ModuleMap::ModuleHeaderRole getHeaderRole() const
Get the HeaderRole properly typed.
Definition: HeaderSearch.h:125
StringRef getUniqueFrameworkName(StringRef Framework)
Retrieve a uniqued framework name.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96
void SetFileControllingMacro(const FileEntry *File, const IdentifierInfo *ControllingMacro)
Mark the specified file as having a controlling macro.
Definition: HeaderSearch.h:463