1556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner//===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===// 2556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner// 3556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner// The LLVM Compiler Infrastructure 4556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 7556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner// 8556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner//===----------------------------------------------------------------------===// 9556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner// 10556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner// This file defines the ASTConsumer class. 11556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner// 12556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner//===----------------------------------------------------------------------===// 13556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 14556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner#ifndef LLVM_CLANG_AST_ASTCONSUMER_H 15556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner#define LLVM_CLANG_AST_ASTCONSUMER_H 16556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 17556beb71b8820ed5243e385ffcc91433a494c170Chris Lattnernamespace clang { 18556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner class ASTContext; 196fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor class CXXRecordDecl; 20d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith class Decl; 21682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner class DeclGroupRef; 222ae34ed8caf90ca4044feca07811561053c08666Chris Lattner class HandleTagDeclDefinition; 23a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor class PPMutationListener; 247b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis class ASTMutationListener; 25571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl class ASTDeserializationListener; // layering violation because void* is ugly 26e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor class SemaConsumer; // layering violation required for safe SemaConsumer 27ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl class TagDecl; 28b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor class VarDecl; 296d968363877388f0a0268711d59367907b465ae1Argyrios Kyrtzidis class FunctionDecl; 30d3d981627c375b187f33cc92a034a77ac329ec47Argyrios Kyrtzidis class ImportDecl; 31e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 32556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner/// ASTConsumer - This is an abstract interface that should be implemented by 33556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner/// clients that read ASTs. This abstraction layer allows the client to be 34556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner/// independent of the AST producer (e.g. parser vs AST dump file reader, etc). 35556beb71b8820ed5243e385ffcc91433a494c170Chris Lattnerclass ASTConsumer { 36e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor /// \brief Whether this AST consumer also requires information about 37e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor /// semantic analysis. 38e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor bool SemaConsumer; 39e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 40e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor friend class SemaConsumer; 41e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 42556beb71b8820ed5243e385ffcc91433a494c170Chris Lattnerpublic: 43e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor ASTConsumer() : SemaConsumer(false) { } 44e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 45682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner virtual ~ASTConsumer() {} 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner /// Initialize - This is called to initialize the consumer, providing the 483926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// ASTContext. 4995041a2029a069386ee67439f6d0fb524a9d184fTed Kremenek virtual void Initialize(ASTContext &Context) {} 501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 512ff3e691ecc63a5d82d4023b46b5b47ce14ace53Ted Kremenek /// HandleTopLevelDecl - Handle the specified top-level declaration. This is 523926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// called by the parser to process every top-level Decl*. Note that D can be 533926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// the head of a chain of Decls (e.g. for `int a, b` the chain will have two 543926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// elements). Use Decl::getNextDeclarator() to walk the chain. 5588c2596edc8eb475e20f6033de1ea01669695a0cArgyrios Kyrtzidis /// 5688c2596edc8eb475e20f6033de1ea01669695a0cArgyrios Kyrtzidis /// \returns true to continue parsing, or false to abort parsing. 5788c2596edc8eb475e20f6033de1ea01669695a0cArgyrios Kyrtzidis virtual bool HandleTopLevelDecl(DeclGroupRef D); 581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5927372b4f1f402e95dd479ecf40c39ca71c15619fSebastian Redl /// HandleInterestingDecl - Handle the specified interesting declaration. This 603c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl /// is called by the AST reader when deserializing things that might interest 6127372b4f1f402e95dd479ecf40c39ca71c15619fSebastian Redl /// the consumer. The default implementation forwards to HandleTopLevelDecl. 6227372b4f1f402e95dd479ecf40c39ca71c15619fSebastian Redl virtual void HandleInterestingDecl(DeclGroupRef D); 6327372b4f1f402e95dd479ecf40c39ca71c15619fSebastian Redl 64c87190da60bca25fe3bc1fe6831916f0076b72b8Ted Kremenek /// HandleTranslationUnit - This method is called when the ASTs for entire 653926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// translation unit have been parsed. 661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump virtual void HandleTranslationUnit(ASTContext &Ctx) {} 671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 682ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl 692ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// (e.g. struct, union, enum, class) is completed. This allows the client to 702ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// hack on the type, which can occur at any point in the file (because these 712ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// can be defined in declspecs). 722ae34ed8caf90ca4044feca07811561053c08666Chris Lattner virtual void HandleTagDeclDefinition(TagDecl *D) {} 731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 746d968363877388f0a0268711d59367907b465ae1Argyrios Kyrtzidis /// \brief Invoked when a function is implicitly instantiated. 756d968363877388f0a0268711d59367907b465ae1Argyrios Kyrtzidis /// Note that at this point point it does not have a body, its body is 766d968363877388f0a0268711d59367907b465ae1Argyrios Kyrtzidis /// instantiated at the end of the translation unit and passed to 776d968363877388f0a0268711d59367907b465ae1Argyrios Kyrtzidis /// HandleTopLevelDecl. 786d968363877388f0a0268711d59367907b465ae1Argyrios Kyrtzidis virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {} 796d968363877388f0a0268711d59367907b465ae1Argyrios Kyrtzidis 80b4a686df4de21ec4eeca69211b21f7fe716abeaeArgyrios Kyrtzidis /// \brief Handle the specified top-level declaration that occurred inside 81b4a686df4de21ec4eeca69211b21f7fe716abeaeArgyrios Kyrtzidis /// and ObjC container. 82b4a686df4de21ec4eeca69211b21f7fe716abeaeArgyrios Kyrtzidis /// The default implementation ignored them. 83b4a686df4de21ec4eeca69211b21f7fe716abeaeArgyrios Kyrtzidis virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D); 84b4a686df4de21ec4eeca69211b21f7fe716abeaeArgyrios Kyrtzidis 85d3d981627c375b187f33cc92a034a77ac329ec47Argyrios Kyrtzidis /// \brief Handle an ImportDecl that was implicitly created due to an 86d3d981627c375b187f33cc92a034a77ac329ec47Argyrios Kyrtzidis /// inclusion directive. 87d3d981627c375b187f33cc92a034a77ac329ec47Argyrios Kyrtzidis /// The default implementation passes it to HandleTopLevelDecl. 88d3d981627c375b187f33cc92a034a77ac329ec47Argyrios Kyrtzidis virtual void HandleImplicitImportDecl(ImportDecl *D); 89d3d981627c375b187f33cc92a034a77ac329ec47Argyrios Kyrtzidis 903926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// CompleteTentativeDefinition - Callback invoked at the end of a translation 913926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// unit to notify the consumer that the given tentative definition should be 923926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar /// completed. 93b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// 94b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// The variable declaration itself will be a tentative 95b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// definition. If it had an incomplete array type, its type will 96b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// have already been changed to an array of size 1. However, the 97b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// declaration remains a tentative definition and has not been 98b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// modified by the introduction of an implicit zero initializer. 99b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor virtual void CompleteTentativeDefinition(VarDecl *D) {} 100b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor 101025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this 102025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola // variable has been instantiated. 103025039377d7247620750205dbd61ca1ba336f7e0Rafael Espindola virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {} 104234fe654a3dd2888be42ae5db34db96c5c2c4ba3Rafael Espindola 1056fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// \brief Callback involved at the end of a translation unit to 1066fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// notify the consumer that a vtable for the given C++ class is 1076fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// required. 1086fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// 1096fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// \param RD The class whose vtable was used. 1106fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// 1116fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// \param DefinitionRequired Whether a definition of this vtable is 1126fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// required in this translation unit; otherwise, it is only needed if 1136fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor /// it was actually used. 1146fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {} 1156fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor 116a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// \brief If the consumer is interested in preprocessor entities getting 117a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// modified after their initial creation, it should return a pointer to 118a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor /// a PPMutationListener here. 119a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor virtual PPMutationListener *GetPPMutationListener() { return 0; } 120a8235d6c4093cd38dcf742909651f867de62e55bDouglas Gregor 1217b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis /// \brief If the consumer is interested in entities getting modified after 1227b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis /// their initial creation, it should return a pointer to 12358a2cd8c0d52e710cbcc57a67eac7b51b0b831c4Sebastian Redl /// an ASTMutationListener here. 1247b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis virtual ASTMutationListener *GetASTMutationListener() { return 0; } 1257b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis 126ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl /// \brief If the consumer is interested in entities being deserialized from 127571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl /// AST files, it should return a pointer to a ASTDeserializationListener here 128ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie virtual ASTDeserializationListener *GetASTDeserializationListener() { 129ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie return 0; 130ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie } 131ffaab3e2bb13991bb3357e80f14bcae3745b2347Sebastian Redl 132556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner /// PrintStats - If desired, print any statistics. 1333926a1fe92f622f194d7d99560d0b17b2af65a61Daniel Dunbar virtual void PrintStats() {} 134d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith 135d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith /// \brief This callback is called for each function if the Parser was 136d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith /// initialized with \c SkipFunctionBodies set to \c true. 137d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith /// 138d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith /// \return \c true if the function's body should be skipped. The function 139d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith /// body may be parsed anyway if it is needed (for instance, if it contains 140d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith /// the code completion point or is constexpr). 141d1bac8d46740eb00085ec816af0829fd75fb4d5cRichard Smith virtual bool shouldSkipFunctionBody(Decl *D) { return true; } 142556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner}; 143556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 144556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner} // end namespace clang. 145556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 146556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner#endif 147