ffi-clang 0.6.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9cc050343b09622e74559239ce649bbda2d777ec48ca34a694ec2e86ff7adb8d
4
- data.tar.gz: c5a87040ba99b6adbeeaa4ce2db643a4dce996c127adbdfc7dc1a13d7f489279
3
+ metadata.gz: 371454aeb7550fde909b4e944d5371e8c56a3b07551fb4321b9761db71c65290
4
+ data.tar.gz: 95d22ce375a63f2ab4a2881c39b048393297246684af30751ba70e1886957473
5
5
  SHA512:
6
- metadata.gz: 0bbfe4335e44c46de7a97c8afa8fdc1fdb4008558dd7c46b5ece6db0275e0ce424910a49ff4edce9442887c048cc39f9305a982f55871a7c152f6eac254db5d5
7
- data.tar.gz: c264998e24053cb04283313cbb2f07cbda23522e9c5e470c394db927e0ab99c677e9650abf17c9701a78775d277636454f664680e3fce0efd9bba9e1ef3d6f3b
6
+ metadata.gz: a89207faa58c1c78a44147d7405f88bce71734c33850f1b171b8f93ddaaaf3610521ad18ccd82ccbc327789bd674ef5aaa912d8bfb855729753eb0a640dc63b7
7
+ data.tar.gz: 3b8cf9d510d9abc186c4d695db6c6d4d2268f9b0fcfa8b7fd6261d19bf2fed8d052edbde8c5565ea13bd0e05bf61781f1f46a256add91e6e4feb34c8a9298699
data/.editorconfig ADDED
@@ -0,0 +1,23 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ trim_trailing_whitespace = false
8
+ indent_style = tab
9
+
10
+ [{*.{rb,gemspec},Gemfile,Rakefile}]
11
+ indent_size = 2
12
+
13
+ [*.{c,cc,cpp,cxx,h,hpp,hxx}]
14
+ indent_size = 4
15
+
16
+ [*.json]
17
+ indent_size = 2
18
+
19
+ [*.yml]
20
+ indent_size = 2
21
+
22
+ [*.md]
23
+ indent_size = 4
data/Gemfile CHANGED
@@ -2,12 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :development do
6
- gem 'transpec'
7
- gem 'pry'
5
+ group :maintenance, optional: true do
6
+ gem "bake-gem"
7
+ gem "bake-modernize"
8
8
  end
9
9
 
10
10
  group :test do
11
11
  gem 'simplecov'
12
- gem 'coveralls', require: false
13
12
  end
data/ffi-clang.gemspec CHANGED
@@ -7,7 +7,6 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "ffi-clang"
8
8
  spec.version = FFI::Clang::VERSION
9
9
  spec.authors = ["Jari Bakken", "Samuel Williams"]
10
- spec.email = ["Jari Bakken", "samuel.williams@oriontransfer.co.nz"]
11
10
  spec.description = %q{Ruby FFI bindings for libclang C interface.}
12
11
  spec.summary = %q{Ruby FFI bindings for libclang C interface.}
13
12
  spec.homepage = ""
@@ -20,7 +19,7 @@ Gem::Specification.new do |spec|
20
19
 
21
20
  spec.add_dependency "ffi"
22
21
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rspec", "~> 3.4.0"
22
+ spec.add_development_dependency "bundler", ">= 1.3"
23
+ spec.add_development_dependency "rspec", ">= 3.4.0"
25
24
  spec.add_development_dependency "rake"
26
25
  end
@@ -24,6 +24,7 @@ require_relative 'lib/cursor'
24
24
  require_relative 'lib/code_completion'
25
25
 
26
26
  require_relative 'source_location'
27
+ require_relative 'source_range'
27
28
  require_relative 'comment'
28
29
  require_relative 'type'
29
30
 
@@ -251,6 +252,18 @@ module FFI
251
252
  Lib.visit_children(@cursor, adapter, nil)
252
253
  end
253
254
 
255
+ def find_references_in_file(file = nil, &block)
256
+ file ||= Lib.extract_string Lib.get_translation_unit_spelling(@translation_unit)
257
+
258
+ visit_adapter = Proc.new do |unused, cxcursor, cxsource_range|
259
+ block.call Cursor.new(cxcursor, @translation_unit), SourceRange.new(cxsource_range)
260
+ end
261
+ visitor = FFI::Clang::Lib::CXCursorAndRangeVisitor.new
262
+ visitor[:visit] = visit_adapter
263
+
264
+ Lib.find_references_in_file(@cursor, Lib.get_file(@translation_unit, file), visitor)
265
+ end
266
+
254
267
  def linkage
