diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index cae65fae..6eb74d16 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -11,6 +12,7 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.Set; import java.util.concurrent.RecursiveTask; +import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -749,7 +751,11 @@ public class TypeUnifyTask extends RecursiveTask>> { //System.out.println(i); //if (i == 62) // System.out.println(tqp.toString()); - Optional opt = stdUnify.unify(tqp.setTypeParams(newTp), thetaPrime); + BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; + HashMap hm = tqp.getInvolvedPlaceholderTypes().stream() + .reduce(new HashMap(), + (x, y)-> { x.put(y,PlaceholderType.freshPlaceholder()); return x; }, combiner); + Optional opt = stdUnify.unify(tqp.accept(new freshPlaceholder(), hm), thetaPrime); if (!opt.isPresent()) { //tpq muesse freshtv gesetzt werden PL 2018-03-16 continue; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java b/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java new file mode 100644 index 00000000..45ccb6bb --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java @@ -0,0 +1,47 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.HashMap; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; +import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import de.dhbwstuttgart.typeinference.unify.model.SuperType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; + +public class freshPlaceholder implements UnifyTypeVisitor { + + public ReferenceType visit(ReferenceType refty, HashMap ht) { + return new ReferenceType(refty.getName(), + new TypeParams( + Arrays.stream(refty.getTypeParams().get()) + .map(x -> x.accept(this, ht)) + .collect(Collectors.toCollection(ArrayList::new)))); + } + + public PlaceholderType visit(PlaceholderType phty, HashMap ht) { + return ht.get(phty); + } + + public FunNType visit(FunNType funnty, HashMap ht) { + return FunNType.getFunNType( + new TypeParams( + Arrays.stream(funnty.getTypeParams().get()) + .map(x -> x.accept(this, ht)) + .collect(Collectors.toCollection(ArrayList::new))) + ); + } + + public SuperType visit(SuperType suty, HashMap ht) { + return new SuperType(suty.getWildcardedType().accept(this, ht)); + } + + public ExtendsType visit(ExtendsType extty, HashMap ht) { + return new ExtendsType(extty.getWildcardedType().accept(this, ht)); + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index 510e4162..a97977c5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -2,7 +2,7 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -13,7 +13,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public final class ExtendsType extends WildcardType { - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 44a4fa71..dd96dedd 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -1,6 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.model; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public class FunNType extends UnifyType { - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index a85f356f..5aab8784 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -2,8 +2,8 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; -import java.util.Hashtable; import java.util.Random; import java.util.Set; @@ -56,7 +56,7 @@ public final class PlaceholderType extends UnifyType{ IsGenerated = isGenerated; } - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java index f1023862..133a87ed 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java @@ -1,6 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.model; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -19,7 +19,7 @@ public final class ReferenceType extends UnifyType { private final int hashCode; - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index c746bd47..0b98c159 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -1,6 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.model; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public final class SuperType extends WildcardType { - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 66bd80a8..16986d65 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -2,7 +2,7 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; -import java.util.Hashtable; +import java.util.HashMap; import java.util.List; import java.util.Set; @@ -37,7 +37,7 @@ public abstract class UnifyType { } - abstract public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht); + abstract public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht); /** * Returns the name of the type.