PreprocessorOptions.h revision 4182ed686283b72736b287cbe28583cb641f8934
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, a PCH with compiler errors will not be rejected. 70 bool AllowPCHWithCompilerErrors; 71 72 /// \brief Dump declarations that are deserialized from PCH, for testing. 73 bool DumpDeserializedPCHDecls; 74 75 /// \brief This is a set of names for decls that we do not want to be 76 /// deserialized, and we emit an error if they are; for testing purposes. 77 std::set<std::string> DeserializedPCHDeclsToErrorOn; 78 79 /// \brief If non-zero, the implicit PCH include is actually a precompiled 80 /// preamble that covers this number of bytes in the main source file. 81 /// 82 /// The boolean indicates whether the preamble ends at the start of a new 83 /// line. 84 std::pair<unsigned, bool> PrecompiledPreambleBytes; 85 86 /// The implicit PTH input included at the start of the translation unit, or 87 /// empty. 88 std::string ImplicitPTHInclude; 89 90 /// If given, a PTH cache file to use for speeding up header parsing. 91 std::string TokenCache; 92 93 /// \brief True if the SourceManager should report the original file name for 94 /// contents of files that were remapped to other files. Defaults to true. 95 bool RemappedFilesKeepOriginalName; 96 97 /// \brief The set of file remappings, which take existing files on 98 /// the system (the first part of each pair) and gives them the 99 /// contents of other files on the system (the second part of each 100 /// pair). 101 std::vector<std::pair<std::string, std::string> > RemappedFiles; 102 103 /// \brief The set of file-to-buffer remappings, which take existing files 104 /// on the system (the first part of each pair) and gives them the contents 105 /// of the specified memory buffer (the second part of each pair). 106 std::vector<std::pair<std::string, const llvm::MemoryBuffer *> > 107 RemappedFileBuffers; 108 109 /// \brief Whether the compiler instance should retain (i.e., not free) 110 /// the buffers associated with remapped files. 111 /// 112 /// This flag defaults to false; it can be set true only through direct 113 /// manipulation of the compiler invocation object, in cases where the 114 /// compiler invocation and its buffers will be reused. 115 bool RetainRemappedFileBuffers; 116 117 /// \brief The Objective-C++ ARC standard library that we should support, 118 /// by providing appropriate definitions to retrofit the standard library 119 /// with support for lifetime-qualified pointers. 120 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary; 121 122 /// \brief The path of modules being build, which is used to detect 123 /// cycles in the module dependency graph as modules are being built. 124 /// 125 /// There is no way to set this value from the command line. If we ever need 126 /// to do so (e.g., if on-demand module construction moves out-of-process), 127 /// we can add a cc1-level option to do so. 128 SmallVector<std::string, 2> ModuleBuildPath; 129 130 typedef std::vector<std::pair<std::string, std::string> >::iterator 131 remapped_file_iterator; 132 typedef std::vector<std::pair<std::string, std::string> >::const_iterator 133 const_remapped_file_iterator; 134 remapped_file_iterator remapped_file_begin() { 135 return RemappedFiles.begin(); 136 } 137 const_remapped_file_iterator remapped_file_begin() const { 138 return RemappedFiles.begin(); 139 } 140 remapped_file_iterator remapped_file_end() { 141 return RemappedFiles.end(); 142 } 143 const_remapped_file_iterator remapped_file_end() const { 144 return RemappedFiles.end(); 145 } 146 147 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >:: 148 iterator remapped_file_buffer_iterator; 149 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >:: 150 const_iterator const_remapped_file_buffer_iterator; 151 remapped_file_buffer_iterator remapped_file_buffer_begin() { 152 return RemappedFileBuffers.begin(); 153 } 154 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const { 155 return RemappedFileBuffers.begin(); 156 } 157 remapped_file_buffer_iterator remapped_file_buffer_end() { 158 return RemappedFileBuffers.end(); 159 } 160 const_remapped_file_buffer_iterator remapped_file_buffer_end() const { 161 return RemappedFileBuffers.end(); 162 } 163 164public: 165 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), 166 DetailedRecordConditionalDirectives(false), 167 DisablePCHValidation(false), 168 AllowPCHWithCompilerErrors(false), 169 DumpDeserializedPCHDecls(false), 170 PrecompiledPreambleBytes(0, true), 171 RemappedFilesKeepOriginalName(true), 172 RetainRemappedFileBuffers(false), 173 ObjCXXARCStandardLibrary(ARCXX_nolib) { } 174 175 void addMacroDef(StringRef Name) { 176 Macros.push_back(std::make_pair(Name, false)); 177 } 178 void addMacroUndef(StringRef Name) { 179 Macros.push_back(std::make_pair(Name, true)); 180 } 181 void addRemappedFile(StringRef From, StringRef To) { 182 RemappedFiles.push_back(std::make_pair(From, To)); 183 } 184 185 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) { 186 return RemappedFiles.erase(Remapped); 187 } 188 189 void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) { 190 RemappedFileBuffers.push_back(std::make_pair(From, To)); 191 } 192 193 remapped_file_buffer_iterator 194 eraseRemappedFile(remapped_file_buffer_iterator Remapped) { 195 return RemappedFileBuffers.erase(Remapped); 196 } 197 198 void clearRemappedFiles() { 199 RemappedFiles.clear(); 200 RemappedFileBuffers.clear(); 201 } 202 203 /// \brief Reset any options that are not considered when building a 204 /// module. 205 void resetNonModularOptions() { 206 Includes.clear(); 207 MacroIncludes.clear(); 208 ChainedIncludes.clear(); 209 DumpDeserializedPCHDecls = false; 210 ImplicitPCHInclude.clear(); 211 ImplicitPTHInclude.clear(); 212 TokenCache.clear(); 213 RetainRemappedFileBuffers = true; 214 PrecompiledPreambleBytes.first = 0; 215 PrecompiledPreambleBytes.second = 0; 216 } 217}; 218 219} // end namespace clang 220 221#endif 222