255
268
  Lib.get_cursor_linkage(@cursor)
256
269
  end
@@ -381,6 +394,15 @@ module FFI
381
394
  filter.collect{|child, parent| child}
382
395
  end
383
396
 
397
+ def references(file = nil)
398
+ refs = []
399
+ self.find_references_in_file(file) do |cursor, unused|
400
+ refs << cursor
401
+ :continue
402
+ end
403
+ refs
404
+ end
405
+
384
406
  class PlatformAvailability < AutoPointer
385
407
  def initialize(memory_pointer)
386
408
  pointer = FFI::Pointer.new(memory_pointer)
@@ -32,19 +32,24 @@ module FFI
32
32
  enum :cursor_kind, [
33
33
  :cursor_unexposed_decl, 1,
34
34
  :cursor_struct, 2,
35
+ # :cusor_struct_decl, :cursor_struct
35
36
  :cursor_union, 3,
37
+ # :cusor_union_decl, :cursor_union
36
38
  :cursor_class_decl, 4,
37
39
  :cursor_enum_decl, 5,
38
40
  :cursor_field_decl, 6,
39
41
  :cursor_enum_constant_decl, 7,
40
42
  :cursor_function, 8,
43
+ # :cursor_function_decl, :cursor_function,
41
44
  :cursor_variable, 9,
45
+ # :cursor_var_decl, :cursor_variable,
42
46
  :cursor_parm_decl, 10,
43
47
  :cursor_obj_c_interface_decl, 11,
44
48
  :cursor_obj_c_category_decl, 12,
45
49
  :cursor_obj_c_protocol_decl, 13,
46
50
  :cursor_obj_c_property_decl, 14,
47
51
  :cursor_obj_c_instance_var_decl, 15,
52
+ # :cursor_obj_c_ivar_decl, :cursor_obj_c_instance_var_decl,
48
53
  :cursor_obj_c_instance_method_decl, 16,
49
54
  :cursor_obj_c_class_method_decl, 17,
50
55
  :cursor_obj_c_implementation_decl, 18,
@@ -69,6 +74,9 @@ module FFI
69
74
  :cursor_obj_c_synthesize_decl, 37,
70
75
  :cursor_obj_c_dynamic_decl, 38,
71
76
  :cursor_cxx_access_specifier, 39,
77
+ # :cursor_first_decl, :cursor_unexposed_decl,
78
+ # :cursor_last_decl, :cursor_cxx_access_specifier,
79
+ :cursor_first_ref, 40,
72
80
  :cursor_obj_c_super_class_ref, 40,
73
81
  :cursor_obj_c_protocol_ref, 41,
74
82
  :cursor_obj_c_class_ref, 42,
@@ -80,10 +88,14 @@ module FFI
80
88
  :cursor_label_ref, 48,
81
89
  :cursor_overloaded_decl_ref, 49,
82
90
  :cursor_variable_ref, 50,
91
+ # :cursor_last_ref, :cursor_variable_ref,
92
+ :cursor_first_invalid, 70,
83
93
  :cursor_invalid_file, 70,
84
94
  :cursor_no_decl_found, 71,
85
95
  :cursor_not_implemented, 72,
86
96
  :cursor_invalid_code, 73,
97
+ # :cursor_last_invalid, :cursor_invalid_code,
98
+ :cursor_first_expr, 100,
87
99
  :cursor_unexposed_expr, 100,
88
100
  :cursor_decl_ref_expr, 101,
89
101
  :cursor_member_ref_expr, 102,
@@ -113,25 +125,33 @@ module FFI
113
125
  :cursor_cxx_reinterpret_cast_expr, 126,
114
126
  :cursor_cxx_const_cast_expr, 127,
115
127
  :cursor_cxx_functional_cast_expr, 128,
116
- :cursor_cxx_typeid_expr, 129,
117
- :cursor_cxx_bool_literal_expr, 130,
118
- :cursor_cxx_null_ptr_literal_expr, 131,
119
- :cursor_cxx_this_expr, 132,
120
- :cursor_cxx_throw_expr, 133,
121
- :cursor_cxx_new_expr, 134,
122
- :cursor_cxx_delete_expr, 135,
123
- :cursor_unary_expr, 136,
124
- :cursor_obj_c_string_literal, 137,
125
- :cursor_obj_c_encode_expr, 138,
126
- :cursor_obj_c_selector_expr, 139,
127
- :cursor_obj_c_protocol_expr, 140,
128
- :cursor_obj_c_bridged_cast_expr, 141,
129
- :cursor_pack_expansion_expr, 142,
130
- :cursor_size_of_pack_expr, 143,
131
- :cursor_lambda_expr, 144,
132
- :cursor_obj_c_bool_literal_expr, 145,
133
- :cursor_obj_c_self_expr, 146,
128
+ :cursor_cxx_addrspace_cast_expr, 129,
129
+ :cursor_cxx_typeid_expr, 130,
130
+ :cursor_cxx_bool_literal_expr, 131,
131
+ :cursor_cxx_null_ptr_literal_expr, 132,
132
+ :cursor_cxx_this_expr, 133,
133
+ :cursor_cxx_throw_expr, 134,
134
+ :cursor_cxx_new_expr, 135,
135
+ :cursor_cxx_delete_expr, 136,
136
+ :cursor_unary_expr, 137,
137
+ :cursor_obj_c_string_literal, 138,
138
+ :cursor_obj_c_encode_expr, 139,
139
+ :cursor_obj_c_selector_expr, 140,
140
+ :cursor_obj_c_protocol_expr, 141,
141
+ :cursor_obj_c_bridged_cast_expr, 142,
142
+ :cursor_pack_expansion_expr, 143,
143
+ :cursor_size_of_pack_expr, 144,
144
+ :cursor_lambda_expr, 145,
145
+ :cursor_obj_c_bool_literal_expr, 146,
146
+ :cursor_obj_c_self_expr, 147,
147
+ :cursor_omp_array_section_expr, 148,
148
+ :cursor_obj_c_availability_check_expr, 149,
149
+ :cursor_fixed_point_literal, 150,
150
+ :cursor_omp_array_shaping_expr, 151,
151
+ :cursor_omp_iterator_expr, 152,
152
+ # :cursor_last_expr, :cursor_omp_iterator_expr,
134
153
  :cursor_unexposed_stmt, 200,
154
+ # :cursor_first_stmt, :cursor_unexposed_stmt,
135
155
  :cursor_label_stmt, 201,
136
156
  :cursor_compound_stmt, 202,
137
157
  :cursor_case_stmt, 203,
@@ -147,6 +167,7 @@ module FFI
147
167
  :cursor_break_stmt, 213,
148
168
  :cursor_return_stmt, 214,
149
169
  :cursor_gcc_asm_stmt, 215,
170
+ # :cursor_asm_stmt, :cursor_gcc_asm_stmt,
150
171
  :cursor_obj_c_at_try_stmt, 216,
151
172
  :cursor_obj_c_at_catch_stmt, 217,
152
173
  :cursor_obj_c_at_finally_stmt, 218,
@@ -164,7 +185,64 @@ module FFI
164
185
  :cursor_null_stmt, 230,
165
186
  :cursor_decl_stmt, 231,
166
187
  :cursor_omp_parallel_directive, 232,
188
+ :cursor_omp_simd_directive, 233,
189
+ :cursor_omp_for_directive, 234,
190
+ :cursor_omp_sections_directive, 235,
191
+ :cursor_omp_section_directive, 236,
192
+ :cursor_omp_single_directive, 237,
193
+ :cursor_omp_parallel_for_directive, 238,
194
+ :cursor_omp_parallel_sections_directive, 239,
195
+ :cursor_omp_task_directive, 240,
196
+ :cursor_omp_master_directive, 241,
197
+ :cursor_omp_critical_directive, 242,
198
+ :cursor_omp_taskyield_directive, 243,
199
+ :cursor_omp_barrier_directive, 244,
200
+ :cursor_omp_taskwait_directive, 245,
201
+ :cursor_omp_flush_directive, 246,
202
+ :cursor_seh_leave_stmt, 247,
203
+ :cursor_omp_ordered_directive, 248,
204
+ :cursor_omp_atomic_directive, 249,
205
+ :cursor_omp_for_simd_directive, 250,
206
+ :cursor_omp_parallel_for_simd_directive, 251,
207
+ :cursor_omp_target_directive, 252,
208
+ :cursor_omp_teams_directive, 253,
209
+ :cursor_omp_taskgroup_directive, 254,
210
+ :cursor_omp_cancellation_point_directive, 255,
211
+ :cursor_omp_cancel_directive, 256,
212
+ :cursor_omp_target_data_directive, 257,
213
+ :cursor_omp_task_loop_directive, 258,
214
+ :cursor_omp_task_loop_simd_directive, 259,
215
+ :cursor_omp_distribute_directive, 260,
216
+ :cursor_omp_target_enter_data_directive, 261,
217
+ :cursor_omp_target_exit_data_directive, 262,
218
+ :cursor_omp_target_parallel_directive, 263,
219
+ :cursor_omp_target_parallel_for_directive, 264,
220
+ :cursor_omp_target_update_directive, 265,
221
+ :cursor_omp_distribute_parallel_for_directive, 266,
222
+ :cursor_omp_distribute_parallel_for_simd_directive, 267,
223
+ :cursor_omp_distribute_simd_directive, 268,
224
+ :cursor_omp_target_parallel_for_simd_directive, 269,
225
+ :cursor_omp_target_simd_directive, 270,
226
+ :cursor_omp_teams_distribute_directive, 271,
227
+ :cursor_omp_teams_distribute_simd_directive, 272,
228
+ :cursor_omp_teams_distribute_parallel_for_simd_directive, 273,
229
+ :cursor_omp_teams_distribute_parallel_for_directive, 274,
230
+ :cursor_omp_target_teams_directive, 275,
231
+ :cursor_omp_target_teams_distribute_directive, 276,
232
+ :cursor_omp_target_teams_distribute_parallel_for_directive, 277,
233
+ :cursor_omp_target_teams_distribute_parallel_for_simd_directive, 278,
234
+ :cursor_omp_target_teams_distribute_simd_directive, 279,
235
+ :cursor_builtin_bit_cast_expr, 280,
236
+ :cursor_omp_master_task_loop_directive, 281,
237
+ :cursor_omp_parallel_master_task_loop_directive, 282,
238
+ :cursor_omp_master_task_loop_simd_directive, 283,
239
+ :cursor_omp_parallel_master_task_loop_simd_directive, 284,
240
+ :cursor_omp_parallel_master_directive, 285,
241
+ :cursor_omp_depobj_directive, 286,
242
+ :cursor_omp_scan_directive, 287,
243
+ # :cursor_last_stmt, :cursor_omp_scan_directive,
167
244
  :cursor_translation_unit, 300,
245
+ :cursor_first_attr, 400,
168
246
  :cursor_unexposed_attr, 400,
169
247
  :cursor_ibaction_attr, 401,
170
248
  :cursor_iboutlet_attr, 402,
@@ -174,11 +252,54 @@ module FFI
174
252
  :cursor_annotate_attr, 406,
175
253
  :cursor_asm_label_attr, 407,
176
254
  :cursor_packed_attr, 408,
255
+ :cursor_pure_attr, 409,
256
+ :cursor_const_attr, 410,
257
+ :cursor_no_duplicate_attr, 411,
258
+ :cursor_cuda_constant_attr, 412,
259
+ :cursor_cuda_device_attr, 413,
260
+ :cursor_cuda_global_attr, 414,
261
+ :cursor_cuda_host_attr, 415,
262
+ :cursor_cuda_shared_attr, 416,
263
+ :cursor_visibility_attr, 417,
264
+ :cursor_dll_export, 418,
265
+ :cursor_dll_import, 419,
266
+ :cursor_ns_returns_retained, 420,
267
+ :cursor_ns_returns_not_retained, 421,
268
+ :cursor_ns_returns_autoreleased, 422,
269
+ :cursor_ns_consumes_self, 423,
270
+ :cursor_ns_consumed, 424,
271
+ :cursor_obj_c_exception, 425,
272
+ :cursor_obj_c_ns_object, 426,
273
+ :cursor_obj_c_independent_class, 427,
274
+ :cursor_obj_c_precise_lifetime, 428,
275
+ :cursor_obj_c_returns_inner_pointer, 429,
276
+ :cursor_obj_c_requires_super, 430,
277
+ :cursor_obj_c_root_class, 431,
278
+ :cursor_obj_c_subclassing_restricted, 432,
279
+ :cursor_obj_c_explicit_protocol_impl, 433,
280
+ :cursor_obj_c_designated_initializer, 434,
281
+ :cursor_obj_c_runtime_visible, 435,
282
+ :cursor_obj_c_boxable, 436,
283
+ :cursor_flag_enum, 437,
284
+ :cursor_convergent_attr, 438,
285
+ :cursor_warn_unused_attr, 439,
286
+ :cursor_warn_unused_result_attr, 440,
287
+ :cursor_aligned_attr, 441,
288
+ # :cursor_last_attr, :cursor_aligned_attr,
177
289
  :cursor_preprocessing_directive, 500,
178
290
  :cursor_macro_definition, 501,
179
291
  :cursor_macro_expansion, 502,
292
+ # :cursor_macro_instantiation, :cursor_macro_expansion,
180
293
  :cursor_inclusion_directive, 503,
294
+ # :cursor_first_preprocessing, :cursor_preprocessing_directive,
295
+ # :cursor_last_preprocessing, :cursor_inclusion_directive,
181
296
  :cursor_module_import_decl, 600,
297
+ :cursor_type_alias_template_decl, 601,
298
+ :cursor_static_assert, 602,
299
+ :cursor_friend_decl, 603,
300
+ # :cursor_first_extra_decl, :cursor_module_import_decl,
301
+ # :cursor_last_extra_decl, :cursor_friend_decl,
302
+ :cursor_overload_candidate, 700
182
303
  ]
