clang  14.0.0git
HeaderSearchOptions.h
Go to the documentation of this file.
1 //===- HeaderSearchOptions.h ------------------------------------*- 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 #ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
10 #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/CachedHashString.h"
14 #include "llvm/ADT/Hashing.h"
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/HashBuilder.h"
18 #include <cstdint>
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 namespace clang {
24 
25 namespace frontend {
26 
27 /// IncludeDirGroup - Identifies the group an include Entry belongs to,
28 /// representing its relative positive in the search list.
29 /// \#include directives whose paths are enclosed by string quotes ("")
30 /// start searching at the Quoted group (specified by '-iquote'),
31 /// then search the Angled group, then the System group, etc.
33  /// '\#include ""' paths, added by 'gcc -iquote'.
34  Quoted = 0,
35 
36  /// Paths for '\#include <>' added by '-I'.
38 
39  /// Like Angled, but marks header maps used when building frameworks.
41 
42  /// Like Angled, but marks system directories.
44 
45  /// Like System, but headers are implicitly wrapped in extern "C".
47 
48  /// Like System, but only used for C.
50 
51  /// Like System, but only used for C++.
53 
54  /// Like System, but only used for ObjC.
56 
57  /// Like System, but only used for ObjC++.
59 
60  /// Like System, but searched after the system directories.
62 };
63 
64 } // namespace frontend
65 
66 /// HeaderSearchOptions - Helper class for storing options related to the
67 /// initialization of the HeaderSearch object.
69 public:
70  struct Entry {
73  unsigned IsFramework : 1;
74 
75  /// IgnoreSysRoot - This is false if an absolute path should be treated
76  /// relative to the sysroot, or true if it should always be the absolute
77  /// path.
78  unsigned IgnoreSysRoot : 1;
79 
80  Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
81  bool ignoreSysRoot)
82  : Path(path), Group(group), IsFramework(isFramework),
83  IgnoreSysRoot(ignoreSysRoot) {}
84  };
85 
87  /// A prefix to be matched against paths in \#include directives.
89 
90  /// True if paths beginning with this prefix should be treated as system
91  /// headers.
93 
96  };
97 
98  /// If non-empty, the directory to use as a "virtual system root" for include
99  /// paths.
101 
102  /// User specified include entries.
103  std::vector<Entry> UserEntries;
104 
105  /// User-specified system header prefixes.
106  std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
107 
108  /// The directory which holds the compiler resource files (builtin includes,
109  /// etc.).
111 
112  /// The directory used for the module cache.
114 
115  /// The directory used for a user build.
117 
118  /// The mapping of module names to prebuilt module files.
119  std::map<std::string, std::string, std::less<>> PrebuiltModuleFiles;
120 
121  /// The directories used to load prebuilt module files.
122  std::vector<std::string> PrebuiltModulePaths;
123 
124  /// The module/pch container format.
126 
127  /// Whether we should disable the use of the hash string within the
128  /// module cache.
129  ///
130  /// Note: Only used for testing!
131  unsigned DisableModuleHash : 1;
132 
133  /// Implicit module maps. This option is enabld by default when
134  /// modules is enabled.
135  unsigned ImplicitModuleMaps : 1;
136 
137  /// Set the 'home directory' of a module map file to the current
138  /// working directory (or the home directory of the module map file that
139  /// contained the 'extern module' directive importing this module map file
140  /// if any) rather than the directory containing the module map file.
141  //
142  /// The home directory is where we look for files named in the module map
143  /// file.
145 
146  /// Also search for prebuilt implicit modules in the prebuilt module cache
147  /// path.
149 
150  /// The interval (in seconds) between pruning operations.
151  ///
152  /// This operation is expensive, because it requires Clang to walk through
153  /// the directory structure of the module cache, stat()'ing and removing
154  /// files.
155  ///
156  /// The default value is large, e.g., the operation runs once a week.
157  unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60;
158 
159  /// The time (in seconds) after which an unused module file will be
160  /// considered unused and will, therefore, be pruned.
161  ///
162  /// When the module cache is pruned, any module file that has not been
163  /// accessed in this many seconds will be removed. The default value is
164  /// large, e.g., a month, to avoid forcing infrequently-used modules to be
165  /// regenerated often.
166  unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60;
167 
168  /// The time in seconds when the build session started.
169  ///
170  /// This time is used by other optimizations in header search and module
171  /// loading.
172  uint64_t BuildSessionTimestamp = 0;
173 
174  /// The set of macro names that should be ignored for the purposes
175  /// of computing the module hash.
177 
178  /// The set of user-provided virtual filesystem overlay files.
179  std::vector<std::string> VFSOverlayFiles;
180 
181  /// Include the compiler builtin includes.
182  unsigned UseBuiltinIncludes : 1;
183 
184  /// Include the system standard include search directories.
186 
187  /// Include the system standard C++ library include search directories.
189 
190  /// Use libc++ instead of the default libstdc++.
191  unsigned UseLibcxx : 1;
192 
193  /// Whether header search information should be output as for -v.
194  unsigned Verbose : 1;
195 
196  /// If true, skip verifying input files used by modules if the
197  /// module was already verified during this build session (see
198  /// \c BuildSessionTimestamp).
200 
201  /// Whether to validate system input files when a module is loaded.
203 
204  // Whether the content of input files should be hashed and used to
205  // validate consistency.
207 
208  /// Whether the module includes debug information (-gmodules).
209  unsigned UseDebugInfo : 1;
210 
212 
213  unsigned ModulesHashContent : 1;
214 
215  /// Whether we should include all things that could impact the module in the
216  /// hash.
217  ///
218  /// This includes things like the full header search path, and enabled
219  /// diagnostics.
221 
222  HeaderSearchOptions(StringRef _Sysroot = "/")
223  : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
233 
234  /// AddPath - Add the \p Path path to the specified \p Group list.
236  bool IsFramework, bool IgnoreSysRoot) {
237  UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
238  }
239 
240  /// AddSystemHeaderPrefix - Override whether \#include directives naming a
241  /// path starting with \p Prefix should be considered as naming a system
242  /// header.
243  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
244  SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
245  }
246 
247  void AddVFSOverlayFile(StringRef Name) {
248  VFSOverlayFiles.push_back(std::string(Name));
249  }
250 
251  void AddPrebuiltModulePath(StringRef Name) {
252  PrebuiltModulePaths.push_back(std::string(Name));
253  }
254 };
255 
256 inline llvm::hash_code hash_value(const HeaderSearchOptions::Entry &E) {
258 }
259 
260 template <typename HasherT, llvm::support::endianness Endianness>
261 inline void addHash(llvm::HashBuilderImpl<HasherT, Endianness> &HBuilder,
262  const HeaderSearchOptions::Entry &E) {
263  HBuilder.add(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
264 }
265 
266 inline llvm::hash_code
268  return llvm::hash_combine(SHP.Prefix, SHP.IsSystemHeader);
269 }
270 
271 template <typename HasherT, llvm::support::endianness Endianness>
272 inline void addHash(llvm::HashBuilderImpl<HasherT, Endianness> &HBuilder,
274  HBuilder.add(SHP.Prefix, SHP.IsSystemHeader);
275 }
276 
277 } // namespace clang
278 
279 #endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::HeaderSearchOptions::HeaderSearchOptions
HeaderSearchOptions(StringRef _Sysroot="/")
Definition: HeaderSearchOptions.h:222
clang::HeaderSearchOptions::BuildSessionTimestamp
uint64_t BuildSessionTimestamp
The time in seconds when the build session started.
Definition: HeaderSearchOptions.h:172
clang::HeaderSearchOptions::Entry::IgnoreSysRoot
unsigned IgnoreSysRoot
IgnoreSysRoot - This is false if an absolute path should be treated relative to the sysroot,...
Definition: HeaderSearchOptions.h:78
clang::HeaderSearchOptions::UseStandardSystemIncludes
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
Definition: HeaderSearchOptions.h:185
clang::HeaderSearchOptions::ModulesValidateSystemHeaders
unsigned ModulesValidateSystemHeaders
Whether to validate system input files when a module is loaded.
Definition: HeaderSearchOptions.h:202
clang::HeaderSearchOptions::Verbose
unsigned Verbose
Whether header search information should be output as for -v.
Definition: HeaderSearchOptions.h:194
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::frontend::CSystem
@ CSystem
Like System, but only used for C.
Definition: HeaderSearchOptions.h:49
clang::HeaderSearchOptions::ModulesValidateDiagnosticOptions
unsigned ModulesValidateDiagnosticOptions
Definition: HeaderSearchOptions.h:211
clang::frontend::IndexHeaderMap
@ IndexHeaderMap
Like Angled, but marks header maps used when building frameworks.
Definition: HeaderSearchOptions.h:40
clang::HeaderSearchOptions::UseDebugInfo
unsigned UseDebugInfo
Whether the module includes debug information (-gmodules).
Definition: HeaderSearchOptions.h:209
clang::frontend::ObjCSystem
@ ObjCSystem
Like System, but only used for ObjC.
Definition: HeaderSearchOptions.h:55
clang::frontend::ExternCSystem
@ ExternCSystem
Like System, but headers are implicitly wrapped in extern "C".
Definition: HeaderSearchOptions.h:46
clang::hash_value
llvm::hash_code hash_value(const clang::SanitizerMask &Arg)
Definition: Sanitizers.cpp:68
clang::HeaderSearchOptions::SystemHeaderPrefix::Prefix
std::string Prefix
A prefix to be matched against paths in #include directives.
Definition: HeaderSearchOptions.h:88
clang::frontend::System
@ System
Like Angled, but marks system directories.
Definition: HeaderSearchOptions.h:43
clang::HeaderSearchOptions::Entry::IsFramework
unsigned IsFramework
Definition: HeaderSearchOptions.h:73
clang::HeaderSearchOptions::ModuleCachePruneAfter
unsigned ModuleCachePruneAfter
The time (in seconds) after which an unused module file will be considered unused and will,...
Definition: HeaderSearchOptions.h:166
clang::HeaderSearchOptions::ModulesStrictContextHash
unsigned ModulesStrictContextHash
Whether we should include all things that could impact the module in the hash.
Definition: HeaderSearchOptions.h:220
clang::frontend::ObjCXXSystem
@ ObjCXXSystem
Like System, but only used for ObjC++.
Definition: HeaderSearchOptions.h:58
clang::HeaderSearchOptions::Entry::Path
std::string Path
Definition: HeaderSearchOptions.h:71
clang::HeaderSearchOptions::Sysroot
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
Definition: HeaderSearchOptions.h:100
clang::HeaderSearchOptions::ModuleMapFileHomeIsCwd
unsigned ModuleMapFileHomeIsCwd
Set the 'home directory' of a module map file to the current working directory (or the home directory...
Definition: HeaderSearchOptions.h:144
clang::HeaderSearchOptions::ValidateASTInputFilesContent
unsigned ValidateASTInputFilesContent
Definition: HeaderSearchOptions.h:206
clang::HeaderSearchOptions::Entry::Entry
Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, bool ignoreSysRoot)
Definition: HeaderSearchOptions.h:80
clang::HeaderSearchOptions::ModuleFormat
std::string ModuleFormat
The module/pch container format.
Definition: HeaderSearchOptions.h:125
clang::HeaderSearchOptions::SystemHeaderPrefix
Definition: HeaderSearchOptions.h:86
clang::frontend::Quoted
@ Quoted
'#include ""' paths, added by 'gcc -iquote'.
Definition: HeaderSearchOptions.h:34
clang::HeaderSearchOptions::UseLibcxx
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
Definition: HeaderSearchOptions.h:191
clang::HeaderSearchOptions::PrebuiltModulePaths
std::vector< std::string > PrebuiltModulePaths
The directories used to load prebuilt module files.
Definition: HeaderSearchOptions.h:122
clang::HeaderSearchOptions::UseStandardCXXIncludes
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
Definition: HeaderSearchOptions.h:188
clang::HeaderSearchOptions::PrebuiltModuleFiles
std::map< std::string, std::string, std::less<> > PrebuiltModuleFiles
The mapping of module names to prebuilt module files.
Definition: HeaderSearchOptions.h:119
clang::format::hash_combine
static void hash_combine(std::size_t &seed, const T &v)
Definition: UnwrappedLineParser.cpp:643
clang::HeaderSearchOptions::EnablePrebuiltImplicitModules
unsigned EnablePrebuiltImplicitModules
Also search for prebuilt implicit modules in the prebuilt module cache path.
Definition: HeaderSearchOptions.h:148
clang::frontend::Angled
@ Angled
Paths for '#include <>' added by '-I'.
Definition: HeaderSearchOptions.h:37
clang::HeaderSearchOptions::ImplicitModuleMaps
unsigned ImplicitModuleMaps
Implicit module maps.
Definition: HeaderSearchOptions.h:135
clang::HeaderSearchOptions::ModulesIgnoreMacros
llvm::SmallSetVector< llvm::CachedHashString, 16 > ModulesIgnoreMacros
The set of macro names that should be ignored for the purposes of computing the module hash.
Definition: HeaderSearchOptions.h:176
clang::HeaderSearchOptions::ModuleUserBuildPath
std::string ModuleUserBuildPath
The directory used for a user build.
Definition: HeaderSearchOptions.h:116
false
#define false
Definition: stdbool.h:17
clang::HeaderSearchOptions::AddPath
void AddPath(StringRef Path, frontend::IncludeDirGroup Group, bool IsFramework, bool IgnoreSysRoot)
AddPath - Add the Path path to the specified Group list.
Definition: HeaderSearchOptions.h:235
clang::frontend::IncludeDirGroup
IncludeDirGroup
IncludeDirGroup - Identifies the group an include Entry belongs to, representing its relative positiv...
Definition: HeaderSearchOptions.h:32
clang::HeaderSearchOptions::SystemHeaderPrefix::SystemHeaderPrefix
SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
Definition: HeaderSearchOptions.h:94
clang::addHash
void addHash(llvm::HashBuilderImpl< HasherT, Endianness > &HBuilder, const HeaderSearchOptions::Entry &E)
Definition: HeaderSearchOptions.h:261
clang::HeaderSearchOptions::AddSystemHeaderPrefix
void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
AddSystemHeaderPrefix - Override whether #include directives naming a path starting with Prefix shoul...
Definition: HeaderSearchOptions.h:243
clang::frontend::After
@ After
Like System, but searched after the system directories.
Definition: HeaderSearchOptions.h:61
LLVM.h
clang::frontend::CXXSystem
@ CXXSystem
Like System, but only used for C++.
Definition: HeaderSearchOptions.h:52
clang::HeaderSearchOptions::UserEntries
std::vector< Entry > UserEntries
User specified include entries.
Definition: HeaderSearchOptions.h:103
clang::HeaderSearchOptions::SystemHeaderPrefixes
std::vector< SystemHeaderPrefix > SystemHeaderPrefixes
User-specified system header prefixes.
Definition: HeaderSearchOptions.h:106
clang::HeaderSearchOptions::ModuleCachePath
std::string ModuleCachePath
The directory used for the module cache.
Definition: HeaderSearchOptions.h:113
clang::HeaderSearchOptions::VFSOverlayFiles
std::vector< std::string > VFSOverlayFiles
The set of user-provided virtual filesystem overlay files.
Definition: HeaderSearchOptions.h:179
clang
Definition: CalledOnceCheck.h:17
clang::HeaderSearchOptions::SystemHeaderPrefix::IsSystemHeader
bool IsSystemHeader
True if paths beginning with this prefix should be treated as system headers.
Definition: HeaderSearchOptions.h:92
clang::HeaderSearchOptions::ModulesHashContent
unsigned ModulesHashContent
Definition: HeaderSearchOptions.h:213
clang::HeaderSearchOptions::ResourceDir
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
Definition: HeaderSearchOptions.h:110
true
#define true
Definition: stdbool.h:16
llvm::SmallSetVector< llvm::CachedHashString, 16 >
clang::HeaderSearchOptions::AddPrebuiltModulePath
void AddPrebuiltModulePath(StringRef Name)
Definition: HeaderSearchOptions.h:251
clang::HeaderSearchOptions::DisableModuleHash
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
Definition: HeaderSearchOptions.h:131
clang::HeaderSearchOptions::Entry
Definition: HeaderSearchOptions.h:70
clang::HeaderSearchOptions::Entry::Group
frontend::IncludeDirGroup Group
Definition: HeaderSearchOptions.h:72
clang::HeaderSearchOptions::UseBuiltinIncludes
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
Definition: HeaderSearchOptions.h:182
clang::HeaderSearchOptions::AddVFSOverlayFile
void AddVFSOverlayFile(StringRef Name)
Definition: HeaderSearchOptions.h:247
clang::HeaderSearchOptions::ModulesValidateOncePerBuildSession
unsigned ModulesValidateOncePerBuildSession
If true, skip verifying input files used by modules if the module was already verified during this bu...
Definition: HeaderSearchOptions.h:199
clang::HeaderSearchOptions
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Definition: HeaderSearchOptions.h:68
clang::HeaderSearchOptions::ModuleCachePruneInterval
unsigned ModuleCachePruneInterval
The interval (in seconds) between pruning operations.
Definition: HeaderSearchOptions.h:157