Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1 | //===--- 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 | |
| 13 | namespace clang { |
| 14 | namespace comments { |
| 15 | |
| 16 | const 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 | |
| 30 | namespace { |
| 31 | struct good {}; |
| 32 | struct bad {}; |
| 33 | |
| 34 | template <typename T> |
| 35 | good implements_child_begin_end(Comment::child_iterator (T::*)() const) { |
| 36 | return good(); |
| 37 | } |
| 38 | |
| 39 | static 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 | |
| 47 | static 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 | |
| 61 | Comment::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 | } |
Matt Beaumont-Gay | 4d48b5c | 2012-07-06 21:13:09 +0000 | [diff] [blame] | 72 | llvm_unreachable("Unknown comment kind!"); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | Comment::child_iterator Comment::child_end() const { |
| 76 | switch (getCommentKind()) { |
| 77 | case NoCommentKind: llvm_unreachable("comment without a kind"); |
| 78 | #define ABSTRACT_COMMENT(COMMENT) |
| 79 | #define COMMENT(CLASS, PARENT) \ |
| 80 | case CLASS##Kind: \ |
| 81 | return static_cast<const CLASS *>(this)->child_end(); |
| 82 | #include "clang/AST/CommentNodes.inc" |
| 83 | #undef COMMENT |
| 84 | #undef ABSTRACT_COMMENT |
| 85 | } |
Matt Beaumont-Gay | 4d48b5c | 2012-07-06 21:13:09 +0000 | [diff] [blame] | 86 | llvm_unreachable("Unknown comment kind!"); |
Dmitri Gribenko | 8d3ba23 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |
| 90 | } // end namespace comments |
| 91 | } // end namespace clang |