Class: FFI::Clang::Types::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi/clang/types/type.rb

Overview

Represents a type in the C/C++ type system. This class wraps libclang’s type representation and provides methods to query type properties.

Direct Known Subclasses

Array, Elaborated, Function, Pointer, Record, TypeDef, Vector

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, translation_unit) ⇒ Type

Create a new type instance.



51
52
53
54
# File 'lib/ffi/clang/types/type.rb', line 51

def initialize(type, translation_unit)
  @type = type
  @translation_unit = translation_unit
end

Instance Attribute Details

#translation_unitObject (readonly)

Returns the value of attribute translation_unit.



21
# File 'lib/ffi/clang/types/type.rb', line 21

attr_reader :type, :translation_unit

#typeObject (readonly)



21
22
23
# File 'lib/ffi/clang/types/type.rb', line 21

def type
  @type
end

Class Method Details

.create(cxtype, translation_unit) ⇒ Object

Create a type instance of the appropriate subclass based on the type kind.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ffi/clang/types/type.rb', line 27

def self.create(cxtype, translation_unit)
  case cxtype[:kind]
  when :type_pointer, :type_block_pointer, :type_obj_c_object_pointer, :type_member_pointer
    Pointer.new(cxtype, translation_unit)
  when :type_constant_array, :type_incomplete_array, :type_variable_array, :type_dependent_sized_array
    Array.new(cxtype, translation_unit)
  when :type_vector
    Vector.new(cxtype, translation_unit)
  when :type_function_no_proto, :type_function_proto
    Function.new(cxtype, translation_unit)
  when :type_elaborated
    Elaborated.new(cxtype, translation_unit)
  when :type_typedef
    TypeDef.new(cxtype, translation_unit)
  when :type_record
    Record.new(cxtype, translation_unit)
  else
    Type.new(cxtype, translation_unit)
  end
end

Instance Method Details

#==(other) ⇒ Object

Compare this type with another for equality.



138
139
140
# File 'lib/ffi/clang/types/type.rb', line 138

def ==(other)
  Lib.equal_types(@type, other.type) != 0
end

#alignofObject

Get the alignment of this type in bytes.



106
107
108
# File 'lib/ffi/clang/types/type.rb', line 106

def alignof
  Lib.type_get_align_of(@type)
end

#canonicalObject

Get the canonical type.



76
77
78
# File 'lib/ffi/clang/types/type.rb', line 76

def canonical
  Type.create Lib.get_canonical_type(@type), @translation_unit
end

#const_qualified?Boolean

Check if this type is const-qualified.

Returns:

  • (Boolean)


88
89
90
# File 'lib/ffi/clang/types/type.rb', line 88

def const_qualified?
  Lib.is_const_qualified_type(@type) != 0
end

#declarationObject

Get the cursor for the declaration of this type.



124
125
126
# File 'lib/ffi/clang/types/type.rb', line 124

def declaration
  Cursor.new Lib.get_type_declaration(@type), @translation_unit
end

#kindObject

Get the kind of this type.



58
59
60
# File 'lib/ffi/clang/types/type.rb', line 58

def kind
  @type[:kind]
end

#kind_spellingObject

Get the spelling of this type’s kind.



64
65
66
# File 'lib/ffi/clang/types/type.rb', line 64

def kind_spelling
  Lib.extract_string Lib.get_type_kind_spelling @type[:kind]
end

#non_reference_typeObject

Get the non-reference type. For reference types, returns the type that is being referenced.



131
132
133
# File 'lib/ffi/clang/types/type.rb', line 131

def non_reference_type
  Type.create Lib.get_non_reference_type(@type),@translation_unit
end

#pod?Boolean

Check if this is a Plain Old Data (POD) type.

Returns:

  • (Boolean)


82
83
84
# File 'lib/ffi/clang/types/type.rb', line 82

def pod?
  Lib.is_pod_type(@type) != 0
end

#ref_qualifierObject

Get the ref-qualifier for this type (C++ only).



118
119
120
# File 'lib/ffi/clang/types/type.rb', line 118

def ref_qualifier
  Lib.type_get_cxx_ref_qualifier(@type)
end

#restrict_qualified?Boolean

Check if this type is restrict-qualified.

Returns:

  • (Boolean)


100
101
102
# File 'lib/ffi/clang/types/type.rb', line 100

def restrict_qualified?
  Lib.is_restrict_qualified_type(@type) != 0
end

#sizeofObject

Get the size of this type in bytes.



112
113
114
# File 'lib/ffi/clang/types/type.rb', line 112

def sizeof
  Lib.type_get_size_of(@type)
end

#spellingObject

Get the spelling of this type.



70
71
72
# File 'lib/ffi/clang/types/type.rb', line 70

def spelling
  Lib.extract_string Lib.get_type_spelling(@type)
end

#to_sObject

Get a string representation of this type.



144
145
146
# File 'lib/ffi/clang/types/type.rb', line 144

def to_s
  "#{self.class.name} <#{self.kind}: #{self.spelling}>"
end

#volatile_qualified?Boolean

Check if this type is volatile-qualified.

Returns:

  • (Boolean)


94
95
96
# File 'lib/ffi/clang/types/type.rb', line 94

def volatile_qualified?
  Lib.is_volatile_qualified_type(@type) != 0
end