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_FRONTEND_PREPROCESSOROPTIONS_H_
11 #define LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
13 #include "llvm/ADT/StringRef.h"
29 /// \brief Enumerate the kinds of standard library that
30 enum ObjCXXARCStandardLibraryKind {
38 /// PreprocessorOptions - This class is used for passing the various options
39 /// used in preprocessor initialization to InitializePreprocessor().
40 class PreprocessorOptions {
42 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
43 std::vector<std::string> Includes;
44 std::vector<std::string> MacroIncludes;
46 unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
47 /// and target specific predefines.
49 unsigned DetailedRecord : 1; /// Whether we should maintain a detailed
50 /// record of all macro definitions and
53 /// \brief Whether we should automatically translate #include or #import
54 /// operations into module imports when possible.
55 unsigned AutoModuleImport : 1;
57 /// \brief Whether the detailed preprocessing record includes nested macro
59 unsigned DetailedRecordIncludesNestedMacroExpansions : 1;
61 /// The implicit PCH included at the start of the translation unit, or empty.
62 std::string ImplicitPCHInclude;
64 /// \brief Headers that will be converted to chained PCHs in memory.
65 std::vector<std::string> ChainedIncludes;
67 /// \brief When true, disables most of the normal validation performed on
68 /// precompiled headers.
69 bool DisablePCHValidation;
71 /// \brief When true, disables the use of the stat cache within a
72 /// precompiled header or AST file.
73 bool DisableStatCache;
75 /// \brief Dump declarations that are deserialized from PCH, for testing.
76 bool DumpDeserializedPCHDecls;
78 /// \brief This is a set of names for decls that we do not want to be
79 /// deserialized, and we emit an error if they are; for testing purposes.
80 std::set<std::string> DeserializedPCHDeclsToErrorOn;
82 /// \brief If non-zero, the implicit PCH include is actually a precompiled
83 /// preamble that covers this number of bytes in the main source file.
85 /// The boolean indicates whether the preamble ends at the start of a new
87 std::pair<unsigned, bool> PrecompiledPreambleBytes;
89 /// The implicit PTH input included at the start of the translation unit, or
91 std::string ImplicitPTHInclude;
93 /// If given, a PTH cache file to use for speeding up header parsing.
94 std::string TokenCache;
96 /// \brief True if the SourceManager should report the original file name for
97 /// contents of files that were remapped to other files. Defaults to true.
98 bool RemappedFilesKeepOriginalName;
100 /// \brief The set of file remappings, which take existing files on
101 /// the system (the first part of each pair) and gives them the
102 /// contents of other files on the system (the second part of each
104 std::vector<std::pair<std::string, std::string> > RemappedFiles;
106 /// \brief The set of file-to-buffer remappings, which take existing files
107 /// on the system (the first part of each pair) and gives them the contents
108 /// of the specified memory buffer (the second part of each pair).
109 std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >
112 /// \brief Whether the compiler instance should retain (i.e., not free)
113 /// the buffers associated with remapped files.
115 /// This flag defaults to false; it can be set true only through direct
116 /// manipulation of the compiler invocation object, in cases where the
117 /// compiler invocation and its buffers will be reused.
118 bool RetainRemappedFileBuffers;
120 /// \brief The Objective-C++ ARC standard library that we should support,
121 /// by providing appropriate definitions to retrofit the standard library
122 /// with support for lifetime-qualified pointers.
123 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
125 /// \brief The path of modules being build, which is used to detect
126 /// cycles in the module dependency graph as modules are being built.
128 /// There is no way to set this value from the command line. If we ever need
129 /// to do so (e.g., if on-demand module construction moves out-of-process),
130 /// we can add a cc1-level option to do so.
131 SmallVector<std::string, 2> ModuleBuildPath;
133 typedef std::vector<std::pair<std::string, std::string> >::iterator
134 remapped_file_iterator;
135 typedef std::vector<std::pair<std::string, std::string> >::const_iterator
136 const_remapped_file_iterator;
137 remapped_file_iterator remapped_file_begin() {
138 return RemappedFiles.begin();
140 const_remapped_file_iterator remapped_file_begin() const {
141 return RemappedFiles.begin();
143 remapped_file_iterator remapped_file_end() {
144 return RemappedFiles.end();
146 const_remapped_file_iterator remapped_file_end() const {
147 return RemappedFiles.end();
150 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
151 iterator remapped_file_buffer_iterator;
152 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
153 const_iterator const_remapped_file_buffer_iterator;
154 remapped_file_buffer_iterator remapped_file_buffer_begin() {
155 return RemappedFileBuffers.begin();
157 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
158 return RemappedFileBuffers.begin();
160 remapped_file_buffer_iterator remapped_file_buffer_end() {
161 return RemappedFileBuffers.end();
163 const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
164 return RemappedFileBuffers.end();
168 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
169 AutoModuleImport(false),
170 DetailedRecordIncludesNestedMacroExpansions(true),
171 DisablePCHValidation(false), DisableStatCache(false),
172 DumpDeserializedPCHDecls(false),
173 PrecompiledPreambleBytes(0, true),
174 RemappedFilesKeepOriginalName(true),
175 RetainRemappedFileBuffers(false),
176 ObjCXXARCStandardLibrary(ARCXX_nolib) { }
178 void addMacroDef(StringRef Name) {
179 Macros.push_back(std::make_pair(Name, false));
181 void addMacroUndef(StringRef Name) {
182 Macros.push_back(std::make_pair(Name, true));
184 void addRemappedFile(StringRef From, StringRef To) {
185 RemappedFiles.push_back(std::make_pair(From, To));
188 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
189 return RemappedFiles.erase(Remapped);
192 void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) {
193 RemappedFileBuffers.push_back(std::make_pair(From, To));
196 remapped_file_buffer_iterator
197 eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
198 return RemappedFileBuffers.erase(Remapped);
201 void clearRemappedFiles() {
202 RemappedFiles.clear();
203 RemappedFileBuffers.clear();
206 /// \brief Reset any options that are not considered when building a
208 void resetNonModularOptions() {
210 MacroIncludes.clear();
211 ChainedIncludes.clear();
212 DumpDeserializedPCHDecls = false;
213 ImplicitPCHInclude.clear();
214 ImplicitPTHInclude.clear();
216 RetainRemappedFileBuffers = true;
217 PrecompiledPreambleBytes.first = 0;
218 PrecompiledPreambleBytes.second = 0;
222 } // end namespace clang