1 /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
5 |* See https://llvm.org/LICENSE.txt for license information. *|
6 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
8 |*===----------------------------------------------------------------------===*|
10 |* This header provides a supplementary interface for inspecting *|
11 |* documentation comments. *|
13 \*===----------------------------------------------------------------------===*/
15 #ifndef LLVM_CLANG_C_DOCUMENTATION_H
16 #define LLVM_CLANG_C_DOCUMENTATION_H
18 #include "clang-c/ExternC.h"
19 #include "clang-c/Index.h"
21 LLVM_CLANG_C_EXTERN_C_BEGIN
24 * \defgroup CINDEX_COMMENT Comment introspection
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.
38 CXTranslationUnit TranslationUnit;
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.
46 CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
49 * Describes the type of the comment AST node (\c CXComment). A comment
50 * node can be considered block content (e. g., paragraph), inline content
51 * (plain text) or neither (the root AST node).
55 * Null comment. No AST node is constructed at the requested location
56 * because there is no text or a syntax error.
61 * Plain text. Inline content.
66 * A command with word-like arguments that is considered inline content.
68 * For example: \\c command.
70 CXComment_InlineCommand = 2,
73 * HTML start tag with attributes (name-value pairs). Considered
78 * <br> <br /> <a href="http://example.org/">
81 CXComment_HTMLStartTag = 3,
84 * HTML end tag. Considered inline content.
91 CXComment_HTMLEndTag = 4,
94 * A paragraph, contains inline comment. The paragraph itself is
97 CXComment_Paragraph = 5,
100 * A command that has zero or more word-like arguments (number of
101 * word-like arguments depends on command name) and a paragraph as an
102 * argument. Block command is block content.
104 * Paragraph argument is also a child of the block command.
106 * For example: \has 0 word-like arguments and a paragraph argument.
108 * AST nodes of special kinds that parser knows about (e. g., \\param
109 * command) have their own node kinds.
111 CXComment_BlockCommand = 6,
114 * A \\param or \\arg command that describes the function parameter
115 * (name, passing direction, description).
117 * For example: \\param [in] ParamName description.
119 CXComment_ParamCommand = 7,
122 * A \\tparam command that describes a template parameter (name and
125 * For example: \\tparam T description.
127 CXComment_TParamCommand = 8,
130 * A verbatim block command (e. g., preformatted code). Verbatim
131 * block has an opening and a closing command and contains multiple lines of
132 * text (\c CXComment_VerbatimBlockLine child nodes).
139 CXComment_VerbatimBlockCommand = 9,
142 * A line of text that is contained within a
143 * CXComment_VerbatimBlockCommand node.
145 CXComment_VerbatimBlockLine = 10,
148 * A verbatim line command. Verbatim line has an opening command,
149 * a single line of text (up to the newline after the opening command) and
150 * has no closing command.
152 CXComment_VerbatimLine = 11,
155 * A full comment attached to a declaration, contains block content.
157 CXComment_FullComment = 12
161 * The most appropriate rendering mode for an inline command, chosen on
162 * command semantics in Doxygen.
164 enum CXCommentInlineCommandRenderKind {
166 * Command argument should be rendered in a normal font.
168 CXCommentInlineCommandRenderKind_Normal,
171 * Command argument should be rendered in a bold font.
173 CXCommentInlineCommandRenderKind_Bold,
176 * Command argument should be rendered in a monospaced font.
178 CXCommentInlineCommandRenderKind_Monospaced,
181 * Command argument should be rendered emphasized (typically italic
184 CXCommentInlineCommandRenderKind_Emphasized,
187 * Command argument should not be rendered (since it only defines an anchor).
189 CXCommentInlineCommandRenderKind_Anchor
193 * Describes parameter passing direction for \\param or \\arg command.
195 enum CXCommentParamPassDirection {
197 * The parameter is an input parameter.
199 CXCommentParamPassDirection_In,
202 * The parameter is an output parameter.
204 CXCommentParamPassDirection_Out,
207 * The parameter is an input and output parameter.
209 CXCommentParamPassDirection_InOut
213 * \param Comment AST node of any kind.
215 * \returns the type of the AST node.
217 CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
220 * \param Comment AST node of any kind.
222 * \returns number of children of the AST node.
224 CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
227 * \param Comment AST node of any kind.
229 * \param ChildIdx child index (zero-based).
231 * \returns the specified child of the AST node.
234 CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
237 * A \c CXComment_Paragraph node is considered whitespace if it contains
238 * only \c CXComment_Text nodes that are empty or whitespace.
240 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
241 * never considered whitespace.
243 * \returns non-zero if \c Comment is whitespace.
245 CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
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
253 unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
256 * \param Comment a \c CXComment_Text AST node.
258 * \returns text contained in the AST node.
260 CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
263 * \param Comment a \c CXComment_InlineCommand AST node.
265 * \returns name of the inline command.
268 CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
271 * \param Comment a \c CXComment_InlineCommand AST node.
273 * \returns the most appropriate rendering mode, chosen on command
274 * semantics in Doxygen.
276 CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
277 clang_InlineCommandComment_getRenderKind(CXComment Comment);
280 * \param Comment a \c CXComment_InlineCommand AST node.
282 * \returns number of command arguments.
285 unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
288 * \param Comment a \c CXComment_InlineCommand AST node.
290 * \param ArgIdx argument index (zero-based).
292 * \returns text of the specified argument.
295 CXString clang_InlineCommandComment_getArgText(CXComment Comment,
299 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
302 * \returns HTML tag name.
304 CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
307 * \param Comment a \c CXComment_HTMLStartTag AST node.
309 * \returns non-zero if tag is self-closing (for example, <br />).
312 unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
315 * \param Comment a \c CXComment_HTMLStartTag AST node.
317 * \returns number of attributes (name-value pairs) attached to the start tag.
319 CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
322 * \param Comment a \c CXComment_HTMLStartTag AST node.
324 * \param AttrIdx attribute index (zero-based).
326 * \returns name of the specified attribute.
329 CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
332 * \param Comment a \c CXComment_HTMLStartTag AST node.
334 * \param AttrIdx attribute index (zero-based).
336 * \returns value of the specified attribute.
339 CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
342 * \param Comment a \c CXComment_BlockCommand AST node.
344 * \returns name of the block command.
347 CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
350 * \param Comment a \c CXComment_BlockCommand AST node.
352 * \returns number of word-like arguments.
355 unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
358 * \param Comment a \c CXComment_BlockCommand AST node.
360 * \param ArgIdx argument index (zero-based).
362 * \returns text of the specified word-like argument.
365 CXString clang_BlockCommandComment_getArgText(CXComment Comment,
369 * \param Comment a \c CXComment_BlockCommand or
370 * \c CXComment_VerbatimBlockCommand AST node.
372 * \returns paragraph argument of the block command.
375 CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
378 * \param Comment a \c CXComment_ParamCommand AST node.
380 * \returns parameter name.
383 CXString clang_ParamCommandComment_getParamName(CXComment Comment);
386 * \param Comment a \c CXComment_ParamCommand AST node.
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.
393 unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
396 * \param Comment a \c CXComment_ParamCommand AST node.
398 * \returns zero-based parameter index in function prototype.
401 unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
404 * \param Comment a \c CXComment_ParamCommand AST node.
406 * \returns non-zero if parameter passing direction was specified explicitly in
410 unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
413 * \param Comment a \c CXComment_ParamCommand AST node.
415 * \returns parameter passing direction.
418 enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
422 * \param Comment a \c CXComment_TParamCommand AST node.
424 * \returns template parameter name.
427 CXString clang_TParamCommandComment_getParamName(CXComment Comment);
430 * \param Comment a \c CXComment_TParamCommand AST node.
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
439 unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
442 * \param Comment a \c CXComment_TParamCommand AST node.
444 * \returns zero-based nesting depth of this parameter in the template parameter list.
448 * template<typename C, template<typename T> class TT>
449 * void test(TT<int> aaa);
451 * for C and TT nesting depth is 0,
452 * for T nesting depth is 1.
455 unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
458 * \param Comment a \c CXComment_TParamCommand AST node.
460 * \returns zero-based parameter index in the template parameter list at a
461 * given nesting depth.
465 * template<typename C, template<typename T> class TT>
466 * void test(TT<int> aaa);
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.
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.
476 unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
479 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
481 * \returns text contained in the AST node.
484 CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
487 * \param Comment a \c CXComment_VerbatimLine AST node.
489 * \returns text contained in the AST node.
491 CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
494 * Convert an HTML tag AST node to string.
496 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
499 * \returns string containing an HTML tag.
501 CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
504 * Convert a given full parsed comment to an HTML fragment.
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.
509 * Currently the following CSS classes are used:
510 * \li "para-brief" for \paragraph and equivalent commands;
511 * \li "para-returns" for \\returns paragraph and equivalent commands;
512 * \li "word-returns" for the "Returns" word in \\returns paragraph.
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.
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.
530 * \param Comment a \c CXComment_FullComment AST node.
532 * \returns string containing an HTML fragment.
534 CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
537 * Convert a given full parsed comment to an XML document.
539 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
540 * inside clang source tree.
542 * \param Comment a \c CXComment_FullComment AST node.
544 * \returns string containing an XML document.
546 CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
552 LLVM_CLANG_C_EXTERN_C_END
554 #endif /* CLANG_C_DOCUMENTATION_H */