Class: RCGTK::Type Abstract

Inherits:
Object
  • Object
show all
Includes:
Filigree::AbstractClass, BindingClass
Defined in:
lib/rcgtk/type.rb

Overview

This class is abstract.

Root of the type class hierarchy.

The Type class and its sub-classes are used to describe the size and structure of various data objects inside LLVM and how different operations interact with them. When instantiating objects of the Value class you will often need to pass in some type information.

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BindingClass

#==

Constructor Details

#initialize(context = nil) ⇒ Type

The default constructor for Type objects.

Parameters:

  • context (Context, nil) (defaults to: nil)

    An optional context in which to create the type.



66
67
68
69
70
71
72
73
74
75
# File 'lib/rcgtk/type.rb', line 66

def initialize(context = nil)
	bname = Bindings.get_bname(self.class.short_name)

	@ptr =
	if context
		Bindings.send((bname.to_s + '_in_context').to_sym, check_type(context, Context, 'context'))
	else
		Bindings.send(bname)
	end
end

Class Method Details

.from_ptr(ptr) ⇒ Type

Instantiate a Type object from a pointer. This function is used internally, and as a library user you should never have to call it.

Parameters:

  • ptr (FFI::Pointer)

Returns:

  • (Type)

    A object of type Type or one of its sub-classes.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rcgtk/type.rb', line 42

def self.from_ptr(ptr)
	case Bindings.get_type_kind(ptr)
	when :array     then ArrayType.new(ptr)
	when :half      then HalfType.new
	when :double    then DoubleType.new
	when :float     then FloatType.new
	when :function  then FunctionType.new(ptr)
	when :fp128     then FP128Type.new
	when :integer   then IntType.new
	when :label     then LabelType.new
	when :metadata  then raise "Can't generate a Type object for objects of type Metadata."
	when :pointer   then PointerType.new(ptr)
	when :ppc_fp128 then PPCFP128Type.new
	when :struct    then StructType.new(ptr)
	when :vector    then VectorType.new(ptr)
	when :void      then VoidType.new
	when :x86_fp80  then X86FP80Type.new
	when :x86_mmx   then X86MMXType.new
	end
end

Instance Method Details

#allignmentNativeInt

Returns Alignment of the type.

Returns:



78
79
80
# File 'lib/rcgtk/type.rb', line 78

def allignment
	NativeInt.new(Bindings.align_of(@ptr))
end

#contextContext

Returns Context in which this type was created.

Returns:

  • (Context)

    Context in which this type was created.



83
84
85
# File 'lib/rcgtk/type.rb', line 83

def context
	Context.new(Bindings.get_type_context(@ptr))
end

#dumpvoid

This method returns an undefined value.

Dump a string representation of the type to stdout.



90
91
92
# File 'lib/rcgtk/type.rb', line 90

def dump
	Bindings.dump_type(@ptr)
end

#hashFixnum

Returns Hashed value of the pointer representing this type.

Returns:

  • (Fixnum)

    Hashed value of the pointer representing this type.



95
96
97
# File 'lib/rcgtk/type.rb', line 95

def hash
	@ptr.address.hash
end

#kindSymbol

Returns The kind of this type.

Returns:

  • (Symbol)

    The kind of this type.

See Also:



102
103
104
# File 'lib/rcgtk/type.rb', line 102

def kind
	Bindings.get_type_kind(@ptr)
end

#sizeNativeInt

Returns Size of objects of this type.

Returns:

  • (NativeInt)

    Size of objects of this type.



107
108
109
# File 'lib/rcgtk/type.rb', line 107

def size
	Int64.new(Bindings.size_of(@ptr))
end

#to_sString

Returns LLVM IR representation of the type.

Returns:

  • (String)

    LLVM IR representation of the type



112
113
114
# File 'lib/rcgtk/type.rb', line 112

def to_s
	Bindings.print_type_to_string(@ptr)
end