clang API Documentation

Documentation.h
Go to the documentation of this file.
00001 /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
00002 |*                                                                            *|
00003 |*                     The LLVM Compiler Infrastructure                       *|
00004 |*                                                                            *|
00005 |* This file is distributed under the University of Illinois Open Source      *|
00006 |* License. See LICENSE.TXT for details.                                      *|
00007 |*                                                                            *|
00008 |*===----------------------------------------------------------------------===*|
00009 |*                                                                            *|
00010 |* This header provides a supplementary interface for inspecting              *|
00011 |* documentation comments.                                                    *|
00012 |*                                                                            *|
00013 \*===----------------------------------------------------------------------===*/
00014 
00015 #ifndef LLVM_CLANG_C_DOCUMENTATION_H
00016 #define LLVM_CLANG_C_DOCUMENTATION_H
00017 
00018 #include "clang-c/Index.h"
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 /**
00025  * \defgroup CINDEX_COMMENT Comment introspection
00026  *
00027  * The routines in this group provide access to information in documentation
00028  * comments. These facilities are distinct from the core and may be subject to
00029  * their own schedule of stability and deprecation.
00030  *
00031  * @{
00032  */
00033 
00034 /**
00035  * \brief A parsed comment.
00036  */
00037 typedef struct {
00038   const void *ASTNode;
00039   CXTranslationUnit TranslationUnit;
00040 } CXComment;
00041 
00042 /**
00043  * \brief Given a cursor that represents a documentable entity (e.g.,
00044  * declaration), return the associated parsed comment as a
00045  * \c CXComment_FullComment AST node.
00046  */
00047 CINDEX_LINKAGE CXComment clang_Cursor_getParsedComment(CXCursor C);
00048 
00049 /**
00050  * \brief Describes the type of the comment AST node (\c CXComment).  A comment
00051  * node can be considered block content (e. g., paragraph), inline content
00052  * (plain text) or neither (the root AST node).
00053  */
00054 enum CXCommentKind {
00055   /**
00056    * \brief Null comment.  No AST node is constructed at the requested location
00057    * because there is no text or a syntax error.
00058    */
00059   CXComment_Null = 0,
00060 
00061   /**
00062    * \brief Plain text.  Inline content.
00063    */
00064   CXComment_Text = 1,
00065 
00066   /**
00067    * \brief A command with word-like arguments that is considered inline content.
00068    *
00069    * For example: \\c command.
00070    */
00071   CXComment_InlineCommand = 2,
00072 
00073   /**
00074    * \brief HTML start tag with attributes (name-value pairs).  Considered
00075    * inline content.
00076    *
00077    * For example:
00078    * \verbatim
00079    * <br> <br /> <a href="http://example.org/">
00080    * \endverbatim
00081    */
00082   CXComment_HTMLStartTag = 3,
00083 
00084   /**
00085    * \brief HTML end tag.  Considered inline content.
00086    *
00087    * For example:
00088    * \verbatim
00089    * </a>
00090    * \endverbatim
00091    */
00092   CXComment_HTMLEndTag = 4,
00093 
00094   /**
00095    * \brief A paragraph, contains inline comment.  The paragraph itself is
00096    * block content.
00097    */
00098   CXComment_Paragraph = 5,
00099 
00100   /**
00101    * \brief A command that has zero or more word-like arguments (number of
00102    * word-like arguments depends on command name) and a paragraph as an
00103    * argument.  Block command is block content.
00104    *
00105    * Paragraph argument is also a child of the block command.
00106    *
00107    * For example: \\brief has 0 word-like arguments and a paragraph argument.
00108    *
00109    * AST nodes of special kinds that parser knows about (e. g., \\param
00110    * command) have their own node kinds.
00111    */
00112   CXComment_BlockCommand = 6,
00113 
00114   /**
00115    * \brief A \\param or \\arg command that describes the function parameter
00116    * (name, passing direction, description).
00117    *
00118    * For example: \\param [in] ParamName description.
00119    */
00120   CXComment_ParamCommand = 7,
00121 
00122   /**
00123    * \brief A \\tparam command that describes a template parameter (name and
00124    * description).
00125    *
00126    * For example: \\tparam T description.
00127    */
00128   CXComment_TParamCommand = 8,
00129 
00130   /**
00131    * \brief A verbatim block command (e. g., preformatted code).  Verbatim
00132    * block has an opening and a closing command and contains multiple lines of
00133    * text (\c CXComment_VerbatimBlockLine child nodes).
00134    *
00135    * For example:
00136    * \\verbatim
00137    * aaa
00138    * \\endverbatim
00139    */
00140   CXComment_VerbatimBlockCommand = 9,
00141 
00142   /**
00143    * \brief A line of text that is contained within a
00144    * CXComment_VerbatimBlockCommand node.
00145    */
00146   CXComment_VerbatimBlockLine = 10,
00147 
00148   /**
00149    * \brief A verbatim line command.  Verbatim line has an opening command,
00150    * a single line of text (up to the newline after the opening command) and
00151    * has no closing command.
00152    */
00153   CXComment_VerbatimLine = 11,
00154 
00155   /**
00156    * \brief A full comment attached to a declaration, contains block content.
00157    */
00158   CXComment_FullComment = 12
00159 };
00160 
00161 /**
00162  * \brief The most appropriate rendering mode for an inline command, chosen on
00163  * command semantics in Doxygen.
00164  */
00165 enum CXCommentInlineCommandRenderKind {
00166   /**
00167    * \brief Command argument should be rendered in a normal font.
00168    */
00169   CXCommentInlineCommandRenderKind_Normal,
00170 
00171   /**
00172    * \brief Command argument should be rendered in a bold font.
00173    */
00174   CXCommentInlineCommandRenderKind_Bold,
00175 
00176   /**
00177    * \brief Command argument should be rendered in a monospaced font.
00178    */
00179   CXCommentInlineCommandRenderKind_Monospaced,
00180 
00181   /**
00182    * \brief Command argument should be rendered emphasized (typically italic
00183    * font).
00184    */
00185   CXCommentInlineCommandRenderKind_Emphasized
00186 };
00187 
00188 /**
00189  * \brief Describes parameter passing direction for \\param or \\arg command.
00190  */
00191 enum CXCommentParamPassDirection {
00192   /**
00193    * \brief The parameter is an input parameter.
00194    */
00195   CXCommentParamPassDirection_In,
00196 
00197   /**
00198    * \brief The parameter is an output parameter.
00199    */
00200   CXCommentParamPassDirection_Out,
00201 
00202   /**
00203    * \brief The parameter is an input and output parameter.
00204    */
00205   CXCommentParamPassDirection_InOut
00206 };
00207 
00208 /**
00209  * \param Comment AST node of any kind.
00210  *
00211  * \returns the type of the AST node.
00212  */
00213 CINDEX_LINKAGE enum CXCommentKind clang_Comment_getKind(CXComment Comment);
00214 
00215 /**
00216  * \param Comment AST node of any kind.
00217  *
00218  * \returns number of children of the AST node.
00219  */
00220 CINDEX_LINKAGE unsigned clang_Comment_getNumChildren(CXComment Comment);
00221 
00222 /**
00223  * \param Comment AST node of any kind.
00224  *
00225  * \param ChildIdx child index (zero-based).
00226  *
00227  * \returns the specified child of the AST node.
00228  */
00229 CINDEX_LINKAGE
00230 CXComment clang_Comment_getChild(CXComment Comment, unsigned ChildIdx);
00231 
00232 /**
00233  * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
00234  * only \c CXComment_Text nodes that are empty or whitespace.
00235  *
00236  * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
00237  * never considered whitespace.
00238  *
00239  * \returns non-zero if \c Comment is whitespace.
00240  */
00241 CINDEX_LINKAGE unsigned clang_Comment_isWhitespace(CXComment Comment);
00242 
00243 /**
00244  * \returns non-zero if \c Comment is inline content and has a newline
00245  * immediately following it in the comment text.  Newlines between paragraphs
00246  * do not count.
00247  */
00248 CINDEX_LINKAGE
00249 unsigned clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
00250 
00251 /**
00252  * \param Comment a \c CXComment_Text AST node.
00253  *
00254  * \returns text contained in the AST node.
00255  */
00256 CINDEX_LINKAGE CXString clang_TextComment_getText(CXComment Comment);
00257 
00258 /**
00259  * \param Comment a \c CXComment_InlineCommand AST node.
00260  *
00261  * \returns name of the inline command.
00262  */
00263 CINDEX_LINKAGE
00264 CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
00265 
00266 /**
00267  * \param Comment a \c CXComment_InlineCommand AST node.
00268  *
00269  * \returns the most appropriate rendering mode, chosen on command
00270  * semantics in Doxygen.
00271  */
00272 CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
00273 clang_InlineCommandComment_getRenderKind(CXComment Comment);
00274 
00275 /**
00276  * \param Comment a \c CXComment_InlineCommand AST node.
00277  *
00278  * \returns number of command arguments.
00279  */
00280 CINDEX_LINKAGE
00281 unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
00282 
00283 /**
00284  * \param Comment a \c CXComment_InlineCommand AST node.
00285  *
00286  * \param ArgIdx argument index (zero-based).
00287  *
00288  * \returns text of the specified argument.
00289  */
00290 CINDEX_LINKAGE
00291 CXString clang_InlineCommandComment_getArgText(CXComment Comment,
00292                                                unsigned ArgIdx);
00293 
00294 /**
00295  * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
00296  * node.
00297  *
00298  * \returns HTML tag name.
00299  */
00300 CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
00301 
00302 /**
00303  * \param Comment a \c CXComment_HTMLStartTag AST node.
00304  *
00305  * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
00306  */
00307 CINDEX_LINKAGE
00308 unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
00309 
00310 /**
00311  * \param Comment a \c CXComment_HTMLStartTag AST node.
00312  *
00313  * \returns number of attributes (name-value pairs) attached to the start tag.
00314  */
00315 CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
00316 
00317 /**
00318  * \param Comment a \c CXComment_HTMLStartTag AST node.
00319  *
00320  * \param AttrIdx attribute index (zero-based).
00321  *
00322  * \returns name of the specified attribute.
00323  */
00324 CINDEX_LINKAGE
00325 CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
00326 
00327 /**
00328  * \param Comment a \c CXComment_HTMLStartTag AST node.
00329  *
00330  * \param AttrIdx attribute index (zero-based).
00331  *
00332  * \returns value of the specified attribute.
00333  */
00334 CINDEX_LINKAGE
00335 CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
00336 
00337 /**
00338  * \param Comment a \c CXComment_BlockCommand AST node.
00339  *
00340  * \returns name of the block command.
00341  */
00342 CINDEX_LINKAGE
00343 CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
00344 
00345 /**
00346  * \param Comment a \c CXComment_BlockCommand AST node.
00347  *
00348  * \returns number of word-like arguments.
00349  */
00350 CINDEX_LINKAGE
00351 unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
00352 
00353 /**
00354  * \param Comment a \c CXComment_BlockCommand AST node.
00355  *
00356  * \param ArgIdx argument index (zero-based).
00357  *
00358  * \returns text of the specified word-like argument.
00359  */
00360 CINDEX_LINKAGE
00361 CXString clang_BlockCommandComment_getArgText(CXComment Comment,
00362                                               unsigned ArgIdx);
00363 
00364 /**
00365  * \param Comment a \c CXComment_BlockCommand or
00366  * \c CXComment_VerbatimBlockCommand AST node.
00367  *
00368  * \returns paragraph argument of the block command.
00369  */
00370 CINDEX_LINKAGE
00371 CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
00372 
00373 /**
00374  * \param Comment a \c CXComment_ParamCommand AST node.
00375  *
00376  * \returns parameter name.
00377  */
00378 CINDEX_LINKAGE
00379 CXString clang_ParamCommandComment_getParamName(CXComment Comment);
00380 
00381 /**
00382  * \param Comment a \c CXComment_ParamCommand AST node.
00383  *
00384  * \returns non-zero if the parameter that this AST node represents was found
00385  * in the function prototype and \c clang_ParamCommandComment_getParamIndex
00386  * function will return a meaningful value.
00387  */
00388 CINDEX_LINKAGE
00389 unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
00390 
00391 /**
00392  * \param Comment a \c CXComment_ParamCommand AST node.
00393  *
00394  * \returns zero-based parameter index in function prototype.
00395  */
00396 CINDEX_LINKAGE
00397 unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
00398 
00399 /**
00400  * \param Comment a \c CXComment_ParamCommand AST node.
00401  *
00402  * \returns non-zero if parameter passing direction was specified explicitly in
00403  * the comment.
00404  */
00405 CINDEX_LINKAGE
00406 unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
00407 
00408 /**
00409  * \param Comment a \c CXComment_ParamCommand AST node.
00410  *
00411  * \returns parameter passing direction.
00412  */
00413 CINDEX_LINKAGE
00414 enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
00415                                                             CXComment Comment);
00416 
00417 /**
00418  * \param Comment a \c CXComment_TParamCommand AST node.
00419  *
00420  * \returns template parameter name.
00421  */
00422 CINDEX_LINKAGE
00423 CXString clang_TParamCommandComment_getParamName(CXComment Comment);
00424 
00425 /**
00426  * \param Comment a \c CXComment_TParamCommand AST node.
00427  *
00428  * \returns non-zero if the parameter that this AST node represents was found
00429  * in the template parameter list and
00430  * \c clang_TParamCommandComment_getDepth and
00431  * \c clang_TParamCommandComment_getIndex functions will return a meaningful
00432  * value.
00433  */
00434 CINDEX_LINKAGE
00435 unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
00436 
00437 /**
00438  * \param Comment a \c CXComment_TParamCommand AST node.
00439  *
00440  * \returns zero-based nesting depth of this parameter in the template parameter list.
00441  *
00442  * For example,
00443  * \verbatim
00444  *     template<typename C, template<typename T> class TT>
00445  *     void test(TT<int> aaa);
00446  * \endverbatim
00447  * for C and TT nesting depth is 0,
00448  * for T nesting depth is 1.
00449  */
00450 CINDEX_LINKAGE
00451 unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
00452 
00453 /**
00454  * \param Comment a \c CXComment_TParamCommand AST node.
00455  *
00456  * \returns zero-based parameter index in the template parameter list at a
00457  * given nesting depth.
00458  *
00459  * For example,
00460  * \verbatim
00461  *     template<typename C, template<typename T> class TT>
00462  *     void test(TT<int> aaa);
00463  * \endverbatim
00464  * for C and TT nesting depth is 0, so we can ask for index at depth 0:
00465  * at depth 0 C's index is 0, TT's index is 1.
00466  *
00467  * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
00468  * at depth 0 T's index is 1 (same as TT's),
00469  * at depth 1 T's index is 0.
00470  */
00471 CINDEX_LINKAGE
00472 unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
00473 
00474 /**
00475  * \param Comment a \c CXComment_VerbatimBlockLine AST node.
00476  *
00477  * \returns text contained in the AST node.
00478  */
00479 CINDEX_LINKAGE
00480 CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
00481 
00482 /**
00483  * \param Comment a \c CXComment_VerbatimLine AST node.
00484  *
00485  * \returns text contained in the AST node.
00486  */
00487 CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
00488 
00489 /**
00490  * \brief Convert an HTML tag AST node to string.
00491  *
00492  * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
00493  * node.
00494  *
00495  * \returns string containing an HTML tag.
00496  */
00497 CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
00498 
00499 /**
00500  * \brief Convert a given full parsed comment to an HTML fragment.
00501  *
00502  * Specific details of HTML layout are subject to change.  Don't try to parse
00503  * this HTML back into an AST, use other APIs instead.
00504  *
00505  * Currently the following CSS classes are used:
00506  * \li "para-brief" for \\brief paragraph and equivalent commands;
00507  * \li "para-returns" for \\returns paragraph and equivalent commands;
00508  * \li "word-returns" for the "Returns" word in \\returns paragraph.
00509  *
00510  * Function argument documentation is rendered as a <dl> list with arguments
00511  * sorted in function prototype order.  CSS classes used:
00512  * \li "param-name-index-NUMBER" for parameter name (<dt>);
00513  * \li "param-descr-index-NUMBER" for parameter description (<dd>);
00514  * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
00515  * parameter index is invalid.
00516  *
00517  * Template parameter documentation is rendered as a <dl> list with
00518  * parameters sorted in template parameter list order.  CSS classes used:
00519  * \li "tparam-name-index-NUMBER" for parameter name (<dt>);
00520  * \li "tparam-descr-index-NUMBER" for parameter description (<dd>);
00521  * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
00522  * names inside template template parameters;
00523  * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
00524  * parameter position is invalid.
00525  *
00526  * \param Comment a \c CXComment_FullComment AST node.
00527  *
00528  * \returns string containing an HTML fragment.
00529  */
00530 CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
00531 
00532 /**
00533  * \brief Convert a given full parsed comment to an XML document.
00534  *
00535  * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
00536  * inside clang source tree.
00537  *
00538  * \param Comment a \c CXComment_FullComment AST node.
00539  *
00540  * \returns string containing an XML document.
00541  */
00542 CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);
00543 
00544 /**
00545  * @}
00546  */
00547 
00548 
00549 #ifdef __cplusplus
00550 }
00551 #endif
00552 
00553 #endif /* CLANG_C_DOCUMENTATION_H */
00554