clang 24.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/SetVector.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/HashBuilder.h"
17#include <cstdint>
18#include <map>
19#include <string>
20#include <vector>
21
22namespace clang {
23
24namespace frontend {
25
26/// IncludeDirGroup - Identifies the group an include Entry belongs to,
27/// representing its relative positive in the search list.
28/// \#include directives whose paths are enclosed by string quotes ("")
29/// start searching at the Quoted group (specified by '-iquote'),
30/// then search the Angled group, then the System group, etc.
32 /// '\#include ""' paths, added by 'gcc -iquote'.
33 Quoted = 0,
34
35 /// Paths for '\#include <>' added by '-I'.
37
38 /// Like Angled, but marks system directories.
40
41 /// Like System, but headers are implicitly wrapped in extern "C".
43
44 /// Like System, but only used for C.
46
47 /// Like System, but only used for C++.
49
50 /// Like System, but only used for ObjC.
52
53 /// Like System, but only used for ObjC++.
55
56 /// Like System, but searched after the system directories.
58};
59
60} // namespace frontend
61
62/// HeaderSearchOptions - Helper class for storing options related to the
63/// initialization of the HeaderSearch object.
65public:
66 struct Entry {
67 std::string Path;
69 LLVM_PREFERRED_TYPE(bool)
71
72 /// IgnoreSysRoot - This is false if an absolute path should be treated
73 /// relative to the sysroot, or true if it should always be the absolute
74 /// path.
75 LLVM_PREFERRED_TYPE(bool)
76 unsigned IgnoreSysRoot : 1;
77
78 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
79 bool ignoreSysRoot)
80 : Path(path), Group(group), IsFramework(isFramework),
81 IgnoreSysRoot(ignoreSysRoot) {}
82 };
83
85 /// A prefix to be matched against paths in \#include directives.
86 std::string Prefix;
87
88 /// True if paths beginning with this prefix should be treated as system
89 /// headers.
91
94 };
95
96 /// If non-empty, the directory to use as a "virtual system root" for include
97 /// paths.
98 std::string Sysroot;
99
100 /// User specified include entries.
101 std::vector<Entry> UserEntries;
102
103 /// User-specified system header prefixes.
104 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
105
106 /// The directory which holds the compiler resource files (builtin includes,
107 /// etc.).
108 std::string ResourceDir;
109
110 /// The directory used for the module cache.
111 std::string ModuleCachePath;
112
113 /// The directory used for a user build.
115
116 /// The mapping of module names to prebuilt module files.
117 std::map<std::string, std::string, std::less<>> PrebuiltModuleFiles;
118
119 /// The directories used to load prebuilt module files.
120 std::vector<std::string> PrebuiltModulePaths;
121
122 /// The module/pch container format.
123 std::string ModuleFormat;
124
125 /// Whether we should disable the use of the hash string within the
126 /// module cache.
127 ///
128 /// Note: Only used for testing!
129 LLVM_PREFERRED_TYPE(bool)
131
132 /// Implicit module maps. This option is enabld by default when
133 /// modules is enabled.
134 LLVM_PREFERRED_TYPE(bool)
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.
144 LLVM_PREFERRED_TYPE(bool)
146
147 /// Set the base path of a built module file to be the current working
148 /// directory. This is useful for sharing module files across machines
149 /// that build with different paths without having to rewrite all
150 /// modulemap files to have working directory relative paths.
151 LLVM_PREFERRED_TYPE(bool)
153
154 /// Serialize precompiled header input paths relative to the current working
155 /// directory. Relative paths resolve against the consumer's working
156 /// directory; unlike relocatable PCHs, no base directory is stored or
157 /// re-rooted at load.
158 LLVM_PREFERRED_TYPE(bool)
159 unsigned PCHBaseDirIsCwd : 1;
160
161 /// Also search for prebuilt implicit modules in the prebuilt module cache
162 /// path.
163 LLVM_PREFERRED_TYPE(bool)
165
166 /// The interval (in seconds) between pruning operations.
167 ///
168 /// This operation is expensive, because it requires Clang to walk through
169 /// the directory structure of the module cache, stat()'ing and removing
170 /// files.
171 ///
172 /// The default value is large, e.g., the operation runs once a week.
173 unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60;
174
175 /// The time (in seconds) after which an unused module file will be
176 /// considered unused and will, therefore, be pruned.
177 ///
178 /// When the module cache is pruned, any module file that has not been
179 /// accessed in this many seconds will be removed. The default value is
180 /// large, e.g., a month, to avoid forcing infrequently-used modules to be
181 /// regenerated often.
182 unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60;
183
184 /// The time in seconds when the build session started.
185 ///
186 /// This time is used by other optimizations in header search and module
187 /// loading.
189
190 /// The set of macro names that should be ignored by implicitly-built modules.
192
193 /// The set of header search paths that should be ignored by implicitly-built
194 /// modules.
196
197 /// The set of user-provided virtual filesystem overlay files.
198 std::vector<std::string> VFSOverlayFiles;
199
200 /// Include the compiler builtin includes.
201 LLVM_PREFERRED_TYPE(bool)
202 unsigned UseBuiltinIncludes : 1;
203
204 /// Include the system standard include search directories.
205 LLVM_PREFERRED_TYPE(bool)
207
208 /// Include the system standard C++ library include search directories.
209 LLVM_PREFERRED_TYPE(bool)
211
212 /// Use libc++ instead of the default libstdc++.
213 LLVM_PREFERRED_TYPE(bool)
214 unsigned UseLibcxx : 1;
215
216 /// Whether header search information should be output as for -v.
217 LLVM_PREFERRED_TYPE(bool)
218 unsigned Verbose : 1;
219
220 /// If true, skip verifying input files used by modules if the
221 /// module was already verified during this build session (see
222 /// \c BuildSessionTimestamp).
223 LLVM_PREFERRED_TYPE(bool)
225
226 /// Whether to validate system input files when a module is loaded.
227 LLVM_PREFERRED_TYPE(bool)
229
230 /// Whether to force the validation of user input files when a module is
231 /// loaded (even despite the build session saying that is not necessary).
232 LLVM_PREFERRED_TYPE(bool)
234
235 /// Whether to treat an implicitly built module as out of date when a
236 /// directory it depends on the listing of changed after it was built.
237 LLVM_PREFERRED_TYPE(bool)
239
240 // Whether the content of input files should be hashed and used to
241 // validate consistency.
242 LLVM_PREFERRED_TYPE(bool)
244
245 // Whether the input files from C++20 Modules should be checked.
246 LLVM_PREFERRED_TYPE(bool)
248
249 /// Whether the module includes debug information (-gmodules).
250 LLVM_PREFERRED_TYPE(bool)
251 unsigned UseDebugInfo : 1;
252
253 LLVM_PREFERRED_TYPE(bool)
255
256 /// Whether to entirely skip writing diagnostic options.
257 /// Primarily used to speed up deserialization during dependency scanning.
258 /// FIXME: Consider moving these into separate `SerializationOptions` class.
259 LLVM_PREFERRED_TYPE(bool)
261
262 /// Whether to entirely skip writing header search paths.
263 /// Primarily used to speed up deserialization during dependency scanning.
264 LLVM_PREFERRED_TYPE(bool)
266
267 /// Whether to entirely skip writing pragma diagnostic mappings.
268 /// Primarily used to speed up deserialization during dependency scanning.
269 LLVM_PREFERRED_TYPE(bool)
271
272 /// Whether to prune non-affecting module map files from PCM files.
273 LLVM_PREFERRED_TYPE(bool)
275
276 LLVM_PREFERRED_TYPE(bool)
277 unsigned ModulesHashContent : 1;
278
279 /// Whether AST files should only contain the preprocessor information.
280 LLVM_PREFERRED_TYPE(bool)
282
283 /// Whether we should include all things that could impact the module in the
284 /// hash.
285 ///
286 /// This includes things like the full header search path, and enabled
287 /// diagnostics.
288 LLVM_PREFERRED_TYPE(bool)
290
291 /// Whether to include ivfsoverlay usage information in written AST files.
292 LLVM_PREFERRED_TYPE(bool)
294
295 /// Whether we should look for a module in module maps only in provided
296 /// header search paths or if we are allowed to look for module maps in
297 /// subdirectories of provided paths too.
298 LLVM_PREFERRED_TYPE(bool)
300
301 /// Whether modules from module maps should only be loaded when used, not just
302 /// when parsed.
303 LLVM_PREFERRED_TYPE(bool)
304 unsigned LazyLoadModuleMaps : 1;
305
327
328 /// AddPath - Add the \p Path path to the specified \p Group list.
329 void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
330 bool IsFramework, bool IgnoreSysRoot) {
331 UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
332 }
333
334 /// AddSystemHeaderPrefix - Override whether \#include directives naming a
335 /// path starting with \p Prefix should be considered as naming a system
336 /// header.
337 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
338 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
339 }
340
341 void AddVFSOverlayFile(StringRef Name) {
342 VFSOverlayFiles.push_back(std::string(Name));
343 }
344
345 void AddPrebuiltModulePath(StringRef Name) {
346 PrebuiltModulePaths.push_back(std::string(Name));
347 }
348};
349
350template <typename HasherT, llvm::endianness Endianness>
351inline void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
353 HBuilder.add(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
354}
355
356template <typename HasherT, llvm::endianness Endianness>
357inline void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
359 HBuilder.add(SHP.Prefix, SHP.IsSystemHeader);
360}
361
362} // namespace clang
363
364#endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
unsigned ModulesPruneNonAffectingModuleMaps
Whether to prune non-affecting module map files from PCM files.
unsigned ModulesStrictContextHash
Whether we should include all things that could impact the module in the hash.
unsigned Verbose
Whether header search information should be output as for -v.
unsigned ModulesForceValidateUserHeaders
Whether to force the validation of user input files when a module is loaded (even despite the build s...
void AddPath(StringRef Path, frontend::IncludeDirGroup Group, bool IsFramework, bool IgnoreSysRoot)
AddPath - Add the Path path to the specified Group list.
unsigned ModuleCachePruneInterval
The interval (in seconds) between pruning operations.
unsigned LazyLoadModuleMaps
Whether modules from module maps should only be loaded when used, not just when parsed.
std::map< std::string, std::string, std::less<> > PrebuiltModuleFiles
The mapping of module names to prebuilt module files.
uint64_t BuildSessionTimestamp
The time in seconds when the build session started.
std::vector< std::string > PrebuiltModulePaths
The directories used to load prebuilt module files.
unsigned ModulesSkipHeaderSearchPaths
Whether to entirely skip writing header search paths.
unsigned ImplicitModuleMaps
Implicit module maps.
void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
AddSystemHeaderPrefix - Override whether #include directives naming a path starting with Prefix shoul...
unsigned ModulesValidateSystemHeaders
Whether to validate system input files when a module is loaded.
std::vector< SystemHeaderPrefix > SystemHeaderPrefixes
User-specified system header prefixes.
HeaderSearchOptions(StringRef _Sysroot="/")
std::string ModuleFormat
The module/pch container format.
unsigned EnablePrebuiltImplicitModules
Also search for prebuilt implicit modules in the prebuilt module cache path.
unsigned ModuleMapFileHomeIsCwd
Set the 'home directory' of a module map file to the current working directory (or the home directory...
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
unsigned ModulesSkipDiagnosticOptions
Whether to entirely skip writing diagnostic options.
llvm::SmallSetVector< llvm::CachedHashString, 16 > ModulesIgnoreMacros
The set of macro names that should be ignored by implicitly-built modules.
std::string ModuleCachePath
The directory used for the module cache.
std::string ModuleUserBuildPath
The directory used for a user build.
std::vector< std::string > VFSOverlayFiles
The set of user-provided virtual filesystem overlay files.
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
unsigned ModuleFileHomeIsCwd
Set the base path of a built module file to be the current working directory.
unsigned ModulesSerializeOnlyPreprocessor
Whether AST files should only contain the preprocessor information.
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
unsigned PCHBaseDirIsCwd
Serialize precompiled header input paths relative to the current working directory.
unsigned ModulesSkipPragmaDiagnosticMappings
Whether to entirely skip writing pragma diagnostic mappings.
unsigned UseDebugInfo
Whether the module includes debug information (-gmodules).
unsigned ModulesIncludeVFSUsage
Whether to include ivfsoverlay usage information in written AST files.
std::vector< Entry > UserEntries
User specified include entries.
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
void AddPrebuiltModulePath(StringRef Name)
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
void AddVFSOverlayFile(StringRef Name)
llvm::SmallSetVector< llvm::CachedHashString, 16 > ModulesIgnoreSearchPaths
The set of header search paths that should be ignored by implicitly-built modules.
unsigned ModulesValidateOncePerBuildSession
If true, skip verifying input files used by modules if the module was already verified during this bu...
unsigned AllowModuleMapSubdirectorySearch
Whether we should look for a module in module maps only in provided header search paths or if we are ...
unsigned ModulesValidateDirectoryDependencies
Whether to treat an implicitly built module as out of date when a directory it depends on the listing...
unsigned ModuleCachePruneAfter
The time (in seconds) after which an unused module file will be considered unused and will,...
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
IncludeDirGroup
IncludeDirGroup - Identifies the group an include Entry belongs to, representing its relative positiv...
@ CXXSystem
Like System, but only used for C++.
@ Angled
Paths for '#include <>' added by '-I'.
@ CSystem
Like System, but only used for C.
@ System
Like Angled, but marks system directories.
@ Quoted
'#include ""' paths, added by 'gcc -iquote'.
@ ExternCSystem
Like System, but headers are implicitly wrapped in extern "C".
@ ObjCSystem
Like System, but only used for ObjC.
@ ObjCXXSystem
Like System, but only used for ObjC++.
@ After
Like System, but searched after the system directories.
Top level wrappers for InstallAPI frontend operations.
void addHash(llvm::HashBuilder< HasherT, Endianness > &HBuilder, const HeaderSearchOptions::Entry &E)
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 unsigned
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, bool ignoreSysRoot)
unsigned IgnoreSysRoot
IgnoreSysRoot - This is false if an absolute path should be treated relative to the sysroot,...
std::string Prefix
A prefix to be matched against paths in #include directives.
bool IsSystemHeader
True if paths beginning with this prefix should be treated as system headers.
SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)