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