Class: GirFFI::Builders::ArgumentBuilder

Inherits:
BaseArgumentBuilder show all
Defined in:
lib/gir_ffi/builders/argument_builder.rb

Overview

Implements building pre- and post-processing statements for arguments.

Constant Summary

Constants inherited from BaseArgumentBuilder

BaseArgumentBuilder::KEYWORDS

Instance Attribute Summary

Attributes inherited from BaseArgumentBuilder

#arginfo, #array_arg, #length_arg

Instance Method Summary collapse

Methods inherited from BaseArgumentBuilder

#argument_class_name, #array_length_idx, #array_length_parameter?, #call_argument_name, #closure=, #closure?, #closure_idx, #destroy_idx, #destroy_notifier?, #direction, #helper_argument?, #initialize, #mark_as_destroy_notifier, #name, #new_variable, #ownership_transfer, #safe, #specialized_type_tag, #type_info

Constructor Details

This class inherits a constructor from GirFFI::Builders::BaseArgumentBuilder

Instance Method Details

#allow_none?Boolean

Returns:



21
22
23
# File 'lib/gir_ffi/builders/argument_builder.rb', line 21

def allow_none?
  arginfo.may_be_null?
end

#block_argument?Boolean

Returns:



17
18
19
# File 'lib/gir_ffi/builders/argument_builder.rb', line 17

def block_argument?
  specialized_type_tag == :callback
end

#capture_variable_nameObject



39
40
41
# File 'lib/gir_ffi/builders/argument_builder.rb', line 39

def capture_variable_name
  nil
end

#method_argument_nameObject



13
14
15
# File 'lib/gir_ffi/builders/argument_builder.rb', line 13

def method_argument_name
  name if has_input_value? && !helper_argument?
end

#post_conversionObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/gir_ffi/builders/argument_builder.rb', line 63

def post_conversion
  if direction == :error
    ["GirFFI::ArgHelper.check_error(#{call_argument_name})"]
  elsif has_post_conversion?
    value = output_value
    ["#{post_converted_name} = #{value}"]
  else
    []
  end
end

#post_converted_nameObject



25
26
27
28
29
30
31
# File 'lib/gir_ffi/builders/argument_builder.rb', line 25

def post_converted_name
  @post_converted_name ||= if has_post_conversion?
                             new_variable
                           else
                             call_argument_name
                           end
end

#pre_conversionObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gir_ffi/builders/argument_builder.rb', line 43

def pre_conversion
  pr = []
  if has_ingoing_component?
    pr << fixed_array_size_check if needs_size_check?
    pr << array_length_assignment if array_length_parameter?
  end
  case direction
  when :in
    pr << "#{call_argument_name} = #{ingoing_convertor.conversion}"
  when :inout
    pr << out_parameter_preparation
    pr << ingoing_value_storage
  when :out
    pr << out_parameter_preparation
  when :error
    pr << "#{call_argument_name} = FFI::MemoryPointer.new(:pointer).write_pointer nil"
  end
  pr
end

#return_value_nameObject



33
34
35
36
37
# File 'lib/gir_ffi/builders/argument_builder.rb', line 33

def return_value_name
  if has_output_value?
    post_converted_name unless array_length_parameter?
  end
end