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 VerifyPCH, ///< Load and verify that a PCH file is usable.
47 ParseSyntaxOnly, ///< Parse and perform semantic analysis.
48 PluginAction, ///< Run a plugin action, \see ActionName.
49 PrintDeclContext, ///< Print DeclContext and their Decls.
50 PrintPreamble, ///< Print the "preamble" of the input file
51 PrintPreprocessedInput, ///< -E mode.
52 RewriteMacros, ///< Expand macros but not \#includes.
53 RewriteObjC, ///< ObjC->C Rewriter.
54 RewriteTest, ///< Rewriter playground
55 RunAnalysis, ///< Run one or more source code analyses.
56 MigrateSource, ///< Run migrator.
57 RunPreprocessorOnly ///< Just lex, no output.
71 IK_PreprocessedObjCXX,
79 /// \brief An input file for the front end.
80 class FrontendInputFile {
81 /// \brief The file name, or "-" to read from standard input.
84 llvm::MemoryBuffer *Buffer;
86 /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
89 /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
93 FrontendInputFile() : Buffer(nullptr), Kind(IK_None) { }
94 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
95 : File(File.str()), Buffer(nullptr), Kind(Kind), IsSystem(IsSystem) { }
96 FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind,
97 bool IsSystem = false)
98 : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { }
100 InputKind getKind() const { return Kind; }
101 bool isSystem() const { return IsSystem; }
103 bool isEmpty() const { return File.empty() && Buffer == nullptr; }
104 bool isFile() const { return !isBuffer(); }
105 bool isBuffer() const { return Buffer != nullptr; }
107 StringRef getFile() const {
111 llvm::MemoryBuffer *getBuffer() const {
117 /// FrontendOptions - Options for controlling the behavior of the frontend.
118 class FrontendOptions {
120 unsigned DisableFree : 1; ///< Disable memory freeing on exit.
121 unsigned RelocatablePCH : 1; ///< When generating PCH files,
122 /// instruct the AST writer to create
123 /// relocatable PCH files.
124 unsigned ShowHelp : 1; ///< Show the -help text.
125 unsigned ShowStats : 1; ///< Show frontend performance
126 /// metrics and statistics.
127 unsigned ShowTimers : 1; ///< Show timers for individual
129 unsigned ShowVersion : 1; ///< Show the -version text.
130 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are
131 /// unfixable errors.
132 unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings.
133 unsigned FixAndRecompile : 1; ///< Apply fixes and recompile.
134 unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files.
135 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the
136 /// migrator can fix them
137 unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to
138 /// speed up parsing in cases you do
139 /// not need them (e.g. with code
141 unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the
142 ///< global module index if available.
143 unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the
144 ///< global module index if needed.
145 unsigned ASTDumpDecls : 1; ///< Whether we include declaration
146 ///< dumps in AST dumps.
147 unsigned ASTDumpLookups : 1; ///< Whether we include lookup table
148 ///< dumps in AST dumps.
150 CodeCompleteOptions CodeCompleteOpts;
161 /// \brief Enable migration to modern ObjC literals.
162 ObjCMT_Literals = 0x1,
163 /// \brief Enable migration to modern ObjC subscripting.
164 ObjCMT_Subscripting = 0x2,
165 /// \brief Enable migration to modern ObjC readonly property.
166 ObjCMT_ReadonlyProperty = 0x4,
167 /// \brief Enable migration to modern ObjC readwrite property.
168 ObjCMT_ReadwriteProperty = 0x8,
169 /// \brief Enable migration to modern ObjC property.
170 ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty),
171 /// \brief Enable annotation of ObjCMethods of all kinds.
172 ObjCMT_Annotation = 0x10,
173 /// \brief Enable migration of ObjC methods to 'instancetype'.
174 ObjCMT_Instancetype = 0x20,
175 /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros.
176 ObjCMT_NsMacros = 0x40,
177 /// \brief Enable migration to add conforming protocols.
178 ObjCMT_ProtocolConformance = 0x80,
179 /// \brief prefer 'atomic' property over 'nonatomic'.
180 ObjCMT_AtomicProperty = 0x100,
181 /// \brief annotate property with NS_RETURNS_INNER_POINTER
182 ObjCMT_ReturnsInnerPointerProperty = 0x200,
183 /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
184 ObjCMT_NsAtomicIOSOnlyProperty = 0x400,
185 /// \brief Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
186 ObjCMT_DesignatedInitializer = 0x800,
187 /// \brief Enable converting setter/getter expressions to property-dot syntx.
188 ObjCMT_PropertyDotSyntax = 0x1000,
189 ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
190 ObjCMT_Annotation | ObjCMT_Instancetype |
191 ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
192 ObjCMT_NsAtomicIOSOnlyProperty |
193 ObjCMT_DesignatedInitializer),
194 ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting |
195 ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax)
197 unsigned ObjCMTAction;
198 std::string ObjCMTWhiteListPath;
200 std::string MTMigrateDir;
201 std::string ARCMTMigrateReportOut;
203 /// The input files and their types.
204 std::vector<FrontendInputFile> Inputs;
206 /// The output file, if any.
207 std::string OutputFile;
209 /// If given, the new suffix for fix-it rewritten files.
210 std::string FixItSuffix;
212 /// If given, filter dumped AST Decl nodes by this substring.
213 std::string ASTDumpFilter;
215 /// If given, enable code completion at the provided location.
216 ParsedSourceLocation CodeCompletionAt;
218 /// The frontend action to perform.
219 frontend::ActionKind ProgramAction;
221 /// The name of the action to run when using a plugin action.
222 std::string ActionName;
224 /// Args to pass to the plugin
225 std::vector<std::string> PluginArgs;
227 /// The list of plugin actions to run in addition to the normal action.
228 std::vector<std::string> AddPluginActions;
230 /// Args to pass to the additional plugins
231 std::vector<std::vector<std::string> > AddPluginArgs;
233 /// The list of plugins to load.
234 std::vector<std::string> Plugins;
236 /// \brief The list of module map files to load before processing the input.
237 std::vector<std::string> ModuleMapFiles;
239 /// \brief The list of additional prebuilt module files to load before
240 /// processing the input.
241 std::vector<std::string> ModuleFiles;
243 /// \brief The list of AST files to merge.
244 std::vector<std::string> ASTMergeFiles;
246 /// \brief A list of arguments to forward to LLVM's option processing; this
247 /// should only be used for debugging and experimental features.
248 std::vector<std::string> LLVMArgs;
250 /// \brief File name of the file that will provide record layouts
251 /// (in the format produced by -fdump-record-layouts).
252 std::string OverrideRecordLayoutsFile;
256 DisableFree(false), RelocatablePCH(false), ShowHelp(false),
257 ShowStats(false), ShowTimers(false), ShowVersion(false),
258 FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
259 FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
260 SkipFunctionBodies(false), UseGlobalModuleIndex(true),
261 GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false),
262 ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None),
263 ProgramAction(frontend::ParseSyntaxOnly)
266 /// getInputKindForExtension - Return the appropriate input kind for a file
267 /// extension. For example, "c" would return IK_C.
269 /// \return The input kind for the extension, or IK_None if the extension is
271 static InputKind getInputKindForExtension(StringRef Extension);
274 } // end namespace clang