ASTConsumer.h revision b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2
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; 19682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner class DeclGroupRef; 202ae34ed8caf90ca4044feca07811561053c08666Chris Lattner class TagDecl; 212ae34ed8caf90ca4044feca07811561053c08666Chris Lattner class HandleTagDeclDefinition; 22e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor class SemaConsumer; // layering violation required for safe SemaConsumer 23b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor class VarDecl; 24e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 25556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner/// ASTConsumer - This is an abstract interface that should be implemented by 26556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner/// clients that read ASTs. This abstraction layer allows the client to be 27556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner/// independent of the AST producer (e.g. parser vs AST dump file reader, etc). 28556beb71b8820ed5243e385ffcc91433a494c170Chris Lattnerclass ASTConsumer { 29e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor /// \brief Whether this AST consumer also requires information about 30e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor /// semantic analysis. 31e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor bool SemaConsumer; 32e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 33e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor friend class SemaConsumer; 34e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 35556beb71b8820ed5243e385ffcc91433a494c170Chris Lattnerpublic: 36e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor ASTConsumer() : SemaConsumer(false) { } 37e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 38682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner virtual ~ASTConsumer() {} 39556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 40556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner /// Initialize - This is called to initialize the consumer, providing the 41e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor /// ASTContext and the Action. 4295041a2029a069386ee67439f6d0fb524a9d184fTed Kremenek virtual void Initialize(ASTContext &Context) {} 43556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 442ff3e691ecc63a5d82d4023b46b5b47ce14ace53Ted Kremenek /// HandleTopLevelDecl - Handle the specified top-level declaration. This is 4591c027e2021366396696977af7fdc0e070bdd614Nico Weber /// called by the parser to process every top-level Decl*. Note that D can 4691c027e2021366396696977af7fdc0e070bdd614Nico Weber /// be the head of a chain of Decls (e.g. for `int a, b` the chain will have 474afa39deaa245592977136d367251ee2c173dd8dDouglas Gregor /// two elements). Use Decl::getNextDeclarator() to walk the chain. 48682bf92db408a6cbc3d37b5496a99b6ef85041ecChris Lattner virtual void HandleTopLevelDecl(DeclGroupRef D); 49c87190da60bca25fe3bc1fe6831916f0076b72b8Ted Kremenek 50c87190da60bca25fe3bc1fe6831916f0076b72b8Ted Kremenek /// HandleTranslationUnit - This method is called when the ASTs for entire 51c87190da60bca25fe3bc1fe6831916f0076b72b8Ted Kremenek /// translation unit have been parsed. 52dacbc5d46aaeea817742b8c76c987b87d2490c85Chris Lattner virtual void HandleTranslationUnit(ASTContext &Ctx) {} 532ff3e691ecc63a5d82d4023b46b5b47ce14ace53Ted Kremenek 542ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl 552ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// (e.g. struct, union, enum, class) is completed. This allows the client to 562ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// hack on the type, which can occur at any point in the file (because these 572ae34ed8caf90ca4044feca07811561053c08666Chris Lattner /// can be defined in declspecs). 582ae34ed8caf90ca4044feca07811561053c08666Chris Lattner virtual void HandleTagDeclDefinition(TagDecl *D) {} 59556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 60b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// \brief Callback invoked at the end of a translation unit to 61b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// notify the consumer that the given tentative definition should 62b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// be completed. 63b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// 64b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// The variable declaration itself will be a tentative 65b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// definition. If it had an incomplete array type, its type will 66b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// have already been changed to an array of size 1. However, the 67b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// declaration remains a tentative definition and has not been 68b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor /// modified by the introduction of an implicit zero initializer. 69b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor virtual void CompleteTentativeDefinition(VarDecl *D) {} 70b6c8c8bd8d362c8a6cdb767415b0d21e62b77eb2Douglas Gregor 71556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner /// PrintStats - If desired, print any statistics. 72556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner virtual void PrintStats() { 73556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner } 74e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor 75e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor // Support isa/cast/dyn_cast 76e7785040107266d01ebdcc066365f70b7ace371fDouglas Gregor static bool classof(const ASTConsumer *) { return true; } 77556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner}; 78556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 79556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner} // end namespace clang. 80556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner 81556beb71b8820ed5243e385ffcc91433a494c170Chris Lattner#endif 82