Coverage Report

Created: 2018-09-23 03:40

/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
//                     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_FRONTEND_FRONTENDOPTIONS_H
11
#define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
12
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 pre-tokenized header.
92
  GeneratePTH,
93
94
  /// Only execute frontend initialization.
95
  InitOnly,
96
97
  /// Dump information about a module file.
98
  ModuleFileInfo,
99
100
  /// Load and verify that a PCH file is usable.
101
  VerifyPCH,
102
103
  /// Parse and perform semantic analysis.
104
  ParseSyntaxOnly,
105
106
  /// Run a plugin action, \see ActionName.
107
  PluginAction,
108
109
  /// Print DeclContext and their Decls.
110
  PrintDeclContext,
111
112
  /// Print the "preamble" of the input file
113
  PrintPreamble,
114
115
  /// -E mode.
116
  PrintPreprocessedInput,
117
118
  /// Expand macros but not \#includes.
119
  RewriteMacros,
120
121
  /// ObjC->C Rewriter.
122
  RewriteObjC,
123
124
  /// Rewriter playground
125
  RewriteTest,
126
127
  /// Run one or more source code analyses.
128
  RunAnalysis,
129
130
  /// Dump template instantiations
131
  TemplightDump,
132
133
  /// Run migrator.
134
  MigrateSource,
135
136
  /// Just lex, no output.
137
  RunPreprocessorOnly
