class GirFFI::Builder::Argument::Base

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

Constants

KEYWORDS
TAG_TO_WRAPPER_CLASS_MAP

Attributes

array_arg[RW]
length_arg[RW]
name[R]
retname[R]

Public Class Methods

new(var_gen, name, typeinfo, direction) click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 22
def initialize var_gen, name, typeinfo, direction
  @typeinfo = typeinfo
  @inarg = nil
  @retname = nil
  @name = safe(name)
  @var_gen = var_gen
  @length_arg = nil
  @array_arg = nil
end

Public Instance Methods

argument_class_name() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 57
def argument_class_name
  case (tag = type_tag)
  when :interface
    type_info.interface_type_name
  when :array
    case type_info.array_type
    when :byte_array
      'GLib::ByteArray'
    when :array
      'GLib::Array'
    when :ptr_array
      'GLib::PtrArray'
    else # :c
      if type_info.zero_terminated?
        if type_info.element_type == :utf8
          'GLib::Strv'
        else
          'GirFFI::InPointer'
        end
      else
        'GirFFI::InPointer'
      end
    end
  else
    TAG_TO_WRAPPER_CLASS_MAP[tag]
  end
end
array_size() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 104
def array_size
  if @length_arg
    @length_arg.retname
  else
    type_info.array_fixed_size
  end
end
callarg() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 128
def callarg
  @callarg ||= @var_gen.new_var
end
cleanup() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 144
def cleanup
  []
end
elm_t() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 100
def elm_t
  type_info.element_type.inspect
end
inarg() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 120
def inarg
  @array_arg.nil? ? @inarg : nil
end
post() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 136
def post
  []
end
postpost() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 140
def postpost
  []
end
pre() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 132
def pre
  []
end
retval() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 124
def retval
  @array_arg.nil? ? @retname : nil
end
safe(name) click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 112
def safe name
  if KEYWORDS.include? name
    "#{name}_"
  else
    name
  end
end
specialized_type_tag() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 40
def specialized_type_tag
  type_info.flattened_tag
end
subtype_tag_or_class_name(index=0) click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 85
def subtype_tag_or_class_name index=0
  type = type_info.param_type(index)
  tag = type.tag
  base = if tag == :interface
           type.interface_type_name
         else
           tag.inspect
         end
  if type.pointer?
    "[:pointer, #{base}]"
  else
    base
  end
end
type_info() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 32
def type_info
  @typeinfo
end
type_specification() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 44
def type_specification
  type_info.type_specification
end
type_tag() click to toggle source
# File lib/gir_ffi/builder/argument/base.rb, line 36
def type_tag
  type_info.tag
end