clang  14.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 
13 #include "clang/Basic/LLVM.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/StringSet.h"
17 #include <functional>
18 #include <map>
19 #include <memory>
20 #include <set>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 namespace llvm {
26 
27 class MemoryBuffer;
28 
29 } // namespace llvm
30 
31 namespace clang {
32 
33 /// Enumerate the kinds of standard library that
36 
37  /// libc++
39 
40  /// libstdc++
42 };
43 
44 /// Whether to disable the normal validation performed on precompiled
45 /// headers and module files when they are loaded.
47  /// Perform validation, don't disable it.
48  None = 0,
49 
50  /// Disable validation for a precompiled header and the modules it depends on.
51  PCH = 0x1,
52 
53  /// Disable validation for module files.
54  Module = 0x2,
55 
56  /// Disable validation for all kinds.
57  All = PCH | Module,
58 
59  LLVM_MARK_AS_BITMASK_ENUM(Module)
60 };
61 
62 /// PreprocessorOptions - This class is used for passing the various options
63 /// used in preprocessor initialization to InitializePreprocessor().
65 public:
66  std::vector<std::pair<std::string, bool/*isUndef*/>> Macros;
67  std::vector<std::string> Includes;
68  std::vector<std::string> MacroIncludes;
69 
70  /// Initialize the preprocessor with the compiler and target specific
71  /// predefines.
72  bool UsePredefines = true;
73 
74  /// Whether we should maintain a detailed record of all macro
75  /// definitions and expansions.
76  bool DetailedRecord = false;
77 
78  /// When true, we are creating or using a PCH where a #pragma hdrstop is
79  /// expected to indicate the beginning or end of the PCH.
80  bool PCHWithHdrStop = false;
81 
82  /// When true, we are creating a PCH or creating the PCH object while
83  /// expecting a #pragma hdrstop to separate the two. Allow for a
84  /// missing #pragma hdrstop, which generates a PCH for the whole file,
85  /// and creates an empty PCH object.
86  bool PCHWithHdrStopCreate = false;
87 
88  /// If non-empty, the filename used in an #include directive in the primary
89  /// source file (or command-line preinclude) that is used to implement
90  /// MSVC-style precompiled headers. When creating a PCH, after the #include
91  /// of this header, the PCH generation stops. When using a PCH, tokens are
92  /// skipped until after an #include of this header is seen.
94 
95  /// The implicit PCH included at the start of the translation unit, or empty.
97 
98  /// Headers that will be converted to chained PCHs in memory.
99  std::vector<std::string> ChainedIncludes;
100 
101  /// Whether to disable most of the normal validation performed on
102  /// precompiled headers and module files.
105 
106  /// When true, a PCH with compiler errors will not be rejected.
108 
109  /// When true, a PCH with modules cache path different to the current
110  /// compilation will not be rejected.
112 
113  /// Dump declarations that are deserialized from PCH, for testing.
115 
116  /// This is a set of names for decls that we do not want to be
117  /// deserialized, and we emit an error if they are; for testing purposes.
118  std::set<std::string> DeserializedPCHDeclsToErrorOn;
119 
120  /// If non-zero, the implicit PCH include is actually a precompiled
121  /// preamble that covers this number of bytes in the main source file.
122  ///
123  /// The boolean indicates whether the preamble ends at the start of a new
124  /// line.
125  std::pair<unsigned, bool> PrecompiledPreambleBytes;
126 
127  /// True indicates that a preamble is being generated.
128  ///
129  /// When the lexer is done, one of the things that need to be preserved is the
130  /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when
131  /// processing the rest of the file.
132  bool GeneratePreamble = false;
133 
134  /// Whether to write comment locations into the PCH when building it.
135  /// Reading the comments from the PCH can be a performance hit even if the
136  /// clients don't use them.
138 
139  /// When enabled, preprocessor is in a mode for parsing a single file only.
140  ///
141  /// Disables #includes of other files and if there are unresolved identifiers
142  /// in preprocessor directive conditions it causes all blocks to be parsed so
143  /// that the client can get the maximum amount of information from the parser.
144  bool SingleFileParseMode = false;
145 
146  /// When enabled, the preprocessor will construct editor placeholder tokens.
148 
149  /// True if the SourceManager should report the original file name for
150  /// contents of files that were remapped to other files. Defaults to true.
152 
153  /// The set of file remappings, which take existing files on
154  /// the system (the first part of each pair) and gives them the
155  /// contents of other files on the system (the second part of each
156  /// pair).
157  std::vector<std::pair<std::string, std::string>> RemappedFiles;
158 
159  /// The set of file-to-buffer remappings, which take existing files
160  /// on the system (the first part of each pair) and gives them the contents
161  /// of the specified memory buffer (the second part of each pair).
162  std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers;
163 
164  /// Whether the compiler instance should retain (i.e., not free)
165  /// the buffers associated with remapped files.
166  ///
167  /// This flag defaults to false; it can be set true only through direct
168  /// manipulation of the compiler invocation object, in cases where the
169  /// compiler invocation and its buffers will be reused.
171 
172  /// When enabled, excluded conditional blocks retain in the main file.
174 
175  /// The Objective-C++ ARC standard library that we should support,
176  /// by providing appropriate definitions to retrofit the standard library
177  /// with support for lifetime-qualified pointers.
179 
180  /// Records the set of modules
182  llvm::StringSet<> Failed;
183 
184  public:
185  bool hasAlreadyFailed(StringRef module) {
186  return Failed.count(module) > 0;
187  }
188 
189  void addFailed(StringRef module) {
190  Failed.insert(module);
191  }
192  };
193 
194  /// The set of modules that failed to build.
195  ///
196  /// This pointer will be shared among all of the compiler instances created
197  /// to (re)build modules, so that once a module fails to build anywhere,
198  /// other instances will see that the module has failed and won't try to
199  /// build it again.
200  std::shared_ptr<FailedModulesSet> FailedModules;
201 
202  /// Contains the currently active skipped range mappings for skipping excluded
203  /// conditional directives.
204  ///
205  /// The pointer is passed to the Preprocessor when it's constructed. The
206  /// pointer is unowned, the client is responsible for its lifetime.
209 
210  /// Set up preprocessor for RunAnalysis action.
211  bool SetUpStaticAnalyzer = false;
212 
213  /// Prevents intended crashes when using #pragma clang __debug. For testing.
215 
216 public:
218 
219  void addMacroDef(StringRef Name) {
220  Macros.emplace_back(std::string(Name), false);
221  }
222  void addMacroUndef(StringRef Name) {
223  Macros.emplace_back(std::string(Name), true);
224  }
225 
226  void addRemappedFile(StringRef From, StringRef To) {
227  RemappedFiles.emplace_back(std::string(From), std::string(To));
228  }
229 
230  void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) {
231  RemappedFileBuffers.emplace_back(std::string(From), To);
232  }
233 
235  RemappedFiles.clear();
236  RemappedFileBuffers.clear();
237  }
238 
239  /// Reset any options that are not considered when building a
240  /// module.
242  Includes.clear();
243  MacroIncludes.clear();
244  ChainedIncludes.clear();
245  DumpDeserializedPCHDecls = false;
246  ImplicitPCHInclude.clear();
247  SingleFileParseMode = false;
248  LexEditorPlaceholders = true;
250  PrecompiledPreambleBytes.first = 0;
251  PrecompiledPreambleBytes.second = false;
253  }
254 };
255 
256 } // namespace clang
257 
258 #endif // LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
llvm
Definition: Dominators.h:30
clang::PreprocessorOptions::SetUpStaticAnalyzer
bool SetUpStaticAnalyzer
Set up preprocessor for RunAnalysis action.
Definition: PreprocessorOptions.h:211
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:64
clang::PreprocessorOptions::PreprocessorOptions
PreprocessorOptions()
Definition: PreprocessorOptions.h:217
clang::DisableValidationForModuleKind::Module
@ Module
Disable validation for module files.
clang::ARCXX_nolib
@ ARCXX_nolib
Definition: PreprocessorOptions.h:35
clang::PreprocessorOptions::DumpDeserializedPCHDecls
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
Definition: PreprocessorOptions.h:114
clang::PreprocessorOptions::DetailedRecord
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
Definition: PreprocessorOptions.h:76
clang::ExcludedPreprocessorDirectiveSkipMapping
llvm::DenseMap< const char *, const PreprocessorSkippedRangeMapping * > ExcludedPreprocessorDirectiveSkipMapping
The datastructure that holds the mapping between the active memory buffers and the individual skip ma...
Definition: PreprocessorExcludedConditionalDirectiveSkipMapping.h:26
clang::PreprocessorOptions::Includes
std::vector< std::string > Includes
Definition: PreprocessorOptions.h:67
clang::DisableValidationForModuleKind::None
@ None
Perform validation, don't disable it.
clang::PreprocessorOptions::DisablePragmaDebugCrash
bool DisablePragmaDebugCrash
Prevents intended crashes when using #pragma clang __debug. For testing.
Definition: PreprocessorOptions.h:214
clang::PreprocessorOptions::PCHWithHdrStopCreate
bool PCHWithHdrStopCreate
When true, we are creating a PCH or creating the PCH object while expecting a #pragma hdrstop to sepa...
Definition: PreprocessorOptions.h:86
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::PreprocessorOptions::FailedModulesSet
Records the set of modules.
Definition: PreprocessorOptions.h:181
clang::PreprocessorOptions::ChainedIncludes
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
Definition: PreprocessorOptions.h:99
clang::PreprocessorOptions::ExcludedConditionalDirectiveSkipMappings
ExcludedPreprocessorDirectiveSkipMapping * ExcludedConditionalDirectiveSkipMappings
Contains the currently active skipped range mappings for skipping excluded conditional directives.
Definition: PreprocessorOptions.h:208
clang::PreprocessorOptions::AllowPCHWithDifferentModulesCachePath
bool AllowPCHWithDifferentModulesCachePath
When true, a PCH with modules cache path different to the current compilation will not be rejected.
Definition: PreprocessorOptions.h:111
PreprocessorExcludedConditionalDirectiveSkipMapping.h
clang::DisableValidationForModuleKind
DisableValidationForModuleKind
Whether to disable the normal validation performed on precompiled headers and module files when they ...
Definition: PreprocessorOptions.h:46
clang::PreprocessorOptions::FailedModulesSet::hasAlreadyFailed
bool hasAlreadyFailed(StringRef module)
Definition: PreprocessorOptions.h:185
clang::PreprocessorOptions::AllowPCHWithCompilerErrors
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
Definition: PreprocessorOptions.h:107
clang::PreprocessorOptions::DisablePCHOrModuleValidation
DisableValidationForModuleKind DisablePCHOrModuleValidation
Whether to disable most of the normal validation performed on precompiled headers and module files.
Definition: PreprocessorOptions.h:103
clang::PreprocessorOptions::UsePredefines
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
Definition: PreprocessorOptions.h:72
clang::ARCXX_libcxx
@ ARCXX_libcxx
libc++
Definition: PreprocessorOptions.h:38
clang::DisableValidationForModuleKind::PCH
@ PCH
Disable validation for a precompiled header and the modules it depends on.
clang::PreprocessorOptions::addRemappedFile
void addRemappedFile(StringRef From, llvm::MemoryBuffer *To)
Definition: PreprocessorOptions.h:230
clang::PreprocessorOptions::GeneratePreamble
bool GeneratePreamble
True indicates that a preamble is being generated.
Definition: PreprocessorOptions.h:132
clang::PreprocessorOptions::RetainRemappedFileBuffers
bool RetainRemappedFileBuffers
Whether the compiler instance should retain (i.e., not free) the buffers associated with remapped fil...
Definition: PreprocessorOptions.h:170
clang::PreprocessorOptions::SingleFileParseMode
bool SingleFileParseMode
When enabled, preprocessor is in a mode for parsing a single file only.
Definition: PreprocessorOptions.h:144
false
#define false
Definition: stdbool.h:17
clang::PreprocessorOptions::resetNonModularOptions
void resetNonModularOptions()
Reset any options that are not considered when building a module.
Definition: PreprocessorOptions.h:241
clang::PreprocessorOptions::addMacroDef
void addMacroDef(StringRef Name)
Definition: PreprocessorOptions.h:219
clang::PreprocessorOptions::PCHThroughHeader
std::string PCHThroughHeader
If non-empty, the filename used in an include directive in the primary source file (or command-line p...
Definition: PreprocessorOptions.h:93
clang::PreprocessorOptions::PCHWithHdrStop
bool PCHWithHdrStop
When true, we are creating or using a PCH where a #pragma hdrstop is expected to indicate the beginni...
Definition: PreprocessorOptions.h:80
clang::PreprocessorOptions::RemappedFileBuffers
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...
Definition: PreprocessorOptions.h:162
clang::PreprocessorOptions::PrecompiledPreambleBytes
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
Definition: PreprocessorOptions.h:125
BitmaskEnum.h
clang::PreprocessorOptions::FailedModules
std::shared_ptr< FailedModulesSet > FailedModules
The set of modules that failed to build.
Definition: PreprocessorOptions.h:200
LLVM.h
clang::PreprocessorOptions::DeserializedPCHDeclsToErrorOn
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...
Definition: PreprocessorOptions.h:118
clang::DisableValidationForModuleKind::All
@ All
Disable validation for all kinds.
clang::PreprocessorOptions::ObjCXXARCStandardLibrary
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
Definition: PreprocessorOptions.h:178
clang::PreprocessorOptions::RemappedFiles
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...
Definition: PreprocessorOptions.h:157
clang::ARCXX_libstdcxx
@ ARCXX_libstdcxx
libstdc++
Definition: PreprocessorOptions.h:41
clang
Definition: CalledOnceCheck.h:17
clang::PreprocessorOptions::LexEditorPlaceholders
bool LexEditorPlaceholders
When enabled, the preprocessor will construct editor placeholder tokens.
Definition: PreprocessorOptions.h:147
clang::PreprocessorOptions::MacroIncludes
std::vector< std::string > MacroIncludes
Definition: PreprocessorOptions.h:68
clang::PreprocessorOptions::addMacroUndef
void addMacroUndef(StringRef Name)
Definition: PreprocessorOptions.h:222
clang::PreprocessorOptions::clearRemappedFiles
void clearRemappedFiles()
Definition: PreprocessorOptions.h:234
clang::ObjCXXARCStandardLibraryKind
ObjCXXARCStandardLibraryKind
Enumerate the kinds of standard library that.
Definition: PreprocessorOptions.h:34
clang::PreprocessorOptions::WriteCommentListToPCH
bool WriteCommentListToPCH
Whether to write comment locations into the PCH when building it.
Definition: PreprocessorOptions.h:137
clang::PreprocessorOptions::addRemappedFile
void addRemappedFile(StringRef From, StringRef To)
Definition: PreprocessorOptions.h:226
clang::PreprocessorOptions::Macros
std::vector< std::pair< std::string, bool > > Macros
Definition: PreprocessorOptions.h:66
clang::PreprocessorOptions::RetainExcludedConditionalBlocks
bool RetainExcludedConditionalBlocks
When enabled, excluded conditional blocks retain in the main file.
Definition: PreprocessorOptions.h:173
clang::PreprocessorOptions::FailedModulesSet::addFailed
void addFailed(StringRef module)
Definition: PreprocessorOptions.h:189
clang::PreprocessorOptions::ImplicitPCHInclude
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
Definition: PreprocessorOptions.h:96
clang::PreprocessorOptions::RemappedFilesKeepOriginalName
bool RemappedFilesKeepOriginalName
True if the SourceManager should report the original file name for contents of files that were remapp...
Definition: PreprocessorOptions.h:151