clang API Documentation

FrontendOptions.h
Go to the documentation of this file.
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 "llvm/ADT/StringRef.h"
00015 #include <string>
00016 #include <vector>
00017 
00018 namespace clang {
00019 
00020 namespace frontend {
00021   enum ActionKind {
00022     ASTDump,                ///< Parse ASTs and dump them.
00023     ASTDumpXML,             ///< Parse ASTs and dump them in XML.
00024     ASTPrint,               ///< Parse ASTs and print them.
00025     ASTView,                ///< Parse ASTs and view them in Graphviz.
00026     DumpRawTokens,          ///< Dump out raw tokens.
00027     DumpTokens,             ///< Dump out preprocessed tokens.
00028     EmitAssembly,           ///< Emit a .s file.
00029     EmitBC,                 ///< Emit a .bc file.
00030     EmitHTML,               ///< Translate input source into HTML.
00031     EmitLLVM,               ///< Emit a .ll file.
00032     EmitLLVMOnly,           ///< Generate LLVM IR, but do not emit anything.
00033     EmitCodeGenOnly,        ///< Generate machine code, but don't emit anything.
00034     EmitObj,                ///< Emit a .o file.
00035     FixIt,                  ///< Parse and apply any fixits to the source.
00036     GenerateModule,         ///< Generate pre-compiled module.
00037     GeneratePCH,            ///< Generate pre-compiled header.
00038     GeneratePTH,            ///< Generate pre-tokenized header.
00039     InitOnly,               ///< Only execute frontend initialization.
00040     ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
00041     PluginAction,           ///< Run a plugin action, \see ActionName.
00042     PrintDeclContext,       ///< Print DeclContext and their Decls.
00043     PrintPreamble,          ///< Print the "preamble" of the input file
00044     PrintPreprocessedInput, ///< -E mode.
00045     RewriteMacros,          ///< Expand macros but not #includes.
00046     RewriteObjC,            ///< ObjC->C Rewriter.
00047     RewriteTest,            ///< Rewriter playground
00048     RunAnalysis,            ///< Run one or more source code analyses.
00049     MigrateSource,          ///< Run migrator.
00050     RunPreprocessorOnly     ///< Just lex, no output.
00051   };
00052 }
00053 
00054 enum InputKind {
00055   IK_None,
00056   IK_Asm,
00057   IK_C,
00058   IK_CXX,
00059   IK_ObjC,
00060   IK_ObjCXX,
00061   IK_PreprocessedC,
00062   IK_PreprocessedCXX,
00063   IK_PreprocessedObjC,
00064   IK_PreprocessedObjCXX,
00065   IK_OpenCL,
00066   IK_CUDA,
00067   IK_AST,
00068   IK_LLVM_IR
00069 };
00070 
00071   
00072 /// \brief An input file for the front end.
00073 struct FrontendInputFile {
00074   /// \brief The file name, or "-" to read from standard input.
00075   std::string File;
00076 
00077   /// \brief The kind of input, e.g., C source, AST file, LLVM IR.
00078   InputKind Kind;
00079 
00080   /// \brief Whether we're dealing with a 'system' input (vs. a 'user' input).
00081   bool IsSystem;
00082   
00083   FrontendInputFile() : Kind(IK_None) { }
00084   FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false)
00085     : File(File.str()), Kind(Kind), IsSystem(IsSystem) { }
00086 };
00087   
00088 /// FrontendOptions - Options for controlling the behavior of the frontend.
00089 class FrontendOptions {
00090 public:
00091   unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
00092   unsigned RelocatablePCH : 1;             ///< When generating PCH files,
00093                                            /// instruct the AST writer to create
00094                                            /// relocatable PCH files.
00095   unsigned ShowHelp : 1;                   ///< Show the -help text.
00096   unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion
00097                                            /// results.
00098   unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code
00099                                                  /// completion results.
00100   unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in
00101                                                   /// code completion results.
00102   unsigned ShowStats : 1;                  ///< Show frontend performance
00103                                            /// metrics and statistics.
00104   unsigned ShowTimers : 1;                 ///< Show timers for individual
00105                                            /// actions.
00106   unsigned ShowVersion : 1;                ///< Show the -version text.
00107   unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
00108                                            /// unfixable errors.
00109   unsigned FixOnlyWarnings : 1;            ///< Apply fixes only for warnings.
00110   unsigned FixAndRecompile : 1;            ///< Apply fixes and recompile.
00111   unsigned FixToTemporaries : 1;           ///< Apply fixes to temporary files.
00112   unsigned ARCMTMigrateEmitARCErrors : 1;  /// Emit ARC errors even if the
00113                                            /// migrator can fix them
00114   unsigned SkipFunctionBodies : 1;         ///< Skip over function bodies to
00115                                            /// speed up parsing in cases you do
00116                                            /// not need them (e.g. with code
00117                                            /// completion).
00118 
00119   enum {
00120     ARCMT_None,
00121     ARCMT_Check,
00122     ARCMT_Modify,
00123     ARCMT_Migrate
00124   } ARCMTAction;
00125 
00126   enum {
00127     ObjCMT_None = 0,
00128     /// \brief Enable migration to modern ObjC literals.
00129     ObjCMT_Literals = 0x1,
00130     /// \brief Enable migration to modern ObjC subscripting.
00131     ObjCMT_Subscripting = 0x2
00132   };
00133   unsigned ObjCMTAction;
00134 
00135   std::string MTMigrateDir;
00136   std::string ARCMTMigrateReportOut;
00137 
00138   /// The input files and their types.
00139   std::vector<FrontendInputFile> Inputs;
00140 
00141   /// The output file, if any.
00142   std::string OutputFile;
00143 
00144   /// If given, the new suffix for fix-it rewritten files.
00145   std::string FixItSuffix;
00146 
00147   /// If given, enable code completion at the provided location.
00148   ParsedSourceLocation CodeCompletionAt;
00149 
00150   /// The frontend action to perform.
00151   frontend::ActionKind ProgramAction;
00152 
00153   /// The name of the action to run when using a plugin action.
00154   std::string ActionName;
00155 
00156   /// Args to pass to the plugin
00157   std::vector<std::string> PluginArgs;
00158 
00159   /// The list of plugin actions to run in addition to the normal action.
00160   std::vector<std::string> AddPluginActions;
00161 
00162   /// Args to pass to the additional plugins
00163   std::vector<std::vector<std::string> > AddPluginArgs;
00164 
00165   /// The list of plugins to load.
00166   std::vector<std::string> Plugins;
00167 
00168   /// \brief The list of AST files to merge.
00169   std::vector<std::string> ASTMergeFiles;
00170 
00171   /// \brief A list of arguments to forward to LLVM's option processing; this
00172   /// should only be used for debugging and experimental features.
00173   std::vector<std::string> LLVMArgs;
00174 
00175   /// \brief File name of the file that will provide record layouts
00176   /// (in the format produced by -fdump-record-layouts).
00177   std::string OverrideRecordLayoutsFile;
00178   
00179 public:
00180   FrontendOptions() {
00181     DisableFree = 0;
00182     ProgramAction = frontend::ParseSyntaxOnly;
00183     ActionName = "";
00184     RelocatablePCH = 0;
00185     ShowHelp = 0;
00186     ShowMacrosInCodeCompletion = 0;
00187     ShowCodePatternsInCodeCompletion = 0;
00188     ShowGlobalSymbolsInCodeCompletion = 1;
00189     ShowStats = 0;
00190     ShowTimers = 0;
00191     ShowVersion = 0;
00192     ARCMTAction = ARCMT_None;
00193     ARCMTMigrateEmitARCErrors = 0;
00194     SkipFunctionBodies = 0;
00195     ObjCMTAction = ObjCMT_None;
00196   }
00197 
00198   /// getInputKindForExtension - Return the appropriate input kind for a file
00199   /// extension. For example, "c" would return IK_C.
00200   ///
00201   /// \return The input kind for the extension, or IK_None if the extension is
00202   /// not recognized.
00203   static InputKind getInputKindForExtension(StringRef Extension);
00204 };
00205 
00206 }  // end namespace clang
00207 
00208 #endif