1 //===--- TypeLocVisitor.h - Visitor for TypeLoc subclasses ------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the TypeLocVisitor interface.
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_CLANG_AST_TYPELOCVISITOR_H
13 #define LLVM_CLANG_AST_TYPELOCVISITOR_H
15 #include "clang/AST/TypeLoc.h"
16 #include "clang/AST/TypeVisitor.h"
17 #include "llvm/Support/ErrorHandling.h"
21 #define DISPATCH(CLASSNAME) \
22 return static_cast<ImplClass*>(this)-> \
23 Visit##CLASSNAME(TyLoc.castAs<CLASSNAME>())
25 template<typename ImplClass, typename RetTy=void>
26 class TypeLocVisitor {
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"
35 llvm_unreachable("unexpected type loc class!");
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"
45 llvm_unreachable("unexpected type loc class!");
48 #define TYPELOC(CLASS, PARENT) \
49 RetTy Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
52 #include "clang/AST/TypeLocNodes.def"
54 RetTy VisitTypeLoc(TypeLoc TyLoc) { return RetTy(); }
59 } // end namespace clang
61 #endif // LLVM_CLANG_AST_TYPELOCVISITOR_H