1 //===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the ASTConsumer class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_AST_ASTCONSUMER_H
14 #define LLVM_CLANG_AST_ASTCONSUMER_H
22 class ASTMutationListener;
23 class ASTDeserializationListener; // layering violation because void* is ugly
24 class SemaConsumer; // layering violation required for safe SemaConsumer
30 /// ASTConsumer - This is an abstract interface that should be implemented by
31 /// clients that read ASTs. This abstraction layer allows the client to be
32 /// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
34 /// Whether this AST consumer also requires information about
35 /// semantic analysis.
38 friend class SemaConsumer;
41 ASTConsumer() : SemaConsumer(false) { }
43 virtual ~ASTConsumer() {}
45 /// Initialize - This is called to initialize the consumer, providing the
47 virtual void Initialize(ASTContext &Context) {}
49 /// HandleTopLevelDecl - Handle the specified top-level declaration. This is
50 /// called by the parser to process every top-level Decl*.
52 /// \returns true to continue parsing, or false to abort parsing.
53 virtual bool HandleTopLevelDecl(DeclGroupRef D);
55 /// This callback is invoked each time an inline (method or friend)
56 /// function definition in a class is completed.
57 virtual void HandleInlineFunctionDefinition(FunctionDecl *D) {}
59 /// HandleInterestingDecl - Handle the specified interesting declaration. This
60 /// is called by the AST reader when deserializing things that might interest
61 /// the consumer. The default implementation forwards to HandleTopLevelDecl.
62 virtual void HandleInterestingDecl(DeclGroupRef D);
64 /// HandleTranslationUnit - This method is called when the ASTs for entire
65 /// translation unit have been parsed.
66 virtual void HandleTranslationUnit(ASTContext &Ctx) {}
68 /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
69 /// (e.g. struct, union, enum, class) is completed. This allows the client to
70 /// hack on the type, which can occur at any point in the file (because these
71 /// can be defined in declspecs).
72 virtual void HandleTagDeclDefinition(TagDecl *D) {}
74 /// This callback is invoked the first time each TagDecl is required to
76 virtual void HandleTagDeclRequiredDefinition(const TagDecl *D) {}
78 /// Invoked when a function is implicitly instantiated.
79 /// Note that at this point point it does not have a body, its body is
80 /// instantiated at the end of the translation unit and passed to
81 /// HandleTopLevelDecl.
82 virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {}
84 /// Handle the specified top-level declaration that occurred inside
85 /// and ObjC container.
86 /// The default implementation ignored them.
87 virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D);
89 /// Handle an ImportDecl that was implicitly created due to an
90 /// inclusion directive.
91 /// The default implementation passes it to HandleTopLevelDecl.
92 virtual void HandleImplicitImportDecl(ImportDecl *D);
94 /// CompleteTentativeDefinition - Callback invoked at the end of a translation
95 /// unit to notify the consumer that the given tentative definition should be
98 /// The variable declaration itself will be a tentative
99 /// definition. If it had an incomplete array type, its type will
100 /// have already been changed to an array of size 1. However, the
101 /// declaration remains a tentative definition and has not been
102 /// modified by the introduction of an implicit zero initializer.
103 virtual void CompleteTentativeDefinition(VarDecl *D) {}
105 /// Callback invoked when an MSInheritanceAttr has been attached to a
107 virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
109 /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
110 // variable has been instantiated.
111 virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {}
113 /// Callback involved at the end of a translation unit to
114 /// notify the consumer that a vtable for the given C++ class is
117 /// \param RD The class whose vtable was used.
118 virtual void HandleVTable(CXXRecordDecl *RD) {}
120 /// 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 nullptr; }
125 /// 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() {
131 /// PrintStats - If desired, print any statistics.
132 virtual void PrintStats() {}
134 /// This callback is called for each function if the Parser was
135 /// initialized with \c SkipFunctionBodies set to \c true.
137 /// \return \c true if the function's body should be skipped. The function
138 /// body may be parsed anyway if it is needed (for instance, if it contains
139 /// the code completion point or is constexpr).
140 virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
143 } // end namespace clang.