ghazel-ffi_gen 1.3.1 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ffi_gen.rb +6 -4
- data/lib/ffi_gen/{java_pre.java → java_interface.java} +0 -0
- data/lib/ffi_gen/java_output.rb +36 -12
- data/lib/ffi_gen/java_static.java +9 -0
- metadata +4 -4
- data/lib/ffi_gen/java_enum.java +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43bc6326ee11945bede82eb49c7481a27217099a
|
4
|
+
data.tar.gz: fa9c1dcff4c9cc46df121774b78a3de43908df8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22209a392916602e57e97af4f5577c53c4ba81d2d9b8a8baf4b7a8ef9330df791bf18ec8e1a0c68801a00e9d320aa9002f87cbd992f630ffecb9b8fdec66abe4
|
7
|
+
data.tar.gz: f85eef1eedd50c1f337f6d3d0df92d95498992d2d728069fb0603ece080f51eb55f3258fab0c9bf1fc9e40d762aa939aa87620518be15c419c1bf2acae429a85
|
data/lib/ffi_gen.rb
CHANGED
@@ -230,9 +230,10 @@ class FFIGen
|
|
230
230
|
end
|
231
231
|
|
232
232
|
class PointerType < Type
|
233
|
-
attr_reader :pointee_name, :depth
|
233
|
+
attr_reader :pointee_type, :pointee_name, :depth
|
234
234
|
|
235
|
-
def initialize(pointee_name, depth)
|
235
|
+
def initialize(pointee_type, pointee_name, depth)
|
236
|
+
@pointee_type = pointee_type
|
236
237
|
@pointee_name = pointee_name
|
237
238
|
@depth = depth
|
238
239
|
end
|
@@ -677,7 +678,8 @@ class FFIGen
|
|
677
678
|
break
|
678
679
|
end
|
679
680
|
end
|
680
|
-
|
681
|
+
pointee_type = resolve_type current_type
|
682
|
+
type = PointerType.new pointee_type, pointee_name, pointer_depth
|
681
683
|
end
|
682
684
|
|
683
685
|
type
|
@@ -693,7 +695,7 @@ class FFIGen
|
|
693
695
|
when :unexposed, :function_proto
|
694
696
|
UnknownType.new
|
695
697
|
when :incomplete_array
|
696
|
-
|
698
|
+
ArrayType.new resolve_type(Clang.get_array_element_type(canonical_type)), nil
|
697
699
|
else
|
698
700
|
raise NotImplementedError, "No translation for values of type #{canonical_type[:kind]}"
|
699
701
|
end
|
File without changes
|
data/lib/ffi_gen/java_output.rb
CHANGED
@@ -4,7 +4,7 @@ class FFIGen
|
|
4
4
|
writer.puts "// Generated by ffi_gen. Please do not change this file by hand.", "import java.util.*;", "import com.sun.jna.*;", "import java.lang.annotation.*;", "import java.lang.reflect.Method;", "", "public class #{@module_name} {"
|
5
5
|
writer.indent do
|
6
6
|
writer.puts "private static #{@module_name}Interface INSTANCE = #{@module_name}Interface.JnaInstanceCreator.createInstance();"
|
7
|
-
writer.puts "", *IO.readlines(File.join(File.dirname(__FILE__), "
|
7
|
+
writer.puts "", *IO.readlines(File.join(File.dirname(__FILE__), "java_static.java")).map(&:rstrip), ""
|
8
8
|
|
9
9
|
declarations.each do |declaration|
|
10
10
|
if declaration.respond_to? :write_static_java
|
@@ -17,7 +17,7 @@ class FFIGen
|
|
17
17
|
|
18
18
|
writer.puts "private interface #{@module_name}Interface extends Library {"
|
19
19
|
writer.indent do
|
20
|
-
writer.puts "", *IO.readlines(File.join(File.dirname(__FILE__), "
|
20
|
+
writer.puts "", *IO.readlines(File.join(File.dirname(__FILE__), "java_interface.java")).map(&:rstrip), ""
|
21
21
|
writer.puts "static class JnaInstanceCreator {"
|
22
22
|
writer.indent do
|
23
23
|
writer.puts "private static #{@module_name}Interface createInstance() {"
|
@@ -165,23 +165,49 @@ class FFIGen
|
|
165
165
|
def write_static_java(writer)
|
166
166
|
return if @is_callback # not yet supported
|
167
167
|
|
168
|
+
replace = {}
|
169
|
+
parameters = []
|
170
|
+
lp = nil
|
171
|
+
@parameters.each do |p|
|
172
|
+
if lp && lp[:type].is_a?(PointerType) && lp[:type].pointee_type.clang_type == :u_char && p[:type].clang_type == :u_long
|
173
|
+
n = lp[:name].to_java_downcase
|
174
|
+
replace[n] = "bytesToPointer(#{n})"
|
175
|
+
replace[p[:name].to_java_downcase] = "#{n}.length";
|
176
|
+
d = lp.dup
|
177
|
+
d[:type] = ArrayType.new(lp[:type].pointee_type, nil)
|
178
|
+
parameters << d
|
179
|
+
lp = nil
|
180
|
+
else
|
181
|
+
if lp
|
182
|
+
parameters << lp
|
183
|
+
end
|
184
|
+
lp = p
|
185
|
+
end
|
186
|
+
end
|
187
|
+
if lp
|
188
|
+
parameters << lp
|
189
|
+
end
|
190
|
+
|
168
191
|
writer.comment do
|
169
192
|
writer.write_description @function_description
|
170
193
|
writer.puts "", "<em>This entry is only for documentation and no real method.</em>" if @is_callback
|
171
|
-
writer.puts "", "@method #{@is_callback ? "_callback_#{java_name}_" : java_name}(#{
|
172
|
-
|
194
|
+
writer.puts "", "@method #{@is_callback ? "_callback_#{java_name}_" : java_name}(#{parameters.map{ |parameter| parameter[:name].to_java_downcase }.join(', ')})"
|
195
|
+
parameters.each do |parameter|
|
173
196
|
writer.write_description parameter[:description], false, "@param [#{parameter[:type].java_description}] #{parameter[:name].to_java_downcase} ", " "
|
174
197
|
end
|
175
198
|
writer.write_description @return_value_description, false, "@return [#{@return_type.java_description}] ", " "
|
176
199
|
writer.puts "@scope class"
|
177
200
|
end
|
178
201
|
|
179
|
-
args = @parameters.map{ |parameter|
|
180
|
-
|
202
|
+
args = @parameters.map{ |parameter|
|
203
|
+
n = parameter[:name].to_java_downcase
|
204
|
+
replace[n] || n
|
205
|
+
}.join(', ')
|
206
|
+
jna_signature = "#{parameters.map{ |parameter| "#{parameter[:type].java_jna_type} #{parameter[:name].to_java_downcase}" }.join(', ')}"
|
181
207
|
writer.puts "static #{@return_type.java_jna_type} #{java_name}(#{jna_signature}) {"
|
182
208
|
writer.indent do
|
183
209
|
call = "INSTANCE.#{java_name}(#{args});"
|
184
|
-
if @return_type.respond_to? :
|
210
|
+
if @return_type.respond_to? :clang_type and @return_type.clang_type == :void
|
185
211
|
writer.puts call
|
186
212
|
else
|
187
213
|
writer.puts "return #{call}"
|
@@ -225,6 +251,8 @@ class FFIGen
|
|
225
251
|
end
|
226
252
|
|
227
253
|
class PrimitiveType
|
254
|
+
attr_accessor :clang_type
|
255
|
+
|
228
256
|
def java_name
|
229
257
|
case @clang_type
|
230
258
|
when :void
|
@@ -256,10 +284,6 @@ class FFIGen
|
|
256
284
|
when :double then "double"
|
257
285
|
end
|
258
286
|
end
|
259
|
-
|
260
|
-
def no_return
|
261
|
-
@clang_type == :void
|
262
|
-
end
|
263
287
|
end
|
264
288
|
|
265
289
|
class StringType
|
@@ -303,7 +327,7 @@ class FFIGen
|
|
303
327
|
|
304
328
|
def java_jna_type
|
305
329
|
if @constant_size
|
306
|
-
|
330
|
+
"#{@element_type.java_jna_type}[#{@constant_size}]"
|
307
331
|
else
|
308
332
|
"#{@element_type.java_jna_type}[]"
|
309
333
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghazel-ffi_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Musiol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -38,8 +38,8 @@ files:
|
|
38
38
|
- LICENSE
|
39
39
|
- README.md
|
40
40
|
- lib/ffi_gen/empty.h
|
41
|
-
- lib/ffi_gen/
|
42
|
-
- lib/ffi_gen/
|
41
|
+
- lib/ffi_gen/java_interface.java
|
42
|
+
- lib/ffi_gen/java_static.java
|
43
43
|
homepage: https://github.com/neelance/ffi_gen
|
44
44
|
licenses:
|
45
45
|
- MIT
|
data/lib/ffi_gen/java_enum.java
DELETED