rbind 0.0.26 → 0.0.27
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 +4 -4
- data/lib/rbind/core/hooks.rb +57 -0
- data/lib/rbind/core/rcast_operation.rb +14 -0
- data/lib/rbind/core/rclass.rb +93 -10
- data/lib/rbind/core/rnamespace.rb +20 -2
- data/lib/rbind/core.rb +2 -1
- data/lib/rbind/default_parser.rb +43 -26
- data/lib/rbind/generator_c.rb +60 -57
- data/lib/rbind/generator_extern.rb +7 -3
- data/lib/rbind/generator_ruby.rb +1 -1
- data/lib/rbind/logger.rb +2 -1
- data/lib/rbind/rbind.rb +23 -53
- data/lib/rbind/templates/c/CMakeLists.txt +8 -21
- data/lib/rbind/templates/c/cmake/FindRuby.cmake +15 -8
- data/lib/rbind/templates/c/operations.cc +1 -1
- data/lib/rbind/templates/c/operations.h +6 -3
- data/lib/rbind/templates/c/type_wrapper.h +1 -1
- data/lib/rbind/templates/c/types.h +9 -0
- data/lib/rbind/templates/ruby/rbind.rb +8 -2
- data/lib/rbind/tools/hdr_parser.py +43 -32
- data/manifest.xml +0 -2
- data/rbind.gemspec +2 -3
- metadata +9 -27
- data/lib/rbind/clang/clang.rb +0 -3719
- data/lib/rbind/clang/clang_types.rb +0 -338
- data/lib/rbind/clang_parser.rb +0 -523
- data/lib/rbind/templates/c/cmake/FindGem.cmake +0 -155
- data/lib/rbind/templates/c/find_gem.txt +0 -3
- data/lib/rbind/templates/c/rbind.pc.in +0 -11
@@ -1,338 +0,0 @@
|
|
1
|
-
module Clang
|
2
|
-
|
3
|
-
class Clang
|
4
|
-
@@index = Hash.new
|
5
|
-
attr_reader :units
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
ObjectSpace.define_finalizer(self, Clang.method(:finalize))
|
9
|
-
@index = Rbind::create_index(1, 1)
|
10
|
-
@@index[self.object_id] = @index
|
11
|
-
@units = []
|
12
|
-
end
|
13
|
-
|
14
|
-
def translation_unit(file,args)
|
15
|
-
raise ArgumentError,"File #{file} does not exist!" unless File.exist?(file)
|
16
|
-
@pargs = args.map do |a|
|
17
|
-
FFI::MemoryPointer.from_string(a)
|
18
|
-
end
|
19
|
-
@cargs = FFI::MemoryPointer.new(:pointer, @pargs.size)
|
20
|
-
@cargs.write_array_of_pointer(@pargs)
|
21
|
-
tu = Rbind::parse_translation_unit(@index,file,@cargs,@pargs.size,nil,0,1)
|
22
|
-
# auto release if Clang goes out of scope
|
23
|
-
# this cannot be encapsulate into the obj because
|
24
|
-
# each cursor can return a pointer to the unit
|
25
|
-
@units << TranslationUnitImplStruct.new(FFI::AutoPointer.new(tu.__obj_ptr__.pointer,TranslationUnitImplStruct.method(:release)))
|
26
|
-
tu
|
27
|
-
end
|
28
|
-
|
29
|
-
# dispose index
|
30
|
-
def self.finalize(id)
|
31
|
-
Rbind::dispose_index(@@index[id])
|
32
|
-
@@index.delete(id)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# A single translation unit, which resides in an index.
|
37
|
-
class TranslationUnitImplStruct < FFI::Struct
|
38
|
-
layout :dummy, :char
|
39
|
-
|
40
|
-
# do not call this for each instance !
|
41
|
-
# class Clang is taking care of this
|
42
|
-
def self.release(pointer)
|
43
|
-
Rbind::dispose_translation_unit(pointer) unless pointer.null?
|
44
|
-
rescue => e
|
45
|
-
puts e
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class TranslationUnitImpl
|
50
|
-
extend FFI::DataConverter
|
51
|
-
native_type FFI::Type::POINTER
|
52
|
-
|
53
|
-
def self.to_native(obj,context)
|
54
|
-
if obj.is_a? TranslationUnitImpl
|
55
|
-
obj.__obj_ptr__
|
56
|
-
else
|
57
|
-
raise TypeError, "expected kind of #{name}, was #{obj.class}"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.from_native(ptr,context)
|
62
|
-
TranslationUnitImpl.new(ptr)
|
63
|
-
end
|
64
|
-
|
65
|
-
attr_reader :__obj_ptr__
|
66
|
-
def initialize(ptr)
|
67
|
-
@__obj_ptr__ = if ptr.is_a? TranslationUnitImplStruct
|
68
|
-
ptr
|
69
|
-
else
|
70
|
-
TranslationUnitImplStruct.new(ptr)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def cursor
|
75
|
-
cu = Rbind::get_translation_unit_cursor(self)
|
76
|
-
cu.instance_variable_set(:@__translation_unit__,self)
|
77
|
-
cu
|
78
|
-
end
|
79
|
-
|
80
|
-
def spelling
|
81
|
-
Rbind::get_translation_unit_spelling(self).to_s
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# extend Structs to support auto dispose
|
86
|
-
module Rbind
|
87
|
-
class Cursor < FFI::Struct
|
88
|
-
extend ::Rbind::Logger
|
89
|
-
|
90
|
-
def null?
|
91
|
-
1 == Rbind::cursor_is_null(self)
|
92
|
-
end
|
93
|
-
|
94
|
-
def location
|
95
|
-
line = FFI::MemoryPointer.new(:uint,1)
|
96
|
-
col = FFI::MemoryPointer.new(:uint,1)
|
97
|
-
location = Rbind::get_cursor_location(self)
|
98
|
-
fstr = String.new
|
99
|
-
Rbind::get_presumed_location(location,fstr,line,col)
|
100
|
-
result = [fstr.to_s,line.get_uint(0),col.get_uint(0)]
|
101
|
-
result
|
102
|
-
end
|
103
|
-
|
104
|
-
def location_int
|
105
|
-
Rbind::get_cursor_location(self)[:int_data]
|
106
|
-
end
|
107
|
-
|
108
|
-
def referenced
|
109
|
-
Rbind::get_cursor_referenced self
|
110
|
-
end
|
111
|
-
|
112
|
-
def file_name
|
113
|
-
location[0]
|
114
|
-
end
|
115
|
-
|
116
|
-
def line
|
117
|
-
location[1]
|
118
|
-
end
|
119
|
-
|
120
|
-
def column
|
121
|
-
location[2]
|
122
|
-
end
|
123
|
-
|
124
|
-
def private?
|
125
|
-
cxx_access_specifier == :x_private
|
126
|
-
end
|
127
|
-
|
128
|
-
def public?
|
129
|
-
cxx_access_specifier == :x_public
|
130
|
-
end
|
131
|
-
|
132
|
-
def protected?
|
133
|
-
cxx_access_specifier == :x_protected
|
134
|
-
end
|
135
|
-
|
136
|
-
def cxx_access_specifier
|
137
|
-
Rbind::get_cxx_access_specifier self
|
138
|
-
end
|
139
|
-
|
140
|
-
def extent
|
141
|
-
Rbind::get_cursor_extent self
|
142
|
-
end
|
143
|
-
|
144
|
-
def semantic_parent
|
145
|
-
Rbind::get_cursor_semantic_parent self
|
146
|
-
end
|
147
|
-
|
148
|
-
def namespace
|
149
|
-
namespace = []
|
150
|
-
cursor = semantic_parent
|
151
|
-
while !cursor.translation_unit?
|
152
|
-
namespace << cursor.spelling
|
153
|
-
cursor = cursor.semantic_parent
|
154
|
-
if cursor.invalid_file?
|
155
|
-
Cursor.log.warn "Cursor #{self} with invalid file"
|
156
|
-
break
|
157
|
-
end
|
158
|
-
end
|
159
|
-
namespace = namespace.select{|s| !s.empty?}
|
160
|
-
namespace.reverse.join("::")
|
161
|
-
end
|
162
|
-
|
163
|
-
def translation_unit?
|
164
|
-
kind == :translation_unit
|
165
|
-
end
|
166
|
-
|
167
|
-
def invalid_file?
|
168
|
-
kind == :invalid_file
|
169
|
-
end
|
170
|
-
|
171
|
-
def expression
|
172
|
-
num = FFI::MemoryPointer.new(:uint,1)
|
173
|
-
tokens = FFI::MemoryPointer.new(:pointer,1)
|
174
|
-
tu = translation_unit
|
175
|
-
Rbind::tokenize(tu,extent,tokens,num)
|
176
|
-
ptr = FFI::Pointer.new(Token,tokens.read_pointer)
|
177
|
-
result = 0.upto(num.read_uint-1).map do |i|
|
178
|
-
Rbind::get_token_spelling(tu,ptr[i])
|
179
|
-
end
|
180
|
-
Rbind::dispose_tokens(tu,ptr,num.get_uint(0))
|
181
|
-
result
|
182
|
-
end
|
183
|
-
|
184
|
-
def result_type
|
185
|
-
Rbind::get_cursor_result_type self
|
186
|
-
end
|
187
|
-
|
188
|
-
def kind_spelling
|
189
|
-
Rbind::get_cursor_kind_spelling(self).to_s
|
190
|
-
end
|
191
|
-
|
192
|
-
def spelling
|
193
|
-
Rbind::get_cursor_spelling(self).to_s
|
194
|
-
end
|
195
|
-
|
196
|
-
def display_name
|
197
|
-
Rbind::get_cursor_display_name(self).to_s
|
198
|
-
end
|
199
|
-
|
200
|
-
def kind
|
201
|
-
Rbind::get_cursor_kind(self)
|
202
|
-
end
|
203
|
-
|
204
|
-
def translation_unit
|
205
|
-
Rbind::cursor_get_translation_unit(self)
|
206
|
-
end
|
207
|
-
|
208
|
-
def type
|
209
|
-
Rbind::get_cursor_type self
|
210
|
-
end
|
211
|
-
|
212
|
-
def virtual_base?
|
213
|
-
1 == Rbind::is_virtual_base(self)
|
214
|
-
end
|
215
|
-
|
216
|
-
def specialized_template
|
217
|
-
Rbind::get_specialized_cursor_template self
|
218
|
-
end
|
219
|
-
|
220
|
-
def template_kind
|
221
|
-
Rbind::get_template_cursor_kind self
|
222
|
-
end
|
223
|
-
|
224
|
-
def complete?
|
225
|
-
!incomplete?
|
226
|
-
end
|
227
|
-
|
228
|
-
def incomplete?
|
229
|
-
definition.null?
|
230
|
-
end
|
231
|
-
|
232
|
-
def definition
|
233
|
-
Rbind::get_cursor_definition self
|
234
|
-
end
|
235
|
-
|
236
|
-
def static?
|
237
|
-
1 == Rbind::cxx_method_is_static(self)
|
238
|
-
end
|
239
|
-
|
240
|
-
def virtual?
|
241
|
-
1 == Rbind::cxx_method_is_virtual(self)
|
242
|
-
end
|
243
|
-
|
244
|
-
def visit_children(recurse=false,*reg_filters,&block)
|
245
|
-
if reg_filters.empty?
|
246
|
-
reg_filters << Regexp.new("#{File.dirname(translation_unit.spelling)}")
|
247
|
-
end
|
248
|
-
p = proc do |cur,parent,data|
|
249
|
-
# puts "#{cur.kind} #{cur.spelling} #{cur.template_kind} #{cur.specialized_template.kind} #{cur.location}"
|
250
|
-
if(reg_filters.find{|reg| cur.file_name =~ reg})
|
251
|
-
block.call(cur,parent)
|
252
|
-
if recurse
|
253
|
-
:recurse
|
254
|
-
else
|
255
|
-
:continue
|
256
|
-
end
|
257
|
-
else
|
258
|
-
:continue
|
259
|
-
end
|
260
|
-
end
|
261
|
-
Rbind::visit_children(self,p,FFI::Pointer.new(0))
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
class String < FFI::Struct
|
266
|
-
@@pointer = Hash.new
|
267
|
-
|
268
|
-
def self.finalize(id)
|
269
|
-
Rbind::dispose_string(@@pointer[id])
|
270
|
-
@@pointer.delete(id)
|
271
|
-
rescue => e
|
272
|
-
puts e
|
273
|
-
end
|
274
|
-
|
275
|
-
def initialize(*args)
|
276
|
-
super
|
277
|
-
# we cannot use auto pointer because string is returned as value
|
278
|
-
ObjectSpace.define_finalizer(self, String.method(:finalize))
|
279
|
-
@@pointer[self.object_id] = pointer
|
280
|
-
end
|
281
|
-
|
282
|
-
def to_s
|
283
|
-
Rbind.get_c_string self
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
class Token < FFI::Struct
|
288
|
-
def self.release(pointer)
|
289
|
-
end
|
290
|
-
|
291
|
-
def spelling(translation_unit)
|
292
|
-
Rbind::get_token_spelling(translation_unit,self).to_s
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
class Type < FFI::Struct
|
297
|
-
def null?
|
298
|
-
kind == :invalid
|
299
|
-
end
|
300
|
-
|
301
|
-
def declaration
|
302
|
-
Rbind::get_type_declaration self
|
303
|
-
end
|
304
|
-
|
305
|
-
def const_qualified?
|
306
|
-
1 == Rbind::is_const_qualified_type(self)
|
307
|
-
end
|
308
|
-
|
309
|
-
def canonical_type
|
310
|
-
Rbind::get_canonical_type self
|
311
|
-
end
|
312
|
-
|
313
|
-
def result_type
|
314
|
-
Rbind::get_result_type self
|
315
|
-
end
|
316
|
-
|
317
|
-
def pointee_type
|
318
|
-
Rbind::get_pointee_type self
|
319
|
-
end
|
320
|
-
|
321
|
-
def pod?
|
322
|
-
1 == Rbind::is_pod_type(self)
|
323
|
-
end
|
324
|
-
|
325
|
-
def array_size
|
326
|
-
Rbind::get_array_size self
|
327
|
-
end
|
328
|
-
|
329
|
-
def array_element_type
|
330
|
-
Rbind::get_array_element_type self
|
331
|
-
end
|
332
|
-
|
333
|
-
def kind
|
334
|
-
self[:kind]
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|