1 /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
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/Index.h"
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.
35 * \brief A parsed comment.
39 CXTranslationUnit TranslationUnit
;
43 * \brief 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
);
50 * \brief 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).
56 * \brief Null comment. No AST node is constructed at the requested location
57 * because there is no text or a syntax error.
62 * \brief Plain text. Inline content.
67 * \brief A command with word-like arguments that is considered inline content.
69 * For example: \\c command.
71 CXComment_InlineCommand
= 2,
74 * \brief HTML start tag with attributes (name-value pairs). Considered
79 * <br> <br /> <a href="http://example.org/">
82 CXComment_HTMLStartTag
= 3,
85 * \brief HTML end tag. Considered inline content.
92 CXComment_HTMLEndTag
= 4,
95 * \brief A paragraph, contains inline comment. The paragraph itself is
98 CXComment_Paragraph
= 5,
101 * \brief 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: \\brief 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 * \brief 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 * \brief A \\tparam command that describes a template parameter (name and
126 * For example: \\tparam T description.
128 CXComment_TParamCommand
= 8,
131 * \brief 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).
140 CXComment_VerbatimBlockCommand
= 9,
143 * \brief A line of text that is contained within a
144 * CXComment_VerbatimBlockCommand node.
146 CXComment_VerbatimBlockLine
= 10,
149 * \brief 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 * \brief A full comment attached to a declaration, contains block content.
158 CXComment_FullComment
= 12
162 * \brief The most appropriate rendering mode for an inline command, chosen on
163 * command semantics in Doxygen.
165 enum CXCommentInlineCommandRenderKind
{
167 * \brief Command argument should be rendered in a normal font.
169 CXCommentInlineCommandRenderKind_Normal
,
172 * \brief Command argument should be rendered in a bold font.
174 CXCommentInlineCommandRenderKind_Bold
,
177 * \brief Command argument should be rendered in a monospaced font.
179 CXCommentInlineCommandRenderKind_Monospaced
,
182 * \brief Command argument should be rendered emphasized (typically italic
185 CXCommentInlineCommandRenderKind_Emphasized
189 * \brief Describes parameter passing direction for \\param or \\arg command.
191 enum CXCommentParamPassDirection
{
193 * \brief The parameter is an input parameter.
195 CXCommentParamPassDirection_In
,
198 * \brief The parameter is an output parameter.
200 CXCommentParamPassDirection_Out
,
203 * \brief The parameter is an input and output parameter.
205 CXCommentParamPassDirection_InOut
209 * \param Comment AST node of any kind.
211 * \returns the type of the AST node.
213 CINDEX_LINKAGE
enum CXCommentKind
clang_Comment_getKind(CXComment Comment
);
216 * \param Comment AST node of any kind.
218 * \returns number of children of the AST node.
220 CINDEX_LINKAGE
unsigned clang_Comment_getNumChildren(CXComment Comment
);
223 * \param Comment AST node of any kind.
225 * \param ChildIdx child index (zero-based).
227 * \returns the specified child of the AST node.
230 CXComment
clang_Comment_getChild(CXComment Comment
, unsigned ChildIdx
);
233 * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
234 * only \c CXComment_Text nodes that are empty or whitespace.
236 * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
237 * never considered whitespace.
239 * \returns non-zero if \c Comment is whitespace.
241 CINDEX_LINKAGE
unsigned clang_Comment_isWhitespace(CXComment Comment
);
244 * \returns non-zero if \c Comment is inline content and has a newline
245 * immediately following it in the comment text. Newlines between paragraphs
249 unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment
);
252 * \param Comment a \c CXComment_Text AST node.
254 * \returns text contained in the AST node.
256 CINDEX_LINKAGE CXString
clang_TextComment_getText(CXComment Comment
);
259 * \param Comment a \c CXComment_InlineCommand AST node.
261 * \returns name of the inline command.
264 CXString
clang_InlineCommandComment_getCommandName(CXComment Comment
);
267 * \param Comment a \c CXComment_InlineCommand AST node.
269 * \returns the most appropriate rendering mode, chosen on command
270 * semantics in Doxygen.
272 CINDEX_LINKAGE
enum CXCommentInlineCommandRenderKind
273 clang_InlineCommandComment_getRenderKind(CXComment Comment
);
276 * \param Comment a \c CXComment_InlineCommand AST node.
278 * \returns number of command arguments.
281 unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment
);
284 * \param Comment a \c CXComment_InlineCommand AST node.
286 * \param ArgIdx argument index (zero-based).
288 * \returns text of the specified argument.
291 CXString
clang_InlineCommandComment_getArgText(CXComment Comment
,
295 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
298 * \returns HTML tag name.
300 CINDEX_LINKAGE CXString
clang_HTMLTagComment_getTagName(CXComment Comment
);
303 * \param Comment a \c CXComment_HTMLStartTag AST node.
305 * \returns non-zero if tag is self-closing (for example, <br />).
308 unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment
);
311 * \param Comment a \c CXComment_HTMLStartTag AST node.
313 * \returns number of attributes (name-value pairs) attached to the start tag.
315 CINDEX_LINKAGE
unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment
);
318 * \param Comment a \c CXComment_HTMLStartTag AST node.
320 * \param AttrIdx attribute index (zero-based).
322 * \returns name of the specified attribute.
325 CXString
clang_HTMLStartTag_getAttrName(CXComment Comment
, unsigned AttrIdx
);
328 * \param Comment a \c CXComment_HTMLStartTag AST node.
330 * \param AttrIdx attribute index (zero-based).
332 * \returns value of the specified attribute.
335 CXString
clang_HTMLStartTag_getAttrValue(CXComment Comment
, unsigned AttrIdx
);
338 * \param Comment a \c CXComment_BlockCommand AST node.
340 * \returns name of the block command.
343 CXString
clang_BlockCommandComment_getCommandName(CXComment Comment
);
346 * \param Comment a \c CXComment_BlockCommand AST node.
348 * \returns number of word-like arguments.
351 unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment
);
354 * \param Comment a \c CXComment_BlockCommand AST node.
356 * \param ArgIdx argument index (zero-based).
358 * \returns text of the specified word-like argument.
361 CXString
clang_BlockCommandComment_getArgText(CXComment Comment
,
365 * \param Comment a \c CXComment_BlockCommand or
366 * \c CXComment_VerbatimBlockCommand AST node.
368 * \returns paragraph argument of the block command.
371 CXComment
clang_BlockCommandComment_getParagraph(CXComment Comment
);
374 * \param Comment a \c CXComment_ParamCommand AST node.
376 * \returns parameter name.
379 CXString
clang_ParamCommandComment_getParamName(CXComment Comment
);
382 * \param Comment a \c CXComment_ParamCommand AST node.
384 * \returns non-zero if the parameter that this AST node represents was found
385 * in the function prototype and \c clang_ParamCommandComment_getParamIndex
386 * function will return a meaningful value.
389 unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment
);
392 * \param Comment a \c CXComment_ParamCommand AST node.
394 * \returns zero-based parameter index in function prototype.
397 unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment
);
400 * \param Comment a \c CXComment_ParamCommand AST node.
402 * \returns non-zero if parameter passing direction was specified explicitly in
406 unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment
);
409 * \param Comment a \c CXComment_ParamCommand AST node.
411 * \returns parameter passing direction.
414 enum CXCommentParamPassDirection
clang_ParamCommandComment_getDirection(
418 * \param Comment a \c CXComment_TParamCommand AST node.
420 * \returns template parameter name.
423 CXString
clang_TParamCommandComment_getParamName(CXComment Comment
);
426 * \param Comment a \c CXComment_TParamCommand AST node.
428 * \returns non-zero if the parameter that this AST node represents was found
429 * in the template parameter list and
430 * \c clang_TParamCommandComment_getDepth and
431 * \c clang_TParamCommandComment_getIndex functions will return a meaningful
435 unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment
);
438 * \param Comment a \c CXComment_TParamCommand AST node.
440 * \returns zero-based nesting depth of this parameter in the template parameter list.
444 * template<typename C, template<typename T> class TT>
445 * void test(TT<int> aaa);
447 * for C and TT nesting depth is 0,
448 * for T nesting depth is 1.
451 unsigned clang_TParamCommandComment_getDepth(CXComment Comment
);
454 * \param Comment a \c CXComment_TParamCommand AST node.
456 * \returns zero-based parameter index in the template parameter list at a
457 * given nesting depth.
461 * template<typename C, template<typename T> class TT>
462 * void test(TT<int> aaa);
464 * for C and TT nesting depth is 0, so we can ask for index at depth 0:
465 * at depth 0 C's index is 0, TT's index is 1.
467 * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
468 * at depth 0 T's index is 1 (same as TT's),
469 * at depth 1 T's index is 0.
472 unsigned clang_TParamCommandComment_getIndex(CXComment Comment
, unsigned Depth
);
475 * \param Comment a \c CXComment_VerbatimBlockLine AST node.
477 * \returns text contained in the AST node.
480 CXString
clang_VerbatimBlockLineComment_getText(CXComment Comment
);
483 * \param Comment a \c CXComment_VerbatimLine AST node.
485 * \returns text contained in the AST node.
487 CINDEX_LINKAGE CXString
clang_VerbatimLineComment_getText(CXComment Comment
);
490 * \brief Convert an HTML tag AST node to string.
492 * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
495 * \returns string containing an HTML tag.
497 CINDEX_LINKAGE CXString
clang_HTMLTagComment_getAsString(CXComment Comment
);
500 * \brief Convert a given full parsed comment to an HTML fragment.
502 * Specific details of HTML layout are subject to change. Don't try to parse
503 * this HTML back into an AST, use other APIs instead.
505 * Currently the following CSS classes are used:
506 * \li "para-brief" for \\brief paragraph and equivalent commands;
507 * \li "para-returns" for \\returns paragraph and equivalent commands;
508 * \li "word-returns" for the "Returns" word in \\returns paragraph.
510 * Function argument documentation is rendered as a \<dl\> list with arguments
511 * sorted in function prototype order. CSS classes used:
512 * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
513 * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
514 * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
515 * parameter index is invalid.
517 * Template parameter documentation is rendered as a \<dl\> list with
518 * parameters sorted in template parameter list order. CSS classes used:
519 * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
520 * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
521 * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
522 * names inside template template parameters;
523 * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
524 * parameter position is invalid.
526 * \param Comment a \c CXComment_FullComment AST node.
528 * \returns string containing an HTML fragment.
530 CINDEX_LINKAGE CXString
clang_FullComment_getAsHTML(CXComment Comment
);
533 * \brief Convert a given full parsed comment to an XML document.
535 * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
536 * inside clang source tree.
538 * \param Comment a \c CXComment_FullComment AST node.
540 * \returns string containing an XML document.
542 CINDEX_LINKAGE CXString
clang_FullComment_getAsXML(CXComment Comment
);
553 #endif /* CLANG_C_DOCUMENTATION_H */