1 //===--- PreprocessorOptions.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
11 #define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
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"
33 /// \brief Enumerate the kinds of standard library that
34 enum ObjCXXARCStandardLibraryKind {
42 /// PreprocessorOptions - This class is used for passing the various options
43 /// used in preprocessor initialization to InitializePreprocessor().
44 class PreprocessorOptions : public RefCountedBase<PreprocessorOptions> {
46 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
47 std::vector<std::string> Includes;
48 std::vector<std::string> MacroIncludes;
50 /// \brief Initialize the preprocessor with the compiler and target specific
52 unsigned UsePredefines : 1;
54 /// \brief Whether we should maintain a detailed record of all macro
55 /// definitions and expansions.
56 unsigned DetailedRecord : 1;
58 /// The implicit PCH included at the start of the translation unit, or empty.
59 std::string ImplicitPCHInclude;
61 /// \brief Headers that will be converted to chained PCHs in memory.
62 std::vector<std::string> ChainedIncludes;
64 /// \brief When true, disables most of the normal validation performed on
65 /// precompiled headers.
66 bool DisablePCHValidation;
68 /// \brief When true, a PCH with compiler errors will not be rejected.
69 bool AllowPCHWithCompilerErrors;
71 /// \brief Dump declarations that are deserialized from PCH, for testing.
72 bool DumpDeserializedPCHDecls;
74 /// \brief This is a set of names for decls that we do not want to be
75 /// deserialized, and we emit an error if they are; for testing purposes.
76 std::set<std::string> DeserializedPCHDeclsToErrorOn;
78 /// \brief If non-zero, the implicit PCH include is actually a precompiled
79 /// preamble that covers this number of bytes in the main source file.
81 /// The boolean indicates whether the preamble ends at the start of a new
83 std::pair<unsigned, bool> PrecompiledPreambleBytes;
85 /// The implicit PTH input included at the start of the translation unit, or
87 std::string ImplicitPTHInclude;
89 /// If given, a PTH cache file to use for speeding up header parsing.
90 std::string TokenCache;
92 /// \brief True if the SourceManager should report the original file name for
93 /// contents of files that were remapped to other files. Defaults to true.
94 bool RemappedFilesKeepOriginalName;
96 /// \brief The set of file remappings, which take existing files on
97 /// the system (the first part of each pair) and gives them the
98 /// contents of other files on the system (the second part of each
100 std::vector<std::pair<std::string, std::string>> RemappedFiles;
102 /// \brief The set of file-to-buffer remappings, which take existing files
103 /// on the system (the first part of each pair) and gives them the contents
104 /// of the specified memory buffer (the second part of each pair).
105 std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers;
107 /// \brief Whether the compiler instance should retain (i.e., not free)
108 /// the buffers associated with remapped files.
110 /// This flag defaults to false; it can be set true only through direct
111 /// manipulation of the compiler invocation object, in cases where the
112 /// compiler invocation and its buffers will be reused.
113 bool RetainRemappedFileBuffers;
115 /// \brief The Objective-C++ ARC standard library that we should support,
116 /// by providing appropriate definitions to retrofit the standard library
117 /// with support for lifetime-qualified pointers.
118 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
120 /// \brief Records the set of modules
121 class FailedModulesSet : public RefCountedBase<FailedModulesSet> {
122 llvm::StringSet<> Failed;
125 bool hasAlreadyFailed(StringRef module) {
126 return Failed.count(module) > 0;
129 void addFailed(StringRef module) {
130 Failed.insert(module);
134 /// \brief The set of modules that failed to build.
136 /// This pointer will be shared among all of the compiler instances created
137 /// to (re)build modules, so that once a module fails to build anywhere,
138 /// other instances will see that the module has failed and won't try to
140 IntrusiveRefCntPtr<FailedModulesSet> FailedModules;
143 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
144 DisablePCHValidation(false),
145 AllowPCHWithCompilerErrors(false),
146 DumpDeserializedPCHDecls(false),
147 PrecompiledPreambleBytes(0, true),
148 RemappedFilesKeepOriginalName(true),
149 RetainRemappedFileBuffers(false),
150 ObjCXXARCStandardLibrary(ARCXX_nolib) { }
152 void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); }
153 void addMacroUndef(StringRef Name) { Macros.emplace_back(Name, true); }
154 void addRemappedFile(StringRef From, StringRef To) {
155 RemappedFiles.emplace_back(From, To);
158 void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) {
159 RemappedFileBuffers.emplace_back(From, To);
162 void clearRemappedFiles() {
163 RemappedFiles.clear();
164 RemappedFileBuffers.clear();
167 /// \brief Reset any options that are not considered when building a
169 void resetNonModularOptions() {
171 MacroIncludes.clear();
172 ChainedIncludes.clear();
173 DumpDeserializedPCHDecls = false;
174 ImplicitPCHInclude.clear();
175 ImplicitPTHInclude.clear();
177 RetainRemappedFileBuffers = true;
178 PrecompiledPreambleBytes.first = 0;
179 PrecompiledPreambleBytes.second = 0;
183 } // end namespace clang