clang API Documentation
00001 //===--- FrontendOptions.h --------------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H 00011 #define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H 00012 00013 #include "clang/Frontend/CommandLineSourceLoc.h" 00014 #include "clang/Sema/CodeCompleteOptions.h" 00015 #include "llvm/ADT/StringRef.h" 00016 #include <string> 00017 #include <vector> 00018 00019 namespace llvm { 00020 class MemoryBuffer; 00021 } 00022 00023 namespace clang { 00024 00025 namespace frontend { 00026 enum ActionKind { 00027 ASTDeclList, ///< Parse ASTs and list Decl nodes. 00028 ASTDump, ///< Parse ASTs and dump them. 00029 ASTPrint, ///< Parse ASTs and print them. 00030 ASTView, ///< Parse ASTs and view them in Graphviz. 00031 DumpRawTokens, ///< Dump out raw tokens. 00032 DumpTokens, ///< Dump out preprocessed tokens. 00033 EmitAssembly, ///< Emit a .s file. 00034 EmitBC, ///< Emit a .bc file. 00035 EmitHTML, ///< Translate input source into HTML. 00036 EmitLLVM, ///< Emit a .ll file. 00037 EmitLLVMOnly, ///< Generate LLVM IR, but do not emit anything. 00038 EmitCodeGenOnly, ///< Generate machine code, but don't emit anything. 00039 EmitObj, ///< Emit a .o file. 00040 FixIt, ///< Parse and apply any fixits to the source. 00041 GenerateModule, ///< Generate pre-compiled module. 00042 GeneratePCH, ///< Generate pre-compiled header. 00043 GeneratePTH, ///< Generate pre-tokenized header. 00044 InitOnly, ///< Only execute frontend initialization. 00045 ModuleFileInfo, ///< Dump information about a module file. 00046 VerifyPCH, ///< Load and verify that a PCH file is usable. 00047 ParseSyntaxOnly, ///< Parse and perform semantic analysis. 00048 PluginAction, ///< Run a plugin action, \see ActionName. 00049 PrintDeclContext, ///< Print DeclContext and their Decls. 00050 PrintPreamble, ///< Print the "preamble" of the input file 00051 PrintPreprocessedInput, ///< -E mode. 00052 RewriteMacros, ///< Expand macros but not \#includes. 00053 RewriteObjC, ///< ObjC->C Rewriter. 00054 RewriteTest, ///< Rewriter playground 00055 RunAnalysis, ///< Run one or more source code analyses. 00056 MigrateSource, ///< Run migrator. 00057 RunPreprocessorOnly ///< Just lex, no output. 00058 }; 00059 } 00060 00061 enum InputKind { 00062 IK_None, 00063 IK_Asm, 00064 IK_C, 00065 IK_CXX, 00066 IK_ObjC, 00067 IK_ObjCXX, 00068 IK_PreprocessedC, 00069 IK_PreprocessedCXX, 00070 IK_PreprocessedObjC, 00071 IK_PreprocessedObjCXX, 00072 IK_OpenCL, 00073 IK_CUDA, 00074 IK_AST, 00075 IK_LLVM_IR 00076 }; 00077 00078 00079 /// \brief An input file for the front end. 00080 class FrontendInputFile { 00081 /// \brief The file name, or "-" to read from standard input. 00082 std::string File; 00083 00084 llvm::MemoryBuffer *Buffer; 00085 00086 /// \brief The kind of input, e.g., C source, AST file, LLVM IR. 00087 InputKind Kind; 00088 00089 /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input). 00090 bool IsSystem; 00091 00092 public: 00093 FrontendInputFile() : Buffer(nullptr), Kind(IK_None) { } 00094 FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) 00095 : File(File.str()), Buffer(nullptr), Kind(Kind), IsSystem(IsSystem) { } 00096 FrontendInputFile(llvm::MemoryBuffer *buffer, InputKind Kind, 00097 bool IsSystem = false) 00098 : Buffer(buffer), Kind(Kind), IsSystem(IsSystem) { } 00099 00100 InputKind getKind() const { return Kind; } 00101 bool isSystem() const { return IsSystem; } 00102 00103 bool isEmpty() const { return File.empty() && Buffer == nullptr; } 00104 bool isFile() const { return !isBuffer(); } 00105 bool isBuffer() const { return Buffer != nullptr; } 00106 00107 StringRef getFile() const { 00108 assert(isFile()); 00109 return File; 00110 } 00111 llvm::MemoryBuffer *getBuffer() const { 00112 assert(isBuffer()); 00113 return Buffer; 00114 } 00115 }; 00116 00117 /// FrontendOptions - Options for controlling the behavior of the frontend. 00118 class FrontendOptions { 00119 public: 00120 unsigned DisableFree : 1; ///< Disable memory freeing on exit. 00121 unsigned RelocatablePCH : 1; ///< When generating PCH files, 00122 /// instruct the AST writer to create 00123 /// relocatable PCH files. 00124 unsigned ShowHelp : 1; ///< Show the -help text. 00125 unsigned ShowStats : 1; ///< Show frontend performance 00126 /// metrics and statistics. 00127 unsigned ShowTimers : 1; ///< Show timers for individual 00128 /// actions. 00129 unsigned ShowVersion : 1; ///< Show the -version text. 00130 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are 00131 /// unfixable errors. 00132 unsigned FixOnlyWarnings : 1; ///< Apply fixes only for warnings. 00133 unsigned FixAndRecompile : 1; ///< Apply fixes and recompile. 00134 unsigned FixToTemporaries : 1; ///< Apply fixes to temporary files. 00135 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the 00136 /// migrator can fix them 00137 unsigned SkipFunctionBodies : 1; ///< Skip over function bodies to 00138 /// speed up parsing in cases you do 00139 /// not need them (e.g. with code 00140 /// completion). 00141 unsigned UseGlobalModuleIndex : 1; ///< Whether we can use the 00142 ///< global module index if available. 00143 unsigned GenerateGlobalModuleIndex : 1; ///< Whether we can generate the 00144 ///< global module index if needed. 00145 unsigned ASTDumpDecls : 1; ///< Whether we include declaration 00146 ///< dumps in AST dumps. 00147 unsigned ASTDumpLookups : 1; ///< Whether we include lookup table 00148 ///< dumps in AST dumps. 00149 00150 CodeCompleteOptions CodeCompleteOpts; 00151 00152 enum { 00153 ARCMT_None, 00154 ARCMT_Check, 00155 ARCMT_Modify, 00156 ARCMT_Migrate 00157 } ARCMTAction; 00158 00159 enum { 00160 ObjCMT_None = 0, 00161 /// \brief Enable migration to modern ObjC literals. 00162 ObjCMT_Literals = 0x1, 00163 /// \brief Enable migration to modern ObjC subscripting. 00164 ObjCMT_Subscripting = 0x2, 00165 /// \brief Enable migration to modern ObjC readonly property. 00166 ObjCMT_ReadonlyProperty = 0x4, 00167 /// \brief Enable migration to modern ObjC readwrite property. 00168 ObjCMT_ReadwriteProperty = 0x8, 00169 /// \brief Enable migration to modern ObjC property. 00170 ObjCMT_Property = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty), 00171 /// \brief Enable annotation of ObjCMethods of all kinds. 00172 ObjCMT_Annotation = 0x10, 00173 /// \brief Enable migration of ObjC methods to 'instancetype'. 00174 ObjCMT_Instancetype = 0x20, 00175 /// \brief Enable migration to NS_ENUM/NS_OPTIONS macros. 00176 ObjCMT_NsMacros = 0x40, 00177 /// \brief Enable migration to add conforming protocols. 00178 ObjCMT_ProtocolConformance = 0x80, 00179 /// \brief prefer 'atomic' property over 'nonatomic'. 00180 ObjCMT_AtomicProperty = 0x100, 00181 /// \brief annotate property with NS_RETURNS_INNER_POINTER 00182 ObjCMT_ReturnsInnerPointerProperty = 0x200, 00183 /// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute 00184 ObjCMT_NsAtomicIOSOnlyProperty = 0x400, 00185 /// \brief Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods. 00186 ObjCMT_DesignatedInitializer = 0x800, 00187 /// \brief Enable converting setter/getter expressions to property-dot syntx. 00188 ObjCMT_PropertyDotSyntax = 0x1000, 00189 ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | 00190 ObjCMT_Annotation | ObjCMT_Instancetype | 00191 ObjCMT_NsMacros | ObjCMT_ProtocolConformance | 00192 ObjCMT_NsAtomicIOSOnlyProperty | 00193 ObjCMT_DesignatedInitializer), 00194 ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | 00195 ObjCMT_MigrateDecls | ObjCMT_PropertyDotSyntax) 00196 }; 00197 unsigned ObjCMTAction; 00198 std::string ObjCMTWhiteListPath; 00199 00200 std::string MTMigrateDir; 00201 std::string ARCMTMigrateReportOut; 00202 00203 /// The input files and their types. 00204 std::vector<FrontendInputFile> Inputs; 00205 00206 /// The output file, if any. 00207 std::string OutputFile; 00208 00209 /// If given, the new suffix for fix-it rewritten files. 00210 std::string FixItSuffix; 00211 00212 /// If given, filter dumped AST Decl nodes by this substring. 00213 std::string ASTDumpFilter; 00214 00215 /// If given, enable code completion at the provided location. 00216 ParsedSourceLocation CodeCompletionAt; 00217 00218 /// The frontend action to perform. 00219 frontend::ActionKind ProgramAction; 00220 00221 /// The name of the action to run when using a plugin action. 00222 std::string ActionName; 00223 00224 /// Args to pass to the plugin 00225 std::vector<std::string> PluginArgs; 00226 00227 /// The list of plugin actions to run in addition to the normal action. 00228 std::vector<std::string> AddPluginActions; 00229 00230 /// Args to pass to the additional plugins 00231 std::vector<std::vector<std::string> > AddPluginArgs; 00232 00233 /// The list of plugins to load. 00234 std::vector<std::string> Plugins; 00235 00236 /// \brief The list of additional prebuilt module files to load before 00237 /// processing the input. 00238 std::vector<std::string> ModuleFiles; 00239 00240 /// \brief The list of AST files to merge. 00241 std::vector<std::string> ASTMergeFiles; 00242 00243 /// \brief A list of arguments to forward to LLVM's option processing; this 00244 /// should only be used for debugging and experimental features. 00245 std::vector<std::string> LLVMArgs; 00246 00247 /// \brief File name of the file that will provide record layouts 00248 /// (in the format produced by -fdump-record-layouts). 00249 std::string OverrideRecordLayoutsFile; 00250 00251 public: 00252 FrontendOptions() : 00253 DisableFree(false), RelocatablePCH(false), ShowHelp(false), 00254 ShowStats(false), ShowTimers(false), ShowVersion(false), 00255 FixWhatYouCan(false), FixOnlyWarnings(false), FixAndRecompile(false), 00256 FixToTemporaries(false), ARCMTMigrateEmitARCErrors(false), 00257 SkipFunctionBodies(false), UseGlobalModuleIndex(true), 00258 GenerateGlobalModuleIndex(true), ASTDumpDecls(false), ASTDumpLookups(false), 00259 ARCMTAction(ARCMT_None), ObjCMTAction(ObjCMT_None), 00260 ProgramAction(frontend::ParseSyntaxOnly) 00261 {} 00262 00263 /// getInputKindForExtension - Return the appropriate input kind for a file 00264 /// extension. For example, "c" would return IK_C. 00265 /// 00266 /// \return The input kind for the extension, or IK_None if the extension is 00267 /// not recognized. 00268 static InputKind getInputKindForExtension(StringRef Extension); 00269 }; 00270 00271 } // end namespace clang 00272 00273 #endif