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
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var_gen, arginfo) ⇒ BaseArgumentBuilder

Returns a new instance of BaseArgumentBuilder.



29
30
31
32
33
34
35
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 29

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

Instance Attribute Details

#arginfoObject (readonly)

Returns the value of attribute arginfo.



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

def arginfo
  @arginfo
end

#array_argObject

Returns the value of attribute array_arg.



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

def array_arg
  @array_arg
end

#length_argObject

Returns the value of attribute length_arg.



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

def length_arg
  @length_arg
end

Instance Method Details

#argument_class_nameObject

TODO: Use class rather than class name



55
56
57
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 55

def argument_class_name
  type_info.argument_class_name
end

#array_length_idxObject



59
60
61
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 59

def array_length_idx
  type_info.array_length
end

#call_argument_nameObject



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

def call_argument_name
  @call_argument_name ||= new_variable
end

#closure=(arg) ⇒ Object



25
26
27
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 25

def closure= arg
  @is_closure = arg
end

#closure?Boolean

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.

Returns:

  • (Boolean)


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

def closure?
  @is_closure
end

#directionObject



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

def direction
  @direction ||= arginfo.direction
end

#nameObject



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

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

#new_variableObject



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

def new_variable
  @var_gen.new_var
end

#safe(name) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 63

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

#specialized_type_tagObject



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

def specialized_type_tag
  # SMELL: Law of Demeter, due to this being arginfo.argument_type.flattened_tag
  type_info.flattened_tag
end

#type_infoObject



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

def type_info
  @type_info ||= arginfo.argument_type
end