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 the detailed preprocessing record includes nested macro
55 unsigned DetailedRecordIncludesNestedMacroExpansions : 1;
57 /// The implicit PCH included at the start of the translation unit, or empty.
58 std::string ImplicitPCHInclude;
60 /// \brief Headers that will be converted to chained PCHs in memory.
61 std::vector<std::string> ChainedIncludes;
63 /// \brief When true, disables most of the normal validation performed on
64 /// precompiled headers.
65 bool DisablePCHValidation;
67 /// \brief When true, disables the use of the stat cache within a
68 /// precompiled header or AST file.
69 bool DisableStatCache;
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 typedef std::vector<std::pair<std::string, std::string> >::iterator
122 remapped_file_iterator;
123 typedef std::vector<std::pair<std::string, std::string> >::const_iterator
124 const_remapped_file_iterator;
125 remapped_file_iterator remapped_file_begin() {
126 return RemappedFiles.begin();
128 const_remapped_file_iterator remapped_file_begin() const {
129 return RemappedFiles.begin();
131 remapped_file_iterator remapped_file_end() {
132 return RemappedFiles.end();
134 const_remapped_file_iterator remapped_file_end() const {
135 return RemappedFiles.end();
138 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
139 iterator remapped_file_buffer_iterator;
140 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
141 const_iterator const_remapped_file_buffer_iterator;
142 remapped_file_buffer_iterator remapped_file_buffer_begin() {
143 return RemappedFileBuffers.begin();
145 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
146 return RemappedFileBuffers.begin();
148 remapped_file_buffer_iterator remapped_file_buffer_end() {
149 return RemappedFileBuffers.end();
151 const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
152 return RemappedFileBuffers.end();
156 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
157 DetailedRecordIncludesNestedMacroExpansions(true),
158 DisablePCHValidation(false), DisableStatCache(false),
159 DumpDeserializedPCHDecls(false),
160 PrecompiledPreambleBytes(0, true),
161 RemappedFilesKeepOriginalName(true),
162 RetainRemappedFileBuffers(false),
163 ObjCXXARCStandardLibrary(ARCXX_nolib) { }
165 void addMacroDef(llvm::StringRef Name) {
166 Macros.push_back(std::make_pair(Name, false));
168 void addMacroUndef(llvm::StringRef Name) {
169 Macros.push_back(std::make_pair(Name, true));
171 void addRemappedFile(llvm::StringRef From, llvm::StringRef To) {
172 RemappedFiles.push_back(std::make_pair(From, To));
175 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
176 return RemappedFiles.erase(Remapped);
179 void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) {
180 RemappedFileBuffers.push_back(std::make_pair(From, To));
183 remapped_file_buffer_iterator
184 eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
185 return RemappedFileBuffers.erase(Remapped);
188 void clearRemappedFiles() {
189 RemappedFiles.clear();
190 RemappedFileBuffers.clear();
194 } // end namespace clang