clang 19.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
23namespace clang {
24
25namespace 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.
61 After
62};
63
64} // namespace frontend
65
66/// HeaderSearchOptions - Helper class for storing options related to the
67/// initialization of the HeaderSearch object.
69public:
70 struct Entry {
71 std::string Path;
73 LLVM_PREFERRED_TYPE(bool)
75
76 /// IgnoreSysRoot - This is false if an absolute path should be treated
77 /// relative to the sysroot, or true if it should always be the absolute
78 /// path.
79 LLVM_PREFERRED_TYPE(bool)
80 unsigned IgnoreSysRoot : 1;
81
82 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
83 bool ignoreSysRoot)
84 : Path(path), Group(group), IsFramework(isFramework),
85 IgnoreSysRoot(ignoreSysRoot) {}
86 };
87
89 /// A prefix to be matched against paths in \#include directives.
90 std::string Prefix;
91
92 /// True if paths beginning with this prefix should be treated as system
93 /// headers.
95
98 };
99
100 /// If non-empty, the directory to use as a "virtual system root" for include
101 /// paths.
102 std::string Sysroot;
103
104 /// User specified include entries.
105 std::vector<Entry> UserEntries;
106
107 /// User-specified system header prefixes.
108 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
109
110 /// The directory which holds the compiler resource files (builtin includes,
111 /// etc.).
112 std::string ResourceDir;
113
114 /// The directory used for the module cache.
115 std::string ModuleCachePath;
116
117 /// The directory used for a user build.
119
120 /// The mapping of module names to prebuilt module files.
121 std::map<std::string, std::string, std::less<>> PrebuiltModuleFiles;
122
123 /// The directories used to load prebuilt module files.
124 std::vector<std::string> PrebuiltModulePaths;
125
126 /// The module/pch container format.
127 std::string ModuleFormat;
128
129 /// Whether we should disable the use of the hash string within the
130 /// module cache.
131 ///
132 /// Note: Only used for testing!
133 LLVM_PREFERRED_TYPE(bool)
135
136 /// Implicit module maps. This option is enabld by default when
137 /// modules is enabled.
138 LLVM_PREFERRED_TYPE(bool)
139 unsigned ImplicitModuleMaps : 1;
140
141 /// Set the 'home directory' of a module map file to the current
142 /// working directory (or the home directory of the module map file that
143 /// contained the 'extern module' directive importing this module map file
144 /// if any) rather than the directory containing the module map file.
145 //
146 /// The home directory is where we look for files named in the module map
147 /// file.
148 LLVM_PREFERRED_TYPE(bool)
150
151 /// Set the base path of a built module file to be the current working
152 /// directory. This is useful for sharing module files across machines
153 /// that build with different paths without having to rewrite all
154 /// modulemap files to have working directory relative paths.
155 LLVM_PREFERRED_TYPE(bool)
157
158 /// Also search for prebuilt implicit modules in the prebuilt module cache
159 /// path.
160 LLVM_PREFERRED_TYPE(bool)
162
163 /// The interval (in seconds) between pruning operations.
164 ///
165 /// This operation is expensive, because it requires Clang to walk through
166 /// the directory structure of the module cache, stat()'ing and removing
167 /// files.
168 ///
169 /// The default value is large, e.g., the operation runs once a week.
170 unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60;
171
172 /// The time (in seconds) after which an unused module file will be
173 /// considered unused and will, therefore, be pruned.
174 ///
175 /// When the module cache is pruned, any module file that has not been
176 /// accessed in this many seconds will be removed. The default value is
177 /// large, e.g., a month, to avoid forcing infrequently-used modules to be
178 /// regenerated often.
179 unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60;
180
181 /// The time in seconds when the build session started.
182 ///
183 /// This time is used by other optimizations in header search and module
184 /// loading.
186
187 /// The set of macro names that should be ignored for the purposes
188 /// of computing the module hash.
190
191 /// The set of user-provided virtual filesystem overlay files.
192 std::vector<std::string> VFSOverlayFiles;
193
194 /// Include the compiler builtin includes.
195 LLVM_PREFERRED_TYPE(bool)
196 unsigned UseBuiltinIncludes : 1;
197
198 /// Include the system standard include search directories.
199 LLVM_PREFERRED_TYPE(bool)
201
202 /// Include the system standard C++ library include search directories.
203 LLVM_PREFERRED_TYPE(bool)
205
206 /// Use libc++ instead of the default libstdc++.
207 LLVM_PREFERRED_TYPE(bool)
208 unsigned UseLibcxx : 1;
209
210 /// Whether header search information should be output as for -v.
211 LLVM_PREFERRED_TYPE(bool)
212 unsigned Verbose : 1;
213
214 /// If true, skip verifying input files used by modules if the
215 /// module was already verified during this build session (see
216 /// \c BuildSessionTimestamp).
217 LLVM_PREFERRED_TYPE(bool)
219
220 /// Whether to validate system input files when a module is loaded.
221 LLVM_PREFERRED_TYPE(bool)
223
224 // Whether the content of input files should be hashed and used to
225 // validate consistency.
226 LLVM_PREFERRED_TYPE(bool)
228
229 // Whether the input files from C++20 Modules should be checked.
230 LLVM_PREFERRED_TYPE(bool)
232
233 /// Whether the module includes debug information (-gmodules).
234 LLVM_PREFERRED_TYPE(bool)
235 unsigned UseDebugInfo : 1;
236
237 LLVM_PREFERRED_TYPE(bool)
239
240 /// Whether to entirely skip writing diagnostic options.
241 /// Primarily used to speed up deserialization during dependency scanning.
242 LLVM_PREFERRED_TYPE(bool)
244
245 /// Whether to entirely skip writing header search paths.
246 /// Primarily used to speed up deserialization during dependency scanning.
247 LLVM_PREFERRED_TYPE(bool)
249
250 /// Whether to entirely skip writing pragma diagnostic mappings.
251 /// Primarily used to speed up deserialization during dependency scanning.
252 LLVM_PREFERRED_TYPE(bool)
254
255 /// Whether to prune non-affecting module map files from PCM files.
256 LLVM_PREFERRED_TYPE(bool)
258
259 LLVM_PREFERRED_TYPE(bool)
260 unsigned ModulesHashContent : 1;
261
262 /// Whether we should include all things that could impact the module in the
263 /// hash.
264 ///
265 /// This includes things like the full header search path, and enabled
266 /// diagnostics.
267 LLVM_PREFERRED_TYPE(bool)
269
270 /// Whether to include ivfsoverlay usage information in written AST files.
271 LLVM_PREFERRED_TYPE(bool)
273
274 HeaderSearchOptions(StringRef _Sysroot = "/")
275 : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
290
291 /// AddPath - Add the \p Path path to the specified \p Group list.
292 void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
293 bool IsFramework, bool IgnoreSysRoot) {
294 UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
295 }
296
297 /// AddSystemHeaderPrefix - Override whether \#include directives naming a
298 /// path starting with \p Prefix should be considered as naming a system
299 /// header.
300 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
301 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
302 }
303
304 void AddVFSOverlayFile(StringRef Name) {
305 VFSOverlayFiles.push_back(std::string(Name));
306 }
307
308 void AddPrebuiltModulePath(StringRef Name) {
309 PrebuiltModulePaths.push_back(std::string(Name));
310 }
311};
312
313inline llvm::hash_code hash_value(const HeaderSearchOptions::Entry &E) {
314 return llvm::hash_combine(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
315}
316
317template <typename HasherT, llvm::endianness Endianness>
318inline void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
320 HBuilder.add(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
321}
322
323inline llvm::hash_code
325 return llvm::hash_combine(SHP.Prefix, SHP.IsSystemHeader);
326}
327
328template <typename HasherT, llvm::endianness Endianness>
329inline void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
331 HBuilder.add(SHP.Prefix, SHP.IsSystemHeader);
332}
333
334} // namespace clang
335
336#endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
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.
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.
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.
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 for the purposes of computing the module hash.
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 UseStandardCXXIncludes
Include the system standard C++ library include search directories.
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)
unsigned ModulesValidateOncePerBuildSession
If true, skip verifying input files used by modules if the module was already verified during this bu...
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.
@ IndexHeaderMap
Like Angled, but marks header maps used when building frameworks.
@ ObjCXXSystem
Like System, but only used for ObjC++.
@ After
Like System, but searched after the system directories.
The JSON file list parser is used to communicate input to InstallAPI.
void addHash(llvm::HashBuilder< HasherT, Endianness > &HBuilder, const HeaderSearchOptions::Entry &E)
llvm::hash_code hash_value(const CustomizableOptional< T > &O)
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Definition: Format.h:5427
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
frontend::IncludeDirGroup Group
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)