]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/FrontendOptions.h
Import Zstandard 1.2.0
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Frontend / FrontendOptions.h
1 //===--- FrontendOptions.h --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
11 #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
12
13 #include "clang/Frontend/CommandLineSourceLoc.h"
14 #include "clang/Serialization/ModuleFileExtension.h"
15 #include "clang/Sema/CodeCompleteOptions.h"
16 #include "llvm/ADT/StringRef.h"
17 #include <string>
18 #include <vector>
19 #include <unordered_map>
20
21 namespace llvm {
22 class MemoryBuffer;
23 }
24
25 namespace clang {
26
27 namespace frontend {
28   enum ActionKind {
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
45                             ///< interface file.
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.
62   };
63 }
64
65 enum InputKind {
66   IK_None,
67   IK_Asm,
68   IK_C,
69   IK_CXX,
70   IK_ObjC,
71   IK_ObjCXX,
72   IK_PreprocessedC,
73   IK_PreprocessedCXX,
74   IK_PreprocessedObjC,
75   IK_PreprocessedObjCXX,
76   IK_OpenCL,
77   IK_CUDA,
78   IK_PreprocessedCuda,
79   IK_RenderScript,
80   IK_AST,
81   IK_LLVM_IR
82 };
83
84   
85 /// \brief An input file for the front end.
86 class FrontendInputFile {
87   /// \brief The file name, or "-" to read from standard input.
88   std::string File;
89
90   llvm::MemoryBuffer *Buffer;
91
92   /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
93   InputKind Kind;
94
95   /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
96   bool IsSystem;
97
98 public:
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) { }
105
106   InputKind getKind() const { return Kind; }
107   bool isSystem() const { return IsSystem; }
108
109   bool isEmpty() const { return File.empty() && Buffer == nullptr; }
110   bool isFile() const { return !isBuffer(); }
111   bool isBuffer() const { return Buffer != nullptr; }
112
113   StringRef getFile() const {
114     assert(isFile());
115     return File;
116   }
117   llvm::MemoryBuffer *getBuffer() const {
118     assert(isBuffer());
119     return Buffer;
120   }
121 };
122
123 /// FrontendOptions - Options for controlling the behavior of the frontend.
124 class FrontendOptions {
125 public:
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
134                                            /// actions.
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
146                                            /// completion).
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.
161
162   CodeCompleteOptions CodeCompleteOpts;
163
164   enum {
165     ARCMT_None,
166     ARCMT_Check,
167     ARCMT_Modify,
168     ARCMT_Migrate
169   } ARCMTAction;
170
171   enum {
172     ObjCMT_None = 0,
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)
208   };
209   unsigned ObjCMTAction;
210   std::string ObjCMTWhiteListPath;
211
212   std::string MTMigrateDir;
213   std::string ARCMTMigrateReportOut;
214
215   /// The input files and their types.
216   std::vector<FrontendInputFile> Inputs;
217
218   /// The output file, if any.
219   std::string OutputFile;
220
221   /// If given, the new suffix for fix-it rewritten files.
222   std::string FixItSuffix;
223
224   /// If given, filter dumped AST Decl nodes by this substring.
225   std::string ASTDumpFilter;
226
227   /// If given, enable code completion at the provided location.
228   ParsedSourceLocation CodeCompletionAt;
229
230   /// The frontend action to perform.
231   frontend::ActionKind ProgramAction;
232
233   /// The name of the action to run when using a plugin action.
234   std::string ActionName;
235
236   /// Args to pass to the plugins
237   std::unordered_map<std::string,std::vector<std::string>> PluginArgs;
238
239   /// The list of plugin actions to run in addition to the normal action.
240   std::vector<std::string> AddPluginActions;
241
242   /// The list of plugins to load.
243   std::vector<std::string> Plugins;
244
245   /// The list of module file extensions.
246   std::vector<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
247
248   /// \brief The list of module map files to load before processing the input.
249   std::vector<std::string> ModuleMapFiles;
250
251   /// \brief The list of additional prebuilt module files to load before
252   /// processing the input.
253   std::vector<std::string> ModuleFiles;
254
255   /// \brief The list of files to embed into the compiled module file.
256   std::vector<std::string> ModulesEmbedFiles;
257
258   /// \brief The list of AST files to merge.
259   std::vector<std::string> ASTMergeFiles;
260
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;
264
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;
268
269   /// \brief Auxiliary triple for CUDA compilation.
270   std::string AuxTriple;
271
272   /// \brief If non-empty, search the pch input file as it was a header
273   // included by this file.
274   std::string FindPchSource;
275
276   /// Filename to write statistics to.
277   std::string StatsFile;
278
279 public:
280   FrontendOptions() :
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)
290   {}
291
292   /// getInputKindForExtension - Return the appropriate input kind for a file
293   /// extension. For example, "c" would return IK_C.
294   ///
295   /// \return The input kind for the extension, or IK_None if the extension is
296   /// not recognized.
297   static InputKind getInputKindForExtension(StringRef Extension);
298 };
299
300 }  // end namespace clang
301
302 #endif