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 #ifndef LLVM_CLANG_AST_COMMENTVISITOR_H
11 #define LLVM_CLANG_AST_COMMENTVISITOR_H
13 #include "clang/AST/Comment.h"
14 #include "llvm/Support/ErrorHandling.h"
19 template <typename T> struct make_ptr { typedef T *type; };
20 template <typename T> struct make_const_ptr { typedef const T *type; };
22 template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
23 class CommentVisitorBase {
25 #define PTR(CLASS) typename Ptr<CLASS>::type
26 #define DISPATCH(NAME, CLASS) \
27 return static_cast<ImplClass*>(this)->visit ## NAME(static_cast<PTR(CLASS)>(C))
29 RetTy visit(PTR(Comment) C) {
33 switch (C->getCommentKind()) {
34 default: llvm_unreachable("Unknown comment kind!");
35 #define ABSTRACT_COMMENT(COMMENT)
36 #define COMMENT(CLASS, PARENT) \
37 case Comment::CLASS##Kind: DISPATCH(CLASS, CLASS);
38 #include "clang/AST/CommentNodes.inc"
39 #undef ABSTRACT_COMMENT
44 // If the derived class does not implement a certain Visit* method, fall back
45 // on Visit* method for the superclass.
46 #define ABSTRACT_COMMENT(COMMENT) COMMENT
47 #define COMMENT(CLASS, PARENT) \
48 RetTy visit ## CLASS(PTR(CLASS) C) { DISPATCH(PARENT, PARENT); }
49 #include "clang/AST/CommentNodes.inc"
50 #undef ABSTRACT_COMMENT
53 RetTy visitComment(PTR(Comment) C) { return RetTy(); }
59 template<typename ImplClass, typename RetTy=void>
60 class CommentVisitor :
61 public CommentVisitorBase<make_ptr, ImplClass, RetTy> {};
63 template<typename ImplClass, typename RetTy=void>
64 class ConstCommentVisitor :
65 public CommentVisitorBase<make_const_ptr, ImplClass, RetTy> {};
67 } // end namespace comments
68 } // end namespace clang