183
304
 
184
305
  enum :access_specifier, [
@@ -250,6 +371,15 @@ module FFI
250
371
  )
251
372
  end
252
373
 
374
+ enum :visitor_result, [:break, :continue]
375
+
376
+ class CXCursorAndRangeVisitor < FFI::Struct
377
+ layout(
378
+ :context, :pointer,
379
+ :visit, callback([:pointer, CXCursor.by_value, CXSourceRange.by_value], :visitor_result),
380
+ )
381
+ end
382
+
253
383
  enum :cxx_access_specifier, [:invalid, :public, :protected, :private]
254
384
  attach_function :get_cxx_access_specifier, :clang_getCXXAccessSpecifier, [CXCursor.by_value], :cxx_access_specifier
255
385
 
@@ -312,6 +442,9 @@ module FFI
312
442
  callback :visit_children_function, [CXCursor.by_value, CXCursor.by_value, :pointer], :child_visit_result
313
443
  attach_function :visit_children, :clang_visitChildren, [CXCursor.by_value, :visit_children_function, :pointer], :uint
314
444
 
445
+ enum :result, [:success, :invalid, :visit_break]
446
+ attach_function :find_references_in_file, :clang_findReferencesInFile, [CXCursor.by_value, :CXFile, CXCursorAndRangeVisitor.by_value], :result
447
+
315
448
  attach_function :get_cursor_type, :clang_getCursorType, [CXCursor.by_value], CXType.by_value
