clang API Documentation
00001 //===--- PreprocessorOptions.h ----------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_ 00011 #define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_ 00012 00013 #include "clang/Basic/SourceLocation.h" 00014 #include "llvm/ADT/IntrusiveRefCntPtr.h" 00015 #include "llvm/ADT/SmallVector.h" 00016 #include "llvm/ADT/StringRef.h" 00017 #include "llvm/ADT/StringSet.h" 00018 #include <cassert> 00019 #include <set> 00020 #include <string> 00021 #include <utility> 00022 #include <vector> 00023 00024 namespace llvm { 00025 class MemoryBuffer; 00026 } 00027 00028 namespace clang { 00029 00030 class Preprocessor; 00031 class LangOptions; 00032 00033 /// \brief Enumerate the kinds of standard library that 00034 enum ObjCXXARCStandardLibraryKind { 00035 ARCXX_nolib, 00036 /// \brief libc++ 00037 ARCXX_libcxx, 00038 /// \brief libstdc++ 00039 ARCXX_libstdcxx 00040 }; 00041 00042 /// PreprocessorOptions - This class is used for passing the various options 00043 /// used in preprocessor initialization to InitializePreprocessor(). 00044 class PreprocessorOptions : public RefCountedBase<PreprocessorOptions> { 00045 public: 00046 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros; 00047 std::vector<std::string> Includes; 00048 std::vector<std::string> MacroIncludes; 00049 00050 /// \brief Initialize the preprocessor with the compiler and target specific 00051 /// predefines. 00052 unsigned UsePredefines : 1; 00053 00054 /// \brief Whether we should maintain a detailed record of all macro 00055 /// definitions and expansions. 00056 unsigned DetailedRecord : 1; 00057 00058 /// The implicit PCH included at the start of the translation unit, or empty. 00059 std::string ImplicitPCHInclude; 00060 00061 /// \brief Headers that will be converted to chained PCHs in memory. 00062 std::vector<std::string> ChainedIncludes; 00063 00064 /// \brief When true, disables most of the normal validation performed on 00065 /// precompiled headers. 00066 bool DisablePCHValidation; 00067 00068 /// \brief When true, a PCH with compiler errors will not be rejected. 00069 bool AllowPCHWithCompilerErrors; 00070 00071 /// \brief Dump declarations that are deserialized from PCH, for testing. 00072 bool DumpDeserializedPCHDecls; 00073 00074 /// \brief This is a set of names for decls that we do not want to be 00075 /// deserialized, and we emit an error if they are; for testing purposes. 00076 std::set<std::string> DeserializedPCHDeclsToErrorOn; 00077 00078 /// \brief If non-zero, the implicit PCH include is actually a precompiled 00079 /// preamble that covers this number of bytes in the main source file. 00080 /// 00081 /// The boolean indicates whether the preamble ends at the start of a new 00082 /// line. 00083 std::pair<unsigned, bool> PrecompiledPreambleBytes; 00084 00085 /// The implicit PTH input included at the start of the translation unit, or 00086 /// empty. 00087 std::string ImplicitPTHInclude; 00088 00089 /// If given, a PTH cache file to use for speeding up header parsing. 00090 std::string TokenCache; 00091 00092 /// \brief True if the SourceManager should report the original file name for 00093 /// contents of files that were remapped to other files. Defaults to true. 00094 bool RemappedFilesKeepOriginalName; 00095 00096 /// \brief The set of file remappings, which take existing files on 00097 /// the system (the first part of each pair) and gives them the 00098 /// contents of other files on the system (the second part of each 00099 /// pair). 00100 std::vector<std::pair<std::string, std::string>> RemappedFiles; 00101 00102 /// \brief The set of file-to-buffer remappings, which take existing files 00103 /// on the system (the first part of each pair) and gives them the contents 00104 /// of the specified memory buffer (the second part of each pair). 00105 std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers; 00106 00107 /// \brief Whether the compiler instance should retain (i.e., not free) 00108 /// the buffers associated with remapped files. 00109 /// 00110 /// This flag defaults to false; it can be set true only through direct 00111 /// manipulation of the compiler invocation object, in cases where the 00112 /// compiler invocation and its buffers will be reused. 00113 bool RetainRemappedFileBuffers; 00114 00115 /// \brief The Objective-C++ ARC standard library that we should support, 00116 /// by providing appropriate definitions to retrofit the standard library 00117 /// with support for lifetime-qualified pointers. 00118 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary; 00119 00120 /// \brief Records the set of modules 00121 class FailedModulesSet : public RefCountedBase<FailedModulesSet> { 00122 llvm::StringSet<> Failed; 00123 00124 public: 00125 bool hasAlreadyFailed(StringRef module) { 00126 return Failed.count(module) > 0; 00127 } 00128 00129 void addFailed(StringRef module) { 00130 Failed.insert(module); 00131 } 00132 }; 00133 00134 /// \brief The set of modules that failed to build. 00135 /// 00136 /// This pointer will be shared among all of the compiler instances created 00137 /// to (re)build modules, so that once a module fails to build anywhere, 00138 /// other instances will see that the module has failed and won't try to 00139 /// build it again. 00140 IntrusiveRefCntPtr<FailedModulesSet> FailedModules; 00141 00142 public: 00143 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), 00144 DisablePCHValidation(false), 00145 AllowPCHWithCompilerErrors(false), 00146 DumpDeserializedPCHDecls(false), 00147 PrecompiledPreambleBytes(0, true), 00148 RemappedFilesKeepOriginalName(true), 00149 RetainRemappedFileBuffers(false), 00150 ObjCXXARCStandardLibrary(ARCXX_nolib) { } 00151 00152 void addMacroDef(StringRef Name) { 00153 Macros.push_back(std::make_pair(Name, false)); 00154 } 00155 void addMacroUndef(StringRef Name) { 00156 Macros.push_back(std::make_pair(Name, true)); 00157 } 00158 void addRemappedFile(StringRef From, StringRef To) { 00159 RemappedFiles.push_back(std::make_pair(From, To)); 00160 } 00161 00162 void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) { 00163 RemappedFileBuffers.push_back(std::make_pair(From, To)); 00164 } 00165 00166 void clearRemappedFiles() { 00167 RemappedFiles.clear(); 00168 RemappedFileBuffers.clear(); 00169 } 00170 00171 /// \brief Reset any options that are not considered when building a 00172 /// module. 00173 void resetNonModularOptions() { 00174 Includes.clear(); 00175 MacroIncludes.clear(); 00176 ChainedIncludes.clear(); 00177 DumpDeserializedPCHDecls = false; 00178 ImplicitPCHInclude.clear(); 00179 ImplicitPTHInclude.clear(); 00180 TokenCache.clear(); 00181 RetainRemappedFileBuffers = true; 00182 PrecompiledPreambleBytes.first = 0; 00183 PrecompiledPreambleBytes.second = 0; 00184 } 00185 }; 00186 00187 } // end namespace clang 00188 00189 #endif