]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/FrontendOptions.h
Merge ^/head r305301 through r305345.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Frontend / FrontendOptions.h
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 <string>
18 #include <vector>
19 #include <unordered_map>
20
21 namespace llvm {
22 class MemoryBuffer;
23 }
24
25 namespace clang {
26
27 namespace frontend {
28   enum ActionKind {
29     ASTDeclList,            ///< Parse ASTs and list Decl nodes.
30     ASTDump,                ///< Parse ASTs and dump them.
31     ASTPrint,               ///< Parse ASTs and print them.
32     ASTView,                ///< Parse ASTs and view them in Graphviz.
33     DumpRawTokens,          ///< Dump out raw tokens.
34     DumpTokens,             ///< Dump out preprocessed tokens.
35     EmitAssembly,           ///< Emit a .s file.
36     EmitBC,                 ///< Emit a .bc file.
37     EmitHTML,               ///< Translate input source into HTML.
38     EmitLLVM,               ///< Emit a .ll file.
39     EmitLLVMOnly,           ///< Generate LLVM IR, but do not emit anything.
40     EmitCodeGenOnly,        ///< Generate machine code, but don't emit anything.
41     EmitObj,                ///< Emit a .o file.
42     FixIt,                  ///< Parse and apply any fixits to the source.
43     GenerateModule,         ///< Generate pre-compiled module.
44     GeneratePCH,            ///< Generate pre-compiled header.
45     GeneratePTH,            ///< Generate pre-tokenized header.
46     InitOnly,               ///< Only execute frontend initialization.
47     ModuleFileInfo,         ///< Dump information about a module file.
48     VerifyPCH,              ///< Load and verify that a PCH file is usable.
49     ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
50     PluginAction,           ///< Run a plugin action, \see ActionName.
51     PrintDeclContext,       ///< Print DeclContext and their Decls.
52     PrintPreamble,          ///< Print the "preamble" of the input file
53     PrintPreprocessedInput, ///< -E mode.
54     RewriteMacros,          ///< Expand macros but not \#includes.
55     RewriteObjC,            ///< ObjC->C Rewriter.
56     RewriteTest,            ///< Rewriter playground
57     RunAnalysis,            ///< Run one or more source code analyses.
58     MigrateSource,          ///< Run migrator.
59     RunPreprocessorOnly     ///< Just lex, no output.
60   };
61 }
62
63 enum InputKind {
64   IK_None,
65   IK_Asm,
66   IK_C,
67   IK_CXX,
68   IK_ObjC,
69   IK_ObjCXX,
70   IK_PreprocessedC,
71   IK_PreprocessedCXX,
72   IK_PreprocessedObjC,
73   IK_PreprocessedObjCXX,
74   IK_OpenCL,
75   IK_CUDA,
76   IK_PreprocessedCuda,
77   IK_RenderScript,
78   IK_AST,
79   IK_LLVM_IR
80 };
81
82   
83 /// \brief An input file for the front end.
84 class FrontendInputFile {
85   /// \brief The file name, or "-" to read from standard input.
86   std::string File;
87
88   llvm::MemoryBuffer *Buffer;
89
90   /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
91   InputKind Kind;
92
93   /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
94   bool IsSystem;
95
96 public:
97   FrontendInputFile() : Buffer(nullptr), Kind(IK_None), IsSystem(false) { }
98   FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
99     : File(File.str()), Buffer(nullptr), Kind(Kind), IsSystem(IsSystem) { }
100   FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind,
101                     bool IsSystem = false)
102     : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { }
103
104   InputKind getKind() const { return Kind; }
105   bool isSystem() const { return IsSystem; }
106
107   bool isEmpty() const { return File.empty() && Buffer == nullptr; }
108   bool isFile() const { return !isBuffer(); }
109   bool isBuffer() const { return Buffer != nullptr; }
110
111   StringRef getFile() const {
112     assert(isFile());
113     return File;
114   }
115   llvm::MemoryBuffer *getBuffer() const {
116     assert(isBuffer());
117     return Buffer;
118   }
119 };
120
121 /// FrontendOptions - Options for controlling the behavior of the frontend.
122 class FrontendOptions {
123 public:
124   unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
125   unsigned RelocatablePCH : 1;             ///< When generating PCH files,
126                                            /// instruct the AST writer to create
127                                            /// relocatable PCH files.
128   unsigned ShowHelp : 1;                   ///< Show the -help text.
129   unsigned ShowStats : 1;                  ///< Show frontend performance
130                                            /// metrics and statistics.
131   unsigned ShowTimers : 1;                 ///< Show timers for individual
132                                            /// actions.
133   unsigned ShowVersion : 1;                ///< Show the -version text.
134   unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
135                                            /// unfixable errors.
136   unsigned FixOnlyWarnings : 1;            ///< Apply fixes only for warnings.
137   unsigned FixAndRecompile : 1;            ///< Apply fixes and recompile.
138   unsigned FixToTemporaries : 1;           ///< Apply fixes to temporary files.
139   unsigned ARCMTMigrateEmitARCErrors : 1;  /// Emit ARC errors even if the
140                                            /// migrator can fix them
141   unsigned SkipFunctionBodies : 1;         ///< Skip over function bodies to
142                                            /// speed up parsing in cases you do
143                                            /// not need them (e.g. with code
144                                            /// completion).
145   unsigned UseGlobalModuleIndex : 1;       ///< Whether we can use the
146                                            ///< global module index if available.
147   unsigned GenerateGlobalModuleIndex : 1;  ///< Whether we can generate the
148                                            ///< global module index if needed.
149   unsigned ASTDumpDecls : 1;               ///< Whether we include declaration
150                                            ///< dumps in AST dumps.
151   unsigned ASTDumpLookups : 1;             ///< Whether we include lookup table
152                                            ///< dumps in AST dumps.
153   unsigned BuildingImplicitModule : 1;     ///< Whether we are performing an
154                                            ///< implicit module build.
155   unsigned ModulesEmbedAllFiles : 1;       ///< Whether we should embed all used
156                                            ///< files into the PCM file.
157   unsigned IncludeTimestamps : 1;          ///< Whether timestamps should be
158                                            ///< written to the produced PCH file.
159
160   CodeCompleteOptions CodeCompleteOpts;
161
162   enum {
163     ARCMT_None,
164     ARCMT_Check,
165     ARCMT_Modify,
166     ARCMT_Migrate
167   } ARCMTAction;
168
169   enum {
170     ObjCMT_None = 0,
171     /// \brief Enable migration to modern ObjC literals.
172     ObjCMT_Literals = 0x1,
173     /// \brief Enable migration to modern ObjC subscripting.
174     ObjCMT_Subscripting = 0x2,
175     /// \brief Enable migration to modern ObjC readonly property.
176     ObjCMT_ReadonlyProperty = 0x4,
177     /// \brief Enable migration to modern ObjC readwrite property.
178     ObjCMT_ReadwriteProperty = 0x8,
179     /// \brief Enable migration to modern ObjC property.
180     ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty),
181     /// \brief Enable annotation of ObjCMethods of all kinds.
182     ObjCMT_Annotation = 0x10,
183     /// \brief Enable migration of ObjC methods to 'instancetype'.
184     ObjCMT_Instancetype = 0x20,
185     /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros.
186     ObjCMT_NsMacros = 0x40,
187     /// \brief Enable migration to add conforming protocols.
188     ObjCMT_ProtocolConformance = 0x80,
189     /// \brief prefer 'atomic' property over 'nonatomic'.
190     ObjCMT_AtomicProperty = 0x100,
191     /// \brief annotate property with NS_RETURNS_INNER_POINTER
192     ObjCMT_ReturnsInnerPointerProperty = 0x200,
193     /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
194     ObjCMT_NsAtomicIOSOnlyProperty = 0x400,
195     /// \brief Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
196     ObjCMT_DesignatedInitializer = 0x800,
197     /// \brief Enable converting setter/getter expressions to property-dot syntx.
198     ObjCMT_PropertyDotSyntax = 0x1000,
199     ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
200                            ObjCMT_Annotation | ObjCMT_Instancetype |
201                            ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
202                            ObjCMT_NsAtomicIOSOnlyProperty |
203                            ObjCMT_DesignatedInitializer),
204     ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting |
205                          ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax)
206   };
207   unsigned ObjCMTAction;
208   std::string ObjCMTWhiteListPath;
209
210   std::string MTMigrateDir;
211   std::string ARCMTMigrateReportOut;
212
213   /// The input files and their types.
214   std::vector<FrontendInputFile> Inputs;
215
216   /// The output file, if any.
217   std::string OutputFile;
218
219   /// If given, the new suffix for fix-it rewritten files.
220   std::string FixItSuffix;
221
222   /// If given, filter dumped AST Decl nodes by this substring.
223   std::string ASTDumpFilter;
224
225   /// If given, enable code completion at the provided location.
226   ParsedSourceLocation CodeCompletionAt;
227
228   /// The frontend action to perform.
229   frontend::ActionKind ProgramAction;
230
231   /// The name of the action to run when using a plugin action.
232   std::string ActionName;
233
234   /// Args to pass to the plugins
235   std::unordered_map<std::string,std::vector<std::string>> PluginArgs;
236
237   /// The list of plugin actions to run in addition to the normal action.
238   std::vector<std::string> AddPluginActions;
239
240   /// The list of plugins to load.
241   std::vector<std::string> Plugins;
242
243   /// The list of module file extensions.
244   std::vector<IntrusiveRefCntPtr<ModuleFileExtension>> ModuleFileExtensions;
245
246   /// \brief The list of module map files to load before processing the input.
247   std::vector<std::string> ModuleMapFiles;
248
249   /// \brief The list of additional prebuilt module files to load before
250   /// processing the input.
251   std::vector<std::string> ModuleFiles;
252
253   /// \brief The list of files to embed into the compiled module file.
254   std::vector<std::string> ModulesEmbedFiles;
255
256   /// \brief The list of AST files to merge.
257   std::vector<std::string> ASTMergeFiles;
258
259   /// \brief A list of arguments to forward to LLVM's option processing; this
260   /// should only be used for debugging and experimental features.
261   std::vector<std::string> LLVMArgs;
262
263   /// \brief File name of the file that will provide record layouts
264   /// (in the format produced by -fdump-record-layouts).
265   std::string OverrideRecordLayoutsFile;
266
267   /// \brief Auxiliary triple for CUDA compilation.
268   std::string AuxTriple;
269
270   /// \brief If non-empty, search the pch input file as it was a header
271   // included by this file.
272   std::string FindPchSource;
273
274 public:
275   FrontendOptions() :
276     DisableFree(false), RelocatablePCH(false), ShowHelp(false),
277     ShowStats(false), ShowTimers(false), ShowVersion(false),
278     FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
279     FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
280     SkipFunctionBodies(false), UseGlobalModuleIndex(true),
281     GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false),
282     BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
283     IncludeTimestamps(true), ARCMTAction(ARCMT_None),
284     ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly)
285   {}
286
287   /// getInputKindForExtension - Return the appropriate input kind for a file
288   /// extension. For example, "c" would return IK_C.
289   ///
290   /// \return The input kind for the extension, or IK_None if the extension is
291   /// not recognized.
292   static InputKind getInputKindForExtension(StringRef Extension);
293 };
294
295 }  // end namespace clang
296
297 #endif