modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java

modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
UndefPairs werden zurueckgegegeben und die naechsten gefiltert

protected boolean isUndefinedPairSet(Set<UnifyPair> s) hat Fehler
This commit is contained in:
Martin Plümicke 2018-04-04 21:47:07 +02:00
parent 52f480147e
commit 1baaf79f8c
2 changed files with 32 additions and 3 deletions

View File

@ -317,6 +317,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
ArrayList<Set<Set<UnifyPair>>> remainingSets = topLevelSets.stream()
.filter(x -> x.size()>1)
.collect(Collectors.toCollection(ArrayList::new));
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
Set<Set<UnifyPair>> result = unify2(fstElems, eq, fc, parallel);
return result;
}
Set<Set<UnifyPair>> nextSet = remainingSets.remove(0);
writeLog("nextSet: " + nextSet.toString());
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
@ -432,9 +436,32 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
}
}
if (isUndefinedPairSetSet(result)) {
Set<UnifyPair> abhSubst = result.stream().findFirst()
.get()
.stream()
.map(x -> x.getAllSubstitutions())
.reduce((y,z) -> { y.addAll(z); return y;}).get();
Set<UnifyPair> durchschnitt = abhSubst.stream()
.filter(x -> a.contains(x))
.filter(y -> abhSubst.contains(y))
.collect(Collectors.toCollection(HashSet::new));
Set<PlaceholderType> 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<Set<Set<UnifyPair>>> {
protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
Falsch!
Optional<Boolean> res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y));
if (res.isPresent()) { return res.get(); }
else { return false; }

View File

@ -125,10 +125,12 @@ public class UnifyPair {
return undefinedPair;
}
Set<UnifyPair> getAllSubstitutions () {
public Set<UnifyPair> getAllSubstitutions () {
Set<UnifyPair> ret = new HashSet<>();
ret.addAll(getSubstitution());
if (basePair != null) {
ret.addAll(basePair.getAllSubstitutions());
}
return ret;
}