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