Documentation.h 16 KB

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