1//===--- TypeLocVisitor.h - Visitor for TypeLoc subclasses ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9//  This file defines the TypeLocVisitor interface.
10//
11//===----------------------------------------------------------------------===//
12#ifndef LLVM_CLANG_AST_TYPELOCVISITOR_H
13#define LLVM_CLANG_AST_TYPELOCVISITOR_H
14
15#include "clang/AST/TypeLoc.h"
16#include "clang/AST/TypeVisitor.h"
17#include "llvm/Support/ErrorHandling.h"
18
19namespace clang {
20
21#define DISPATCH(CLASSNAME) \
22  return static_cast<ImplClass*>(this)-> \
23    Visit##CLASSNAME(TyLoc.castAs<CLASSNAME>())
24
25template<typename ImplClass, typename RetTy=void>
26class TypeLocVisitor {
27public:
28  RetTy Visit(TypeLoc TyLoc) {
29    switch (TyLoc.getTypeLocClass()) {
30#define ABSTRACT_TYPELOC(CLASS, PARENT)
31#define TYPELOC(CLASS, PARENT) \
32    case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc);
33#include "clang/AST/TypeLocNodes.def"
34    }
35    llvm_unreachable("unexpected type loc class!");
36  }
37
38  RetTy Visit(UnqualTypeLoc TyLoc) {
39    switch (TyLoc.getTypeLocClass()) {
40#define ABSTRACT_TYPELOC(CLASS, PARENT)
41#define TYPELOC(CLASS, PARENT) \
42    case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc);
43#include "clang/AST/TypeLocNodes.def"
44    }
45    llvm_unreachable("unexpected type loc class!");
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