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; }
113 StringRef getFile() const {
117 llvm::MemoryBuffer *getBuffer() const {
123 /// FrontendOptions - Options for controlling the behavior of the frontend.
124 class FrontendOptions {
126 unsigned DisableFree : 1; ///< Disable memory freeing on exit.
127 unsigned RelocatablePCH : 1; ///< When generating PCH files,
128 /// instruct the AST writer to create
129 /// relocatable PCH files.
130 unsigned ShowHelp : 1; ///< Show the -help text.
131 unsigned ShowStats : 1; ///< Show frontend performance
132 /// metrics and statistics.
133 unsigned ShowTimers : 1; ///< Show timers for individual
135 unsigned ShowVersion : 1; ///< Show the -version text.
136 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are
137 /// unfixable errors.
138 unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings.
139 unsigned FixAndRecompile : 1; ///< Apply fixes and recompile.
140 unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files.
141 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the
142 /// migrator can fix them
143 unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to
144 /// speed up parsing in cases you do
145 /// not need them (e.g. with code
147 unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the
148 ///< global module index if available.
149 unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the
150 ///< global module index if needed.
151 unsigned ASTDumpDecls : 1; ///< Whether we include declaration
152 ///< dumps in AST dumps.
153 unsigned ASTDumpLookups : 1; ///< Whether we include lookup table
154 ///< dumps in AST dumps.
155 unsigned BuildingImplicitModule : 1; ///< Whether we are performing an
156 ///< implicit module build.
157 unsigned ModulesEmbedAllFiles : 1; ///< Whether we should embed all used
158 ///< files into the PCM file.
159 unsigned IncludeTimestamps : 1; ///< Whether timestamps should be
160 ///< written to the produced PCH file.
162 CodeCompleteOptions CodeCompleteOpts;
173 /// \brief Enable migration to modern ObjC literals.
174 ObjCMT_Literals = 0x1,
175 /// \brief Enable migration to modern ObjC subscripting.
176 ObjCMT_Subscripting = 0x2,
177 /// \brief Enable migration to modern ObjC readonly property.
178 ObjCMT_ReadonlyProperty = 0x4,
179 /// \brief Enable migration to modern ObjC readwrite property.
180 ObjCMT_ReadwriteProperty = 0x8,
181 /// \brief Enable migration to modern ObjC property.
182 ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty),
183 /// \brief Enable annotation of ObjCMethods of all kinds.
184 ObjCMT_Annotation = 0x10,
185 /// \brief Enable migration of ObjC methods to 'instancetype'.
186 ObjCMT_Instancetype = 0x20,
187 /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros.
188 ObjCMT_NsMacros = 0x40,
189 /// \brief Enable migration to add conforming protocols.
190 ObjCMT_ProtocolConformance = 0x80,
191 /// \brief prefer 'atomic' property over 'nonatomic'.
192 ObjCMT_AtomicProperty = 0x100,
193 /// \brief annotate property with NS_RETURNS_INNER_POINTER
194 ObjCMT_ReturnsInnerPointerProperty = 0x200,
195 /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
196 ObjCMT_NsAtomicIOSOnlyProperty = 0x400,
197 /// \brief Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
198 ObjCMT_DesignatedInitializer = 0x800,
199 /// \brief Enable converting setter/getter expressions to property-dot syntx.
200 ObjCMT_PropertyDotSyntax = 0x1000,
201 ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
202 ObjCMT_Annotation | ObjCMT_Instancetype |
203 ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
204 ObjCMT_NsAtomicIOSOnlyProperty |
205 ObjCMT_DesignatedInitializer),
206 ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting |
207 ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax)
209 unsigned ObjCMTAction;
210 std::string ObjCMTWhiteListPath;
212 std::string MTMigrateDir;
213 std::string ARCMTMigrateReportOut;
215 /// The input files and their types.
216 std::vector<FrontendInputFile> Inputs;
218 /// The output file, if any.
219 std::string OutputFile;
221 /// If given, the new suffix for fix-it rewritten files.
222 std::string FixItSuffix;
224 /// If given, filter dumped AST Decl nodes by this substring.
225 std::string ASTDumpFilter;
227 /// If given, enable code completion at the provided location.
228 ParsedSourceLocation CodeCompletionAt;
230 /// The frontend action to perform.
231 frontend::ActionKind ProgramAction;
233 /// The name of the action to run when using a plugin action.
234 std::string ActionName;
236 /// Args to pass to the plugins
237 std::unordered_map<std::string,std::vector<std::string>> PluginArgs;
239 /// The list of plugin actions to run in addition to the normal action.
240 std::vector<std::string> AddPluginActions;
242 /// The list of plugins to load.
243 std::vector<std::string> Plugins;
245 /// The list of module file extensions.
246 std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
248 /// \brief The list of module map files to load before processing the input.
249 std::vector<std::string> ModuleMapFiles;
251 /// \brief The list of additional prebuilt module files to load before
252 /// processing the input.
253 std::vector<std::string> ModuleFiles;
255 /// \brief The list of files to embed into the compiled module file.
256 std::vector<std::string> ModulesEmbedFiles;
258 /// \brief The list of AST files to merge.
259 std::vector<std::string> ASTMergeFiles;
261 /// \brief A list of arguments to forward to LLVM's option processing; this
262 /// should only be used for debugging and experimental features.
263 std::vector<std::string> LLVMArgs;
265 /// \brief File name of the file that will provide record layouts
266 /// (in the format produced by -fdump-record-layouts).
267 std::string OverrideRecordLayoutsFile;
269 /// \brief Auxiliary triple for CUDA compilation.
270 std::string AuxTriple;
272 /// \brief If non-empty, search the pch input file as it was a header
273 // included by this file.
274 std::string FindPchSource;
276 /// Filename to write statistics to.
277 std::string StatsFile;
281 DisableFree(false), RelocatablePCH(false), ShowHelp(false),
282 ShowStats(false), ShowTimers(false), ShowVersion(false),
283 FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false),
284 FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false),
285 SkipFunctionBodies(false), UseGlobalModuleIndex(true),
286 GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false),
287 BuildingImplicitModule(false), ModulesEmbedAllFiles(false),
288 IncludeTimestamps(true), ARCMTAction(ARCMT_None),
289 ObjCMTAction(ObjCMT_None), ProgramAction(frontend::ParseSyntaxOnly)
292 /// getInputKindForExtension - Return the appropriate input kind for a file
293 /// extension. For example, "c" would return IK_C.
295 /// \return The input kind for the extension, or IK_None if the extension is
297 static InputKind getInputKindForExtension(StringRef Extension);
300 } // end namespace clang