]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Lex/PreprocessorOptions.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Lex / PreprocessorOptions.h
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/LLVM.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/StringSet.h"
16 #include <memory>
17 #include <set>
18 #include <string>
19 #include <utility>
20 #include <vector>
21
22 namespace llvm {
23
24 class MemoryBuffer;
25
26 } // namespace llvm
27
28 namespace clang {
29
30 /// Enumerate the kinds of standard library that
31 enum ObjCXXARCStandardLibraryKind {
32   ARCXX_nolib,
33
34   /// libc++
35   ARCXX_libcxx,
36
37   /// 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   /// Initialize the preprocessor with the compiler and target specific
50   /// predefines.
51   bool UsePredefines = true;
52
53   /// Whether we should maintain a detailed record of all macro
54   /// definitions and expansions.
55   bool DetailedRecord = false;
56
57   /// If non-empty, the filename used in an #include directive in the primary
58   /// source file (or command-line preinclude) that is used to implement
59   /// MSVC-style precompiled headers. When creating a PCH, after the #include
60   /// of this header, the PCH generation stops. When using a PCH, tokens are
61   /// skipped until after an #include of this header is seen.
62   std::string PCHThroughHeader;
63
64   /// The implicit PCH included at the start of the translation unit, or empty.
65   std::string ImplicitPCHInclude;
66
67   /// Headers that will be converted to chained PCHs in memory.
68   std::vector<std::string> ChainedIncludes;
69
70   /// When true, disables most of the normal validation performed on
71   /// precompiled headers.
72   bool DisablePCHValidation = false;
73
74   /// When true, a PCH with compiler errors will not be rejected.
75   bool AllowPCHWithCompilerErrors = false;
76
77   /// Dump declarations that are deserialized from PCH, for testing.
78   bool DumpDeserializedPCHDecls = false;
79
80   /// This is a set of names for decls that we do not want to be
81   /// deserialized, and we emit an error if they are; for testing purposes.
82   std::set<std::string> DeserializedPCHDeclsToErrorOn;
83
84   /// If non-zero, the implicit PCH include is actually a precompiled
85   /// preamble that covers this number of bytes in the main source file.
86   ///
87   /// The boolean indicates whether the preamble ends at the start of a new
88   /// line.
89   std::pair<unsigned, bool> PrecompiledPreambleBytes;
90
91   /// True indicates that a preamble is being generated.
92   ///
93   /// When the lexer is done, one of the things that need to be preserved is the
94   /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when
95   /// processing the rest of the file.
96   bool GeneratePreamble = false;
97
98   /// Whether to write comment locations into the PCH when building it.
99   /// Reading the comments from the PCH can be a performance hit even if the
100   /// clients don't use them.
101   bool WriteCommentListToPCH = true;
102
103   /// The implicit PTH input included at the start of the translation unit, or
104   /// empty.
105   std::string ImplicitPTHInclude;
106
107   /// If given, a PTH cache file to use for speeding up header parsing.
108   std::string TokenCache;
109
110   /// When enabled, preprocessor is in a mode for parsing a single file only.
111   ///
112   /// Disables #includes of other files and if there are unresolved identifiers
113   /// in preprocessor directive conditions it causes all blocks to be parsed so
114   /// that the client can get the maximum amount of information from the parser.
115   bool SingleFileParseMode = false;
116
117   /// When enabled, the preprocessor will construct editor placeholder tokens.
118   bool LexEditorPlaceholders = true;
119
120   /// True if the SourceManager should report the original file name for
121   /// contents of files that were remapped to other files. Defaults to true.
122   bool RemappedFilesKeepOriginalName = true;
123
124   /// The set of file remappings, which take existing files on
125   /// the system (the first part of each pair) and gives them the
126   /// contents of other files on the system (the second part of each
127   /// pair).
128   std::vector<std::pair<std::string, std::string>> RemappedFiles;
129
130   /// The set of file-to-buffer remappings, which take existing files
131   /// on the system (the first part of each pair) and gives them the contents
132   /// of the specified memory buffer (the second part of each pair).
133   std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers;
134
135   /// Whether the compiler instance should retain (i.e., not free)
136   /// the buffers associated with remapped files.
137   ///
138   /// This flag defaults to false; it can be set true only through direct
139   /// manipulation of the compiler invocation object, in cases where the
140   /// compiler invocation and its buffers will be reused.
141   bool RetainRemappedFileBuffers = false;
142
143   /// The Objective-C++ ARC standard library that we should support,
144   /// by providing appropriate definitions to retrofit the standard library
145   /// with support for lifetime-qualified pointers.
146   ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary = ARCXX_nolib;
147
148   /// Records the set of modules
149   class FailedModulesSet {
150     llvm::StringSet<> Failed;
151
152   public:
153     bool hasAlreadyFailed(StringRef module) {
154       return Failed.count(module) > 0;
155     }
156
157     void addFailed(StringRef module) {
158       Failed.insert(module);
159     }
160   };
161
162   /// The set of modules that failed to build.
163   ///
164   /// This pointer will be shared among all of the compiler instances created
165   /// to (re)build modules, so that once a module fails to build anywhere,
166   /// other instances will see that the module has failed and won't try to
167   /// build it again.
168   std::shared_ptr<FailedModulesSet> FailedModules;
169
170 public:
171   PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
172
173   void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); }
174   void addMacroUndef(StringRef Name) { Macros.emplace_back(Name, true); }
175
176   void addRemappedFile(StringRef From, StringRef To) {
177     RemappedFiles.emplace_back(From, To);
178   }
179
180   void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) {
181     RemappedFileBuffers.emplace_back(From, To);
182   }
183
184   void clearRemappedFiles() {
185     RemappedFiles.clear();
186     RemappedFileBuffers.clear();
187   }
188
189   /// Reset any options that are not considered when building a
190   /// module.
191   void resetNonModularOptions() {
192     Includes.clear();
193     MacroIncludes.clear();
194     ChainedIncludes.clear();
195     DumpDeserializedPCHDecls = false;
196     ImplicitPCHInclude.clear();
197     ImplicitPTHInclude.clear();
198     TokenCache.clear();
199     SingleFileParseMode = false;
200     LexEditorPlaceholders = true;
201     RetainRemappedFileBuffers = true;
202     PrecompiledPreambleBytes.first = 0;
203     PrecompiledPreambleBytes.second = false;
204   }
205 };
206
207 } // namespace clang
208
209 #endif // LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_