ASTConsumer.h revision 91c027e2021366396696977af7fdc0e070bdd614
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
17namespace clang {
18  class ASTContext;
19  class TranslationUnit;
20  class Decl;
21  class TagDecl;
22  class HandleTagDeclDefinition;
23
24/// ASTConsumer - This is an abstract interface that should be implemented by
25/// clients that read ASTs.  This abstraction layer allows the client to be
26/// independent of the AST producer (e.g. parser vs AST dump file reader, etc).
27class ASTConsumer {
28public:
29  virtual ~ASTConsumer();
30
31  /// Initialize - This is called to initialize the consumer, providing the
32  /// ASTContext.
33  virtual void Initialize(ASTContext &Context) {}
34
35  virtual void InitializeTU(TranslationUnit& TU);
36
37  /// HandleTopLevelDecl - Handle the specified top-level declaration.  This is
38  ///  called by the parser to process every top-level Decl*. Note that D can
39  ///  be the head of a chain of Decls (e.g. for `int a, b` the chain will have
40  ///  two elements). Use ScopedDecl::getNextDeclarator() to walk the chain.
41  virtual void HandleTopLevelDecl(Decl *D) {}
42
43  /// HandleTranslationUnit - This method is called when the ASTs for entire
44  ///  translation unit have been parsed.
45  virtual void HandleTranslationUnit(TranslationUnit& TU) {}
46
47  /// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
48  /// (e.g. struct, union, enum, class) is completed.  This allows the client to
49  /// hack on the type, which can occur at any point in the file (because these
50  /// can be defined in declspecs).
51  virtual void HandleTagDeclDefinition(TagDecl *D) {}
52
53  /// PrintStats - If desired, print any statistics.
54  virtual void PrintStats() {
55  }
56};
57
58} // end namespace clang.
59
60#endif
61