blob: 22277ad88ae642590f0fffa86f4dcc8c3ff845f2 [file] [log] [blame]
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001//===--- Comment.cpp - Comment AST node implementation --------------------===//
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#include "clang/AST/Comment.h"
11#include "llvm/Support/ErrorHandling.h"
12
13namespace clang {
14namespace comments {
15
16const char *Comment::getCommentKindName() const {
17 switch (getCommentKind()) {
18 case NoCommentKind: return "NoCommentKind";
19#define ABSTRACT_COMMENT(COMMENT)
20#define COMMENT(CLASS, PARENT) \
21 case CLASS##Kind: \
22 return #CLASS;
23#include "clang/AST/CommentNodes.inc"
24#undef COMMENT
25#undef ABSTRACT_COMMENT
26 }
27 llvm_unreachable("Unknown comment kind!");
28}
29
30namespace {
31struct good {};
32struct bad {};
33
34template <typename T>
35good implements_child_begin_end(Comment::child_iterator (T::*)() const) {
36 return good();
37}
38
39static inline bad implements_child_begin_end(
40 Comment::child_iterator (Comment::*)() const) {
41 return bad();
42}
43
44#define ASSERT_IMPLEMENTS_child_begin(function) \
45 (void) sizeof(good(implements_child_begin_end(function)))
46
47static inline void CheckCommentASTNodes() {
48#define ABSTRACT_COMMENT(COMMENT)
49#define COMMENT(CLASS, PARENT) \
50 ASSERT_IMPLEMENTS_child_begin(&CLASS::child_begin); \
51 ASSERT_IMPLEMENTS_child_begin(&CLASS::child_end);
52#include "clang/AST/CommentNodes.inc"
53#undef COMMENT
54#undef ABSTRACT_COMMENT
55}
56
57#undef ASSERT_IMPLEMENTS_child_begin
58
59} // end unnamed namespace
60
61Comment::child_iterator Comment::child_begin() const {
62 switch (getCommentKind()) {
63 case NoCommentKind: llvm_unreachable("comment without a kind");
64#define ABSTRACT_COMMENT(COMMENT)
65#define COMMENT(CLASS, PARENT) \
66 case CLASS##Kind: \
67 return static_cast<const CLASS *>(this)->child_begin();
68#include "clang/AST/CommentNodes.inc"
69#undef COMMENT
70#undef ABSTRACT_COMMENT
71 }
72}
73
74Comment::child_iterator Comment::child_end() const {
75 switch (getCommentKind()) {
76 case NoCommentKind: llvm_unreachable("comment without a kind");
77#define ABSTRACT_COMMENT(COMMENT)
78#define COMMENT(CLASS, PARENT) \
79 case CLASS##Kind: \
80 return static_cast<const CLASS *>(this)->child_end();
81#include "clang/AST/CommentNodes.inc"
82#undef COMMENT
83#undef ABSTRACT_COMMENT
84 }
85}
86
87
88} // end namespace comments
89} // end namespace clang
90