1208600Srdivacky//===--- TypeVisitor.h - Visitor for Type subclasses ------------*- C++ -*-===//
2194613Sed//
3194613Sed//                     The LLVM Compiler Infrastructure
4194613Sed//
5194613Sed// This file is distributed under the University of Illinois Open Source
6194613Sed// License. See LICENSE.TXT for details.
7194613Sed//
8194613Sed//===----------------------------------------------------------------------===//
9194613Sed//
10194613Sed//  This file defines the TypeVisitor interface.
11194613Sed//
12194613Sed//===----------------------------------------------------------------------===//
13194613Sed
14194613Sed#ifndef LLVM_CLANG_AST_TYPEVISITOR_H
15194613Sed#define LLVM_CLANG_AST_TYPEVISITOR_H
16194613Sed
17194613Sed#include "clang/AST/Type.h"
18194613Sed
19194613Sednamespace clang {
20198092Srdivacky
21194613Sed#define DISPATCH(CLASS) \
22218893Sdim  return static_cast<ImplClass*>(this)-> \
23218893Sdim           Visit##CLASS(static_cast<const CLASS*>(T))
24198092Srdivacky
25194613Sedtemplate<typename ImplClass, typename RetTy=void>
26194613Sedclass TypeVisitor {
27194613Sedpublic:
28218893Sdim  RetTy Visit(const Type *T) {
29208600Srdivacky    // Top switch stmt: dispatch to VisitFooType for each FooType.
30194613Sed    switch (T->getTypeClass()) {
31198092Srdivacky#define ABSTRACT_TYPE(CLASS, PARENT)
32194613Sed#define TYPE(CLASS, PARENT) case Type::CLASS: DISPATCH(CLASS##Type);
33194613Sed#include "clang/AST/TypeNodes.def"
34194613Sed    }
35234353Sdim    llvm_unreachable("Unknown type class!");
36194613Sed  }
37198092Srdivacky
38194613Sed  // If the implementation chooses not to implement a certain visit method, fall
39194613Sed  // back on superclass.
40218893Sdim#define TYPE(CLASS, PARENT) RetTy Visit##CLASS##Type(const CLASS##Type *T) { \
41198092Srdivacky  DISPATCH(PARENT);                                                          \
42198092Srdivacky}
43194613Sed#include "clang/AST/TypeNodes.def"
44194613Sed
45194613Sed  // Base case, ignore it. :)
46218893Sdim  RetTy VisitType(const Type*) { return RetTy(); }
47194613Sed};
48194613Sed
49194613Sed#undef DISPATCH
50194613Sed
51194613Sed}  // end namespace clang
52194613Sed
53194613Sed#endif
54