clang  6.0.0svn
CommentVisitor.h
Go to the documentation of this file.
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/Support/ErrorHandling.h"
15 
16 namespace clang {
17 namespace comments {
18 
19 template <typename T> struct make_ptr { using type = T *; };
20 template <typename T> struct make_const_ptr { using type = const T *; };
21 
22 template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
24 public:
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))
28 
29  RetTy visit(PTR(Comment) C) {
30  if (!C)
31  return RetTy();
32 
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
40 #undef COMMENT
41  }
42  }
43 
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
51 #undef COMMENT
52 
53  RetTy visitComment(PTR(Comment) C) { return RetTy(); }
54 
55 #undef PTR
56 #undef DISPATCH
57 };
58 
59 template<typename ImplClass, typename RetTy=void>
61  public CommentVisitorBase<make_ptr, ImplClass, RetTy> {};
62 
63 template<typename ImplClass, typename RetTy=void>
65  public CommentVisitorBase<make_const_ptr, ImplClass, RetTy> {};
66 
67 } // namespace comments
68 } // namespace clang
69 
70 #endif // LLVM_CLANG_AST_COMMENTVISITOR_H
#define PTR(CLASS)
RetTy visitComment(PTR(Comment) C)
Any part of the comment.
Definition: Comment.h:53
const FunctionProtoType * T
CommentKind getCommentKind() const
Definition: Comment.h:204
Dataflow Directional Tag Classes.