Class: GirFFI::Builders::ArgumentBuilderCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/gir_ffi/builders/argument_builder_collection.rb

Overview

Class representing the argument and return value builders for a callback mapping function or marshaller. Implements collecting the conversion code and parameter and variable names for use by function builders.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(return_value_builder, argument_builders, options = {}) ⇒ ArgumentBuilderCollection

Returns a new instance of ArgumentBuilderCollection.



10
11
12
13
14
15
16
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 10

def initialize return_value_builder, argument_builders, options = {}
  @receiver_builder = options[:receiver_builder]
  @argument_builders = argument_builders
  @return_value_builder = return_value_builder
  self.class.set_up_argument_relations argument_builders
  @argument_builders.unshift @receiver_builder if @receiver_builder
end

Instance Attribute Details

#argument_buildersObject (readonly)

Returns the value of attribute argument_builders.



8
9
10
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 8

def argument_builders
  @argument_builders
end

#return_value_builderObject (readonly)

Returns the value of attribute return_value_builder.



7
8
9
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 7

def return_value_builder
  @return_value_builder
end

Class Method Details

.set_up_argument_relations(argument_builders) ⇒ Object



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

def self.set_up_argument_relations argument_builders
  argument_builders.each do |arg|
    if (idx = arg.arginfo.closure) >= 0
      argument_builders[idx].is_closure = true
    end
  end
  argument_builders.each do |bldr|
    if (idx = bldr.array_length_idx) >= 0
      other = argument_builders[idx]

      bldr.length_arg = other
      other.array_arg = bldr
    end
  end
end

Instance Method Details

#call_argument_namesObject



32
33
34
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 32

def call_argument_names
  @call_argument_names ||= argument_builders.map(&:call_argument_name).compact
end

#capture_variable_namesObject



27
28
29
30
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 27

def capture_variable_names
  @capture_variable_names ||=
    all_builders.map(&:capture_variable_name).compact
end

#method_argument_namesObject



36
37
38
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 36

def method_argument_names
  @method_argument_names ||= argument_builders.map(&:method_argument_name)
end

#parameter_preparationObject



18
19
20
21
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 18

def parameter_preparation
  argument_builders.sort_by.with_index {|arg, i|
    [arg.type_info.array_length, i] }.map(&:pre_conversion).flatten
end

#return_value_conversionObject



23
24
25
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 23

def return_value_conversion
  all_builders.map(&:post_conversion).flatten
end

#return_value_nameObject



40
41
42
# File 'lib/gir_ffi/builders/argument_builder_collection.rb', line 40

def return_value_name
  return_value_builder.return_value_name if return_value_builder.is_relevant?
end