Home | History | Annotate | Download | only in AST
      1 //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- 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 //  This file defines the ASTConsumer class.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_CLANG_AST_ASTCONSUMER_H
     15 #define LLVM_CLANG_AST_ASTCONSUMER_H
     16 
     17 namespace clang {
     18   class ASTContext;
     19   class CXXMethodDecl;
     20   class CXXRecordDecl;
     21   class Decl;
     22   class DeclGroupRef;
     23   class ASTMutationListener;
     24   class ASTDeserializationListener; // layering violation because void* is ugly
     25   class SemaConsumer; // layering violation required for safe SemaConsumer
     26   class TagDecl;
     27   class VarDecl;
     28   class FunctionDecl;
     29   class ImportDecl;
     30 
     31 /// ASTConsumer - This is an abstract interface that should be implemented by
     32 /// clients that read ASTs.  This abstraction layer allows the client to be
     33 /// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
     34 class ASTConsumer {
     35   /// \brief Whether this AST consumer also requires information about
     36   /// semantic analysis.
     37   bool SemaConsumer;
     38 
     39   friend class SemaConsumer;
     40 
     41 public:
     42   ASTConsumer() : SemaConsumer(false) { }
     43 
     44   virtual ~ASTConsumer() {}
     45 
     46   /// Initialize - This is called to initialize the consumer, providing the
     47   /// ASTContext.
     48   virtual void Initialize(ASTContext &Context) {}
     49 
     50   /// HandleTopLevelDecl - Handle the specified top-level declaration.  This is
     51   /// called by the parser to process every top-level Decl*.
     52   ///
     53   /// \returns true to continue parsing, or false to abort parsing.
     54   virtual bool HandleTopLevelDecl(DeclGroupRef D);
     55 
     56   /// \brief This callback is invoked each time an inline (method or friend)
     57   /// function definition in a class is completed.
     58   virtual void HandleInlineFunctionDefinition(FunctionDecl *D) {}
     59 
     60   /// HandleInterestingDecl - Handle the specified interesting declaration. This
     61   /// is called by the AST reader when deserializing things that might interest
     62   /// the consumer. The default implementation forwards to HandleTopLevelDecl.
     63   virtual void HandleInterestingDecl(DeclGroupRef D);
     64 
     65   /// HandleTranslationUnit - This method is called when the ASTs for entire
     66   /// translation unit have been parsed.
     67   virtual void HandleTranslationUnit(ASTContext &Ctx) {}
     68 
     69   /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
     70   /// (e.g. struct, union, enum, class) is completed.  This allows the client to
     71   /// hack on the type, which can occur at any point in the file (because these
     72   /// can be defined in declspecs).
     73   virtual void HandleTagDeclDefinition(TagDecl *D) {}
     74 
     75   /// \brief This callback is invoked the first time each TagDecl is required to
     76   /// be complete.
     77   virtual void HandleTagDeclRequiredDefinition(const TagDecl *D) {}
     78 
     79   /// \brief Invoked when a function is implicitly instantiated.
     80   /// Note that at this point point it does not have a body, its body is
     81   /// instantiated at the end of the translation unit and passed to
     82   /// HandleTopLevelDecl.
     83   virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {}
     84 
     85   /// \brief Handle the specified top-level declaration that occurred inside
     86   /// and ObjC container.
     87   /// The default implementation ignored them.
     88   virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D);
     89 
     90   /// \brief Handle an ImportDecl that was implicitly created due to an
     91   /// inclusion directive.
     92   /// The default implementation passes it to HandleTopLevelDecl.
     93   virtual void HandleImplicitImportDecl(ImportDecl *D);
     94 
     95   /// CompleteTentativeDefinition - Callback invoked at the end of a translation
     96   /// unit to notify the consumer that the given tentative definition should be
     97   /// completed.
     98   ///
     99   /// The variable declaration itself will be a tentative
    100   /// definition. If it had an incomplete array type, its type will
    101   /// have already been changed to an array of size 1. However, the
    102   /// declaration remains a tentative definition and has not been
    103   /// modified by the introduction of an implicit zero initializer.
    104   virtual void CompleteTentativeDefinition(VarDecl *D) {}
    105 
    106   /// \brief Callback invoked when an MSInheritanceAttr has been attached to a
    107   /// CXXRecordDecl.
    108   virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
    109 
    110   /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
    111   // variable has been instantiated.
    112   virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {}
    113 
    114   /// \brief Callback involved at the end of a translation unit to
    115   /// notify the consumer that a vtable for the given C++ class is
    116   /// required.
    117   ///
    118   /// \param RD The class whose vtable was used.
    119   virtual void HandleVTable(CXXRecordDecl *RD) {}
    120 
    121   /// \brief If the consumer is interested in entities getting modified after
    122   /// their initial creation, it should return a pointer to
    123   /// an ASTMutationListener here.
    124   virtual ASTMutationListener *GetASTMutationListener() { return nullptr; }
    125 
    126   /// \brief If the consumer is interested in entities being deserialized from
    127   /// AST files, it should return a pointer to a ASTDeserializationListener here
    128   virtual ASTDeserializationListener *GetASTDeserializationListener() {
    129     return nullptr;
    130   }
    131 
    132   /// PrintStats - If desired, print any statistics.
    133   virtual void PrintStats() {}
    134 
    135   /// \brief This callback is called for each function if the Parser was
    136   /// initialized with \c SkipFunctionBodies set to \c true.
    137   ///
    138   /// \return \c true if the function's body should be skipped. The function
    139   /// body may be parsed anyway if it is needed (for instance, if it contains
    140   /// the code completion point or is constexpr).
    141   virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
    142 };
    143 
    144 } // end namespace clang.
    145 
    146 #endif
    147