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(TyLoc.castAs<CLASSNAME>())
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_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    llvm_unreachable("unexpected type loc class!");
47  }
48
49#define TYPELOC(CLASS, PARENT)      \
50  RetTy Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
51    DISPATCH(PARENT);               \
52  }
53#include "clang/AST/TypeLocNodes.def"
54
55  RetTy VisitTypeLoc(TypeLoc TyLoc) { return RetTy(); }
56};
57
58#undef DISPATCH
59
60}  // end namespace clang
61
62#endif // LLVM_CLANG_AST_TYPELOCVISITOR_H
63