]> granicus.if.org Git - clang/commitdiff
Extend the CommentVisitor with parameter types
authorStephen Kelly <steveire@gmail.com>
Sun, 2 Dec 2018 17:30:34 +0000 (17:30 +0000)
committerStephen Kelly <steveire@gmail.com>
Sun, 2 Dec 2018 17:30:34 +0000 (17:30 +0000)
Summary:
This has precedent in the StmtVisitor.  This change will make it
possible to clean up the comment handling in ASTDumper.

Reviewers: aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55069

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348100 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/CommentVisitor.h

index d1cc2d0a4e5e1a981e0a9501cbf426254501b093..5845e4fb51d5018a6df20c0ca2d0786ffb3b40c3 100644 (file)
@@ -19,14 +19,16 @@ namespace comments {
 template <typename T> struct make_ptr { using type = T *; };
 template <typename T> struct make_const_ptr { using type = const T *; };
 
-template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
+template <template <typename> class Ptr, typename ImplClass,
+          typename RetTy = void, class... ParamTys>
 class CommentVisitorBase {
 public:
 #define PTR(CLASS) typename Ptr<CLASS>::type
-#define DISPATCH(NAME, CLASS) \
- return static_cast<ImplClass*>(this)->visit ## NAME(static_cast<PTR(CLASS)>(C))
+#define DISPATCH(NAME, CLASS)                                                  \
+  return static_cast<ImplClass *>(this)->visit##NAME(                          \
+      static_cast<PTR(CLASS)>(C), std::forward<ParamTys>(P)...)
 
-  RetTy visit(PTR(Comment) C) {
+  RetTy visit(PTR(Comment) C, ParamTys... P) {
     if (!C)
       return RetTy();
 
@@ -44,25 +46,26 @@ public:
   // If the derived class does not implement a certain Visit* method, fall back
   // on Visit* method for the superclass.
 #define ABSTRACT_COMMENT(COMMENT) COMMENT
-#define COMMENT(CLASS, PARENT) \
-  RetTy visit ## CLASS(PTR(CLASS) C) { DISPATCH(PARENT, PARENT); }
+#define COMMENT(CLASS, PARENT)                                                 \
+  RetTy visit##CLASS(PTR(CLASS) C, ParamTys... P) { DISPATCH(PARENT, PARENT); }
 #include "clang/AST/CommentNodes.inc"
 #undef ABSTRACT_COMMENT
 #undef COMMENT
 
-  RetTy visitComment(PTR(Comment) C) { return RetTy(); }
+  RetTy visitComment(PTR(Comment) C, ParamTys... P) { return RetTy(); }
 
 #undef PTR
 #undef DISPATCH
 };
 
-template<typename ImplClass, typename RetTy=void>
-class CommentVisitor :
-    public CommentVisitorBase<make_ptr, ImplClass, RetTy> {};
+template <typename ImplClass, typename RetTy = void, class... ParamTys>
+class CommentVisitor
+    : public CommentVisitorBase<make_ptr, ImplClass, RetTy, ParamTys...> {};
 
-template<typename ImplClass, typename RetTy=void>
-class ConstCommentVisitor :
-    public CommentVisitorBase<make_const_ptr, ImplClass, RetTy> {};
+template <typename ImplClass, typename RetTy = void, class... ParamTys>
+class ConstCommentVisitor
+    : public CommentVisitorBase<make_const_ptr, ImplClass, RetTy, ParamTys...> {
+};
 
 } // namespace comments
 } // namespace clang