class CType
Constants
- KNOWN_TYPES
REFACTOR: nuke this
- TYPES
Attributes
list[RW]
type[RW]
Public Class Methods
function(lhs_type, arg_types, return_type = nil)
click to toggle source
# File lib/type.rb, line 37 def self.function lhs_type, arg_types, return_type = nil unless return_type then $stderr.puts "\nWARNING: adding Type.unknown for #{caller[0]}" if $DEBUG # TODO: gross, maybe go back to the *args version from method_missing return_type = arg_types arg_types = lhs_type lhs_type = CType.unknown end self.new FunctionType.new(lhs_type, arg_types, return_type) end
method_missing(type, *args)
click to toggle source
# File lib/type.rb, line 53 def self.method_missing(type, *args) raise "Unknown type Type.#{type} (#{type.inspect})" unless KNOWN_TYPES.has_key?(type) if type.to_s =~ /(.*)_list$/ then TYPES[type] = self.new($1.intern, true) unless TYPES.has_key?(type) return TYPES[type] else TYPES[type] = self.new(type) unless TYPES.has_key?(type) return TYPES[type] end end
new(type, list=false)
click to toggle source
# File lib/type.rb, line 73 def initialize(type, list=false) # HACK unless KNOWN_TYPES.has_key? type or type.class.name =~ /Type$/ then raise "Unknown type Type.new(#{type.inspect})" end @type = Handle.new type @list = list end
unknown()
click to toggle source
# File lib/type.rb, line 49 def self.unknown self.new :unknown end
unknown_list()
click to toggle source
# File lib/type.rb, line 66 def self.unknown_list self.new(:unknown, true) end
Public Instance Methods
eql?(other)
click to toggle source
# File lib/type.rb, line 99 def eql?(other) return nil unless other.class == self.class other.type == self.type && other.list? == self.list? end
Also aliased as: ==
function?()
click to toggle source
# File lib/type.rb, line 82 def function? not KNOWN_TYPES.has_key? self.type.contents end
hash()
click to toggle source
# File lib/type.rb, line 107 def hash type.contents.hash ^ @list.hash end
inspect()
click to toggle source
# File lib/type.rb, line 144 def inspect to_s end
list?()
click to toggle source
# File lib/type.rb, line 90 def list? @list end
list_type()
click to toggle source
REFACTOR: this should be named type, but that'll break code at the moment
# File lib/type.rb, line 95 def list_type @type.contents end
to_s()
click to toggle source
# File lib/type.rb, line 138 def to_s str = "Type.#{self.type.contents}" str << "_list" if self.list? str end
unify(other)
click to toggle source
# File lib/type.rb, line 111 def unify(other) return other.unify(self) if Array === other return self if other == self and (not self.unknown?) return self if other.nil? if self.unknown? and other.unknown? then # link types between unknowns self.type = other.type self.list = other.list? or self.list? # HACK may need to be tri-state elsif self.unknown? then # other's type is now my type self.type.contents = other.type.contents self.list = other.list? elsif other.unknown? then # my type is now other's type other.type.contents = self.type.contents other.list = self.list? elsif self.function? and other.function? then self_fun = self.type.contents other_fun = other.type.contents self_fun.unify_components other_fun else raise TypeError, "Unable to unify #{self.inspect} with #{other.inspect}" end return self end
unknown?()
click to toggle source
# File lib/type.rb, line 86 def unknown? self.type.contents == :unknown end