FFI::ClangSourceFFIClangTypesType

class Type

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

Definitions

attr_reader :type, :translation_unit

Signature

attribute r

type

returns FFI::Struct

The underlying CXType structure.

attribute r

translation_unit

returns TranslationUnit

The translation unit this type belongs to.

def self.create(cxtype, translation_unit)

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

Signature

parameter cxtype FFI::Struct

The low-level CXType structure.

parameter translation_unit TranslationUnit

The translation unit this type belongs to.

returns Type

A Type instance of the appropriate subclass.

Implementation

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

def initialize(type, translation_unit)

Create a new type instance.

Signature

parameter type FFI::Struct

The low-level CXType structure.

parameter translation_unit TranslationUnit

The translation unit this type belongs to.

Implementation

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

def kind

Get the kind of this type.

Signature

returns Symbol

The type kind (e.g., :type_int, :type_pointer).

Implementation

def kind
	@type[:kind]
end

def kind_spelling

Get the spelling of this type's kind.

Signature

returns String

A human-readable string describing the type kind.

Implementation

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

def spelling

Get the spelling of this type.

Signature

returns String

The type as it would appear in source code.

Implementation

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

def canonical

Get the canonical type.

Signature

returns Type

The canonical (unqualified, unaliased) form of this type.

Implementation

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

def pod?

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

Signature

returns Boolean

True if this is a POD type.

Implementation

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

def const_qualified?

Check if this type is const-qualified.

Signature

returns Boolean

True if the type has a const qualifier.

Implementation

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

def volatile_qualified?

Check if this type is volatile-qualified.

Signature

returns Boolean

True if the type has a volatile qualifier.

Implementation

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

def restrict_qualified?

Check if this type is restrict-qualified.

Signature

returns Boolean

True if the type has a restrict qualifier.

Implementation

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

def alignof

Get the alignment of this type in bytes.

Signature

returns Integer

The alignment requirement in bytes.

Implementation

def alignof
	Lib.type_get_align_of(@type)
end

def sizeof

Get the size of this type in bytes.

Signature

returns Integer

The size in bytes, or -1 if the size cannot be determined.

Implementation

def sizeof
	Lib.type_get_size_of(@type)
end

def ref_qualifier

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

Signature

returns Symbol

The ref-qualifier (:ref_qualifier_none, :ref_qualifier_lvalue, :ref_qualifier_rvalue).

Implementation

def ref_qualifier
	Lib.type_get_cxx_ref_qualifier(@type)
end

def declaration

Get the cursor for the declaration of this type.

Signature

returns Cursor

The cursor representing the type declaration.

Implementation

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

def non_reference_type

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

Signature

returns Type

The non-reference type.

Implementation

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

def ==(other)

Compare this type with another for equality.

Signature

parameter other Type

The other type to compare.

returns Boolean

True if the types are equal.

Implementation

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

def to_s

Get a string representation of this type.

Signature

returns String

A string describing this type.

Implementation

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