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   /// CompleteTentativeDefinition - Callback invoked at the end of a translation
     69   /// unit to notify the consumer that the given tentative definition should be
     70   /// completed.
     71   ///
     72   /// The variable declaration itself will be a tentative
     73   /// definition. If it had an incomplete array type, its type will
     74   /// have already been changed to an array of size 1. However, the
     75   /// declaration remains a tentative definition and has not been
     76   /// modified by the introduction of an implicit zero initializer.
     77   virtual void CompleteTentativeDefinition(VarDecl *D) {}
     78 
     79   /// \brief Callback involved at the end of a translation unit to
     80   /// notify the consumer that a vtable for the given C++ class is
     81   /// required.
     82   ///
     83   /// \param RD The class whose vtable was used.
     84   ///
     85   /// \param DefinitionRequired Whether a definition of this vtable is
     86   /// required in this translation unit; otherwise, it is only needed if
     87   /// it was actually used.
     88   virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {}
     89 
     90   /// \brief If the consumer is interested in entities getting modified after
     91   /// their initial creation, it should return a pointer to
     92   /// an ASTMutationListener here.
     93   virtual ASTMutationListener *GetASTMutationListener() { return 0; }
     94 
     95   /// \brief If the consumer is interested in entities being deserialized from
     96   /// AST files, it should return a pointer to a ASTDeserializationListener here
     97   virtual ASTDeserializationListener *GetASTDeserializationListener() { return 0; }
     98 
     99   /// PrintStats - If desired, print any statistics.
    100   virtual void PrintStats() {}
    101 
    102   // Support isa/cast/dyn_cast
    103   static bool classof(const ASTConsumer *) { return true; }
    104 };
    105 
    106 } // end namespace clang.
    107 
    108 #endif
    109