ffi-clang 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -0
  3. data/ext/rakefile.rb +4 -0
  4. data/ext/teapot.rb +4 -3
  5. data/lib/ffi/clang/clang_version.rb +9 -19
  6. data/lib/ffi/clang/code_completion.rb +4 -18
  7. data/lib/ffi/clang/comment.rb +7 -19
  8. data/lib/ffi/clang/compilation_database.rb +4 -18
  9. data/lib/ffi/clang/cursor.rb +92 -25
  10. data/lib/ffi/clang/diagnostic.rb +8 -21
  11. data/lib/ffi/clang/file.rb +4 -18
  12. data/lib/ffi/clang/index.rb +9 -20
  13. data/lib/ffi/clang/lib/clang_version.rb +5 -19
  14. data/lib/ffi/clang/lib/code_completion.rb +4 -18
  15. data/lib/ffi/clang/lib/comment.rb +7 -20
  16. data/lib/ffi/clang/lib/compilation_database.rb +4 -18
  17. data/lib/ffi/clang/lib/cursor.rb +185 -41
  18. data/lib/ffi/clang/lib/diagnostic.rb +8 -28
  19. data/lib/ffi/clang/lib/file.rb +5 -20
  20. data/lib/ffi/clang/lib/inclusions.rb +5 -19
  21. data/lib/ffi/clang/lib/index.rb +6 -20
  22. data/lib/ffi/clang/lib/source_location.rb +5 -20
  23. data/lib/ffi/clang/lib/source_range.rb +5 -22
  24. data/lib/ffi/clang/lib/string.rb +6 -20
  25. data/lib/ffi/clang/lib/token.rb +4 -18
  26. data/lib/ffi/clang/lib/translation_unit.rb +7 -21
  27. data/lib/ffi/clang/lib/type.rb +8 -20
  28. data/lib/ffi/clang/lib.rb +31 -23
  29. data/lib/ffi/clang/source_location.rb +7 -20
  30. data/lib/ffi/clang/source_range.rb +7 -22
  31. data/lib/ffi/clang/token.rb +4 -18
  32. data/lib/ffi/clang/translation_unit.rb +17 -23
  33. data/lib/ffi/clang/type.rb +7 -19
  34. data/lib/ffi/clang/unsaved_file.rb +6 -20
  35. data/lib/ffi/clang/version.rb +7 -21
  36. data/lib/ffi/clang.rb +9 -20
  37. data/license.md +38 -0
  38. data/readme.md +46 -0
  39. data.tar.gz.sig +0 -0
  40. metadata +78 -81
  41. metadata.gz.sig +2 -0
  42. data/.gitignore +0 -19
  43. data/.rspec +0 -5
  44. data/.travis.yml +0 -30
  45. data/Gemfile +0 -13
  46. data/README.md +0 -74
  47. data/Rakefile +0 -12
  48. data/examples/docs.cpp +0 -25
  49. data/examples/docs.rb +0 -31
  50. data/ffi-clang.gemspec +0 -26
  51. data/spec/ffi/clang/code_completion_spec.rb +0 -181
  52. data/spec/ffi/clang/comment_spec.rb +0 -453
  53. data/spec/ffi/clang/compilation_database_spec.rb +0 -176
  54. data/spec/ffi/clang/cursor_spec.rb +0 -701
  55. data/spec/ffi/clang/diagnostic_spec.rb +0 -89
  56. data/spec/ffi/clang/file_spec.rb +0 -82
  57. data/spec/ffi/clang/fixtures/a.c +0 -7
  58. data/spec/ffi/clang/fixtures/canonical.c +0 -5
  59. data/spec/ffi/clang/fixtures/class.cpp +0 -8
  60. data/spec/ffi/clang/fixtures/compile_commands.json +0 -17
  61. data/spec/ffi/clang/fixtures/completion.cxx +0 -8
  62. data/spec/ffi/clang/fixtures/docs.c +0 -1
  63. data/spec/ffi/clang/fixtures/docs.cc +0 -1
  64. data/spec/ffi/clang/fixtures/docs.h +0 -54
  65. data/spec/ffi/clang/fixtures/list.c +0 -11
  66. data/spec/ffi/clang/fixtures/location1.c +0 -7
  67. data/spec/ffi/clang/fixtures/simple.ast +0 -0
  68. data/spec/ffi/clang/fixtures/simple.c +0 -3
  69. data/spec/ffi/clang/fixtures/test.cxx +0 -62
  70. data/spec/ffi/clang/index_spec.rb +0 -90
  71. data/spec/ffi/clang/source_location_spec.rb +0 -138
  72. data/spec/ffi/clang/source_range_spec.rb +0 -74
  73. data/spec/ffi/clang/token_spec.rb +0 -82
  74. data/spec/ffi/clang/translation_unit_spec.rb +0 -214
  75. data/spec/ffi/clang/type_spec.rb +0 -273
  76. data/spec/ffi/clang/version_spec.rb +0 -28
  77. data/spec/spec_helper.rb +0 -51
@@ -1,701 +0,0 @@
1
- # Copyright, 2010-2012 by Jari Bakken.
2
- # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com>
3
- # Copyright, 2013, by Garry C. Marshall. <http://www.meaningfulname.net>
4
- # Copyright, 2014, by Masahiro Sano.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in
14
- # all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
- # THE SOFTWARE.
23
-
24
- describe "Function Call Cursors" do
25
- let(:translation_unit) {Index.new.parse_translation_unit(fixture_path("class.cpp"))}
26
- let(:cursor) {translation_unit.cursor}
27
- let(:call) {find_first(cursor, :cursor_call_expr)}
28
-
29
- it "should parse correctly" do
30
- expect(translation_unit.diagnostics).to be_empty
31
- end
32
-
33
- it "should find a method call" do
34
- expect(call).to_not be_nil
35
- end
36
- end
37
-
38
-
39
- describe Cursor do
40
- let(:cursor) { Index.new.parse_translation_unit(fixture_path("list.c")).cursor }
41
- let(:cursor_cxx) { Index.new.parse_translation_unit(fixture_path("test.cxx")).cursor }
42
- let(:cursor_canon) { Index.new.parse_translation_unit(fixture_path("canonical.c")).cursor }
43
- let(:cursor_pp) { Index.new.parse_translation_unit(fixture_path("docs.c"),[],[],{detailed_preprocessing_record: true}).cursor }
44
-
45
- it "can be obtained from a translation unit" do
46
- expect(cursor).to be_kind_of(Cursor)
47
- expect(cursor.kind).to equal(:cursor_translation_unit)
48
- expect(cursor.null?).to equal(false)
49
- expect(cursor.translation_unit?).to equal(true)
50
- end
51
-
52
- it "returns the source location of the cursor" do
53
- location = cursor.location
54
- expect(location).to be_kind_of(SourceLocation)
55
- end
56
-
57
- describe '#extent' do
58
- let(:extent) { cursor.extent }
59
- it "has an extent which is a SourceRange" do
60
- expect(extent).to be_kind_of(SourceRange)
61
- end
62
-
63
- it 'has filename and posion at start point' do
64
- expect(extent.start.file).to eq(fixture_path("list.c"))
65
- expect(extent.start.line).to equal(1)
66
- end
67
-
68
- it 'has filename and posion at end point' do
69
- expect(extent.end.file).to eq(fixture_path("list.c"))
70
- expect(extent.end.line).to equal(12)
71
- end
72
- end
73
-
74
- it "returns the path of the translation unit for the translation unit cursor" do
75
- expect(cursor.display_name).to eq(fixture_path("list.c"))
76
- expect(cursor.spelling).to eq(fixture_path("list.c"))
77
- end
78
-
79
- it "allows us to visit its children" do
80
- counter = 0
81
- cursor.visit_children do |cursor, parent|
82
- counter += 1
83
- :recurse
84
- end
85
- expect(counter).not_to equal(0)
86
- end
87
-
88
- describe "Null Cursor" do
89
- it "can be a null cursor" do
90
- expect(Cursor.null_cursor).to be_kind_of(Cursor)
91
- expect(Cursor.null_cursor.kind).to equal(:cursor_invalid_file)
92
- end
93
-
94
- it "is null?" do
95
- expect(Cursor.null_cursor.null?).to equal(true)
96
- end
97
-
98
- it "is invalid?" do
99
- expect(Cursor.null_cursor.invalid?).to equal(true)
100
- end
101
-
102
- it "compares as equal to another null cursor instance" do
103
- expect(Cursor.null_cursor).to eq(Cursor.null_cursor)
104
- end
105
-
106
- it "should not equal a Translation Unit cursor" do
107
- expect(Cursor.null_cursor).not_to eq(cursor)
108
- end
109
- end
110
-
111
- describe "Function Cursors" do
112
- let (:func) { find_first(cursor, :cursor_function) }
113
-
114
- it "is not invalid?" do
115
- expect(func.invalid?).to equal(false)
116
- end
117
-
118
- it "can find the first function declaration" do
119
- expect(func).not_to equal(nil)
120
- expect(func.kind).to equal(:cursor_function)
121
- end
122
-
123
- it "has an extent representing the bounds of the function" do
124
- expect(func.extent).to be_kind_of(SourceRange)
125
- expect(func.extent.start.line).to equal(5)
126
- expect(func.extent.end.line).to equal(5)
127
- end
128
-
129
- it "returns the name of the function" do
130
- expect(func.spelling).to eq("sum")
131
- expect(func.display_name).to eq("sum(union List *)")
132
- end
133
- end
134
-
135
- describe "Struct Cursors" do
136
- let (:struct) { find_first(cursor, :cursor_struct) }
137
-
138
- it "can find the first struct" do
139
- expect(struct).not_to equal(nil)
140
- expect(struct.kind).to equal(:cursor_struct)
141
- end
142
-
143
- it "has an extent representing the bounds of the struct" do
144
- expect(struct.extent.start.line).to equal(1)
145
- expect(struct.extent.end.line).to equal(4)
146
- end
147
-
148
- it "returns the name of the struct" do
149
- expect(struct.spelling).to eq("List")
150
- expect(struct.display_name).to eq("List")
151
- end
152
-
153
- end
154
-
155
- describe '#kind_spelling' do
156
- let (:struct) { find_first(cursor, :cursor_struct) }
157
-
158
- it "returns the spelling of the given kind" do
159
- expect(struct.kind_spelling).to eq('StructDecl')
160
- end
161
- end
162
-
163
- describe '#declaration?' do
164
- let (:struct) { find_first(cursor, :cursor_struct) }
165
-
166
- it "checks the cursor is declaration" do
167
- expect(struct.declaration?).to be true
168
- end
169
- end
170
-
171
- describe '#reference?' do
172
- let (:ref) { find_first(cursor, :cursor_type_ref) }
173
-
174
- it "checks the cursor is reference" do
175
- expect(ref.reference?).to be true
176
- end
177
- end
178
-
179
- describe '#expression?' do
180
- let (:literal) { find_first(cursor, :cursor_integer_literal) }
181
-
182
- it "checks the cursor is expression" do
183
- expect(literal.expression?).to be true
184
- end
185
- end
186
-
187
- describe '#statement?' do
188
- let (:return_stmt) { find_first(cursor, :cursor_return_stmt) }
189
-
190
- it "checks the cursor is statement" do
191
- expect(return_stmt.statement?).to be true
192
- end
193
- end
194
-
195
- describe '#attribute?' do
196
- let (:attr) { find_first(cursor_cxx, :cursor_unexposed_attr) }
197
-
198
- it "checks the cursor is attribute" do
199
- expect(attr.attribute?).to be true
200
- end
201
- end
202
-
203
- describe '#public?' do
204
- let(:public_cursor) { find_matching(cursor_cxx) { |child, parent|
205
- child.kind == :cursor_field_decl and child.spelling == 'public_member_int' } }
206
-
207
- it 'checks access control level is public' do
208
- expect(public_cursor.public?).to be true
209
- end
210
- end
211
-
212
- describe '#private?' do
213
- let(:private_cursor) { find_matching(cursor_cxx) { |child, parent|
214
- child.kind == :cursor_field_decl and child.spelling == 'private_member_int' } }
215
-
216
- it 'checks access control level is private' do
217
- expect(private_cursor.private?).to be true
218
- end
219
- end
220
-
221
- describe '#protected?' do
222
- let(:protected_cursor) { find_matching(cursor_cxx) { |child, parent|
223
- child.kind == :cursor_field_decl and child.spelling == 'protected_member_int' } }
224
-
225
- it 'checks access control level is protected' do
226
- expect(protected_cursor.protected?).to be true
227
- end
228
- end
229
-
230
- describe '#preprocessing?' do
231
- let (:pp) { find_first(cursor_pp, :cursor_macro_definition) }
232
-
233
- it 'checks the cursor is preprocessing' do
234
- expect(pp.preprocessing?).to be true
235
- end
236
- end
237
-
238
- describe '#unexposed?' do
239
- let(:unexposed_cursor) { find_matching(cursor_cxx) { |child, parent|
240
- child.kind == :cursor_unexposed_expr and child.spelling == 'func_overloaded' } }
241
-
242
- it 'checks the cursor is unexposed' do
243
- expect(unexposed_cursor.unexposed?).to be true
244
- end
245
- end
246
-
247
- describe '#virtual_base?' do
248
- let(:virtual_base_cursor) { find_matching(cursor_cxx) { |child, parent|
249
- child.kind == :cursor_cxx_base_specifier and parent.spelling == 'B' } }
250
-
251
- it 'checks cursor is virtual base' do
252
- expect(virtual_base_cursor.virtual_base?).to equal true
253
- end
254
- end
255
-
256
- describe '#virtual?' do
257
- let(:virtual_cursor) { find_matching(cursor_cxx) { |child, parent|
258
- child.kind == :cursor_cxx_method and child.spelling == 'func_a' } }
259
-
260
- it 'checks member function is virtual' do
261
- expect(virtual_cursor.virtual?).to equal true
262
- end
263
- end
264
-
265
- describe '#pure_virtual?' do
266
- let(:pure_virtual_cursor) { find_matching(cursor_cxx) { |child, parent|
267
- child.kind == :cursor_cxx_method and
268
- child.spelling == 'func_a' and parent.spelling == 'A' } }
269
-
270
- it 'checks member function is purely virtual' do
271
- expect(pure_virtual_cursor.pure_virtual?).to equal true
272
- end
273
- end
274
-
275
- describe '#static?' do
276
- let(:static_method_cursor) { find_matching(cursor_cxx) { |child, parent|
277
- child.kind == :cursor_cxx_method and child.spelling == 'func_b' } }
278
-
279
- it 'checks cursor is static member function' do
280
- expect(static_method_cursor.static?).to equal true
281
- end
282
- end
283
-
284
- describe '#enum_value' do
285
- let(:enum_value_cursor) { find_matching(cursor_cxx) { |child, parent|
286
- child.kind == :cursor_enum_constant_decl and child.spelling == 'EnumC' } }
287
-
288
- it 'returns enum value' do
289
- expect(enum_value_cursor.enum_value).to equal 100
290
- end
291
- end
292
-
293
- describe '#enum_unsigned_value' do
294
- let(:enum_value_cursor) { find_matching(cursor_cxx) { |child, parent|
295
- child.kind == :cursor_enum_constant_decl and child.spelling == 'EnumC' } }
296
-
297
- it 'returns enum unsigned value' do
298
- expect(enum_value_cursor.enum_unsigned_value).to eq(100)
299
- end
300
- end
301
-
302
- describe '#dynamic_call?' do
303
- let(:dynamic_call) { find_matching(cursor_cxx) { |child, parent|
304
- child.kind == :cursor_call_expr and child.spelling == 'func_a' and
305
- child.semantic_parent.spelling == 'f_dynamic_call' } }
306
-
307
- it 'checks if the method call is dynamic' do
308
- expect(dynamic_call.dynamic_call?).to be true
309
- end
310
- end
311
-
312
- describe '#specialized_template' do # looks not working on 3.2
313
- let(:cursor_function) { find_matching(cursor_cxx) { |child, parent|
314
- child.kind == :cursor_function and child.spelling == 'func_overloaded' } }
315
-
316
- it "returns a cursor that may represent a specialization or instantiation of a template" do
317
- expect(cursor_function.specialized_template).to be_kind_of(Cursor)
318
- expect(cursor_function.specialized_template.kind).to be(:cursor_function_template)
319
- end
320
- end
321
-
322
- describe '#canonical' do
323
- let (:structs) { find_all(cursor_canon, :cursor_struct) }
324
-
325
- it "mathes 3 cursors" do
326
- expect(structs.size).to eq(3)
327
- end
328
-
329
- it "refers the first cursor as canonical one" do
330
- expect(structs[0].canonical).to eq(structs[0])
331
- expect(structs[1].canonical).to eq(structs[0])
332
- expect(structs[2].canonical).to eq(structs[0])
333
- end
334
- end
335
-
336
- describe '#definition' do
337
- let (:structs) { find_all(cursor_canon, :cursor_struct) }
338
-
339
- it "mathes 3 cursors" do
340
- expect(structs.size).to eq(3)
341
- end
342
-
343
- it "refers the third cursor as definition one" do
344
- expect(structs[0].definition).to eq(structs[2])
345
- expect(structs[1].definition).to eq(structs[2])
346
- expect(structs[2].definition).to eq(structs[2])
347
- end
348
- end
349
-
350
- describe '#template_kind' do # looks not working on 3.2
351
- let(:template) { find_matching(cursor_cxx) { |child, parent|
352
- child.kind == :cursor_function_template and child.spelling == 'func_overloaded' } }
353
-
354
- it "returns the cursor kind of the specializations would be generated" do
355
- expect(template.template_kind).to be_kind_of(Symbol)
356
- expect(template.template_kind).to be(:cursor_function)
357
- end
358
- end
359
-
360
- describe '#access_specifier' do
361
- let(:access_specifier_cursor) { find_matching(cursor_cxx) { |child, parent|
362
- child.kind == :cursor_cxx_method and child.spelling == 'func_d' } }
363
-
364
- it 'returns access specifier symbol' do
365
- expect(access_specifier_cursor.access_specifier).to equal :private
366
- end
367
- end
368
-
369
- describe '#language' do
370
- let(:c_language_cursor) { find_matching(cursor) { |c, p| c.kind == :cursor_struct } }
371
- let(:cxx_language_cursor) { find_matching(cursor_cxx) { |c, p| c.kind == :cursor_struct } }
372
-
373
- it 'returns :c if the cursor language is C' do
374
- expect(c_language_cursor.language).to equal :c
375
- end
376
-
377
- it 'returns :c_plus_plus if the cursor language is C++' do
378
- expect(cxx_language_cursor.language).to equal :c_plus_plus
379
- end
380
- end
381
-
382
- describe '#translation_unit' do
383
- let (:struct) { find_first(cursor, :cursor_struct) }
384
-
385
- it "can find the first struct" do
386
- expect(struct).not_to equal(nil)
387
- end
388
-
389
- it "returns the translation unit that a cursor originated from" do
390
- expect(struct.translation_unit).to be_kind_of(TranslationUnit)
391
- expect(struct.translation_unit.spelling).to eq(fixture_path("list.c"))
392
- end
393
- end
394
-
395
- describe '#linkage' do
396
- let (:ref) { find_first(cursor, :cursor_type_ref) }
397
- let (:func) { find_first(cursor, :cursor_function) }
398
-
399
- it "returns :external if the cursor is non-static function" do
400
- expect(func.linkage).to equal :external
401
- end
402
-
403
- it "returns :invalid if the cursor does not have linkage" do
404
- expect(ref.linkage).to equal :invalid
405
- end
406
- end
407
-
408
- describe '#semantic_parent' do
409
- let(:parent) { find_matching(cursor_cxx) { |child, parent|
410
- child.kind == :cursor_cxx_method and child.spelling == 'func_d' and parent.spelling != 'D' } }
411
-
412
- it 'returns base class as semantic parent' do
413
- expect(parent.semantic_parent.spelling).to eq('D')
414
- end
415
- end
416
-
417
- describe '#lexical_parent' do
418
- let(:parent) { find_matching(cursor_cxx) { |child, parent|
419
- child.kind == :cursor_cxx_method and child.spelling == 'func_d' and parent.spelling != 'D' } }
420
-
421
- it 'returns translation unit as lexical parent' do
422
- expect(parent.lexical_parent.kind).to eq(:cursor_translation_unit)
423
- end
424
- end
425
-
426
- describe '#included_file' do
427
- #TODO
428
- end
429
-
430
- describe '#definition?' do
431
- let (:struct) { find_all(cursor_canon, :cursor_struct).at(2) }
432
-
433
- it "checks cursor is a definition" do
434
- expect(struct.definition?).to be true
435
- end
436
- end
437
-
438
- describe '#usr' do
439
- let (:func) { find_first(cursor, :cursor_function) }
440
-
441
- it "returns something in string" do
442
- expect(func.usr).to be_kind_of(String)
443
- end
444
- end
445
-
446
- describe '#variadic?' do
447
- let(:func) { find_matching(cursor_cxx) { |child, parent|
448
- child.kind == :cursor_function and child.spelling == 'f_variadic' } }
449
-
450
- it "checks cursor is a variadic function" do
451
- expect(func.variadic?).to be true
452
- end
453
- end
454
-
455
- describe '#referenced' do
456
- let(:struct) { find_matching(cursor_cxx) { |child, parent|
457
- child.kind == :cursor_struct and child.spelling == 'A' } }
458
- let(:ref) { find_matching(cursor_cxx) { |child, parent|
459
- child.kind == :cursor_type_ref and child.spelling == 'struct A' } }
460
-
461
- it "returns a cursor that this cursor references" do
462
- expect(ref.referenced).to eq(struct)
463
- end
464
-
465
- end
466
-
467
- describe '#hash' do
468
- let (:func) { find_first(cursor, :cursor_function) }
469
-
470
- it "computes hash for the cursor" do
471
- expect(func.hash).to be_kind_of(Fixnum)
472
- end
473
- end
474
-
475
- describe '#availability' do
476
- let (:func) { find_first(cursor, :cursor_function) }
477
-
478
- it "returns :available for the cursor availability" do
479
- expect(func.availability).to equal(:available)
480
- end
481
- end
482
-
483
- describe '#type' do
484
- let (:field) { find_first(cursor, :cursor_field_decl) }
485
-
486
- it "returns type for the cursor" do
487
- expect(field.type).to be_kind_of(Type)
488
- expect(field.type.kind).to equal(:type_int)
489
- end
490
- end
491
-
492
- describe '#underlying_type' do
493
- let (:typedef) { find_first(cursor_cxx, :cursor_typedef_decl) }
494
-
495
- it "returns type that the cursor type is underlying" do
496
- expect(typedef.underlying_type).to be_kind_of(Type)
497
- expect(typedef.underlying_type.kind).to equal(:type_pointer)
498
- end
499
- end
500
-
501
- describe '#bitfield?' do
502
- let(:bitfield) { find_matching(cursor_cxx) { |child, parent|
503
- child.kind == :cursor_field_decl and child.spelling == 'bit_field_a' } }
504
- let(:non_bitfield) { find_matching(cursor_cxx) { |child, parent|
505
- child.kind == :cursor_field_decl and child.spelling == 'non_bit_field_c' } }
506
-
507
- it "returns true if the cursor is bitfield" do
508
- expect(bitfield.bitfield?).to be true
509
- end
510
-
511
- it "returns false if the cursor is not bitfield" do
512
- expect(non_bitfield.bitfield?).to be false
513
- end
514
- end
515
-
516
- describe '#bitwidth' do
517
- let(:bitfield) { find_matching(cursor_cxx) { |child, parent|
518
- child.kind == :cursor_field_decl and child.spelling == 'bit_field_a' } }
519
- let(:non_bitfield) { find_matching(cursor_cxx) { |child, parent|
520
- child.kind == :cursor_field_decl and child.spelling == 'non_bit_field_c' } }
521
-
522
- it "returns the bit width of the bit field if the cursor is bitfield" do
523
- expect(bitfield.bitwidth).to be_kind_of(Integer)
524
- expect(bitfield.bitwidth).to eq(2)
525
- end
526
-
527
- it "returns -1 if the cursor is not bitfield" do
528
- expect(non_bitfield.bitwidth).to eq(-1)
529
- end
530
- end
531
-
532
- describe '#enum_decl_integer_type' do
533
- let(:enum) { find_matching(cursor_cxx) { |child, parent|
534
- child.kind == :cursor_enum_decl and child.spelling == 'normal_enum' } }
535
-
536
- it "returns the integer type of the enum declaration" do
537
- expect(enum.enum_decl_integer_type).to be_kind_of(Type)
538
- expect(enum.enum_decl_integer_type.kind).to be(:type_uint)
539
- end
540
- end
541
-
542
- describe '#platform_availability' do
543
- let(:func) { find_matching(cursor_cxx) { |child, parent|
544
- child.kind == :cursor_function and child.spelling == 'availability_func'} }
545
- let(:availability) { func.platform_availability }
546
-
547
- it "returns the availability of the entity as Hash" do
548
- expect(availability).to be_kind_of(Hash)
549
- expect(availability[:always_deprecated]).to be_kind_of(Integer)
550
- expect(availability[:always_unavailable]).to be_kind_of(Integer)
551
- expect(availability[:deprecated_message]).to be_kind_of(String)
552
- expect(availability[:unavailable_message]).to be_kind_of(String)
553
- expect(availability[:availability]).to be_kind_of(Array)
554
- end
555
- end
556
-
557
- describe '#overriddens' do
558
- let(:override_cursor) { find_matching(cursor_cxx) { |child, parent|
559
- child.kind == :cursor_cxx_method and
560
- child.spelling == 'func_a' and parent.spelling == 'D' } }
561
-
562
- it "returns the set of methods which are overridden by this cursor method" do
563
- expect(override_cursor.overriddens).to be_kind_of(Array)
564
- expect(override_cursor.overriddens.size).to eq(2)
565
- expect(override_cursor.overriddens.map{|cur| cur.semantic_parent.spelling}).to eq(["B", "C"])
566
- end
567
- end
568
-
569
- describe '#overloaded_decl' do
570
- let(:overloaded) { find_matching(cursor_cxx) { |child, parent|
571
- child.kind == :cursor_overloaded_decl_ref and child.spelling == 'func_overloaded' } }
572
-
573
- it "returns a cursor for one of the overloaded declarations" do
574
- expect(overloaded.overloaded_decl(0)).to be_kind_of(Cursor)
575
- expect(overloaded.overloaded_decl(0).kind).to be(:cursor_function_template)
576
- expect(overloaded.overloaded_decl(0).spelling).to eq('func_overloaded')
577
- end
578
- end
579
-
580
- describe '#num_overloaded_decls' do
581
- let(:overloaded) { find_matching(cursor_cxx) { |child, parent|
582
- child.kind == :cursor_overloaded_decl_ref and child.spelling == 'func_overloaded' } }
583
-
584
- it "returns the number of overloaded declarations" do
585
- expect(overloaded.num_overloaded_decls).to be_kind_of(Integer)
586
- expect(overloaded.num_overloaded_decls).to be(2)
587
- end
588
- end
589
-
590
- describe '#objc_type_encoding' do
591
- #TODO
592
- end
593
-
594
- describe '#argument' do
595
- let(:func) { find_matching(cursor_cxx) { |child, parent|
596
- child.kind == :cursor_function and child.spelling == 'f_non_variadic' } }
597
-
598
- it "returns the argument cursor of the function" do
599
- expect(func.argument(0)).to be_kind_of(Cursor)
600
- expect(func.argument(0).spelling).to eq('a')
601
- end
602
- end
603
-
604
- describe '#num_arguments' do
605
- let(:cursor_cxx) { Index.new.parse_translation_unit(fixture_path("test.cxx")).cursor }
606
- let(:func) { find_matching(cursor_cxx) { |child, parent|
607
- child.kind == :cursor_function and child.spelling == 'f_non_variadic' } }
608
-
609
- it "returns the number of non-variadic arguments" do
610
- expect(func.num_arguments).to be_kind_of(Integer)
611
- expect(func.num_arguments).to be(3)
612
- end
613
- end
614
-
615
- describe '#result_type' do
616
- let(:func) { find_matching(cursor_cxx) { |child, parent|
617
- child.kind == :cursor_function and child.spelling == 'f_non_variadic' } }
618
-
619
- it "result the result type of the function" do
620
- expect(func.result_type).to be_kind_of(Type)
621
- expect(func.result_type.kind).to be(:type_void)
622
- end
623
- end
624
-
625
- describe '#raw_comment_text' do
626
- let(:func) { find_matching(cursor_pp) { |child, parent|
627
- child.kind == :cursor_function and child.spelling == 'a_function' } }
628
-
629
- it "checks the cursor is declaration" do
630
- expect(func.raw_comment_text).to be_kind_of(String)
631
- expect(func.raw_comment_text).not_to be_empty
632
- end
633
- end
634
-
635
- describe '#comment' do
636
- let(:func) { find_matching(cursor_pp) { |child, parent|
637
- child.kind == :cursor_function and child.spelling == 'a_function' } }
638
-
639
- it "checks the cursor is declaration" do
640
- expect(func.comment).to be_kind_of(Comment)
641
- end
642
- end
643
-
644
- describe '#included_file' do
645
- let (:inclusion) { find_first(cursor_pp, :cursor_inclusion_directive) }
646
-
647
- it 'returns the file that is included by the given inclusion directive cursor' do
648
- expect(inclusion.included_file).to be_kind_of(FFI::Clang::File)
649
- expect(File.basename(inclusion.included_file.name)).to eq("docs.h")
650
- end
651
- end
652
-
653
- describe Cursor::PlatformAvailability do
654
- let(:func) { find_matching(cursor_cxx) { |child, parent|
655
- child.kind == :cursor_function and child.spelling == 'availability_func'} }
656
- let(:availability) { func.platform_availability[:availability].first }
657
-
658
- it "can be obtained by Cursor#platform_availability" do
659
- expect(availability).to be_kind_of(Cursor::PlatformAvailability)
660
- end
661
-
662
- describe "#platform" do
663
- it "returns availability information for the platform" do
664
- expect(availability.platform).to be_kind_of(String)
665
- end
666
- end
667
-
668
- describe "#introduced" do
669
- it "returns the version number in which this entity was introduced" do
670
- expect(availability.introduced).to be_kind_of(Lib::CXVersion)
671
- expect(availability.introduced.to_s).to eq("10.4.1")
672
- end
673
- end
674
-
675
- describe "#deprecated" do
676
- it "returns the version number in which this entity was deprecated" do
677
- expect(availability.deprecated).to be_kind_of(Lib::CXVersion)
678
- expect(availability.deprecated.to_s).to eq("10.6")
679
- end
680
- end
681
-
682
- describe "#obsoleted" do
683
- it "returns the version number in which this entity was obsoleted" do
684
- expect(availability.obsoleted).to be_kind_of(Lib::CXVersion)
685
- expect(availability.obsoleted.to_s).to eq("10.7")
686
- end
687
- end
688
-
689
- describe "#unavailable" do
690
- it "returns whether the entity is unavailable on this platform" do
691
- expect(availability.unavailable).to be false
692
- end
693
- end
694
-
695
- describe "#message" do
696
- it "returns an optional message to provide to a user of this API" do
697
- expect(availability.message).to be_kind_of(String)
698
- end
699
- end
700
- end
701
- end