Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:43

0001 //===- TemplateArgumentVisitor.h - Visitor for TArg subclasses --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines the TemplateArgumentVisitor interface.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
0014 #define LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H
0015 
0016 #include "clang/AST/TemplateBase.h"
0017 
0018 namespace clang {
0019 
0020 namespace templateargumentvisitor {
0021 
0022 /// A simple visitor class that helps create template argument visitors.
0023 template <template <typename> class Ref, typename ImplClass,
0024           typename RetTy = void, typename... ParamTys>
0025 class Base {
0026 public:
0027 #define REF(CLASS) typename Ref<CLASS>::type
0028 #define DISPATCH(NAME)                                                         \
0029   case TemplateArgument::NAME:                                                 \
0030     return static_cast<ImplClass *>(this)->Visit##NAME##TemplateArgument(      \
0031         TA, std::forward<ParamTys>(P)...)
0032 
0033   RetTy Visit(REF(TemplateArgument) TA, ParamTys... P) {
0034     switch (TA.getKind()) {
0035       DISPATCH(Null);
0036       DISPATCH(Type);
0037       DISPATCH(Declaration);
0038       DISPATCH(NullPtr);
0039       DISPATCH(Integral);
0040       DISPATCH(StructuralValue);
0041       DISPATCH(Template);
0042       DISPATCH(TemplateExpansion);
0043       DISPATCH(Expression);
0044       DISPATCH(Pack);
0045     }
0046     llvm_unreachable("TemplateArgument is not covered in switch!");
0047   }
0048 
0049   // If the implementation chooses not to implement a certain visit
0050   // method, fall back to the parent.
0051 
0052 #define VISIT_METHOD(CATEGORY)                                                 \
0053   RetTy Visit##CATEGORY##TemplateArgument(REF(TemplateArgument) TA,            \
0054                                           ParamTys... P) {                     \
0055     return static_cast<ImplClass *>(this)->VisitTemplateArgument(              \
0056         TA, std::forward<ParamTys>(P)...);                                     \
0057   }
0058 
0059   VISIT_METHOD(Null);
0060   VISIT_METHOD(Type);
0061   VISIT_METHOD(Declaration);
0062   VISIT_METHOD(NullPtr);
0063   VISIT_METHOD(Integral);
0064   VISIT_METHOD(StructuralValue);
0065   VISIT_METHOD(Template);
0066   VISIT_METHOD(TemplateExpansion);
0067   VISIT_METHOD(Expression);
0068   VISIT_METHOD(Pack);
0069 
0070   RetTy VisitTemplateArgument(REF(TemplateArgument), ParamTys...) {
0071     return RetTy();
0072   }
0073 
0074 #undef REF
0075 #undef DISPATCH
0076 #undef VISIT_METHOD
0077 };
0078 
0079 } // namespace templateargumentvisitor
0080 
0081 /// A simple visitor class that helps create template argument visitors.
0082 ///
0083 /// This class does not preserve constness of TemplateArgument references (see
0084 /// also ConstTemplateArgumentVisitor).
0085 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
0086 class TemplateArgumentVisitor
0087     : public templateargumentvisitor::Base<std::add_lvalue_reference, ImplClass,
0088                                            RetTy, ParamTys...> {};
0089 
0090 /// A simple visitor class that helps create template argument visitors.
0091 ///
0092 /// This class preserves constness of TemplateArgument references (see also
0093 /// TemplateArgumentVisitor).
0094 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
0095 class ConstTemplateArgumentVisitor
0096     : public templateargumentvisitor::Base<llvm::make_const_ref, ImplClass,
0097                                            RetTy, ParamTys...> {};
0098 
0099 } // namespace clang
0100 
0101 #endif // LLVM_CLANG_AST_TEMPLATEARGUMENTVISITOR_H