Class: GirFFI::BaseArgumentBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gir_ffi/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 =
[
  "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"
]
TAG_TO_WRAPPER_CLASS_MAP =
{
  :array => 'GLib::Array',
  :byte_array => 'GLib::ByteArray',
  :c => 'GLib::SizedArray',
  :callback => 'GirFFI::Callback',
  :error => 'GLib::Error',
  :ghash => 'GLib::HashTable',
  :glist => 'GLib::List',
  :gslist => 'GLib::SList',
  :ptr_array => 'GLib::PtrArray',
  :strv => 'GLib::Strv',
  :utf8 => 'GirFFI::InPointer',
  :void => 'GirFFI::InPointer',
  :zero_terminated => 'GirFFI::ZeroTerminated'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var_gen, name, typeinfo, direction) ⇒ BaseArgumentBuilder

Returns a new instance of BaseArgumentBuilder.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gir_ffi/base_argument_builder.rb', line 18

def initialize var_gen, name, typeinfo, direction
  @var_gen = var_gen

  @typeinfo = typeinfo
  @direction = direction
  @name = safe(name)

  @inarg = nil
  @retname = nil

  @length_arg = nil
  @array_arg = nil
end

Instance Attribute Details

#array_argObject

Returns the value of attribute array_arg.



16
17
18
# File 'lib/gir_ffi/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/base_argument_builder.rb', line 16

def length_arg
  @length_arg
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#retnameObject (readonly)

Returns the value of attribute retname.



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

def retname
  @retname
end

Instance Method Details

#argument_class_nameObject

TODO: Use class rather than class name



57
58
59
60
61
62
63
64
# File 'lib/gir_ffi/base_argument_builder.rb', line 57

def argument_class_name
  case (tag = type_info.flattened_tag)
  when :struct, :union, :object, :interface, :enum, :flags
    type_info.interface_type_name
  else
    TAG_TO_WRAPPER_CLASS_MAP[tag]
  end
end

#array_sizeObject



74
75
76
77
78
79
80
# File 'lib/gir_ffi/base_argument_builder.rb', line 74

def array_size
  if @length_arg
    @length_arg.retname
  else
    type_info.array_fixed_size
  end
end

#callargObject



98
99
100
# File 'lib/gir_ffi/base_argument_builder.rb', line 98

def callarg
  @callarg ||= @var_gen.new_var
end

#cleanupObject



110
111
112
# File 'lib/gir_ffi/base_argument_builder.rb', line 110

def cleanup
  []
end

#elm_tObject



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

def elm_t
  type_info.element_type.inspect
end

#inargObject



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

def inarg
  @array_arg.nil? ? @inarg : nil
end

#postObject



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

def post
  []
end

#preObject



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

def pre
  []
end

#retvalObject



94
95
96
# File 'lib/gir_ffi/base_argument_builder.rb', line 94

def retval
  @array_arg.nil? ? retname : nil
end

#safe(name) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/gir_ffi/base_argument_builder.rb', line 82

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

#specialized_type_tagObject



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

def specialized_type_tag
  type_info.flattened_tag
end

#subtype_tag_or_class_nameObject



66
67
68
# File 'lib/gir_ffi/base_argument_builder.rb', line 66

def subtype_tag_or_class_name
  type_info.subtype_tag_or_class_name
end

#type_infoObject



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

def type_info
  @typeinfo
end