xref: /minix3/external/bsd/llvm/dist/clang/include/clang/AST/ASTConsumer.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
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:
ASTConsumer()44   ASTConsumer() : SemaConsumer(false) { }
45 
~ASTConsumer()46   virtual ~ASTConsumer() {}
47 
48   /// Initialize - This is called to initialize the consumer, providing the
49   /// ASTContext.
Initialize(ASTContext & Context)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 definition is
59   /// completed.
HandleInlineMethodDefinition(CXXMethodDecl * D)60   virtual void HandleInlineMethodDefinition(CXXMethodDecl *D) {}
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.
HandleTranslationUnit(ASTContext & Ctx)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).
HandleTagDeclDefinition(TagDecl * D)75   virtual void HandleTagDeclDefinition(TagDecl *D) {}
76 
77   /// \brief This callback is invoked the first time each TagDecl is required to
78   /// be complete.
HandleTagDeclRequiredDefinition(const TagDecl * D)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.
HandleCXXImplicitFunctionInstantiation(FunctionDecl * D)85   virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {}
86 
87   /// \brief Handle the specified top-level declaration that occurred inside
88   /// and ObjC container.
89   /// The default implementation ignored them.
90   virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D);
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   /// \brief Handle a pragma that appends to Linker Options.  Currently this
98   /// only exists to support Microsoft's #pragma comment(linker, "/foo").
HandleLinkerOptionPragma(llvm::StringRef Opts)99   virtual void HandleLinkerOptionPragma(llvm::StringRef Opts) {}
100 
101   /// \brief Handle a pragma that emits a mismatch identifier and value to the
102   /// object file for the linker to work with.  Currently, this only exists to
103   /// support Microsoft's #pragma detect_mismatch.
HandleDetectMismatch(llvm::StringRef Name,llvm::StringRef Value)104   virtual void HandleDetectMismatch(llvm::StringRef Name,
105                                     llvm::StringRef Value) {}
106 
107   /// \brief Handle a dependent library created by a pragma in the source.
108   /// Currently this only exists to support Microsoft's
109   /// #pragma comment(lib, "/foo").
HandleDependentLibrary(llvm::StringRef Lib)110   virtual void HandleDependentLibrary(llvm::StringRef Lib) {}
111 
112   /// CompleteTentativeDefinition - Callback invoked at the end of a translation
113   /// unit to notify the consumer that the given tentative definition should be
114   /// completed.
115   ///
116   /// The variable declaration itself will be a tentative
117   /// definition. If it had an incomplete array type, its type will
118   /// have already been changed to an array of size 1. However, the
119   /// declaration remains a tentative definition and has not been
120   /// modified by the introduction of an implicit zero initializer.
CompleteTentativeDefinition(VarDecl * D)121   virtual void CompleteTentativeDefinition(VarDecl *D) {}
122 
123   /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
124   // variable has been instantiated.
HandleCXXStaticMemberVarInstantiation(VarDecl * D)125   virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {}
126 
127   /// \brief Callback involved at the end of a translation unit to
128   /// notify the consumer that a vtable for the given C++ class is
129   /// required.
130   ///
131   /// \param RD The class whose vtable was used.
132   ///
133   /// \param DefinitionRequired Whether a definition of this vtable is
134   /// required in this translation unit; otherwise, it is only needed if
135   /// it was actually used.
HandleVTable(CXXRecordDecl * RD,bool DefinitionRequired)136   virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {}
137 
138   /// \brief If the consumer is interested in entities getting modified after
139   /// their initial creation, it should return a pointer to
140   /// an ASTMutationListener here.
GetASTMutationListener()141   virtual ASTMutationListener *GetASTMutationListener() { return nullptr; }
142 
143   /// \brief If the consumer is interested in entities being deserialized from
144   /// AST files, it should return a pointer to a ASTDeserializationListener here
GetASTDeserializationListener()145   virtual ASTDeserializationListener *GetASTDeserializationListener() {
146     return nullptr;
147   }
148 
149   /// PrintStats - If desired, print any statistics.
PrintStats()150   virtual void PrintStats() {}
151 
152   /// \brief This callback is called for each function if the Parser was
153   /// initialized with \c SkipFunctionBodies set to \c true.
154   ///
155   /// \return \c true if the function's body should be skipped. The function
156   /// body may be parsed anyway if it is needed (for instance, if it contains
157   /// the code completion point or is constexpr).
shouldSkipFunctionBody(Decl * D)158   virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
159 };
160 
161 } // end namespace clang.
162 
163 #endif
164