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