TypeLocVisitor.h revision 51bd803fbdade51d674598ed45da3d54190a656c
1//===--- TypeLocVisitor.h - Visitor for TypeLoc 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 TypeLocVisitor interface. 11// 12//===----------------------------------------------------------------------===// 13#ifndef LLVM_CLANG_AST_TYPELOCVISITOR_H 14#define LLVM_CLANG_AST_TYPELOCVISITOR_H 15 16#include "clang/AST/TypeLoc.h" 17#include "clang/AST/TypeVisitor.h" 18#include "llvm/Support/ErrorHandling.h" 19 20namespace clang { 21 22#define DISPATCH(CLASSNAME) \ 23 return static_cast<ImplClass*>(this)-> \ 24 Visit##CLASSNAME(cast<CLASSNAME>(TyLoc)) 25 26template<typename ImplClass, typename RetTy=void> 27class TypeLocVisitor { 28public: 29 RetTy Visit(TypeLoc TyLoc) { 30 switch (TyLoc.getTypeLocClass()) { 31#define ABSTRACT_TYPELOC(CLASS, PARENT) 32#define TYPELOC(CLASS, PARENT) \ 33 case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc); 34#include "clang/AST/TypeLocNodes.def" 35 } 36 llvm::llvm_unreachable("unexpected type loc class!"); 37 } 38 39 RetTy Visit(UnqualTypeLoc TyLoc) { 40 switch (TyLoc.getTypeLocClass()) { 41#define ABSTRACT_TYPELOC(CLASS, PARENT) 42#define TYPELOC(CLASS, PARENT) \ 43 case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc); 44#include "clang/AST/TypeLocNodes.def" 45 } 46 } 47 48#define TYPELOC(CLASS, PARENT) \ 49 RetTy Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \ 50 DISPATCH(PARENT); \ 51 } 52#include "clang/AST/TypeLocNodes.def" 53 54 RetTy VisitTypeLoc(TypeLoc TyLoc) { return RetTy(); } 55}; 56 57#undef DISPATCH 58 59} // end namespace clang 60 61#endif // LLVM_CLANG_AST_TYPELOCVISITOR_H 62