Documentation.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
  2. |* *|
  3. |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
  4. |* Exceptions. *|
  5. |* See https://llvm.org/LICENSE.txt for license information. *|
  6. |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
  7. |* *|
  8. |*===----------------------------------------------------------------------===*|
  9. |* *|
  10. |* This header provides a supplementary interface for inspecting *|
  11. |* documentation comments. *|
  12. |* *|
  13. \*===----------------------------------------------------------------------===*/
  14. #ifndef LLVM_CLANG_C_DOCUMENTATION_H
  15. #define LLVM_CLANG_C_DOCUMENTATION_H
  16. #include "clang-c/ExternC.h"
  17. #include "clang-c/Index.h"
  18. LLVM_CLANG_C_EXTERN_C_BEGIN
  19. /**
  20. * \defgroup CINDEX_COMMENT Comment introspection
  21. *
  22. * The routines in this group provide access to information in documentation
  23. * comments. These facilities are distinct from the core and may be subject to
  24. * their own schedule of stability and deprecation.
  25. *
  26. * @{
  27. */
  28. /**
  29. * A parsed comment.
  30. */
  31. typedef struct {
  32. const void *ASTNode;
  33. CXTranslationUnit TranslationUnit;
  34. } CXComment;
  35. /**
  36. * Given a cursor that represents a documentable entity (e.g.,
  37. * declaration), return the associated parsed comment as a
  38. * \c CXComment_FullComment AST node.
  39. */
  40. CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
  41. /**
  42. * Describes the type of the comment AST node (\c CXComment). A comment
  43. * node can be considered block content (e. g., paragraph), inline content
  44. * (plain text) or neither (the root AST node).
  45. */
  46. enum CXCommentKind {
  47. /**
  48. * Null comment. No AST node is constructed at the requested location
  49. * because there is no text or a syntax error.
  50. */
  51. CXComment_Null = 0,
  52. /**
  53. * Plain text. Inline content.
  54. */
  55. CXComment_Text = 1,
  56. /**
  57. * A command with word-like arguments that is considered inline content.
  58. *
  59. * For example: \\c command.
  60. */
  61. CXComment_InlineCommand = 2,
  62. /**
  63. * HTML start tag with attributes (name-value pairs). Considered
  64. * inline content.
  65. *
  66. * For example:
  67. * \verbatim
  68. * <br> <br /> <a href="http://example.org/">
  69. * \endverbatim
  70. */
  71. CXComment_HTMLStartTag = 3,
  72. /**
  73. * HTML end tag. Considered inline content.
  74. *
  75. * For example:
  76. * \verbatim
  77. * </a>
  78. * \endverbatim
  79. */
  80. CXComment_HTMLEndTag = 4,
  81. /**
  82. * A paragraph, contains inline comment. The paragraph itself is
  83. * block content.
  84. */
  85. CXComment_Paragraph = 5,
  86. /**
  87. * A command that has zero or more word-like arguments (number of
  88. * word-like arguments depends on command name) and a paragraph as an
  89. * argument. Block command is block content.
  90. *
  91. * Paragraph argument is also a child of the block command.
  92. *
  93. * For example: \has 0 word-like arguments and a paragraph argument.
  94. *
  95. * AST nodes of special kinds that parser knows about (e. g., \\param
  96. * command) have their own node kinds.
  97. */
  98. CXComment_BlockCommand = 6,
  99. /**
  100. * A \\param or \\arg command that describes the function parameter
  101. * (name, passing direction, description).
  102. *
  103. * For example: \\param [in] ParamName description.
  104. */
  105. CXComment_ParamCommand = 7,
  106. /**
  107. * A \\tparam command that describes a template parameter (name and
  108. * description).
  109. *
  110. * For example: \\tparam T description.
  111. */
  112. CXComment_TParamCommand = 8,
  113. /**
  114. * A verbatim block command (e. g., preformatted code). Verbatim
  115. * block has an opening and a closing command and contains multiple lines of
  116. * text (\c CXComment_VerbatimBlockLine child nodes).
  117. *
  118. * For example:
  119. * \\verbatim
  120. * aaa
  121. * \\endverbatim
  122. */
  123. CXComment_VerbatimBlockCommand = 9,
  124. /**
  125. * A line of text that is contained within a
  126. * CXComment_VerbatimBlockCommand node.
  127. */
  128. CXComment_VerbatimBlockLine = 10,
  129. /**
  130. * A verbatim line command. Verbatim line has an opening command,
  131. * a single line of text (up to the newline after the opening command) and
  132. * has no closing command.
  133. */
  134. CXComment_VerbatimLine = 11,
  135. /**
  136. * A full comment attached to a declaration, contains block content.
  137. */
  138. CXComment_FullComment = 12
  139. };
  140. /**
  141. * The most appropriate rendering mode for an inline command, chosen on
  142. * command semantics in Doxygen.
  143. */
  144. enum CXCommentInlineCommandRenderKind {
  145. /**
  146. * Command argument should be rendered in a normal font.
  147. */
  148. CXCommentInlineCommandRenderKind_Normal,
  149. /**
  150. * Command argument should be rendered in a bold font.
  151. */
  152. CXCommentInlineCommandRenderKind_Bold,
  153. /**
  154. * Command argument should be rendered in a monospaced font.
  155. */
  156. CXCommentInlineCommandRenderKind_Monospaced,
  157. /**
  158. * Command argument should be rendered emphasized (typically italic
  159. * font).
  160. */
  161. CXCommentInlineCommandRenderKind_Emphasized,
  162. /**
  163. * Command argument should not be rendered (since it only defines an anchor).
  164. */
  165. CXCommentInlineCommandRenderKind_Anchor
  166. };
  167. /**
  168. * Describes parameter passing direction for \\param or \\arg command.
  169. */
  170. enum CXCommentParamPassDirection {
  171. /**
  172. * The parameter is an input parameter.
  173. */
  174. CXCommentParamPassDirection_In,
  175. /**
  176. * The parameter is an output parameter.
  177. */
  178. CXCommentParamPassDirection_Out,
  179. /**
  180. * The parameter is an input and output parameter.
  181. */
  182. CXCommentParamPassDirection_InOut
  183. };
  184. /**
  185. * \param Comment AST node of any kind.
  186. *
  187. * \returns the type of the AST node.
  188. */
  189. CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
  190. /**
  191. * \param Comment AST node of any kind.
  192. *
  193. * \returns number of children of the AST node.
  194. */
  195. CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
  196. /**
  197. * \param Comment AST node of any kind.
  198. *
  199. * \param ChildIdx child index (zero-based).
  200. *
  201. * \returns the specified child of the AST node.
  202. */
  203. CINDEX_LINKAGE
  204. CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
  205. /**
  206. * A \c CXComment_Paragraph node is considered whitespace if it contains
  207. * only \c CXComment_Text nodes that are empty or whitespace.
  208. *
  209. * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
  210. * never considered whitespace.
  211. *
  212. * \returns non-zero if \c Comment is whitespace.
  213. */
  214. CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
  215. /**
  216. * \returns non-zero if \c Comment is inline content and has a newline
  217. * immediately following it in the comment text. Newlines between paragraphs
  218. * do not count.
  219. */
  220. CINDEX_LINKAGE
  221. unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
  222. /**
  223. * \param Comment a \c CXComment_Text AST node.
  224. *
  225. * \returns text contained in the AST node.
  226. */
  227. CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
  228. /**
  229. * \param Comment a \c CXComment_InlineCommand AST node.
  230. *
  231. * \returns name of the inline command.
  232. */
  233. CINDEX_LINKAGE
  234. CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
  235. /**
  236. * \param Comment a \c CXComment_InlineCommand AST node.
  237. *
  238. * \returns the most appropriate rendering mode, chosen on command
  239. * semantics in Doxygen.
  240. */
  241. CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
  242. clang_InlineCommandComment_getRenderKind(CXComment Comment);
  243. /**
  244. * \param Comment a \c CXComment_InlineCommand AST node.
  245. *
  246. * \returns number of command arguments.
  247. */
  248. CINDEX_LINKAGE
  249. unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
  250. /**
  251. * \param Comment a \c CXComment_InlineCommand AST node.
  252. *
  253. * \param ArgIdx argument index (zero-based).
  254. *
  255. * \returns text of the specified argument.
  256. */
  257. CINDEX_LINKAGE
  258. CXString clang_InlineCommandComment_getArgText(CXComment Comment,
  259. unsigned ArgIdx);
  260. /**
  261. * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
  262. * node.
  263. *
  264. * \returns HTML tag name.
  265. */
  266. CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
  267. /**
  268. * \param Comment a \c CXComment_HTMLStartTag AST node.
  269. *
  270. * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
  271. */
  272. CINDEX_LINKAGE
  273. unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
  274. /**
  275. * \param Comment a \c CXComment_HTMLStartTag AST node.
  276. *
  277. * \returns number of attributes (name-value pairs) attached to the start tag.
  278. */
  279. CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
  280. /**
  281. * \param Comment a \c CXComment_HTMLStartTag AST node.
  282. *
  283. * \param AttrIdx attribute index (zero-based).
  284. *
  285. * \returns name of the specified attribute.
  286. */
  287. CINDEX_LINKAGE
  288. CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
  289. /**
  290. * \param Comment a \c CXComment_HTMLStartTag AST node.
  291. *
  292. * \param AttrIdx attribute index (zero-based).
  293. *
  294. * \returns value of the specified attribute.
  295. */
  296. CINDEX_LINKAGE
  297. CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
  298. /**
  299. * \param Comment a \c CXComment_BlockCommand AST node.
  300. *
  301. * \returns name of the block command.
  302. */
  303. CINDEX_LINKAGE
  304. CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
  305. /**
  306. * \param Comment a \c CXComment_BlockCommand AST node.
  307. *
  308. * \returns number of word-like arguments.
  309. */
  310. CINDEX_LINKAGE
  311. unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
  312. /**
  313. * \param Comment a \c CXComment_BlockCommand AST node.
  314. *
  315. * \param ArgIdx argument index (zero-based).
  316. *
  317. * \returns text of the specified word-like argument.
  318. */
  319. CINDEX_LINKAGE
  320. CXString clang_BlockCommandComment_getArgText(CXComment Comment,
  321. unsigned ArgIdx);
  322. /**
  323. * \param Comment a \c CXComment_BlockCommand or
  324. * \c CXComment_VerbatimBlockCommand AST node.
  325. *
  326. * \returns paragraph argument of the block command.
  327. */
  328. CINDEX_LINKAGE
  329. CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
  330. /**
  331. * \param Comment a \c CXComment_ParamCommand AST node.
  332. *
  333. * \returns parameter name.
  334. */
  335. CINDEX_LINKAGE
  336. CXString clang_ParamCommandComment_getParamName(CXComment Comment);
  337. /**
  338. * \param Comment a \c CXComment_ParamCommand AST node.
  339. *
  340. * \returns non-zero if the parameter that this AST node represents was found
  341. * in the function prototype and \c clang_ParamCommandComment_getParamIndex
  342. * function will return a meaningful value.
  343. */
  344. CINDEX_LINKAGE
  345. unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
  346. /**
  347. * \param Comment a \c CXComment_ParamCommand AST node.
  348. *
  349. * \returns zero-based parameter index in function prototype.
  350. */
  351. CINDEX_LINKAGE
  352. unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
  353. /**
  354. * \param Comment a \c CXComment_ParamCommand AST node.
  355. *
  356. * \returns non-zero if parameter passing direction was specified explicitly in
  357. * the comment.
  358. */
  359. CINDEX_LINKAGE
  360. unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
  361. /**
  362. * \param Comment a \c CXComment_ParamCommand AST node.
  363. *
  364. * \returns parameter passing direction.
  365. */
  366. CINDEX_LINKAGE
  367. enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
  368. CXComment Comment);
  369. /**
  370. * \param Comment a \c CXComment_TParamCommand AST node.
  371. *
  372. * \returns template parameter name.
  373. */
  374. CINDEX_LINKAGE
  375. CXString clang_TParamCommandComment_getParamName(CXComment Comment);
  376. /**
  377. * \param Comment a \c CXComment_TParamCommand AST node.
  378. *
  379. * \returns non-zero if the parameter that this AST node represents was found
  380. * in the template parameter list and
  381. * \c clang_TParamCommandComment_getDepth and
  382. * \c clang_TParamCommandComment_getIndex functions will return a meaningful
  383. * value.
  384. */
  385. CINDEX_LINKAGE
  386. unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
  387. /**
  388. * \param Comment a \c CXComment_TParamCommand AST node.
  389. *
  390. * \returns zero-based nesting depth of this parameter in the template parameter list.
  391. *
  392. * For example,
  393. * \verbatim
  394. * template<typename C, template<typename T> class TT>
  395. * void test(TT<int> aaa);
  396. * \endverbatim
  397. * for C and TT nesting depth is 0,
  398. * for T nesting depth is 1.
  399. */
  400. CINDEX_LINKAGE
  401. unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
  402. /**
  403. * \param Comment a \c CXComment_TParamCommand AST node.
  404. *
  405. * \returns zero-based parameter index in the template parameter list at a
  406. * given nesting depth.
  407. *
  408. * For example,
  409. * \verbatim
  410. * template<typename C, template<typename T> class TT>
  411. * void test(TT<int> aaa);
  412. * \endverbatim
  413. * for C and TT nesting depth is 0, so we can ask for index at depth 0:
  414. * at depth 0 C's index is 0, TT's index is 1.
  415. *
  416. * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
  417. * at depth 0 T's index is 1 (same as TT's),
  418. * at depth 1 T's index is 0.
  419. */
  420. CINDEX_LINKAGE
  421. unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
  422. /**
  423. * \param Comment a \c CXComment_VerbatimBlockLine AST node.
  424. *
  425. * \returns text contained in the AST node.
  426. */
  427. CINDEX_LINKAGE
  428. CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
  429. /**
  430. * \param Comment a \c CXComment_VerbatimLine AST node.
  431. *
  432. * \returns text contained in the AST node.
  433. */
  434. CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
  435. /**
  436. * Convert an HTML tag AST node to string.
  437. *
  438. * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
  439. * node.
  440. *
  441. * \returns string containing an HTML tag.
  442. */
  443. CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
  444. /**
  445. * Convert a given full parsed comment to an HTML fragment.
  446. *
  447. * Specific details of HTML layout are subject to change. Don't try to parse
  448. * this HTML back into an AST, use other APIs instead.
  449. *
  450. * Currently the following CSS classes are used:
  451. * \li "para-brief" for \paragraph and equivalent commands;
  452. * \li "para-returns" for \\returns paragraph and equivalent commands;
  453. * \li "word-returns" for the "Returns" word in \\returns paragraph.
  454. *
  455. * Function argument documentation is rendered as a \<dl\> list with arguments
  456. * sorted in function prototype order. CSS classes used:
  457. * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
  458. * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
  459. * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
  460. * parameter index is invalid.
  461. *
  462. * Template parameter documentation is rendered as a \<dl\> list with
  463. * parameters sorted in template parameter list order. CSS classes used:
  464. * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
  465. * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
  466. * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
  467. * names inside template template parameters;
  468. * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
  469. * parameter position is invalid.
  470. *
  471. * \param Comment a \c CXComment_FullComment AST node.
  472. *
  473. * \returns string containing an HTML fragment.
  474. */
  475. CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
  476. /**
  477. * Convert a given full parsed comment to an XML document.
  478. *
  479. * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
  480. * inside clang source tree.
  481. *
  482. * \param Comment a \c CXComment_FullComment AST node.
  483. *
  484. * \returns string containing an XML document.
  485. */
  486. CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
  487. /**
  488. * @}
  489. */
  490. LLVM_CLANG_C_EXTERN_C_END
  491. #endif /* CLANG_C_DOCUMENTATION_H */