1 //===--- PreprocessorOptions.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
11 #define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
13 #include "clang/Basic/SourceLocation.h"
14 #include "llvm/ADT/IntrusiveRefCntPtr.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/StringSet.h"
33 /// \brief Enumerate the kinds of standard library that
34 enum ObjCXXARCStandardLibraryKind {
42 /// PreprocessorOptions - This class is used for passing the various options
43 /// used in preprocessor initialization to InitializePreprocessor().
44 class PreprocessorOptions : public RefCountedBase<PreprocessorOptions> {
46 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
47 std::vector<std::string> Includes;
48 std::vector<std::string> MacroIncludes;
50 /// \brief Initialize the preprocessor with the compiler and target specific
52 unsigned UsePredefines : 1;
54 /// \brief Whether we should maintain a detailed record of all macro
55 /// definitions and expansions.
56 unsigned DetailedRecord : 1;
58 /// The implicit PCH included at the start of the translation unit, or empty.
59 std::string ImplicitPCHInclude;
61 /// \brief Headers that will be converted to chained PCHs in memory.
62 std::vector<std::string> ChainedIncludes;
64 /// \brief When true, disables most of the normal validation performed on
65 /// precompiled headers.
66 bool DisablePCHValidation;
68 /// \brief When true, a PCH with compiler errors will not be rejected.
69 bool AllowPCHWithCompilerErrors;
71 /// \brief Dump declarations that are deserialized from PCH, for testing.
72 bool DumpDeserializedPCHDecls;
74 /// \brief This is a set of names for decls that we do not want to be
75 /// deserialized, and we emit an error if they are; for testing purposes.
76 std::set<std::string> DeserializedPCHDeclsToErrorOn;
78 /// \brief If non-zero, the implicit PCH include is actually a precompiled
79 /// preamble that covers this number of bytes in the main source file.
81 /// The boolean indicates whether the preamble ends at the start of a new
83 std::pair<unsigned, bool> PrecompiledPreambleBytes;
85 /// The implicit PTH input included at the start of the translation unit, or
87 std::string ImplicitPTHInclude;
89 /// If given, a PTH cache file to use for speeding up header parsing.
90 std::string TokenCache;
92 /// \brief True if the SourceManager should report the original file name for
93 /// contents of files that were remapped to other files. Defaults to true.
94 bool RemappedFilesKeepOriginalName;
96 /// \brief The set of file remappings, which take existing files on
97 /// the system (the first part of each pair) and gives them the
98 /// contents of other files on the system (the second part of each
100 std::vector<std::pair<std::string, std::string> > RemappedFiles;
102 /// \brief The set of file-to-buffer remappings, which take existing files
103 /// on the system (the first part of each pair) and gives them the contents
104 /// of the specified memory buffer (the second part of each pair).
105 std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >
108 /// \brief Whether the compiler instance should retain (i.e., not free)
109 /// the buffers associated with remapped files.
111 /// This flag defaults to false; it can be set true only through direct
112 /// manipulation of the compiler invocation object, in cases where the
113 /// compiler invocation and its buffers will be reused.
114 bool RetainRemappedFileBuffers;
116 /// \brief The Objective-C++ ARC standard library that we should support,
117 /// by providing appropriate definitions to retrofit the standard library
118 /// with support for lifetime-qualified pointers.
119 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
121 /// \brief Records the set of modules
122 class FailedModulesSet : public RefCountedBase<FailedModulesSet> {
123 llvm::StringSet<> Failed;
126 bool hasAlreadyFailed(StringRef module) {
127 return Failed.count(module) > 0;
130 void addFailed(StringRef module) {
131 Failed.insert(module);
135 /// \brief The set of modules that failed to build.
137 /// This pointer will be shared among all of the compiler instances created
138 /// to (re)build modules, so that once a module fails to build anywhere,
139 /// other instances will see that the module has failed and won't try to
141 IntrusiveRefCntPtr<FailedModulesSet> FailedModules;
143 typedef std::vector<std::pair<std::string, std::string> >::iterator
144 remapped_file_iterator;
145 typedef std::vector<std::pair<std::string, std::string> >::const_iterator
146 const_remapped_file_iterator;
147 remapped_file_iterator remapped_file_begin() {
148 return RemappedFiles.begin();
150 const_remapped_file_iterator remapped_file_begin() const {
151 return RemappedFiles.begin();
153 remapped_file_iterator remapped_file_end() {
154 return RemappedFiles.end();
156 const_remapped_file_iterator remapped_file_end() const {
157 return RemappedFiles.end();
160 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
161 iterator remapped_file_buffer_iterator;
162 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
163 const_iterator const_remapped_file_buffer_iterator;
164 remapped_file_buffer_iterator remapped_file_buffer_begin() {
165 return RemappedFileBuffers.begin();
167 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
168 return RemappedFileBuffers.begin();
170 remapped_file_buffer_iterator remapped_file_buffer_end() {
171 return RemappedFileBuffers.end();
173 const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
174 return RemappedFileBuffers.end();
178 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
179 DisablePCHValidation(false),
180 AllowPCHWithCompilerErrors(false),
181 DumpDeserializedPCHDecls(false),
182 PrecompiledPreambleBytes(0, true),
183 RemappedFilesKeepOriginalName(true),
184 RetainRemappedFileBuffers(false),
185 ObjCXXARCStandardLibrary(ARCXX_nolib) { }
187 void addMacroDef(StringRef Name) {
188 Macros.push_back(std::make_pair(Name, false));
190 void addMacroUndef(StringRef Name) {
191 Macros.push_back(std::make_pair(Name, true));
193 void addRemappedFile(StringRef From, StringRef To) {
194 RemappedFiles.push_back(std::make_pair(From, To));
197 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
198 return RemappedFiles.erase(Remapped);
201 void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) {
202 RemappedFileBuffers.push_back(std::make_pair(From, To));
205 remapped_file_buffer_iterator
206 eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
207 return RemappedFileBuffers.erase(Remapped);
210 void clearRemappedFiles() {
211 RemappedFiles.clear();
212 RemappedFileBuffers.clear();
215 /// \brief Reset any options that are not considered when building a
217 void resetNonModularOptions() {
219 MacroIncludes.clear();
220 ChainedIncludes.clear();
221 DumpDeserializedPCHDecls = false;
222 ImplicitPCHInclude.clear();
223 ImplicitPTHInclude.clear();
225 RetainRemappedFileBuffers = true;
226 PrecompiledPreambleBytes.first = 0;
227 PrecompiledPreambleBytes.second = 0;
231 } // end namespace clang