diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8fe9e477..06783d9c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -317,6 +317,10 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingSets = topLevelSets.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); + if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig + Set> result = unify2(fstElems, eq, fc, parallel); + return result; + } Set> nextSet = remainingSets.remove(0); writeLog("nextSet: " + nextSet.toString()); List> nextSetasList =new ArrayList<>(nextSet); @@ -432,9 +436,32 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } + if (isUndefinedPairSetSet(result)) { + Set abhSubst = result.stream().findFirst() + .get() + .stream() + .map(x -> x.getAllSubstitutions()) + .reduce((y,z) -> { y.addAll(z); return y;}).get(); + Set durchschnitt = abhSubst.stream() + .filter(x -> a.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)); + 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)); + System.out.println(""); + } if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { return result; } + else { + result.removeIf(y -> isUndefinedPairSet(y)); + } //else result.stream().filter(y -> !isUndefinedPairSet(y)); } return result; @@ -442,7 +469,7 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean isUndefinedPairSet(Set s) { - + Falsch! Optional res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y)); if (res.isPresent()) { return res.get(); } else { return false; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 8f1c6d57..b3d0c85a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -125,10 +125,12 @@ public class UnifyPair { return undefinedPair; } - Set getAllSubstitutions () { + public Set getAllSubstitutions () { Set ret = new HashSet<>(); ret.addAll(getSubstitution()); - + if (basePair != null) { + ret.addAll(basePair.getAllSubstitutions()); + } return ret; }