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/StringRef.h" 14 #include <cassert> 15 #include <string> 16 #include <utility> 17 #include <vector> 18 #include <set> 19 20 namespace llvm { 21 class MemoryBuffer; 22 } 23 24 namespace clang { 25 26 class Preprocessor; 27 class LangOptions; 28 29 /// \brief Enumerate the kinds of standard library that 30 enum ObjCXXARCStandardLibraryKind { 31 ARCXX_nolib, 32 /// \brief libc++ 33 ARCXX_libcxx, 34 /// \brief libstdc++ 35 ARCXX_libstdcxx 36 }; 37 38 /// PreprocessorOptions - This class is used for passing the various options 39 /// used in preprocessor initialization to InitializePreprocessor(). 40 class PreprocessorOptions { 41 public: 42 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros; 43 std::vector<std::string> Includes; 44 std::vector<std::string> MacroIncludes; 45 46 unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler 47 /// and target specific predefines. 48 49 unsigned DetailedRecord : 1; /// Whether we should maintain a detailed 50 /// record of all macro definitions and 51 /// expansions. 52 53 /// \brief Whether the detailed preprocessing record includes nested macro 54 /// expansions. 55 unsigned DetailedRecordIncludesNestedMacroExpansions : 1; 56 57 /// The implicit PCH included at the start of the translation unit, or empty. 58 std::string ImplicitPCHInclude; 59 60 /// \brief Headers that will be converted to chained PCHs in memory. 61 std::vector<std::string> ChainedIncludes; 62 63 /// \brief When true, disables most of the normal validation performed on 64 /// precompiled headers. 65 bool DisablePCHValidation; 66 67 /// \brief When true, disables the use of the stat cache within a 68 /// precompiled header or AST file. 69 bool DisableStatCache; 70 71 /// \brief Dump declarations that are deserialized from PCH, for testing. 72 bool DumpDeserializedPCHDecls; 73 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; 77 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. 80 /// 81 /// The boolean indicates whether the preamble ends at the start of a new 82 /// line. 83 std::pair<unsigned, bool> PrecompiledPreambleBytes; 84 85 /// The implicit PTH input included at the start of the translation unit, or 86 /// empty. 87 std::string ImplicitPTHInclude; 88 89 /// If given, a PTH cache file to use for speeding up header parsing. 90 std::string TokenCache; 91 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; 95 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 99 /// pair). 100 std::vector<std::pair<std::string, std::string> > RemappedFiles; 101 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 *> > 106 RemappedFileBuffers; 107 108 /// \brief Whether the compiler instance should retain (i.e., not free) 109 /// the buffers associated with remapped files. 110 /// 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; 115 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; 120 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; remapped_file_begin()125 remapped_file_iterator remapped_file_begin() { 126 return RemappedFiles.begin(); 127 } remapped_file_begin()128 const_remapped_file_iterator remapped_file_begin() const { 129 return RemappedFiles.begin(); 130 } remapped_file_end()131 remapped_file_iterator remapped_file_end() { 132 return RemappedFiles.end(); 133 } remapped_file_end()134 const_remapped_file_iterator remapped_file_end() const { 135 return RemappedFiles.end(); 136 } 137 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; remapped_file_buffer_begin()142 remapped_file_buffer_iterator remapped_file_buffer_begin() { 143 return RemappedFileBuffers.begin(); 144 } remapped_file_buffer_begin()145 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const { 146 return RemappedFileBuffers.begin(); 147 } remapped_file_buffer_end()148 remapped_file_buffer_iterator remapped_file_buffer_end() { 149 return RemappedFileBuffers.end(); 150 } remapped_file_buffer_end()151 const_remapped_file_buffer_iterator remapped_file_buffer_end() const { 152 return RemappedFileBuffers.end(); 153 } 154 155 public: PreprocessorOptions()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) { } 164 addMacroDef(llvm::StringRef Name)165 void addMacroDef(llvm::StringRef Name) { 166 Macros.push_back(std::make_pair(Name, false)); 167 } addMacroUndef(llvm::StringRef Name)168 void addMacroUndef(llvm::StringRef Name) { 169 Macros.push_back(std::make_pair(Name, true)); 170 } addRemappedFile(llvm::StringRef From,llvm::StringRef To)171 void addRemappedFile(llvm::StringRef From, llvm::StringRef To) { 172 RemappedFiles.push_back(std::make_pair(From, To)); 173 } 174 eraseRemappedFile(remapped_file_iterator Remapped)175 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) { 176 return RemappedFiles.erase(Remapped); 177 } 178 addRemappedFile(llvm::StringRef From,const llvm::MemoryBuffer * To)179 void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) { 180 RemappedFileBuffers.push_back(std::make_pair(From, To)); 181 } 182 183 remapped_file_buffer_iterator eraseRemappedFile(remapped_file_buffer_iterator Remapped)184 eraseRemappedFile(remapped_file_buffer_iterator Remapped) { 185 return RemappedFileBuffers.erase(Remapped); 186 } 187 clearRemappedFiles()188 void clearRemappedFiles() { 189 RemappedFiles.clear(); 190 RemappedFileBuffers.clear(); 191 } 192 }; 193 194 } // end namespace clang 195 196 #endif 197