Path: blob/main/contrib/llvm-project/clang/include/clang-c/Documentation.h
35233 views
/*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\1|* *|2|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|3|* Exceptions. *|4|* See https://llvm.org/LICENSE.txt for license information. *|5|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|6|* *|7|*===----------------------------------------------------------------------===*|8|* *|9|* This header provides a supplementary interface for inspecting *|10|* documentation comments. *|11|* *|12\*===----------------------------------------------------------------------===*/1314#ifndef LLVM_CLANG_C_DOCUMENTATION_H15#define LLVM_CLANG_C_DOCUMENTATION_H1617#include "clang-c/CXErrorCode.h"18#include "clang-c/ExternC.h"19#include "clang-c/Index.h"2021LLVM_CLANG_C_EXTERN_C_BEGIN2223/**24* \defgroup CINDEX_COMMENT Comment introspection25*26* The routines in this group provide access to information in documentation27* comments. These facilities are distinct from the core and may be subject to28* their own schedule of stability and deprecation.29*30* @{31*/3233/**34* A parsed comment.35*/36typedef struct {37const void *ASTNode;38CXTranslationUnit TranslationUnit;39} CXComment;4041/**42* Given a cursor that represents a documentable entity (e.g.,43* declaration), return the associated parsed comment as a44* \c CXComment_FullComment AST node.45*/46CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);4748/**49* Describes the type of the comment AST node (\c CXComment). A comment50* node can be considered block content (e. g., paragraph), inline content51* (plain text) or neither (the root AST node).52*/53enum CXCommentKind {54/**55* Null comment. No AST node is constructed at the requested location56* because there is no text or a syntax error.57*/58CXComment_Null = 0,5960/**61* Plain text. Inline content.62*/63CXComment_Text = 1,6465/**66* A command with word-like arguments that is considered inline content.67*68* For example: \\c command.69*/70CXComment_InlineCommand = 2,7172/**73* HTML start tag with attributes (name-value pairs). Considered74* inline content.75*76* For example:77* \verbatim78* <br> <br /> <a href="http://example.org/">79* \endverbatim80*/81CXComment_HTMLStartTag = 3,8283/**84* HTML end tag. Considered inline content.85*86* For example:87* \verbatim88* </a>89* \endverbatim90*/91CXComment_HTMLEndTag = 4,9293/**94* A paragraph, contains inline comment. The paragraph itself is95* block content.96*/97CXComment_Paragraph = 5,9899/**100* A command that has zero or more word-like arguments (number of101* word-like arguments depends on command name) and a paragraph as an102* argument. Block command is block content.103*104* Paragraph argument is also a child of the block command.105*106* For example: \has 0 word-like arguments and a paragraph argument.107*108* AST nodes of special kinds that parser knows about (e. g., \\param109* command) have their own node kinds.110*/111CXComment_BlockCommand = 6,112113/**114* A \\param or \\arg command that describes the function parameter115* (name, passing direction, description).116*117* For example: \\param [in] ParamName description.118*/119CXComment_ParamCommand = 7,120121/**122* A \\tparam command that describes a template parameter (name and123* description).124*125* For example: \\tparam T description.126*/127CXComment_TParamCommand = 8,128129/**130* A verbatim block command (e. g., preformatted code). Verbatim131* block has an opening and a closing command and contains multiple lines of132* text (\c CXComment_VerbatimBlockLine child nodes).133*134* For example:135* \\verbatim136* aaa137* \\endverbatim138*/139CXComment_VerbatimBlockCommand = 9,140141/**142* A line of text that is contained within a143* CXComment_VerbatimBlockCommand node.144*/145CXComment_VerbatimBlockLine = 10,146147/**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) and150* has no closing command.151*/152CXComment_VerbatimLine = 11,153154/**155* A full comment attached to a declaration, contains block content.156*/157CXComment_FullComment = 12158};159160/**161* The most appropriate rendering mode for an inline command, chosen on162* command semantics in Doxygen.163*/164enum CXCommentInlineCommandRenderKind {165/**166* Command argument should be rendered in a normal font.167*/168CXCommentInlineCommandRenderKind_Normal,169170/**171* Command argument should be rendered in a bold font.172*/173CXCommentInlineCommandRenderKind_Bold,174175/**176* Command argument should be rendered in a monospaced font.177*/178CXCommentInlineCommandRenderKind_Monospaced,179180/**181* Command argument should be rendered emphasized (typically italic182* font).183*/184CXCommentInlineCommandRenderKind_Emphasized,185186/**187* Command argument should not be rendered (since it only defines an anchor).188*/189CXCommentInlineCommandRenderKind_Anchor190};191192/**193* Describes parameter passing direction for \\param or \\arg command.194*/195enum CXCommentParamPassDirection {196/**197* The parameter is an input parameter.198*/199CXCommentParamPassDirection_In,200201/**202* The parameter is an output parameter.203*/204CXCommentParamPassDirection_Out,205206/**207* The parameter is an input and output parameter.208*/209CXCommentParamPassDirection_InOut210};211212/**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);218219/**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);225226/**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_LINKAGE234CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);235236/**237* A \c CXComment_Paragraph node is considered whitespace if it contains238* only \c CXComment_Text nodes that are empty or whitespace.239*240* Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are241* never considered whitespace.242*243* \returns non-zero if \c Comment is whitespace.244*/245CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);246247/**248* \returns non-zero if \c Comment is inline content and has a newline249* immediately following it in the comment text. Newlines between paragraphs250* do not count.251*/252CINDEX_LINKAGE253unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);254255/**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);261262/**263* \param Comment a \c CXComment_InlineCommand AST node.264*265* \returns name of the inline command.266*/267CINDEX_LINKAGE268CXString clang_InlineCommandComment_getCommandName(CXComment Comment);269270/**271* \param Comment a \c CXComment_InlineCommand AST node.272*273* \returns the most appropriate rendering mode, chosen on command274* semantics in Doxygen.275*/276CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind277clang_InlineCommandComment_getRenderKind(CXComment Comment);278279/**280* \param Comment a \c CXComment_InlineCommand AST node.281*282* \returns number of command arguments.283*/284CINDEX_LINKAGE285unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);286287/**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_LINKAGE295CXString clang_InlineCommandComment_getArgText(CXComment Comment,296unsigned ArgIdx);297298/**299* \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST300* node.301*302* \returns HTML tag name.303*/304CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);305306/**307* \param Comment a \c CXComment_HTMLStartTag AST node.308*309* \returns non-zero if tag is self-closing (for example, <br />).310*/311CINDEX_LINKAGE312unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);313314/**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);320321/**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_LINKAGE329CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);330331/**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_LINKAGE339CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);340341/**342* \param Comment a \c CXComment_BlockCommand AST node.343*344* \returns name of the block command.345*/346CINDEX_LINKAGE347CXString clang_BlockCommandComment_getCommandName(CXComment Comment);348349/**350* \param Comment a \c CXComment_BlockCommand AST node.351*352* \returns number of word-like arguments.353*/354CINDEX_LINKAGE355unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);356357/**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_LINKAGE365CXString clang_BlockCommandComment_getArgText(CXComment Comment,366unsigned ArgIdx);367368/**369* \param Comment a \c CXComment_BlockCommand or370* \c CXComment_VerbatimBlockCommand AST node.371*372* \returns paragraph argument of the block command.373*/374CINDEX_LINKAGE375CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);376377/**378* \param Comment a \c CXComment_ParamCommand AST node.379*380* \returns parameter name.381*/382CINDEX_LINKAGE383CXString clang_ParamCommandComment_getParamName(CXComment Comment);384385/**386* \param Comment a \c CXComment_ParamCommand AST node.387*388* \returns non-zero if the parameter that this AST node represents was found389* in the function prototype and \c clang_ParamCommandComment_getParamIndex390* function will return a meaningful value.391*/392CINDEX_LINKAGE393unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);394395/**396* \param Comment a \c CXComment_ParamCommand AST node.397*398* \returns zero-based parameter index in function prototype.399*/400CINDEX_LINKAGE401unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);402403/**404* \param Comment a \c CXComment_ParamCommand AST node.405*406* \returns non-zero if parameter passing direction was specified explicitly in407* the comment.408*/409CINDEX_LINKAGE410unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);411412/**413* \param Comment a \c CXComment_ParamCommand AST node.414*415* \returns parameter passing direction.416*/417CINDEX_LINKAGE418enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(419CXComment Comment);420421/**422* \param Comment a \c CXComment_TParamCommand AST node.423*424* \returns template parameter name.425*/426CINDEX_LINKAGE427CXString clang_TParamCommandComment_getParamName(CXComment Comment);428429/**430* \param Comment a \c CXComment_TParamCommand AST node.431*432* \returns non-zero if the parameter that this AST node represents was found433* in the template parameter list and434* \c clang_TParamCommandComment_getDepth and435* \c clang_TParamCommandComment_getIndex functions will return a meaningful436* value.437*/438CINDEX_LINKAGE439unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);440441/**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* \verbatim448* template<typename C, template<typename T> class TT>449* void test(TT<int> aaa);450* \endverbatim451* for C and TT nesting depth is 0,452* for T nesting depth is 1.453*/454CINDEX_LINKAGE455unsigned clang_TParamCommandComment_getDepth(CXComment Comment);456457/**458* \param Comment a \c CXComment_TParamCommand AST node.459*460* \returns zero-based parameter index in the template parameter list at a461* given nesting depth.462*463* For example,464* \verbatim465* template<typename C, template<typename T> class TT>466* void test(TT<int> aaa);467* \endverbatim468* 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_LINKAGE476unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);477478/**479* \param Comment a \c CXComment_VerbatimBlockLine AST node.480*481* \returns text contained in the AST node.482*/483CINDEX_LINKAGE484CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);485486/**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);492493/**494* Convert an HTML tag AST node to string.495*496* \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST497* node.498*499* \returns string containing an HTML tag.500*/501CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);502503/**504* Convert a given full parsed comment to an HTML fragment.505*506* Specific details of HTML layout are subject to change. Don't try to parse507* this HTML back into an AST, use other APIs instead.508*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.513*514* Function argument documentation is rendered as a \<dl\> list with arguments515* 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 if519* parameter index is invalid.520*521* Template parameter documentation is rendered as a \<dl\> list with522* 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 for526* names inside template template parameters;527* \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if528* 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);535536/**537* Convert a given full parsed comment to an XML document.538*539* A Relax NG schema for the XML can be found in comment-xml-schema.rng file540* 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);547548/**549* CXAPISet is an opaque type that represents a data structure containing all550* the API information for a given translation unit. This can be used for a551* single symbol symbol graph for a given symbol.552*/553typedef struct CXAPISetImpl *CXAPISet;554555/**556* Traverses the translation unit to create a \c CXAPISet.557*558* \param tu is the \c CXTranslationUnit to build the \c CXAPISet for.559*560* \param out_api is a pointer to the output of this function. It is needs to be561* disposed of by calling clang_disposeAPISet.562*563* \returns Error code indicating success or failure of the APISet creation.564*/565CINDEX_LINKAGE enum CXErrorCode clang_createAPISet(CXTranslationUnit tu,566CXAPISet *out_api);567568/**569* Dispose of an APISet.570*571* The provided \c CXAPISet can not be used after this function is called.572*/573CINDEX_LINKAGE void clang_disposeAPISet(CXAPISet api);574575/**576* Generate a single symbol symbol graph for the given USR. Returns a null577* string if the associated symbol can not be found in the provided \c CXAPISet.578*579* The output contains the symbol graph as well as some additional information580* about related symbols.581*582* \param usr is a string containing the USR of the symbol to generate the583* symbol graph for.584*585* \param api the \c CXAPISet to look for the symbol in.586*587* \returns a string containing the serialized symbol graph representation for588* the symbol being queried or a null string if it can not be found in the589* APISet.590*/591CINDEX_LINKAGE CXString clang_getSymbolGraphForUSR(const char *usr,592CXAPISet api);593594/**595* Generate a single symbol symbol graph for the declaration at the given596* cursor. Returns a null string if the AST node for the cursor isn't a597* declaration.598*599* The output contains the symbol graph as well as some additional information600* about related symbols.601*602* \param cursor the declaration for which to generate the single symbol symbol603* graph.604*605* \returns a string containing the serialized symbol graph representation for606* the symbol being queried or a null string if it can not be found in the607* APISet.608*/609CINDEX_LINKAGE CXString clang_getSymbolGraphForCursor(CXCursor cursor);610611/**612* @}613*/614615LLVM_CLANG_C_EXTERN_C_END616617#endif /* CLANG_C_DOCUMENTATION_H */618619620621