module RubyBreaker::TypeComparer

This module compares two RubyBreaker-defined types for the syntactic equivalence.

Public Class Methods

compare(lhs,rhs) click to toggle source

This equal method determines whether two types are syntactically equivalent. Note that this is NOT a type equivalent check.

# File lib/rubybreaker/type/type_comparer.rb, line 95
def self.compare(lhs,rhs)
  if lhs == rhs
    is_equal = true
  elsif lhs.class != rhs.class 
    is_equal = false
  elsif lhs.instance_of?(NominalType)
    is_equal = (lhs.mod == rhs.mod)
  elsif lhs.instance_of?(SelfType)
    is_equal = rhs.instance_of?(SelfType)
  elsif lhs.instance_of?(DuckType)
    is_equal = duck_compare(lhs,rhs)
  elsif lhs.instance_of?(FusionType)
    is_equal = self.compare(lhs.nom_type, rhs.nom_type)        
    if is_equal # do more testing
      is_equal = duck_compare(lhs,rhs)
    end
  elsif lhs.instance_of?(MethodType)
    is_equal = lhs.meth_name == rhs.meth_name
    if is_equal # then do more testing
      is_equal = self.proc_compare(lhs,rhs)
    end
  elsif lhs.instance_of?(BlockType)
    is_equal = self.proc_compare(lhs,rhs)
  elsif lhs.instance_of?(MethodListType)
    is_equal = self.meth_list_compare(lhs,rhs)
  elsif lhs.instance_of?(OrType)
    is_equal = self.or_compare(lhs,rhs)
  elsif lhs.instance_of?(VarLengthType)
    is_equal = rhs.instance_of?(VarLengthType) && 
               self.compare(lhs.type, rhs.type)
  elsif lhs.instance_of?(OptionalType)
    is_equal = rhs.instance_of?(OptionalType) &&
               self.compare(lhs.type, rhs.type)
  else
    is_equal = lhs.class == rhs.class
  end
  return is_equal
end