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 "llvm/Support/ErrorHandling.h"
17 
18 namespace clang {
19 
20 #define DISPATCH(CLASSNAME) \
21   return static_cast<ImplClass*>(this)-> \
22     Visit##CLASSNAME(TyLoc.castAs<CLASSNAME>())
23 
24 template<typename ImplClass, typename RetTy=void>
25 class TypeLocVisitor {
26 public:
Visit(TypeLoc TyLoc)27   RetTy Visit(TypeLoc TyLoc) {
28     switch (TyLoc.getTypeLocClass()) {
29 #define ABSTRACT_TYPELOC(CLASS, PARENT)
30 #define TYPELOC(CLASS, PARENT) \
31     case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc);
32 #include "clang/AST/TypeLocNodes.def"
33     }
34     llvm_unreachable("unexpected type loc class!");
35   }
36 
Visit(UnqualTypeLoc TyLoc)37   RetTy Visit(UnqualTypeLoc TyLoc) {
38     switch (TyLoc.getTypeLocClass()) {
39 #define ABSTRACT_TYPELOC(CLASS, PARENT)
40 #define TYPELOC(CLASS, PARENT) \
41     case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc);
42 #include "clang/AST/TypeLocNodes.def"
43     }
44     llvm_unreachable("unexpected type loc class!");
45   }
46 
47 #define TYPELOC(CLASS, PARENT)      \
48   RetTy Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
49     DISPATCH(PARENT);               \
50   }
51 #include "clang/AST/TypeLocNodes.def"
52 
VisitTypeLoc(TypeLoc TyLoc)53   RetTy VisitTypeLoc(TypeLoc TyLoc) { return RetTy(); }
54 };
55 
56 #undef DISPATCH
57 
58 }  // end namespace clang
59 
60 #endif // LLVM_CLANG_AST_TYPELOCVISITOR_H
61