138
};
139
140
} // namespace frontend
141
142
/// The kind of a file that we've been handed as an input.
143
class InputKind {
144
private:
145
  unsigned Lang : 4;
146
  unsigned Fmt : 3;
147
  unsigned Preprocessed : 1;
148
149
public:
150
  /// The language for the input, used to select and validate the language
151
  /// standard and possible actions.
152
  enum Language {
153
    Unknown,
154
155
    /// Assembly: we accept this only so that we can preprocess it.
156
    Asm,
157
158
    /// LLVM IR: we accept this so that we can run the optimizer on it,
159
    /// and compile it to assembly or object code.
160
    LLVM_IR,
161
162
    ///@{ Languages that the frontend can parse and compile.
163
    C,
164
    CXX,
165
    ObjC,
166
    ObjCXX,
167
    OpenCL,
168
    CUDA,
169
    RenderScript,
170
    HIP,
171
    ///@}
172
  };
173
174
  /// The input file format.
175
  enum Format {
176
    Source,
177
    ModuleMap,
178
    Precompiled
179
  };
180
181
  constexpr InputKind(Language L = Unknown, Format F = Source,
182
                      bool PP = false)
183
812k
      : Lang(L), Fmt(F), Preprocessed(PP) {}
184
185
476k
  Language getLanguage() const { return static_cast<Language>(Lang); }
186
321k
  Format getFormat() const { return static_cast<Format>(Fmt); }
187
41.2k
  bool isPreprocessed() const { return Preprocessed; }
188
189
  /// Is the input kind fully-unknown?
190
135k
  bool isUnknown() const { return Lang == Unknown && 
Fmt == Source25.1k
; }
191
192
  /// Is the language of the input some dialect of Objective-C?
193
36.2k
  bool isObjectiveC() const { return Lang == ObjC || 
Lang == ObjCXX33.6k
; }
194
195
106k
  InputKind getPreprocessed() const {
196
106k
    return InputKind(getLanguage(), getFormat(), true);
197
106k
  }
198
199
202
  InputKind withFormat(Format F) const {
200
202
    return InputKind(getLanguage(), F, isPreprocessed());
201
202
  }
202
};
203
204
/// An input file for the front end.
205
class FrontendInputFile {
206
  /// The file name, or "-" to read from standard input.
207
  std::string File;
208
209
  /// The input, if it comes from a buffer rather than a file. This object
210
  /// does not own the buffer, and the caller is responsible for ensuring
211
  /// that it outlives any users.
212
  llvm::MemoryBuffer *Buffer = nullptr;
213
214
  /// The kind of input, e.g., C source, AST file, LLVM IR.
215
  InputKind Kind;
216
217
  /// Whether we're dealing with a 'system' input (vs. a 'user' input).
218
  bool IsSystem = false;
219
220
public:
221
91.6k
  FrontendInputFile() = default;
222
  FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
223
42.5k
      : File(File.str()), Kind(Kind), IsSystem(IsSystem) {}
224
  FrontendInputFile(llvm::MemoryBuffer *Buffer, InputKind Kind,
225
                    bool IsSystem = false)
226
4
      : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {}
227
228
238k
  InputKind getKind() const { return Kind; }
229
45.3k
  bool isSystem() const { return IsSystem; }
230
231
0
  bool isEmpty() const { return File.empty() && Buffer == nullptr; }
232
43.2k
  bool isFile() const { return !isBuffer(); }
233
87.1k
  bool isBuffer() const { return Buffer != nullptr; }
234
38.6k
  bool isPreprocessed() const { return Kind.isPreprocessed(); }
235
236
98.0k
  StringRef getFile() const {
237
98.0k
    assert(isFile());
238
98.0k
    return File;
239
98.0k
  }
240
241
8
  llvm::MemoryBuffer *getBuffer() const {
242
8
    assert(isBuffer());
243
8
    return Buffer;
244
8
  }
245
};
246
247
/// FrontendOptions - Options for controlling the behavior of the frontend.
248
class FrontendOptions {
249
public:
250
  /// Disable memory freeing on exit.
251
  unsigned DisableFree : 1;
252
253
  /// When generating PCH files, instruct the AST writer to create relocatable
254
  /// PCH files.
255
  unsigned RelocatablePCH : 1;
256
257
  /// Show the -help text.
258
  unsigned ShowHelp : 1;
259
260
  /// Show frontend performance metrics and statistics.
261
  unsigned ShowStats : 1;
262
263
  /// Show timers for individual actions.
264
  unsigned ShowTimers : 1;
265
266
  /// Show the -version text.
267
  unsigned ShowVersion : 1;
268
269
  /// Apply fixes even if there are unfixable errors.
270
  unsigned FixWhatYouCan : 1;
271
272
  /// Apply fixes only for warnings.
273
  unsigned FixOnlyWarnings : 1;
274
275
  /// Apply fixes and recompile.
276
  unsigned FixAndRecompile : 1;
277
278
  /// Apply fixes to temporary files.
279
  unsigned FixToTemporaries : 1;
280
281
  /// Emit ARC errors even if the migrator can fix them.
282
  unsigned ARCMTMigrateEmitARCErrors : 1;
283
284
  /// Skip over function bodies to speed up parsing in cases you do not need
285
  /// them (e.g. with code completion).
286
  unsigned SkipFunctionBodies : 1;
287
288
  /// Whether we can use the global module index if available.
289
  unsigned UseGlobalModuleIndex : 1;
290
291
  /// Whether we can generate the global module index if needed.
292
  unsigned GenerateGlobalModuleIndex : 1;
293
294
  /// Whether we include declaration dumps in AST dumps.
295
  unsigned ASTDumpDecls : 1;
296
297
  /// Whether we deserialize all decls when forming AST dumps.
298
  unsigned ASTDumpAll : 1;
299
300
  /// Whether we include lookup table dumps in AST dumps.
301
  unsigned ASTDumpLookups : 1;
302
303
  /// Whether we are performing an implicit module build.
304
  unsigned BuildingImplicitModule : 1;
305
306
  /// Whether we should embed all used files into the PCM file.
307
  unsigned ModulesEmbedAllFiles : 1;
308
309
  /// Whether timestamps should be written to the produced PCH file.
310
  unsigned IncludeTimestamps : 1;
311
312
  CodeCompleteOptions CodeCompleteOpts;
313
314
  enum {
315
    ARCMT_None,
316
    ARCMT_Check,
317
    ARCMT_Modify,
318
    ARCMT_Migrate
319
  } ARCMTAction = ARCMT_None;
320
321
  enum {
322
    ObjCMT_None = 0,
323
324
    /// Enable migration to modern ObjC literals.
325
    ObjCMT_Literals = 0x1,
326
327
    /// Enable migration to modern ObjC subscripting.
328
    ObjCMT_Subscripting = 0x2,
329
330
    /// Enable migration to modern ObjC readonly property.
331
    ObjCMT_ReadonlyProperty = 0x4,
332
333
    /// Enable migration to modern ObjC readwrite property.
334
    ObjCMT_ReadwriteProperty = 0x8,
335
336
    /// Enable migration to modern ObjC property.
337
    ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty),
338
339
    /// Enable annotation of ObjCMethods of all kinds.
340
    ObjCMT_Annotation = 0x10,
341
342
    /// Enable migration of ObjC methods to 'instancetype'.
343
    ObjCMT_Instancetype = 0x20,
344
345
    /// Enable migration to NS_ENUM/NS_OPTIONS macros.
346
    ObjCMT_NsMacros = 0x40,
347
348
    /// Enable migration to add conforming protocols.
349
    ObjCMT_ProtocolConformance = 0x80,
350
351
    /// prefer 'atomic' property over 'nonatomic'.
352
    ObjCMT_AtomicProperty = 0x100,
353
354
    /// annotate property with NS_RETURNS_INNER_POINTER
355
    ObjCMT_ReturnsInnerPointerProperty = 0x200,
356
357
    /// use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
358
    ObjCMT_NsAtomicIOSOnlyProperty = 0x400,
359
360
    /// Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
361
    ObjCMT_DesignatedInitializer = 0x800,
362
363
    /// Enable converting setter/getter expressions to property-dot syntx.
364
    ObjCMT_PropertyDotSyntax = 0x1000,
365
366
    ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
367
                           ObjCMT_Annotation | ObjCMT_Instancetype |
368
                           ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
369
                           ObjCMT_NsAtomicIOSOnlyProperty |
370
                           ObjCMT_DesignatedInitializer),
