gir_ffi 0.6.7 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{History.txt → Changelog.md} +93 -61
- data/{DESIGN.rdoc → DESIGN.md} +7 -7
- data/README.md +5 -7
- data/TODO.md +90 -0
- data/lib/ffi-glib.rb +0 -1
- data/lib/ffi-glib/array.rb +13 -29
- data/lib/ffi-glib/array_methods.rb +13 -0
- data/lib/ffi-glib/container_class_methods.rb +6 -1
- data/lib/ffi-glib/hash_table.rb +3 -2
- data/lib/ffi-glib/list.rb +3 -17
- data/lib/ffi-glib/list_methods.rb +22 -3
- data/lib/ffi-glib/ptr_array.rb +19 -19
- data/lib/ffi-glib/s_list.rb +3 -17
- data/lib/ffi-gobject.rb +10 -17
- data/lib/ffi-gobject/object.rb +19 -9
- data/lib/ffi-gobject/object_class.rb +14 -0
- data/lib/ffi-gobject/ruby_closure.rb +4 -5
- data/lib/ffi-gobject/value.rb +7 -5
- data/lib/ffi-gobject_introspection/i_vfunc_info.rb +1 -1
- data/lib/gir_ffi-base.rb +0 -2
- data/lib/gir_ffi-base/gobject.rb +1 -0
- data/lib/gir_ffi-base/gobject/lib.rb +1 -1
- data/lib/gir_ffi.rb +2 -0
- data/lib/gir_ffi/arg_helper.rb +18 -8
- data/lib/gir_ffi/builders/argument_builder.rb +62 -55
- data/lib/gir_ffi/builders/base_argument_builder.rb +52 -106
- data/lib/gir_ffi/builders/base_type_builder.rb +3 -3
- data/lib/gir_ffi/builders/c_to_ruby_convertor.rb +34 -0
- data/lib/gir_ffi/builders/callback_argument_builder.rb +73 -0
- data/lib/gir_ffi/builders/callback_builder.rb +19 -9
- data/lib/gir_ffi/builders/callback_return_value_builder.rb +54 -0
- data/lib/gir_ffi/builders/closure_convertor.rb +9 -0
- data/lib/gir_ffi/builders/closure_to_pointer_convertor.rb +9 -0
- data/lib/gir_ffi/builders/constructor_result_convertor.rb +9 -0
- data/lib/gir_ffi/builders/enum_builder.rb +16 -16
- data/lib/gir_ffi/builders/field_builder.rb +36 -15
- data/lib/gir_ffi/builders/function_builder.rb +32 -27
- data/lib/gir_ffi/builders/interface_builder.rb +14 -4
- data/lib/gir_ffi/builders/mapping_method_builder.rb +95 -43
- data/lib/gir_ffi/builders/module_builder.rb +22 -35
- data/lib/gir_ffi/builders/null_convertor.rb +9 -0
- data/lib/gir_ffi/builders/object_builder.rb +11 -14
- data/lib/gir_ffi/builders/property_builder.rb +107 -9
- data/lib/gir_ffi/builders/registered_type_builder.rb +2 -2
- data/lib/gir_ffi/builders/return_value_builder.rb +42 -33
- data/lib/gir_ffi/builders/ruby_to_c_convertor.rb +15 -0
- data/lib/gir_ffi/builders/signal_builder.rb +18 -58
- data/lib/gir_ffi/builders/struct_builder.rb +1 -2
- data/lib/gir_ffi/builders/type_builder.rb +1 -0
- data/lib/gir_ffi/builders/unintrospectable_builder.rb +4 -4
- data/lib/gir_ffi/builders/user_defined_builder.rb +151 -26
- data/lib/gir_ffi/builders/vfunc_builder.rb +57 -0
- data/lib/gir_ffi/builders/with_layout.rb +10 -8
- data/lib/gir_ffi/builders/with_methods.rb +1 -1
- data/lib/gir_ffi/callback_base.rb +42 -8
- data/lib/gir_ffi/class_base.rb +1 -2
- data/lib/gir_ffi/enum_base.rb +26 -4
- data/lib/gir_ffi/error_argument_info.rb +21 -0
- data/lib/gir_ffi/{setter_argument_info.rb → field_argument_info.rb} +2 -1
- data/lib/gir_ffi/g_type.rb +25 -0
- data/lib/gir_ffi/in_out_pointer.rb +3 -14
- data/lib/gir_ffi/in_pointer.rb +20 -21
- data/lib/gir_ffi/info_ext.rb +2 -0
- data/lib/gir_ffi/info_ext/i_callable_info.rb +0 -9
- data/lib/gir_ffi/info_ext/i_callback_info.rb +17 -0
- data/lib/gir_ffi/info_ext/i_function_info.rb +4 -0
- data/lib/gir_ffi/info_ext/i_property_info.rb +4 -0
- data/lib/gir_ffi/info_ext/i_registered_type_info.rb +1 -0
- data/lib/gir_ffi/info_ext/i_signal_info.rb +14 -16
- data/lib/gir_ffi/info_ext/i_type_info.rb +72 -34
- data/lib/gir_ffi/info_ext/i_vfunc_info.rb +12 -0
- data/lib/gir_ffi/info_ext/safe_constant_name.rb +3 -2
- data/lib/gir_ffi/interface_base.rb +8 -3
- data/lib/gir_ffi/module_base.rb +3 -5
- data/lib/gir_ffi/object_base.rb +8 -0
- data/lib/gir_ffi/receiver_argument_info.rb +21 -0
- data/lib/gir_ffi/receiver_type_info.rb +27 -0
- data/lib/gir_ffi/return_value_info.rb +23 -0
- data/lib/gir_ffi/signal_base.rb +1 -1
- data/lib/{ffi-glib → gir_ffi}/sized_array.rb +10 -6
- data/lib/gir_ffi/struct_base.rb +10 -9
- data/lib/gir_ffi/type_base.rb +1 -0
- data/lib/gir_ffi/type_map.rb +3 -0
- data/lib/gir_ffi/unintrospectable_type_info.rb +4 -1
- data/lib/gir_ffi/union_base.rb +4 -21
- data/lib/gir_ffi/user_data_argument_info.rb +21 -0
- data/lib/gir_ffi/user_data_type_info.rb +17 -0
- data/lib/gir_ffi/user_defined_type_info.rb +18 -4
- data/lib/gir_ffi/version.rb +1 -1
- data/lib/gir_ffi/vfunc_base.rb +8 -0
- data/lib/gir_ffi/vfunc_implementation.rb +11 -0
- data/lib/gir_ffi/zero_terminated.rb +18 -24
- data/test/base_test_helper.rb +2 -3
- data/test/ffi-glib/array_test.rb +3 -3
- data/test/ffi-glib/ruby_closure_test.rb +3 -3
- data/test/ffi-gobject/value_test.rb +15 -1
- data/test/ffi-gobject_test.rb +2 -1
- data/test/gir_ffi/arg_helper_test.rb +21 -2
- data/test/gir_ffi/builders/argument_builder_test.rb +213 -287
- data/test/gir_ffi/builders/base_argument_builder_test.rb +1 -1
- data/test/gir_ffi/builders/callback_builder_test.rb +26 -8
- data/test/gir_ffi/builders/field_builder_test.rb +18 -3
- data/test/gir_ffi/builders/function_builder_test.rb +30 -12
- data/test/gir_ffi/builders/interface_builder_test.rb +9 -0
- data/test/gir_ffi/builders/module_builder_test.rb +0 -39
- data/test/gir_ffi/builders/object_builder_test.rb +27 -27
- data/test/gir_ffi/builders/property_builder_test.rb +110 -0
- data/test/gir_ffi/builders/return_value_builder_test.rb +168 -200
- data/test/gir_ffi/builders/signal_builder_test.rb +58 -14
- data/test/gir_ffi/builders/struct_builder_test.rb +2 -41
- data/test/gir_ffi/builders/user_defined_builder_test.rb +88 -20
- data/test/gir_ffi/builders/vfunc_builder_test.rb +44 -0
- data/test/gir_ffi/g_type_test.rb +29 -0
- data/test/gir_ffi/in_pointer_test.rb +28 -9
- data/test/gir_ffi/info_ext/i_callable_info_test.rb +0 -9
- data/test/gir_ffi/info_ext/i_callback_info_test.rb +19 -0
- data/test/gir_ffi/info_ext/i_function_info_test.rb +9 -0
- data/test/gir_ffi/info_ext/i_signal_info_test.rb +8 -11
- data/test/gir_ffi/info_ext/i_type_info_test.rb +140 -16
- data/test/gir_ffi/interface_base_test.rb +9 -3
- data/test/gir_ffi/object_base_test.rb +1 -2
- data/test/{ffi-glib → gir_ffi}/sized_array_test.rb +28 -28
- data/test/gir_ffi/type_map_test.rb +1 -1
- data/test/gir_ffi/user_defined_type_info_test.rb +36 -4
- data/test/gir_ffi_test.rb +5 -5
- data/test/gir_ffi_test_helper.rb +4 -0
- data/test/integration/generated_gimarshallingtests_test.rb +163 -59
- data/test/integration/generated_gobject_test.rb +21 -8
- data/test/integration/generated_pango_test.rb +2 -2
- data/test/integration/generated_regress_test.rb +361 -101
- data/test/lib/autogen.sh +5 -1
- metadata +51 -35
- data/TODO.rdoc +0 -63
- data/lib/gir_ffi-base/gir_ffi/library.rb +0 -17
- data/lib/gir_ffi-base/gir_ffi/struct.rb +0 -27
@@ -32,12 +32,12 @@ module GirFFI
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def setup_constants
|
35
|
-
|
36
|
-
|
35
|
+
klass.const_set :GIR_INFO, info
|
36
|
+
klass.const_set :GIR_FFI_BUILDER, self
|
37
37
|
end
|
38
38
|
|
39
39
|
def already_set_up
|
40
|
-
const_defined_for
|
40
|
+
const_defined_for klass, :GIR_FFI_BUILDER
|
41
41
|
end
|
42
42
|
|
43
43
|
def gir
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class GirFFI::Builders::CToRubyConvertor
|
2
|
+
def initialize type_info, argument_name, length_arg
|
3
|
+
@type_info = type_info
|
4
|
+
@argument_name = argument_name
|
5
|
+
@length_arg = length_arg
|
6
|
+
end
|
7
|
+
|
8
|
+
def conversion
|
9
|
+
case @type_info.flattened_tag
|
10
|
+
when :utf8, :filename
|
11
|
+
"#{@argument_name}.to_utf8"
|
12
|
+
else
|
13
|
+
"#{@type_info.argument_class_name}.wrap(#{conversion_arguments})"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def conversion_arguments
|
20
|
+
if @type_info.flattened_tag == :c
|
21
|
+
"#{@type_info.element_type.inspect}, #{array_size}, #{@argument_name}"
|
22
|
+
else
|
23
|
+
@type_info.extra_conversion_arguments.map(&:inspect).push(@argument_name).join(", ")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def array_size
|
28
|
+
if @length_arg
|
29
|
+
@length_arg
|
30
|
+
else
|
31
|
+
@type_info.array_fixed_size
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'gir_ffi/builders/base_argument_builder'
|
2
|
+
require 'gir_ffi/builders/c_to_ruby_convertor'
|
3
|
+
require 'gir_ffi/builders/closure_convertor'
|
4
|
+
require 'gir_ffi/builders/null_convertor'
|
5
|
+
|
6
|
+
module GirFFI
|
7
|
+
module Builders
|
8
|
+
class CallbackArgumentBuilder < BaseArgumentBuilder
|
9
|
+
def method_argument_name
|
10
|
+
@method_argument_name ||= name || new_variable
|
11
|
+
end
|
12
|
+
|
13
|
+
def pre_converted_name
|
14
|
+
@pre_converted_name ||= new_variable
|
15
|
+
end
|
16
|
+
|
17
|
+
def call_argument_name
|
18
|
+
if direction == :in
|
19
|
+
pre_converted_name unless array_arg
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def capture_variable_name
|
24
|
+
if direction == :out
|
25
|
+
@capture_variable_name ||= new_variable
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def pre_conversion
|
30
|
+
case direction
|
31
|
+
when :in
|
32
|
+
[ "#{pre_converted_name} = #{pre_convertor.conversion}" ]
|
33
|
+
when :out
|
34
|
+
[ "#{pre_converted_name} = #{out_parameter_preparation}" ]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def post_conversion
|
39
|
+
if direction == :out
|
40
|
+
[ "#{pre_converted_name}.set_value #{capture_variable_name}" ]
|
41
|
+
else
|
42
|
+
[]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def pre_convertor
|
49
|
+
@pre_convertor ||= if is_closure
|
50
|
+
ClosureConvertor.new(method_argument_name)
|
51
|
+
elsif type_info.needs_conversion_for_callbacks?
|
52
|
+
CToRubyConvertor.new(type_info,
|
53
|
+
method_argument_name,
|
54
|
+
length_argument_name)
|
55
|
+
else
|
56
|
+
NullConvertor.new(method_argument_name)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def out_parameter_preparation
|
61
|
+
"GirFFI::InOutPointer.new(#{type_info.tag_or_class.inspect}, #{method_argument_name})"
|
62
|
+
end
|
63
|
+
|
64
|
+
def length_argument_name
|
65
|
+
length_arg && length_arg.pre_converted_name
|
66
|
+
end
|
67
|
+
|
68
|
+
def is_void_return_value?
|
69
|
+
specialized_type_tag == :void && !type_info.pointer?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -9,17 +9,27 @@ module GirFFI
|
|
9
9
|
# as a callback for FFI.
|
10
10
|
class CallbackBuilder < BaseTypeBuilder
|
11
11
|
def instantiate_class
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
setup_class unless already_set_up
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup_class
|
16
|
+
setup_callback
|
17
|
+
setup_constants
|
18
|
+
klass.class_eval mapping_method_definition
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup_callback
|
22
|
+
optionally_define_constant klass, :Callback do
|
23
|
+
lib.callback callback_sym, argument_types, return_type
|
17
24
|
end
|
18
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
def klass
|
28
|
+
@klass ||= get_or_define_class namespace_module, @classname, CallbackBase
|
19
29
|
end
|
20
30
|
|
21
31
|
def mapping_method_definition
|
22
|
-
MappingMethodBuilder.
|
32
|
+
MappingMethodBuilder.for_callback(info.args, info.return_type).method_definition
|
23
33
|
end
|
24
34
|
|
25
35
|
def callback_sym
|
@@ -27,11 +37,11 @@ module GirFFI
|
|
27
37
|
end
|
28
38
|
|
29
39
|
def argument_types
|
30
|
-
@info.argument_ffi_types
|
40
|
+
@argument_types ||= @info.argument_ffi_types
|
31
41
|
end
|
32
42
|
|
33
43
|
def return_type
|
34
|
-
@info.return_ffi_type
|
44
|
+
@return_type ||= @info.return_ffi_type
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'gir_ffi/builders/return_value_builder'
|
2
|
+
require 'gir_ffi/builders/ruby_to_c_convertor'
|
3
|
+
|
4
|
+
module GirFFI
|
5
|
+
module Builders
|
6
|
+
class CallbackReturnValueBuilder < BaseArgumentBuilder
|
7
|
+
def is_relevant?
|
8
|
+
!is_void_return_value? && !arginfo.skip?
|
9
|
+
end
|
10
|
+
|
11
|
+
def capture_variable_name
|
12
|
+
if is_relevant?
|
13
|
+
@capture_variable_name ||= new_variable
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def post_converted_name
|
18
|
+
@post_converted_name ||= if has_post_conversion?
|
19
|
+
new_variable
|
20
|
+
else
|
21
|
+
capture_variable_name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def return_value_name
|
26
|
+
if is_relevant?
|
27
|
+
post_converted_name unless array_arg
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def post_conversion
|
32
|
+
if has_post_conversion?
|
33
|
+
[ "#{post_converted_name} = #{post_convertor.conversion}" ]
|
34
|
+
else
|
35
|
+
[]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def has_post_conversion?
|
42
|
+
type_info.needs_conversion_for_callbacks?
|
43
|
+
end
|
44
|
+
|
45
|
+
def post_convertor
|
46
|
+
@post_convertor ||= RubyToCConvertor.new(type_info, capture_variable_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def is_void_return_value?
|
50
|
+
specialized_type_tag == :void && !type_info.pointer?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -24,21 +24,26 @@ module GirFFI
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def instantiate_class
|
27
|
-
@
|
28
|
-
@enum = optionally_define_constant @klass, :Enum do
|
27
|
+
@enum = optionally_define_constant klass, :Enum do
|
29
28
|
lib.enum(enum_sym, value_spec)
|
30
29
|
end
|
31
|
-
unless already_set_up
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
setup_class unless already_set_up
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_class
|
34
|
+
klass.extend superclass
|
35
|
+
setup_constants
|
36
|
+
setup_gtype_getter
|
37
|
+
stub_methods
|
38
|
+
setup_inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
def klass
|
42
|
+
@klass ||= get_or_define_module namespace_module, @classname
|
38
43
|
end
|
39
44
|
|
40
45
|
def setup_inspect
|
41
|
-
|
46
|
+
klass.instance_eval <<-EOS
|
42
47
|
def self.inspect
|
43
48
|
"#{@namespace}::#{@classname}"
|
44
49
|
end
|
@@ -46,17 +51,12 @@ module GirFFI
|
|
46
51
|
end
|
47
52
|
|
48
53
|
def already_set_up
|
49
|
-
|
54
|
+
klass.respond_to? :get_gtype
|
50
55
|
end
|
51
56
|
|
52
57
|
def superclass
|
53
58
|
@superclass ||= EnumBase
|
54
59
|
end
|
55
|
-
|
56
|
-
# FIXME: Remove duplication with ModuleBuilder
|
57
|
-
def get_or_define_module parent, name
|
58
|
-
optionally_define_constant(parent, name) { ::Module.new }
|
59
|
-
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'gir_ffi/builders/argument_builder'
|
2
2
|
require 'gir_ffi/builders/return_value_builder'
|
3
3
|
require 'gir_ffi/variable_name_generator'
|
4
|
-
require 'gir_ffi/
|
4
|
+
require 'gir_ffi/field_argument_info'
|
5
5
|
|
6
6
|
module GirFFI
|
7
7
|
module Builders
|
@@ -14,10 +14,24 @@ module GirFFI
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def build
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
setup_getter
|
18
|
+
setup_setter
|
19
|
+
end
|
20
|
+
|
21
|
+
def setup_getter
|
22
|
+
container_class.class_eval getter_def unless container_defines_getter_method?
|
23
|
+
end
|
24
|
+
|
25
|
+
def container_defines_getter_method?
|
26
|
+
container_info.find_instance_method info.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_setter
|
30
|
+
container_class.class_eval setter_def if is_writable_field?
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_writable_field?
|
34
|
+
info.writable?
|
21
35
|
end
|
22
36
|
|
23
37
|
def getter_def
|
@@ -30,9 +44,9 @@ module GirFFI
|
|
30
44
|
def #{info.name}
|
31
45
|
#{field_ptr} = @struct.to_ptr + #{info.offset}
|
32
46
|
#{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag_or_class.inspect}, #{field_ptr})
|
33
|
-
#{builder.
|
34
|
-
#{builder.
|
35
|
-
#{builder.
|
47
|
+
#{builder.capture_variable_name} = #{typed_ptr}.to_value
|
48
|
+
#{builder.post_conversion.join("\n")}
|
49
|
+
#{builder.return_value_name}
|
36
50
|
end
|
37
51
|
CODE
|
38
52
|
end
|
@@ -44,10 +58,10 @@ module GirFFI
|
|
44
58
|
typed_ptr = builder.new_variable
|
45
59
|
|
46
60
|
return <<-CODE.reset_indentation
|
47
|
-
def #{info.name}= #{builder.
|
61
|
+
def #{info.name}= #{builder.method_argument_name}
|
48
62
|
#{field_ptr} = @struct.to_ptr + #{info.offset}
|
49
63
|
#{typed_ptr} = GirFFI::InOutPointer.new(#{field_type_tag_or_class.inspect}, #{field_ptr})
|
50
|
-
#{builder.
|
64
|
+
#{builder.pre_conversion.join("\n ")}
|
51
65
|
#{typed_ptr}.set_value #{builder.callarg}
|
52
66
|
end
|
53
67
|
CODE
|
@@ -79,15 +93,22 @@ module GirFFI
|
|
79
93
|
@info.name.to_sym
|
80
94
|
end
|
81
95
|
|
96
|
+
def field_type
|
97
|
+
@field_type ||= @info.field_type
|
98
|
+
end
|
99
|
+
|
100
|
+
def field_argument_info
|
101
|
+
@field_argument_info ||= FieldArgumentInfo.new "value", field_type
|
102
|
+
end
|
103
|
+
|
82
104
|
def return_value_builder
|
83
|
-
|
84
|
-
|
105
|
+
@rv_builder ||= ReturnValueBuilder.new(VariableNameGenerator.new,
|
106
|
+
field_argument_info)
|
85
107
|
end
|
86
108
|
|
87
109
|
def setter_builder
|
88
|
-
|
89
|
-
|
90
|
-
ArgumentBuilder.new vargen, argument_info
|
110
|
+
@setter_builder ||= ArgumentBuilder.new(VariableNameGenerator.new,
|
111
|
+
field_argument_info)
|
91
112
|
end
|
92
113
|
end
|
93
114
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'gir_ffi/builders/argument_builder'
|
2
|
+
require 'gir_ffi/return_value_info'
|
3
|
+
require 'gir_ffi/error_argument_info'
|
2
4
|
require 'gir_ffi/builders/return_value_builder'
|
3
5
|
require 'gir_ffi/builders/error_argument_builder'
|
4
6
|
require 'gir_ffi/builders/null_argument_builder'
|
@@ -17,37 +19,44 @@ module GirFFI
|
|
17
19
|
vargen = GirFFI::VariableNameGenerator.new
|
18
20
|
@argument_builders = @info.args.map {|arg| ArgumentBuilder.new vargen, arg }
|
19
21
|
@return_value_builder = ReturnValueBuilder.new(vargen,
|
20
|
-
@info.return_type,
|
21
|
-
@info.constructor
|
22
|
-
@info.skip_return?)
|
22
|
+
ReturnValueInfo.new(@info.return_type, @info.skip_return?),
|
23
|
+
@info.constructor?)
|
23
24
|
|
24
|
-
|
25
|
+
set_up_argument_relations
|
25
26
|
setup_error_argument vargen
|
26
27
|
return filled_out_template
|
27
28
|
end
|
28
29
|
|
29
30
|
private
|
30
31
|
|
31
|
-
def
|
32
|
-
|
32
|
+
def lib_module_name
|
33
|
+
"#{@info.safe_namespace}::Lib"
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
+
def set_up_argument_relations
|
36
37
|
alldata = @argument_builders.dup << @return_value_builder
|
37
38
|
|
38
|
-
alldata.each
|
39
|
-
idx = data.
|
40
|
-
if idx > -1
|
39
|
+
alldata.each do |data|
|
40
|
+
if (idx = data.array_length_idx) >= 0
|
41
41
|
other_data = @argument_builders[idx]
|
42
42
|
data.length_arg = other_data
|
43
43
|
other_data.array_arg = data
|
44
44
|
end
|
45
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
@argument_builders.each do |data|
|
48
|
+
if (idx = data.arginfo.closure) >= 0
|
49
|
+
@argument_builders[idx].is_closure = true
|
50
|
+
end
|
51
|
+
end
|
46
52
|
end
|
47
53
|
|
48
54
|
def setup_error_argument vargen
|
49
|
-
|
50
|
-
|
55
|
+
@errarg = if @info.throws?
|
56
|
+
ErrorArgumentBuilder.new vargen, ErrorArgumentInfo.new
|
57
|
+
else
|
58
|
+
NullArgumentBuilder.new
|
59
|
+
end
|
51
60
|
end
|
52
61
|
|
53
62
|
def filled_out_template
|
@@ -59,17 +68,17 @@ module GirFFI
|
|
59
68
|
end
|
60
69
|
|
61
70
|
def method_body
|
62
|
-
lines = preparation << function_call << post_processing
|
71
|
+
lines = preparation << function_call << post_processing
|
63
72
|
lines << "return #{return_values.join(', ')}" if has_return_values?
|
64
73
|
lines.flatten.join("\n").indent
|
65
74
|
end
|
66
75
|
|
67
76
|
def function_call
|
68
|
-
"#{capture}#{
|
77
|
+
"#{capture}#{lib_module_name}.#{@info.symbol} #{function_call_arguments.join(', ')}"
|
69
78
|
end
|
70
79
|
|
71
80
|
def method_arguments
|
72
|
-
@argument_builders.map(&:
|
81
|
+
@argument_builders.map(&:method_argument_name).compact
|
73
82
|
end
|
74
83
|
|
75
84
|
def function_call_arguments
|
@@ -80,14 +89,14 @@ module GirFFI
|
|
80
89
|
end
|
81
90
|
|
82
91
|
def preparation
|
83
|
-
pr = @argument_builders.map(&:
|
92
|
+
pr = @argument_builders.map(&:pre_conversion)
|
84
93
|
pr << @errarg.pre
|
85
94
|
pr.flatten
|
86
95
|
end
|
87
96
|
|
88
97
|
def capture
|
89
98
|
if has_capture?
|
90
|
-
"#{@return_value_builder.
|
99
|
+
"#{@return_value_builder.capture_variable_name} = "
|
91
100
|
else
|
92
101
|
""
|
93
102
|
end
|
@@ -96,19 +105,15 @@ module GirFFI
|
|
96
105
|
def post_processing
|
97
106
|
# FIXME: Sorting knows too much about internals of ArgumentBuilder.
|
98
107
|
args = @argument_builders.sort_by {|arg| arg.type_info.array_length}
|
99
|
-
args << @return_value_builder
|
100
|
-
args.unshift @errarg
|
101
|
-
|
102
|
-
args.map {|arg| arg.post}
|
103
|
-
end
|
104
108
|
|
105
|
-
|
106
|
-
|
109
|
+
result = args.map {|arg| arg.post_conversion}
|
110
|
+
result.unshift @errarg.post
|
111
|
+
result << @return_value_builder.post_conversion
|
107
112
|
end
|
108
113
|
|
109
114
|
def return_values
|
110
|
-
@return_values ||= ([@return_value_builder.
|
111
|
-
@argument_builders.map(&:
|
115
|
+
@return_values ||= ([@return_value_builder.return_value_name] +
|
116
|
+
@argument_builders.map(&:return_value_name)).compact
|
112
117
|
end
|
113
118
|
|
114
119
|
def has_return_values?
|