clang 8.0.0

TemplateArgumentVisitor.h
Go to the documentation of this file.
1 //===- TemplateArgumentVisitor.h - Visitor for TArg 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 TemplateArgumentVisitor interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
15 #define LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
16
17 #include "clang/AST/TemplateBase.h"
18
19 namespace clang {
20
21 namespace templateargumentvisitor {
22
23 /// A simple visitor class that helps create template argument visitors.
24 template <template <typename> class Ref, typename ImplClass,
25 typename RetTy = void, typename... ParamTys>
26 class Base {
27 public:
28 #define REF(CLASS) typename Ref<CLASS>::type
29 #define DISPATCH(NAME) \
30 case TemplateArgument::NAME: \
31 return static_cast<ImplClass *>(this)->Visit##NAME##TemplateArgument( \
32 TA, std::forward<ParamTys>(P)...)
33
34 RetTy Visit(REF(TemplateArgument) TA, ParamTys... P) {
35 switch (TA.getKind()) {
36 DISPATCH(Null);
37 DISPATCH(Type);
38 DISPATCH(Declaration);
39 DISPATCH(NullPtr);
40 DISPATCH(Integral);
41 DISPATCH(Template);
42 DISPATCH(TemplateExpansion);
43 DISPATCH(Expression);
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 VisitTemplateArgument(TA, std::forward<ParamTys>(P)...); \
56 }
57
58 VISIT_METHOD(Null);
59 VISIT_METHOD(Type);
60 VISIT_METHOD(Declaration);
61 VISIT_METHOD(NullPtr);
62 VISIT_METHOD(Integral);
63 VISIT_METHOD(Template);
64 VISIT_METHOD(TemplateExpansion);
65 VISIT_METHOD(Expression);
66 VISIT_METHOD(Pack);
67
68 RetTy VisitTemplateArgument(REF(TemplateArgument), ParamTys...) {
69 return RetTy();
70 }
71
72 #undef REF
73 #undef DISPATCH
74 #undef VISIT_METHOD
75 };
76
77 } // namespace templateargumentvisitor
78
79 /// A simple visitor class that helps create template argument visitors.
80 ///
81 /// This class does not preserve constness of TemplateArgument references (see
82 /// also ConstTemplateArgumentVisitor).
83 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
84 class TemplateArgumentVisitor
85 : public templateargumentvisitor::Base<std::add_lvalue_reference, ImplClass,
86 RetTy, ParamTys...> {};
87
88 /// A simple visitor class that helps create template argument visitors.
89 ///
90 /// This class preserves constness of TemplateArgument references (see also
91 /// TemplateArgumentVisitor).
92 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
93 class ConstTemplateArgumentVisitor
94 : public templateargumentvisitor::Base<llvm::make_const_ref, ImplClass,
95 RetTy, ParamTys...> {};
96
97 } // namespace clang
98
99 #endif // LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
clang::templateargumentvisitor::Base::VisitTemplateArgument
RetTy VisitTemplateArgument(REF(TemplateArgument), ParamTys...)
Definition: TemplateArgumentVisitor.h:68
clang::templateargumentvisitor::Base::Visit
RetTy Visit(REF(TemplateArgument) TA, ParamTys... P)
Definition: TemplateArgumentVisitor.h:34
P
StringRef P
Definition: ASTMatchersInternal.cpp:439
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1407
REF
#define REF(CLASS)
Definition: TemplateArgumentVisitor.h:28
clang::TemplateArgumentVisitor
A simple visitor class that helps create template argument visitors.
Definition: TemplateArgumentVisitor.h:84
clang::ConstTemplateArgumentVisitor
A simple visitor class that helps create template argument visitors.
Definition: TemplateArgumentVisitor.h:93
clang::templateargumentvisitor::Base
A simple visitor class that helps create template argument visitors.
Definition: TemplateArgumentVisitor.h:26
clang::TemplateArgument
Represents a template argument.
Definition: TemplateBase.h:51
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
TemplateBase.h
clang::TemplateArgument::getKind
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:235
clang::templateargumentvisitor::Base::VISIT_METHOD
VISIT_METHOD(Null)
DISPATCH
#define DISPATCH(NAME)
Definition: TemplateArgumentVisitor.h:29