371
    ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting |
372
                         ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax)
373
  };
374
  unsigned ObjCMTAction = ObjCMT_None;
375
  std::string ObjCMTWhiteListPath;
376
377
  std::string MTMigrateDir;
378
  std::string ARCMTMigrateReportOut;
379
380
  /// The input files and their types.
381
  std::vector<FrontendInputFile> Inputs;
382
383
  /// When the input is a module map, the original module map file from which
384
  /// that map was inferred, if any (for umbrella modules).
385
  std::string OriginalModuleMap;
386
387
  /// The output file, if any.
388
  std::string OutputFile;
389
390
  /// If given, the new suffix for fix-it rewritten files.
391
  std::string FixItSuffix;
392
393
  /// If given, filter dumped AST Decl nodes by this substring.
394
  std::string ASTDumpFilter;
395
396
  /// If given, enable code completion at the provided location.
397
  ParsedSourceLocation CodeCompletionAt;
398
399
  /// The frontend action to perform.
400
  frontend::ActionKind ProgramAction = frontend::ParseSyntaxOnly;
401
402
  /// The name of the action to run when using a plugin action.
403
  std::string ActionName;
404
405
  /// Args to pass to the plugins
406
  std::unordered_map<std::string,std::vector<std::string>> PluginArgs;
407
408
  /// The list of plugin actions to run in addition to the normal action.
409
  std::vector<std::string> AddPluginActions;
410
411
  /// The list of plugins to load.
412
  std::vector<std::string> Plugins;
413
414
  /// The list of module file extensions.
415
  std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
416
417
  /// The list of module map files to load before processing the input.
418
  std::vector<std::string> ModuleMapFiles;
419
420
  /// The list of additional prebuilt module files to load before
421
  /// processing the input.
422
  std::vector<std::string> ModuleFiles;
423
424
  /// The list of files to embed into the compiled module file.
425
  std::vector<std::string> ModulesEmbedFiles;
426
427
  /// The list of AST files to merge.
428
  std::vector<std::string> ASTMergeFiles;
429
430
  /// A list of arguments to forward to LLVM's option processing; this
431
  /// should only be used for debugging and experimental features.
432
  std::vector<std::string> LLVMArgs;
433
434
  /// File name of the file that will provide record layouts
435
  /// (in the format produced by -fdump-record-layouts).
436
  std::string OverrideRecordLayoutsFile;
437
438
  /// Auxiliary triple for CUDA compilation.
439
  std::string AuxTriple;
440
441
  /// Filename to write statistics to.
442
  std::string StatsFile;
443
444
public:
445
  FrontendOptions()
446
      : DisableFree(false), RelocatablePCH(false), ShowHelp(false),
447
        ShowStats(false), ShowTimers(false), ShowVersion(false),
448
        FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
449
        FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
450
        SkipFunctionBodies(false), UseGlobalModuleIndex(true),
451
        GenerateGlobalModuleIndex(true), ASTDumpDecls(false),
452
        ASTDumpLookups(false), BuildingImplicitModule(false),
453
50.1k
        ModulesEmbedAllFiles(false), IncludeTimestamps(true) {}
454
455
  /// getInputKindForExtension - Return the appropriate input kind for a file
456
  /// extension. For example, "c" would return InputKind::C.
457
  ///
458
  /// \return The input kind for the extension, or InputKind::Unknown if the
459
  /// extension is not recognized.
460
  static InputKind getInputKindForExtension(StringRef Extension);
461
};
462
463
} // namespace clang
464
465
#endif // LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H