Module: RubyBindgen::TypePointerFormatter

Defined in:
lib/ruby-bindgen/type_pointer_formatter.rb

Overview

Shared pointer-type formatting for both the fully-qualified-name shim and the Rice type speller. The caller supplies how non-pointer child types should be spelled.

Class Method Summary collapse

Class Method Details

.function_pointer_pointee?(type) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ruby-bindgen/type_pointer_formatter.rb', line 31

def function_pointer_pointee?(type)
  type.kind == :type_function_proto || type.kind == :type_function_no_proto
end

.pointer_spelling(type) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby-bindgen/type_pointer_formatter.rb', line 8

def pointer_spelling(type)
  pointee = type.pointee

  if function_pointer_pointee?(pointee)
    ptr_const = type.const_qualified? ? " const" : ""
    result_type = yield(pointee.result_type)
    arg_types = pointee.arg_types.map { |arg_type| yield(arg_type) }.join(", ")
    return "#{result_type} (*#{ptr_const})(#{arg_types})"
  end

  parts = []
  current = type
  while current.kind == :type_pointer
    inner = current.pointee
    break if function_pointer_pointee?(inner)

    parts << (current.const_qualified? ? "*const" : "*")
    current = inner
  end

  "#{yield(current)} #{parts.reverse.join}"
end