1 //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ASTConsumer class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_ASTCONSUMER_H
15 #define LLVM_CLANG_AST_ASTCONSUMER_H
22 class HandleTagDeclDefinition;
23 class SemaConsumer; // layering violation required for safe SemaConsumer
26 /// ASTConsumer - This is an abstract interface that should be implemented by
27 /// clients that read ASTs. This abstraction layer allows the client to be
28 /// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
30 /// \brief Whether this AST consumer also requires information about
31 /// semantic analysis.
34 friend class SemaConsumer;
37 ASTConsumer() : SemaConsumer(false) { }
39 virtual ~ASTConsumer() {}
41 /// Initialize - This is called to initialize the consumer, providing the
43 virtual void Initialize(ASTContext &Context) {}
45 /// HandleTopLevelDecl - Handle the specified top-level declaration. This is
46 /// called by the parser to process every top-level Decl*. Note that D can be
47 /// the head of a chain of Decls (e.g. for `int a, b` the chain will have two
48 /// elements). Use Decl::getNextDeclarator() to walk the chain.
49 virtual void HandleTopLevelDecl(DeclGroupRef D);
51 /// HandleTranslationUnit - This method is called when the ASTs for entire
52 /// translation unit have been parsed.
53 virtual void HandleTranslationUnit(ASTContext &Ctx) {}
55 /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
56 /// (e.g. struct, union, enum, class) is completed. This allows the client to
57 /// hack on the type, which can occur at any point in the file (because these
58 /// can be defined in declspecs).
59 virtual void HandleTagDeclDefinition(TagDecl *D) {}
61 /// CompleteTentativeDefinition - Callback invoked at the end of a translation
62 /// unit to notify the consumer that the given tentative definition should be
65 /// The variable declaration itself will be a tentative
66 /// definition. If it had an incomplete array type, its type will
67 /// have already been changed to an array of size 1. However, the
68 /// declaration remains a tentative definition and has not been
69 /// modified by the introduction of an implicit zero initializer.
70 virtual void CompleteTentativeDefinition(VarDecl *D) {}
72 /// \brief Callback involved at the end of a translation unit to
73 /// notify the consumer that a vtable for the given C++ class is
76 /// \param RD The class whose vtable was used.
78 /// \param DefinitionRequired Whether a definition of this vtable is
79 /// required in this translation unit; otherwise, it is only needed if
80 /// it was actually used.
81 virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {}
83 /// PrintStats - If desired, print any statistics.
84 virtual void PrintStats() {}
86 // Support isa/cast/dyn_cast
87 static bool classof(const ASTConsumer *) { return true; }
90 } // end namespace clang.