ASTConsumer.h revision b43d87b0646aa04951056c7e0d1ab9a58eb09f66
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 PPMutationListener; 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). 34class ASTConsumer { 35 /// \brief Whether this AST consumer also requires information about 36 /// semantic analysis. 37 bool SemaConsumer; 38 39 friend class SemaConsumer; 40 41public: 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*. Note that D can be 52 /// the head of a chain of Decls (e.g. for `int a, b` the chain will have two 53 /// elements). Use Decl::getNextDeclarator() to walk the chain. 54 /// 55 /// \returns true to continue parsing, or false to abort parsing. 56 virtual bool HandleTopLevelDecl(DeclGroupRef D); 57 58 /// HandleInterestingDecl - Handle the specified interesting declaration. This 59 /// is called by the AST reader when deserializing things that might interest 60 /// the consumer. The default implementation forwards to HandleTopLevelDecl. 61 virtual void HandleInterestingDecl(DeclGroupRef D); 62 63 /// HandleTranslationUnit - This method is called when the ASTs for entire 64 /// translation unit have been parsed. 65 virtual void HandleTranslationUnit(ASTContext &Ctx) {} 66 67 /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl 68 /// (e.g. struct, union, enum, class) is completed. This allows the client to 69 /// hack on the type, which can occur at any point in the file (because these 70 /// can be defined in declspecs). 71 virtual void HandleTagDeclDefinition(TagDecl *D) {} 72 73 /// \brief Invoked when a function is implicitly instantiated. 74 /// Note that at this point point it does not have a body, its body is 75 /// instantiated at the end of the translation unit and passed to 76 /// HandleTopLevelDecl. 77 virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {} 78 79 /// \brief Handle the specified top-level declaration that occurred inside 80 /// and ObjC container. 81 /// The default implementation ignored them. 82 virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D); 83 84 /// \brief Handle an ImportDecl that was implicitly created due to an 85 /// inclusion directive. 86 /// The default implementation passes it to HandleTopLevelDecl. 87 virtual void HandleImplicitImportDecl(ImportDecl *D); 88 89 /// CompleteTentativeDefinition - Callback invoked at the end of a translation 90 /// unit to notify the consumer that the given tentative definition should be 91 /// completed. 92 /// 93 /// The variable declaration itself will be a tentative 94 /// definition. If it had an incomplete array type, its type will 95 /// have already been changed to an array of size 1. However, the 96 /// declaration remains a tentative definition and has not been 97 /// modified by the introduction of an implicit zero initializer. 98 virtual void CompleteTentativeDefinition(VarDecl *D) {} 99 100 /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this 101 // variable has been instantiated. 102 virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {} 103 104 /// \brief Callback involved at the end of a translation unit to 105 /// notify the consumer that a vtable for the given C++ class is 106 /// required. 107 /// 108 /// \param RD The class whose vtable was used. 109 /// 110 /// \param DefinitionRequired Whether a definition of this vtable is 111 /// required in this translation unit; otherwise, it is only needed if 112 /// it was actually used. 113 virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {} 114 115 /// \brief If the consumer is interested in preprocessor entities getting 116 /// modified after their initial creation, it should return a pointer to 117 /// a PPMutationListener here. 118 virtual PPMutationListener *GetPPMutationListener() { return 0; } 119 120 /// \brief If the consumer is interested in entities getting modified after 121 /// their initial creation, it should return a pointer to 122 /// an ASTMutationListener here. 123 virtual ASTMutationListener *GetASTMutationListener() { return 0; } 124 125 /// \brief If the consumer is interested in entities being deserialized from 126 /// AST files, it should return a pointer to a ASTDeserializationListener here 127 virtual ASTDeserializationListener *GetASTDeserializationListener() { 128 return 0; 129 } 130 131 /// PrintStats - If desired, print any statistics. 132 virtual void PrintStats() {} 133}; 134 135} // end namespace clang. 136 137#endif 138