Documentation.h 16 KB

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