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 =
[
  "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.



19
20
21
22
23
24
25
# 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
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

#is_closureObject

Returns the value of attribute is_closure.



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

def is_closure
  @is_closure
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



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

def argument_class_name
  type_info.argument_class_name
end

#array_length_idxObject



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

def array_length_idx
  type_info.array_length
end

#callargObject



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

def callarg
  @callarg ||= new_variable
end

#directionObject



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

def direction
  @direction ||= arginfo.direction
end

#nameObject



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

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

#new_variableObject



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

def new_variable
  @var_gen.new_var
end

#safe(name) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/gir_ffi/builders/base_argument_builder.rb', line 52

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

#specialized_type_tagObject



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

def specialized_type_tag
  type_info.flattened_tag
end

#type_infoObject



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

def type_info
  @type_info ||= arginfo.argument_type
end