FrontendOptions.h revision 5d2a20671954f55f765b96375e8bcd38367cb3ba
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/Sema/CodeCompleteOptions.h" 15#include "llvm/ADT/StringRef.h" 16#include <string> 17#include <vector> 18 19namespace llvm { 20class MemoryBuffer; 21} 22 23namespace clang { 24 25namespace frontend { 26 enum ActionKind { 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 ParseSyntaxOnly, ///< Parse and perform semantic analysis. 47 PluginAction, ///< Run a plugin action, \see ActionName. 48 PrintDeclContext, ///< Print DeclContext and their Decls. 49 PrintPreamble, ///< Print the "preamble" of the input file 50 PrintPreprocessedInput, ///< -E mode. 51 RewriteMacros, ///< Expand macros but not \#includes. 52 RewriteObjC, ///< ObjC->C Rewriter. 53 RewriteTest, ///< Rewriter playground 54 RunAnalysis, ///< Run one or more source code analyses. 55 MigrateSource, ///< Run migrator. 56 RunPreprocessorOnly ///< Just lex, no output. 57 }; 58} 59 60enum InputKind { 61 IK_None, 62 IK_Asm, 63 IK_C, 64 IK_CXX, 65 IK_ObjC, 66 IK_ObjCXX, 67 IK_PreprocessedC, 68 IK_PreprocessedCXX, 69 IK_PreprocessedObjC, 70 IK_PreprocessedObjCXX, 71 IK_OpenCL, 72 IK_CUDA, 73 IK_AST, 74 IK_LLVM_IR 75}; 76 77 78/// \brief An input file for the front end. 79class FrontendInputFile { 80 /// \brief The file name, or "-" to read from standard input. 81 std::string File; 82 83 llvm::MemoryBuffer *Buffer; 84 85 /// \brief The kind of input, e.g., C source, AST file, LLVM IR. 86 InputKind Kind; 87 88 /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input). 89 bool IsSystem; 90 91public: 92 FrontendInputFile() : Buffer(0), Kind(IK_None) { } 93 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) 94 : File(File.str()), Buffer(0), Kind(Kind), IsSystem(IsSystem) { } 95 FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind, 96 bool IsSystem = false) 97 : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { } 98 99 InputKind getKind() const { return Kind; } 100 bool isSystem() const { return IsSystem; } 101 102 bool isEmpty() const { return File.empty() && Buffer == 0; } 103 bool isFile() const { return !isBuffer(); } 104 bool isBuffer() const { return Buffer != 0; } 105 106 StringRef getFile() const { 107 assert(isFile()); 108 return File; 109 } 110 llvm::MemoryBuffer *getBuffer() const { 111 assert(isBuffer()); 112 return Buffer; 113 } 114}; 115 116/// FrontendOptions - Options for controlling the behavior of the frontend. 117class FrontendOptions { 118public: 119 unsigned DisableFree : 1; ///< Disable memory freeing on exit. 120 unsigned RelocatablePCH : 1; ///< When generating PCH files, 121 /// instruct the AST writer to create 122 /// relocatable PCH files. 123 unsigned ShowHelp : 1; ///< Show the -help text. 124 unsigned ShowStats : 1; ///< Show frontend performance 125 /// metrics and statistics. 126 unsigned ShowTimers : 1; ///< Show timers for individual 127 /// actions. 128 unsigned ShowVersion : 1; ///< Show the -version text. 129 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are 130 /// unfixable errors. 131 unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings. 132 unsigned FixAndRecompile : 1; ///< Apply fixes and recompile. 133 unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files. 134 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the 135 /// migrator can fix them 136 unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to 137 /// speed up parsing in cases you do 138 /// not need them (e.g. with code 139 /// completion). 140 unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the 141 ///< global module index if available. 142 unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the 143 ///< global module index if needed. 144 unsigned ASTDumpLookups : 1; ///< Whether we include lookup table 145 ///< dumps in AST dumps. 146 147 CodeCompleteOptions CodeCompleteOpts; 148 149 enum { 150 ARCMT_None, 151 ARCMT_Check, 152 ARCMT_Modify, 153 ARCMT_Migrate 154 } ARCMTAction; 155 156 enum { 157 ObjCMT_None = 0, 158 /// \brief Enable migration to modern ObjC literals. 159 ObjCMT_Literals = 0x1, 160 /// \brief Enable migration to modern ObjC subscripting. 161 ObjCMT_Subscripting = 0x2, 162 /// \brief Enable migration to modern ObjC readonly property. 163 ObjCMT_ReadonlyProperty = 0x4, 164 /// \brief Enable migration to modern ObjC readwrite property. 165 ObjCMT_ReadwriteProperty = 0x8, 166 /// \brief Enable migration to modern ObjC property. 167 ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty), 168 /// \brief Enable annotation of ObjCMethods of all kinds. 169 ObjCMT_Annotation = 0x10, 170 /// \brief Enable migration of ObjC methods to 'instancetype'. 171 ObjCMT_Instancetype = 0x20, 172 /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros. 173 ObjCMT_NsMacros = 0x40, 174 /// \brief Enable migration to add conforming protocols. 175 ObjCMT_ProtocolConformance = 0x80, 176 /// \brief prefer 'atomic' property over 'nonatomic'. 177 ObjCMT_AtomicProperty = 0x100, 178 /// \brief annotate property with NS_RETURNS_INNER_POINTER 179 ObjCMT_ReturnsInnerPointerProperty = 0x200, 180 /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute 181 ObjCMT_NsAtomicIOSOnlyProperty = 0x400, 182 ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | 183 ObjCMT_Annotation | ObjCMT_Instancetype | 184 ObjCMT_NsMacros | ObjCMT_ProtocolConformance | 185 ObjCMT_NsAtomicIOSOnlyProperty), 186 ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | ObjCMT_MigrateDecls) 187 }; 188 unsigned ObjCMTAction; 189 190 std::string MTMigrateDir; 191 std::string ARCMTMigrateReportOut; 192 193 /// The input files and their types. 194 std::vector<FrontendInputFile> Inputs; 195 196 /// The output file, if any. 197 std::string OutputFile; 198 199 /// If given, the new suffix for fix-it rewritten files. 200 std::string FixItSuffix; 201 202 /// If given, filter dumped AST Decl nodes by this substring. 203 std::string ASTDumpFilter; 204 205 /// If given, enable code completion at the provided location. 206 ParsedSourceLocation CodeCompletionAt; 207 208 /// The frontend action to perform. 209 frontend::ActionKind ProgramAction; 210 211 /// The name of the action to run when using a plugin action. 212 std::string ActionName; 213 214 /// Args to pass to the plugin 215 std::vector<std::string> PluginArgs; 216 217 /// The list of plugin actions to run in addition to the normal action. 218 std::vector<std::string> AddPluginActions; 219 220 /// Args to pass to the additional plugins 221 std::vector<std::vector<std::string> > AddPluginArgs; 222 223 /// The list of plugins to load. 224 std::vector<std::string> Plugins; 225 226 /// \brief The list of AST files to merge. 227 std::vector<std::string> ASTMergeFiles; 228 229 /// \brief A list of arguments to forward to LLVM's option processing; this 230 /// should only be used for debugging and experimental features. 231 std::vector<std::string> LLVMArgs; 232 233 /// \brief File name of the file that will provide record layouts 234 /// (in the format produced by -fdump-record-layouts). 235 std::string OverrideRecordLayoutsFile; 236 237public: 238 FrontendOptions() : 239 DisableFree(false), RelocatablePCH(false), ShowHelp(false), 240 ShowStats(false), ShowTimers(false), ShowVersion(false), 241 FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false), 242 FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false), 243 SkipFunctionBodies(false), UseGlobalModuleIndex(true), 244 GenerateGlobalModuleIndex(true), ASTDumpLookups(false), 245 ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None), 246 ProgramAction(frontend::ParseSyntaxOnly) 247 {} 248 249 /// getInputKindForExtension - Return the appropriate input kind for a file 250 /// extension. For example, "c" would return IK_C. 251 /// 252 /// \return The input kind for the extension, or IK_None if the extension is 253 /// not recognized. 254 static InputKind getInputKindForExtension(StringRef Extension); 255}; 256 257} // end namespace clang 258 259#endif 260