316
449
  attach_function :get_cursor_result_type, :clang_getCursorResultType, [CXCursor.by_value], CXType.by_value
317
450
  attach_function :get_typedef_decl_underlying_type, :clang_getTypedefDeclUnderlyingType, [CXCursor.by_value], CXType.by_value
@@ -22,18 +22,11 @@
22
22
  require_relative 'translation_unit'
23
23
  require_relative 'source_location'
24
24
  require_relative 'string'
25
+ require_relative 'source_range'
25
26
 
26
27
  module FFI
27
28
  module Clang
28
29
  module Lib
29
- class CXSourceRange < FFI::Struct
30
- layout(
31
- :ptr_data, [:pointer, 2],
32
- :begin_int_data, :uint,
33
- :end_int_data, :uint
34
- )
35
- end
36
-
37
30
  typedef :pointer, :CXDiagnostic
38
31
  typedef :pointer, :CXDiagnosticSet
39
32
 
@@ -96,7 +96,7 @@ module FFI
96
96
  attach_function :parse_translation_unit, :clang_parseTranslationUnit, [:CXIndex, :string, :pointer, :int, :pointer, :uint, :uint], :CXTranslationUnit
97
97
  attach_function :create_translation_unit, :clang_createTranslationUnit, [:CXIndex, :string], :CXTranslationUnit
