clang  9.0.0svn
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 
16 namespace 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 VarDecl;
27  class FunctionDecl;
28  class ImportDecl;
29 
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).
33 class ASTConsumer {
34  /// Whether this AST consumer also requires information about
35  /// semantic analysis.
36  bool SemaConsumer;
37 
38  friend class SemaConsumer;
39 
40 public:
41  ASTConsumer() : SemaConsumer(false) { }
42 
43  virtual ~ASTConsumer() {}
44 
45  /// Initialize - This is called to initialize the consumer, providing the
46  /// ASTContext.
47  virtual void Initialize(ASTContext &Context) {}
48 
49  /// HandleTopLevelDecl - Handle the specified top-level declaration. This is
50  /// called by the parser to process every top-level Decl*.
51  ///
52  /// \returns true to continue parsing, or false to abort parsing.
53  virtual bool HandleTopLevelDecl(DeclGroupRef D);
54 
55  /// This callback is invoked each time an inline (method or friend)
56  /// function definition in a class is completed.
58 
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);
63 
64  /// HandleTranslationUnit - This method is called when the ASTs for entire
65  /// translation unit have been parsed.
66  virtual void HandleTranslationUnit(ASTContext &Ctx) {}
67 
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) {}
73 
74  /// This callback is invoked the first time each TagDecl is required to
75  /// be complete.
76  virtual void HandleTagDeclRequiredDefinition(const TagDecl *D) {}
77 
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.
83 
84  /// Handle the specified top-level declaration that occurred inside
85  /// and ObjC container.
86  /// The default implementation ignored them.
88 
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);
93 
94  /// CompleteTentativeDefinition - Callback invoked at the end of a translation
95  /// unit to notify the consumer that the given tentative definition should be
96  /// completed.
97  ///
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.
104 
105  /// Callback invoked when an MSInheritanceAttr has been attached to a
106  /// CXXRecordDecl.
108 
109  /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
110  // variable has been instantiated.
112 
113  /// Callback involved at the end of a translation unit to
114  /// notify the consumer that a vtable for the given C++ class is
115  /// required.
116  ///
117  /// \param RD The class whose vtable was used.
118  virtual void HandleVTable(CXXRecordDecl *RD) {}
119 
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; }
124 
125  /// If the consumer is interested in entities being deserialized from
126  /// AST files, it should return a pointer to a ASTDeserializationListener here
128  return nullptr;
129  }
130 
131  /// PrintStats - If desired, print any statistics.
132  virtual void PrintStats() {}
133 
134  /// This callback is called for each function if the Parser was
135  /// initialized with \c SkipFunctionBodies set to \c true.
136  ///
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; }
141 };
142 
143 } // end namespace clang.
144 
145 #endif
Represents a function declaration or definition.
Definition: Decl.h:1743
virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D)
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
Definition: ASTConsumer.h:111
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Definition: ASTConsumer.h:33
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
virtual void PrintStats()
PrintStats - If desired, print any statistics.
Definition: ASTConsumer.h:132
Represents a variable declaration or definition.
Definition: Decl.h:812
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:57
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
virtual void HandleTagDeclRequiredDefinition(const TagDecl *D)
This callback is invoked the first time each TagDecl is required to be complete.
Definition: ASTConsumer.h:76
An abstract interface that should be implemented by clients that read ASTs and then require further s...
Definition: SemaConsumer.h:25
virtual void HandleInterestingDecl(DeclGroupRef D)
HandleInterestingDecl - Handle the specified interesting declaration.
Definition: ASTConsumer.cpp:22
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:118
virtual ASTMutationListener * GetASTMutationListener()
If the consumer is interested in entities getting modified after their initial creation, it should return a pointer to an ASTMutationListener here.
Definition: ASTConsumer.h:123
virtual ~ASTConsumer()
Definition: ASTConsumer.h:43
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
Definition: ASTConsumer.h:107
virtual void HandleTranslationUnit(ASTContext &Ctx)
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Definition: ASTConsumer.h:66
#define false
Definition: stdbool.h:17
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3069
virtual ASTDeserializationListener * GetASTDeserializationListener()
If the consumer is interested in entities being deserialized from AST files, it should return a point...
Definition: ASTConsumer.h:127
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4161
Dataflow Directional Tag Classes.
virtual void HandleImplicitImportDecl(ImportDecl *D)
Handle an ImportDecl that was implicitly created due to an inclusion directive.
Definition: ASTConsumer.cpp:28
virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D)
Invoked when a function is implicitly instantiated.
Definition: ASTConsumer.h:82
virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D)
Handle the specified top-level declaration that occurred inside and ObjC container.
Definition: ASTConsumer.cpp:26
virtual void Initialize(ASTContext &Context)
Initialize - This is called to initialize the consumer, providing the ASTContext. ...
Definition: ASTConsumer.h:47
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
virtual bool shouldSkipFunctionBody(Decl *D)
This callback is called for each function if the Parser was initialized with SkipFunctionBodies set t...
Definition: ASTConsumer.h:140
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:18
virtual void CompleteTentativeDefinition(VarDecl *D)
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
Definition: ASTConsumer.h:103
virtual void HandleTagDeclDefinition(TagDecl *D)
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
Definition: ASTConsumer.h:72