@@ -22,18 +22,6 @@ module Bindgen
2222 end
2323 end
2424
25- def arguments_from_binding (list : Enumerable (Parser ::Argument ))
26- argument = Argument .new(@db )
27-
28- list.map_with_index do |arg , idx |
29- if idx == list.size - 1 && arg.variadic?
30- self .variadic_argument
31- else
32- from_binding(arg, qualified: true ).to_argument(argument.name(arg, idx))
33- end
34- end
35- end
36-
3725 # Turns the list of arguments into a list of `Call::Argument`s.
3826 def arguments_to_wrapper (list : Enumerable (Parser ::Argument ))
3927 argument = Argument .new(@db )
@@ -77,25 +65,8 @@ module Bindgen
7765 is_ref, ptr = reconfigure_pass_type(rules.pass_by, is_ref, ptr)
7866 end
7967
80- # HACK: Since the conversion *template* for function types cannot be a
81- # simple string substitution, we simply build the entire string here,
82- # assuming the result is oblivious to `Util.template`. Ideally,
83- # *template* should be lifted to a class hierarchy.
8468 if type .kind.function?
85- func_arg_types = type .template.not_nil!.arguments.dup
86- func_ret_type = func_arg_types.shift
87- func_args = func_arg_types.map_with_index do |type , i |
88- Parser ::Argument .new(" arg#{ i } " , type )
89- end
90- builder = CallBuilder ::CrystalFromCpp .new(@db )
91- call = builder.build(Parser ::Method .build(
92- name: " call" ,
93- return_type: func_ret_type,
94- arguments: func_args,
95- class_name: " Proc" ,
96- ), receiver: " _proc_" )
97- code = call.body.to_code(call, Graph ::Platform ::Crystal )
98- template = %[ BindgenHelper.wrap_proc(#{ code.gsub(/\{ (.*) \} / , " do \\ 1 end " ) } )]
69+ template = Template ::ProcFromWrapper .new(type , @db ).followed_by(template)
9970 end
10071
10172 ptr += 1 if is_ref # Translate reference to pointer
@@ -119,17 +90,6 @@ module Bindgen
11990 " Proc(#{ names } )"
12091 end
12192
122- # As above, but for Crystal bindings.
123- private def proc_to_binding (type )
124- args = type .template.not_nil!.arguments
125-
126- types = args[1 ..- 1 ]
127- types << args.first
128- names = types.map { |t | to_binding(t, qualified: true ).type_name.as(String ) }.join(" , " )
129-
130- " Proc(#{ names } )"
131- end
132-
13393 # Computes a result for passing *type* to the wrapper.
13494 def to_wrapper (type : Parser ::Type ) : Call ::Result
13595 to(type ) do |is_ref , ptr , type_name , nilable |
0 commit comments