clangc 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clangc/_clangc_functions.c +303 -0
  3. data/ext/clangc/_clangc_functions.h +51 -0
  4. data/ext/clangc/clangc.c +376 -0
  5. data/ext/clangc/class_CodeCompleteResults.c +186 -0
  6. data/ext/clangc/class_CodeCompleteResults.h +51 -0
  7. data/ext/clangc/class_CompletionResult.c +98 -0
  8. data/ext/clangc/class_CompletionResult.h +36 -0
  9. data/ext/clangc/class_CompletionString.c +231 -0
  10. data/ext/clangc/class_CompletionString.h +57 -0
  11. data/ext/clangc/class_Cursor.c +1677 -0
  12. data/ext/clangc/class_Cursor.h +259 -0
  13. data/ext/clangc/class_CursorSet.c +109 -0
  14. data/ext/clangc/class_CursorSet.h +39 -0
  15. data/ext/clangc/class_Diagnostic.c +322 -0
  16. data/ext/clangc/class_Diagnostic.h +66 -0
  17. data/ext/clangc/class_File.c +145 -0
  18. data/ext/clangc/class_File.h +45 -0
  19. data/ext/clangc/class_Index.c +461 -0
  20. data/ext/clangc/class_Index.h +58 -0
  21. data/ext/clangc/class_Module.c +181 -0
  22. data/ext/clangc/class_Module.h +51 -0
  23. data/ext/clangc/class_OverriddenCursor.c +51 -0
  24. data/ext/clangc/class_OverriddenCursor.h +31 -0
  25. data/ext/clangc/class_SourceLocation.c +197 -0
  26. data/ext/clangc/class_SourceLocation.h +45 -0
  27. data/ext/clangc/class_SourceRange.c +123 -0
  28. data/ext/clangc/class_SourceRange.h +42 -0
  29. data/ext/clangc/class_TranslationUnit.c +457 -0
  30. data/ext/clangc/class_TranslationUnit.h +63 -0
  31. data/ext/clangc/class_Type.c +564 -0
  32. data/ext/clangc/class_Type.h +108 -0
  33. data/ext/clangc/constants.c +660 -0
  34. data/ext/clangc/constants.h +21 -0
  35. data/ext/clangc/extconf.rb +34 -0
  36. data/ext/clangc/macros.h +230 -0
  37. data/lib/clangc.rb +397 -0
  38. metadata +95 -0
@@ -0,0 +1,57 @@
1
+ /*
2
+ * ruby-clangc ruby bindings for the C interface of Clang
3
+ * Copyright (C) 2015-2016 Cedric Le Moigne cedlemo <cedlemo@gmx.com>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ #ifndef COMPLETIONSTRING_H
19
+ #define COMPLETIONSTRING_H
20
+ #include <ruby/ruby.h>
21
+ #include "clang-c/Index.h"
22
+ typedef struct CompletionString_t
23
+ {
24
+ CXCompletionString data;
25
+ VALUE parent;
26
+ } CompletionString_t;
27
+
28
+ VALUE
29
+ c_CompletionString_struct_alloc(VALUE);
30
+
31
+ VALUE
32
+ c_CompletionString_get_availability(VALUE);
33
+
34
+ VALUE
35
+ c_CompletionString_get_priority(VALUE);
36
+
37
+ VALUE
38
+ c_CompletionString_get_num_chunks(VALUE);
39
+
40
+ VALUE
41
+ c_CompletionString_get_chunk_kind(VALUE, VALUE);
42
+
43
+ VALUE
44
+ c_CompletionString_get_chunk_text(VALUE, VALUE);
45
+
46
+ VALUE
47
+ c_CompletionString_get_num_annotations(VALUE);
48
+
49
+ VALUE
50
+ c_CompletionString_get_annotation(VALUE, VALUE);
51
+
52
+ VALUE
53
+ c_CompletionString_get_brief_comment(VALUE);
54
+
55
+ VALUE
56
+ c_CompletionString_get_chunk_completion_string(VALUE, VALUE);
57
+ #endif // COMPLETIONSTRING_H
@@ -0,0 +1,1677 @@
1
+ /*
2
+ * ruby-clangc ruby bindings for the C interface of Clang
3
+ * Copyright (C) 2015-2016 Cedric Le Moigne cedlemo <cedlemo@gmx.com>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ /*Cursor ruby class*/
19
+ #include "class_Cursor.h"
20
+ #include "class_Type.h"
21
+ #include "class_SourceLocation.h"
22
+ #include "class_SourceRange.h"
23
+ #include "class_File.h"
24
+ #include "class_CompletionString.h"
25
+ #include "class_TranslationUnit.h"
26
+ #include "class_OverriddenCursor.h"
27
+ #include "class_Module.h"
28
+ #include "macros.h"
29
+
30
+ static void c_Cursor_struct_free(Cursor_t *s)
31
+ {
32
+ if (s)
33
+ {
34
+ ruby_xfree(s);
35
+ }
36
+ }
37
+
38
+ static void c_Cursor_mark(void *s)
39
+ {
40
+ if (s)
41
+ {
42
+ Cursor_t *t = (Cursor_t *) s;
43
+ rb_gc_mark(t->parent);
44
+ }
45
+ }
46
+
47
+ VALUE
48
+ c_Cursor_struct_alloc(VALUE klass)
49
+ {
50
+
51
+ Cursor_t *ptr;
52
+ ptr = (Cursor_t *) ruby_xmalloc(sizeof(Cursor_t));
53
+ ptr->parent = Qnil;
54
+
55
+ return Data_Wrap_Struct(klass, NULL, c_Cursor_struct_free, (void *) ptr);
56
+ }
57
+
58
+ /**
59
+ * call-seq:
60
+ * Clangc::Cursor#is_null => true /false
61
+ *
62
+ * return true is the cursor is a null Cursor or false otherwise
63
+ */
64
+ VALUE
65
+ c_Cursor_is_null(VALUE self)
66
+ {
67
+ Cursor_t *c;
68
+ Data_Get_Struct(self, Cursor_t, c);
69
+ return NOT_0_2_RVAL(clang_Cursor_isNull(c->data));
70
+ }
71
+
72
+ /**
73
+ * call-seq:
74
+ * Clangc::Cursor#is_equal(cursor1) => true/false
75
+ *
76
+ * Determine whether two cursors are equivalent.
77
+ */
78
+ VALUE
79
+ c_Cursor_is_equal(VALUE self, VALUE cursor1)
80
+ {
81
+ Cursor_t *c;
82
+ Cursor_t *c1;
83
+
84
+ Data_Get_Struct(self, Cursor_t, c);
85
+ CHECK_ARG_TYPE(cursor1, Cursor);
86
+ Data_Get_Struct(cursor1, Cursor_t, c1);
87
+
88
+ return NOT_0_2_RVAL(clang_equalCursors(c->data, c1->data));
89
+ }
90
+
91
+ /**
92
+ * call-seq:
93
+ * Clangc::Cursor#hash => Fixnum
94
+ *
95
+ * Compute a hash value for the given cursor.
96
+ */
97
+ VALUE
98
+ c_Cursor_get_hash(VALUE self)
99
+ {
100
+ Cursor_t *c;
101
+ Data_Get_Struct(self, Cursor_t, c);
102
+ return CUINT_2_NUM(clang_hashCursor(c->data));
103
+ }
104
+
105
+ /**
106
+ * call-seq:
107
+ * Clangc::Cursor#kind => Fixnum
108
+ *
109
+ * Retrieve the kind of the given cursor.
110
+ * The value should refer to the constants in
111
+ * Clangc::CursorKind
112
+ */
113
+ VALUE
114
+ c_Cursor_get_kind(VALUE self)
115
+ {
116
+ Cursor_t *c;
117
+ Data_Get_Struct(self, Cursor_t, c);
118
+ return CUINT_2_NUM(clang_getCursorKind(c->data));
119
+ }
120
+
121
+ /**
122
+ * call-seq:
123
+ * Clangc::Cursor#linkage => Fixnum
124
+ *
125
+ * Determine the linkage of the entity referred to by a given cursor.
126
+ * The value should refer to the constants in
127
+ * Clangc::LinkageKind
128
+ */
129
+ VALUE
130
+ c_Cursor_get_linkage(VALUE self)
131
+ {
132
+ Cursor_t *c;
133
+ Data_Get_Struct(self, Cursor_t, c);
134
+ return CUINT_2_NUM(clang_getCursorLinkage(c->data));
135
+ }
136
+
137
+ /**
138
+ * call-seq:
139
+ * Clangc::Cursor#availability => Fixnum
140
+ *
141
+ * Determine the availability of the entity that this cursor refers to,
142
+ * taking the current target platform into account.
143
+ *
144
+ * The availability of the cursor.
145
+ * The value should refer to the constants in
146
+ * Clangc::AvailabilityKind
147
+ */
148
+ VALUE
149
+ c_Cursor_get_availability(VALUE self)
150
+ {
151
+ Cursor_t *c;
152
+ Data_Get_Struct(self, Cursor_t, c);
153
+ return CUINT_2_NUM(clang_getCursorAvailability(c->data));
154
+ }
155
+
156
+ /**
157
+ * call-seq:
158
+ * Clangc::Cursor#language => Fixnum
159
+ *
160
+ * Determine the "language" of the entity referred to by a given cursor.
161
+ * The value should refer to the constants in
162
+ * Clangc::LanguageKind
163
+ */
164
+ VALUE
165
+ c_Cursor_get_language(VALUE self)
166
+ {
167
+ Cursor_t *c;
168
+ Data_Get_Struct(self, Cursor_t, c);
169
+ return CUINT_2_NUM(clang_getCursorLanguage(c->data));
170
+ }
171
+
172
+ /**
173
+ * call-seq:
174
+ * Clangc::Cursor#type => Clangc::Type
175
+ *
176
+ * Retrieve the type of a CXCursor (if any).
177
+ */
178
+ VALUE
179
+ c_Cursor_get_type(VALUE self)
180
+ {
181
+ Cursor_t *c;
182
+ Data_Get_Struct(self, Cursor_t, c);
183
+ Type_t *t;
184
+ VALUE type;
185
+ R_GET_CLASS_DATA("Clangc", Type, type, t);
186
+ t->data = clang_getCursorType(c->data);
187
+ t->parent = self;
188
+ return type;
189
+ }
190
+
191
+ /**
192
+ * call-seq:
193
+ * Clangc::Cursor#semantic_parent => Clangc::Cursor
194
+ *
195
+ * Determine the semantic parent of the given cursor.
196
+ *
197
+ * The semantic parent of a cursor is the cursor that semantically contains
198
+ * the given cursor. For many declarations, the lexical and semantic parents
199
+ * are equivalent (the lexical parent is returned by
200
+ * Clang::Cursor#lexical_parent). They diverge when declarations or
201
+ * definitions are provided out-of-line. For example:
202
+ *
203
+ * class C {
204
+ * void f();
205
+ * };
206
+ *
207
+ * void C::f() { }
208
+ *
209
+ * In the out-of-line definition of "C::f", the semantic parent is
210
+ * the class "C", of which this function is a member. The lexical parent is
211
+ * the place where the declaration actually occurs in the source code; in this
212
+ * case, the definition occurs in the translation unit. In general, the
213
+ * lexical parent for a given entity can change without affecting the semantics
214
+ * of the program, and the lexical parent of different declarations of the
215
+ * same entity may be different. Changing the semantic parent of a declaration,
216
+ * on the other hand, can have a major impact on semantics, and redeclarations
217
+ * of a particular entity should all have the same semantic context.
218
+ *
219
+ * In the example above, both declarations of "C::f" have "C" as their
220
+ * semantic context, while the lexical context of the first "C::f" is "C"
221
+ * and the lexical context of the second "C::f" is the translation unit.
222
+ *
223
+ * For global declarations, the semantic parent is the translation unit.
224
+ */
225
+ VALUE
226
+ c_Cursor_get_semantic_parent(VALUE self)
227
+ {
228
+ Cursor_t *c;
229
+ Data_Get_Struct(self, Cursor_t, c);
230
+ Cursor_t *s;
231
+ VALUE sem_par;
232
+ R_GET_CLASS_DATA("Clangc", Cursor, sem_par, s);
233
+ s->data = clang_getCursorSemanticParent(c->data);
234
+ s->parent = c->parent;
235
+ return sem_par;
236
+ }
237
+
238
+ /**
239
+ * call-seq:
240
+ * Clangc::Cursor#lexical_parent => Clangc::Cursor
241
+ *
242
+ * Determine the lexical parent of the given cursor.
243
+ *
244
+ * The lexical parent of a cursor is the cursor in which the given cursor
245
+ * was actually written. For many declarations, the lexical and semantic parents
246
+ * are equivalent (the semantic parent is returned by
247
+ * Clangc::Cursor#semantic_parent). They diverge when declarations or
248
+ * definitions are provided out-of-line. For example:
249
+ *
250
+ * class C {
251
+ * void f();
252
+ * };
253
+ *
254
+ * void C::f() { }
255
+ *
256
+ * In the out-of-line definition of "C::f", the semantic parent is
257
+ * the class "C", of which this function is a member. The lexical parent is
258
+ * the place where the declaration actually occurs in the source code; in this
259
+ * case, the definition occurs in the translation unit. In general, the
260
+ * lexical parent for a given entity can change without affecting the semantics
261
+ * of the program, and the lexical parent of different declarations of the
262
+ * same entity may be different. Changing the semantic parent of a declaration,
263
+ * on the other hand, can have a major impact on semantics, and redeclarations
264
+ * of a particular entity should all have the same semantic context.
265
+ *
266
+ * In the example above, both declarations of "C::f" have "C" as their
267
+ * semantic context, while the lexical context of the first "C::f" is "C"
268
+ * and the lexical context of the second "C::f" is the translation unit.
269
+ *
270
+ * For declarations written in the global scope, the lexical parent is
271
+ * the translation unit.
272
+ */
273
+ VALUE
274
+ c_Cursor_get_lexical_parent(VALUE self)
275
+ {
276
+ Cursor_t *c;
277
+ Data_Get_Struct(self, Cursor_t, c);
278
+ Cursor_t *l;
279
+ VALUE lex_par;
280
+ R_GET_CLASS_DATA("Clangc", Cursor, lex_par, l);
281
+ l->data = clang_getCursorLexicalParent(c->data);
282
+ l->parent = c->parent;
283
+ return lex_par;
284
+ }
285
+
286
+ /**
287
+ * call-seq:
288
+ * Clangc::Cursor#location => Clangc::SourceLocation
289
+ *
290
+ * Retrieve the physical location of the source constructor referenced
291
+ * by the given cursor.
292
+ *
293
+ * The location of a declaration is typically the location of the name of that
294
+ * declaration, where the name of that declaration would occur if it is
295
+ * unnamed, or some keyword that introduces that particular declaration.
296
+ * The location of a reference is where that reference occurs within the
297
+ * source code.
298
+ */
299
+ VALUE
300
+ c_Cursor_get_source_location(VALUE self)
301
+ {
302
+ Cursor_t *c;
303
+ Data_Get_Struct(self, Cursor_t, c);
304
+ SourceLocation_t *s;
305
+ VALUE src_loc;
306
+ R_GET_CLASS_DATA("Clangc", SourceLocation, src_loc, s);
307
+ s->data = clang_getCursorLocation(c->data);
308
+ s->parent = self;
309
+ return src_loc;
310
+ }
311
+
312
+ /**
313
+ * call-seq:
314
+ * Clangc::Cursor#extent => Clangc::SourceRange
315
+ *
316
+ * Retrieve the physical extent of the source construct referenced by
317
+ * the given cursor.
318
+ *
319
+ * The extent of a cursor starts with the file/line/column pointing at the
320
+ * first character within the source construct that the cursor refers to and
321
+ * ends with the last character within that source construct. For a
322
+ * declaration, the extent covers the declaration itself. For a reference,
323
+ * the extent covers the location of the reference (e.g., where the referenced
324
+ * entity was actually used).
325
+ */
326
+ VALUE
327
+ c_Cursor_get_extent(VALUE self)
328
+ {
329
+ Cursor_t *c;
330
+ Data_Get_Struct(self, Cursor_t, c);
331
+ SourceRange_t *s;
332
+ VALUE src_rge;
333
+ R_GET_CLASS_DATA("Clangc", SourceRange, src_rge, s);
334
+ s->data = clang_getCursorExtent(c->data);
335
+ s->parent = self;
336
+ return src_rge;
337
+ }
338
+
339
+ /**
340
+ * call-seq:
341
+ * Clangc::Cursor#spelling => String
342
+ *
343
+ * Retrieve a name for the entity referenced by this cursor.
344
+ */
345
+ VALUE
346
+ c_Cursor_get_spelling(VALUE self)
347
+ {
348
+ Cursor_t *c;
349
+ Data_Get_Struct(self, Cursor_t, c);
350
+ return CXSTR_2_RVAL(clang_getCursorSpelling(c->data));
351
+ }
352
+
353
+ /**
354
+ * call-seq:
355
+ * Clangc::Cursor#typedef_decl_underlying_type => Clangc::Type
356
+ *
357
+ * Retrieve the underlying type of a typedef declaration.
358
+ *
359
+ * If the cursor does not reference a typedef declaration, an invalid type is
360
+ * returned.
361
+ */
362
+ VALUE
363
+ c_Cursor_get_typedef_decl_underlying_type(VALUE self)
364
+ {
365
+ Cursor_t *c;
366
+ Data_Get_Struct(self, Cursor_t, c);
367
+ Type_t *t;
368
+ VALUE type;
369
+ R_GET_CLASS_DATA("Clangc", Type, type, t);
370
+ t->data = clang_getTypedefDeclUnderlyingType(c->data);
371
+ t->parent = c->parent;
372
+ return type;
373
+ }
374
+
375
+ /**
376
+ * call-seq:
377
+ * Clangc::Cursor#included_file => Clangc::File
378
+ *
379
+ * Retrieve the file that is included by the given inclusion directive
380
+ * cursor.
381
+ */
382
+ VALUE
383
+ c_Cursor_get_included_file(VALUE self)
384
+ {
385
+ Cursor_t *c;
386
+ Data_Get_Struct(self, Cursor_t, c);
387
+ VALUE included;
388
+ File_t *f;
389
+ R_GET_CLASS_DATA("Clangc", File, included, f);
390
+ f->data = clang_getIncludedFile(c->data);
391
+ f->parent = c->parent;
392
+ return included;
393
+ }
394
+
395
+ /**
396
+ * call-seq:
397
+ * Clangc::Cursor#is_declaration => true/false
398
+ *
399
+ * Determine whether the given cursor kind represents a declaration.
400
+ */
401
+ VALUE
402
+ c_Cursor_is_declaration(VALUE self)
403
+ {
404
+ Cursor_t *c;
405
+ Data_Get_Struct(self, Cursor_t, c);
406
+ return NOT_0_2_RVAL(clang_isDeclaration(clang_getCursorKind(c->data)));
407
+ }
408
+
409
+ /**
410
+ * call-seq:
411
+ * Clangc::Cursor#is_reference => true/false
412
+ *
413
+ * Determine whether the given cursor kind represents a simple
414
+ * reference.
415
+ *
416
+ * Note that other kinds of cursors (such as expressions) can also refer to
417
+ * other cursors. Use Clangc::Cursor#cursor_referenced to determine whether a
418
+ * particular cursor refers to another entity.
419
+ */
420
+ VALUE
421
+ c_Cursor_is_reference(VALUE self)
422
+ {
423
+ Cursor_t *c;
424
+ Data_Get_Struct(self, Cursor_t, c);
425
+ return NOT_0_2_RVAL(clang_isReference(clang_getCursorKind(c->data)));
426
+ }
427
+
428
+ /**
429
+ * call-seq:
430
+ * Clangc::Cursor#is_expression => true/false
431
+ *
432
+ * Determine whether the given cursor kind represents an expression.
433
+ */
434
+ VALUE
435
+ c_Cursor_is_expression(VALUE self)
436
+ {
437
+ Cursor_t *c;
438
+ Data_Get_Struct(self, Cursor_t, c);
439
+ return NOT_0_2_RVAL(clang_isExpression(clang_getCursorKind(c->data)));
440
+ }
441
+
442
+ /**
443
+ * call-seq:
444
+ * Clangc::Cursor#is_statement => true/false
445
+ *
446
+ * Determine whether the given cursor kind represents a statement.
447
+ */
448
+ VALUE
449
+ c_Cursor_is_statement(VALUE self)
450
+ {
451
+ Cursor_t *c;
452
+ Data_Get_Struct(self, Cursor_t, c);
453
+ return NOT_0_2_RVAL(clang_isStatement(clang_getCursorKind(c->data)));
454
+ }
455
+
456
+ /**
457
+ * call-seq:
458
+ * Clangc::Cursor#is_attribute => true/false
459
+ *
460
+ * Determine whether the given cursor kind represents an attribute.
461
+ */
462
+ VALUE
463
+ c_Cursor_is_attribute(VALUE self)
464
+ {
465
+ Cursor_t *c;
466
+ Data_Get_Struct(self, Cursor_t, c);
467
+ return NOT_0_2_RVAL(clang_isAttribute(clang_getCursorKind(c->data)));
468
+ }
469
+
470
+ /**
471
+ * call-seq:
472
+ * Clangc::Cursor#is_invalid => true/false
473
+ *
474
+ * Determine whether the given cursor kind represents an invalid
475
+ * cursor.
476
+ */
477
+ VALUE
478
+ c_Cursor_is_invalid(VALUE self)
479
+ {
480
+ Cursor_t *c;
481
+ Data_Get_Struct(self, Cursor_t, c);
482
+ return NOT_0_2_RVAL(clang_isInvalid(clang_getCursorKind(c->data)));
483
+ }
484
+
485
+ /**
486
+ * call-seq:
487
+ * Clangc::Cursor#is_translation_unit => true/false
488
+ *
489
+ * Determine whether the given cursor kind represents a translation
490
+ * unit.
491
+ */
492
+ VALUE
493
+ c_Cursor_is_translation_unit(VALUE self)
494
+ {
495
+ Cursor_t *c;
496
+ Data_Get_Struct(self, Cursor_t, c);
497
+ return NOT_0_2_RVAL(clang_isTranslationUnit(clang_getCursorKind(c->data)));
498
+ }
499
+
500
+ /**
501
+ * call-seq:
502
+ * Clangc::Cursor#is_preprocessing => true/false
503
+ *
504
+ * Determine whether the given cursor represents a preprocessing
505
+ * element, such as a preprocessor directive or macro instantiation.
506
+ */
507
+ VALUE
508
+ c_Cursor_is_preprocessing(VALUE self)
509
+ {
510
+ Cursor_t *c;
511
+ Data_Get_Struct(self, Cursor_t, c);
512
+ return NOT_0_2_RVAL(clang_isPreprocessing(clang_getCursorKind(c->data)));
513
+ }
514
+ /**
515
+ * call-seq:
516
+ * Clangc::Cursor#enum_integer_type => Clangc::Type
517
+ *
518
+ * Retrieve the integer type of an enum declaration.
519
+ *
520
+ * If the cursor does not reference an enum declaration, an invalid type is
521
+ * returned.
522
+ */
523
+ VALUE
524
+ c_Cursor_get_enum_decl_integer_type(VALUE self)
525
+ {
526
+ Cursor_t *c;
527
+ Data_Get_Struct(self, Cursor_t, c);
528
+ Type_t *t;
529
+ VALUE type;
530
+ R_GET_CLASS_DATA("Clangc", Type, type, t);
531
+ t->data = clang_getEnumDeclIntegerType(c->data);
532
+ t->parent = c->parent;
533
+ return type;
534
+ }
535
+
536
+ /**
537
+ * call-seq:
538
+ * Clangc::Cursor#enum_const_decl_value => Fixnum
539
+ *
540
+ * Retrieve the integer value of an enum constant declaration as a signed
541
+ * long long.
542
+ *
543
+ * If the cursor does not reference an enum constant declaration, ULLONG_MIN is
544
+ * returned.
545
+ * Since this is also potentially a valid constant value, the kind of the cursor
546
+ * must be verified before calling this function.
547
+ */
548
+ VALUE
549
+ c_Cursor_get_enum_const_decl_value(VALUE self)
550
+ {
551
+ Cursor_t *c;
552
+ Data_Get_Struct(self, Cursor_t, c);
553
+ return CLLONG_2_NUM(clang_getEnumConstantDeclValue(c->data));
554
+ }
555
+
556
+ /**
557
+ * call-seq:
558
+ * Clangc::Cursor#enum_const_decl_unsigned_value => Fixnum
559
+ *
560
+ * Retrieve the integer value of an enum constant declaration as an unsigned
561
+ * long long.
562
+ *
563
+ * If the cursor does not reference an enum constant declaration, ULLONG_MAX is
564
+ * returned.
565
+ * Since this is also potentially a valid constant value, the kind of the cursor
566
+ * must be verified before calling this function.
567
+ */
568
+ VALUE
569
+ c_Cursor_get_enum_const_decl_unsigned_value(VALUE self)
570
+ {
571
+ Cursor_t *c;
572
+ Data_Get_Struct(self, Cursor_t, c);
573
+ return CULLONG_2_NUM(clang_getEnumConstantDeclUnsignedValue(c->data));
574
+ }
575
+
576
+ /**
577
+ * call-seq:
578
+ * Clangc::Cursor#field_decl_bit_width => Fixnum
579
+ *
580
+ * Retrieve the bit width of a bit field declaration as an integer.
581
+ *
582
+ * If a cursor that is not a bit field declaration is passed in, -1 is returned.
583
+ */
584
+ VALUE
585
+ c_Cursor_get_field_decl_bit_width(VALUE self)
586
+ {
587
+ Cursor_t *c;
588
+ Data_Get_Struct(self, Cursor_t, c);
589
+ return CINT_2_NUM(clang_getFieldDeclBitWidth(c->data));
590
+ }
591
+
592
+ /**
593
+ * call-seq:
594
+ * Clangc::Cursor#num_arguments => Fixnum
595
+ *
596
+ * Retrieve the number of non-variadic arguments associated with a given
597
+ * cursor.
598
+ *
599
+ * The number of arguments can be determined for calls as well as for
600
+ * declarations of functions or methods. For other cursors -1 is returned.
601
+ */
602
+ VALUE
603
+ c_Cursor_get_num_arguments(VALUE self)
604
+ {
605
+ Cursor_t *c;
606
+ Data_Get_Struct(self, Cursor_t, c);
607
+ return CINT_2_NUM(clang_Cursor_getNumArguments(c->data));
608
+ }
609
+
610
+ /**
611
+ * call-seq:
612
+ * Clangc::Cursor#get_argument(index) => Clangc::Cursor
613
+ *
614
+ * Retrieve the argument cursor of a function or method.
615
+ *
616
+ * The argument cursor can be determined for calls as well as for declarations
617
+ * of functions or methods. For other cursors and for invalid indices, an
618
+ * invalid cursor is returned.
619
+ */
620
+ VALUE
621
+ c_Cursor_get_argument(VALUE self, VALUE index)
622
+ {
623
+ Cursor_t *c;
624
+ Data_Get_Struct(self, Cursor_t, c);
625
+ int max = clang_Cursor_getNumArguments(c->data);
626
+ if (max < 0) max = 0;
627
+ unsigned int c_index = NUM2UINT(index);
628
+ CHECK_IN_RANGE(c_index, 0, max);
629
+ Cursor_t *a;
630
+ VALUE arg;
631
+ R_GET_CLASS_DATA("Clangc", Cursor, arg, a);
632
+ a->data = clang_Cursor_getArgument(c->data, c_index);
633
+ a->parent = c->parent;
634
+ return arg;
635
+ }
636
+
637
+ #if (CINDEX_VERSION_MINOR >= 29)
638
+ /**
639
+ * call-seq:
640
+ * Clangc::Cursor#num_template_arguments => Fixnum
641
+ *
642
+ * Returns the number of template args of a function decl representing a
643
+ * template specialization.
644
+ *
645
+ * If the argument cursor cannot be converted into a template function
646
+ * declaration, -1 is returned.
647
+ *
648
+ * For example, for the following declaration and specialization:
649
+
650
+ * template <typename T, int kInt, bool kBool>
651
+ * void foo() { ... }
652
+ *
653
+ * template <>
654
+ * void foo<float, -7, true>();
655
+ *
656
+ * The value 3 would be returned from this call.
657
+ */
658
+ VALUE
659
+ c_Cursor_get_num_template_arguments(VALUE self)
660
+ {
661
+ Cursor_t *c;
662
+ Data_Get_Struct(self, Cursor_t, c);
663
+ return CINT_2_NUM(clang_Cursor_getNumTemplateArguments(c->data));
664
+ }
665
+ #endif
666
+
667
+ /**
668
+ * call-seq:
669
+ * Clangc::Cursor#decl_objectC_type_encoding => string
670
+ *
671
+ * Returns the Objective-C type encoding for the specified declaration.
672
+ */
673
+ VALUE
674
+ c_Cursor_get_decl_obj_c_type_encoding(VALUE self)
675
+ {
676
+ Cursor_t *c;
677
+ Data_Get_Struct(self, Cursor_t, c);
678
+ return CXSTR_2_RVAL(clang_getDeclObjCTypeEncoding(c->data));
679
+ }
680
+
681
+ /**
682
+ * call-seq:
683
+ * Clangc::Cursor#result_tye => Clangc::Type
684
+ *
685
+ * Retrieve the return type associated with a function type.
686
+ *
687
+ * If a non-function type is passed in, an invalid type is returned.
688
+ */
689
+ VALUE
690
+ c_Cursor_get_result_type(VALUE self)
691
+ {
692
+ Cursor_t *c;
693
+ Data_Get_Struct(self, Cursor_t, c);
694
+ Type_t *t;
695
+ VALUE result_type;
696
+ R_GET_CLASS_DATA("Clangc", Type, result_type, t);
697
+ t->data = clang_getCursorResultType(c->data);
698
+ t->parent = self;
699
+ return result_type;
700
+ }
701
+
702
+ #if (CINDEX_VERSION_MINOR >= 30)
703
+ /**
704
+ * call-seq:
705
+ * Clangc::Cursor#offset_field => Fixnum
706
+ *
707
+ * Return the offset of the field represented by the Cursor.
708
+ *
709
+ * If the cursor is not a field declaration, -1 is returned.
710
+ * If the cursor semantic parent is not a record field declaration,
711
+ * Clangc::TypeLayoutError::INVALID is returned.
712
+ * If the field's type declaration is an incomplete type,
713
+ * Clangc::TypeLayoutError::INCOMPLETE is returned.
714
+ * If the field's type declaration is a dependent type,
715
+ * Clangc::TypeLayoutError::DEPENDENT is returned.
716
+ * If the field's name S is not found,
717
+ * Clangc::TypeLayoutError::INVALIDfIELD_NAME is returned.
718
+ */
719
+ VALUE
720
+ c_Cursor_get_offset_of_field(VALUE self)
721
+ {
722
+ Cursor_t *c;
723
+ Data_Get_Struct(self, Cursor_t, c);
724
+ return CLLONG_2_NUM(clang_Cursor_getOffsetOfField(c->data));
725
+ }
726
+
727
+ /**
728
+ * call-seq:
729
+ * Clangc::Cursor#is_anonymous => true / false
730
+ *
731
+ * Determine whether the given cursor represents an anonymous record
732
+ * declaration.
733
+ */
734
+ VALUE
735
+ c_Cursor_is_anonymous(VALUE self)
736
+ {
737
+ Cursor_t *c;
738
+ Data_Get_Struct(self, Cursor_t, c);
739
+ return NOT_0_2_RVAL(clang_Cursor_isAnonymous(c->data));
740
+ }
741
+ #endif
742
+
743
+ /**
744
+ * call-seq:
745
+ * Clangc::Cursor#is_bit_field => true/false
746
+ *
747
+ * Returns true if the cursor specifies a Record member that is a
748
+ * bitfield.
749
+ */
750
+ VALUE
751
+ c_Cursor_is_bit_field(VALUE self)
752
+ {
753
+ Cursor_t *c;
754
+ Data_Get_Struct(self, Cursor_t, c);
755
+ return NOT_0_2_RVAL(clang_Cursor_isBitField(c->data));
756
+ }
757
+
758
+ /**
759
+ * call-seq:
760
+ * Clangc::Cursor#is_virtual_base => true/false
761
+ *
762
+ * Returns true if the base class specified by the cursor with kind
763
+ * Clangc::CursorKind::CXX_BASE_SPECIFIER is virtual.
764
+ */
765
+ VALUE
766
+ c_Cursor_is_virtual_base(VALUE self)
767
+ {
768
+ Cursor_t *c;
769
+ Data_Get_Struct(self, Cursor_t, c);
770
+
771
+ return EQ_1_2_RVAL(clang_isVirtualBase(c->data));
772
+ }
773
+
774
+ /**
775
+ * call-seq:
776
+ * Clangc::Cursor#cxx_access_specifier => Clangc::CXXAccessSpecifier.constants
777
+ *
778
+ * Returns the access control level for the referenced object.
779
+ * The returned value is one of the Clangc::CXXAccesSpecifier.constants.
780
+ * It represents the C++ access control level to a base class for a
781
+ * cursor with kind Clangc::Cursor::CXX_BASE_SPECIFIER.
782
+ *
783
+ * If the cursor refers to a C++ declaration, its access control level within its
784
+ * parent scope is returned. Otherwise, if the cursor refers to a base specifier
785
+ * or
786
+ * access specifier, the specifier itself is returned.
787
+ */
788
+ VALUE
789
+ c_Cursor_get_cxx_access_specifier(VALUE self)
790
+ {
791
+ Cursor_t *c;
792
+ Data_Get_Struct(self, Cursor_t, c);
793
+ return CUINT_2_NUM(clang_getCXXAccessSpecifier(c->data));
794
+ }
795
+
796
+ #if (CINDEX_VERSION_MINOR >= 29)
797
+ /**
798
+ * call-seq:
799
+ * Clangc::Cursor#storage_class => Clangc::StorageClass.constants
800
+ *
801
+ * Returns the storage class for a function or variable declaration.
802
+ *
803
+ * If the passed in Cursor is not a function or variable declaration,
804
+ * Clangc::StorageClass::SC_INVALID is returned else the storage class.
805
+ */
806
+ VALUE
807
+ c_Cursor_get_storage_class(VALUE self)
808
+ {
809
+ Cursor_t *c;
810
+ Data_Get_Struct(self, Cursor_t, c);
811
+ return CUINT_2_NUM(clang_Cursor_getStorageClass(c->data));
812
+ }
813
+ #endif
814
+ /**
815
+ * call-seq:
816
+ * Clangc::Cursor#num_overloaded_decls => Fixnum >= 0
817
+ *
818
+ * Determine the number of overloaded declarations referenced by a
819
+ * Clangc::CursorKind::OVERLOADED_DECL_REF cursor.
820
+ *
821
+ * The number of overloaded declarations referenced by cursor. If it
822
+ * is not a Clangc::CursorKind::OVERLOADED_DECL_REF cursor, returns 0.
823
+ */
824
+ VALUE
825
+ c_Cursor_get_num_overloaded_decls(VALUE self)
826
+ {
827
+ Cursor_t *c;
828
+ Data_Get_Struct(self, Cursor_t, c);
829
+ return CUINT_2_NUM(clang_getNumOverloadedDecls(c->data));
830
+ }
831
+
832
+ /**
833
+ * call-seq:
834
+ * Clangc::Cursor#overloaded_decl(index) => Clangc::Cursor
835
+ *
836
+ * Retrieve a cursor for one of the overloaded declarations referenced
837
+ * by a Clangc::CursorKind::OVERLOADED_DECL_REF cursor.
838
+ *
839
+ * index The zero-based index into the set of overloaded declarations in
840
+ * the cursor.
841
+ *
842
+ * Returns a cursor representing the declaration referenced by the given
843
+ * cursor at the specified index. If the cursor does not have an
844
+ * associated set of overloaded declarations, or if the index is out of bounds,
845
+ * returns a nul cursor;
846
+ */
847
+ VALUE
848
+ c_Cursor_get_overloaded_decl(VALUE self, VALUE index)
849
+ {
850
+ Cursor_t *c;
851
+ Data_Get_Struct(self, Cursor_t, c);
852
+ unsigned int c_index = NUM2UINT(index);
853
+ Cursor_t *o;
854
+ VALUE overl_decl;
855
+ R_GET_CLASS_DATA("Clangc", Cursor, overl_decl, o);
856
+ o->data = clang_getOverloadedDecl(c->data, c_index);
857
+ o->parent = c->parent;
858
+ return overl_decl;
859
+ }
860
+ /**
861
+ * call-seq:
862
+ * Clangc::Cursor#display_name => String
863
+ *
864
+ * Retrieve the display name for the entity referenced by this cursor.
865
+ *
866
+ * The display name contains extra information that helps identify the cursor,
867
+ * such as the parameters of a function or template or the arguments of a
868
+ * class template specialization.
869
+ */
870
+ VALUE
871
+ c_Cursor_get_display_name(VALUE self)
872
+ {
873
+ Cursor_t *c;
874
+ Data_Get_Struct(self, Cursor_t, c);
875
+ return CXSTR_2_RVAL(clang_getCursorDisplayName(c->data));
876
+ }
877
+
878
+ /**
879
+ * call-seq:
880
+ * Clangc::Cursor#ib_outlet_collection_type => Clangc::Type
881
+ *
882
+ * For cursors representing an iboutletcollection attribute,
883
+ * this function returns the collection element type.
884
+ */
885
+ VALUE
886
+ c_Cursor_get_ib_outlet_collection_type(VALUE self)
887
+ {
888
+ Cursor_t *c;
889
+ Data_Get_Struct(self, Cursor_t, c);
890
+ Type_t *t;
891
+ VALUE collection_type;
892
+ R_GET_CLASS_DATA("Clangc", Type, collection_type, t);
893
+ t->data = clang_getIBOutletCollectionType(c->data);
894
+ t->parent = self;
895
+ return collection_type;
896
+ }
897
+
898
+ /**
899
+ * call-seq:
900
+ * Clangc::Cursor#usr => String
901
+ *
902
+ * Retrieve a Unified Symbol Resolution (USR) for the entity referenced
903
+ * by the given cursor.
904
+ *
905
+ * A Unified Symbol Resolution (USR) is a string that identifies a particular
906
+ * entity (function, class, variable, etc.) within a program. USRs can be
907
+ * compared across translation units to determine, e.g., when references in
908
+ * one translation refer to an entity defined in another translation unit.
909
+ */
910
+ VALUE
911
+ c_Cursor_get_usr(VALUE self)
912
+ {
913
+ Cursor_t *c;
914
+ Data_Get_Struct(self, Cursor_t, c);
915
+ return CXSTR_2_RVAL(clang_getCursorUSR(c->data));
916
+ }
917
+ /**
918
+ * call-seq:
919
+ * Clangc::Cursor#referenced => Clangc::Cursor
920
+ *
921
+ * For a cursor that is a reference, retrieve a cursor representing the
922
+ * entity that it references.
923
+ *
924
+ * Reference cursors refer to other entities in the AST. For example, an
925
+ * Objective-C superclass reference cursor refers to an Objective-C class.
926
+ * This function produces the cursor for the Objective-C class from the
927
+ * cursor for the superclass reference. If the input cursor is a declaration or
928
+ * definition, it returns that declaration or definition unchanged.
929
+ * Otherwise, returns the NULL cursor.
930
+ */
931
+ VALUE
932
+ c_Cursor_get_referenced(VALUE self)
933
+ {
934
+ Cursor_t *c;
935
+ Data_Get_Struct(self, Cursor_t, c);
936
+ Cursor_t *r;
937
+ VALUE referenced;
938
+ R_GET_CLASS_DATA("Clangc", Cursor, referenced, r);
939
+ r->data = clang_getCursorReferenced(c->data);
940
+ r->parent = c->parent;
941
+ return referenced;
942
+ }
943
+
944
+ /**
945
+ * call-seq:
946
+ * Clangc::Cursor#definition => Clangc::Cursor
947
+ *
948
+ * For a cursor that is either a reference to or a declaration
949
+ * of some entity, retrieve a cursor that describes the definition of
950
+ * that entity.
951
+ *
952
+ * Some entities can be declared multiple times within a translation
953
+ * unit, but only one of those declarations can also be a
954
+ * definition. For example, given:
955
+ *
956
+ * int f(int, int);
957
+ * int g(int x, int y) { return f(x, y); }
958
+ * int f(int a, int b) { return a + b; }
959
+ * int f(int, int);
960
+ *
961
+ * there are three declarations of the function "f", but only the
962
+ * second one is a definition. The clang_getCursorDefinition()
963
+ * function will take any cursor pointing to a declaration of "f"
964
+ * (the first or fourth lines of the example) or a cursor referenced
965
+ * that uses "f" (the call to "f' inside "g") and will return a
966
+ * declaration cursor pointing to the definition (the second "f"
967
+ * declaration).
968
+ *
969
+ * If given a cursor for which there is no corresponding definition,
970
+ * e.g., because there is no definition of that entity within this
971
+ * translation unit, returns a NULL cursor.
972
+ */
973
+ VALUE
974
+ c_Cursor_get_definition(VALUE self)
975
+ {
976
+ Cursor_t *c;
977
+ Data_Get_Struct(self, Cursor_t, c);
978
+ Cursor_t *d;
979
+ VALUE definition;
980
+ R_GET_CLASS_DATA("Clangc", Cursor, definition, d);
981
+ d->data = clang_getCursorDefinition(c->data);
982
+ d->parent = c->parent;
983
+ return definition;
984
+ }
985
+
986
+ /**
987
+ * call-seq:
988
+ * Clangc::Cursor#is_definition => true/false
989
+ *
990
+ * Determine whether the declaration pointed to by this cursor
991
+ * is also a definition of that entity.
992
+ */
993
+ VALUE
994
+ c_Cursor_is_definition(VALUE self)
995
+ {
996
+ Cursor_t *c;
997
+ Data_Get_Struct(self, Cursor_t, c);
998
+ return NOT_0_2_RVAL(clang_isCursorDefinition(c->data));
999
+ }
1000
+
1001
+ /**
1002
+ * call-seq:
1003
+ * Clangc::Cursor#canonical_cursor => Clangc::Cursor
1004
+ *
1005
+ * Retrieve the canonical cursor corresponding to the given cursor.
1006
+ *
1007
+ * In the C family of languages, many kinds of entities can be declared several
1008
+ * times within a single translation unit. For example, a structure type can
1009
+ * be forward-declared (possibly multiple times) and later defined:
1010
+ *
1011
+ * struct X;
1012
+ * struct X;
1013
+ * struct X {
1014
+ * int member;
1015
+ * };
1016
+ *
1017
+ * The declarations and the definition of \c X are represented by three
1018
+ * different cursors, all of which are declarations of the same underlying
1019
+ * entity. One of these cursor is considered the "canonical" cursor, which
1020
+ * is effectively the representative for the underlying entity. One can
1021
+ * determine if two cursors are declarations of the same underlying entity by
1022
+ * comparing their canonical cursors.
1023
+ *
1024
+ * It returns The canonical cursor for the entity referred to by the given
1025
+ * cursor.
1026
+ */
1027
+ VALUE
1028
+ c_Cursor_get_canonical_cursor(VALUE self)
1029
+ {
1030
+ Cursor_t *c;
1031
+ Data_Get_Struct(self, Cursor_t, c);
1032
+ Cursor_t *cc;
1033
+ VALUE canonical_cursor;
1034
+ R_GET_CLASS_DATA("Clangc", Cursor, canonical_cursor, cc);
1035
+ cc->data = clang_getCanonicalCursor(c->data);
1036
+ cc->parent = c->parent;
1037
+ return canonical_cursor;
1038
+ }
1039
+ /**
1040
+ * call-seq:
1041
+ * Clangc::Cursor#obj_c_selector_index => Fixnum
1042
+ *
1043
+ * If the cursor points to a selector identifier in an Objective-C
1044
+ * method or message expression, this returns the selector index.
1045
+ *
1046
+ * After getting a cursor with #clang_getCursor, this can be called to
1047
+ * determine if the location points to a selector identifier.
1048
+ *
1049
+ * It returns The selector index if the cursor is an Objective-C method or
1050
+ * message
1051
+ * expression and the cursor is pointing to a selector identifier, or -1
1052
+ * otherwise.
1053
+ */
1054
+ VALUE
1055
+ c_Cursor_get_obj_c_selector_index(VALUE self)
1056
+ {
1057
+ Cursor_t *c;
1058
+ Data_Get_Struct(self, Cursor_t, c);
1059
+ return CINT_2_NUM(clang_Cursor_getObjCSelectorIndex(c->data));
1060
+ }
1061
+ /**
1062
+ * call-seq:
1063
+ * Clangc::Cursor#is_dynamic_call => true/ false
1064
+ *
1065
+ * Given a cursor pointing to a C++ method call or an Objective-C
1066
+ * message, returns non-zero if the method/message is "dynamic", meaning:
1067
+ *
1068
+ * For a C++ method: the call is virtual.
1069
+ * For an Objective-C message: the receiver is an object instance, not 'super'
1070
+ * or a specific class.
1071
+ *
1072
+ * If the method/message is "static" or the cursor does not point to a
1073
+ * method/message, it will return zero.
1074
+ */
1075
+ VALUE
1076
+ c_Cursor_is_dynamic_call(VALUE self)
1077
+ {
1078
+ Cursor_t *c;
1079
+ Data_Get_Struct(self, Cursor_t, c);
1080
+ return NOT_0_2_RVAL(clang_Cursor_isDynamicCall(c->data));
1081
+ }
1082
+ /**
1083
+ * call-seq:
1084
+ * Clangc::Cursor#receiver_type => Clangc::Type
1085
+ *
1086
+ * Given a cursor pointing to an Objective-C message, returns the CXType
1087
+ * of the receiver.
1088
+ */
1089
+ VALUE
1090
+ c_Cursor_get_receiver_type(VALUE self)
1091
+ {
1092
+ Cursor_t *c;
1093
+ Data_Get_Struct(self, Cursor_t, c);
1094
+ Type_t *t;
1095
+ VALUE receiver_type;
1096
+ R_GET_CLASS_DATA("Clangc", Type, receiver_type, t);
1097
+ t->data = clang_Cursor_getReceiverType(c->data);
1098
+ t->parent = self;
1099
+ return receiver_type;
1100
+ }
1101
+ /**
1102
+ * call-seq:
1103
+ * Clangc::Cursor#obj_c_decl_qualifiers => Fixnum
1104
+
1105
+ * \brief Given a cursor that represents an Objective-C method or parameter
1106
+ * declaration, return the associated Objective-C qualifiers for the return
1107
+ * type or the parameter respectively. The bits are formed from
1108
+ * Clangc::ObjCDeclQualifierKind constants.
1109
+ */
1110
+ VALUE
1111
+ c_Cursor_get_obj_c_decl_qualifiers(VALUE self)
1112
+ {
1113
+ Cursor_t *c;
1114
+ Data_Get_Struct(self, Cursor_t, c);
1115
+ return CUINT_2_NUM(clang_Cursor_getObjCDeclQualifiers(c->data));
1116
+ }
1117
+
1118
+ /**
1119
+ * call-seq:
1120
+ * Clangc::Cursor#is_obj_c_optional => true / false
1121
+ *
1122
+ * Given a cursor that represents an Objective-C method or property
1123
+ * declaration, return non-zero if the declaration was affected by "@optional".
1124
+ * Returns zero if the cursor is not such a declaration or it is "@required".
1125
+ */
1126
+ VALUE
1127
+ c_Cursor_is_obj_c_optional(VALUE self)
1128
+ {
1129
+ Cursor_t *c;
1130
+ Data_Get_Struct(self, Cursor_t, c);
1131
+ return NOT_0_2_RVAL(clang_Cursor_isObjCOptional(c->data));
1132
+ }
1133
+ /**
1134
+ * call-seq:
1135
+ * Clangc::Cursor#is_variadic => true / false
1136
+ *
1137
+ * Returns non-zero if the given cursor is a variadic function or method.
1138
+ */
1139
+ VALUE
1140
+ c_Cursor_is_variadic(VALUE self)
1141
+ {
1142
+ Cursor_t *c;
1143
+ Data_Get_Struct(self, Cursor_t, c);
1144
+ return NOT_0_2_RVAL(clang_Cursor_isVariadic(c->data));
1145
+ }
1146
+ /**
1147
+ * call-seq:
1148
+ * Clangc::Cursor#comment_range => Clangc::SourceRange
1149
+ *
1150
+ * Given a cursor that represents a declaration, return the associated
1151
+ * comment's source range. The range may include multiple consecutive comments
1152
+ * with whitespace in between.
1153
+ */
1154
+ VALUE
1155
+ c_Cursor_get_comment_range(VALUE self)
1156
+ {
1157
+ Cursor_t *c;
1158
+ Data_Get_Struct(self, Cursor_t, c);
1159
+ SourceRange_t *s;
1160
+ VALUE cmt_rge;
1161
+ R_GET_CLASS_DATA("Clangc", SourceRange, cmt_rge, s);
1162
+ s->data = clang_Cursor_getCommentRange(c->data);
1163
+ s->parent = self;
1164
+ return cmt_rge;
1165
+ }
1166
+ /**
1167
+ * call-seq:
1168
+ * Clangc::Cursor#raw_comment_text => String
1169
+ *
1170
+ * Given a cursor that represents a declaration, return the associated
1171
+ * comment text, including comment markers.
1172
+ */
1173
+ VALUE
1174
+ c_Cursor_get_raw_comment_text(VALUE self)
1175
+ {
1176
+ Cursor_t *c;
1177
+ Data_Get_Struct(self, Cursor_t, c);
1178
+ return CXSTR_2_RVAL(clang_Cursor_getRawCommentText(c->data));
1179
+ }
1180
+
1181
+ /**
1182
+ * call-seq:
1183
+ * Clangc::Cursor#brief_comment_text => String
1184
+ *
1185
+ * Given a cursor that represents a documentable entity (e.g.,
1186
+ * declaration), return the associated \\brief paragraph; otherwise return the
1187
+ * first paragraph.
1188
+ */
1189
+ VALUE
1190
+ c_Cursor_get_brief_comment_text(VALUE self)
1191
+ {
1192
+ Cursor_t *c;
1193
+ Data_Get_Struct(self, Cursor_t, c);
1194
+ return CXSTR_2_RVAL(clang_Cursor_getBriefCommentText(c->data));
1195
+ }
1196
+
1197
+ #if (CINDEX_VERSION_MINOR >= 29)
1198
+ /**
1199
+ * call-seq:
1200
+ * Clangc::Cursor#mangling => String
1201
+ * Retrieve the String representing the mangled name of the cursor.
1202
+ */
1203
+ VALUE
1204
+ c_Cursor_get_mangling(VALUE self)
1205
+ {
1206
+ Cursor_t *c;
1207
+ Data_Get_Struct(self, Cursor_t, c);
1208
+ return CXSTR_2_RVAL(clang_Cursor_getMangling(c->data));
1209
+ }
1210
+ #endif
1211
+
1212
+ /**
1213
+ * call-seq:
1214
+ * Clangc::Cursor#cxx_method_is_pure_virtual => true /false
1215
+ *
1216
+ * Determine if a C++ member function or member function template is
1217
+ * pure virtual.
1218
+ */
1219
+ VALUE
1220
+ c_Cursor_cxx_method_is_pure_virtual(VALUE self)
1221
+ {
1222
+ Cursor_t *c;
1223
+ Data_Get_Struct(self, Cursor_t, c);
1224
+ return NOT_0_2_RVAL(clang_CXXMethod_isPureVirtual(c->data));
1225
+ }
1226
+
1227
+ /**
1228
+ * call-seq:
1229
+ * Clangc::Cursor#cxx_method_is_static => true /false
1230
+ *
1231
+ * Determine if a C++ member function or member function template is
1232
+ * static.
1233
+ */
1234
+ VALUE
1235
+ c_Cursor_cxx_method_is_static(VALUE self)
1236
+ {
1237
+ Cursor_t *c;
1238
+ Data_Get_Struct(self, Cursor_t, c);
1239
+ return NOT_0_2_RVAL(clang_CXXMethod_isStatic(c->data));
1240
+ }
1241
+ /**
1242
+ * call-seq:
1243
+ * Clangc::Cursor#cxx_method_is_virtual => true /false
1244
+ *
1245
+ * Determine if a C++ member function or member function template is
1246
+ * explicitly declared 'virtual' or if it overrides a virtual method from
1247
+ * one of the base classes.
1248
+ */
1249
+ VALUE
1250
+ c_Cursor_cxx_method_is_virtual(VALUE self)
1251
+ {
1252
+ Cursor_t *c;
1253
+ Data_Get_Struct(self, Cursor_t, c);
1254
+ return NOT_0_2_RVAL(clang_CXXMethod_isVirtual(c->data));
1255
+ }
1256
+
1257
+ /**
1258
+ * call-seq:
1259
+ * Clangc::Cursor#cxx_method_is_const => true /false
1260
+ *
1261
+ * Determine if a C++ member function or member function template is
1262
+ * constant.
1263
+ */
1264
+ VALUE
1265
+ c_Cursor_cxx_method_is_const(VALUE self)
1266
+ {
1267
+ Cursor_t *c;
1268
+ Data_Get_Struct(self, Cursor_t, c);
1269
+ return NOT_0_2_RVAL(clang_CXXMethod_isConst(c->data));
1270
+ }
1271
+
1272
+ /**
1273
+ * call-seq:
1274
+ * Clangc::Cursor#template_cursor_kind => Clangc::CursorKind.constants
1275
+ *
1276
+ * Given a cursor that represents a template, determine the cursor kind of
1277
+ * the specializations would be generated by instantiating the template.
1278
+ *
1279
+ * This routine can be used to determine what flavor of function template,
1280
+ * class template, or class template partial specialization is stored in the
1281
+ * cursor. For example, it can describe whether a class template cursor is
1282
+ * declared with "struct", "class" or "union".
1283
+ *
1284
+ * C The cursor to query should represent a template declaration.
1285
+ *
1286
+ * It returns the cursor kind of the specializations that would be generated
1287
+ * by instantiating the template . If the cursor is not a template, it returns
1288
+ * Clangc::CursorKind::NO_DECL_FOUND.
1289
+ */
1290
+ VALUE
1291
+ c_Cursor_get_template_cursor_kind(VALUE self)
1292
+ {
1293
+ Cursor_t *c;
1294
+ Data_Get_Struct(self, Cursor_t, c);
1295
+ return CUINT_2_NUM(clang_getTemplateCursorKind(c->data));
1296
+ }
1297
+
1298
+ /**
1299
+ * call-seq:
1300
+ * Clangc::Cursor#specialized_cursor_template => Clangc::Cursor
1301
+ *
1302
+ * Given a cursor that may represent a specialization or instantiation
1303
+ * of a template, retrieve the cursor that represents the template that it
1304
+ * specializes or from which it was instantiated.
1305
+ *
1306
+ * This routine determines the template involved both for explicit
1307
+ * specializations of templates and for implicit instantiations of the template,
1308
+ * both of which are referred to as "specializations". For a class template
1309
+ * specialization (e.g., \c std::vector<bool>), this routine will return
1310
+ * either the primary template (\c std::vector) or, if the specialization was
1311
+ * instantiated from a class template partial specialization, the class template
1312
+ * partial specialization. For a class template partial specialization and a
1313
+ * function template specialization (including instantiations), this
1314
+ * this routine will return the specialized template.
1315
+ *
1316
+ * For members of a class template (e.g., member functions, member classes, or
1317
+ * static data members), returns the specialized or instantiated member.
1318
+ * Although not strictly "templates" in the C++ language, members of class
1319
+ * templates have the same notions of specializations and instantiations that
1320
+ * templates do, so this routine treats them similarly.
1321
+ *
1322
+ * The cursor may be a specialization of a template or a member
1323
+ * of a template.
1324
+ *
1325
+ * If the given cursor is a specialization or instantiation of a
1326
+ * template or a member thereof, it returns the template or member that it
1327
+ * specializes or
1328
+ * from which it was instantiated. Otherwise, returns a NULL cursor.
1329
+ */
1330
+ VALUE
1331
+ c_Cursor_get_specialized_cursor_template(VALUE self)
1332
+ {
1333
+ Cursor_t *c;
1334
+ Data_Get_Struct(self, Cursor_t, c);
1335
+ Cursor_t *sct;
1336
+ VALUE specialized_cursor_template;
1337
+ R_GET_CLASS_DATA("Clangc", Cursor, specialized_cursor_template, sct);
1338
+ sct->data = clang_getSpecializedCursorTemplate(c->data);
1339
+ sct->parent = c->parent;
1340
+ return specialized_cursor_template;
1341
+ }
1342
+
1343
+ /**
1344
+ * call-seq:
1345
+ * Clangc::Cursor#completion_string => Clangc::CompletionString
1346
+ *
1347
+ * Retrieve a completion string for an arbitrary declaration or macro
1348
+ * definition cursor.
1349
+ *
1350
+ * It returns a non-context-sensitive completion string for declaration and macro
1351
+ * definition cursors, or nil for other kinds of cursors.
1352
+ */
1353
+ VALUE
1354
+ c_Cursor_get_completion_string(VALUE self)
1355
+ {
1356
+ Cursor_t *c;
1357
+ Data_Get_Struct(self, Cursor_t, c);
1358
+ CompletionString_t *cs;
1359
+ VALUE completion_string;
1360
+ R_GET_CLASS_DATA("Clangc", CompletionString, completion_string, cs);
1361
+ cs->data = clang_getCursorCompletionString(c->data);
1362
+ cs->parent = self;
1363
+ if (cs->data == NULL)
1364
+ return Qnil;
1365
+ else
1366
+ return completion_string;
1367
+ }
1368
+
1369
+ /**
1370
+ * clang_Cursor_getTranslationUnit won't be implemented
1371
+ * The memory managment would be too tricky
1372
+ */
1373
+
1374
+ #if (CINDEX_VERSION_MINOR >= 29)
1375
+ /**
1376
+ * call-seq:
1377
+ * Clangc::Cursor#template_argument_kind(i) => Clangc::TemplateArgumentKind
1378
+ *
1379
+ * Retrieve the kind of the I'th template argument of the CXCursor C.
1380
+ *
1381
+ * If the argument CXCursor does not represent a
1382
+ * Clangc::CursorKind::FUNCTION_DECL, an invalid
1383
+ * template argument kind is returned.
1384
+ *
1385
+ * For example, for the following declaration and specialization:
1386
+ * template <typename T, int kInt, bool kBool>
1387
+ * void foo() { ... }
1388
+ *
1389
+ * template <>
1390
+ * void foo<float, -7, true>();
1391
+ *
1392
+ * For I = 0, 1, and 2, Type, Integral, and Integral will be returned,
1393
+ * respectively.
1394
+ */
1395
+ VALUE
1396
+ c_Cursor_get_template_argument_kind(VALUE self, VALUE index)
1397
+ {
1398
+ Cursor_t *c;
1399
+ Data_Get_Struct(self, Cursor_t, c);
1400
+ unsigned c_index = NUM2UINT(index);
1401
+ return CUINT_2_NUM(clang_Cursor_getTemplateArgumentKind(c->data, c_index));
1402
+ }
1403
+
1404
+ /**
1405
+ * call-seq:
1406
+ * Clangc::Cursor#template_argument_type => Clangc::Type
1407
+ *
1408
+ * Retrieve a Clangc::Type representing the type of a TemplateArgument of a
1409
+ * function decl representing a template specialization.
1410
+ *
1411
+ * If the Clangc::Cursor does not represent a Clangc::CursorKind::FUNCTION_DECL
1412
+ * whose I'th
1413
+ * template argument has a kind of CXTemplateArgKind_Integral, an invalid type
1414
+ * is returned.
1415
+ *
1416
+ * For example, for the following declaration and specialization:
1417
+ * template <typename T, int kInt, bool kBool>
1418
+ * void foo() { ... }
1419
+ *
1420
+ * template <>
1421
+ * void foo<float, -7, true>();
1422
+ *
1423
+ * If called with I = 0, "float", will be returned.
1424
+ * Invalid types will be returned for I == 1 or 2.
1425
+ */
1426
+ VALUE
1427
+ c_Cursor_get_template_argument_type(VALUE self, VALUE index)
1428
+ {
1429
+ Cursor_t *c;
1430
+ Data_Get_Struct(self, Cursor_t, c);
1431
+ unsigned c_index = NUM2UINT(index);
1432
+ Type_t *t;
1433
+ VALUE type;
1434
+ R_GET_CLASS_DATA("Clangc", Type, type, t);
1435
+ t->data = clang_Cursor_getTemplateArgumentType(c->data, c_index);
1436
+ t->parent = self;
1437
+ return type;
1438
+ }
1439
+
1440
+ /**
1441
+ * call-seq:
1442
+ * Clangc::Cursor#template_argument_value => Integer
1443
+ *
1444
+ * Retrieve the value of an Integral TemplateArgument (of a function
1445
+ * decl representing a template specialization) as a signed long long.
1446
+ *
1447
+ * It is undefined to call this function on a CXCursor that does not represent a
1448
+ * FunctionDecl or whose I'th template argument is not an integral value.
1449
+ *
1450
+ * For example, for the following declaration and specialization:
1451
+ * template <typename T, int kInt, bool kBool>
1452
+ * void foo() { ... }
1453
+ *
1454
+ * template <>
1455
+ * void foo<float, -7, true>();
1456
+ *
1457
+ * If called with I = 1 or 2, -7 or true will be returned, respectively.
1458
+ * For I == 0, this function's behavior is undefined.
1459
+ */
1460
+ VALUE
1461
+ c_Cursor_get_template_argument_value(VALUE self, VALUE index)
1462
+ {
1463
+ Cursor_t *c;
1464
+ Data_Get_Struct(self, Cursor_t, c);
1465
+ unsigned c_index = NUM2UINT(index);
1466
+ return CLLONG_2_NUM(
1467
+ clang_Cursor_getTemplateArgumentValue(c->data, c_index));
1468
+ }
1469
+
1470
+ /**
1471
+ * call-seq:
1472
+ * Clangc::Cursor#template_argument_unsigned_value => Integer
1473
+ *
1474
+ * Retrieve the value of an Integral TemplateArgument (of a function
1475
+ * decl representing a template specialization) as an unsigned long long.
1476
+ *
1477
+ * It is undefined to call this function on a CXCursor that does not represent a
1478
+ * FunctionDecl or whose I'th template argument is not an integral value.
1479
+ *
1480
+ * For example, for the following declaration and specialization:
1481
+ * template <typename T, int kInt, bool kBool>
1482
+ * void foo() { ... }
1483
+ *
1484
+ * template <>
1485
+ * void foo<float, 2147483649, true>();
1486
+ *
1487
+ * If called with I = 1 or 2, 2147483649 or true will be returned, respectively.
1488
+ * For I == 0, this function's behavior is undefined.
1489
+ */
1490
+ VALUE
1491
+ c_Cursor_get_template_argument_unsigned_value(VALUE self, VALUE index)
1492
+ {
1493
+ Cursor_t *c;
1494
+ Data_Get_Struct(self, Cursor_t, c);
1495
+ unsigned c_index = NUM2UINT(index);
1496
+ return CULLONG_2_NUM(
1497
+ clang_Cursor_getTemplateArgumentUnsignedValue(c->data, c_index));
1498
+ }
1499
+ #endif
1500
+ /**
1501
+ * call-seq:
1502
+ * Clangc::Cursor#obj_c_property_attributes(reserved) => Integer
1503
+ *
1504
+ * Given a cursor that represents a property declaration, return the
1505
+ * associated property attributes. The bits are formed from
1506
+ * Clangc::ObjCPropertyAttrKind constants.
1507
+ *
1508
+ * reserved Reserved for future use, pass 0.
1509
+ */
1510
+ VALUE
1511
+ c_Cursor_get_obj_c_property_attributes(VALUE self, VALUE reserved)
1512
+ {
1513
+ Cursor_t *c;
1514
+ Data_Get_Struct(self, Cursor_t, c);
1515
+ unsigned c_reserved = CLANGC_CONSTANT_TO_UINT("ObjCPropertyAttrKind",
1516
+ reserved);
1517
+ return CUINT_2_NUM(
1518
+ clang_Cursor_getObjCPropertyAttributes(c->data, c_reserved));
1519
+ }
1520
+
1521
+ /**
1522
+ * call-seq:
1523
+ * Clangc::Cursor#overriden_cursors => Array
1524
+ *
1525
+ * Determine the set of methods that are overridden by the given
1526
+ * method.
1527
+ *
1528
+ * In both Objective-C and C++, a method (aka virtual member function,
1529
+ * in C++) can override a virtual method in a base class. For
1530
+ * Objective-C, a method is said to override any method in the class's
1531
+ * base class, its protocols, or its categories' protocols, that has the same
1532
+ * selector and is of the same kind (class or instance).
1533
+ * If no such method exists, the search continues to the class's superclass,
1534
+ * its protocols, and its categories, and so on. A method from an Objective-C
1535
+ * implementation is considered to override the same methods as its
1536
+ * corresponding method in the interface.
1537
+ *
1538
+ * For C++, a virtual member function overrides any virtual member
1539
+ * function with the same signature that occurs in its base
1540
+ * classes. With multiple inheritance, a virtual member function can
1541
+ * override several virtual member functions coming from different
1542
+ * base classes.
1543
+ *
1544
+ * In all cases, this function determines the immediate overridden
1545
+ * method, rather than all of the overridden methods. For example, if
1546
+ * a method is originally declared in a class A, then overridden in B
1547
+ * (which in inherits from A) and also in C (which inherited from B),
1548
+ * then the only overridden method returned from this function when
1549
+ * invoked on C's method will be B's method. The client may then
1550
+ * invoke this function again, given the previously-found overridden
1551
+ * methods, to map out the complete method-override set.
1552
+ *
1553
+ * It returns an Array of Clangc::Cursors or an empty Array.
1554
+ */
1555
+ VALUE
1556
+ c_Cursor_get_overridden_cursors(VALUE self)
1557
+ {
1558
+ Cursor_t *c;
1559
+ Data_Get_Struct(self, Cursor_t, c);
1560
+
1561
+ CXCursor **overridden;
1562
+ unsigned num_overridden;
1563
+ clang_getOverriddenCursors(c->data, overridden, &num_overridden);
1564
+
1565
+ VALUE ret = rb_ary_new();
1566
+ if (overridden == NULL) return ret;
1567
+
1568
+ unsigned i;
1569
+ for (i = 0; i < num_overridden; i++)
1570
+ {
1571
+ CXCursor *ptr;
1572
+ ptr = *(overridden + i);
1573
+ VALUE overridden_cursor;
1574
+ OverriddenCursor_t *oc;
1575
+ R_GET_CLASS_DATA("Clangc", OverriddenCursor, overridden_cursor, oc);
1576
+ oc->data = *ptr;
1577
+ oc->ptr = ptr;
1578
+ rb_ary_push(ret, overridden_cursor);
1579
+ }
1580
+
1581
+ return ret;
1582
+ }
1583
+
1584
+ /**
1585
+ * call-seq:
1586
+ * Clangc::Cursor#module => Clangc::Module
1587
+ *
1588
+ * Given a Clangc::CursorKind::MODULE_IMPORT_DECL cursor, return the associated
1589
+ * module.
1590
+ */
1591
+ VALUE
1592
+ c_Cursor_get_module(VALUE self)
1593
+ {
1594
+ Cursor_t *c;
1595
+ Data_Get_Struct(self, Cursor_t, c);
1596
+ Module_t *m;
1597
+ VALUE module;
1598
+ R_GET_CLASS_DATA("Clangc", Module, module, m);
1599
+ m->data = clang_Cursor_getModule(c->data);
1600
+ m->parent = self;
1601
+ return module;
1602
+ }
1603
+
1604
+ /**
1605
+ * call-seq:
1606
+ * Clangc::Cursor#spelling_name_range(Integer, Integer) => Clangc::SourceRange
1607
+ *
1608
+ * Retrieve a range for a piece that forms the cursors spelling name.
1609
+ * Most of the times there is only one range for the complete spelling but for
1610
+ * Objective-C methods and Objective-C message expressions, there are multiple
1611
+ * pieces for each selector identifier.
1612
+ *
1613
+ * First parameter is the index of the spelling name piece. If this is greater
1614
+ * than the actual number of pieces, it will return a NULL (invalid) range.
1615
+ *
1616
+ * The second parameter is for options and are Reserved.
1617
+ */
1618
+ VALUE
1619
+ c_Cursor_get_spelling_name_range(VALUE self, VALUE index, VALUE options)
1620
+ {
1621
+ Cursor_t *c;
1622
+ Data_Get_Struct(self, Cursor_t, c);
1623
+ SourceRange_t *sr;
1624
+ VALUE source_range;
1625
+ R_GET_CLASS_DATA("Clangc", SourceRange, source_range, sr);
1626
+ sr->data = clang_Cursor_getSpellingNameRange(
1627
+ c->data, NUM2UINT(index), NUM2UINT(options));
1628
+ sr->parent = c->parent;
1629
+ return source_range;
1630
+ }
1631
+
1632
+ /**
1633
+ * call-seq:
1634
+ * Clangc::Cursor#reference_name_range(Clangc::NameFlags, piece_index) =>
1635
+ * Clangc::SourceRange or Clangc::Cursor (null)
1636
+ *
1637
+ * Given a cursor that references something else, return the source range
1638
+ * covering that reference.
1639
+ *
1640
+ * For a cursor pointing to a member reference, a declaration reference, or
1641
+ * an operator call.
1642
+ *
1643
+ * First parameter is a Clangc::NameFlags. A bitset with three independent
1644
+ * flags:
1645
+ * CXNameRange_WantQualifier, CXNameRange_WantTemplateArgs, and
1646
+ * CXNameRange_WantSinglePiece.
1647
+ *
1648
+ * piece_index For contiguous names or when passing the flag
1649
+ * CXNameRange_WantSinglePiece, only one piece with index 0 is
1650
+ * available. When the CXNameRange_WantSinglePiece flag is not passed for a
1651
+ * non-contiguous names, this index can be used to retrieve the individual
1652
+ * pieces of the name. See also CXNameRange_WantSinglePiece.
1653
+ *
1654
+ * It returns the piece of the name pointed to by the given cursor. If there is
1655
+ * no
1656
+ * name, or if the PieceIndex is out-of-range, a null-cursor will be returned.
1657
+ */
1658
+ VALUE
1659
+ c_Cursor_get_reference_name_range(VALUE self,
1660
+ VALUE name_flags,
1661
+ VALUE piece_index)
1662
+ {
1663
+ Cursor_t *c;
1664
+ Data_Get_Struct(self, Cursor_t, c);
1665
+ SourceRange_t *sr;
1666
+ VALUE source_range;
1667
+ unsigned int c_name_flags;
1668
+ unsigned int c_piece_index;
1669
+ c_name_flags = CLANGC_CONSTANT_TO_UINT("NameRefFlags", name_flags);
1670
+ c_piece_index = NUM2UINT(piece_index);
1671
+ R_GET_CLASS_DATA("Clangc", SourceRange, source_range, sr);
1672
+
1673
+ sr->data = clang_getCursorReferenceNameRange(
1674
+ c->data, c_name_flags, c_piece_index);
1675
+ sr->parent = c->parent;
1676
+ return source_range;
1677
+ }