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/Serialization/ModuleFileExtension.h"
15 #include "clang/Sema/CodeCompleteOptions.h"
16 #include "llvm/ADT/StringRef.h"
19 #include <unordered_map>
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 from a module map.
44 GenerateModuleInterface,///< Generate pre-compiled module from a C++ module
46 GeneratePCH, ///< Generate pre-compiled header.
47 GeneratePTH, ///< Generate pre-tokenized header.
48 InitOnly, ///< Only execute frontend initialization.
49 ModuleFileInfo, ///< Dump information about a module file.
50 VerifyPCH, ///< Load and verify that a PCH file is usable.
51 ParseSyntaxOnly, ///< Parse and perform semantic analysis.
52 PluginAction, ///< Run a plugin action, \see ActionName.
53 PrintDeclContext, ///< Print DeclContext and their Decls.
54 PrintPreamble, ///< Print the "preamble" of the input file
55 PrintPreprocessedInput, ///< -E mode.
56 RewriteMacros, ///< Expand macros but not \#includes.
57 RewriteObjC, ///< ObjC->C Rewriter.
58 RewriteTest, ///< Rewriter playground
59 RunAnalysis, ///< Run one or more source code analyses.
60 MigrateSource, ///< Run migrator.
61 RunPreprocessorOnly ///< Just lex, no output.
75 IK_PreprocessedObjCXX,
85 /// \brief An input file for the front end.
86 class FrontendInputFile {
87 /// \brief The file name, or "-" to read from standard input.
90 llvm::MemoryBuffer *Buffer;
92 /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
95 /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
99 FrontendInputFile() : Buffer(nullptr), Kind(IK_None), IsSystem(false) { }
100 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
101 : File(File.str()), Buffer(nullptr), Kind(Kind), IsSystem(IsSystem) { }
102 FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind,
103 bool IsSystem = false)
104 : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { }
106 InputKind getKind() const { return Kind; }
107 bool isSystem() const { return IsSystem; }
109 bool isEmpty() const { return File.empty() && Buffer == nullptr; }
110 bool isFile() const { return !isBuffer(); }
111 bool isBuffer() const { return Buffer != nullptr; }
112 bool isPreprocessed() const {
113 return Kind == IK_PreprocessedC ||
114 Kind == IK_PreprocessedCXX ||
115 Kind == IK_PreprocessedObjC ||
116 Kind == IK_PreprocessedObjCXX ||
117 Kind == IK_PreprocessedCuda;
120 StringRef getFile() const {
124 llvm::MemoryBuffer *getBuffer() const {
130 /// FrontendOptions - Options for controlling the behavior of the frontend.
131 class FrontendOptions {
133 unsigned DisableFree : 1; ///< Disable memory freeing on exit.
134 unsigned RelocatablePCH : 1; ///< When generating PCH files,
135 /// instruct the AST writer to create
136 /// relocatable PCH files.
137 unsigned ShowHelp : 1; ///< Show the -help text.
138 unsigned ShowStats : 1; ///< Show frontend performance
139 /// metrics and statistics.
140 unsigned ShowTimers : 1; ///< Show timers for individual
142 unsigned ShowVersion : 1; ///< Show the -version text.
143 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are
144 /// unfixable errors.
145 unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings.
146 unsigned FixAndRecompile : 1; ///< Apply fixes and recompile.
147 unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files.
148 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the
149 /// migrator can fix them
150 unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to
151 /// speed up parsing in cases you do
152 /// not need them (e.g. with code
154 unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the
155 ///< global module index if available.
156 unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the
157 ///< global module index if needed.
158 unsigned ASTDumpDecls : 1; ///< Whether we include declaration
159 ///< dumps in AST dumps.
160 unsigned ASTDumpAll : 1; ///< Whether we deserialize all decls
161 ///< when forming AST dumps.
162 unsigned ASTDumpLookups : 1; ///< Whether we include lookup table
163 ///< dumps in AST dumps.
164 unsigned BuildingImplicitModule : 1; ///< Whether we are performing an
165 ///< implicit module build.
166 unsigned ModulesEmbedAllFiles : 1; ///< Whether we should embed all used
167 ///< files into the PCM file.
168 unsigned IncludeTimestamps : 1; ///< Whether timestamps should be
169 ///< written to the produced PCH file.
171 CodeCompleteOptions CodeCompleteOpts;
182 /// \brief Enable migration to modern ObjC literals.
183 ObjCMT_Literals = 0x1,
184 /// \brief Enable migration to modern ObjC subscripting.
185 ObjCMT_Subscripting = 0x2,
186 /// \brief Enable migration to modern ObjC readonly property.
187 ObjCMT_ReadonlyProperty = 0x4,
188 /// \brief Enable migration to modern ObjC readwrite property.
189 ObjCMT_ReadwriteProperty = 0x8,
190 /// \brief Enable migration to modern ObjC property.
191 ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty),
192 /// \brief Enable annotation of ObjCMethods of all kinds.
193 ObjCMT_Annotation = 0x10,
194 /// \brief Enable migration of ObjC methods to 'instancetype'.
195 ObjCMT_Instancetype = 0x20,
196 /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros.
197 ObjCMT_NsMacros = 0x40,
198 /// \brief Enable migration to add conforming protocols.
199 ObjCMT_ProtocolConformance = 0x80,
200 /// \brief prefer 'atomic' property over 'nonatomic'.
201 ObjCMT_AtomicProperty = 0x100,
202 /// \brief annotate property with NS_RETURNS_INNER_POINTER
203 ObjCMT_ReturnsInnerPointerProperty = 0x200,
204 /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
205 ObjCMT_NsAtomicIOSOnlyProperty = 0x400,
206 /// \brief Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
207 ObjCMT_DesignatedInitializer = 0x800,
208 /// \brief Enable converting setter/getter expressions to property-dot syntx.
209 ObjCMT_PropertyDotSyntax = 0x1000,
210 ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
211 ObjCMT_Annotation | ObjCMT_Instancetype |
212 ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
213 ObjCMT_NsAtomicIOSOnlyProperty |
214 ObjCMT_DesignatedInitializer),
215 ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting |
216 ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax)
218 unsigned ObjCMTAction;
219 std::string ObjCMTWhiteListPath;
221 std::string MTMigrateDir;
222 std::string ARCMTMigrateReportOut;
224 /// The input files and their types.
225 std::vector<FrontendInputFile> Inputs;
227 /// The output file, if any.
228 std::string OutputFile;
230 /// If given, the new suffix for fix-it rewritten files.
231 std::string FixItSuffix;
233 /// If given, filter dumped AST Decl nodes by this substring.
234 std::string ASTDumpFilter;
236 /// If given, enable code completion at the provided location.
237 ParsedSourceLocation CodeCompletionAt;
239 /// The frontend action to perform.
240 frontend::ActionKind ProgramAction;
242 /// The name of the action to run when using a plugin action.
243 std::string ActionName;
245 /// Args to pass to the plugins
246 std::unordered_map<std::string,std::vector<std::string>> PluginArgs;
248 /// The list of plugin actions to run in addition to the normal action.
249 std::vector<std::string> AddPluginActions;
251 /// The list of plugins to load.
252 std::vector<std::string> Plugins;
254 /// The list of module file extensions.
255 std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
257 /// \brief The list of module map files to load before processing the input.
258 std::vector<std::string> ModuleMapFiles;
260 /// \brief The list of additional prebuilt module files to load before
261 /// processing the input.
262 std::vector<std::string> ModuleFiles;
264 /// \brief The list of files to embed into the compiled module file.
265 std::vector<std::string> ModulesEmbedFiles;
267 /// \brief The list of AST files to merge.
268 std::vector<std::string> ASTMergeFiles;
270 /// \brief A list of arguments to forward to LLVM's option processing; this
271 /// should only be used for debugging and experimental features.
272 std::vector<std::string> LLVMArgs;
274 /// \brief File name of the file that will provide record layouts
275 /// (in the format produced by -fdump-record-layouts).
276 std::string OverrideRecordLayoutsFile;
278 /// \brief Auxiliary triple for CUDA compilation.
279 std::string AuxTriple;
281 /// \brief If non-empty, search the pch input file as it was a header
282 // included by this file.
283 std::string FindPchSource;
285 /// Filename to write statistics to.
286 std::string StatsFile;
290 DisableFree(false), RelocatablePCH(false), ShowHelp(false),
291 ShowStats(false), ShowTimers(false), ShowVersion(false),
292 FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
293 FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
294 SkipFunctionBodies(false), UseGlobalModuleIndex(true),
295 GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false),
296 BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
297 IncludeTimestamps(true), ARCMTAction(ARCMT_None),
298 ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly)
301 /// getInputKindForExtension - Return the appropriate input kind for a file
302 /// extension. For example, "c" would return IK_C.
304 /// \return The input kind for the extension, or IK_None if the extension is
306 static InputKind getInputKindForExtension(StringRef Extension);
309 } // end namespace clang