File indexing completed on 2026-05-10 08:36:30
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_AST_COMMENTVISITOR_H
0010 #define LLVM_CLANG_AST_COMMENTVISITOR_H
0011
0012 #include "clang/AST/Comment.h"
0013 #include "llvm/ADT/STLExtras.h"
0014 #include "llvm/Support/ErrorHandling.h"
0015
0016 namespace clang {
0017 namespace comments {
0018 template <template <typename> class Ptr, typename ImplClass,
0019 typename RetTy = void, class... ParamTys>
0020 class CommentVisitorBase {
0021 public:
0022 #define PTR(CLASS) typename Ptr<CLASS>::type
0023 #define DISPATCH(NAME, CLASS) \
0024 return static_cast<ImplClass *>(this)->visit##NAME( \
0025 static_cast<PTR(CLASS)>(C), std::forward<ParamTys>(P)...)
0026
0027 RetTy visit(PTR(Comment) C, ParamTys... P) {
0028 if (!C)
0029 return RetTy();
0030
0031 switch (C->getCommentKind()) {
0032 default: llvm_unreachable("Unknown comment kind!");
0033 #define ABSTRACT_COMMENT(COMMENT)
0034 #define COMMENT(CLASS, PARENT) \
0035 case CommentKind::CLASS: \
0036 DISPATCH(CLASS, CLASS);
0037 #include "clang/AST/CommentNodes.inc"
0038 #undef ABSTRACT_COMMENT
0039 #undef COMMENT
0040 }
0041 }
0042
0043
0044
0045 #define ABSTRACT_COMMENT(COMMENT) COMMENT
0046 #define COMMENT(CLASS, PARENT) \
0047 RetTy visit##CLASS(PTR(CLASS) C, ParamTys... P) { DISPATCH(PARENT, PARENT); }
0048 #include "clang/AST/CommentNodes.inc"
0049 #undef ABSTRACT_COMMENT
0050 #undef COMMENT
0051
0052 RetTy visitComment(PTR(Comment) C, ParamTys... P) { return RetTy(); }
0053
0054 #undef PTR
0055 #undef DISPATCH
0056 };
0057
0058 template <typename ImplClass, typename RetTy = void, class... ParamTys>
0059 class CommentVisitor : public CommentVisitorBase<std::add_pointer, ImplClass,
0060 RetTy, ParamTys...> {};
0061
0062 template <typename ImplClass, typename RetTy = void, class... ParamTys>
0063 class ConstCommentVisitor
0064 : public CommentVisitorBase<llvm::make_const_ptr, ImplClass, RetTy,
0065 ParamTys...> {};
0066
0067 }
0068 }
0069
0070 #endif