1 //===--- FrontendOptions.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
11 #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
13 #include "clang/Frontend/CommandLineSourceLoc.h"
14 #include "clang/Sema/CodeCompleteOptions.h"
15 #include "llvm/ADT/StringRef.h"
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.
70 IK_PreprocessedObjCXX,
78 /// \brief An input file for the front end.
79 class FrontendInputFile {
80 /// \brief The file name, or "-" to read from standard input.
83 llvm::MemoryBuffer *Buffer;
85 /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
88 /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
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) { }
99 InputKind getKind() const { return Kind; }
100 bool isSystem() const { return IsSystem; }
102 bool isEmpty() const { return File.empty() && Buffer == 0; }
103 bool isFile() const { return !isBuffer(); }
104 bool isBuffer() const { return Buffer != 0; }
106 StringRef getFile() const {
110 llvm::MemoryBuffer *getBuffer() const {
116 /// FrontendOptions - Options for controlling the behavior of the frontend.
117 class FrontendOptions {
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
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
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.
147 CodeCompleteOptions CodeCompleteOpts;
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)
188 unsigned ObjCMTAction;
189 std::string ObjCMTWhiteListPath;
191 std::string MTMigrateDir;
192 std::string ARCMTMigrateReportOut;
194 /// The input files and their types.
195 std::vector<FrontendInputFile> Inputs;
197 /// The output file, if any.
198 std::string OutputFile;
200 /// If given, the new suffix for fix-it rewritten files.
201 std::string FixItSuffix;
203 /// If given, filter dumped AST Decl nodes by this substring.
204 std::string ASTDumpFilter;
206 /// If given, enable code completion at the provided location.
207 ParsedSourceLocation CodeCompletionAt;
209 /// The frontend action to perform.
210 frontend::ActionKind ProgramAction;
212 /// The name of the action to run when using a plugin action.
213 std::string ActionName;
215 /// Args to pass to the plugin
216 std::vector<std::string> PluginArgs;
218 /// The list of plugin actions to run in addition to the normal action.
219 std::vector<std::string> AddPluginActions;
221 /// Args to pass to the additional plugins
222 std::vector<std::vector<std::string> > AddPluginArgs;
224 /// The list of plugins to load.
225 std::vector<std::string> Plugins;
227 /// \brief The list of AST files to merge.
228 std::vector<std::string> ASTMergeFiles;
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;
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;
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)
250 /// getInputKindForExtension - Return the appropriate input kind for a file
251 /// extension. For example, "c" would return IK_C.
253 /// \return The input kind for the extension, or IK_None if the extension is
255 static InputKind getInputKindForExtension(StringRef Extension);
258 } // end namespace clang