Class: C::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/castaddon/type.rb

Overview

This class provides an extention to the CAST type class. It contains a number of functions applicable to types such as pointers, arrays, structures, floats, integers, etc.

The provided methods are just helpers to extend the CAST functionality and to clean-up the Bones classes.

Instance Method Summary collapse

Instance Method Details

#array_or_pointer?Boolean

This method is used to determine whether the variable is an array and/or a pointer. Returns either true or false.

Returns:

  • (Boolean)


12
13
14
# File 'lib/castaddon/type.rb', line 12

def array_or_pointer?
  ((self.class == C::Array) || (self.class == C::Pointer))
end

#dimensions(count = 0) ⇒ Object

This method returns the variable’s dimension as an integer. it uses recursion in case the type is an array or a pointer. Types that are neither arrays nor pointers have a dimension of zero. For arrays and pointers, each ‘*’ or ‘[]’ contributes to one additional dimension.



30
31
32
# File 'lib/castaddon/type.rb', line 30

def dimensions(count=0)
  (self.array_or_pointer?) ? self.type.dimensions(count+1) : count
end

#type_nameObject

This method recursively searches for the type of a variable. Recursion is needed when a type is an array or a pointer. The method eventually returns one of the CAST algorithm types being either: void, int, float, char, bool, complex or imaginary.



21
22
23
# File 'lib/castaddon/type.rb', line 21

def type_name
  (self.array_or_pointer?) ? self.type.type_name : self
end