1 //===--- TypeVisitor.h - Visitor for Type 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 TypeVisitor interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_TYPEVISITOR_H
15 #define LLVM_CLANG_AST_TYPEVISITOR_H
17 #include "clang/AST/Type.h"
21 #define DISPATCH(CLASS) \
22 return static_cast<ImplClass*>(this)-> \
23 Visit##CLASS(static_cast<const CLASS*>(T))
25 template<typename ImplClass, typename RetTy=void>
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"
35 llvm_unreachable("Unknown type class!");
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) { \
43 #include "clang/AST/TypeNodes.def"
45 // Base case, ignore it. :)
46 RetTy VisitType(const Type*) { return RetTy(); }
51 } // end namespace clang