clang 20.0.0git
ASTConsumer.h
Go to the documentation of this file.
1//===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTConsumer class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_ASTCONSUMER_H
14#define LLVM_CLANG_AST_ASTCONSUMER_H
15
16namespace clang {
17 class ASTContext;
18 class CXXMethodDecl;
19 class CXXRecordDecl;
20 class Decl;
21 class DeclGroupRef;
22 class ASTMutationListener;
23 class ASTDeserializationListener; // layering violation because void* is ugly
24 class SemaConsumer; // layering violation required for safe SemaConsumer
25 class TagDecl;
26 class DeclaratorDecl;
27 class VarDecl;
28 class FunctionDecl;
29 class ImportDecl;
30
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 /// Whether this AST consumer also requires information about
36 /// semantic analysis.
37 bool SemaConsumer = false;
38
39 friend class SemaConsumer;
40
41public:
42 ASTConsumer() = default;
43
44 virtual ~ASTConsumer() {}
45
46 /// Initialize - This is called to initialize the consumer, providing the
47 /// ASTContext.
48 virtual void Initialize(ASTContext &Context) {}
49
50 /// HandleTopLevelDecl - Handle the specified top-level declaration. This is
51 /// called by the parser to process every top-level Decl*.
52 ///
53 /// \returns true to continue parsing, or false to abort parsing.
54 virtual bool HandleTopLevelDecl(DeclGroupRef D);
55
56 /// This callback is invoked each time an inline (method or friend)
57 /// function definition in a class is completed.
59
60 /// HandleInterestingDecl - Handle the specified interesting declaration. This
61 /// is called by the AST reader when deserializing things that might interest
62 /// the consumer. The default implementation forwards to HandleTopLevelDecl.
64
65 /// HandleTranslationUnit - This method is called when the ASTs for entire
66 /// translation unit have been parsed.
67 virtual void HandleTranslationUnit(ASTContext &Ctx) {}
68
69 /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
70 /// (e.g. struct, union, enum, class) is completed. This allows the client to
71 /// hack on the type, which can occur at any point in the file (because these
72 /// can be defined in declspecs).
74
75 /// This callback is invoked the first time each TagDecl is required to
76 /// be complete.
78
79 /// Invoked when a function is implicitly instantiated.
80 /// Note that at this point it does not have a body, its body is
81 /// instantiated at the end of the translation unit and passed to
82 /// HandleTopLevelDecl.
84
85 /// Handle the specified top-level declaration that occurred inside
86 /// and ObjC container.
87 /// The default implementation ignored them.
89
90 /// Handle an ImportDecl that was implicitly created due to an
91 /// inclusion directive.
92 /// The default implementation passes it to HandleTopLevelDecl.
94
95 /// CompleteTentativeDefinition - Callback invoked at the end of a translation
96 /// unit to notify the consumer that the given tentative definition should be
97 /// completed.
98 ///
99 /// The variable declaration itself will be a tentative
100 /// definition. If it had an incomplete array type, its type will
101 /// have already been changed to an array of size 1. However, the
102 /// declaration remains a tentative definition and has not been
103 /// modified by the introduction of an implicit zero initializer.
105
106 /// CompleteExternalDeclaration - Callback invoked at the end of a translation
107 /// unit to notify the consumer that the given external declaration should be
108 /// completed.
110
111 /// Callback invoked when an MSInheritanceAttr has been attached to a
112 /// CXXRecordDecl.
114
115 /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
116 // variable has been instantiated.
118
119 /// Callback involved at the end of a translation unit to
120 /// notify the consumer that a vtable for the given C++ class is
121 /// required.
122 ///
123 /// \param RD The class whose vtable was used.
124 virtual void HandleVTable(CXXRecordDecl *RD) {}
125
126 /// If the consumer is interested in entities getting modified after
127 /// their initial creation, it should return a pointer to
128 /// an ASTMutationListener here.
129 virtual ASTMutationListener *GetASTMutationListener() { return nullptr; }
130
131 /// If the consumer is interested in entities being deserialized from
132 /// AST files, it should return a pointer to a ASTDeserializationListener here
134 return nullptr;
135 }
136
137 /// PrintStats - If desired, print any statistics.
138 virtual void PrintStats() {}
139
140 /// This callback is called for each function if the Parser was
141 /// initialized with \c SkipFunctionBodies set to \c true.
142 ///
143 /// \return \c true if the function's body should be skipped. The function
144 /// body may be parsed anyway if it is needed (for instance, if it contains
145 /// the code completion point or is constexpr).
146 virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
147};
148
149} // end namespace clang.
150
151#endif
const Decl * D
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:34
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
Definition: ASTConsumer.h:73
virtual void HandleTranslationUnit(ASTContext &Ctx)
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: ASTConsumer.h:67
virtual void HandleInlineFunctionDefinition(FunctionDecl *D)
This callback is invoked each time an inline (method or friend) function definition in a class is com...
Definition: ASTConsumer.h:58
virtual void HandleVTable(CXXRecordDecl *RD)
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
Definition: ASTConsumer.h:124
ASTConsumer()=default
virtual void HandleTagDeclRequiredDefinition(const TagDecl *D)
This callback is invoked the first time each TagDecl is required to be complete.
Definition: ASTConsumer.h:77
virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D)
Handle the specified top-level declaration that occurred inside and ObjC container.
Definition: ASTConsumer.cpp:26
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:18
virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D)
Invoked when a function is implicitly instantiated.
Definition: ASTConsumer.h:83
virtual void Initialize(ASTContext &Context)
Initialize - This is called to initialize the consumer, providing the ASTContext.
Definition: ASTConsumer.h:48
virtual bool shouldSkipFunctionBody(Decl *D)
This callback is called for each function if the Parser was initialized with SkipFunctionBodies set t...
Definition: ASTConsumer.h:146
virtual void PrintStats()
PrintStats - If desired, print any statistics.
Definition: ASTConsumer.h:138
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
Definition: ASTConsumer.h:113
virtual ~ASTConsumer()
Definition: ASTConsumer.h:44
virtual void CompleteTentativeDefinition(VarDecl *D)
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
Definition: ASTConsumer.h:104
virtual void HandleImplicitImportDecl(ImportDecl *D)
Handle an ImportDecl that was implicitly created due to an inclusion directive.
Definition: ASTConsumer.cpp:28
virtual ASTDeserializationListener * GetASTDeserializationListener()
If the consumer is interested in entities being deserialized from AST files, it should return a point...
Definition: ASTConsumer.h:133
virtual void HandleInterestingDecl(DeclGroupRef D)
HandleInterestingDecl - Handle the specified interesting declaration.
Definition: ASTConsumer.cpp:22
virtual ASTMutationListener * GetASTMutationListener()
If the consumer is interested in entities getting modified after their initial creation,...
Definition: ASTConsumer.h:129
virtual void CompleteExternalDeclaration(DeclaratorDecl *D)
CompleteExternalDeclaration - Callback invoked at the end of a translation unit to notify the consume...
Definition: ASTConsumer.h:109
virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D)
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
Definition: ASTConsumer.h:117
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:186
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:731
Represents a function declaration or definition.
Definition: Decl.h:1932
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4779
An abstract interface that should be implemented by clients that read ASTs and then require further s...
Definition: SemaConsumer.h:25
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3557
Represents a variable declaration or definition.
Definition: Decl.h:879
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.