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/StringRef.h" 16 #include "llvm/ADT/StringSet.h" 17 #include <cassert> 18 #include <set> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 namespace llvm { 24 class MemoryBuffer; 25 } 26 27 namespace clang { 28 29 class Preprocessor; 30 class LangOptions; 31 32 /// \brief Enumerate the kinds of standard library that 33 enum 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(). 43 class PreprocessorOptions { 44 public: 45 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros; 46 std::vector<std::string> Includes; 47 std::vector<std::string> MacroIncludes; 48 49 /// \brief Initialize the preprocessor with the compiler and target specific 50 /// predefines. 51 unsigned UsePredefines : 1; 52 53 /// \brief Whether we should maintain a detailed record of all macro 54 /// definitions and expansions. 55 unsigned DetailedRecord : 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, a PCH with compiler errors will not be rejected. 68 bool AllowPCHWithCompilerErrors; 69 70 /// \brief Dump declarations that are deserialized from PCH, for testing. 71 bool DumpDeserializedPCHDecls; 72 73 /// \brief This is a set of names for decls that we do not want to be 74 /// deserialized, and we emit an error if they are; for testing purposes. 75 std::set<std::string> DeserializedPCHDeclsToErrorOn; 76 77 /// \brief If non-zero, the implicit PCH include is actually a precompiled 78 /// preamble that covers this number of bytes in the main source file. 79 /// 80 /// The boolean indicates whether the preamble ends at the start of a new 81 /// line. 82 std::pair<unsigned, bool> PrecompiledPreambleBytes; 83 84 /// \brief True indicates that a preamble is being generated. 85 /// 86 /// When the lexer is done, one of the things that need to be preserved is the 87 /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when 88 /// processing the rest of the file. 89 bool GeneratePreamble; 90 91 /// The implicit PTH input included at the start of the translation unit, or 92 /// empty. 93 std::string ImplicitPTHInclude; 94 95 /// If given, a PTH cache file to use for speeding up header parsing. 96 std::string TokenCache; 97 98 /// When enabled, preprocessor is in a mode for parsing a single file only. 99 bool SingleFileParseMode = false; 100 101 /// When enabled, the preprocessor will construct editor placeholder tokens. 102 bool LexEditorPlaceholders = true; 103 104 /// \brief True if the SourceManager should report the original file name for 105 /// contents of files that were remapped to other files. Defaults to true. 106 bool RemappedFilesKeepOriginalName; 107 108 /// \brief The set of file remappings, which take existing files on 109 /// the system (the first part of each pair) and gives them the 110 /// contents of other files on the system (the second part of each 111 /// pair). 112 std::vector<std::pair<std::string, std::string>> RemappedFiles; 113 114 /// \brief The set of file-to-buffer remappings, which take existing files 115 /// on the system (the first part of each pair) and gives them the contents 116 /// of the specified memory buffer (the second part of each pair). 117 std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers; 118 119 /// \brief Whether the compiler instance should retain (i.e., not free) 120 /// the buffers associated with remapped files. 121 /// 122 /// This flag defaults to false; it can be set true only through direct 123 /// manipulation of the compiler invocation object, in cases where the 124 /// compiler invocation and its buffers will be reused. 125 bool RetainRemappedFileBuffers; 126 127 /// \brief The Objective-C++ ARC standard library that we should support, 128 /// by providing appropriate definitions to retrofit the standard library 129 /// with support for lifetime-qualified pointers. 130 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary; 131 132 /// \brief Records the set of modules 133 class FailedModulesSet { 134 llvm::StringSet<> Failed; 135 136 public: 137 bool hasAlreadyFailed(StringRef module) { 138 return Failed.count(module) > 0; 139 } 140 141 void addFailed(StringRef module) { 142 Failed.insert(module); 143 } 144 }; 145 146 /// \brief The set of modules that failed to build. 147 /// 148 /// This pointer will be shared among all of the compiler instances created 149 /// to (re)build modules, so that once a module fails to build anywhere, 150 /// other instances will see that the module has failed and won't try to 151 /// build it again. 152 std::shared_ptr<FailedModulesSet> FailedModules; 153 154 public: 155 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), 156 DisablePCHValidation(false), 157 AllowPCHWithCompilerErrors(false), 158 DumpDeserializedPCHDecls(false), 159 PrecompiledPreambleBytes(0, true), 160 GeneratePreamble(false), 161 RemappedFilesKeepOriginalName(true), 162 RetainRemappedFileBuffers(false), 163 ObjCXXARCStandardLibrary(ARCXX_nolib) { } 164 165 void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); } 166 void addMacroUndef(StringRef Name) { Macros.emplace_back(Name, true); } 167 void addRemappedFile(StringRef From, StringRef To) { 168 RemappedFiles.emplace_back(From, To); 169 } 170 171 void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) { 172 RemappedFileBuffers.emplace_back(From, To); 173 } 174 175 void clearRemappedFiles() { 176 RemappedFiles.clear(); 177 RemappedFileBuffers.clear(); 178 } 179 180 /// \brief Reset any options that are not considered when building a 181 /// module. 182 void resetNonModularOptions() { 183 Includes.clear(); 184 MacroIncludes.clear(); 185 ChainedIncludes.clear(); 186 DumpDeserializedPCHDecls = false; 187 ImplicitPCHInclude.clear(); 188 ImplicitPTHInclude.clear(); 189 TokenCache.clear(); 190 SingleFileParseMode = false; 191 LexEditorPlaceholders = true; 192 RetainRemappedFileBuffers = true; 193 PrecompiledPreambleBytes.first = 0; 194 PrecompiledPreambleBytes.second = 0; 195 } 196 }; 197 198 } // end namespace clang 199 200 #endif 201