aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/clang14/include/clang/AST/TemplateArgumentVisitor.h
blob: 90ea6d41d13f062fa73edfe9c7df3e84a9aca1e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif

//===- TemplateArgumentVisitor.h - Visitor for TArg subclasses --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//  This file defines the TemplateArgumentVisitor interface.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
#define LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H

#include "clang/AST/TemplateBase.h"

namespace clang {

namespace templateargumentvisitor {

/// A simple visitor class that helps create template argument visitors.
template <template <typename> class Ref, typename ImplClass,
          typename RetTy = void, typename... ParamTys>
class Base {
public:
#define REF(CLASS) typename Ref<CLASS>::type
#define DISPATCH(NAME)                                                         \
  case TemplateArgument::NAME:                                                 \
    return static_cast<ImplClass *>(this)->Visit##NAME##TemplateArgument(      \
        TA, std::forward<ParamTys>(P)...)

  RetTy Visit(REF(TemplateArgument) TA, ParamTys... P) {
    switch (TA.getKind()) {
      DISPATCH(Null);
      DISPATCH(Type);
      DISPATCH(Declaration);
      DISPATCH(NullPtr);
      DISPATCH(Integral);
      DISPATCH(Template);
      DISPATCH(TemplateExpansion);
      DISPATCH(Expression);
      DISPATCH(Pack);
    }
    llvm_unreachable("TemplateArgument is not covered in switch!");
  }

  // If the implementation chooses not to implement a certain visit
  // method, fall back to the parent.

#define VISIT_METHOD(CATEGORY)                                                 \
  RetTy Visit##CATEGORY##TemplateArgument(REF(TemplateArgument) TA,            \
                                          ParamTys... P) {                     \
    return VisitTemplateArgument(TA, std::forward<ParamTys>(P)...);            \
  }

  VISIT_METHOD(Null);
  VISIT_METHOD(Type);
  VISIT_METHOD(Declaration);
  VISIT_METHOD(NullPtr);
  VISIT_METHOD(Integral);
  VISIT_METHOD(Template);
  VISIT_METHOD(TemplateExpansion);
  VISIT_METHOD(Expression);
  VISIT_METHOD(Pack);

  RetTy VisitTemplateArgument(REF(TemplateArgument), ParamTys...) {
    return RetTy();
  }

#undef REF
#undef DISPATCH
#undef VISIT_METHOD
};

} // namespace templateargumentvisitor

/// A simple visitor class that helps create template argument visitors.
///
/// This class does not preserve constness of TemplateArgument references (see
/// also ConstTemplateArgumentVisitor).
template <typename ImplClass, typename RetTy = void, typename... ParamTys>
class TemplateArgumentVisitor
    : public templateargumentvisitor::Base<std::add_lvalue_reference, ImplClass,
                                           RetTy, ParamTys...> {};

/// A simple visitor class that helps create template argument visitors.
///
/// This class preserves constness of TemplateArgument references (see also
/// TemplateArgumentVisitor).
template <typename ImplClass, typename RetTy = void, typename... ParamTys>
class ConstTemplateArgumentVisitor
    : public templateargumentvisitor::Base<llvm::make_const_ref, ImplClass,
                                           RetTy, ParamTys...> {};

} // namespace clang

#endif // LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif