diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 76db7a2a..53390bbc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -601,6 +601,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList 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>> { } } else { - variance = 2; + //variance = 2; + oderConstraint = true; } - } else { - variance = 2; + //variance = 2; + oderConstraint = true; } + + if (oderConstraint) { + if (printtag) System.out.println("nextSetasList " + nextSetasList); + Optional 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> al = new ArrayList<>(nextSetasList.size()); // for (int ii = 0; ii < nextSetasList.size();ii++) { @@ -662,7 +679,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ Set sameEqSet = new HashSet<>(); - if (variance != 2) { + //if (variance != 2) { + if (!oderConstraint) { Optional 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> 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 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>> { } /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional 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 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>> { 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>> { 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 optAPair = nSaL.stream().filter(x -> ( + Optional 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>> { 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>> { } 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> aParDefIt = aParDef.iterator(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set 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 a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set 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) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index c342269b..8ce37eb6 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -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> { 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 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> { //if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) { // System.out.print(""); //} + + //ODER-CONSTRAINT + Set lefteqOder = lefteq.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof ReferenceType)) + .collect(Collectors.toCollection(HashSet::new)); + Set righteqOder = righteq.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof ReferenceType)) + .collect(Collectors.toCollection(HashSet::new)); + Set lefteqRet = left.stream() + .filter(x -> (x.getRhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) + .collect(Collectors.toCollection(HashSet::new)); + Set righteqRet = right.stream() + .filter(x -> (x.getRhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) + .collect(Collectors.toCollection(HashSet::new)); + Set leftleOder = left.stream() + .filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT)) + .collect(Collectors.toCollection(HashSet::new)); + Set 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 matchList = + leftleOder.stream().map(x -> { Iterator 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 matchList = + rightleOder.stream().map(x -> { Iterator 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; }