/* zweic -- a compiler for zwei * * Stephane Micheloud & LAMP * * $Id$ */ package zweic; // Internal type abstract class Type { override def toString(): String = this match { case IClassType => "ClassType"; case IIntType => "IntType" case INullType => "NullType" case IBadType => "<Bad>" } def isSubtype(that: Type): Boolean = Pair(this, that) match { // ... à compléter ... case _ => false } def isSametype(that: Type): Boolean = Pair(this, that) match { // ... à compléter ... case _ => false } def lub(that: Type): Option[Type] = Pair(this, that) match { case Pair(IIntType, IIntType) => IIntType case Pair(IClassType(x), INullType) => t1 case Pair(INullType, IClassType(x)) => t2 case Pair(IClassType(c1), IClassType(c2)) => intersection(c1.superclasses, c2.superclasses) match { case t :: ts => t case List() => badLub(t1, t2) } case x => badLub(t1, t2) } } // Class type case class IClassType(c: ClassSymbol) extends Type; // Integer type case object IIntType extends Type; // Null type case object INullType extends Type; // Bad type case object IBadType extends Type;