1193326Sed//===--- ASTConsumer.h - Abstract interface for reading ASTs ----*- C++ -*-===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10193326Sed//  This file defines the ASTConsumer class.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed
14193326Sed#ifndef LLVM_CLANG_AST_ASTCONSUMER_H
15193326Sed#define LLVM_CLANG_AST_ASTCONSUMER_H
16193326Sed
17263508Sdim#include "llvm/ADT/StringRef.h"
18263508Sdim
19193326Sednamespace clang {
20193326Sed  class ASTContext;
21208600Srdivacky  class CXXRecordDecl;
22249423Sdim  class Decl;
23193326Sed  class DeclGroupRef;
24193326Sed  class HandleTagDeclDefinition;
25218893Sdim  class ASTMutationListener;
26212904Sdim  class ASTDeserializationListener; // layering violation because void* is ugly
27193326Sed  class SemaConsumer; // layering violation required for safe SemaConsumer
28212904Sdim  class TagDecl;
29193326Sed  class VarDecl;
30234353Sdim  class FunctionDecl;
31243830Sdim  class ImportDecl;
32193326Sed
33193326Sed/// ASTConsumer - This is an abstract interface that should be implemented by
34193326Sed/// clients that read ASTs.  This abstraction layer allows the client to be
35193326Sed/// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
36193326Sedclass ASTConsumer {
37193326Sed  /// \brief Whether this AST consumer also requires information about
38193326Sed  /// semantic analysis.
39193326Sed  bool SemaConsumer;
40193326Sed
41193326Sed  friend class SemaConsumer;
42193326Sed
43193326Sedpublic:
44193326Sed  ASTConsumer() : SemaConsumer(false) { }
45193326Sed
46193326Sed  virtual ~ASTConsumer() {}
47198092Srdivacky
48193326Sed  /// Initialize - This is called to initialize the consumer, providing the
49198954Srdivacky  /// ASTContext.
50193326Sed  virtual void Initialize(ASTContext &Context) {}
51198092Srdivacky
52193326Sed  /// HandleTopLevelDecl - Handle the specified top-level declaration.  This is
53198954Srdivacky  /// called by the parser to process every top-level Decl*. Note that D can be
54198954Srdivacky  /// the head of a chain of Decls (e.g. for `int a, b` the chain will have two
55198954Srdivacky  /// elements). Use Decl::getNextDeclarator() to walk the chain.
56234353Sdim  ///
57234353Sdim  /// \returns true to continue parsing, or false to abort parsing.
58234353Sdim  virtual bool HandleTopLevelDecl(DeclGroupRef D);
59198092Srdivacky
60212904Sdim  /// HandleInterestingDecl - Handle the specified interesting declaration. This
61212904Sdim  /// is called by the AST reader when deserializing things that might interest
62212904Sdim  /// the consumer. The default implementation forwards to HandleTopLevelDecl.
63212904Sdim  virtual void HandleInterestingDecl(DeclGroupRef D);
64212904Sdim
65193326Sed  /// HandleTranslationUnit - This method is called when the ASTs for entire
66198954Srdivacky  /// translation unit have been parsed.
67198092Srdivacky  virtual void HandleTranslationUnit(ASTContext &Ctx) {}
68198092Srdivacky
69193326Sed  /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
70193326Sed  /// (e.g. struct, union, enum, class) is completed.  This allows the client to
71193326Sed  /// hack on the type, which can occur at any point in the file (because these
72193326Sed  /// can be defined in declspecs).
73193326Sed  virtual void HandleTagDeclDefinition(TagDecl *D) {}
74198092Srdivacky
75263508Sdim  /// \brief This callback is invoked the first time each TagDecl is required to
76263508Sdim  /// be complete.
77263508Sdim  virtual void HandleTagDeclRequiredDefinition(const TagDecl *D) {}
78263508Sdim
79234353Sdim  /// \brief Invoked when a function is implicitly instantiated.
80234353Sdim  /// Note that at this point point it does not have a body, its body is
81234353Sdim  /// instantiated at the end of the translation unit and passed to
82234353Sdim  /// HandleTopLevelDecl.
83234353Sdim  virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) {}
84234353Sdim
85234353Sdim  /// \brief Handle the specified top-level declaration that occurred inside
86234353Sdim  /// and ObjC container.
87234353Sdim  /// The default implementation ignored them.
88234353Sdim  virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D);
89234353Sdim
90243830Sdim  /// \brief Handle an ImportDecl that was implicitly created due to an
91243830Sdim  /// inclusion directive.
92243830Sdim  /// The default implementation passes it to HandleTopLevelDecl.
93243830Sdim  virtual void HandleImplicitImportDecl(ImportDecl *D);
94243830Sdim
95263508Sdim  /// \brief Handle a pragma that appends to Linker Options.  Currently this
96263508Sdim  /// only exists to support Microsoft's #pragma comment(linker, "/foo").
97263508Sdim  virtual void HandleLinkerOptionPragma(llvm::StringRef Opts) {}
98263508Sdim
99263508Sdim  /// \brief Handle a pragma that emits a mismatch identifier and value to the
100263508Sdim  /// object file for the linker to work with.  Currently, this only exists to
101263508Sdim  /// support Microsoft's #pragma detect_mismatch.
102263508Sdim  virtual void HandleDetectMismatch(llvm::StringRef Name,
103263508Sdim                                    llvm::StringRef Value) {}
104263508Sdim
105263508Sdim  /// \brief Handle a dependent library created by a pragma in the source.
106263508Sdim  /// Currently this only exists to support Microsoft's
107263508Sdim  /// #pragma comment(lib, "/foo").
108263508Sdim  virtual void HandleDependentLibrary(llvm::StringRef Lib) {}
109263508Sdim
110198954Srdivacky  /// CompleteTentativeDefinition - Callback invoked at the end of a translation
111198954Srdivacky  /// unit to notify the consumer that the given tentative definition should be
112198954Srdivacky  /// completed.
113193326Sed  ///
114193326Sed  /// The variable declaration itself will be a tentative
115193326Sed  /// definition. If it had an incomplete array type, its type will
116193326Sed  /// have already been changed to an array of size 1. However, the
117193326Sed  /// declaration remains a tentative definition and has not been
118193326Sed  /// modified by the introduction of an implicit zero initializer.
119193326Sed  virtual void CompleteTentativeDefinition(VarDecl *D) {}
120193326Sed
121234353Sdim  /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this
122234353Sdim  // variable has been instantiated.
123234353Sdim  virtual void HandleCXXStaticMemberVarInstantiation(VarDecl *D) {}
124234353Sdim
125208600Srdivacky  /// \brief Callback involved at the end of a translation unit to
126208600Srdivacky  /// notify the consumer that a vtable for the given C++ class is
127208600Srdivacky  /// required.
128208600Srdivacky  ///
129208600Srdivacky  /// \param RD The class whose vtable was used.
130208600Srdivacky  ///
131208600Srdivacky  /// \param DefinitionRequired Whether a definition of this vtable is
132208600Srdivacky  /// required in this translation unit; otherwise, it is only needed if
133208600Srdivacky  /// it was actually used.
134208600Srdivacky  virtual void HandleVTable(CXXRecordDecl *RD, bool DefinitionRequired) {}
135208600Srdivacky
136218893Sdim  /// \brief If the consumer is interested in entities getting modified after
137218893Sdim  /// their initial creation, it should return a pointer to
138221345Sdim  /// an ASTMutationListener here.
139218893Sdim  virtual ASTMutationListener *GetASTMutationListener() { return 0; }
140218893Sdim
141212904Sdim  /// \brief If the consumer is interested in entities being deserialized from
142212904Sdim  /// AST files, it should return a pointer to a ASTDeserializationListener here
143234353Sdim  virtual ASTDeserializationListener *GetASTDeserializationListener() {
144234353Sdim    return 0;
145234353Sdim  }
146212904Sdim
147193326Sed  /// PrintStats - If desired, print any statistics.
148198954Srdivacky  virtual void PrintStats() {}
149249423Sdim
150249423Sdim  /// \brief This callback is called for each function if the Parser was
151249423Sdim  /// initialized with \c SkipFunctionBodies set to \c true.
152249423Sdim  ///
153249423Sdim  /// \return \c true if the function's body should be skipped. The function
154249423Sdim  /// body may be parsed anyway if it is needed (for instance, if it contains
155249423Sdim  /// the code completion point or is constexpr).
156249423Sdim  virtual bool shouldSkipFunctionBody(Decl *D) { return true; }
157193326Sed};
158193326Sed
159193326Sed} // end namespace clang.
160193326Sed
161193326Sed#endif
162