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