/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Frontend/FrontendOptions.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- FrontendOptions.h ----------------------------------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H |
10 | | #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H |
11 | | |
12 | | #include "clang/AST/ASTDumperUtils.h" |
13 | | #include "clang/Frontend/CommandLineSourceLoc.h" |
14 | | #include "clang/Serialization/ModuleFileExtension.h" |
15 | | #include "clang/Sema/CodeCompleteOptions.h" |
16 | | #include "llvm/ADT/StringRef.h" |
17 | | #include <cassert> |
18 | | #include <memory> |
19 | | #include <string> |
20 | | #include <vector> |
21 | | #include <unordered_map> |
22 | | |
23 | | namespace llvm { |
24 | | |
25 | | class MemoryBuffer; |
26 | | |
27 | | } // namespace llvm |
28 | | |
29 | | namespace clang { |
30 | | |
31 | | namespace frontend { |
32 | | |
33 | | enum ActionKind { |
34 | | /// Parse ASTs and list Decl nodes. |
35 | | ASTDeclList, |
36 | | |
37 | | /// Parse ASTs and dump them. |
38 | | ASTDump, |
39 | | |
40 | | /// Parse ASTs and print them. |
41 | | ASTPrint, |
42 | | |
43 | | /// Parse ASTs and view them in Graphviz. |
44 | | ASTView, |
45 | | |
46 | | /// Dump the compiler configuration. |
47 | | DumpCompilerOptions, |
48 | | |
49 | | /// Dump out raw tokens. |
50 | | DumpRawTokens, |
51 | | |
52 | | /// Dump out preprocessed tokens. |
53 | | DumpTokens, |
54 | | |
55 | | /// Emit a .s file. |
56 | | EmitAssembly, |
57 | | |
58 | | /// Emit a .bc file. |
59 | | EmitBC, |
60 | | |
61 | | /// Translate input source into HTML. |
62 | | EmitHTML, |
63 | | |
64 | | /// Emit a .ll file. |
65 | | EmitLLVM, |
66 | | |
67 | | /// Generate LLVM IR, but do not emit anything. |
68 | | EmitLLVMOnly, |
69 | | |
70 | | /// Generate machine code, but don't emit anything. |
71 | | EmitCodeGenOnly, |
72 | | |
73 | | /// Emit a .o file. |
74 | | EmitObj, |
75 | | |
76 | | /// Parse and apply any fixits to the source. |
77 | | FixIt, |
78 | | |
79 | | /// Generate pre-compiled module from a module map. |
80 | | GenerateModule, |
81 | | |
82 | | /// Generate pre-compiled module from a C++ module interface file. |
83 | | GenerateModuleInterface, |
84 | | |
85 | | /// Generate pre-compiled module from a set of header files. |
86 | | GenerateHeaderModule, |
87 | | |
88 | | /// Generate pre-compiled header. |
89 | | GeneratePCH, |
90 | | |
91 | | /// Generate Interface Stub Files. |
92 | | GenerateInterfaceYAMLExpV1, |
93 | | GenerateInterfaceTBEExpV1, |
94 | | |
95 | | /// Only execute frontend initialization. |
96 | | InitOnly, |
97 | | |
98 | | /// Dump information about a module file. |
99 | | ModuleFileInfo, |
100 | | |
101 | | /// Load and verify that a PCH file is usable. |
102 | | VerifyPCH, |
103 | | |
104 | | /// Parse and perform semantic analysis. |
105 | | ParseSyntaxOnly, |
106 | | |
107 | | /// Run a plugin action, \see ActionName. |
108 | | PluginAction, |
109 | | |
110 | | /// Print the "preamble" of the input file |
111 | | PrintPreamble, |
112 | | |
113 | | /// -E mode. |
114 | | PrintPreprocessedInput, |
115 | | |
116 | | /// Expand macros but not \#includes. |
117 | | RewriteMacros, |
118 | | |
119 | | /// ObjC->C Rewriter. |
120 | | RewriteObjC, |
121 | | |
122 | | /// Rewriter playground |
123 | | RewriteTest, |
124 | | |
125 | | /// Run one or more source code analyses. |
126 | | RunAnalysis, |
127 | | |
128 | | /// Dump template instantiations |
129 | | TemplightDump, |
130 | | |
131 | | /// Run migrator. |
132 | | MigrateSource, |
133 | | |
134 | | /// Just lex, no output. |
135 | | RunPreprocessorOnly, |
136 | | |
137 | | /// Print the output of the dependency directives source minimizer. |
138 | | PrintDependencyDirectivesSourceMinimizerOutput |
139 | | }; |
140 | | |
141 | | } // namespace frontend |
142 | | |
143 | | /// The kind of a file that we've been handed as an input. |
144 | | class InputKind { |
145 | | private: |
146 | | unsigned Lang : 4; |
147 | | unsigned Fmt : 3; |
148 | | unsigned Preprocessed : 1; |
149 | | |
150 | | public: |
151 | | /// The language for the input, used to select and validate the language |
152 | | /// standard and possible actions. |
153 | | enum Language { |
154 | | Unknown, |
155 | | |
156 | | /// Assembly: we accept this only so that we can preprocess it. |
157 | | Asm, |
158 | | |
159 | | /// LLVM IR: we accept this so that we can run the optimizer on it, |
160 | | /// and compile it to assembly or object code. |
161 | | LLVM_IR, |
162 | | |
163 | | ///@{ Languages that the frontend can parse and compile. |
164 | | C, |
165 | | CXX, |
166 | | ObjC, |
167 | | ObjCXX, |
168 | | OpenCL, |
169 | | CUDA, |
170 | | RenderScript, |
171 | | HIP, |
172 | | ///@} |
173 | | }; |
174 | | |
175 | | /// The input file format. |
176 | | enum Format { |
177 | | Source, |
178 | | ModuleMap, |
179 | | Precompiled |
180 | | }; |
181 | | |
182 | | constexpr InputKind(Language L = Unknown, Format F = Source, |
183 | | bool PP = false) |
184 | 883k | : Lang(L), Fmt(F), Preprocessed(PP) {} |
185 | | |
186 | 523k | Language getLanguage() const { return static_cast<Language>(Lang); } |
187 | 351k | Format getFormat() const { return static_cast<Format>(Fmt); } |
188 | 73.3k | bool isPreprocessed() const { return Preprocessed; } |
189 | | |
190 | | /// Is the input kind fully-unknown? |
191 | 149k | bool isUnknown() const { return Lang == Unknown && Fmt == Source26.7k ; } |
192 | | |
193 | | /// Is the language of the input some dialect of Objective-C? |
194 | 40.4k | bool isObjectiveC() const { return Lang == ObjC || Lang == ObjCXX37.7k ; } |
195 | | |
196 | 115k | InputKind getPreprocessed() const { |
197 | 115k | return InputKind(getLanguage(), getFormat(), true); |
198 | 115k | } |
199 | | |
200 | 202 | InputKind withFormat(Format F) const { |
201 | 202 | return InputKind(getLanguage(), F, isPreprocessed()); |
202 | 202 | } |
203 | | }; |
204 | | |
205 | | /// An input file for the front end. |
206 | | class FrontendInputFile { |
207 | | /// The file name, or "-" to read from standard input. |
208 | | std::string File; |
209 | | |
210 | | /// The input, if it comes from a buffer rather than a file. This object |
211 | | /// does not own the buffer, and the caller is responsible for ensuring |
212 | | /// that it outlives any users. |
213 | | const llvm::MemoryBuffer *Buffer = nullptr; |
214 | | |
215 | | /// The kind of input, e.g., C source, AST file, LLVM IR. |
216 | | InputKind Kind; |
217 | | |
218 | | /// Whether we're dealing with a 'system' input (vs. a 'user' input). |
219 | | bool IsSystem = false; |
220 | | |
221 | | public: |
222 | 100k | FrontendInputFile() = default; |
223 | | FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) |
224 | 46.8k | : File(File.str()), Kind(Kind), IsSystem(IsSystem) {} |
225 | | FrontendInputFile(const llvm::MemoryBuffer *Buffer, InputKind Kind, |
226 | | bool IsSystem = false) |
227 | 8 | : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {} |
228 | | |
229 | 260k | InputKind getKind() const { return Kind; } |
230 | 49.6k | bool isSystem() const { return IsSystem; } |
231 | | |
232 | 0 | bool isEmpty() const { return File.empty() && Buffer == nullptr; } |
233 | 49.3k | bool isFile() const { return !isBuffer(); } |
234 | 97.4k | bool isBuffer() const { return Buffer != nullptr; } |
235 | 42.7k | bool isPreprocessed() const { return Kind.isPreprocessed(); } |
236 | | |
237 | 110k | StringRef getFile() const { |
238 | 110k | assert(isFile()); |
239 | 110k | return File; |
240 | 110k | } |
241 | | |
242 | 16 | const llvm::MemoryBuffer *getBuffer() const { |
243 | 16 | assert(isBuffer()); |
244 | 16 | return Buffer; |
245 | 16 | } |
246 | | }; |
247 | | |
248 | | /// FrontendOptions - Options for controlling the behavior of the frontend. |
249 | | class FrontendOptions { |
250 | | public: |
251 | | /// Disable memory freeing on exit. |
252 | | unsigned DisableFree : 1; |
253 | | |
254 | | /// When generating PCH files, instruct the AST writer to create relocatable |
255 | | /// PCH files. |
256 | | unsigned RelocatablePCH : 1; |
257 | | |
258 | | /// Show the -help text. |
259 | | unsigned ShowHelp : 1; |
260 | | |
261 | | /// Show frontend performance metrics and statistics. |
262 | | unsigned ShowStats : 1; |
263 | | |
264 | | /// Show timers for individual actions. |
265 | | unsigned ShowTimers : 1; |
266 | | |
267 | | /// print the supported cpus for the current target |
268 | | unsigned PrintSupportedCPUs : 1; |
269 | | |
270 | | /// Output time trace profile. |
271 | | unsigned TimeTrace : 1; |
272 | | |
273 | | /// Show the -version text. |
274 | | unsigned ShowVersion : 1; |
275 | | |
276 | | /// Apply fixes even if there are unfixable errors. |
277 | | unsigned FixWhatYouCan : 1; |
278 | | |
279 | | /// Apply fixes only for warnings. |
280 | | unsigned FixOnlyWarnings : 1; |
281 | | |
282 | | /// Apply fixes and recompile. |
283 | | unsigned FixAndRecompile : 1; |
284 | | |
285 | | /// Apply fixes to temporary files. |
286 | | unsigned FixToTemporaries : 1; |
287 | | |
288 | | /// Emit ARC errors even if the migrator can fix them. |
289 | | unsigned ARCMTMigrateEmitARCErrors : 1; |
290 | | |
291 | | /// Skip over function bodies to speed up parsing in cases you do not need |
292 | | /// them (e.g. with code completion). |
293 | | unsigned SkipFunctionBodies : 1; |
294 | | |
295 | | /// Whether we can use the global module index if available. |
296 | | unsigned UseGlobalModuleIndex : 1; |
297 | | |
298 | | /// Whether we can generate the global module index if needed. |
299 | | unsigned GenerateGlobalModuleIndex : 1; |
300 | | |
301 | | /// Whether we include declaration dumps in AST dumps. |
302 | | unsigned ASTDumpDecls : 1; |
303 | | |
304 | | /// Whether we deserialize all decls when forming AST dumps. |
305 | | unsigned ASTDumpAll : 1; |
306 | | |
307 | | /// Whether we include lookup table dumps in AST dumps. |
308 | | unsigned ASTDumpLookups : 1; |
309 | | |
310 | | /// Whether we are performing an implicit module build. |
311 | | unsigned BuildingImplicitModule : 1; |
312 | | |
313 | | /// Whether we should embed all used files into the PCM file. |
314 | | unsigned ModulesEmbedAllFiles : 1; |
315 | | |
316 | | /// Whether timestamps should be written to the produced PCH file. |
317 | | unsigned IncludeTimestamps : 1; |
318 | | |
319 | | CodeCompleteOptions CodeCompleteOpts; |
320 | | |
321 | | /// Specifies the output format of the AST. |
322 | | ASTDumpOutputFormat ASTDumpFormat = ADOF_Default; |
323 | | |
324 | | enum { |
325 | | ARCMT_None, |
326 | | ARCMT_Check, |
327 | | ARCMT_Modify, |
328 | | ARCMT_Migrate |
329 | | } ARCMTAction = ARCMT_None; |
330 | | |
331 | | enum { |
332 | | ObjCMT_None = 0, |
333 | | |
334 | | /// Enable migration to modern ObjC literals. |
335 | | ObjCMT_Literals = 0x1, |
336 | | |
337 | | /// Enable migration to modern ObjC subscripting. |
338 | | ObjCMT_Subscripting = 0x2, |
339 | | |
340 | | /// Enable migration to modern ObjC readonly property. |
341 | | ObjCMT_ReadonlyProperty = 0x4, |
342 | | |
343 | | /// Enable migration to modern ObjC readwrite property. |
344 | | ObjCMT_ReadwriteProperty = 0x8, |
345 | | |
346 | | /// Enable migration to modern ObjC property. |
347 | | ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty), |
348 | | |
349 | | /// Enable annotation of ObjCMethods of all kinds. |
350 | | ObjCMT_Annotation = 0x10, |
351 | | |
352 | | /// Enable migration of ObjC methods to 'instancetype'. |
353 | | ObjCMT_Instancetype = 0x20, |
354 | | |
355 | | /// Enable migration to NS_ENUM/NS_OPTIONS macros. |
356 | | ObjCMT_NsMacros = 0x40, |
357 | | |
358 | | /// Enable migration to add conforming protocols. |
359 | | ObjCMT_ProtocolConformance = 0x80, |
360 | | |
361 | | /// prefer 'atomic' property over 'nonatomic'. |
362 | | ObjCMT_AtomicProperty = 0x100, |
363 | | |
364 | | /// annotate property with NS_RETURNS_INNER_POINTER |
365 | | ObjCMT_ReturnsInnerPointerProperty = 0x200, |
366 | | |
367 | | /// use NS_NONATOMIC_IOSONLY for property 'atomic' attribute |
368 | | ObjCMT_NsAtomicIOSOnlyProperty = 0x400, |
369 | | |
370 | | /// Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods. |
371 | | ObjCMT_DesignatedInitializer = 0x800, |
372 | | |
373 | | /// Enable converting setter/getter expressions to property-dot syntx. |
374 | | ObjCMT_PropertyDotSyntax = 0x1000, |
375 | | |
376 | | ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | |
377 | | ObjCMT_Annotation | ObjCMT_Instancetype | |
378 | | ObjCMT_NsMacros | ObjCMT_ProtocolConformance | |
379 | | ObjCMT_NsAtomicIOSOnlyProperty | |
380 | | ObjCMT_DesignatedInitializer), |
381 | | ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | |
382 | | ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax) |
383 | | }; |
384 | | unsigned ObjCMTAction = ObjCMT_None; |
385 | | std::string ObjCMTWhiteListPath; |
386 | | |
387 | | std::string MTMigrateDir; |
388 | | std::string ARCMTMigrateReportOut; |
389 | | |
390 | | /// The input files and their types. |
391 | | std::vector<FrontendInputFile> Inputs; |
392 | | |
393 | | /// When the input is a module map, the original module map file from which |
394 | | /// that map was inferred, if any (for umbrella modules). |
395 | | std::string OriginalModuleMap; |
396 | | |
397 | | /// The output file, if any. |
398 | | std::string OutputFile; |
399 | | |
400 | | /// If given, the new suffix for fix-it rewritten files. |
401 | | std::string FixItSuffix; |
402 | | |
403 | | /// If given, filter dumped AST Decl nodes by this substring. |
404 | | std::string ASTDumpFilter; |
405 | | |
406 | | /// If given, enable code completion at the provided location. |
407 | | ParsedSourceLocation CodeCompletionAt; |
408 | | |
409 | | /// The frontend action to perform. |
410 | | frontend::ActionKind ProgramAction = frontend::ParseSyntaxOnly; |
411 | | |
412 | | /// The name of the action to run when using a plugin action. |
413 | | std::string ActionName; |
414 | | |
415 | | /// Args to pass to the plugins |
416 | | std::unordered_map<std::string,std::vector<std::string>> PluginArgs; |
417 | | |
418 | | /// The list of plugin actions to run in addition to the normal action. |
419 | | std::vector<std::string> AddPluginActions; |
420 | | |
421 | | /// The list of plugins to load. |
422 | | std::vector<std::string> Plugins; |
423 | | |
424 | | /// The list of module file extensions. |
425 | | std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions; |
426 | | |
427 | | /// The list of module map files to load before processing the input. |
428 | | std::vector<std::string> ModuleMapFiles; |
429 | | |
430 | | /// The list of additional prebuilt module files to load before |
431 | | /// processing the input. |
432 | | std::vector<std::string> ModuleFiles; |
433 | | |
434 | | /// The list of files to embed into the compiled module file. |
435 | | std::vector<std::string> ModulesEmbedFiles; |
436 | | |
437 | | /// The list of AST files to merge. |
438 | | std::vector<std::string> ASTMergeFiles; |
439 | | |
440 | | /// A list of arguments to forward to LLVM's option processing; this |
441 | | /// should only be used for debugging and experimental features. |
442 | | std::vector<std::string> LLVMArgs; |
443 | | |
444 | | /// File name of the file that will provide record layouts |
445 | | /// (in the format produced by -fdump-record-layouts). |
446 | | std::string OverrideRecordLayoutsFile; |
447 | | |
448 | | /// Auxiliary triple for CUDA compilation. |
449 | | std::string AuxTriple; |
450 | | |
451 | | /// Filename to write statistics to. |
452 | | std::string StatsFile; |
453 | | |
454 | | public: |
455 | | FrontendOptions() |
456 | | : DisableFree(false), RelocatablePCH(false), ShowHelp(false), |
457 | | ShowStats(false), ShowTimers(false), TimeTrace(false), |
458 | | ShowVersion(false), FixWhatYouCan(false), FixOnlyWarnings(false), |
459 | | FixAndRecompile(false), FixToTemporaries(false), |
460 | | ARCMTMigrateEmitARCErrors(false), SkipFunctionBodies(false), |
461 | | UseGlobalModuleIndex(true), GenerateGlobalModuleIndex(true), |
462 | | ASTDumpDecls(false), ASTDumpLookups(false), |
463 | | BuildingImplicitModule(false), ModulesEmbedAllFiles(false), |
464 | 56.7k | IncludeTimestamps(true) {} |
465 | | |
466 | | /// getInputKindForExtension - Return the appropriate input kind for a file |
467 | | /// extension. For example, "c" would return InputKind::C. |
468 | | /// |
469 | | /// \return The input kind for the extension, or InputKind::Unknown if the |
470 | | /// extension is not recognized. |
471 | | static InputKind getInputKindForExtension(StringRef Extension); |
472 | | }; |
473 | | |
474 | | } // namespace clang |
475 | | |
476 | | #endif // LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H |