xref: /minix3/external/bsd/llvm/dist/clang/tools/libclang/CXComment.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===- CXComment.cpp - libclang APIs for manipulating CXComments ----------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file defines all libclang APIs related to walking comment AST.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc #include "clang-c/Index.h"
15f4a2713aSLionel Sambuc #include "CXComment.h"
16f4a2713aSLionel Sambuc #include "CXCursor.h"
17f4a2713aSLionel Sambuc #include "CXString.h"
18*0a6a1f1dSLionel Sambuc #include "clang-c/Documentation.h"
19f4a2713aSLionel Sambuc #include "clang/AST/Decl.h"
20f4a2713aSLionel Sambuc #include "clang/Index/CommentToXML.h"
21f4a2713aSLionel Sambuc #include "llvm/ADT/StringExtras.h"
22f4a2713aSLionel Sambuc #include "llvm/ADT/StringSwitch.h"
23f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
24f4a2713aSLionel Sambuc #include <climits>
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc using namespace clang;
27f4a2713aSLionel Sambuc using namespace clang::comments;
28f4a2713aSLionel Sambuc using namespace clang::cxcomment;
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc extern "C" {
31f4a2713aSLionel Sambuc 
clang_Cursor_getParsedComment(CXCursor C)32*0a6a1f1dSLionel Sambuc CXComment clang_Cursor_getParsedComment(CXCursor C) {
33*0a6a1f1dSLionel Sambuc   using namespace clang::cxcursor;
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc   if (!clang_isDeclaration(C.kind))
36*0a6a1f1dSLionel Sambuc     return createCXComment(nullptr, nullptr);
37*0a6a1f1dSLionel Sambuc 
38*0a6a1f1dSLionel Sambuc   const Decl *D = getCursorDecl(C);
39*0a6a1f1dSLionel Sambuc   const ASTContext &Context = getCursorContext(C);
40*0a6a1f1dSLionel Sambuc   const FullComment *FC = Context.getCommentForDecl(D, /*PP=*/nullptr);
41*0a6a1f1dSLionel Sambuc 
42*0a6a1f1dSLionel Sambuc   return createCXComment(FC, getCursorTU(C));
43*0a6a1f1dSLionel Sambuc }
44*0a6a1f1dSLionel Sambuc 
clang_Comment_getKind(CXComment CXC)45f4a2713aSLionel Sambuc enum CXCommentKind clang_Comment_getKind(CXComment CXC) {
46f4a2713aSLionel Sambuc   const Comment *C = getASTNode(CXC);
47f4a2713aSLionel Sambuc   if (!C)
48f4a2713aSLionel Sambuc     return CXComment_Null;
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc   switch (C->getCommentKind()) {
51f4a2713aSLionel Sambuc   case Comment::NoCommentKind:
52f4a2713aSLionel Sambuc     return CXComment_Null;
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc   case Comment::TextCommentKind:
55f4a2713aSLionel Sambuc     return CXComment_Text;
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc   case Comment::InlineCommandCommentKind:
58f4a2713aSLionel Sambuc     return CXComment_InlineCommand;
59f4a2713aSLionel Sambuc 
60f4a2713aSLionel Sambuc   case Comment::HTMLStartTagCommentKind:
61f4a2713aSLionel Sambuc     return CXComment_HTMLStartTag;
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc   case Comment::HTMLEndTagCommentKind:
64f4a2713aSLionel Sambuc     return CXComment_HTMLEndTag;
65f4a2713aSLionel Sambuc 
66f4a2713aSLionel Sambuc   case Comment::ParagraphCommentKind:
67f4a2713aSLionel Sambuc     return CXComment_Paragraph;
68f4a2713aSLionel Sambuc 
69f4a2713aSLionel Sambuc   case Comment::BlockCommandCommentKind:
70f4a2713aSLionel Sambuc     return CXComment_BlockCommand;
71f4a2713aSLionel Sambuc 
72f4a2713aSLionel Sambuc   case Comment::ParamCommandCommentKind:
73f4a2713aSLionel Sambuc     return CXComment_ParamCommand;
74f4a2713aSLionel Sambuc 
75f4a2713aSLionel Sambuc   case Comment::TParamCommandCommentKind:
76f4a2713aSLionel Sambuc     return CXComment_TParamCommand;
77f4a2713aSLionel Sambuc 
78f4a2713aSLionel Sambuc   case Comment::VerbatimBlockCommentKind:
79f4a2713aSLionel Sambuc     return CXComment_VerbatimBlockCommand;
80f4a2713aSLionel Sambuc 
81f4a2713aSLionel Sambuc   case Comment::VerbatimBlockLineCommentKind:
82f4a2713aSLionel Sambuc     return CXComment_VerbatimBlockLine;
83f4a2713aSLionel Sambuc 
84f4a2713aSLionel Sambuc   case Comment::VerbatimLineCommentKind:
85f4a2713aSLionel Sambuc     return CXComment_VerbatimLine;
86f4a2713aSLionel Sambuc 
87f4a2713aSLionel Sambuc   case Comment::FullCommentKind:
88f4a2713aSLionel Sambuc     return CXComment_FullComment;
89f4a2713aSLionel Sambuc   }
90f4a2713aSLionel Sambuc   llvm_unreachable("unknown CommentKind");
91f4a2713aSLionel Sambuc }
92f4a2713aSLionel Sambuc 
clang_Comment_getNumChildren(CXComment CXC)93f4a2713aSLionel Sambuc unsigned clang_Comment_getNumChildren(CXComment CXC) {
94f4a2713aSLionel Sambuc   const Comment *C = getASTNode(CXC);
95f4a2713aSLionel Sambuc   if (!C)
96f4a2713aSLionel Sambuc     return 0;
97f4a2713aSLionel Sambuc 
98f4a2713aSLionel Sambuc   return C->child_count();
99f4a2713aSLionel Sambuc }
100f4a2713aSLionel Sambuc 
clang_Comment_getChild(CXComment CXC,unsigned ChildIdx)101f4a2713aSLionel Sambuc CXComment clang_Comment_getChild(CXComment CXC, unsigned ChildIdx) {
102f4a2713aSLionel Sambuc   const Comment *C = getASTNode(CXC);
103f4a2713aSLionel Sambuc   if (!C || ChildIdx >= C->child_count())
104*0a6a1f1dSLionel Sambuc     return createCXComment(nullptr, nullptr);
105f4a2713aSLionel Sambuc 
106f4a2713aSLionel Sambuc   return createCXComment(*(C->child_begin() + ChildIdx), CXC.TranslationUnit);
107f4a2713aSLionel Sambuc }
108f4a2713aSLionel Sambuc 
clang_Comment_isWhitespace(CXComment CXC)109f4a2713aSLionel Sambuc unsigned clang_Comment_isWhitespace(CXComment CXC) {
110f4a2713aSLionel Sambuc   const Comment *C = getASTNode(CXC);
111f4a2713aSLionel Sambuc   if (!C)
112f4a2713aSLionel Sambuc     return false;
113f4a2713aSLionel Sambuc 
114f4a2713aSLionel Sambuc   if (const TextComment *TC = dyn_cast<TextComment>(C))
115f4a2713aSLionel Sambuc     return TC->isWhitespace();
116f4a2713aSLionel Sambuc 
117f4a2713aSLionel Sambuc   if (const ParagraphComment *PC = dyn_cast<ParagraphComment>(C))
118f4a2713aSLionel Sambuc     return PC->isWhitespace();
119f4a2713aSLionel Sambuc 
120f4a2713aSLionel Sambuc   return false;
121f4a2713aSLionel Sambuc }
122f4a2713aSLionel Sambuc 
clang_InlineContentComment_hasTrailingNewline(CXComment CXC)123f4a2713aSLionel Sambuc unsigned clang_InlineContentComment_hasTrailingNewline(CXComment CXC) {
124f4a2713aSLionel Sambuc   const InlineContentComment *ICC = getASTNodeAs<InlineContentComment>(CXC);
125f4a2713aSLionel Sambuc   if (!ICC)
126f4a2713aSLionel Sambuc     return false;
127f4a2713aSLionel Sambuc 
128f4a2713aSLionel Sambuc   return ICC->hasTrailingNewline();
129f4a2713aSLionel Sambuc }
130f4a2713aSLionel Sambuc 
clang_TextComment_getText(CXComment CXC)131f4a2713aSLionel Sambuc CXString clang_TextComment_getText(CXComment CXC) {
132f4a2713aSLionel Sambuc   const TextComment *TC = getASTNodeAs<TextComment>(CXC);
133f4a2713aSLionel Sambuc   if (!TC)
134f4a2713aSLionel Sambuc     return cxstring::createNull();
135f4a2713aSLionel Sambuc 
136f4a2713aSLionel Sambuc   return cxstring::createRef(TC->getText());
137f4a2713aSLionel Sambuc }
138f4a2713aSLionel Sambuc 
clang_InlineCommandComment_getCommandName(CXComment CXC)139f4a2713aSLionel Sambuc CXString clang_InlineCommandComment_getCommandName(CXComment CXC) {
140f4a2713aSLionel Sambuc   const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
141f4a2713aSLionel Sambuc   if (!ICC)
142f4a2713aSLionel Sambuc     return cxstring::createNull();
143f4a2713aSLionel Sambuc 
144f4a2713aSLionel Sambuc   const CommandTraits &Traits = getCommandTraits(CXC);
145f4a2713aSLionel Sambuc   return cxstring::createRef(ICC->getCommandName(Traits));
146f4a2713aSLionel Sambuc }
147f4a2713aSLionel Sambuc 
148f4a2713aSLionel Sambuc enum CXCommentInlineCommandRenderKind
clang_InlineCommandComment_getRenderKind(CXComment CXC)149f4a2713aSLionel Sambuc clang_InlineCommandComment_getRenderKind(CXComment CXC) {
150f4a2713aSLionel Sambuc   const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
151f4a2713aSLionel Sambuc   if (!ICC)
152f4a2713aSLionel Sambuc     return CXCommentInlineCommandRenderKind_Normal;
153f4a2713aSLionel Sambuc 
154f4a2713aSLionel Sambuc   switch (ICC->getRenderKind()) {
155f4a2713aSLionel Sambuc   case InlineCommandComment::RenderNormal:
156f4a2713aSLionel Sambuc     return CXCommentInlineCommandRenderKind_Normal;
157f4a2713aSLionel Sambuc 
158f4a2713aSLionel Sambuc   case InlineCommandComment::RenderBold:
159f4a2713aSLionel Sambuc     return CXCommentInlineCommandRenderKind_Bold;
160f4a2713aSLionel Sambuc 
161f4a2713aSLionel Sambuc   case InlineCommandComment::RenderMonospaced:
162f4a2713aSLionel Sambuc     return CXCommentInlineCommandRenderKind_Monospaced;
163f4a2713aSLionel Sambuc 
164f4a2713aSLionel Sambuc   case InlineCommandComment::RenderEmphasized:
165f4a2713aSLionel Sambuc     return CXCommentInlineCommandRenderKind_Emphasized;
166f4a2713aSLionel Sambuc   }
167f4a2713aSLionel Sambuc   llvm_unreachable("unknown InlineCommandComment::RenderKind");
168f4a2713aSLionel Sambuc }
169f4a2713aSLionel Sambuc 
clang_InlineCommandComment_getNumArgs(CXComment CXC)170f4a2713aSLionel Sambuc unsigned clang_InlineCommandComment_getNumArgs(CXComment CXC) {
171f4a2713aSLionel Sambuc   const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
172f4a2713aSLionel Sambuc   if (!ICC)
173f4a2713aSLionel Sambuc     return 0;
174f4a2713aSLionel Sambuc 
175f4a2713aSLionel Sambuc   return ICC->getNumArgs();
176f4a2713aSLionel Sambuc }
177f4a2713aSLionel Sambuc 
clang_InlineCommandComment_getArgText(CXComment CXC,unsigned ArgIdx)178f4a2713aSLionel Sambuc CXString clang_InlineCommandComment_getArgText(CXComment CXC,
179f4a2713aSLionel Sambuc                                                unsigned ArgIdx) {
180f4a2713aSLionel Sambuc   const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC);
181f4a2713aSLionel Sambuc   if (!ICC || ArgIdx >= ICC->getNumArgs())
182f4a2713aSLionel Sambuc     return cxstring::createNull();
183f4a2713aSLionel Sambuc 
184f4a2713aSLionel Sambuc   return cxstring::createRef(ICC->getArgText(ArgIdx));
185f4a2713aSLionel Sambuc }
186f4a2713aSLionel Sambuc 
clang_HTMLTagComment_getTagName(CXComment CXC)187f4a2713aSLionel Sambuc CXString clang_HTMLTagComment_getTagName(CXComment CXC) {
188f4a2713aSLionel Sambuc   const HTMLTagComment *HTC = getASTNodeAs<HTMLTagComment>(CXC);
189f4a2713aSLionel Sambuc   if (!HTC)
190f4a2713aSLionel Sambuc     return cxstring::createNull();
191f4a2713aSLionel Sambuc 
192f4a2713aSLionel Sambuc   return cxstring::createRef(HTC->getTagName());
193f4a2713aSLionel Sambuc }
194f4a2713aSLionel Sambuc 
clang_HTMLStartTagComment_isSelfClosing(CXComment CXC)195f4a2713aSLionel Sambuc unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment CXC) {
196f4a2713aSLionel Sambuc   const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
197f4a2713aSLionel Sambuc   if (!HST)
198f4a2713aSLionel Sambuc     return false;
199f4a2713aSLionel Sambuc 
200f4a2713aSLionel Sambuc   return HST->isSelfClosing();
201f4a2713aSLionel Sambuc }
202f4a2713aSLionel Sambuc 
clang_HTMLStartTag_getNumAttrs(CXComment CXC)203f4a2713aSLionel Sambuc unsigned clang_HTMLStartTag_getNumAttrs(CXComment CXC) {
204f4a2713aSLionel Sambuc   const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
205f4a2713aSLionel Sambuc   if (!HST)
206f4a2713aSLionel Sambuc     return 0;
207f4a2713aSLionel Sambuc 
208f4a2713aSLionel Sambuc   return HST->getNumAttrs();
209f4a2713aSLionel Sambuc }
210f4a2713aSLionel Sambuc 
clang_HTMLStartTag_getAttrName(CXComment CXC,unsigned AttrIdx)211f4a2713aSLionel Sambuc CXString clang_HTMLStartTag_getAttrName(CXComment CXC, unsigned AttrIdx) {
212f4a2713aSLionel Sambuc   const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
213f4a2713aSLionel Sambuc   if (!HST || AttrIdx >= HST->getNumAttrs())
214f4a2713aSLionel Sambuc     return cxstring::createNull();
215f4a2713aSLionel Sambuc 
216f4a2713aSLionel Sambuc   return cxstring::createRef(HST->getAttr(AttrIdx).Name);
217f4a2713aSLionel Sambuc }
218f4a2713aSLionel Sambuc 
clang_HTMLStartTag_getAttrValue(CXComment CXC,unsigned AttrIdx)219f4a2713aSLionel Sambuc CXString clang_HTMLStartTag_getAttrValue(CXComment CXC, unsigned AttrIdx) {
220f4a2713aSLionel Sambuc   const HTMLStartTagComment *HST = getASTNodeAs<HTMLStartTagComment>(CXC);
221f4a2713aSLionel Sambuc   if (!HST || AttrIdx >= HST->getNumAttrs())
222f4a2713aSLionel Sambuc     return cxstring::createNull();
223f4a2713aSLionel Sambuc 
224f4a2713aSLionel Sambuc   return cxstring::createRef(HST->getAttr(AttrIdx).Value);
225f4a2713aSLionel Sambuc }
226f4a2713aSLionel Sambuc 
clang_BlockCommandComment_getCommandName(CXComment CXC)227f4a2713aSLionel Sambuc CXString clang_BlockCommandComment_getCommandName(CXComment CXC) {
228f4a2713aSLionel Sambuc   const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
229f4a2713aSLionel Sambuc   if (!BCC)
230f4a2713aSLionel Sambuc     return cxstring::createNull();
231f4a2713aSLionel Sambuc 
232f4a2713aSLionel Sambuc   const CommandTraits &Traits = getCommandTraits(CXC);
233f4a2713aSLionel Sambuc   return cxstring::createRef(BCC->getCommandName(Traits));
234f4a2713aSLionel Sambuc }
235f4a2713aSLionel Sambuc 
clang_BlockCommandComment_getNumArgs(CXComment CXC)236f4a2713aSLionel Sambuc unsigned clang_BlockCommandComment_getNumArgs(CXComment CXC) {
237f4a2713aSLionel Sambuc   const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
238f4a2713aSLionel Sambuc   if (!BCC)
239f4a2713aSLionel Sambuc     return 0;
240f4a2713aSLionel Sambuc 
241f4a2713aSLionel Sambuc   return BCC->getNumArgs();
242f4a2713aSLionel Sambuc }
243f4a2713aSLionel Sambuc 
clang_BlockCommandComment_getArgText(CXComment CXC,unsigned ArgIdx)244f4a2713aSLionel Sambuc CXString clang_BlockCommandComment_getArgText(CXComment CXC,
245f4a2713aSLionel Sambuc                                               unsigned ArgIdx) {
246f4a2713aSLionel Sambuc   const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
247f4a2713aSLionel Sambuc   if (!BCC || ArgIdx >= BCC->getNumArgs())
248f4a2713aSLionel Sambuc     return cxstring::createNull();
249f4a2713aSLionel Sambuc 
250f4a2713aSLionel Sambuc   return cxstring::createRef(BCC->getArgText(ArgIdx));
251f4a2713aSLionel Sambuc }
252f4a2713aSLionel Sambuc 
clang_BlockCommandComment_getParagraph(CXComment CXC)253f4a2713aSLionel Sambuc CXComment clang_BlockCommandComment_getParagraph(CXComment CXC) {
254f4a2713aSLionel Sambuc   const BlockCommandComment *BCC = getASTNodeAs<BlockCommandComment>(CXC);
255f4a2713aSLionel Sambuc   if (!BCC)
256*0a6a1f1dSLionel Sambuc     return createCXComment(nullptr, nullptr);
257f4a2713aSLionel Sambuc 
258f4a2713aSLionel Sambuc   return createCXComment(BCC->getParagraph(), CXC.TranslationUnit);
259f4a2713aSLionel Sambuc }
260f4a2713aSLionel Sambuc 
clang_ParamCommandComment_getParamName(CXComment CXC)261f4a2713aSLionel Sambuc CXString clang_ParamCommandComment_getParamName(CXComment CXC) {
262f4a2713aSLionel Sambuc   const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
263f4a2713aSLionel Sambuc   if (!PCC || !PCC->hasParamName())
264f4a2713aSLionel Sambuc     return cxstring::createNull();
265f4a2713aSLionel Sambuc 
266f4a2713aSLionel Sambuc   return cxstring::createRef(PCC->getParamNameAsWritten());
267f4a2713aSLionel Sambuc }
268f4a2713aSLionel Sambuc 
clang_ParamCommandComment_isParamIndexValid(CXComment CXC)269f4a2713aSLionel Sambuc unsigned clang_ParamCommandComment_isParamIndexValid(CXComment CXC) {
270f4a2713aSLionel Sambuc   const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
271f4a2713aSLionel Sambuc   if (!PCC)
272f4a2713aSLionel Sambuc     return false;
273f4a2713aSLionel Sambuc 
274f4a2713aSLionel Sambuc   return PCC->isParamIndexValid();
275f4a2713aSLionel Sambuc }
276f4a2713aSLionel Sambuc 
clang_ParamCommandComment_getParamIndex(CXComment CXC)277f4a2713aSLionel Sambuc unsigned clang_ParamCommandComment_getParamIndex(CXComment CXC) {
278f4a2713aSLionel Sambuc   const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
279f4a2713aSLionel Sambuc   if (!PCC || !PCC->isParamIndexValid() || PCC->isVarArgParam())
280f4a2713aSLionel Sambuc     return ParamCommandComment::InvalidParamIndex;
281f4a2713aSLionel Sambuc 
282f4a2713aSLionel Sambuc   return PCC->getParamIndex();
283f4a2713aSLionel Sambuc }
284f4a2713aSLionel Sambuc 
clang_ParamCommandComment_isDirectionExplicit(CXComment CXC)285f4a2713aSLionel Sambuc unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment CXC) {
286f4a2713aSLionel Sambuc   const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
287f4a2713aSLionel Sambuc   if (!PCC)
288f4a2713aSLionel Sambuc     return false;
289f4a2713aSLionel Sambuc 
290f4a2713aSLionel Sambuc   return PCC->isDirectionExplicit();
291f4a2713aSLionel Sambuc }
292f4a2713aSLionel Sambuc 
clang_ParamCommandComment_getDirection(CXComment CXC)293f4a2713aSLionel Sambuc enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
294f4a2713aSLionel Sambuc                                                             CXComment CXC) {
295f4a2713aSLionel Sambuc   const ParamCommandComment *PCC = getASTNodeAs<ParamCommandComment>(CXC);
296f4a2713aSLionel Sambuc   if (!PCC)
297f4a2713aSLionel Sambuc     return CXCommentParamPassDirection_In;
298f4a2713aSLionel Sambuc 
299f4a2713aSLionel Sambuc   switch (PCC->getDirection()) {
300f4a2713aSLionel Sambuc   case ParamCommandComment::In:
301f4a2713aSLionel Sambuc     return CXCommentParamPassDirection_In;
302f4a2713aSLionel Sambuc 
303f4a2713aSLionel Sambuc   case ParamCommandComment::Out:
304f4a2713aSLionel Sambuc     return CXCommentParamPassDirection_Out;
305f4a2713aSLionel Sambuc 
306f4a2713aSLionel Sambuc   case ParamCommandComment::InOut:
307f4a2713aSLionel Sambuc     return CXCommentParamPassDirection_InOut;
308f4a2713aSLionel Sambuc   }
309f4a2713aSLionel Sambuc   llvm_unreachable("unknown ParamCommandComment::PassDirection");
310f4a2713aSLionel Sambuc }
311f4a2713aSLionel Sambuc 
clang_TParamCommandComment_getParamName(CXComment CXC)312f4a2713aSLionel Sambuc CXString clang_TParamCommandComment_getParamName(CXComment CXC) {
313f4a2713aSLionel Sambuc   const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC);
314f4a2713aSLionel Sambuc   if (!TPCC || !TPCC->hasParamName())
315f4a2713aSLionel Sambuc     return cxstring::createNull();
316f4a2713aSLionel Sambuc 
317f4a2713aSLionel Sambuc   return cxstring::createRef(TPCC->getParamNameAsWritten());
318f4a2713aSLionel Sambuc }
319f4a2713aSLionel Sambuc 
clang_TParamCommandComment_isParamPositionValid(CXComment CXC)320f4a2713aSLionel Sambuc unsigned clang_TParamCommandComment_isParamPositionValid(CXComment CXC) {
321f4a2713aSLionel Sambuc   const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC);
322f4a2713aSLionel Sambuc   if (!TPCC)
323f4a2713aSLionel Sambuc     return false;
324f4a2713aSLionel Sambuc 
325f4a2713aSLionel Sambuc   return TPCC->isPositionValid();
326f4a2713aSLionel Sambuc }
327f4a2713aSLionel Sambuc 
clang_TParamCommandComment_getDepth(CXComment CXC)328f4a2713aSLionel Sambuc unsigned clang_TParamCommandComment_getDepth(CXComment CXC) {
329f4a2713aSLionel Sambuc   const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC);
330f4a2713aSLionel Sambuc   if (!TPCC || !TPCC->isPositionValid())
331f4a2713aSLionel Sambuc     return 0;
332f4a2713aSLionel Sambuc 
333f4a2713aSLionel Sambuc   return TPCC->getDepth();
334f4a2713aSLionel Sambuc }
335f4a2713aSLionel Sambuc 
clang_TParamCommandComment_getIndex(CXComment CXC,unsigned Depth)336f4a2713aSLionel Sambuc unsigned clang_TParamCommandComment_getIndex(CXComment CXC, unsigned Depth) {
337f4a2713aSLionel Sambuc   const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC);
338f4a2713aSLionel Sambuc   if (!TPCC || !TPCC->isPositionValid() || Depth >= TPCC->getDepth())
339f4a2713aSLionel Sambuc     return 0;
340f4a2713aSLionel Sambuc 
341f4a2713aSLionel Sambuc   return TPCC->getIndex(Depth);
342f4a2713aSLionel Sambuc }
343f4a2713aSLionel Sambuc 
clang_VerbatimBlockLineComment_getText(CXComment CXC)344f4a2713aSLionel Sambuc CXString clang_VerbatimBlockLineComment_getText(CXComment CXC) {
345f4a2713aSLionel Sambuc   const VerbatimBlockLineComment *VBL =
346f4a2713aSLionel Sambuc       getASTNodeAs<VerbatimBlockLineComment>(CXC);
347f4a2713aSLionel Sambuc   if (!VBL)
348f4a2713aSLionel Sambuc     return cxstring::createNull();
349f4a2713aSLionel Sambuc 
350f4a2713aSLionel Sambuc   return cxstring::createRef(VBL->getText());
351f4a2713aSLionel Sambuc }
352f4a2713aSLionel Sambuc 
clang_VerbatimLineComment_getText(CXComment CXC)353f4a2713aSLionel Sambuc CXString clang_VerbatimLineComment_getText(CXComment CXC) {
354f4a2713aSLionel Sambuc   const VerbatimLineComment *VLC = getASTNodeAs<VerbatimLineComment>(CXC);
355f4a2713aSLionel Sambuc   if (!VLC)
356f4a2713aSLionel Sambuc     return cxstring::createNull();
357f4a2713aSLionel Sambuc 
358f4a2713aSLionel Sambuc   return cxstring::createRef(VLC->getText());
359f4a2713aSLionel Sambuc }
360f4a2713aSLionel Sambuc 
361f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
362f4a2713aSLionel Sambuc // Converting comments to XML.
363f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
364f4a2713aSLionel Sambuc 
clang_HTMLTagComment_getAsString(CXComment CXC)365f4a2713aSLionel Sambuc CXString clang_HTMLTagComment_getAsString(CXComment CXC) {
366f4a2713aSLionel Sambuc   const HTMLTagComment *HTC = getASTNodeAs<HTMLTagComment>(CXC);
367f4a2713aSLionel Sambuc   if (!HTC)
368f4a2713aSLionel Sambuc     return cxstring::createNull();
369f4a2713aSLionel Sambuc 
370f4a2713aSLionel Sambuc   CXTranslationUnit TU = CXC.TranslationUnit;
371f4a2713aSLionel Sambuc   if (!TU->CommentToXML)
372f4a2713aSLionel Sambuc     TU->CommentToXML = new clang::index::CommentToXMLConverter();
373f4a2713aSLionel Sambuc 
374f4a2713aSLionel Sambuc   SmallString<128> Text;
375f4a2713aSLionel Sambuc   TU->CommentToXML->convertHTMLTagNodeToText(
376f4a2713aSLionel Sambuc       HTC, Text, cxtu::getASTUnit(TU)->getASTContext());
377f4a2713aSLionel Sambuc   return cxstring::createDup(Text.str());
378f4a2713aSLionel Sambuc }
379f4a2713aSLionel Sambuc 
clang_FullComment_getAsHTML(CXComment CXC)380f4a2713aSLionel Sambuc CXString clang_FullComment_getAsHTML(CXComment CXC) {
381f4a2713aSLionel Sambuc   const FullComment *FC = getASTNodeAs<FullComment>(CXC);
382f4a2713aSLionel Sambuc   if (!FC)
383f4a2713aSLionel Sambuc     return cxstring::createNull();
384f4a2713aSLionel Sambuc 
385f4a2713aSLionel Sambuc   CXTranslationUnit TU = CXC.TranslationUnit;
386f4a2713aSLionel Sambuc   if (!TU->CommentToXML)
387f4a2713aSLionel Sambuc     TU->CommentToXML = new clang::index::CommentToXMLConverter();
388f4a2713aSLionel Sambuc 
389f4a2713aSLionel Sambuc   SmallString<1024> HTML;
390f4a2713aSLionel Sambuc   TU->CommentToXML
391f4a2713aSLionel Sambuc       ->convertCommentToHTML(FC, HTML, cxtu::getASTUnit(TU)->getASTContext());
392f4a2713aSLionel Sambuc   return cxstring::createDup(HTML.str());
393f4a2713aSLionel Sambuc }
394f4a2713aSLionel Sambuc 
clang_FullComment_getAsXML(CXComment CXC)395f4a2713aSLionel Sambuc CXString clang_FullComment_getAsXML(CXComment CXC) {
396f4a2713aSLionel Sambuc   const FullComment *FC = getASTNodeAs<FullComment>(CXC);
397f4a2713aSLionel Sambuc   if (!FC)
398f4a2713aSLionel Sambuc     return cxstring::createNull();
399f4a2713aSLionel Sambuc 
400f4a2713aSLionel Sambuc   CXTranslationUnit TU = CXC.TranslationUnit;
401f4a2713aSLionel Sambuc   if (!TU->CommentToXML)
402f4a2713aSLionel Sambuc     TU->CommentToXML = new clang::index::CommentToXMLConverter();
403f4a2713aSLionel Sambuc 
404f4a2713aSLionel Sambuc   SmallString<1024> XML;
405f4a2713aSLionel Sambuc   TU->CommentToXML
406f4a2713aSLionel Sambuc       ->convertCommentToXML(FC, XML, cxtu::getASTUnit(TU)->getASTContext());
407f4a2713aSLionel Sambuc   return cxstring::createDup(XML.str());
408f4a2713aSLionel Sambuc }
409f4a2713aSLionel Sambuc 
410f4a2713aSLionel Sambuc } // end extern "C"
411f4a2713aSLionel Sambuc 
412