clang API Documentation
00001 //===--- DeclVisitor.h - Visitor for Decl subclasses ------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the DeclVisitor interface. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 #ifndef LLVM_CLANG_AST_DECLVISITOR_H 00014 #define LLVM_CLANG_AST_DECLVISITOR_H 00015 00016 #include "clang/AST/Decl.h" 00017 #include "clang/AST/DeclObjC.h" 00018 #include "clang/AST/DeclCXX.h" 00019 #include "clang/AST/DeclFriend.h" 00020 #include "clang/AST/DeclTemplate.h" 00021 00022 namespace clang { 00023 00024 #define DISPATCH(NAME, CLASS) \ 00025 return static_cast<ImplClass*>(this)-> Visit##NAME(static_cast<CLASS*>(D)) 00026 00027 /// \brief A simple visitor class that helps create declaration visitors. 00028 template<typename ImplClass, typename RetTy=void> 00029 class DeclVisitor { 00030 public: 00031 RetTy Visit(Decl *D) { 00032 switch (D->getKind()) { 00033 #define DECL(DERIVED, BASE) \ 00034 case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl); 00035 #define ABSTRACT_DECL(DECL) 00036 #include "clang/AST/DeclNodes.inc" 00037 } 00038 llvm_unreachable("Decl that isn't part of DeclNodes.inc!"); 00039 } 00040 00041 // If the implementation chooses not to implement a certain visit 00042 // method, fall back to the parent. 00043 #define DECL(DERIVED, BASE) \ 00044 RetTy Visit##DERIVED##Decl(DERIVED##Decl *D) { DISPATCH(BASE, BASE); } 00045 #include "clang/AST/DeclNodes.inc" 00046 00047 RetTy VisitDecl(Decl *D) { return RetTy(); } 00048 }; 00049 00050 #undef DISPATCH 00051 00052 } // end namespace clang 00053 00054 #endif // LLVM_CLANG_AST_DECLVISITOR_H