Sha256: 57a78ea2c1ce1c160b079c9084b7a9b58f66de04dec6a0e8e9f23de83d1779d2
Contents?: true
Size: 1.26 KB
Versions: 3
Compression:
Stored size: 1.26 KB
Contents
module C # 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. class Type # This method is used to determine whether the variable is # an array and/or a pointer. Returns either true or false. def array_or_pointer? ((self.class == C::Array) || (self.class == C::Pointer)) end # 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. def type_name (self.array_or_pointer?) ? self.type.type_name : self end # 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. def dimensions(count=0) (self.array_or_pointer?) ? self.type.dimensions(count+1) : count end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bones-compiler-1.6.0 | lib/castaddon/type.rb |
bones-compiler-1.3.1 | lib/castaddon/type.rb |
bones-compiler-1.1.0 | lib/castaddon/type.rb |