zcov: / include/clang/Frontend/FrontendAction.h


Files: 1 Branches Taken: 45.5% 5 / 11
Generated: 2010-02-10 01:31 Branches Executed: 81.8% 9 / 11
Line Coverage: 100.0% 23 / 23


Programs: 7 Runs 14727


       1                 : //===-- FrontendAction.h - Generic Frontend Action Interface ----*- 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_FRONTENDACTION_H
      11                 : #define LLVM_CLANG_FRONTEND_FRONTENDACTION_H
      12                 : 
      13                 : #include "llvm/ADT/StringRef.h"
      14                 : #include "llvm/ADT/OwningPtr.h"
      15                 : #include <string>
      16                 : 
      17                 : namespace clang {
      18                 : class ASTUnit;
      19                 : class ASTConsumer;
      20                 : class CompilerInstance;
      21                 : class ASTMergeAction;
      22                 : 
      23                 : /// FrontendAction - Abstract base class for actions which can be performed by
      24                 : /// the frontend.
      25                 : class FrontendAction {
      26                 :   std::string CurrentFile;
      27                 :   llvm::OwningPtr<ASTUnit> CurrentASTUnit;
      28                 :   CompilerInstance *Instance;
      29                 :   friend class ASTMergeAction;
      30                 : 
      31                 : protected:
      32                 :   /// @name Implementation Action Interface
      33                 :   /// @{
      34                 : 
      35                 :   /// CreateASTConsumer - Create the AST consumer object for this action, if
      36                 :   /// supported.
      37                 :   ///
      38                 :   /// This routine is called as part of \see BeginSourceAction(), which will
      39                 :   /// fail if the AST consumer cannot be created. This will not be called if the
      40                 :   /// action has indicated that it only uses the preprocessor.
      41                 :   ///
      42                 :   /// \param CI - The current compiler instance, provided as a convenience, \see
      43                 :   /// getCompilerInstance().
      44                 :   ///
      45                 :   /// \param InFile - The current input file, provided as a convenience, \see
      46                 :   /// getCurrentFile().
      47                 :   ///
      48                 :   /// \return The new AST consumer, or 0 on failure.
      49                 :   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
      50                 :                                          llvm::StringRef InFile) = 0;
      51                 : 
      52                 :   /// BeginSourceFileAction - Callback at the start of processing a single
      53                 :   /// input.
      54                 :   ///
      55                 :   /// \return True on success; on failure \see ExecutionAction() and
      56                 :   /// EndSourceFileAction() will not be called.
      57                 :   virtual bool BeginSourceFileAction(CompilerInstance &CI,
      58             2510:                                      llvm::StringRef Filename) {
      59             2510:     return true;
      60                 :   }
      61                 : 
      62                 :   /// ExecuteAction - Callback to run the program action, using the initialized
      63                 :   /// compiler instance.
      64                 :   ///
      65                 :   /// This routine is guaranteed to only be called between \see
      66                 :   /// BeginSourceFileAction() and \see EndSourceFileAction().
      67                 :   virtual void ExecuteAction() = 0;
      68                 : 
      69                 :   /// EndSourceFileAction - Callback at the end of processing a single input;
      70                 :   /// this is guaranteed to only be called following a successful call to
      71                 :   /// BeginSourceFileAction (and BeingSourceFile).
      72             2507:   virtual void EndSourceFileAction() {}
      73                 : 
      74                 :   /// @}
      75                 : 
      76                 : public:
      77                 :   FrontendAction();
      78                 :   virtual ~FrontendAction();
      79                 : 
      80                 :   /// @name Compiler Instance Access
      81                 :   /// @{
      82                 : 
      83             7572:   CompilerInstance &getCompilerInstance() const {
                        0: branch 0 not taken
                     7572: branch 1 taken
      84             7572:     assert(Instance && "Compiler instance not registered!");
      85             7572:     return *Instance;
      86                 :   }
      87                 : 
      88             5045:   void setCompilerInstance(CompilerInstance *Value) { Instance = Value; }
      89                 : 
      90                 :   /// @}
      91                 :   /// @name Current File Information
      92                 :   /// @{
      93                 : 
      94             7560:   bool isCurrentFileAST() const {
                     7560: branch 1 taken
                        0: branch 2 not taken
      95             7560:     assert(!CurrentFile.empty() && "No current file!");
      96             7560:     return CurrentASTUnit != 0;
      97                 :   }
      98                 : 
      99             2781:   const std::string &getCurrentFile() const {
                     2781: branch 1 taken
                        0: branch 2 not taken
     100             2781:     assert(!CurrentFile.empty() && "No current file!");
     101             2781:     return CurrentFile;
     102                 :   }
     103                 : 
     104                 :   ASTUnit &getCurrentASTUnit() const {
     105                 :     assert(!CurrentASTUnit && "No current AST unit!");
     106                 :     return *CurrentASTUnit;
     107                 :   }
     108                 : 
     109                1:   ASTUnit *takeCurrentASTUnit() {
     110                1:     return CurrentASTUnit.take();
     111                 :   }
     112                 : 
     113                 :   void setCurrentFile(llvm::StringRef Value, ASTUnit *AST = 0);
     114                 : 
     115                 :   /// @}
     116                 :   /// @name Supported Modes
     117                 :   /// @{
     118                 : 
     119                 :   /// usesPreprocessorOnly - Does this action only use the preprocessor? If so
     120                 :   /// no AST context will be created and this action will be invalid with PCH
     121                 :   /// inputs.
     122                 :   virtual bool usesPreprocessorOnly() const = 0;
     123                 : 
     124                 :   /// usesCompleteTranslationUnit - For AST based actions, should the
     125                 :   /// translation unit be completed?
     126             2192:   virtual bool usesCompleteTranslationUnit() { return true; }
     127                 : 
     128                 :   /// hasPCHSupport - Does this action support use with PCH?
     129               35:   virtual bool hasPCHSupport() const { return !usesPreprocessorOnly(); }
     130                 : 
     131                 :   /// hasASTSupport - Does this action support use with AST files?
     132                2:   virtual bool hasASTSupport() const { return !usesPreprocessorOnly(); }
     133                 : 
     134                 :   /// hasCodeCompletionSupport - Does this action support use with code
     135                 :   /// completion?
     136              949:   virtual bool hasCodeCompletionSupport() const { return false; }
     137                 : 
     138                 :   /// @}
     139                 :   /// @name Public Action Interface
     140                 :   /// @{
     141                 : 
     142                 :   /// BeginSourceFile - Prepare the action for processing the input file \arg
     143                 :   /// Filename; this is run after the options and frontend have been
     144                 :   /// initialized, but prior to executing any per-file processing.
     145                 :   ///
     146                 :   /// \param CI - The compiler instance this action is being run from. The
     147                 :   /// action may store and use this object up until the matching EndSourceFile
     148                 :   /// action.
     149                 :   ///
     150                 :   /// \param Filename - The input filename, which will be made available to
     151                 :   /// clients via \see getCurrentFile().
     152                 :   ///
     153                 :   /// \param IsAST - Indicates whether this is an AST input. AST inputs require
     154                 :   /// special handling, since the AST file itself contains several objects which
     155                 :   /// would normally be owned by the CompilerInstance. When processing AST input
     156                 :   /// files, these objects should generally not be initialized in the
     157                 :   /// CompilerInstance -- they will automatically be shared with the AST file in
     158                 :   /// between \see BeginSourceFile() and \see EndSourceFile().
     159                 :   ///
     160                 :   /// \return True on success; the compilation of this file should be aborted
     161                 :   /// and neither Execute nor EndSourceFile should be called.
     162                 :   bool BeginSourceFile(CompilerInstance &CI, llvm::StringRef Filename,
     163                 :                        bool IsAST = false);
     164                 : 
     165                 :   /// Execute - Set the source managers main input file, and run the action.
     166                 :   void Execute();
     167                 : 
     168                 :   /// EndSourceFile - Perform any per-file post processing, deallocate per-file
     169                 :   /// objects, and run statistics and output file cleanup code.
     170                 :   void EndSourceFile();
     171                 : 
     172                 :   /// @}
     173                 : };
     174                 : 
     175                 : /// ASTFrontendAction - Abstract base class to use for AST consumer based
     176                 : /// frontend actions.
                     2239: branch 2 taken
                        0: branch 6 not taken
     177             4478: class ASTFrontendAction : public FrontendAction {
     178                 :   /// ExecuteAction - Implement the ExecuteAction interface by running Sema on
     179                 :   /// the already initialized AST consumer.
     180                 :   ///
     181                 :   /// This will also take care of instantiating a code completion consumer if
     182                 :   /// the user requested it and the action supports it.
     183                 :   virtual void ExecuteAction();
     184                 : 
     185                 : public:
     186             2276:   virtual bool usesPreprocessorOnly() const { return false; }
     187                 : };
     188                 : 
     189                 : /// PreprocessorFrontendAction - Abstract base class to use for preprocessor
     190                 : /// based frontend actions.
                        0: branch 1 not taken
                      283: branch 2 taken
                        0: branch 6 not taken
     191              566: class PreprocessorFrontendAction : public FrontendAction {
     192                 : protected:
     193                 :   /// CreateASTConsumer - Provide a default implementation which returns aborts,
     194                 :   /// this method should never be called by FrontendAction clients.
     195                 :   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     196                 :                                          llvm::StringRef InFile);
     197                 : 
     198                 : public:
     199              283:   virtual bool usesPreprocessorOnly() const { return true; }
     200                 : };
     201                 : 
     202                 : }  // end namespace clang
     203                 : 
     204                 : #endif

Generated: 2010-02-10 01:31 by zcov