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