forked from JavaTX/JavaCompilerCore
modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
weitere Element rausfiltern angefangen modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Methode: getGroundBasePair eingefuegt
This commit is contained in:
parent
54b4ad97f6
commit
241c7f37d9
@ -566,15 +566,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
.filter(x -> b.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));
|
||||
//Set<PlaceholderType> 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<UnifyPair> undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get();
|
||||
Set<Set<UnifyPair>> reducedUndefResSubst = undefRes.stream()
|
||||
.map(x -> x.getAllSubstitutions()).map(y -> { y.removeAll(durchschnitt); return y;})
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> resGroundBasepairs = undefRes.stream().map(x -> x.getGroundBasePair().get()).collect(Collectors.toCollection(HashSet::new));
|
||||
if (res.size() > 1) {
|
||||
System.out.println();
|
||||
}
|
||||
Set<UnifyPair> 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<Set<Set<UnifyPair>>> {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected boolean couldBecorrect(Set<UnifyPair> reducedAbhSubst, UnifyPair groundBasepair, Set<UnifyPair> nextElem) {
|
||||
reducedAbhSubst.add(groundBasepair);
|
||||
reducedAbhSubst.addAll(nextElem);
|
||||
Optional<Set<UnifyPair>> 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<UnifyPair> up = new HashSet<>();
|
||||
up.add(checkPair);
|
||||
Set<UnifyPair> 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<UnifyPair> s) {
|
||||
if (s.size() >= 1 ) {
|
||||
Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y));
|
||||
|
@ -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<UnifyPair> 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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user