1 //===--- TypeVisitor.h - Visitor for Type subclasses ------------*- 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 TypeVisitor interface. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_AST_TYPEVISITOR_H 15 #define LLVM_CLANG_AST_TYPEVISITOR_H 16 17 #include "clang/AST/Type.h" 18 19 namespace clang { 20 21 #define DISPATCH(CLASS) \ 22 return static_cast<ImplClass*>(this)-> \ 23 Visit##CLASS(static_cast<const CLASS*>(T)) 24 25 template<typename ImplClass, typename RetTy=void> 26 class TypeVisitor { 27 public: Visit(const Type * T)28 RetTy Visit(const Type *T) { 29 // Top switch stmt: dispatch to VisitFooType for each FooType. 30 switch (T->getTypeClass()) { 31 #define ABSTRACT_TYPE(CLASS, PARENT) 32 #define TYPE(CLASS, PARENT) case Type::CLASS: DISPATCH(CLASS##Type); 33 #include "clang/AST/TypeNodes.def" 34 } 35 llvm_unreachable("Unknown type class!"); 36 } 37 38 // If the implementation chooses not to implement a certain visit method, fall 39 // back on superclass. 40 #define TYPE(CLASS, PARENT) RetTy Visit##CLASS##Type(const CLASS##Type *T) { \ 41 DISPATCH(PARENT); \ 42 } 43 #include "clang/AST/TypeNodes.def" 44 45 // Base case, ignore it. :) VisitType(const Type *)46 RetTy VisitType(const Type*) { return RetTy(); } 47 }; 48 49 #undef DISPATCH 50 51 } // end namespace clang 52 53 #endif 54