xref: /minix3/external/bsd/llvm/dist/clang/include/clang/AST/CommentVisitor.h (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===--- CommentVisitor.h - Visitor for Comment subclasses ------*- C++ -*-===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc #ifndef LLVM_CLANG_AST_COMMENTVISITOR_H
11*f4a2713aSLionel Sambuc #define LLVM_CLANG_AST_COMMENTVISITOR_H
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc #include "clang/AST/Comment.h"
14*f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc namespace clang {
17*f4a2713aSLionel Sambuc namespace comments {
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc template <typename T> struct make_ptr       { typedef       T *type; };
20*f4a2713aSLionel Sambuc template <typename T> struct make_const_ptr { typedef const T *type; };
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
23*f4a2713aSLionel Sambuc class CommentVisitorBase {
24*f4a2713aSLionel Sambuc public:
25*f4a2713aSLionel Sambuc #define PTR(CLASS) typename Ptr<CLASS>::type
26*f4a2713aSLionel Sambuc #define DISPATCH(NAME, CLASS) \
27*f4a2713aSLionel Sambuc  return static_cast<ImplClass*>(this)->visit ## NAME(static_cast<PTR(CLASS)>(C))
28*f4a2713aSLionel Sambuc 
visit(PTR (Comment)C)29*f4a2713aSLionel Sambuc   RetTy visit(PTR(Comment) C) {
30*f4a2713aSLionel Sambuc     if (!C)
31*f4a2713aSLionel Sambuc       return RetTy();
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc     switch (C->getCommentKind()) {
34*f4a2713aSLionel Sambuc     default: llvm_unreachable("Unknown comment kind!");
35*f4a2713aSLionel Sambuc #define ABSTRACT_COMMENT(COMMENT)
36*f4a2713aSLionel Sambuc #define COMMENT(CLASS, PARENT) \
37*f4a2713aSLionel Sambuc     case Comment::CLASS##Kind: DISPATCH(CLASS, CLASS);
38*f4a2713aSLionel Sambuc #include "clang/AST/CommentNodes.inc"
39*f4a2713aSLionel Sambuc #undef ABSTRACT_COMMENT
40*f4a2713aSLionel Sambuc #undef COMMENT
41*f4a2713aSLionel Sambuc     }
42*f4a2713aSLionel Sambuc   }
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc   // If the derived class does not implement a certain Visit* method, fall back
45*f4a2713aSLionel Sambuc   // on Visit* method for the superclass.
46*f4a2713aSLionel Sambuc #define ABSTRACT_COMMENT(COMMENT) COMMENT
47*f4a2713aSLionel Sambuc #define COMMENT(CLASS, PARENT) \
48*f4a2713aSLionel Sambuc   RetTy visit ## CLASS(PTR(CLASS) C) { DISPATCH(PARENT, PARENT); }
49*f4a2713aSLionel Sambuc #include "clang/AST/CommentNodes.inc"
50*f4a2713aSLionel Sambuc #undef ABSTRACT_COMMENT
51*f4a2713aSLionel Sambuc #undef COMMENT
52*f4a2713aSLionel Sambuc 
visitComment(PTR (Comment)C)53*f4a2713aSLionel Sambuc   RetTy visitComment(PTR(Comment) C) { return RetTy(); }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc #undef PTR
56*f4a2713aSLionel Sambuc #undef DISPATCH
57*f4a2713aSLionel Sambuc };
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc template<typename ImplClass, typename RetTy=void>
60*f4a2713aSLionel Sambuc class CommentVisitor :
61*f4a2713aSLionel Sambuc     public CommentVisitorBase<make_ptr, ImplClass, RetTy> {};
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc template<typename ImplClass, typename RetTy=void>
64*f4a2713aSLionel Sambuc class ConstCommentVisitor :
65*f4a2713aSLionel Sambuc     public CommentVisitorBase<make_const_ptr, ImplClass, RetTy> {};
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc } // end namespace comments
68*f4a2713aSLionel Sambuc } // end namespace clang
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc #endif
71