1 //===--- CommentVisitor.h - Visitor for Comment subclasses ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/AST/Comment.h"
11 #include "llvm/Support/ErrorHandling.h"
16 template <typename T> struct make_ptr { typedef T *type; };
17 template <typename T> struct make_const_ptr { typedef const T *type; };
19 template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
20 class CommentVisitorBase {
22 #define PTR(CLASS) typename Ptr<CLASS>::type
23 #define DISPATCH(NAME, CLASS) \
24 return static_cast<ImplClass*>(this)->visit ## NAME(static_cast<PTR(CLASS)>(C))
26 RetTy visit(PTR(Comment) C) {
30 switch (C->getCommentKind()) {
31 default: llvm_unreachable("Unknown comment kind!");
32 #define ABSTRACT_COMMENT(COMMENT)
33 #define COMMENT(CLASS, PARENT) \
34 case Comment::CLASS##Kind: DISPATCH(CLASS, CLASS);
35 #include "clang/AST/CommentNodes.inc"
36 #undef ABSTRACT_COMMENT
41 // If the derived class does not implement a certain Visit* method, fall back
42 // on Visit* method for the superclass.
43 #define ABSTRACT_COMMENT(COMMENT) COMMENT
44 #define COMMENT(CLASS, PARENT) \
45 RetTy visit ## CLASS(PTR(CLASS) C) { DISPATCH(PARENT, PARENT); }
46 #include "clang/AST/CommentNodes.inc"
47 #undef ABSTRACT_COMMENT
50 RetTy visitComment(PTR(Comment) C) { return RetTy(); }
56 template<typename ImplClass, typename RetTy=void>
57 class CommentVisitor :
58 public CommentVisitorBase<make_ptr, ImplClass, RetTy> {};
60 template<typename ImplClass, typename RetTy=void>
61 class ConstCommentVisitor :
62 public CommentVisitorBase<make_const_ptr, ImplClass, RetTy> {};
64 } // end namespace comments
65 } // end namespace clang