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/StringRef.h"
16 #include "llvm/ADT/StringSet.h"
32 /// \brief Enumerate the kinds of standard library that
33 enum ObjCXXARCStandardLibraryKind {
41 /// PreprocessorOptions - This class is used for passing the various options
42 /// used in preprocessor initialization to InitializePreprocessor().
43 class PreprocessorOptions {
45 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
46 std::vector<std::string> Includes;
47 std::vector<std::string> MacroIncludes;
49 /// \brief Initialize the preprocessor with the compiler and target specific
51 unsigned UsePredefines : 1;
53 /// \brief Whether we should maintain a detailed record of all macro
54 /// definitions and expansions.
55 unsigned DetailedRecord : 1;
57 /// The implicit PCH included at the start of the translation unit, or empty.
58 std::string ImplicitPCHInclude;
60 /// \brief Headers that will be converted to chained PCHs in memory.
61 std::vector<std::string> ChainedIncludes;
63 /// \brief When true, disables most of the normal validation performed on
64 /// precompiled headers.
65 bool DisablePCHValidation;
67 /// \brief When true, a PCH with compiler errors will not be rejected.
68 bool AllowPCHWithCompilerErrors;
70 /// \brief Dump declarations that are deserialized from PCH, for testing.
71 bool DumpDeserializedPCHDecls;
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;
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.
80 /// The boolean indicates whether the preamble ends at the start of a new
82 std::pair<unsigned, bool> PrecompiledPreambleBytes;
84 /// The implicit PTH input included at the start of the translation unit, or
86 std::string ImplicitPTHInclude;
88 /// If given, a PTH cache file to use for speeding up header parsing.
89 std::string TokenCache;
91 /// \brief True if the SourceManager should report the original file name for
92 /// contents of files that were remapped to other files. Defaults to true.
93 bool RemappedFilesKeepOriginalName;
95 /// \brief The set of file remappings, which take existing files on
96 /// the system (the first part of each pair) and gives them the
97 /// contents of other files on the system (the second part of each
99 std::vector<std::pair<std::string, std::string>> RemappedFiles;
101 /// \brief The set of file-to-buffer remappings, which take existing files
102 /// on the system (the first part of each pair) and gives them the contents
103 /// of the specified memory buffer (the second part of each pair).
104 std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers;
106 /// \brief Whether the compiler instance should retain (i.e., not free)
107 /// the buffers associated with remapped files.
109 /// This flag defaults to false; it can be set true only through direct
110 /// manipulation of the compiler invocation object, in cases where the
111 /// compiler invocation and its buffers will be reused.
112 bool RetainRemappedFileBuffers;
114 /// \brief The Objective-C++ ARC standard library that we should support,
115 /// by providing appropriate definitions to retrofit the standard library
116 /// with support for lifetime-qualified pointers.
117 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
119 /// \brief Records the set of modules
120 class FailedModulesSet {
121 llvm::StringSet<> Failed;
124 bool hasAlreadyFailed(StringRef module) {
125 return Failed.count(module) > 0;
128 void addFailed(StringRef module) {
129 Failed.insert(module);
133 /// \brief The set of modules that failed to build.
135 /// This pointer will be shared among all of the compiler instances created
136 /// to (re)build modules, so that once a module fails to build anywhere,
137 /// other instances will see that the module has failed and won't try to
139 std::shared_ptr<FailedModulesSet> FailedModules;
142 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
143 DisablePCHValidation(false),
144 AllowPCHWithCompilerErrors(false),
145 DumpDeserializedPCHDecls(false),
146 PrecompiledPreambleBytes(0, true),
147 RemappedFilesKeepOriginalName(true),
148 RetainRemappedFileBuffers(false),
149 ObjCXXARCStandardLibrary(ARCXX_nolib) { }
151 void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); }
152 void addMacroUndef(StringRef Name) { Macros.emplace_back(Name, true); }
153 void addRemappedFile(StringRef From, StringRef To) {
154 RemappedFiles.emplace_back(From, To);
157 void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) {
158 RemappedFileBuffers.emplace_back(From, To);
161 void clearRemappedFiles() {
162 RemappedFiles.clear();
163 RemappedFileBuffers.clear();
166 /// \brief Reset any options that are not considered when building a
168 void resetNonModularOptions() {
170 MacroIncludes.clear();
171 ChainedIncludes.clear();
172 DumpDeserializedPCHDecls = false;
173 ImplicitPCHInclude.clear();
174 ImplicitPTHInclude.clear();
176 RetainRemappedFileBuffers = true;
177 PrecompiledPreambleBytes.first = 0;
178 PrecompiledPreambleBytes.second = 0;
182 } // end namespace clang