clang 24.0.0git
PreprocessorOptions.h
Go to the documentation of this file.
1//===- PreprocessorOptions.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_PREPROCESSOROPTIONS_H_
10#define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
11
14#include "clang/Basic/LLVM.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/StringSet.h"
18#include <functional>
19#include <map>
20#include <memory>
21#include <optional>
22#include <set>
23#include <string>
24#include <utility>
25#include <vector>
26
27namespace llvm {
28
29class MemoryBuffer;
30
31} // namespace llvm
32
33namespace clang {
34
35/// Enumerate the kinds of standard library that
38
39 /// libc++
41
42 /// libstdc++
44};
45
46/// How to initialize the date/time macros.
48 /// Set to the current date and time.
50
51 /// Set to literal string "1".
53
54 /// Keep undefined.
56};
57
58/// Whether to disable the normal validation performed on precompiled
59/// headers and module files when they are loaded.
61 /// Perform validation, don't disable it.
62 None = 0,
63
64 /// Disable validation for a precompiled header and the modules it depends on.
65 PCH = 0x1,
66
67 /// Disable validation for module files.
68 Module = 0x2,
69
70 /// Disable validation for all kinds.
72
74};
75
76/// PreprocessorOptions - This class is used for passing the various options
77/// used in preprocessor initialization to InitializePreprocessor().
79public:
80 std::vector<std::pair<std::string, bool/*isUndef*/>> Macros;
81 std::vector<std::string> Includes;
82 std::vector<std::string> MacroIncludes;
83
84 /// Perform extra checks when loading PCM files for mutable file systems.
86
87 /// Perform redundant module lookups. This is typically for
88 /// compilations that rely on side effects of module lookup due to
89 /// poor modularization.
91
92 /// Initialize the preprocessor with the compiler and target specific
93 /// predefines.
94 bool UsePredefines = true;
95
96 /// Indicates whether to predefine target OS macros.
98
99 /// Whether we should maintain a detailed record of all macro
100 /// definitions and expansions.
101 bool DetailedRecord = false;
102
103 /// When true, we are creating or using a PCH where a #pragma hdrstop is
104 /// expected to indicate the beginning or end of the PCH.
105 bool PCHWithHdrStop = false;
106
107 /// When true, we are creating a PCH or creating the PCH object while
108 /// expecting a #pragma hdrstop to separate the two. Allow for a
109 /// missing #pragma hdrstop, which generates a PCH for the whole file,
110 /// and creates an empty PCH object.
112
113 /// If non-empty, the filename used in an #include directive in the primary
114 /// source file (or command-line preinclude) that is used to implement
115 /// MSVC-style precompiled headers. When creating a PCH, after the #include
116 /// of this header, the PCH generation stops. When using a PCH, tokens are
117 /// skipped until after an #include of this header is seen.
118 std::string PCHThroughHeader;
119
120 /// The implicit PCH included at the start of the translation unit, or empty.
122
123 /// Headers that will be converted to chained PCHs in memory.
124 std::vector<std::string> ChainedIncludes;
125
126 /// Whether to disable most of the normal validation performed on
127 /// precompiled headers and module files.
130
131 /// When true, a PCH with compiler errors will not be rejected.
133
134 /// When true, a PCH with modules cache path different to the current
135 /// compilation will not be rejected.
137
138 /// Dump declarations that are deserialized from PCH, for testing.
140
141 /// This is a set of names for decls that we do not want to be
142 /// deserialized, and we emit an error if they are; for testing purposes.
143 std::set<std::string> DeserializedPCHDeclsToErrorOn;
144
145 /// If non-zero, the implicit PCH include is actually a precompiled
146 /// preamble that covers this number of bytes in the main source file.
147 ///
148 /// The boolean indicates whether the preamble ends at the start of a new
149 /// line.
150 std::pair<unsigned, bool> PrecompiledPreambleBytes;
151
152 /// True indicates that a preamble is being generated.
153 ///
154 /// When the lexer is done, one of the things that need to be preserved is the
155 /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when
156 /// processing the rest of the file. Similarly, we track an unterminated
157 /// #pragma assume_nonnull.
158 bool GeneratePreamble = false;
159
160 /// Whether to write comment locations into the PCH when building it.
161 /// Reading the comments from the PCH can be a performance hit even if the
162 /// clients don't use them.
164
165 /// When enabled, preprocessor is in a mode for parsing a single file only.
166 ///
167 /// Disables #includes of other files and if there are unresolved identifiers
168 /// in preprocessor directive conditions it causes all blocks to be parsed so
169 /// that the client can get the maximum amount of information from the parser.
171
172 /// When enabled, preprocessor is in a mode for parsing a single module only.
173 ///
174 /// Disables imports of other modules and if there are any unresolved
175 /// identifiers in preprocessor directive conditions it causes all blocks to
176 /// be skipped so that the client can get a strict subset of the contents.
178
179 /// When enabled, the preprocessor will construct editor placeholder tokens.
181
182 /// True if the SourceManager should report the original file name for
183 /// contents of files that were remapped to other files. Defaults to true.
185
186 /// The set of file remappings, which take existing files on
187 /// the system (the first part of each pair) and gives them the
188 /// contents of other files on the system (the second part of each
189 /// pair).
190 std::vector<std::pair<std::string, std::string>> RemappedFiles;
191
192 /// The set of file-to-buffer remappings, which take existing files
193 /// on the system (the first part of each pair) and gives them the contents
194 /// of the specified memory buffer (the second part of each pair).
195 std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers;
196
197 /// User specified embed entries.
198 std::vector<std::string> EmbedEntries;
199
200 /// Whether the compiler instance should retain (i.e., not free)
201 /// the buffers associated with remapped files.
202 ///
203 /// This flag defaults to false; it can be set true only through direct
204 /// manipulation of the compiler invocation object, in cases where the
205 /// compiler invocation and its buffers will be reused.
207
208 /// When enabled, excluded conditional blocks retain in the main file.
210
211 /// The Objective-C++ ARC standard library that we should support,
212 /// by providing appropriate definitions to retrofit the standard library
213 /// with support for lifetime-qualified pointers.
215
216 /// Set up preprocessor for RunAnalysis action.
218
219 /// Prevents intended crashes when using #pragma clang __debug. For testing.
221
222 /// If set, the UNIX timestamp specified by SOURCE_DATE_EPOCH.
223 std::optional<uint64_t> SourceDateEpoch;
224
225 /// The initial value for __COUNTER__; typically is zero but can be set via a
226 /// -cc1 flag for testing purposes.
228
229 /// Specify initialization kind for __DATE__, __TIME__ and __TIMESTAMP__
230 /// macros.
232
233public:
235
236 void addMacroDef(StringRef Name) {
237 Macros.emplace_back(std::string(Name), false);
238 }
239 void addMacroUndef(StringRef Name) {
240 Macros.emplace_back(std::string(Name), true);
241 }
242
243 void addRemappedFile(StringRef From, StringRef To) {
244 RemappedFiles.emplace_back(std::string(From), std::string(To));
245 }
246
247 void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) {
248 RemappedFileBuffers.emplace_back(std::string(From), To);
249 }
250
252 RemappedFiles.clear();
253 RemappedFileBuffers.clear();
254 }
255
256 /// Reset any options that are not considered when building a
257 /// module.
259 Includes.clear();
260 MacroIncludes.clear();
261 ChainedIncludes.clear();
263 ImplicitPCHInclude.clear();
264 SingleFileParseMode = false;
267 PrecompiledPreambleBytes.first = 0;
268 PrecompiledPreambleBytes.second = false;
270 }
271};
272
273} // namespace clang
274
275#endif // LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
Provides LLVM's BitmaskEnum facility to enumeration types declared in namespace clang.
This is the interface for scanning header and source files to get the minimum necessary preprocessor ...
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Describes a module or submodule.
Definition Module.h:340
std::vector< std::pair< std::string, std::string > > RemappedFiles
The set of file remappings, which take existing files on the system (the first part of each pair) and...
bool PCHWithHdrStopCreate
When true, we are creating a PCH or creating the PCH object while expecting a pragma hdrstop to separ...
bool DisablePragmaDebugCrash
Prevents intended crashes when using pragma clang __debug. For testing.
std::vector< std::string > MacroIncludes
std::vector< std::string > Includes
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
bool WriteCommentListToPCH
Whether to write comment locations into the PCH when building it.
bool RemappedFilesKeepOriginalName
True if the SourceManager should report the original file name for contents of files that were remapp...
bool LexEditorPlaceholders
When enabled, the preprocessor will construct editor placeholder tokens.
uint32_t InitialCounterValue
The initial value for COUNTER; typically is zero but can be set via a -cc1 flag for testing purposes.
DateTimeInitKind InitDateTimeMacros
Specify initialization kind for DATE, TIME and TIMESTAMP macros.
void resetNonModularOptions()
Reset any options that are not considered when building a module.
bool RetainRemappedFileBuffers
Whether the compiler instance should retain (i.e., not free) the buffers associated with remapped fil...
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
bool ModulesForceRedundantLookup
Perform redundant module lookups.
bool ModulesCheckRelocated
Perform extra checks when loading PCM files for mutable file systems.
void addMacroUndef(StringRef Name)
std::string PCHThroughHeader
If non-empty, the filename used in an include directive in the primary source file (or command-line p...
std::set< std::string > DeserializedPCHDeclsToErrorOn
This is a set of names for decls that we do not want to be deserialized, and we emit an error if they...
std::vector< std::string > EmbedEntries
User specified embed entries.
bool SingleFileParseMode
When enabled, preprocessor is in a mode for parsing a single file only.
void addMacroDef(StringRef Name)
bool DefineTargetOSMacros
Indicates whether to predefine target OS macros.
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
void addRemappedFile(StringRef From, llvm::MemoryBuffer *To)
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
bool RetainExcludedConditionalBlocks
When enabled, excluded conditional blocks retain in the main file.
bool PCHWithHdrStop
When true, we are creating or using a PCH where a pragma hdrstop is expected to indicate the beginnin...
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
DisableValidationForModuleKind DisablePCHOrModuleValidation
Whether to disable most of the normal validation performed on precompiled headers and module files.
bool AllowPCHWithDifferentModulesCachePath
When true, a PCH with modules cache path different to the current compilation will not be rejected.
bool SingleModuleParseMode
When enabled, preprocessor is in a mode for parsing a single module only.
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
std::optional< uint64_t > SourceDateEpoch
If set, the UNIX timestamp specified by SOURCE_DATE_EPOCH.
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
void addRemappedFile(StringRef From, StringRef To)
bool SetUpStaticAnalyzer
Set up preprocessor for RunAnalysis action.
std::vector< std::pair< std::string, bool > > Macros
bool GeneratePreamble
True indicates that a preamble is being generated.
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
std::vector< std::pair< std::string, llvm::MemoryBuffer * > > RemappedFileBuffers
The set of file-to-buffer remappings, which take existing files on the system (the first part of each...
Top level wrappers for InstallAPI frontend operations.
ObjCXXARCStandardLibraryKind
Enumerate the kinds of standard library that.
@ ARCXX_libcxx
libc++
@ ARCXX_libstdcxx
libstdc++
DateTimeInitKind
How to initialize the date/time macros.
@ Default
Set to the current date and time.
@ Undefined
Keep undefined.
@ LiteralOne
Set to literal string "1".
DisableValidationForModuleKind
Whether to disable the normal validation performed on precompiled headers and module files when they ...
@ None
Perform validation, don't disable it.
@ PCH
Disable validation for a precompiled header and the modules it depends on.
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
#define false
Definition stdbool.h:26