98
98
  attach_function :dispose_translation_unit, :clang_disposeTranslationUnit, [:CXTranslationUnit], :void
99
- attach_function :get_translation_unit_spelling, :clang_getTranslationUnitSpelling, [:CXTranslationUnit], :string
99
+ attach_function :get_translation_unit_spelling, :clang_getTranslationUnitSpelling, [:CXTranslationUnit], CXString.by_value
100
100
 
101
101
  attach_function :default_editing_translation_unit_options, :clang_defaultEditingTranslationUnitOptions, [], :uint
102
102
  attach_function :default_save_options, :clang_defaultSaveOptions, [:CXTranslationUnit], :uint
data/lib/ffi/clang/lib.rb CHANGED
@@ -37,7 +37,15 @@ module FFI
37
37
  libs = []
38
38
  begin
39
39
  xcode_dir = `xcode-select -p`.chomp
40
- libs << "#{xcode_dir}/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib"
40
+ %W[
41
+ #{xcode_dir}/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib
42
+ #{xcode_dir}/usr/lib/libclang.dylib
43
+ ].each do |f|
44
+ if File.exist? f
45
+ libs << f
46
+ break
47
+ end
48
+ end
41
49
  rescue Errno::ENOENT
42
50
  # Ignore
43
51
  end
@@ -48,9 +56,14 @@ module FFI
48
56
  libs << ENV['LIBCLANG']
49
57
  elsif llvm_config
50
58
  llvm_library_dir = `#{llvm_config} --libdir`.chomp
51
-
52
- if FFI::Clang.platform == :darwin
59
+ platform = FFI::Clang.platform
60
+
61
+ case platform
62
+ when :darwin
53
63
  libs << llvm_library_dir + '/libclang.dylib'
64
+ when :windows
65
+ llvm_bin_dir = `#{llvm_config} --bindir`.chomp
66
+ libs << llvm_bin_dir + '/libclang.dll'
54
67
  else
55
68
  libs << llvm_library_dir + '/libclang.so'
56
69
  end
@@ -91,12 +91,16 @@ module FFI
91
91
  ExpansionLocation.new Lib.get_location_offset(self, file, offset)
92
92
  end
93
93
 
94
- def file(file_name)
95
- File.new(Lib.get_file(self, file_name), self)
94
+ def file(file_name = nil)
95
+ if file_name.nil?
96
+ File.new(Lib.get_file(self, spelling), self)
97
+ else
98
+ File.new(Lib.get_file(self, file_name), self)
99
+ end
96
100
  end
97
101
 
98
102
  def spelling
99
- Lib.get_translation_unit_spelling(self)
103
+ Lib.extract_string Lib.get_translation_unit_spelling(self)
100
104
  end
101
105
 
102
106
  def resource_usage
@@ -21,6 +21,6 @@
21
21
 
22
22
  module FFI
23
23
  module Clang
24
- VERSION = "0.6.0"
24
+ VERSION = "0.7.0"
25
25
  end
26
26
  end
@@ -47,7 +47,11 @@ describe CompilationDatabase do
47
47
 
48
48
  it "returns compile commands if the specified file is not found" do
49
49
  expect(cdb.compile_commands(not_found_file)).to be_kind_of(CompilationDatabase::CompileCommands)
50
- expect(cdb.compile_commands(not_found_file).size).to eq(0)
50
+ if FFI::Clang.clang_version_string[/\d+/].to_i >= 10
51
+ expect(cdb.compile_commands(not_found_file).size).to eq(1)
52
+ else
53
+ expect(cdb.compile_commands(not_found_file).size).to eq(0)
54
+ end
51
55
  end
52
56
  end
53
57
 
@@ -114,7 +118,7 @@ describe CompilationDatabase do
114
118
  describe '#num_args' do
115
119
  it "returns the number of CompileCommand" do
116
120
  expect(cmd.num_args).to be_kind_of(Integer)
117
- expect(cmd.num_args).to eq(31)
121
+ expect(cmd.num_args).to be >= 31 # clang may insert additional args
118
122
  end
119
123
  end
120
124
 
@@ -392,6 +392,28 @@ describe Cursor do
392
392
  end
393
393
  end
394
394
 
395
+ describe '#find_references_in_file' do
396
+ let (:struct_cursor) {find_first(cursor_canon, :cursor_struct) }
397
+
398
+ it "visits references to the cursor in the main file" do
399
+ counter = 0
400
+ struct_cursor.find_references_in_file do |ref_cursor, ref_src_loc|
401
+ counter += 1
402
+ :continue
403
+ end
404
+ expect(counter).not_to equal(0)
405
+ end
406
+
407
+ it "visits references to the cursor in the indicated file" do
408
+ counter = 0
409
+ struct_cursor.find_references_in_file(fixture_path("canonical.c")) do |ref_cursor, ref_src_loc|
410
+ counter += 1
411
+ :continue
412
+ end
413
+ expect(counter).not_to equal(0)
414
+ end
415
+ end
416
+
395
417
  describe '#linkage' do
396
418
  let (:ref) { find_first(cursor, :cursor_type_ref) }
397
419
  let (:func) { find_first(cursor, :cursor_function) }
@@ -650,6 +672,24 @@ describe Cursor do
650
672
  end
651
673
  end
652
674
 
675
+ describe '#references' do
676
+ let (:struct_cursor) { find_first(cursor_canon, :cursor_struct) }
677
+ let (:unspecified_references) { struct_cursor.references }
678
+ let (:specified_references) { struct_cursor.references(fixture_path("canonical.c")) }
679
+
680
+ it "returns an Array of reference Cursors in the main file" do
681
+ expect(unspecified_references).to be_kind_of(Array)
682
+ expect(unspecified_references.length).not_to equal(0)
683
+ expect(unspecified_references).to all(be_a (FFI::Clang::Cursor))
684
+ end
685
+
686
+ it "returns an Array of reference Cursors in the specified file" do
687
+ expect(specified_references).to be_kind_of(Array)
688
+ expect(specified_references.length).not_to equal(0)
689
+ expect(specified_references).to all(be_a (FFI::Clang::Cursor))
690
+ end
691
+ end
692
+
653
693
  describe Cursor::PlatformAvailability do
654
694
  let(:func) { find_matching(cursor_cxx) { |child, parent|
655
695
  child.kind == :cursor_function and child.spelling == 'availability_func'} }
@@ -59,10 +59,16 @@ describe TranslationUnit do
59
59
  end
60
60
 
61
61
  describe "#file" do
62
- let (:file) { translation_unit.file(fixture_path("a.c")) }
62
+ let (:specified_file) { translation_unit.file(fixture_path("a.c")) }
63
+ let (:unspecified_file) { translation_unit.file }
63
64
 
64
65
  it "returns File instance" do
65
- expect(file).to be_kind_of(FFI::Clang::File)
66
+ expect(specified_file).to be_kind_of(FFI::Clang::File)
67
+ end
68
+
69
+ it "returns main file when file name is not specified" do
70
+ expect(unspecified_file).to be_kind_of(FFI::Clang::File)
71
+ expect(unspecified_file.name).to include("a.c")
66
72
  end
67
73
  end
68
74
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-clang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
8
8
  - Samuel Williams
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-23 00:00:00.000000000 Z
12
+ date: 2022-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -29,28 +29,28 @@ dependencies:
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.3'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.3'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: 3.4.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: 3.4.0
56
56
  - !ruby/object:Gem::Dependency
@@ -69,12 +69,11 @@ dependencies:
69
69
  version: '0'
70
70
  description: Ruby FFI bindings for libclang C interface.
71
71
  email:
72
- - Jari Bakken
73
- - samuel.williams@oriontransfer.co.nz
74
72
  executables: []
75
73
  extensions: []
76
74
  extra_rdoc_files: []
77
75
  files:
76
+ - ".editorconfig"
78
77
  - ".gitignore"
79
78
  - ".rspec"
80
79
  - ".travis.yml"
@@ -149,7 +148,7 @@ homepage: ''
149
148
  licenses:
150
149
  - MIT
151
150
  metadata: {}
152
- post_install_message:
151
+ post_install_message:
153
152
  rdoc_options: []
154
153
  require_paths:
155
154
  - lib
@@ -164,8 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
163
  - !ruby/object:Gem::Version
165
164
  version: '0'
166
165
  requirements: []
167
- rubygems_version: 3.0.3
168
- signing_key:
166
+ rubygems_version: 3.3.7
167
+ signing_key:
169
168
  specification_version: 4
170
169
  summary: Ruby FFI bindings for libclang C interface.
171
170
  test_files: