TemplateArgumentVisitor.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- TemplateArgumentVisitor.h - Visitor for TArg subclasses --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the TemplateArgumentVisitor interface.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
  18. #define LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
  19. #include "clang/AST/TemplateBase.h"
  20. namespace clang {
  21. namespace templateargumentvisitor {
  22. /// A simple visitor class that helps create template argument visitors.
  23. template <template <typename> class Ref, typename ImplClass,
  24. typename RetTy = void, typename... ParamTys>
  25. class Base {
  26. public:
  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. RetTy Visit(REF(TemplateArgument) TA, ParamTys... P) {
  33. switch (TA.getKind()) {
  34. DISPATCH(Null);
  35. DISPATCH(Type);
  36. DISPATCH(Declaration);
  37. DISPATCH(NullPtr);
  38. DISPATCH(Integral);
  39. DISPATCH(Template);
  40. DISPATCH(TemplateExpansion);
  41. DISPATCH(Expression);
  42. DISPATCH(Pack);
  43. }
  44. llvm_unreachable("TemplateArgument is not covered in switch!");
  45. }
  46. // If the implementation chooses not to implement a certain visit
  47. // method, fall back to the parent.
  48. #define VISIT_METHOD(CATEGORY) \
  49. RetTy Visit##CATEGORY##TemplateArgument(REF(TemplateArgument) TA, \
  50. ParamTys... P) { \
  51. return VisitTemplateArgument(TA, std::forward<ParamTys>(P)...); \
  52. }
  53. VISIT_METHOD(Null);
  54. VISIT_METHOD(Type);
  55. VISIT_METHOD(Declaration);
  56. VISIT_METHOD(NullPtr);
  57. VISIT_METHOD(Integral);
  58. VISIT_METHOD(Template);
  59. VISIT_METHOD(TemplateExpansion);
  60. VISIT_METHOD(Expression);
  61. VISIT_METHOD(Pack);
  62. RetTy VisitTemplateArgument(REF(TemplateArgument), ParamTys...) {
  63. return RetTy();
  64. }
  65. #undef REF
  66. #undef DISPATCH
  67. #undef VISIT_METHOD
  68. };
  69. } // namespace templateargumentvisitor
  70. /// A simple visitor class that helps create template argument visitors.
  71. ///
  72. /// This class does not preserve constness of TemplateArgument references (see
  73. /// also ConstTemplateArgumentVisitor).
  74. template <typename ImplClass, typename RetTy = void, typename... ParamTys>
  75. class TemplateArgumentVisitor
  76. : public templateargumentvisitor::Base<std::add_lvalue_reference, ImplClass,
  77. RetTy, ParamTys...> {};
  78. /// A simple visitor class that helps create template argument visitors.
  79. ///
  80. /// This class preserves constness of TemplateArgument references (see also
  81. /// TemplateArgumentVisitor).
  82. template <typename ImplClass, typename RetTy = void, typename... ParamTys>
  83. class ConstTemplateArgumentVisitor
  84. : public templateargumentvisitor::Base<llvm::make_const_ref, ImplClass,
  85. RetTy, ParamTys...> {};
  86. } // namespace clang
  87. #endif // LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
  88. #ifdef __GNUC__
  89. #pragma GCC diagnostic pop
  90. #endif