diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 0e396810d..3f9466cfa 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -566,15 +566,29 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> b.contains(x)) //.filter(y -> abhSubst.contains(y)) .collect(Collectors.toCollection(HashSet::new)); - Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + //Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); int len = nextSetasList.size(); - nextSetasList = nextSetasList.stream().filter(x -> { - //Boolean ret = false; - //for (PlaceholderType var : vars) { - // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); - //} - return (!x.containsAll(durchschnitt)); - }).collect(Collectors.toCollection(ArrayList::new)); + if (!durchschnitt.isEmpty()) { + UnifyPair groundBasepair = res.iterator().next().iterator().next().getGroundBasePair().get(); + Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); + Set> reducedUndefResSubst = undefRes.stream() + .map(x -> x.getAllSubstitutions()).map(y -> { y.removeAll(durchschnitt); return y;}) + .collect(Collectors.toCollection(HashSet::new)); + Set resGroundBasepairs = undefRes.stream().map(x -> x.getGroundBasePair().get()).collect(Collectors.toCollection(HashSet::new)); + if (res.size() > 1) { + System.out.println(); + } + Set reducedAbhSubst = new HashSet<>(abhSubst); + reducedAbhSubst.removeAll(durchschnitt); + nextSetasList = nextSetasList.stream().filter(x -> { + //Boolean ret = false; + //for (PlaceholderType var : vars) { + // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); + //} + return (!x.containsAll(durchschnitt)); + }).filter(y -> couldBecorrect(reducedAbhSubst, groundBasepair, y)) + .collect(Collectors.toCollection(ArrayList::new)); + } writeLog("abhSubst: " + abhSubst.toString()); writeLog("a: " + a.toString()); writeLog("Durchschnitt: " + durchschnitt.toString()); @@ -598,7 +612,34 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } - + protected boolean couldBecorrect(Set reducedAbhSubst, UnifyPair groundBasepair, Set nextElem) { + reducedAbhSubst.add(groundBasepair); + reducedAbhSubst.addAll(nextElem); + Optional> substRes = rules.subst(reducedAbhSubst); + if (!substRes.isPresent()) { + return true; + } + else { + UnifyPair checkPair = substRes.get().stream().filter(x -> x.getGroundBasePair().get().equals(groundBasepair)).findFirst().get(); + if ((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType)) { + Set up = new HashSet<>(); + up.add(checkPair); + Set undef = new HashSet<>(); + calculatePairSets(up, fc, undef); + if (undef.isEmpty()) { + return true; + } + else { + return false; + } + } + else { + //Pair type <. type' betrachten TODO PL 2018-10-09 + } + } + return true; + } + protected boolean isUndefinedPairSet(Set s) { if (s.size() >= 1 ) { Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 86e13e1d7..dd1858365 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; @@ -151,6 +152,18 @@ public class UnifyPair { return ret; } + public Optional getGroundBasePair () { + if (basePair == null) { + return Optional.empty(); + } + if (basePair.getBasePair() == null) { + return Optional.of(basePair); + } + else { + return basePair.getGroundBasePair(); + } + } + public Boolean wrongWildcard() { return lhs.wrongWildcard() || rhs.wrongWildcard(); }