[memprof] Upgrade a unit test to MemProf Version 3 (#117063)
[llvm-project.git] / clang / include / clang-c / Documentation.h
blobe04c50a0e68b6eaa97df249a2c536797d75c8594
1 /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
2 |* *|
3 |* 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 *|
7 |* *|
8 |*===----------------------------------------------------------------------===*|
9 |* *|
10 |* This header provides a supplementary interface for inspecting *|
11 |* documentation comments. *|
12 |* *|
13 \*===----------------------------------------------------------------------===*/
15 #ifndef LLVM_CLANG_C_DOCUMENTATION_H
16 #define LLVM_CLANG_C_DOCUMENTATION_H
18 #include "clang-c/CXErrorCode.h"
19 #include "clang-c/ExternC.h"
20 #include "clang-c/Index.h"
22 LLVM_CLANG_C_EXTERN_C_BEGIN
24 /**
25 * \defgroup CINDEX_COMMENT Comment introspection
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.
31 * @{
34 /**
35 * A parsed comment.
37 typedef struct {
38 const void *ASTNode;
39 CXTranslationUnit TranslationUnit;
40 } CXComment;
42 /**
43 * Given a cursor that represents a documentable entity (e.g.,
44 * declaration), return the associated parsed comment as a
45 * \c CXComment_FullComment AST node.
47 CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
49 /**
50 * Describes the type of the comment AST node (\c CXComment). A comment
51 * node can be considered block content (e. g., paragraph), inline content
52 * (plain text) or neither (the root AST node).
54 enum CXCommentKind {
55 /**
56 * Null comment. No AST node is constructed at the requested location
57 * because there is no text or a syntax error.
59 CXComment_Null = 0,
61 /**
62 * Plain text. Inline content.
64 CXComment_Text = 1,
66 /**
67 * A command with word-like arguments that is considered inline content.
69 * For example: \\c command.
71 CXComment_InlineCommand = 2,
73 /**
74 * HTML start tag with attributes (name-value pairs). Considered
75 * inline content.
77 * For example:
78 * \verbatim
79 * <br> <br /> <a href="http://example.org/">
80 * \endverbatim
82 CXComment_HTMLStartTag = 3,
84 /**
85 * HTML end tag. Considered inline content.
87 * For example:
88 * \verbatim
89 * </a>
90 * \endverbatim
92 CXComment_HTMLEndTag = 4,
94 /**
95 * A paragraph, contains inline comment. The paragraph itself is
96 * block content.
98 CXComment_Paragraph = 5,
101 * A command that has zero or more word-like arguments (number of
102 * word-like arguments depends on command name) and a paragraph as an
103 * argument. Block command is block content.
105 * Paragraph argument is also a child of the block command.
107 * For example: \has 0 word-like arguments and a paragraph argument.
109 * AST nodes of special kinds that parser knows about (e. g., \\param
110 * command) have their own node kinds.
112 CXComment_BlockCommand = 6,
115 * A \\param or \\arg command that describes the function parameter
116 * (name, passing direction, description).
118 * For example: \\param [in] ParamName description.
120 CXComment_ParamCommand = 7,
123 * A \\tparam command that describes a template parameter (name and
124 * description).
126 * For example: \\tparam T description.
128 CXComment_TParamCommand = 8,
131 * A verbatim block command (e. g., preformatted code). Verbatim
132 * block has an opening and a closing command and contains multiple lines of
133 * text (\c CXComment_VerbatimBlockLine child nodes).
135 * For example:
136 * \\verbatim
137 * aaa
138 * \\endverbatim
140 CXComment_VerbatimBlockCommand = 9,
143 * A line of text that is contained within a
144 * CXComment_VerbatimBlockCommand node.
146 CXComment_VerbatimBlockLine = 10,
149 * A verbatim line command. Verbatim line has an opening command,
150 * a single line of text (up to the newline after the opening command) and
151 * has no closing command.
153 CXComment_VerbatimLine = 11,
156 * A full comment attached to a declaration, contains block content.
158 CXComment_FullComment = 12
162 * The most appropriate rendering mode for an inline command, chosen on
163 * command semantics in Doxygen.
165 enum CXCommentInlineCommandRenderKind {
167 * Command argument should be rendered in a normal font.
169 CXCommentInlineCommandRenderKind_Normal,
172 * Command argument should be rendered in a bold font.
174 CXCommentInlineCommandRenderKind_Bold,
177 * Command argument should be rendered in a monospaced font.
179 CXCommentInlineCommandRenderKind_Monospaced,
182 * Command argument should be rendered emphasized (typically italic
183 * font).
185 CXCommentInlineCommandRenderKind_Emphasized,
188 * Command argument should not be rendered (since it only defines an anchor).
190 CXCommentInlineCommandRenderKind_Anchor
194 * Describes parameter passing direction for \\param or \\arg command.
196 enum CXCommentParamPassDirection {
198 * The parameter is an input parameter.
200 CXCommentParamPassDirection_In,
203 * The parameter is an output parameter.
205 CXCommentParamPassDirection_Out,
208 * The parameter is an input and output parameter.
210 CXCommentParamPassDirection_InOut
214 * \param Comment AST node of any kind.
216 * \returns the type of the AST node.
218 CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
221 * \param Comment AST node of any kind.
223 * \returns number of children of the AST node.
225 CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
228 * \param Comment AST node of any kind.
230 * \param ChildIdx child index (zero-based).
232 * \returns the specified child of the AST node.
234 CINDEX_LINKAGE
235 CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
238 * A \c CXComment_Paragraph node is considered whitespace if it contains
239 * only \c CXComment_Text nodes that are empty or whitespace.
241 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
242 * never considered whitespace.
244 * \returns non-zero if \c Comment is whitespace.
246 CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
249 * \returns non-zero if \c Comment is inline content and has a newline
250 * immediately following it in the comment text. Newlines between paragraphs
251 * do not count.
253 CINDEX_LINKAGE
254 unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
257 * \param Comment a \c CXComment_Text AST node.
259 * \returns text contained in the AST node.
261 CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
264 * \param Comment a \c CXComment_InlineCommand AST node.
266 * \returns name of the inline command.
268 CINDEX_LINKAGE
269 CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
272 * \param Comment a \c CXComment_InlineCommand AST node.
274 * \returns the most appropriate rendering mode, chosen on command
275 * semantics in Doxygen.
277 CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
278 clang_InlineCommandComment_getRenderKind(CXComment Comment);
281 * \param Comment a \c CXComment_InlineCommand AST node.
283 * \returns number of command arguments.
285 CINDEX_LINKAGE
286 unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
289 * \param Comment a \c CXComment_InlineCommand AST node.
291 * \param ArgIdx argument index (zero-based).
293 * \returns text of the specified argument.
295 CINDEX_LINKAGE
296 CXString clang_InlineCommandComment_getArgText(CXComment Comment,
297 unsigned ArgIdx);
300 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
301 * node.
303 * \returns HTML tag name.
305 CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
308 * \param Comment a \c CXComment_HTMLStartTag AST node.
310 * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
312 CINDEX_LINKAGE
313 unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
316 * \param Comment a \c CXComment_HTMLStartTag AST node.
318 * \returns number of attributes (name-value pairs) attached to the start tag.
320 CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
323 * \param Comment a \c CXComment_HTMLStartTag AST node.
325 * \param AttrIdx attribute index (zero-based).
327 * \returns name of the specified attribute.
329 CINDEX_LINKAGE
330 CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
333 * \param Comment a \c CXComment_HTMLStartTag AST node.
335 * \param AttrIdx attribute index (zero-based).
337 * \returns value of the specified attribute.
339 CINDEX_LINKAGE
340 CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
343 * \param Comment a \c CXComment_BlockCommand AST node.
345 * \returns name of the block command.
347 CINDEX_LINKAGE
348 CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
351 * \param Comment a \c CXComment_BlockCommand AST node.
353 * \returns number of word-like arguments.
355 CINDEX_LINKAGE
356 unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
359 * \param Comment a \c CXComment_BlockCommand AST node.
361 * \param ArgIdx argument index (zero-based).
363 * \returns text of the specified word-like argument.
365 CINDEX_LINKAGE
366 CXString clang_BlockCommandComment_getArgText(CXComment Comment,
367 unsigned ArgIdx);
370 * \param Comment a \c CXComment_BlockCommand or
371 * \c CXComment_VerbatimBlockCommand AST node.
373 * \returns paragraph argument of the block command.
375 CINDEX_LINKAGE
376 CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
379 * \param Comment a \c CXComment_ParamCommand AST node.
381 * \returns parameter name.
383 CINDEX_LINKAGE
384 CXString clang_ParamCommandComment_getParamName(CXComment Comment);
387 * \param Comment a \c CXComment_ParamCommand AST node.
389 * \returns non-zero if the parameter that this AST node represents was found
390 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
391 * function will return a meaningful value.
393 CINDEX_LINKAGE
394 unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
397 * \param Comment a \c CXComment_ParamCommand AST node.
399 * \returns zero-based parameter index in function prototype.
401 CINDEX_LINKAGE
402 unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
405 * \param Comment a \c CXComment_ParamCommand AST node.
407 * \returns non-zero if parameter passing direction was specified explicitly in
408 * the comment.
410 CINDEX_LINKAGE
411 unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
414 * \param Comment a \c CXComment_ParamCommand AST node.
416 * \returns parameter passing direction.
418 CINDEX_LINKAGE
419 enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
420 CXComment Comment);
423 * \param Comment a \c CXComment_TParamCommand AST node.
425 * \returns template parameter name.
427 CINDEX_LINKAGE
428 CXString clang_TParamCommandComment_getParamName(CXComment Comment);
431 * \param Comment a \c CXComment_TParamCommand AST node.
433 * \returns non-zero if the parameter that this AST node represents was found
434 * in the template parameter list and
435 * \c clang_TParamCommandComment_getDepth and
436 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
437 * value.
439 CINDEX_LINKAGE
440 unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
443 * \param Comment a \c CXComment_TParamCommand AST node.
445 * \returns zero-based nesting depth of this parameter in the template parameter list.
447 * For example,
448 * \verbatim
449 * template<typename C, template<typename T> class TT>
450 * void test(TT<int> aaa);
451 * \endverbatim
452 * for C and TT nesting depth is 0,
453 * for T nesting depth is 1.
455 CINDEX_LINKAGE
456 unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
459 * \param Comment a \c CXComment_TParamCommand AST node.
461 * \returns zero-based parameter index in the template parameter list at a
462 * given nesting depth.
464 * For example,
465 * \verbatim
466 * template<typename C, template<typename T> class TT>
467 * void test(TT<int> aaa);
468 * \endverbatim
469 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
470 * at depth 0 C's index is 0, TT's index is 1.
472 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
473 * at depth 0 T's index is 1 (same as TT's),
474 * at depth 1 T's index is 0.
476 CINDEX_LINKAGE
477 unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
480 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
482 * \returns text contained in the AST node.
484 CINDEX_LINKAGE
485 CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
488 * \param Comment a \c CXComment_VerbatimLine AST node.
490 * \returns text contained in the AST node.
492 CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
495 * Convert an HTML tag AST node to string.
497 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
498 * node.
500 * \returns string containing an HTML tag.
502 CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
505 * Convert a given full parsed comment to an HTML fragment.
507 * Specific details of HTML layout are subject to change. Don't try to parse
508 * this HTML back into an AST, use other APIs instead.
510 * Currently the following CSS classes are used:
511 * \li "para-brief" for \paragraph and equivalent commands;
512 * \li "para-returns" for \\returns paragraph and equivalent commands;
513 * \li "word-returns" for the "Returns" word in \\returns paragraph.
515 * Function argument documentation is rendered as a \<dl\> list with arguments
516 * sorted in function prototype order. CSS classes used:
517 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
518 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
519 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
520 * parameter index is invalid.
522 * Template parameter documentation is rendered as a \<dl\> list with
523 * parameters sorted in template parameter list order. CSS classes used:
524 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
525 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
526 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
527 * names inside template template parameters;
528 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
529 * parameter position is invalid.
531 * \param Comment a \c CXComment_FullComment AST node.
533 * \returns string containing an HTML fragment.
535 CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
538 * Convert a given full parsed comment to an XML document.
540 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
541 * inside clang source tree.
543 * \param Comment a \c CXComment_FullComment AST node.
545 * \returns string containing an XML document.
547 CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
550 * CXAPISet is an opaque type that represents a data structure containing all
551 * the API information for a given translation unit. This can be used for a
552 * single symbol symbol graph for a given symbol.
554 typedef struct CXAPISetImpl *CXAPISet;
557 * Traverses the translation unit to create a \c CXAPISet.
559 * \param tu is the \c CXTranslationUnit to build the \c CXAPISet for.
561 * \param out_api is a pointer to the output of this function. It is needs to be
562 * disposed of by calling clang_disposeAPISet.
564 * \returns Error code indicating success or failure of the APISet creation.
566 CINDEX_LINKAGE enum CXErrorCode clang_createAPISet(CXTranslationUnit tu,
567 CXAPISet *out_api);
570 * Dispose of an APISet.
572 * The provided \c CXAPISet can not be used after this function is called.
574 CINDEX_LINKAGE void clang_disposeAPISet(CXAPISet api);
577 * Generate a single symbol symbol graph for the given USR. Returns a null
578 * string if the associated symbol can not be found in the provided \c CXAPISet.
580 * The output contains the symbol graph as well as some additional information
581 * about related symbols.
583 * \param usr is a string containing the USR of the symbol to generate the
584 * symbol graph for.
586 * \param api the \c CXAPISet to look for the symbol in.
588 * \returns a string containing the serialized symbol graph representation for
589 * the symbol being queried or a null string if it can not be found in the
590 * APISet.
592 CINDEX_LINKAGE CXString clang_getSymbolGraphForUSR(const char *usr,
593 CXAPISet api);
596 * Generate a single symbol symbol graph for the declaration at the given
597 * cursor. Returns a null string if the AST node for the cursor isn't a
598 * declaration.
600 * The output contains the symbol graph as well as some additional information
601 * about related symbols.
603 * \param cursor the declaration for which to generate the single symbol symbol
604 * graph.
606 * \returns a string containing the serialized symbol graph representation for
607 * the symbol being queried or a null string if it can not be found in the
608 * APISet.
610 CINDEX_LINKAGE CXString clang_getSymbolGraphForCursor(CXCursor cursor);
613 * @}
616 LLVM_CLANG_C_EXTERN_C_END
618 #endif /* CLANG_C_DOCUMENTATION_H */