1 /*==-- clang-c/Documentation.h - Utilities for comment processing -*- C -*-===*\
2 |*                                                                            *|
3 |*                     The LLVM Compiler Infrastructure                       *|
4 |*                                                                            *|
5 |* This file is distributed under the University of Illinois Open Source      *|
6 |* License. See LICENSE.TXT for details.                                      *|
7 |*                                                                            *|
8 |*===----------------------------------------------------------------------===*|
9 |*                                                                            *|
10 |* This header provides a supplementary interface for inspecting              *|
11 |* documentation comments.                                                    *|
12 |*                                                                            *|
13 \*===----------------------------------------------------------------------===*/
14 
15 module clang.c.Documentation;
16 
17 public import clang.c.CXString;
18 public import clang.c.Index;
19 
20 extern (C):
21 
22 /**
23  * \defgroup CINDEX_COMMENT Comment introspection
24  *
25  * The routines in this group provide access to information in documentation
26  * comments. These facilities are distinct from the core and may be subject to
27  * their own schedule of stability and deprecation.
28  *
29  * @{
30  */
31 
32 /**
33  * \brief A parsed comment.
34  */
35 struct CXComment
36 {
37     const(void)* ASTNode;
38     CXTranslationUnit TranslationUnit;
39 }
40 
41 /**
42  * \brief 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.
45  */
46 CXComment clang_Cursor_getParsedComment(CXCursor C);
47 
48 /**
49  * \brief 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).
52  */
53 enum CXCommentKind
54 {
55     /**
56      * \brief Null comment.  No AST node is constructed at the requested location
57      * because there is no text or a syntax error.
58      */
59     null_ = 0,
60 
61     /**
62      * \brief Plain text.  Inline content.
63      */
64     text = 1,
65 
66     /**
67      * \brief A command with word-like arguments that is considered inline content.
68      *
69      * For example: \\c command.
70      */
71     inlineCommand = 2,
72 
73     /**
74      * \brief HTML start tag with attributes (name-value pairs).  Considered
75      * inline content.
76      *
77      * For example:
78      * \verbatim
79      * <br> <br /> <a href="http://example.org/">
80      * \endverbatim
81      */
82     htmlStartTag = 3,
83 
84     /**
85      * \brief HTML end tag.  Considered inline content.
86      *
87      * For example:
88      * \verbatim
89      * </a>
90      * \endverbatim
91      */
92     htmlEndTag = 4,
93 
94     /**
95      * \brief A paragraph, contains inline comment.  The paragraph itself is
96      * block content.
97      */
98     paragraph = 5,
99 
100     /**
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.
104      *
105      * Paragraph argument is also a child of the block command.
106      *
107      * For example: \\brief has 0 word-like arguments and a paragraph argument.
108      *
109      * AST nodes of special kinds that parser knows about (e. g., \\param
110      * command) have their own node kinds.
111      */
112     blockCommand = 6,
113 
114     /**
115      * \brief A \\param or \\arg command that describes the function parameter
116      * (name, passing direction, description).
117      *
118      * For example: \\param [in] ParamName description.
119      */
120     paramCommand = 7,
121 
122     /**
123      * \brief A \\tparam command that describes a template parameter (name and
124      * description).
125      *
126      * For example: \\tparam T description.
127      */
128     tParamCommand = 8,
129 
130     /**
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).
134      *
135      * For example:
136      * \\verbatim
137      * aaa
138      * \\endverbatim
139      */
140     verbatimBlockCommand = 9,
141 
142     /**
143      * \brief A line of text that is contained within a
144      * CXComment_VerbatimBlockCommand node.
145      */
146     verbatimBlockLine = 10,
147 
148     /**
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.
152      */
153     verbatimLine = 11,
154 
155     /**
156      * \brief A full comment attached to a declaration, contains block content.
157      */
158     fullComment = 12
159 }
160 
161 /**
162  * \brief The most appropriate rendering mode for an inline command, chosen on
163  * command semantics in Doxygen.
164  */
165 enum CXCommentInlineCommandRenderKind
166 {
167     /**
168      * \brief Command argument should be rendered in a normal font.
169      */
170     normal = 0,
171 
172     /**
173      * \brief Command argument should be rendered in a bold font.
174      */
175     bold = 1,
176 
177     /**
178      * \brief Command argument should be rendered in a monospaced font.
179      */
180     monospaced = 2,
181 
182     /**
183      * \brief Command argument should be rendered emphasized (typically italic
184      * font).
185      */
186     emphasized = 3
187 }
188 
189 /**
190  * \brief Describes parameter passing direction for \\param or \\arg command.
191  */
192 enum CXCommentParamPassDirection
193 {
194     /**
195      * \brief The parameter is an input parameter.
196      */
197     in_ = 0,
198 
199     /**
200      * \brief The parameter is an output parameter.
201      */
202     out_ = 1,
203 
204     /**
205      * \brief The parameter is an input and output parameter.
206      */
207     inOut = 2
208 }
209 
210 /**
211  * \param Comment AST node of any kind.
212  *
213  * \returns the type of the AST node.
214  */
215 CXCommentKind clang_Comment_getKind(CXComment Comment);
216 
217 /**
218  * \param Comment AST node of any kind.
219  *
220  * \returns number of children of the AST node.
221  */
222 uint clang_Comment_getNumChildren(CXComment Comment);
223 
224 /**
225  * \param Comment AST node of any kind.
226  *
227  * \param ChildIdx child index (zero-based).
228  *
229  * \returns the specified child of the AST node.
230  */
231 CXComment clang_Comment_getChild(CXComment Comment, uint ChildIdx);
232 
233 /**
234  * \brief A \c CXComment_Paragraph node is considered whitespace if it contains
235  * only \c CXComment_Text nodes that are empty or whitespace.
236  *
237  * Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
238  * never considered whitespace.
239  *
240  * \returns non-zero if \c Comment is whitespace.
241  */
242 uint clang_Comment_isWhitespace(CXComment Comment);
243 
244 /**
245  * \returns non-zero if \c Comment is inline content and has a newline
246  * immediately following it in the comment text.  Newlines between paragraphs
247  * do not count.
248  */
249 uint clang_InlineContentComment_hasTrailingNewline(CXComment Comment);
250 
251 /**
252  * \param Comment a \c CXComment_Text AST node.
253  *
254  * \returns text contained in the AST node.
255  */
256 CXString clang_TextComment_getText(CXComment Comment);
257 
258 /**
259  * \param Comment a \c CXComment_InlineCommand AST node.
260  *
261  * \returns name of the inline command.
262  */
263 CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
264 
265 /**
266  * \param Comment a \c CXComment_InlineCommand AST node.
267  *
268  * \returns the most appropriate rendering mode, chosen on command
269  * semantics in Doxygen.
270  */
271 CXCommentInlineCommandRenderKind clang_InlineCommandComment_getRenderKind(
272     CXComment Comment);
273 
274 /**
275  * \param Comment a \c CXComment_InlineCommand AST node.
276  *
277  * \returns number of command arguments.
278  */
279 uint clang_InlineCommandComment_getNumArgs(CXComment Comment);
280 
281 /**
282  * \param Comment a \c CXComment_InlineCommand AST node.
283  *
284  * \param ArgIdx argument index (zero-based).
285  *
286  * \returns text of the specified argument.
287  */
288 CXString clang_InlineCommandComment_getArgText(CXComment Comment, uint ArgIdx);
289 
290 /**
291  * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
292  * node.
293  *
294  * \returns HTML tag name.
295  */
296 CXString clang_HTMLTagComment_getTagName(CXComment Comment);
297 
298 /**
299  * \param Comment a \c CXComment_HTMLStartTag AST node.
300  *
301  * \returns non-zero if tag is self-closing (for example, &lt;br /&gt;).
302  */
303 uint clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
304 
305 /**
306  * \param Comment a \c CXComment_HTMLStartTag AST node.
307  *
308  * \returns number of attributes (name-value pairs) attached to the start tag.
309  */
310 uint clang_HTMLStartTag_getNumAttrs(CXComment Comment);
311 
312 /**
313  * \param Comment a \c CXComment_HTMLStartTag AST node.
314  *
315  * \param AttrIdx attribute index (zero-based).
316  *
317  * \returns name of the specified attribute.
318  */
319 CXString clang_HTMLStartTag_getAttrName(CXComment Comment, uint AttrIdx);
320 
321 /**
322  * \param Comment a \c CXComment_HTMLStartTag AST node.
323  *
324  * \param AttrIdx attribute index (zero-based).
325  *
326  * \returns value of the specified attribute.
327  */
328 CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, uint AttrIdx);
329 
330 /**
331  * \param Comment a \c CXComment_BlockCommand AST node.
332  *
333  * \returns name of the block command.
334  */
335 CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
336 
337 /**
338  * \param Comment a \c CXComment_BlockCommand AST node.
339  *
340  * \returns number of word-like arguments.
341  */
342 uint clang_BlockCommandComment_getNumArgs(CXComment Comment);
343 
344 /**
345  * \param Comment a \c CXComment_BlockCommand AST node.
346  *
347  * \param ArgIdx argument index (zero-based).
348  *
349  * \returns text of the specified word-like argument.
350  */
351 CXString clang_BlockCommandComment_getArgText(CXComment Comment, uint ArgIdx);
352 
353 /**
354  * \param Comment a \c CXComment_BlockCommand or
355  * \c CXComment_VerbatimBlockCommand AST node.
356  *
357  * \returns paragraph argument of the block command.
358  */
359 CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
360 
361 /**
362  * \param Comment a \c CXComment_ParamCommand AST node.
363  *
364  * \returns parameter name.
365  */
366 CXString clang_ParamCommandComment_getParamName(CXComment Comment);
367 
368 /**
369  * \param Comment a \c CXComment_ParamCommand AST node.
370  *
371  * \returns non-zero if the parameter that this AST node represents was found
372  * in the function prototype and \c clang_ParamCommandComment_getParamIndex
373  * function will return a meaningful value.
374  */
375 uint clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
376 
377 /**
378  * \param Comment a \c CXComment_ParamCommand AST node.
379  *
380  * \returns zero-based parameter index in function prototype.
381  */
382 uint clang_ParamCommandComment_getParamIndex(CXComment Comment);
383 
384 /**
385  * \param Comment a \c CXComment_ParamCommand AST node.
386  *
387  * \returns non-zero if parameter passing direction was specified explicitly in
388  * the comment.
389  */
390 uint clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
391 
392 /**
393  * \param Comment a \c CXComment_ParamCommand AST node.
394  *
395  * \returns parameter passing direction.
396  */
397 CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
398     CXComment Comment);
399 
400 /**
401  * \param Comment a \c CXComment_TParamCommand AST node.
402  *
403  * \returns template parameter name.
404  */
405 CXString clang_TParamCommandComment_getParamName(CXComment Comment);
406 
407 /**
408  * \param Comment a \c CXComment_TParamCommand AST node.
409  *
410  * \returns non-zero if the parameter that this AST node represents was found
411  * in the template parameter list and
412  * \c clang_TParamCommandComment_getDepth and
413  * \c clang_TParamCommandComment_getIndex functions will return a meaningful
414  * value.
415  */
416 uint clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
417 
418 /**
419  * \param Comment a \c CXComment_TParamCommand AST node.
420  *
421  * \returns zero-based nesting depth of this parameter in the template parameter list.
422  *
423  * For example,
424  * \verbatim
425  *     template<typename C, template<typename T> class TT>
426  *     void test(TT<int> aaa);
427  * \endverbatim
428  * for C and TT nesting depth is 0,
429  * for T nesting depth is 1.
430  */
431 uint clang_TParamCommandComment_getDepth(CXComment Comment);
432 
433 /**
434  * \param Comment a \c CXComment_TParamCommand AST node.
435  *
436  * \returns zero-based parameter index in the template parameter list at a
437  * given nesting depth.
438  *
439  * For example,
440  * \verbatim
441  *     template<typename C, template<typename T> class TT>
442  *     void test(TT<int> aaa);
443  * \endverbatim
444  * for C and TT nesting depth is 0, so we can ask for index at depth 0:
445  * at depth 0 C's index is 0, TT's index is 1.
446  *
447  * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
448  * at depth 0 T's index is 1 (same as TT's),
449  * at depth 1 T's index is 0.
450  */
451 uint clang_TParamCommandComment_getIndex(CXComment Comment, uint Depth);
452 
453 /**
454  * \param Comment a \c CXComment_VerbatimBlockLine AST node.
455  *
456  * \returns text contained in the AST node.
457  */
458 CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
459 
460 /**
461  * \param Comment a \c CXComment_VerbatimLine AST node.
462  *
463  * \returns text contained in the AST node.
464  */
465 CXString clang_VerbatimLineComment_getText(CXComment Comment);
466 
467 /**
468  * \brief Convert an HTML tag AST node to string.
469  *
470  * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
471  * node.
472  *
473  * \returns string containing an HTML tag.
474  */
475 CXString clang_HTMLTagComment_getAsString(CXComment Comment);
476 
477 /**
478  * \brief Convert a given full parsed comment to an HTML fragment.
479  *
480  * Specific details of HTML layout are subject to change.  Don't try to parse
481  * this HTML back into an AST, use other APIs instead.
482  *
483  * Currently the following CSS classes are used:
484  * \li "para-brief" for \\brief paragraph and equivalent commands;
485  * \li "para-returns" for \\returns paragraph and equivalent commands;
486  * \li "word-returns" for the "Returns" word in \\returns paragraph.
487  *
488  * Function argument documentation is rendered as a \<dl\> list with arguments
489  * sorted in function prototype order.  CSS classes used:
490  * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
491  * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
492  * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
493  * parameter index is invalid.
494  *
495  * Template parameter documentation is rendered as a \<dl\> list with
496  * parameters sorted in template parameter list order.  CSS classes used:
497  * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
498  * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
499  * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
500  * names inside template template parameters;
501  * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
502  * parameter position is invalid.
503  *
504  * \param Comment a \c CXComment_FullComment AST node.
505  *
506  * \returns string containing an HTML fragment.
507  */
508 CXString clang_FullComment_getAsHTML(CXComment Comment);
509 
510 /**
511  * \brief Convert a given full parsed comment to an XML document.
512  *
513  * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
514  * inside clang source tree.
515  *
516  * \param Comment a \c CXComment_FullComment AST node.
517  *
518  * \returns string containing an XML document.
519  */
520 CXString clang_FullComment_getAsXML(CXComment Comment);
521 
522 /**
523  * @}
524  */
525 
526 /* CLANG_C_DOCUMENTATION_H */