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