clang 20.0.0git
TemplateArgumentVisitor.h
Go to the documentation of this file.
1//===- TemplateArgumentVisitor.h - Visitor for TArg 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 TemplateArgumentVisitor interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
14#define LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
15
17
18namespace clang {
19
20namespace templateargumentvisitor {
21
22/// A simple visitor class that helps create template argument visitors.
23template <template <typename> class Ref, typename ImplClass,
24 typename RetTy = void, typename... ParamTys>
25class Base {
26public:
27#define REF(CLASS) typename Ref<CLASS>::type
28#define DISPATCH(NAME) \
29 case TemplateArgument::NAME: \
30 return static_cast<ImplClass *>(this)->Visit##NAME##TemplateArgument( \
31 TA, std::forward<ParamTys>(P)...)
32
33 RetTy Visit(REF(TemplateArgument) TA, ParamTys... P) {
34 switch (TA.getKind()) {
35 DISPATCH(Null);
38 DISPATCH(NullPtr);
39 DISPATCH(Integral);
40 DISPATCH(StructuralValue);
41 DISPATCH(Template);
42 DISPATCH(TemplateExpansion);
44 DISPATCH(Pack);
45 }
46 llvm_unreachable("TemplateArgument is not covered in switch!");
47 }
48
49 // If the implementation chooses not to implement a certain visit
50 // method, fall back to the parent.
51
52#define VISIT_METHOD(CATEGORY) \
53 RetTy Visit##CATEGORY##TemplateArgument(REF(TemplateArgument) TA, \
54 ParamTys... P) { \
55 return static_cast<ImplClass *>(this)->VisitTemplateArgument( \
56 TA, std::forward<ParamTys>(P)...); \
57 }
58
62 VISIT_METHOD(NullPtr);
63 VISIT_METHOD(Integral);
64 VISIT_METHOD(StructuralValue);
65 VISIT_METHOD(Template);
66 VISIT_METHOD(TemplateExpansion);
69
71 return RetTy();
72 }
73
74#undef REF
75#undef DISPATCH
76#undef VISIT_METHOD
77};
78
79} // namespace templateargumentvisitor
80
81/// A simple visitor class that helps create template argument visitors.
82///
83/// This class does not preserve constness of TemplateArgument references (see
84/// also ConstTemplateArgumentVisitor).
85template <typename ImplClass, typename RetTy = void, typename... ParamTys>
87 : public templateargumentvisitor::Base<std::add_lvalue_reference, ImplClass,
88 RetTy, ParamTys...> {};
89
90/// A simple visitor class that helps create template argument visitors.
91///
92/// This class preserves constness of TemplateArgument references (see also
93/// TemplateArgumentVisitor).
94template <typename ImplClass, typename RetTy = void, typename... ParamTys>
96 : public templateargumentvisitor::Base<llvm::make_const_ref, ImplClass,
97 RetTy, ParamTys...> {};
98
99} // namespace clang
100
101#endif // LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
StringRef P
#define DISPATCH(NAME)
Definition: AttrVisitor.h:28
#define REF(CLASS)
A simple visitor class that helps create template argument visitors.
A simple visitor class that helps create template argument visitors.
Represents a template argument.
Definition: TemplateBase.h:61
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
The base class of the type hierarchy.
Definition: Type.h:1828
A simple visitor class that helps create template argument visitors.
RetTy Visit(REF(TemplateArgument) TA, ParamTys... P)
RetTy VisitTemplateArgument(REF(TemplateArgument), ParamTys...)
The JSON file list parser is used to communicate input to InstallAPI.