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