Class: GirFFI::Builders::BaseArgumentBuilder

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

Overview

Abstract parent class of the argument building classes. These classes are used by FunctionBuilder to create the code that processes each argument before and after the actual function call.

Constant Summary collapse

KEYWORDS =
%w(
  alias and begin break case class def do
  else elsif end ensure false for if in
  module next nil not or redo rescue retry
  return self super then true undef unless
  until when while yield
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var_gen, arginfo) ⇒ BaseArgumentBuilder

Returns a new instance of BaseArgumentBuilder.



19
20
21
22
23
24
25
26
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 19

def initialize(var_gen, arginfo)
  @var_gen = var_gen
  @arginfo = arginfo
  @length_arg = nil
  @array_arg = nil
  @is_closure = false
  @destroy_notifier = false
end

Instance Attribute Details

#arginfoObject (readonly)

Returns the value of attribute arginfo.



16
17
18
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 16

def arginfo
  @arginfo
end

#array_argObject

Returns the value of attribute array_arg.



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

def array_arg
  @array_arg
end

#length_argObject

Returns the value of attribute length_arg.



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

def length_arg
  @length_arg
end

Instance Method Details

#argument_class_nameObject

TODO: Use class rather than class name



45
46
47
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 45

def argument_class_name
  type_info.argument_class_name
end

#array_length_idxObject



49
50
51
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 49

def array_length_idx
  type_info.array_length
end

#array_length_parameter?Boolean

Returns:



75
76
77
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 75

def array_length_parameter?
  @array_arg
end

#call_argument_nameObject



103
104
105
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 103

def call_argument_name
  @call_argument_name ||= new_variable
end

#closure=(arg) ⇒ Object

TODO: closure unfortunately means two things in GLib: a closure argument (user_data), and the Closure class (a callable object). Make the distinction more explicit in GirFFI.



64
65
66
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 64

def closure=(arg)
  @is_closure = arg
end

#closure?Boolean

Returns:



79
80
81
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 79

def closure?
  @is_closure
end

#closure_idxObject



53
54
55
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 53

def closure_idx
  arginfo.closure
end

#destroy_idxObject



57
58
59
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 57

def destroy_idx
  arginfo.destroy
end

#destroy_notifier?Boolean

Returns:



83
84
85
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 83

def destroy_notifier?
  @destroy_notifier
end

#directionObject



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

def direction
  @direction ||= arginfo.direction
end

#helper_argument?Boolean

Returns:



87
88
89
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 87

def helper_argument?
  array_length_parameter? || closure? || destroy_notifier?
end

#mark_as_destroy_notifier(callback) ⇒ Object

TODO: Unify relationship set-up methods and improve naming. We currently have length_arg=, array_arg=, closure= and mark_as_destroy_notifier.



71
72
73
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 71

def mark_as_destroy_notifier(callback)
  @destroy_notifier = callback
end

#nameObject



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

def name
  @name ||= safe(arginfo.name)
end

#new_variableObject



107
108
109
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 107

def new_variable
  @var_gen.new_var
end

#ownership_transferObject



91
92
93
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 91

def ownership_transfer
  arginfo.ownership_transfer
end

#safe(name) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 95

def safe(name)
  if KEYWORDS.include? name
    "#{name}_"
  else
    name
  end
end

#specialized_type_tagObject



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

def specialized_type_tag
  type_info.flattened_tag
end

#type_infoObject



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

def type_info
  @type_info ||= arginfo.argument_type
end