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.



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

def initialize(var_gen, arginfo)
  @var_gen = var_gen
  @arginfo = arginfo
  @length_arg = nil
  @array_arg = nil
  @is_user_data = false
  @is_destroy_notifier = false
end

Instance Attribute Details

#arginfoObject (readonly)

Returns the value of attribute arginfo.



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

def arginfo
  @arginfo
end

#array_argObject

Returns the value of attribute array_arg.



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

def array_arg
  @array_arg
end

#length_argObject

Returns the value of attribute length_arg.



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

def length_arg
  @length_arg
end

Returns the value of attribute related_callback_builder.



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

def related_callback_builder
  @related_callback_builder
end

Instance Method Details

#argument_class_nameObject

TODO: Use class rather than class name



47
48
49
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 47

def argument_class_name
  type_info.argument_class_name
end

#array_length_idxObject



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

def array_length_idx
  type_info.array_length
end

#array_length_parameter?Boolean

Returns:



73
74
75
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 73

def array_length_parameter?
  @array_arg
end

#call_argument_nameObject



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

def call_argument_name
  @call_argument_name ||= new_variable
end

#closure_idxObject



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

def closure_idx
  arginfo.closure
end

#destroy_idxObject



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

def destroy_idx
  arginfo.destroy
end

#destroy_notifier?Boolean

Returns:



81
82
83
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 81

def destroy_notifier?
  @is_destroy_notifier
end

#directionObject



34
35
36
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 34

def direction
  @direction ||= arginfo.direction
end

#helper_argument?Boolean

Returns:



85
86
87
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 85

def helper_argument?
  array_length_parameter? || user_data? || destroy_notifier?
end

#mark_as_destroy_notifier(callback_builder) ⇒ Object



68
69
70
71
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 68

def mark_as_destroy_notifier(callback_builder)
  @is_destroy_notifier = true
  @related_callback_builder = callback_builder
end

#mark_as_user_data(callback_builder) ⇒ Object



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

def mark_as_user_data(callback_builder)
  @is_user_data = true
  @related_callback_builder = callback_builder
end

#nameObject



30
31
32
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 30

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

#new_variableObject



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

def new_variable
  @var_gen.new_var
end

#ownership_transferObject



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

def ownership_transfer
  arginfo.ownership_transfer
end

#safe(name) ⇒ Object



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

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

#specialized_type_tagObject



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

def specialized_type_tag
  type_info.flattened_tag
end

#type_infoObject



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

def type_info
  @type_info ||= arginfo.argument_type
end

#user_data?Boolean

Returns:



77
78
79
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 77

def user_data?
  @is_user_data
end