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