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