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