1 //===--- DeclVisitor.h - Visitor for Decl subclasses ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the DeclVisitor interface.
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_AST_DECLVISITOR_H
14 #define LLVM_CLANG_AST_DECLVISITOR_H
16 #include "clang/AST/Decl.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclFriend.h"
20 #include "clang/AST/DeclTemplate.h"
24 #define DISPATCH(NAME, CLASS) \
25 return static_cast<ImplClass*>(this)-> Visit##NAME(static_cast<CLASS*>(D))
27 /// \brief A simple visitor class that helps create declaration visitors.
28 template<typename ImplClass, typename RetTy=void>
31 RetTy Visit(Decl *D) {
32 switch (D->getKind()) {
33 default: assert(false && "Decl that isn't part of DeclNodes.inc!");
34 #define DECL(DERIVED, BASE) \
35 case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl);
36 #define ABSTRACT_DECL(DECL)
37 #include "clang/AST/DeclNodes.inc"
41 // If the implementation chooses not to implement a certain visit
42 // method, fall back to the parent.
43 #define DECL(DERIVED, BASE) \
44 RetTy Visit##DERIVED##Decl(DERIVED##Decl *D) { DISPATCH(BASE, BASE); }
45 #include "clang/AST/DeclNodes.inc"
47 RetTy VisitDecl(Decl *D) { return RetTy(); }
52 } // end namespace clang
54 #endif // LLVM_CLANG_AST_DECLVISITOR_H