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 CXXRecordDecl;
     20   class DeclGroupRef;
     21   class HandleTagDeclDefinition;
     22   class ASTMutationListener;
     23   class ASTDeserializationListener; // layering violation because void* is ugly
     24   class SemaConsumer; // layering violation required for safe SemaConsumer
     25   class TagDecl;
     26   class VarDecl;
     27 
     28 /// ASTConsumer - This is an abstract interface that should be implemented by
     29 /// clients that read ASTs.  This abstraction layer allows the client to be
     30 /// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
     31 class ASTConsumer {
     32   /// \brief Whether this AST consumer also requires information about
     33   /// semantic analysis.
     34   bool SemaConsumer;
     35 
     36   friend class SemaConsumer;
     37 
     38 public:
     39   ASTConsumer() : SemaConsumer(false) { }
     40 
     41   virtual ~ASTConsumer() {}
     42 
     43   /// Initialize - This is called to initialize the consumer, providing the
     44   /// ASTContext.
     45   virtual void Initialize(ASTContext &Context) {}
     46 
     47   /// HandleTopLevelDecl - Handle the specified top-level declaration.  This is
     48   /// called by the parser to process every top-level Decl*. Note that D can be
     49   /// the head of a chain of Decls (e.g. for `int a, b` the chain will have two
     50   /// elements). Use Decl::getNextDeclarator() to walk the chain.
     51   virtual void HandleTopLevelDecl(DeclGroupRef D);
     52 
     53   /// HandleInterestingDecl - Handle the specified interesting declaration. This
     54   /// is called by the AST reader when deserializing things that might interest
     55   /// the consumer. The default implementation forwards to HandleTopLevelDecl.
     56   virtual void HandleInterestingDecl(DeclGroupRef D);
     57 
     58   /// HandleTranslationUnit - This method is called when the ASTs for entire
     59   /// translation unit have been parsed.
     60   virtual void HandleTranslationUnit(ASTContext &Ctx) {}
     61 
     62   /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
     63   /// (e.g. struct, union, enum, class) is completed.  This allows the client to
     64   /// hack on the type, which can occur at any point in the file (because these
     65   /// can be defined in declspecs).
     66   virtual void HandleTagDeclDefinition(TagDecl *D) {}
     67 
     68   /// \brief Handle the specified top-level declaration that occurred inside
     69   /// and ObjC container.
     70   /// The default implementation ignored them.
     71   virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D);
     72 
     73   /// CompleteTentativeDefinition - Callback invoked at the end of a translation
     74   /// unit to notify the consumer that the given tentative definition should be
     75   /// completed.
     76   ///
     77   /// The variable declaration itself will be a tentative
     78   /// definition. If it had an incomplete array type, its type will
     79   /// have already been changed to an array of size 1. However, the
     80   /// declaration remains a tentative definition and has not been
     81   /// modified by the introduction of an implicit zero initializer.
     82   virtual void CompleteTentativeDefinition(VarDecl *D) {}
     83 
     84   /// \brief Callback involved at the end of a translation unit to
     85   /// notify the consumer that a vtable for the given C++ class is
     86   /// required.
     87   ///
     88   /// \param RD The class whose vtable was used.
     89   ///
     90   /// \param DefinitionRequired Whether a definition of this vtable is
     91   /// required in this translation unit; otherwise, it is only needed if
     92   /// it was actually used.
     93   virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {}
     94 
     95   /// \brief If the consumer is interested in entities getting modified after
     96   /// their initial creation, it should return a pointer to
     97   /// an ASTMutationListener here.
     98   virtual ASTMutationListener *GetASTMutationListener() { return 0; }
     99 
    100   /// \brief If the consumer is interested in entities being deserialized from
    101   /// AST files, it should return a pointer to a ASTDeserializationListener here
    102   virtual ASTDeserializationListener *GetASTDeserializationListener() { return 0; }
    103 
    104   /// PrintStats - If desired, print any statistics.
    105   virtual void PrintStats() {}
    106 
    107   // Support isa/cast/dyn_cast
    108   static bool classof(const ASTConsumer *) { return true; }
    109 };
    110 
    111 } // end namespace clang.
    112 
    113 #endif
    114