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