diff --git a/src/main/scala/hb/dhbw/FiniteClosure.scala b/src/main/scala/hb/dhbw/FiniteClosure.scala index 519a6bb..c3411b9 100644 --- a/src/main/scala/hb/dhbw/FiniteClosure.scala +++ b/src/main/scala/hb/dhbw/FiniteClosure.scala @@ -1,9 +1,8 @@ package hb.dhbw -trait FJNamedType{ - def name: String - def params: List[FJNamedType] -} +sealed case class FJType() +sealed case class FJNamedType(name: String, params: List[FJType]) extends FJType +sealed case class FJTypeVariable(name: String) extends FJType class FiniteClosure(val extendsRelations : Set[(FJNamedType, FJNamedType)]){ @@ -17,13 +16,13 @@ class FiniteClosure(val extendsRelations : Set[(FJNamedType, FJNamedType)]){ rel.map(_._2) } private def reflexiveTypes(of: Set[(FJNamedType, FJNamedType)]) ={ - val ref = Set.newBuilder[(UnifyRefType, UnifyRefType)] + val ref = Set.newBuilder[(FJNamedType, FJNamedType)] ref ++= of.map(pair => (pair._1, pair._1)) ref ++= of.map(pair => (pair._2, pair._2)) ref.result() } private def transitiveTypes(of: Set[(FJNamedType, FJNamedType)]) ={ - val ref = Set.newBuilder[(UnifyRefType, UnifyRefType)] + val ref = Set.newBuilder[(FJNamedType, FJNamedType)] ref ++= of.flatMap(pair => of.filter(p => p._1.eq(pair._2))) ref.result() } @@ -31,16 +30,21 @@ class FiniteClosure(val extendsRelations : Set[(FJNamedType, FJNamedType)]){ val extendsRelation = extendsRelations.filter(pair => pair._1.name.equals(of.name)) extendsRelation.map(p => { val paramMap = p._1.params.zip(of.params).toMap - (of,UnifyRefType(p._2.name, p._2.params.map(paramMap))) + (of,FJNamedType(p._2.name, p._2.params.map(paramMap))) }) } private def superClassTypes(of: Set[(FJNamedType, FJNamedType)]) : Set[(FJNamedType, FJNamedType)] ={ - val sClass = Set.newBuilder[(UnifyRefType, UnifyRefType)] + val sClass = Set.newBuilder[(FJNamedType, FJNamedType)] sClass ++= of.flatMap(pair => Set(pair._2, pair._1)).flatMap(t => superClassTypes(t)) sClass.result() } - def superTypes(of : UnifyRefType) : Set[UnifyRefType] = calculateSupertypes(of) + private def convert(unifyType: UnifyType): FJType = unifyType match { + case UnifyRefType(n, p) => FJNamedType(n, p.map(convert(_))) + case UnifyTV(n) => FJTypeVariable(n) + } + + def superTypes(of : UnifyRefType) : Set[UnifyRefType] = calculateSupertypes(convert(of).asInstanceOf[FJNamedType]) def isPossibleSupertype(of: String, superType: String): Boolean = { val extendsMap = extendsRelations.map(p => (p._1.name,p._2.name)).toMap