1a1a38741fdf676af3174ea6f465eb07da003e761Peter Collingbourne//===--- PreprocessorOptions.h ----------------------------------*- C++ -*-===// 2e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner// 3e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner// The LLVM Compiler Infrastructure 4e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner// 5e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner// This file is distributed under the University of Illinois Open Source 6e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner// License. See LICENSE.TXT for details. 7e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner// 8e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner//===----------------------------------------------------------------------===// 9e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 1014e71f04136de056c08ffb9ccd44b4ca391cc8a5Douglas Gregor#ifndef LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_ 1114e71f04136de056c08ffb9ccd44b4ca391cc8a5Douglas Gregor#define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_ 12e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 13830ea5b7c75413526c19531f0180fa6e45b98919Douglas Gregor#include "clang/Basic/SourceLocation.h" 1414e71f04136de056c08ffb9ccd44b4ca391cc8a5Douglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 15ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek#include "llvm/ADT/SmallVector.h" 16b6d1cc84d1a7e314f7a7a02fbe092adc4caf67e8Daniel Dunbar#include "llvm/ADT/StringRef.h" 17463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor#include "llvm/ADT/StringSet.h" 18b52d243d3626bb08758022c39b2cbc58160eadd7Daniel Dunbar#include <cassert> 1930a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include <set> 20e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner#include <string> 21716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor#include <utility> 22e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner#include <vector> 23e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 244db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregornamespace llvm { 254db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor class MemoryBuffer; 264db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor} 274db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor 28e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattnernamespace clang { 29e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 30e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattnerclass Preprocessor; 31e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattnerclass LangOptions; 32e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 33f85e193739c953358c865005855253af4f68a497John McCall/// \brief Enumerate the kinds of standard library that 34f85e193739c953358c865005855253af4f68a497John McCallenum ObjCXXARCStandardLibraryKind { 35f85e193739c953358c865005855253af4f68a497John McCall ARCXX_nolib, 36f85e193739c953358c865005855253af4f68a497John McCall /// \brief libc++ 37f85e193739c953358c865005855253af4f68a497John McCall ARCXX_libcxx, 38f85e193739c953358c865005855253af4f68a497John McCall /// \brief libstdc++ 39f85e193739c953358c865005855253af4f68a497John McCall ARCXX_libstdcxx 40f85e193739c953358c865005855253af4f68a497John McCall}; 41f85e193739c953358c865005855253af4f68a497John McCall 428863b985f1cf78a2fb62913e184dc45162853cf9Daniel Dunbar/// PreprocessorOptions - This class is used for passing the various options 438863b985f1cf78a2fb62913e184dc45162853cf9Daniel Dunbar/// used in preprocessor initialization to InitializePreprocessor(). 44cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenkoclass PreprocessorOptions : public RefCountedBase<PreprocessorOptions> { 45049d3a06ea9f8fc03582488a2b7f24512565a335Daniel Dunbarpublic: 46e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner std::vector<std::pair<std::string, bool/*isUndef*/> > Macros; 47b6d1cc84d1a7e314f7a7a02fbe092adc4caf67e8Daniel Dunbar std::vector<std::string> Includes; 48e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner std::vector<std::string> MacroIncludes; 49e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 50959dc8475fc20ce8c3fd55021cb9f02a531cddc5Dmitri Gribenko /// \brief Initialize the preprocessor with the compiler and target specific 51959dc8475fc20ce8c3fd55021cb9f02a531cddc5Dmitri Gribenko /// predefines. 52959dc8475fc20ce8c3fd55021cb9f02a531cddc5Dmitri Gribenko unsigned UsePredefines : 1; 53959dc8475fc20ce8c3fd55021cb9f02a531cddc5Dmitri Gribenko 54959dc8475fc20ce8c3fd55021cb9f02a531cddc5Dmitri Gribenko /// \brief Whether we should maintain a detailed record of all macro 55959dc8475fc20ce8c3fd55021cb9f02a531cddc5Dmitri Gribenko /// definitions and expansions. 56959dc8475fc20ce8c3fd55021cb9f02a531cddc5Dmitri Gribenko unsigned DetailedRecord : 1; 57468fe246192c3683360d1a6b1b333d85b8794f77Daniel Dunbar 58e0a9581d606ea1a6a723758a8d7eef93650cbe93Daniel Dunbar /// The implicit PCH included at the start of the translation unit, or empty. 59e0a9581d606ea1a6a723758a8d7eef93650cbe93Daniel Dunbar std::string ImplicitPCHInclude; 60e0a9581d606ea1a6a723758a8d7eef93650cbe93Daniel Dunbar 61b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis /// \brief Headers that will be converted to chained PCHs in memory. 62b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis std::vector<std::string> ChainedIncludes; 63b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis 64fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor /// \brief When true, disables most of the normal validation performed on 65fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor /// precompiled headers. 66fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor bool DisablePCHValidation; 67b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 68bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis /// \brief When true, a PCH with compiler errors will not be rejected. 69bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis bool AllowPCHWithCompilerErrors; 70bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis 71b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis /// \brief Dump declarations that are deserialized from PCH, for testing. 72b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis bool DumpDeserializedPCHDecls; 73b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis 743e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis /// \brief This is a set of names for decls that we do not want to be 753e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis /// deserialized, and we emit an error if they are; for testing purposes. 763e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis std::set<std::string> DeserializedPCHDeclsToErrorOn; 773e78593b1ced32b7e0a97da044213014ee0f6f7cArgyrios Kyrtzidis 78f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// \brief If non-zero, the implicit PCH include is actually a precompiled 79f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// preamble that covers this number of bytes in the main source file. 80f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// 81f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// The boolean indicates whether the preamble ends at the start of a new 82f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// line. 83f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor std::pair<unsigned, bool> PrecompiledPreambleBytes; 84f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor 85e0a9581d606ea1a6a723758a8d7eef93650cbe93Daniel Dunbar /// The implicit PTH input included at the start of the translation unit, or 86e0a9581d606ea1a6a723758a8d7eef93650cbe93Daniel Dunbar /// empty. 87e0a9581d606ea1a6a723758a8d7eef93650cbe93Daniel Dunbar std::string ImplicitPTHInclude; 88e0a9581d606ea1a6a723758a8d7eef93650cbe93Daniel Dunbar 89b3cb98ee35b4707c59d7f6d1a6ee2eee95cb7eb5Daniel Dunbar /// If given, a PTH cache file to use for speeding up header parsing. 90b3cb98ee35b4707c59d7f6d1a6ee2eee95cb7eb5Daniel Dunbar std::string TokenCache; 91b3cb98ee35b4707c59d7f6d1a6ee2eee95cb7eb5Daniel Dunbar 92299a4a967b02c9f0d0d94ad8560e3ced893f9116Argyrios Kyrtzidis /// \brief True if the SourceManager should report the original file name for 93299a4a967b02c9f0d0d94ad8560e3ced893f9116Argyrios Kyrtzidis /// contents of files that were remapped to other files. Defaults to true. 94299a4a967b02c9f0d0d94ad8560e3ced893f9116Argyrios Kyrtzidis bool RemappedFilesKeepOriginalName; 95299a4a967b02c9f0d0d94ad8560e3ced893f9116Argyrios Kyrtzidis 96716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor /// \brief The set of file remappings, which take existing files on 97716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor /// the system (the first part of each pair) and gives them the 98716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor /// contents of other files on the system (the second part of each 99716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor /// pair). 100c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines std::vector<std::pair<std::string, std::string>> RemappedFiles; 101716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor 1024db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor /// \brief The set of file-to-buffer remappings, which take existing files 1034db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor /// on the system (the first part of each pair) and gives them the contents 1044db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor /// of the specified memory buffer (the second part of each pair). 105c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers; 106c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 107f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// \brief Whether the compiler instance should retain (i.e., not free) 108f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// the buffers associated with remapped files. 109f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// 110f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// This flag defaults to false; it can be set true only through direct 111f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// manipulation of the compiler invocation object, in cases where the 112f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// compiler invocation and its buffers will be reused. 113f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor bool RetainRemappedFileBuffers; 114f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor 115f85e193739c953358c865005855253af4f68a497John McCall /// \brief The Objective-C++ ARC standard library that we should support, 116f85e193739c953358c865005855253af4f68a497John McCall /// by providing appropriate definitions to retrofit the standard library 117f85e193739c953358c865005855253af4f68a497John McCall /// with support for lifetime-qualified pointers. 118f85e193739c953358c865005855253af4f68a497John McCall ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary; 1194ebd45f4279d84416568ada6adf56044bdf391b7Douglas Gregor 120463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor /// \brief Records the set of modules 121cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko class FailedModulesSet : public RefCountedBase<FailedModulesSet> { 122463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor llvm::StringSet<> Failed; 123463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor 124463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor public: 125463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor bool hasAlreadyFailed(StringRef module) { 126463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor return Failed.count(module) > 0; 127463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor } 128463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor 129463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor void addFailed(StringRef module) { 130463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor Failed.insert(module); 131463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor } 132463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor }; 133f85e193739c953358c865005855253af4f68a497John McCall 134463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor /// \brief The set of modules that failed to build. 135463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor /// 136463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor /// This pointer will be shared among all of the compiler instances created 137463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor /// to (re)build modules, so that once a module fails to build anywhere, 138463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor /// other instances will see that the module has failed and won't try to 139463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor /// build it again. 140cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko IntrusiveRefCntPtr<FailedModulesSet> FailedModules; 141463d90986ec54c62bf8fe31193ef5db701db48a5Douglas Gregor 142e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattnerpublic: 143f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor PreprocessorOptions() : UsePredefines(true), DetailedRecord(false), 1444182ed686283b72736b287cbe28583cb641f8934Argyrios Kyrtzidis DisablePCHValidation(false), 145bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis AllowPCHWithCompilerErrors(false), 146b972858068d2ea77f72a1e7b1812b196afd6be2eArgyrios Kyrtzidis DumpDeserializedPCHDecls(false), 147f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor PrecompiledPreambleBytes(0, true), 148299a4a967b02c9f0d0d94ad8560e3ced893f9116Argyrios Kyrtzidis RemappedFilesKeepOriginalName(true), 149f85e193739c953358c865005855253af4f68a497John McCall RetainRemappedFileBuffers(false), 150f85e193739c953358c865005855253af4f68a497John McCall ObjCXXARCStandardLibrary(ARCXX_nolib) { } 151468fe246192c3683360d1a6b1b333d85b8794f77Daniel Dunbar 152686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void addMacroDef(StringRef Name) { 153e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner Macros.push_back(std::make_pair(Name, false)); 154e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner } 155686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void addMacroUndef(StringRef Name) { 156e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner Macros.push_back(std::make_pair(Name, true)); 157e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner } 158686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void addRemappedFile(StringRef From, StringRef To) { 159716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor RemappedFiles.push_back(std::make_pair(From, To)); 160716f0b3e2e36f362b64a2ce0a40a9ad915103255Douglas Gregor } 161c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 162c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) { 1634db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor RemappedFileBuffers.push_back(std::make_pair(From, To)); 1644db64a461cb3442934afe43c83ed3f17f7c11c1dDouglas Gregor } 165c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 166abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor void clearRemappedFiles() { 167abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor RemappedFiles.clear(); 168abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor RemappedFileBuffers.clear(); 169abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor } 1701c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor 1711c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor /// \brief Reset any options that are not considered when building a 1721c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor /// module. 1731c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor void resetNonModularOptions() { 1746e975c4517958bcc11c834336d340797356058dbDouglas Gregor Includes.clear(); 1751c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor MacroIncludes.clear(); 1766e975c4517958bcc11c834336d340797356058dbDouglas Gregor ChainedIncludes.clear(); 1771c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor DumpDeserializedPCHDecls = false; 1786e975c4517958bcc11c834336d340797356058dbDouglas Gregor ImplicitPCHInclude.clear(); 1796e975c4517958bcc11c834336d340797356058dbDouglas Gregor ImplicitPTHInclude.clear(); 1801c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor TokenCache.clear(); 1811c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor RetainRemappedFileBuffers = true; 1826e975c4517958bcc11c834336d340797356058dbDouglas Gregor PrecompiledPreambleBytes.first = 0; 1836e975c4517958bcc11c834336d340797356058dbDouglas Gregor PrecompiledPreambleBytes.second = 0; 1841c7e0472f5683a8ade62285f366637050cf113e5Douglas Gregor } 185e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner}; 186e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 187e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner} // end namespace clang 188e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner 189e116ccf140b813ecd20e3fb4041d7d0b8a967c0bChris Lattner#endif 190