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