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



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

def argument_class_name
  type_info.argument_class_name
end

#array_length_idxObject



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

def array_length_idx
  type_info.array_length
end

#callargObject



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

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



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

def new_variable
  @var_gen.new_var
end

#safe(name) ⇒ Object



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

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

#specialized_type_tagObject



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

def specialized_type_tag
  # SMELL: Law of Demeter, due to this being arginfo.argument_type.flattened_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