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/Frontend/FrontendAction.h" 15 #include "llvm/ADT/StringRef.h" 16 #include <string> 17 #include <vector> 18 19 namespace clang { 20 21 namespace frontend { 22 enum ActionKind { 23 ASTDump, ///< Parse ASTs and dump them. 24 ASTDumpXML, ///< Parse ASTs and dump them in XML. 25 ASTPrint, ///< Parse ASTs and print them. 26 ASTView, ///< Parse ASTs and view them in Graphviz. 27 DumpRawTokens, ///< Dump out raw tokens. 28 DumpTokens, ///< Dump out preprocessed tokens. 29 EmitAssembly, ///< Emit a .s file. 30 EmitBC, ///< Emit a .bc file. 31 EmitHTML, ///< Translate input source into HTML. 32 EmitLLVM, ///< Emit a .ll file. 33 EmitLLVMOnly, ///< Generate LLVM IR, but do not emit anything. 34 EmitCodeGenOnly, ///< Generate machine code, but don't emit anything. 35 EmitObj, ///< Emit a .o file. 36 FixIt, ///< Parse and apply any fixits to the source. 37 GenerateModule, ///< Generate pre-compiled module. 38 GeneratePCH, ///< Generate pre-compiled header. 39 GeneratePTH, ///< Generate pre-tokenized header. 40 InitOnly, ///< Only execute frontend initialization. 41 ParseSyntaxOnly, ///< Parse and perform semantic analysis. 42 PluginAction, ///< Run a plugin action, \see ActionName. 43 PrintDeclContext, ///< Print DeclContext and their Decls. 44 PrintPreamble, ///< Print the "preamble" of the input file 45 PrintPreprocessedInput, ///< -E mode. 46 RewriteMacros, ///< Expand macros but not #includes. 47 RewriteObjC, ///< ObjC->C Rewriter. 48 RewriteTest, ///< Rewriter playground 49 RunAnalysis, ///< Run one or more source code analyses. 50 RunPreprocessorOnly ///< Just lex, no output. 51 }; 52 } 53 54 /// FrontendOptions - Options for controlling the behavior of the frontend. 55 class FrontendOptions { 56 public: 57 unsigned DisableFree : 1; ///< Disable memory freeing on exit. 58 unsigned RelocatablePCH : 1; ///< When generating PCH files, 59 /// instruct the AST writer to create 60 /// relocatable PCH files. 61 unsigned ShowHelp : 1; ///< Show the -help text. 62 unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion 63 /// results. 64 unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code 65 /// completion results. 66 unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in 67 /// code completion results. 68 unsigned ShowStats : 1; ///< Show frontend performance 69 /// metrics and statistics. 70 unsigned ShowTimers : 1; ///< Show timers for individual 71 /// actions. 72 unsigned ShowVersion : 1; ///< Show the -version text. 73 unsigned FixWhatYouCan : 1; ///< Apply fixes even if there are 74 /// unfixable errors. 75 unsigned ARCMTMigrateEmitARCErrors : 1; /// Emit ARC errors even if the 76 /// migrator can fix them 77 78 enum { 79 ARCMT_None, 80 ARCMT_Check, 81 ARCMT_Modify, 82 ARCMT_Migrate 83 } ARCMTAction; 84 85 std::string ARCMTMigrateDir; 86 std::string ARCMTMigrateReportOut; 87 88 /// The input files and their types. 89 std::vector<std::pair<InputKind, std::string> > Inputs; 90 91 /// The output file, if any. 92 std::string OutputFile; 93 94 /// If given, the new suffix for fix-it rewritten files. 95 std::string FixItSuffix; 96 97 /// If given, enable code completion at the provided location. 98 ParsedSourceLocation CodeCompletionAt; 99 100 /// The frontend action to perform. 101 frontend::ActionKind ProgramAction; 102 103 /// The name of the action to run when using a plugin action. 104 std::string ActionName; 105 106 /// Args to pass to the plugin 107 std::vector<std::string> PluginArgs; 108 109 /// The list of plugin actions to run in addition to the normal action. 110 std::vector<std::string> AddPluginActions; 111 112 /// Args to pass to the additional plugins 113 std::vector<std::vector<std::string> > AddPluginArgs; 114 115 /// The list of plugins to load. 116 std::vector<std::string> Plugins; 117 118 /// \brief The list of AST files to merge. 119 std::vector<std::string> ASTMergeFiles; 120 121 /// \brief A list of arguments to forward to LLVM's option processing; this 122 /// should only be used for debugging and experimental features. 123 std::vector<std::string> LLVMArgs; 124 125 public: 126 FrontendOptions() { 127 DisableFree = 0; 128 ProgramAction = frontend::ParseSyntaxOnly; 129 ActionName = ""; 130 RelocatablePCH = 0; 131 ShowHelp = 0; 132 ShowMacrosInCodeCompletion = 0; 133 ShowCodePatternsInCodeCompletion = 0; 134 ShowGlobalSymbolsInCodeCompletion = 1; 135 ShowStats = 0; 136 ShowTimers = 0; 137 ShowVersion = 0; 138 ARCMTAction = ARCMT_None; 139 ARCMTMigrateEmitARCErrors = 0; 140 } 141 142 /// getInputKindForExtension - Return the appropriate input kind for a file 143 /// extension. For example, "c" would return IK_C. 144 /// 145 /// \return The input kind for the extension, or IK_None if the extension is 146 /// not recognized. 147 static InputKind getInputKindForExtension(StringRef Extension); 148 }; 149 150 } // end namespace clang 151 152 #endif 153