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_FRONTEND_PREPROCESSOROPTIONS_H_ 11 #define LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_ 12 13 #include "llvm/ADT/SmallVector.h" 14 #include "llvm/ADT/StringRef.h" 15 #include <cassert> 16 #include <string> 17 #include <utility> 18 #include <vector> 19 #include <set> 20 21 namespace llvm { 22 class MemoryBuffer; 23 } 24 25 namespace clang { 26 27 class Preprocessor; 28 class LangOptions; 29 30 /// \brief Enumerate the kinds of standard library that 31 enum ObjCXXARCStandardLibraryKind { 32 ARCXX_nolib, 33 /// \brief libc++ 34 ARCXX_libcxx, 35 /// \brief libstdc++ 36 ARCXX_libstdcxx 37 }; 38 39 /// PreprocessorOptions - This class is used for passing the various options 40 /// used in preprocessor initialization to InitializePreprocessor(). 41 class PreprocessorOptions { 42 public: 43 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros; 44 std::vector<std::string> Includes; 45 std::vector<std::string> MacroIncludes; 46 47 unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler 48 /// and target specific predefines. 49 50 unsigned DetailedRecord : 1; /// Whether we should maintain a detailed 51 /// record of all macro definitions and 52 /// expansions. 53 unsigned DetailedRecordConditionalDirectives : 1; /// Whether in the 54 /// preprocessing record we should also keep 55 /// track of locations of conditional directives 56 /// in non-system files. 57 58 /// The implicit PCH included at the start of the translation unit, or empty. 59 std::string ImplicitPCHInclude; 60 61 /// \brief Headers that will be converted to chained PCHs in memory. 62 std::vector<std::string> ChainedIncludes; 63 64 /// \brief When true, disables most of the normal validation performed on 65 /// precompiled headers. 66 bool DisablePCHValidation; 67 68 /// \brief When true, disables the use of the stat cache within a 69 /// precompiled header or AST file. 70 bool DisableStatCache; 71 72 /// \brief When true, a PCH with compiler errors will not be rejected. 73 bool AllowPCHWithCompilerErrors; 74 75 /// \brief Dump declarations that are deserialized from PCH, for testing. 76 bool DumpDeserializedPCHDecls; 77 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; 81 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. 84 /// 85 /// The boolean indicates whether the preamble ends at the start of a new 86 /// line. 87 std::pair<unsigned, bool> PrecompiledPreambleBytes; 88 89 /// The implicit PTH input included at the start of the translation unit, or 90 /// empty. 91 std::string ImplicitPTHInclude; 92 93 /// If given, a PTH cache file to use for speeding up header parsing. 94 std::string TokenCache; 95 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; 99 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 103 /// pair). 104 std::vector<std::pair<std::string, std::string> > RemappedFiles; 105 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 *> > 110 RemappedFileBuffers; 111 112 /// \brief Whether the compiler instance should retain (i.e., not free) 113 /// the buffers associated with remapped files. 114 /// 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; 119 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; 124 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. 127 /// 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; 132 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; remapped_file_begin()137 remapped_file_iterator remapped_file_begin() { 138 return RemappedFiles.begin(); 139 } remapped_file_begin()140 const_remapped_file_iterator remapped_file_begin() const { 141 return RemappedFiles.begin(); 142 } remapped_file_end()143 remapped_file_iterator remapped_file_end() { 144 return RemappedFiles.end(); 145 } remapped_file_end()146 const_remapped_file_iterator remapped_file_end() const { 147 return RemappedFiles.end(); 148 } 149 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; remapped_file_buffer_begin()154 remapped_file_buffer_iterator remapped_file_buffer_begin() { 155 return RemappedFileBuffers.begin(); 156 } remapped_file_buffer_begin()157 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const { 158 return RemappedFileBuffers.begin(); 159 } remapped_file_buffer_end()160 remapped_file_buffer_iterator remapped_file_buffer_end() { 161 return RemappedFileBuffers.end(); 162 } remapped_file_buffer_end()163 const_remapped_file_buffer_iterator remapped_file_buffer_end() const { 164 return RemappedFileBuffers.end(); 165 } 166 167 public: PreprocessorOptions()168 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), 169 DetailedRecordConditionalDirectives(false), 170 DisablePCHValidation(false), DisableStatCache(false), 171 AllowPCHWithCompilerErrors(false), 172 DumpDeserializedPCHDecls(false), 173 PrecompiledPreambleBytes(0, true), 174 RemappedFilesKeepOriginalName(true), 175 RetainRemappedFileBuffers(false), 176 ObjCXXARCStandardLibrary(ARCXX_nolib) { } 177 addMacroDef(StringRef Name)178 void addMacroDef(StringRef Name) { 179 Macros.push_back(std::make_pair(Name, false)); 180 } addMacroUndef(StringRef Name)181 void addMacroUndef(StringRef Name) { 182 Macros.push_back(std::make_pair(Name, true)); 183 } addRemappedFile(StringRef From,StringRef To)184 void addRemappedFile(StringRef From, StringRef To) { 185 RemappedFiles.push_back(std::make_pair(From, To)); 186 } 187 eraseRemappedFile(remapped_file_iterator Remapped)188 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) { 189 return RemappedFiles.erase(Remapped); 190 } 191 addRemappedFile(StringRef From,const llvm::MemoryBuffer * To)192 void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) { 193 RemappedFileBuffers.push_back(std::make_pair(From, To)); 194 } 195 196 remapped_file_buffer_iterator eraseRemappedFile(remapped_file_buffer_iterator Remapped)197 eraseRemappedFile(remapped_file_buffer_iterator Remapped) { 198 return RemappedFileBuffers.erase(Remapped); 199 } 200 clearRemappedFiles()201 void clearRemappedFiles() { 202 RemappedFiles.clear(); 203 RemappedFileBuffers.clear(); 204 } 205 206 /// \brief Reset any options that are not considered when building a 207 /// module. resetNonModularOptions()208 void resetNonModularOptions() { 209 Includes.clear(); 210 MacroIncludes.clear(); 211 ChainedIncludes.clear(); 212 DumpDeserializedPCHDecls = false; 213 ImplicitPCHInclude.clear(); 214 ImplicitPTHInclude.clear(); 215 TokenCache.clear(); 216 RetainRemappedFileBuffers = true; 217 PrecompiledPreambleBytes.first = 0; 218 PrecompiledPreambleBytes.second = 0; 219 } 220 }; 221 222 } // end namespace clang 223 224 #endif 225