Documentation.h 18 KB

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