PreprocessorOptions.h revision 14e71f04136de056c08ffb9ccd44b4ca391cc8a5
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 "llvm/ADT/IntrusiveRefCntPtr.h" 14#include "llvm/ADT/SmallVector.h" 15#include "llvm/ADT/StringRef.h" 16#include <cassert> 17#include <string> 18#include <utility> 19#include <vector> 20#include <set> 21 22namespace llvm { 23 class MemoryBuffer; 24} 25 26namespace clang { 27 28class Preprocessor; 29class LangOptions; 30 31/// \brief Enumerate the kinds of standard library that 32enum ObjCXXARCStandardLibraryKind { 33 ARCXX_nolib, 34 /// \brief libc++ 35 ARCXX_libcxx, 36 /// \brief libstdc++ 37 ARCXX_libstdcxx 38}; 39 40/// PreprocessorOptions - This class is used for passing the various options 41/// used in preprocessor initialization to InitializePreprocessor(). 42class PreprocessorOptions : public llvm::RefCountedBase<PreprocessorOptions> { 43public: 44 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros; 45 std::vector<std::string> Includes; 46 std::vector<std::string> MacroIncludes; 47 48 unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler 49 /// and target specific predefines. 50 51 unsigned DetailedRecord : 1; /// Whether we should maintain a detailed 52 /// record of all macro definitions and 53 /// expansions. 54 unsigned DetailedRecordConditionalDirectives : 1; /// Whether in the 55 /// preprocessing record we should also keep 56 /// track of locations of conditional directives 57 /// in non-system files. 58 59 /// The implicit PCH included at the start of the translation unit, or empty. 60 std::string ImplicitPCHInclude; 61 62 /// \brief Headers that will be converted to chained PCHs in memory. 63 std::vector<std::string> ChainedIncludes; 64 65 /// \brief When true, disables most of the normal validation performed on 66 /// precompiled headers. 67 bool DisablePCHValidation; 68 69 /// \brief When true, disables the use of the stat cache within a 70 /// precompiled header or AST file. 71 bool DisableStatCache; 72 73 /// \brief When true, a PCH with compiler errors will not be rejected. 74 bool AllowPCHWithCompilerErrors; 75 76 /// \brief Dump declarations that are deserialized from PCH, for testing. 77 bool DumpDeserializedPCHDecls; 78 79 /// \brief This is a set of names for decls that we do not want to be 80 /// deserialized, and we emit an error if they are; for testing purposes. 81 std::set<std::string> DeserializedPCHDeclsToErrorOn; 82 83 /// \brief If non-zero, the implicit PCH include is actually a precompiled 84 /// preamble that covers this number of bytes in the main source file. 85 /// 86 /// The boolean indicates whether the preamble ends at the start of a new 87 /// line. 88 std::pair<unsigned, bool> PrecompiledPreambleBytes; 89 90 /// The implicit PTH input included at the start of the translation unit, or 91 /// empty. 92 std::string ImplicitPTHInclude; 93 94 /// If given, a PTH cache file to use for speeding up header parsing. 95 std::string TokenCache; 96 97 /// \brief True if the SourceManager should report the original file name for 98 /// contents of files that were remapped to other files. Defaults to true. 99 bool RemappedFilesKeepOriginalName; 100 101 /// \brief The set of file remappings, which take existing files on 102 /// the system (the first part of each pair) and gives them the 103 /// contents of other files on the system (the second part of each 104 /// pair). 105 std::vector<std::pair<std::string, std::string> > RemappedFiles; 106 107 /// \brief The set of file-to-buffer remappings, which take existing files 108 /// on the system (the first part of each pair) and gives them the contents 109 /// of the specified memory buffer (the second part of each pair). 110 std::vector<std::pair<std::string, const llvm::MemoryBuffer *> > 111 RemappedFileBuffers; 112 113 /// \brief Whether the compiler instance should retain (i.e., not free) 114 /// the buffers associated with remapped files. 115 /// 116 /// This flag defaults to false; it can be set true only through direct 117 /// manipulation of the compiler invocation object, in cases where the 118 /// compiler invocation and its buffers will be reused. 119 bool RetainRemappedFileBuffers; 120 121 /// \brief The Objective-C++ ARC standard library that we should support, 122 /// by providing appropriate definitions to retrofit the standard library 123 /// with support for lifetime-qualified pointers. 124 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary; 125 126 /// \brief The path of modules being build, which is used to detect 127 /// cycles in the module dependency graph as modules are being built. 128 /// 129 /// There is no way to set this value from the command line. If we ever need 130 /// to do so (e.g., if on-demand module construction moves out-of-process), 131 /// we can add a cc1-level option to do so. 132 SmallVector<std::string, 2> ModuleBuildPath; 133 134 typedef std::vector<std::pair<std::string, std::string> >::iterator 135 remapped_file_iterator; 136 typedef std::vector<std::pair<std::string, std::string> >::const_iterator 137 const_remapped_file_iterator; 138 remapped_file_iterator remapped_file_begin() { 139 return RemappedFiles.begin(); 140 } 141 const_remapped_file_iterator remapped_file_begin() const { 142 return RemappedFiles.begin(); 143 } 144 remapped_file_iterator remapped_file_end() { 145 return RemappedFiles.end(); 146 } 147 const_remapped_file_iterator remapped_file_end() const { 148 return RemappedFiles.end(); 149 } 150 151 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >:: 152 iterator remapped_file_buffer_iterator; 153 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >:: 154 const_iterator const_remapped_file_buffer_iterator; 155 remapped_file_buffer_iterator remapped_file_buffer_begin() { 156 return RemappedFileBuffers.begin(); 157 } 158 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const { 159 return RemappedFileBuffers.begin(); 160 } 161 remapped_file_buffer_iterator remapped_file_buffer_end() { 162 return RemappedFileBuffers.end(); 163 } 164 const_remapped_file_buffer_iterator remapped_file_buffer_end() const { 165 return RemappedFileBuffers.end(); 166 } 167 168public: 169 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), 170 DetailedRecordConditionalDirectives(false), 171 DisablePCHValidation(false), DisableStatCache(false), 172 AllowPCHWithCompilerErrors(false), 173 DumpDeserializedPCHDecls(false), 174 PrecompiledPreambleBytes(0, true), 175 RemappedFilesKeepOriginalName(true), 176 RetainRemappedFileBuffers(false), 177 ObjCXXARCStandardLibrary(ARCXX_nolib) { } 178 179 void addMacroDef(StringRef Name) { 180 Macros.push_back(std::make_pair(Name, false)); 181 } 182 void addMacroUndef(StringRef Name) { 183 Macros.push_back(std::make_pair(Name, true)); 184 } 185 void addRemappedFile(StringRef From, StringRef To) { 186 RemappedFiles.push_back(std::make_pair(From, To)); 187 } 188 189 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) { 190 return RemappedFiles.erase(Remapped); 191 } 192 193 void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) { 194 RemappedFileBuffers.push_back(std::make_pair(From, To)); 195 } 196 197 remapped_file_buffer_iterator 198 eraseRemappedFile(remapped_file_buffer_iterator Remapped) { 199 return RemappedFileBuffers.erase(Remapped); 200 } 201 202 void clearRemappedFiles() { 203 RemappedFiles.clear(); 204 RemappedFileBuffers.clear(); 205 } 206 207 /// \brief Reset any options that are not considered when building a 208 /// module. 209 void resetNonModularOptions() { 210 Includes.clear(); 211 MacroIncludes.clear(); 212 ChainedIncludes.clear(); 213 DumpDeserializedPCHDecls = false; 214 ImplicitPCHInclude.clear(); 215 ImplicitPTHInclude.clear(); 216 TokenCache.clear(); 217 RetainRemappedFileBuffers = true; 218 PrecompiledPreambleBytes.first = 0; 219 PrecompiledPreambleBytes.second = 0; 220 } 221}; 222 223} // end namespace clang 224 225#endif 226