Class: FFI::Clang::Types::Pointer

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

Overview

Represents a pointer type. This includes regular pointers, block pointers, Objective-C object pointers, and member pointers.

Instance Attribute Summary

Attributes inherited from Type

#translation_unit, #type

Instance Method Summary collapse

Methods inherited from Type

#==, #address_space, #alignof, #canonical, #const_qualified?, #copy_assignable?, #copyable?, create, #declaration, #fqn_elaborated, #fqn_impl, #fqn_pointer, #fqn_record, #fqn_template_args, #fully_qualified_name, #initialize, #intrinsic_type, #kind, #kind_spelling, #modified_type, #non_reference_type, #nullability, #num_template_arguments, #parse_template_args_from_spelling, #pod?, #pretty_printed, #ref_qualifier, #reference?, #restrict_qualified?, #sizeof, #spelling, #template_argument_type, #to_s, #transparent_tag_typedef?, #typedef_name, #unqualified_type, #value_type, #visit_base_classes, #visit_fields, #visit_methods, #volatile_qualified?

Constructor Details

This class inherits a constructor from FFI::Clang::Types::Type

Instance Method Details

#class_typeObject

Get the class type for member pointers.



27
28
29
30
31
32
33
# File 'lib/ffi/clang/types/pointer.rb', line 27

def class_type
	if self.kind == :type_member_pointer
		Type.create Lib.type_get_class_type(@type), @translation_unit
	else
		nil
	end
end

#forward_declaration?Boolean

Check if this pointer references a forward declaration.

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ffi/clang/types/pointer.rb', line 37

def forward_declaration?
	pointee = self.pointee
	return nil if self.function?
	
	# Resolve to a Record type, handling both elaborated and direct record types.
	# Newer clang versions (22+) may return :type_record directly instead of
	# wrapping in :type_elaborated.
	record_type = if pointee.is_a?(Types::Elaborated) && pointee.canonical.is_a?(Types::Record)
		pointee.canonical
	elsif pointee.is_a?(Types::Record)
		pointee
	end
	
	return nil unless record_type
	
	# Get the universal symbol reference
	usr = record_type.declaration.usr
	
	# Now does that same usr occur earlier in the file?
	first_declaration, _ = self.translation_unit.cursor.find do |child, parent|
		child.usr == usr
	end
	# NOTE - Maybe should also check that the line number of
	# is less than the line number of the declaration this type references
	first_declaration.forward_declaration?
end

#function?Boolean

Check if this is a function pointer.

Returns:

  • (Boolean)


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

def function?
	self.pointee.is_a?(Types::Function)
end

#pointeeObject

Get the type that this pointer points to.



15
16
17
# File 'lib/ffi/clang/types/pointer.rb', line 15

def pointee
	Type.create Lib.get_pointee_type(@type), @translation_unit
end