blob: 5bece2cb6758f3c59e3b1e45235a6ba55bce4bad [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001/*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
2|* *|
Andrew Walbran16937d02019-10-22 13:54:20 +01003|* 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 *|
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01007|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a supplementary interface for inspecting *|
11|* documentation comments. *|
12|* *|
13\*===----------------------------------------------------------------------===*/
14
15#ifndef LLVM_CLANG_C_DOCUMENTATION_H
16#define LLVM_CLANG_C_DOCUMENTATION_H
17
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020018#include "clang-c/ExternC.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010019#include "clang-c/Index.h"
20
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020021LLVM_CLANG_C_EXTERN_C_BEGIN
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010022
23/**
24 * \defgroup CINDEX_COMMENT Comment introspection
25 *
26 * The routines in this group provide access to information in documentation
27 * comments. These facilities are distinct from the core and may be subject to
28 * their own schedule of stability and deprecation.
29 *
30 * @{
31 */
32
33/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010034 * A parsed comment.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010035 */
36typedef struct {
37 const void *ASTNode;
38 CXTranslationUnit TranslationUnit;
39} CXComment;
40
41/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010042 * Given a cursor that represents a documentable entity (e.g.,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010043 * declaration), return the associated parsed comment as a
44 * \c CXComment_FullComment AST node.
45 */
46CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
47
48/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010049 * Describes the type of the comment AST node (\c CXComment). A comment
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010050 * node can be considered block content (e. g., paragraph), inline content
51 * (plain text) or neither (the root AST node).
52 */
53enum CXCommentKind {
54 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010055 * Null comment. No AST node is constructed at the requested location
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010056 * because there is no text or a syntax error.
57 */
58 CXComment_Null = 0,
59
60 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010061 * Plain text. Inline content.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010062 */
63 CXComment_Text = 1,
64
65 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010066 * A command with word-like arguments that is considered inline content.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010067 *
68 * For example: \\c command.
69 */
70 CXComment_InlineCommand = 2,
71
72 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010073 * HTML start tag with attributes (name-value pairs). Considered
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010074 * inline content.
75 *
76 * For example:
77 * \verbatim
78 * <br> <br /> <a href="http://example.org/">
79 * \endverbatim
80 */
81 CXComment_HTMLStartTag = 3,
82
83 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010084 * HTML end tag. Considered inline content.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010085 *
86 * For example:
87 * \verbatim
88 * </a>
89 * \endverbatim
90 */
91 CXComment_HTMLEndTag = 4,
92
93 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +010094 * A paragraph, contains inline comment. The paragraph itself is
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010095 * block content.
96 */
97 CXComment_Paragraph = 5,
98
99 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100100 * A command that has zero or more word-like arguments (number of
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100101 * word-like arguments depends on command name) and a paragraph as an
102 * argument. Block command is block content.
103 *
104 * Paragraph argument is also a child of the block command.
105 *
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100106 * For example: \has 0 word-like arguments and a paragraph argument.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100107 *
108 * AST nodes of special kinds that parser knows about (e. g., \\param
109 * command) have their own node kinds.
110 */
111 CXComment_BlockCommand = 6,
112
113 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100114 * A \\param or \\arg command that describes the function parameter
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100115 * (name, passing direction, description).
116 *
117 * For example: \\param [in] ParamName description.
118 */
119 CXComment_ParamCommand = 7,
120
121 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100122 * A \\tparam command that describes a template parameter (name and
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100123 * description).
124 *
125 * For example: \\tparam T description.
126 */
127 CXComment_TParamCommand = 8,
128
129 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100130 * A verbatim block command (e. g., preformatted code). Verbatim
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100131 * block has an opening and a closing command and contains multiple lines of
132 * text (\c CXComment_VerbatimBlockLine child nodes).
133 *
134 * For example:
135 * \\verbatim
136 * aaa
137 * \\endverbatim
138 */
139 CXComment_VerbatimBlockCommand = 9,
140
141 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100142 * A line of text that is contained within a
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100143 * CXComment_VerbatimBlockCommand node.
144 */
145 CXComment_VerbatimBlockLine = 10,
146
147 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100148 * A verbatim line command. Verbatim line has an opening command,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100149 * a single line of text (up to the newline after the opening command) and
150 * has no closing command.
151 */
152 CXComment_VerbatimLine = 11,
153
154 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100155 * A full comment attached to a declaration, contains block content.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100156 */
157 CXComment_FullComment = 12
158};
159
160/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100161 * The most appropriate rendering mode for an inline command, chosen on
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100162 * command semantics in Doxygen.
163 */
164enum CXCommentInlineCommandRenderKind {
165 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100166 * Command argument should be rendered in a normal font.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100167 */
168 CXCommentInlineCommandRenderKind_Normal,
169
170 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100171 * Command argument should be rendered in a bold font.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100172 */
173 CXCommentInlineCommandRenderKind_Bold,
174
175 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100176 * Command argument should be rendered in a monospaced font.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100177 */
178 CXCommentInlineCommandRenderKind_Monospaced,
179
180 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100181 * Command argument should be rendered emphasized (typically italic
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100182 * font).
183 */
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200184 CXCommentInlineCommandRenderKind_Emphasized,
185
186 /**
187 * Command argument should not be rendered (since it only defines an anchor).
188 */
189 CXCommentInlineCommandRenderKind_Anchor
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100190};
191
192/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100193 * Describes parameter passing direction for \\param or \\arg command.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100194 */
195enum CXCommentParamPassDirection {
196 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100197 * The parameter is an input parameter.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100198 */
199 CXCommentParamPassDirection_In,
200
201 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100202 * The parameter is an output parameter.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100203 */
204 CXCommentParamPassDirection_Out,
205
206 /**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100207 * The parameter is an input and output parameter.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100208 */
209 CXCommentParamPassDirection_InOut
210};
211
212/**
213 * \param Comment AST node of any kind.
214 *
215 * \returns the type of the AST node.
216 */
217CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
218
219/**
220 * \param Comment AST node of any kind.
221 *
222 * \returns number of children of the AST node.
223 */
224CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
225
226/**
227 * \param Comment AST node of any kind.
228 *
229 * \param ChildIdx child index (zero-based).
230 *
231 * \returns the specified child of the AST node.
232 */
233CINDEX_LINKAGE
234CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
235
236/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100237 * A \c CXComment_Paragraph node is considered whitespace if it contains
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100238 * only \c CXComment_Text nodes that are empty or whitespace.
239 *
240 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
241 * never considered whitespace.
242 *
243 * \returns non-zero if \c Comment is whitespace.
244 */
245CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
246
247/**
248 * \returns non-zero if \c Comment is inline content and has a newline
249 * immediately following it in the comment text. Newlines between paragraphs
250 * do not count.
251 */
252CINDEX_LINKAGE
253unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
254
255/**
256 * \param Comment a \c CXComment_Text AST node.
257 *
258 * \returns text contained in the AST node.
259 */
260CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
261
262/**
263 * \param Comment a \c CXComment_InlineCommand AST node.
264 *
265 * \returns name of the inline command.
266 */
267CINDEX_LINKAGE
268CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
269
270/**
271 * \param Comment a \c CXComment_InlineCommand AST node.
272 *
273 * \returns the most appropriate rendering mode, chosen on command
274 * semantics in Doxygen.
275 */
276CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
277clang_InlineCommandComment_getRenderKind(CXComment Comment);
278
279/**
280 * \param Comment a \c CXComment_InlineCommand AST node.
281 *
282 * \returns number of command arguments.
283 */
284CINDEX_LINKAGE
285unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
286
287/**
288 * \param Comment a \c CXComment_InlineCommand AST node.
289 *
290 * \param ArgIdx argument index (zero-based).
291 *
292 * \returns text of the specified argument.
293 */
294CINDEX_LINKAGE
295CXString clang_InlineCommandComment_getArgText(CXComment Comment,
296 unsigned ArgIdx);
297
298/**
299 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
300 * node.
301 *
302 * \returns HTML tag name.
303 */
304CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
305
306/**
307 * \param Comment a \c CXComment_HTMLStartTag AST node.
308 *
309 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
310 */
311CINDEX_LINKAGE
312unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
313
314/**
315 * \param Comment a \c CXComment_HTMLStartTag AST node.
316 *
317 * \returns number of attributes (name-value pairs) attached to the start tag.
318 */
319CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
320
321/**
322 * \param Comment a \c CXComment_HTMLStartTag AST node.
323 *
324 * \param AttrIdx attribute index (zero-based).
325 *
326 * \returns name of the specified attribute.
327 */
328CINDEX_LINKAGE
329CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
330
331/**
332 * \param Comment a \c CXComment_HTMLStartTag AST node.
333 *
334 * \param AttrIdx attribute index (zero-based).
335 *
336 * \returns value of the specified attribute.
337 */
338CINDEX_LINKAGE
339CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
340
341/**
342 * \param Comment a \c CXComment_BlockCommand AST node.
343 *
344 * \returns name of the block command.
345 */
346CINDEX_LINKAGE
347CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
348
349/**
350 * \param Comment a \c CXComment_BlockCommand AST node.
351 *
352 * \returns number of word-like arguments.
353 */
354CINDEX_LINKAGE
355unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
356
357/**
358 * \param Comment a \c CXComment_BlockCommand AST node.
359 *
360 * \param ArgIdx argument index (zero-based).
361 *
362 * \returns text of the specified word-like argument.
363 */
364CINDEX_LINKAGE
365CXString clang_BlockCommandComment_getArgText(CXComment Comment,
366 unsigned ArgIdx);
367
368/**
369 * \param Comment a \c CXComment_BlockCommand or
370 * \c CXComment_VerbatimBlockCommand AST node.
371 *
372 * \returns paragraph argument of the block command.
373 */
374CINDEX_LINKAGE
375CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
376
377/**
378 * \param Comment a \c CXComment_ParamCommand AST node.
379 *
380 * \returns parameter name.
381 */
382CINDEX_LINKAGE
383CXString clang_ParamCommandComment_getParamName(CXComment Comment);
384
385/**
386 * \param Comment a \c CXComment_ParamCommand AST node.
387 *
388 * \returns non-zero if the parameter that this AST node represents was found
389 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
390 * function will return a meaningful value.
391 */
392CINDEX_LINKAGE
393unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
394
395/**
396 * \param Comment a \c CXComment_ParamCommand AST node.
397 *
398 * \returns zero-based parameter index in function prototype.
399 */
400CINDEX_LINKAGE
401unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
402
403/**
404 * \param Comment a \c CXComment_ParamCommand AST node.
405 *
406 * \returns non-zero if parameter passing direction was specified explicitly in
407 * the comment.
408 */
409CINDEX_LINKAGE
410unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
411
412/**
413 * \param Comment a \c CXComment_ParamCommand AST node.
414 *
415 * \returns parameter passing direction.
416 */
417CINDEX_LINKAGE
418enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
419 CXComment Comment);
420
421/**
422 * \param Comment a \c CXComment_TParamCommand AST node.
423 *
424 * \returns template parameter name.
425 */
426CINDEX_LINKAGE
427CXString clang_TParamCommandComment_getParamName(CXComment Comment);
428
429/**
430 * \param Comment a \c CXComment_TParamCommand AST node.
431 *
432 * \returns non-zero if the parameter that this AST node represents was found
433 * in the template parameter list and
434 * \c clang_TParamCommandComment_getDepth and
435 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
436 * value.
437 */
438CINDEX_LINKAGE
439unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
440
441/**
442 * \param Comment a \c CXComment_TParamCommand AST node.
443 *
444 * \returns zero-based nesting depth of this parameter in the template parameter list.
445 *
446 * For example,
447 * \verbatim
448 * template<typename C, template<typename T> class TT>
449 * void test(TT<int> aaa);
450 * \endverbatim
451 * for C and TT nesting depth is 0,
452 * for T nesting depth is 1.
453 */
454CINDEX_LINKAGE
455unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
456
457/**
458 * \param Comment a \c CXComment_TParamCommand AST node.
459 *
460 * \returns zero-based parameter index in the template parameter list at a
461 * given nesting depth.
462 *
463 * For example,
464 * \verbatim
465 * template<typename C, template<typename T> class TT>
466 * void test(TT<int> aaa);
467 * \endverbatim
468 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
469 * at depth 0 C's index is 0, TT's index is 1.
470 *
471 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
472 * at depth 0 T's index is 1 (same as TT's),
473 * at depth 1 T's index is 0.
474 */
475CINDEX_LINKAGE
476unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
477
478/**
479 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
480 *
481 * \returns text contained in the AST node.
482 */
483CINDEX_LINKAGE
484CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
485
486/**
487 * \param Comment a \c CXComment_VerbatimLine AST node.
488 *
489 * \returns text contained in the AST node.
490 */
491CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
492
493/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100494 * Convert an HTML tag AST node to string.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100495 *
496 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
497 * node.
498 *
499 * \returns string containing an HTML tag.
500 */
501CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
502
503/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100504 * Convert a given full parsed comment to an HTML fragment.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100505 *
506 * Specific details of HTML layout are subject to change. Don't try to parse
507 * this HTML back into an AST, use other APIs instead.
508 *
509 * Currently the following CSS classes are used:
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100510 * \li "para-brief" for \paragraph and equivalent commands;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100511 * \li "para-returns" for \\returns paragraph and equivalent commands;
512 * \li "word-returns" for the "Returns" word in \\returns paragraph.
513 *
514 * Function argument documentation is rendered as a \<dl\> list with arguments
515 * sorted in function prototype order. CSS classes used:
516 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
517 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
518 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
519 * parameter index is invalid.
520 *
521 * Template parameter documentation is rendered as a \<dl\> list with
522 * parameters sorted in template parameter list order. CSS classes used:
523 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
524 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
525 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
526 * names inside template template parameters;
527 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
528 * parameter position is invalid.
529 *
530 * \param Comment a \c CXComment_FullComment AST node.
531 *
532 * \returns string containing an HTML fragment.
533 */
534CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
535
536/**
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100537 * Convert a given full parsed comment to an XML document.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100538 *
539 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
540 * inside clang source tree.
541 *
542 * \param Comment a \c CXComment_FullComment AST node.
543 *
544 * \returns string containing an XML document.
545 */
546CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
547
548/**
549 * @}
550 */
551
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200552LLVM_CLANG_C_EXTERN_C_END
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100553
554#endif /* CLANG_C_DOCUMENTATION_H */
555