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