Comment.cpp revision a5ef44ff5d93a3be6ca67782828157a71894cf0c
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
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  llvm_unreachable("Unknown comment kind!");
73}
74
75Comment::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  }
86  llvm_unreachable("Unknown comment kind!");
87}
88
89bool TextComment::isWhitespace() const {
90  for (StringRef::const_iterator I = Text.begin(), E = Text.end();
91       I != E; ++I) {
92    const char C = *I;
93    if (C != ' ' && C != '\n' && C != '\r' &&
94        C != '\t' && C != '\f' && C != '\v')
95      return false;
96  }
97  return true;
98}
99
100bool ParagraphComment::isWhitespace() const {
101  for (child_iterator I = child_begin(), E = child_end(); I != E; ++I) {
102    if (const TextComment *TC = dyn_cast<TextComment>(*I)) {
103      if (!TC->isWhitespace())
104        return false;
105    }
106  }
107  return true;
108}
109
110const char *ParamCommandComment::getDirectionAsString(PassDirection D) {
111  switch (D) {
112  case ParamCommandComment::In:
113    return "[in]";
114  case ParamCommandComment::Out:
115    return "[out]";
116  case ParamCommandComment::InOut:
117    return "[in,out]";
118  }
119  llvm_unreachable("unknown PassDirection");
120}
121
122} // end namespace comments
123} // end namespace clang
124