forked from JavaTX/JavaCompilerCore
modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java 1. Version läuft aber nicht schnell
This commit is contained in:
parent
bda7dcb5c1
commit
1b7bded3c3
@ -31,6 +31,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@ -553,8 +554,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
}
|
||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
||||
|
||||
|
||||
if (isUndefinedPairSetSet(res)) {
|
||||
int nofstred= 0;
|
||||
Set<UnifyPair> abhSubst = res.stream()
|
||||
.map(b ->
|
||||
b.stream()
|
||||
@ -569,35 +571,41 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//Set<PlaceholderType> vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||
int len = nextSetasList.size();
|
||||
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>> reducedUndefResSubstGroundedBasePair = undefRes.stream()
|
||||
.map(x -> { Set<UnifyPair> su = x.getAllSubstitutions(); su.add(x.getGroundBasePair().get()); return su;})
|
||||
.map(y -> { y.removeAll(durchschnitt); return y;})
|
||||
//UnifyPair groundBasepair = res.iterator().next().iterator().next().getGroundBasePair().get();
|
||||
Set<UnifyPair> undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results
|
||||
Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream()
|
||||
.map(x -> { Set<UnifyPair> su = x.getAllSubstitutions(); //alle benutzten Substitutionen
|
||||
su.add(x.getGroundBasePair()); // urspruengliches Paar
|
||||
su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen
|
||||
return new Pair<>(su, x.getGroundBasePair());})
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> resGroundBasepairs = undefRes.stream().map(x -> x.getGroundBasePair().get()).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);
|
||||
//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))
|
||||
})//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
nofstred = nextSetasList.size();
|
||||
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||
// .collect(Collectors.toCollection(ArrayList::new));
|
||||
}
|
||||
writeLog("abhSubst: " + abhSubst.toString());
|
||||
writeLog("a: " + a.toString());
|
||||
writeLog("Durchschnitt: " + durchschnitt.toString());
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
writeLog("Number first erased Elements (undef): " + (len - nofstred));
|
||||
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size()));
|
||||
noAllErasedElements = noAllErasedElements + (len - nextSetasList.size());
|
||||
writeLog("Number erased Elements (undef): " + noAllErasedElements.toString());
|
||||
writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString());
|
||||
noBacktracking++;
|
||||
writeLog("Number of Backtracking: " + noBacktracking);
|
||||
System.out.println("");
|
||||
@ -613,32 +621,35 @@ 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;
|
||||
}
|
||||
protected boolean couldBecorrect(Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set<UnifyPair> nextElem) {
|
||||
return reducedUndefResSubstGroundedBasePair.stream()
|
||||
.map(pair -> {
|
||||
Set<UnifyPair> reducedAbhSubst = pair.getKey();
|
||||
reducedAbhSubst.addAll(nextElem);
|
||||
Optional<Set<UnifyPair>> substRes = rules.subst(reducedAbhSubst);
|
||||
if (!substRes.isPresent()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
//Pair type <. type' betrachten TODO PL 2018-10-09
|
||||
UnifyPair checkPair = substRes.get().stream()
|
||||
.filter(x -> x.getGroundBasePair().equals(pair.getValue().get())).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;
|
||||
return true;}).reduce((xx, yy) -> xx || yy).get();
|
||||
}
|
||||
|
||||
protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
|
||||
|
@ -152,12 +152,12 @@ public class UnifyPair {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Optional<UnifyPair> getGroundBasePair () {
|
||||
public UnifyPair getGroundBasePair () {
|
||||
if (basePair == null) {
|
||||
return Optional.empty();
|
||||
return this;
|
||||
}
|
||||
if (basePair.getBasePair() == null) {
|
||||
return Optional.of(basePair);
|
||||
return basePair;
|
||||
}
|
||||
else {
|
||||
return basePair.getGroundBasePair();
|
||||
|
Loading…
Reference in New Issue
Block a user