Implements building pre- and post-processing statements for arguments.
# File lib/gir_ffi/builders/argument_builder.rb, line 7 def initialize var_gen, arginfo super var_gen, arginfo.name, arginfo.argument_type, arginfo.direction @arginfo = arginfo end
# File lib/gir_ffi/builders/argument_builder.rb, line 12 def inarg if has_input_value? && !is_array_length_parameter? @name end end
# File lib/gir_ffi/builders/argument_builder.rb, line 34 def post if has_output_value? value = output_value ["#{retname} = #{value}"] else [] end end
# File lib/gir_ffi/builders/argument_builder.rb, line 24 def pre pr = [] if has_input_value? pr << fixed_array_size_check if needs_size_check? pr << array_length_assignment if is_array_length_parameter? end pr << set_function_call_argument pr end
# File lib/gir_ffi/builders/argument_builder.rb, line 18 def retname if has_output_value? @retname ||= @var_gen.new_var end end
# File lib/gir_ffi/builders/argument_builder.rb, line 84 def array_length_assignment arrname = @array_arg.name "#{@name} = #{arrname}.nil? ? 0 : #{arrname}.length" end
# File lib/gir_ffi/builders/argument_builder.rb, line 66 def fixed_array_size_check size = type_info.array_fixed_size "GirFFI::ArgHelper.check_fixed_array_size #{size}, #{@name}, \"#{@name}\"" end
# File lib/gir_ffi/builders/argument_builder.rb, line 80 def has_input_value? (@direction == :inout || @direction == :in) && !skipped? end
# File lib/gir_ffi/builders/argument_builder.rb, line 76 def has_output_value? (@direction == :inout || @direction == :out) && !skipped? end
# File lib/gir_ffi/builders/argument_builder.rb, line 113 def ingoing_parameter_conversion args = conversion_arguments @name base = case specialized_type_tag when :array, :c, :callback, :ghash, :glist, :gslist, :object, :ptr_array, :struct, :strv, :utf8, :void, :zero_terminated "#{argument_class_name}.from(#{args})" else args end if has_output_value? "GirFFI::InOutPointer.from #{type_info.tag_or_class.inspect}, #{base}" else base end end
# File lib/gir_ffi/builders/argument_builder.rb, line 58 def is_array_length_parameter? @array_arg end
# File lib/gir_ffi/builders/argument_builder.rb, line 108 def is_caller_allocated_object? [ :struct, :array ].include?(specialized_type_tag) && @arginfo.caller_allocates? end
# File lib/gir_ffi/builders/argument_builder.rb, line 62 def needs_size_check? specialized_type_tag == :c && type_info.array_fixed_size > -1 end
# File lib/gir_ffi/builders/argument_builder.rb, line 45 def output_value if is_caller_allocated_object? callarg else base = "#{callarg}.to_value" if needs_outgoing_parameter_conversion? outgoing_conversion base else base end end end
# File lib/gir_ffi/builders/argument_builder.rb, line 89 def set_function_call_argument value = if skipped? @direction == :in ? "0" : "nil" elsif !has_input_value? if is_caller_allocated_object? if specialized_type_tag == :array "#{argument_class_name}.new #{type_info.element_type.inspect}" else "#{argument_class_name}.new" end else "GirFFI::InOutPointer.for #{type_info.tag_or_class.inspect}" end else ingoing_parameter_conversion end "#{callarg} = #{value}" end
# File lib/gir_ffi/builders/argument_builder.rb, line 71 def skipped? @arginfo.skip? || @array_arg && @array_arg.specialized_type_tag == :strv end