clang  9.0.0svn
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 
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/StringSet.h"
15 #include <memory>
16 #include <set>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 namespace llvm {
22 
23 class MemoryBuffer;
24 
25 } // namespace llvm
26 
27 namespace clang {
28 
29 /// Enumerate the kinds of standard library that
32 
33  /// libc++
35 
36  /// libstdc++
38 };
39 
40 /// PreprocessorOptions - This class is used for passing the various options
41 /// used in preprocessor initialization to InitializePreprocessor().
43 public:
44  std::vector<std::pair<std::string, bool/*isUndef*/>> Macros;
45  std::vector<std::string> Includes;
46  std::vector<std::string> MacroIncludes;
47 
48  /// Initialize the preprocessor with the compiler and target specific
49  /// predefines.
50  bool UsePredefines = true;
51 
52  /// Whether we should maintain a detailed record of all macro
53  /// definitions and expansions.
54  bool DetailedRecord = false;
55 
56  /// When true, we are creating or using a PCH where a #pragma hdrstop is
57  /// expected to indicate the beginning or end of the PCH.
58  bool PCHWithHdrStop = false;
59 
60  /// When true, we are creating a PCH or creating the PCH object while
61  /// expecting a #pragma hdrstop to separate the two. Allow for a
62  /// missing #pragma hdrstop, which generates a PCH for the whole file,
63  /// and creates an empty PCH object.
64  bool PCHWithHdrStopCreate = false;
65 
66  /// If non-empty, the filename used in an #include directive in the primary
67  /// source file (or command-line preinclude) that is used to implement
68  /// MSVC-style precompiled headers. When creating a PCH, after the #include
69  /// of this header, the PCH generation stops. When using a PCH, tokens are
70  /// skipped until after an #include of this header is seen.
71  std::string PCHThroughHeader;
72 
73  /// The implicit PCH included at the start of the translation unit, or empty.
74  std::string ImplicitPCHInclude;
75 
76  /// Headers that will be converted to chained PCHs in memory.
77  std::vector<std::string> ChainedIncludes;
78 
79  /// When true, disables most of the normal validation performed on
80  /// precompiled headers.
81  bool DisablePCHValidation = false;
82 
83  /// When true, a PCH with compiler errors will not be rejected.
84  bool AllowPCHWithCompilerErrors = false;
85 
86  /// Dump declarations that are deserialized from PCH, for testing.
87  bool DumpDeserializedPCHDecls = false;
88 
89  /// This is a set of names for decls that we do not want to be
90  /// deserialized, and we emit an error if they are; for testing purposes.
91  std::set<std::string> DeserializedPCHDeclsToErrorOn;
92 
93  /// If non-zero, the implicit PCH include is actually a precompiled
94  /// preamble that covers this number of bytes in the main source file.
95  ///
96  /// The boolean indicates whether the preamble ends at the start of a new
97  /// line.
98  std::pair<unsigned, bool> PrecompiledPreambleBytes;
99 
100  /// True indicates that a preamble is being generated.
101  ///
102  /// When the lexer is done, one of the things that need to be preserved is the
103  /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when
104  /// processing the rest of the file.
105  bool GeneratePreamble = false;
106 
107  /// Whether to write comment locations into the PCH when building it.
108  /// Reading the comments from the PCH can be a performance hit even if the
109  /// clients don't use them.
110  bool WriteCommentListToPCH = true;
111 
112  /// When enabled, preprocessor is in a mode for parsing a single file only.
113  ///
114  /// Disables #includes of other files and if there are unresolved identifiers
115  /// in preprocessor directive conditions it causes all blocks to be parsed so
116  /// that the client can get the maximum amount of information from the parser.
117  bool SingleFileParseMode = false;
118 
119  /// When enabled, the preprocessor will construct editor placeholder tokens.
120  bool LexEditorPlaceholders = true;
121 
122  /// True if the SourceManager should report the original file name for
123  /// contents of files that were remapped to other files. Defaults to true.
124  bool RemappedFilesKeepOriginalName = true;
125 
126  /// The set of file remappings, which take existing files on
127  /// the system (the first part of each pair) and gives them the
128  /// contents of other files on the system (the second part of each
129  /// pair).
130  std::vector<std::pair<std::string, std::string>> RemappedFiles;
131 
132  /// The set of file-to-buffer remappings, which take existing files
133  /// on the system (the first part of each pair) and gives them the contents
134  /// of the specified memory buffer (the second part of each pair).
135  std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers;
136 
137  /// Whether the compiler instance should retain (i.e., not free)
138  /// the buffers associated with remapped files.
139  ///
140  /// This flag defaults to false; it can be set true only through direct
141  /// manipulation of the compiler invocation object, in cases where the
142  /// compiler invocation and its buffers will be reused.
143  bool RetainRemappedFileBuffers = false;
144 
145  /// The Objective-C++ ARC standard library that we should support,
146  /// by providing appropriate definitions to retrofit the standard library
147  /// with support for lifetime-qualified pointers.
148  ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary = ARCXX_nolib;
149 
150  /// Records the set of modules
152  llvm::StringSet<> Failed;
153 
154  public:
155  bool hasAlreadyFailed(StringRef module) {
156  return Failed.count(module) > 0;
157  }
158 
159  void addFailed(StringRef module) {
160  Failed.insert(module);
161  }
162  };
163 
164  /// The set of modules that failed to build.
165  ///
166  /// This pointer will be shared among all of the compiler instances created
167  /// to (re)build modules, so that once a module fails to build anywhere,
168  /// other instances will see that the module has failed and won't try to
169  /// build it again.
170  std::shared_ptr<FailedModulesSet> FailedModules;
171 
172 public:
173  PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
174 
175  void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); }
176  void addMacroUndef(StringRef Name) { Macros.emplace_back(Name, true); }
177 
178  void addRemappedFile(StringRef From, StringRef To) {
179  RemappedFiles.emplace_back(From, To);
180  }
181 
182  void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) {
183  RemappedFileBuffers.emplace_back(From, To);
184  }
185 
187  RemappedFiles.clear();
188  RemappedFileBuffers.clear();
189  }
190 
191  /// Reset any options that are not considered when building a
192  /// module.
194  Includes.clear();
195  MacroIncludes.clear();
196  ChainedIncludes.clear();
197  DumpDeserializedPCHDecls = false;
198  ImplicitPCHInclude.clear();
199  SingleFileParseMode = false;
200  LexEditorPlaceholders = true;
201  RetainRemappedFileBuffers = true;
202  PrecompiledPreambleBytes.first = 0;
203  PrecompiledPreambleBytes.second = false;
204  }
205 };
206 
207 } // namespace clang
208 
209 #endif // LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
std::vector< std::pair< std::string, bool > > Macros
void addMacroUndef(StringRef Name)
ObjCXXARCStandardLibraryKind
Enumerate the kinds of standard library that.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:29
std::vector< std::string > Includes
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
std::shared_ptr< FailedModulesSet > FailedModules
The set of modules that failed to build.
void addRemappedFile(StringRef From, StringRef To)
void addRemappedFile(StringRef From, llvm::MemoryBuffer *To)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
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...
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
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...
#define false
Definition: stdbool.h:17
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
void resetNonModularOptions()
Reset any options that are not considered when building a module.
std::string PCHThroughHeader
If non-empty, the filename used in an #include directive in the primary source file (or command-line ...
void addMacroDef(StringRef Name)
std::vector< std::string > MacroIncludes
Dataflow Directional Tag Classes.
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...
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...