clang API Documentation

ASTConsumer.h
Go to the documentation of this file.
00001 //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- 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 //  This file defines the ASTConsumer class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_ASTCONSUMER_H
00015 #define LLVM_CLANG_AST_ASTCONSUMER_H
00016 
00017 namespace clang {
00018   class ASTContext;
00019   class CXXRecordDecl;
00020   class DeclGroupRef;
00021   class HandleTagDeclDefinition;
00022   class ASTMutationListener;
00023   class ASTDeserializationListener; // layering violation because void* is ugly
00024   class SemaConsumer; // layering violation required for safe SemaConsumer
00025   class TagDecl;
00026   class VarDecl;
00027   class FunctionDecl;
00028 
00029 /// ASTConsumer - This is an abstract interface that should be implemented by
00030 /// clients that read ASTs.  This abstraction layer allows the client to be
00031 /// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
00032 class ASTConsumer {
00033   /// \brief Whether this AST consumer also requires information about
00034   /// semantic analysis.
00035   bool SemaConsumer;
00036 
00037   friend class SemaConsumer;
00038 
00039 public:
00040   ASTConsumer() : SemaConsumer(false) { }
00041 
00042   virtual ~ASTConsumer() {}
00043 
00044   /// Initialize - This is called to initialize the consumer, providing the
00045   /// ASTContext.
00046   virtual void Initialize(ASTContext &Context) {}
00047 
00048   /// HandleTopLevelDecl - Handle the specified top-level declaration.  This is
00049   /// called by the parser to process every top-level Decl*. Note that D can be
00050   /// the head of a chain of Decls (e.g. for `int a, b` the chain will have two
00051   /// elements). Use Decl::getNextDeclarator() to walk the chain.
00052   ///
00053   /// \returns true to continue parsing, or false to abort parsing.
00054   virtual bool HandleTopLevelDecl(DeclGroupRef D);
00055 
00056   /// HandleInterestingDecl - Handle the specified interesting declaration. This
00057   /// is called by the AST reader when deserializing things that might interest
00058   /// the consumer. The default implementation forwards to HandleTopLevelDecl.
00059   virtual void HandleInterestingDecl(DeclGroupRef D);
00060 
00061   /// HandleTranslationUnit - This method is called when the ASTs for entire
00062   /// translation unit have been parsed.
00063   virtual void HandleTranslationUnit(ASTContext &Ctx) {}
00064 
00065   /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
00066   /// (e.g. struct, union, enum, class) is completed.  This allows the client to
00067   /// hack on the type, which can occur at any point in the file (because these
00068   /// can be defined in declspecs).
00069   virtual void HandleTagDeclDefinition(TagDecl *D) {}
00070 
00071   /// \brief Invoked when a function is implicitly instantiated.
00072   /// Note that at this point point it does not have a body, its body is
00073   /// instantiated at the end of the translation unit and passed to
00074   /// HandleTopLevelDecl.
00075   virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {}
00076 
00077   /// \brief Handle the specified top-level declaration that occurred inside
00078   /// and ObjC container.
00079   /// The default implementation ignored them.
00080   virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D);
00081 
00082   /// CompleteTentativeDefinition - Callback invoked at the end of a translation
00083   /// unit to notify the consumer that the given tentative definition should be
00084   /// completed.
00085   ///
00086   /// The variable declaration itself will be a tentative
00087   /// definition. If it had an incomplete array type, its type will
00088   /// have already been changed to an array of size 1. However, the
00089   /// declaration remains a tentative definition and has not been
00090   /// modified by the introduction of an implicit zero initializer.
00091   virtual void CompleteTentativeDefinition(VarDecl *D) {}
00092 
00093   /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
00094   // variable has been instantiated.
00095   virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {}
00096 
00097   /// \brief Callback involved at the end of a translation unit to
00098   /// notify the consumer that a vtable for the given C++ class is
00099   /// required.
00100   ///
00101   /// \param RD The class whose vtable was used.
00102   ///
00103   /// \param DefinitionRequired Whether a definition of this vtable is
00104   /// required in this translation unit; otherwise, it is only needed if
00105   /// it was actually used.
00106   virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {}
00107 
00108   /// \brief If the consumer is interested in entities getting modified after
00109   /// their initial creation, it should return a pointer to
00110   /// an ASTMutationListener here.
00111   virtual ASTMutationListener *GetASTMutationListener() { return 0; }
00112 
00113   /// \brief If the consumer is interested in entities being deserialized from
00114   /// AST files, it should return a pointer to a ASTDeserializationListener here
00115   virtual ASTDeserializationListener *GetASTDeserializationListener() {
00116     return 0;
00117   }
00118 
00119   /// PrintStats - If desired, print any statistics.
00120   virtual void PrintStats() {}
00121 
00122   // Support isa/cast/dyn_cast
00123   static bool classof(const ASTConsumer *) { return true; }
00124 };
00125 
00126 } // end namespace clang.
00127 
00128 #endif