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