Class: FFI::Clang::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-bindgen/refinements/cursor.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.namerObject



4
5
6
# File 'lib/ruby-bindgen/refinements/cursor.rb', line 4

def self.namer
  @namer || raise("Namer not set — generator must call Cursor.namer= before processing")
end

.namer=(value) ⇒ Object



8
9
10
# File 'lib/ruby-bindgen/refinements/cursor.rb', line 8

def self.namer=(value)
  @namer = value
end

Instance Method Details

#anonymous_definerObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby-bindgen/refinements/cursor.rb', line 20

def anonymous_definer
  return nil unless self.anonymous?

  if self.kind == :cursor_namespace
    return self
  end

  # This could be a typedef of a field declaration in union or struct
  #
  # typedef struct {
  #   union {
  #     char *sdata;
  #     int idata;
  #   } u;
  # } F_TextItemT;
  _, result = self.translation_unit.cursor.find do |child, parent|
    self.eql?(child) && (parent.kind == :cursor_field_decl ||
                         parent.kind == :cursor_typedef_decl)
  end

  # Or this could be a variable declaration
  #
  # struct {
  #   int Value;
  #   uint8_t String[4];
  # } MyArray_t;
  unless result
    variables = self.translation_unit.cursor.find_by_kind(true, :cursor_variable)
    result = variables.find do |variable|
      self.eql?(variable.type.declaration)
    end
  end
  result
end

#cruby_nameObject



16
17
18
# File 'lib/ruby-bindgen/refinements/cursor.rb', line 16

def cruby_name
  self.class.namer.cruby(self)
end

#ruby_nameObject



12
13
14
# File 'lib/ruby-bindgen/refinements/cursor.rb', line 12

def ruby_name
  self.class.namer.ruby(self)
end