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 ASTMutationListener;
24 class ASTDeserializationListener; // layering violation because void* is ugly
25 class SemaConsumer; // layering violation required for safe SemaConsumer
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).
35 /// \brief Whether this AST consumer also requires information about
36 /// semantic analysis.
39 friend class SemaConsumer;
42 ASTConsumer() : SemaConsumer(false) { }
44 virtual ~ASTConsumer() {}
46 /// Initialize - This is called to initialize the consumer, providing the
48 virtual void Initialize(ASTContext &Context) {}
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.
55 /// \returns true to continue parsing, or false to abort parsing.
56 virtual bool HandleTopLevelDecl(DeclGroupRef D);
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);
63 /// HandleTranslationUnit - This method is called when the ASTs for entire
64 /// translation unit have been parsed.
65 virtual void HandleTranslationUnit(ASTContext &Ctx) {}
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) {}
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) {}
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);
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);
89 /// CompleteTentativeDefinition - Callback invoked at the end of a translation
90 /// unit to notify the consumer that the given tentative definition should be
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) {}
100 /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
101 // variable has been instantiated.
102 virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {}
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
108 /// \param RD The class whose vtable was used.
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) {}
115 /// \brief If the consumer is interested in entities getting modified after
116 /// their initial creation, it should return a pointer to
117 /// an ASTMutationListener here.
118 virtual ASTMutationListener *GetASTMutationListener() { return 0; }
120 /// \brief If the consumer is interested in entities being deserialized from
121 /// AST files, it should return a pointer to a ASTDeserializationListener here
122 virtual ASTDeserializationListener *GetASTDeserializationListener() {
126 /// PrintStats - If desired, print any statistics.
127 virtual void PrintStats() {}
129 /// \brief This callback is called for each function if the Parser was
130 /// initialized with \c SkipFunctionBodies set to \c true.
132 /// \return \c true if the function's body should be skipped. The function
133 /// body may be parsed anyway if it is needed (for instance, if it contains
134 /// the code completion point or is constexpr).
135 virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
138 } // end namespace clang.