-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcomment.go
371 lines (335 loc) · 11 KB
/
comment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package clang
// #include <stdlib.h>
// #include "go-clang.h"
//
import "C"
/**
* \brief A comment AST node.
*/
type Comment struct {
c C.CXComment
}
/**
* \param Comment AST node of any kind.
*
* \returns the type of the AST node.
*/
func (c Comment) Kind() CommentKind {
return CommentKind(C.clang_Comment_getKind(c.c))
}
/**
* \param Comment AST node of any kind.
*
* \returns number of children of the AST node.
*/
func (c Comment) NumChildren() int {
return int(C.clang_Comment_getNumChildren(c.c))
}
/**
* \param Comment AST node of any kind.
*
* \param ChildIdx child index (zero-based).
*
* \returns the specified child of the AST node.
*/
func (c Comment) Child(idx int) Comment {
return Comment{C.clang_Comment_getChild(c.c, C.unsigned(idx))}
}
/**
* \brief A \c CXComment_Paragraph node is considered whitespace if it contains
* only \c CXComment_Text nodes that are empty or whitespace.
*
* Other AST nodes (except \c CXComment_Paragraph and \c CXComment_Text) are
* never considered whitespace.
*
* \returns non-zero if \c Comment is whitespace.
*/
func (c Comment) IsWhitespace() bool {
o := C.clang_Comment_isWhitespace(c.c)
if o != 0 {
return true
}
return false
}
/**
* \returns non-zero if \c Comment is inline content and has a newline
* immediately following it in the comment text. Newlines between paragraphs
* do not count.
*/
func (c Comment) HasTrailingNewline() bool {
o := C.clang_InlineContentComment_hasTrailingNewline(c.c)
if 0 != o {
return true
}
return false
}
/**
* \param Comment a \c CXComment_Text AST node.
*
* \returns text contained in the AST node.
*/
func (c Comment) TextComment() string {
o := cxstring{C.clang_TextComment_getText(c.c)}
defer o.Dispose()
return o.String()
}
// TODO: implement more of Comment API
// /**
// * \param Comment a \c CXComment_InlineCommand AST node.
// *
// * \returns name of the inline command.
// */
// CINDEX_LINKAGE
// CXString clang_InlineCommandComment_getCommandName(CXComment Comment);
// /**
// * \param Comment a \c CXComment_InlineCommand AST node.
// *
// * \returns the most appropriate rendering mode, chosen on command
// * semantics in Doxygen.
// */
// CINDEX_LINKAGE enum CXCommentInlineCommandRenderKind
// clang_InlineCommandComment_getRenderKind(CXComment Comment);
// /**
// * \param Comment a \c CXComment_InlineCommand AST node.
// *
// * \returns number of command arguments.
// */
// CINDEX_LINKAGE
// unsigned clang_InlineCommandComment_getNumArgs(CXComment Comment);
// /**
// * \param Comment a \c CXComment_InlineCommand AST node.
// *
// * \param ArgIdx argument index (zero-based).
// *
// * \returns text of the specified argument.
// */
// CINDEX_LINKAGE
// CXString clang_InlineCommandComment_getArgText(CXComment Comment,
// unsigned ArgIdx);
// /**
// * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
// * node.
// *
// * \returns HTML tag name.
// */
// CINDEX_LINKAGE CXString clang_HTMLTagComment_getTagName(CXComment Comment);
// /**
// * \param Comment a \c CXComment_HTMLStartTag AST node.
// *
// * \returns non-zero if tag is self-closing (for example, <br />).
// */
// CINDEX_LINKAGE
// unsigned clang_HTMLStartTagComment_isSelfClosing(CXComment Comment);
// /**
// * \param Comment a \c CXComment_HTMLStartTag AST node.
// *
// * \returns number of attributes (name-value pairs) attached to the start tag.
// */
// CINDEX_LINKAGE unsigned clang_HTMLStartTag_getNumAttrs(CXComment Comment);
// /**
// * \param Comment a \c CXComment_HTMLStartTag AST node.
// *
// * \param AttrIdx attribute index (zero-based).
// *
// * \returns name of the specified attribute.
// */
// CINDEX_LINKAGE
// CXString clang_HTMLStartTag_getAttrName(CXComment Comment, unsigned AttrIdx);
// /**
// * \param Comment a \c CXComment_HTMLStartTag AST node.
// *
// * \param AttrIdx attribute index (zero-based).
// *
// * \returns value of the specified attribute.
// */
// CINDEX_LINKAGE
// CXString clang_HTMLStartTag_getAttrValue(CXComment Comment, unsigned AttrIdx);
// /**
// * \param Comment a \c CXComment_BlockCommand AST node.
// *
// * \returns name of the block command.
// */
// CINDEX_LINKAGE
// CXString clang_BlockCommandComment_getCommandName(CXComment Comment);
// /**
// * \param Comment a \c CXComment_BlockCommand AST node.
// *
// * \returns number of word-like arguments.
// */
// CINDEX_LINKAGE
// unsigned clang_BlockCommandComment_getNumArgs(CXComment Comment);
// /**
// * \param Comment a \c CXComment_BlockCommand AST node.
// *
// * \param ArgIdx argument index (zero-based).
// *
// * \returns text of the specified word-like argument.
// */
// CINDEX_LINKAGE
// CXString clang_BlockCommandComment_getArgText(CXComment Comment,
// unsigned ArgIdx);
// /**
// * \param Comment a \c CXComment_BlockCommand or
// * \c CXComment_VerbatimBlockCommand AST node.
// *
// * \returns paragraph argument of the block command.
// */
// CINDEX_LINKAGE
// CXComment clang_BlockCommandComment_getParagraph(CXComment Comment);
// /**
// * \param Comment a \c CXComment_ParamCommand AST node.
// *
// * \returns parameter name.
// */
// CINDEX_LINKAGE
// CXString clang_ParamCommandComment_getParamName(CXComment Comment);
// /**
// * \param Comment a \c CXComment_ParamCommand AST node.
// *
// * \returns non-zero if the parameter that this AST node represents was found
// * in the function prototype and \c clang_ParamCommandComment_getParamIndex
// * function will return a meaningful value.
// */
// CINDEX_LINKAGE
// unsigned clang_ParamCommandComment_isParamIndexValid(CXComment Comment);
// /**
// * \param Comment a \c CXComment_ParamCommand AST node.
// *
// * \returns zero-based parameter index in function prototype.
// */
// CINDEX_LINKAGE
// unsigned clang_ParamCommandComment_getParamIndex(CXComment Comment);
// /**
// * \param Comment a \c CXComment_ParamCommand AST node.
// *
// * \returns non-zero if parameter passing direction was specified explicitly in
// * the comment.
// */
// CINDEX_LINKAGE
// unsigned clang_ParamCommandComment_isDirectionExplicit(CXComment Comment);
// /**
// * \param Comment a \c CXComment_ParamCommand AST node.
// *
// * \returns parameter passing direction.
// */
// CINDEX_LINKAGE
// enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection(
// CXComment Comment);
// /**
// * \param Comment a \c CXComment_TParamCommand AST node.
// *
// * \returns template parameter name.
// */
// CINDEX_LINKAGE
// CXString clang_TParamCommandComment_getParamName(CXComment Comment);
// /**
// * \param Comment a \c CXComment_TParamCommand AST node.
// *
// * \returns non-zero if the parameter that this AST node represents was found
// * in the template parameter list and
// * \c clang_TParamCommandComment_getDepth and
// * \c clang_TParamCommandComment_getIndex functions will return a meaningful
// * value.
// */
// CINDEX_LINKAGE
// unsigned clang_TParamCommandComment_isParamPositionValid(CXComment Comment);
// /**
// * \param Comment a \c CXComment_TParamCommand AST node.
// *
// * \returns zero-based nesting depth of this parameter in the template parameter list.
// *
// * For example,
// * \verbatim
// * template<typename C, template<typename T> class TT>
// * void test(TT<int> aaa);
// * \endverbatim
// * for C and TT nesting depth is 0,
// * for T nesting depth is 1.
// */
// CINDEX_LINKAGE
// unsigned clang_TParamCommandComment_getDepth(CXComment Comment);
// /**
// * \param Comment a \c CXComment_TParamCommand AST node.
// *
// * \returns zero-based parameter index in the template parameter list at a
// * given nesting depth.
// *
// * For example,
// * \verbatim
// * template<typename C, template<typename T> class TT>
// * void test(TT<int> aaa);
// * \endverbatim
// * for C and TT nesting depth is 0, so we can ask for index at depth 0:
// * at depth 0 C's index is 0, TT's index is 1.
// *
// * For T nesting depth is 1, so we can ask for index at depth 0 and 1:
// * at depth 0 T's index is 1 (same as TT's),
// * at depth 1 T's index is 0.
// */
// CINDEX_LINKAGE
// unsigned clang_TParamCommandComment_getIndex(CXComment Comment, unsigned Depth);
// /**
// * \param Comment a \c CXComment_VerbatimBlockLine AST node.
// *
// * \returns text contained in the AST node.
// */
// CINDEX_LINKAGE
// CXString clang_VerbatimBlockLineComment_getText(CXComment Comment);
// /**
// * \param Comment a \c CXComment_VerbatimLine AST node.
// *
// * \returns text contained in the AST node.
// */
// CINDEX_LINKAGE CXString clang_VerbatimLineComment_getText(CXComment Comment);
// /**
// * \brief Convert an HTML tag AST node to string.
// *
// * \param Comment a \c CXComment_HTMLStartTag or \c CXComment_HTMLEndTag AST
// * node.
// *
// * \returns string containing an HTML tag.
// */
// CINDEX_LINKAGE CXString clang_HTMLTagComment_getAsString(CXComment Comment);
// /**
// * \brief Convert a given full parsed comment to an HTML fragment.
// *
// * Specific details of HTML layout are subject to change. Don't try to parse
// * this HTML back into an AST, use other APIs instead.
// *
// * Currently the following CSS classes are used:
// * \li "para-brief" for \\brief paragraph and equivalent commands;
// * \li "para-returns" for \\returns paragraph and equivalent commands;
// * \li "word-returns" for the "Returns" word in \\returns paragraph.
// *
// * Function argument documentation is rendered as a \<dl\> list with arguments
// * sorted in function prototype order. CSS classes used:
// * \li "param-name-index-NUMBER" for parameter name (\<dt\>);
// * \li "param-descr-index-NUMBER" for parameter description (\<dd\>);
// * \li "param-name-index-invalid" and "param-descr-index-invalid" are used if
// * parameter index is invalid.
// *
// * Template parameter documentation is rendered as a \<dl\> list with
// * parameters sorted in template parameter list order. CSS classes used:
// * \li "tparam-name-index-NUMBER" for parameter name (\<dt\>);
// * \li "tparam-descr-index-NUMBER" for parameter description (\<dd\>);
// * \li "tparam-name-index-other" and "tparam-descr-index-other" are used for
// * names inside template template parameters;
// * \li "tparam-name-index-invalid" and "tparam-descr-index-invalid" are used if
// * parameter position is invalid.
// *
// * \param Comment a \c CXComment_FullComment AST node.
// *
// * \returns string containing an HTML fragment.
// */
// CINDEX_LINKAGE CXString clang_FullComment_getAsHTML(CXComment Comment);
// /**
// * \brief Convert a given full parsed comment to an XML document.
// *
// * A Relax NG schema for the XML can be found in comment-xml-schema.rng file
// * inside clang source tree.
// *
// * \param Comment a \c CXComment_FullComment AST node.
// *
// * \returns string containing an XML document.
// */
// CINDEX_LINKAGE CXString clang_FullComment_getAsXML(CXComment Comment);