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

modified:   src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java

variance = 2 umgesetzt auf variance = 1, variance = -1, variance = 0
This commit is contained in:
pl@gohorb.ba-horb.de 2020-03-19 17:03:54 +01:00
parent 592de5310e
commit ed1bb44089
2 changed files with 146 additions and 37 deletions

View File

@ -601,6 +601,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
Boolean oderConstraint = false;
if (fstBasePair != null) {
Boolean sameBase = true;
@ -620,13 +621,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
}
else {
variance = 2;
//variance = 2;
oderConstraint = true;
}
}
else {
variance = 2;
//variance = 2;
oderConstraint = true;
}
if (oderConstraint) {
if (printtag) System.out.println("nextSetasList " + nextSetasList);
Optional<Integer> optVariance =
nextSetasList.iterator()
.next()
.stream()
.filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType &&
x.getRhsType() instanceof ReferenceType &&
x.getPairOp() == PairOperator.EQUALSDOT)
.map(x -> ((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
.findAny();
variance = optVariance.isPresent() ? optVariance.get() : 2;
}
//if (variance == 1 && nextSetasList.size() > 1) {
// List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
// for (int ii = 0; ii < nextSetasList.size();ii++) {
@ -662,7 +679,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */
Set<UnifyPair> sameEqSet = new HashSet<>();
if (variance != 2) {
//if (variance != 2) {
if (!oderConstraint) {
Optional<UnifyPair> optOrigPair = nextSetElem.stream().filter(x -> (
//x.getBasePair() != null && ist gegeben wenn variance != 2
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
@ -803,7 +821,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> aParDef = new HashSet<>();
/* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
if (variance != 2 && !sameEqSet.isEmpty()) {
if (!oderConstraint && !sameEqSet.isEmpty()) {
Optional<UnifyPair> optAPair = a.stream().filter(x -> (
//x.getBasePair() != null && ist gegeben wenn variance != 2
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
@ -861,10 +879,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
//x.getBasePair() != null && ist gegeben wenn variance != 2
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
(x.getPairOp().equals(PairOperator.EQUALSDOT)
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
//x.getBasePair() != null && ist gegeben wenn variance != 2
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
(x.getPairOp().equals(PairOperator.EQUALSDOT)
/*
(x.getBasePair().getLhsType() instanceof PlaceholderType
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
@ -876,14 +895,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
x.getLhsType().equals(x.getBasePair().getRhsType())
).findFirst();
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
nSaL = null;
noShortendElements++;
continue;
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
nSaL = null;
noShortendElements++;
continue;
}
}
}
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
@ -966,8 +986,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("-1 RM" + nSaL.toString());
}
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
//x.getBasePair() != null && ist gegeben wenn variance != 2
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
(x.getPairOp().equals(PairOperator.EQUALSDOT)
@ -982,14 +1003,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
x.getLhsType().equals(x.getBasePair().getRhsType())
).findFirst();
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
nSaL = null;
noShortendElements++;
continue;
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
UnifyPair aPair = optAPair.get();
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
nSaL = null;
noShortendElements++;
continue;
}
}
}
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
@ -1346,7 +1368,51 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
else { if (variance == 0) {
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
break; }
if (!oderConstraint) {
break;
}
else {//TODO: Hier muessen alle kleineren und größeren Elemente von a geloescht werden
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
writeLog("aParDef: " + aParDef.toString());
aParDef.add(a);
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
while(aParDefIt.hasNext()) {
Set<UnifyPair> a_new = aParDefIt.next();
while (nextSetasListIt.hasNext()) {
Set<UnifyPair> a_next = nextSetasListIt.next();
if (a_new.equals(a_next) ||
(oup.compare(a_new, a_next) == -1)) {
writeLog("Removed: " + a_next.toString());
nextSetasList.remove(a_next); //PL geaendert 2019-01-09
}
else {
System.out.println("");
writeLog("Not Removed: " + a_next.toString());
}
}
}
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
writeLog("aParDef: " + aParDef.toString());
aParDefIt = aParDef.iterator();
while(aParDefIt.hasNext()) {
Set<UnifyPair> a_new = aParDefIt.next();
while (nextSetasListIt.hasNext()) {
Set<UnifyPair> a_next = nextSetasListIt.next();
if (a_new.equals(a_next) ||
(oup.compare(a_new, a_next) == 1)) {
writeLog("Removed: " + a_next.toString());
nextSetasList.remove(a_next);
}
else {
writeLog("Not Removed: " + a_next.toString());
System.out.println("");
}
}
}
}
}
else { if (variance == 2) {
/* vorgezogen vor das if
if (parallel) {

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@ -14,6 +15,7 @@ import java.util.stream.Stream;
import com.google.common.collect.Ordering;
import de.dhbwstuttgart.typeinference.unify.Match;
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
@ -165,16 +167,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
left.add(p4);
*/
if ((left.size() == 1) && right.size() == 1) {
if (left.iterator().next().getLhsType().getName().equals("AFS")) {
System.out.println("");
}
if (((right.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)right.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object")))
||((left.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)left.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object"))))
{
System.out.println("");
}
}
Set<UnifyPair> lefteq = left.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
.collect(Collectors.toCollection(HashSet::new));
@ -202,6 +195,56 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
// System.out.print("");
//}
//ODER-CONSTRAINT
Set<UnifyPair> lefteqOder = lefteq.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof ReferenceType))
.collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> righteqOder = righteq.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof ReferenceType))
.collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> lefteqRet = left.stream()
.filter(x -> (x.getRhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
.collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> righteqRet = right.stream()
.filter(x -> (x.getRhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
.collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> leftleOder = left.stream()
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
.collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> rightleOder = right.stream()
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
.collect(Collectors.toCollection(HashSet::new));
if (lefteqOder.size() == 1 && righteqOder.size() == 1 && lefteqRet.size() == 1 && righteqRet.size() == 1) {
Match m = new Match();
if (compareEq(lefteqOder.iterator().next(), righteqOder.iterator().next()) == -1) {
ArrayList<UnifyPair> matchList =
leftleOder.stream().map(x -> { Iterator<UnifyPair> rightleOderIt = rightleOder.iterator();
return new UnifyPair(x.getRhsType(), rightleOderIt.next().getRhsType(), PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(ArrayList::new));
if (m.match(matchList).isPresent()) {
return -1;
}
else {
return 0;
}
} else if (compareEq(lefteqOder.iterator().next(), righteqOder.iterator().next()) == 1) {
ArrayList<UnifyPair> matchList =
rightleOder.stream().map(x -> { Iterator<UnifyPair> leftOderIt = leftleOder.iterator();
return new UnifyPair(x.getRhsType(), leftOderIt.next().getRhsType(), PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(ArrayList::new));
if (m.match(matchList).isPresent()) {
return 1;
}
else {
return 0;
}
} else {
return 0;
}
}
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
return 1;
}