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:
parent
592de5310e
commit
ed1bb44089
@ -601,6 +601,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
|
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
|
||||||
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
|
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
|
||||||
|
Boolean oderConstraint = false;
|
||||||
|
|
||||||
if (fstBasePair != null) {
|
if (fstBasePair != null) {
|
||||||
Boolean sameBase = true;
|
Boolean sameBase = true;
|
||||||
@ -620,13 +621,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
variance = 2;
|
//variance = 2;
|
||||||
|
oderConstraint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
//if (variance == 1 && nextSetasList.size() > 1) {
|
||||||
// List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
|
// List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
|
||||||
// for (int ii = 0; ii < nextSetasList.size();ii++) {
|
// 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 */
|
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */
|
||||||
Set<UnifyPair> sameEqSet = new HashSet<>();
|
Set<UnifyPair> sameEqSet = new HashSet<>();
|
||||||
if (variance != 2) {
|
//if (variance != 2) {
|
||||||
|
if (!oderConstraint) {
|
||||||
Optional<UnifyPair> optOrigPair = nextSetElem.stream().filter(x -> (
|
Optional<UnifyPair> optOrigPair = nextSetElem.stream().filter(x -> (
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
@ -803,7 +821,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
Set<Set<UnifyPair>> aParDef = new HashSet<>();
|
||||||
|
|
||||||
/* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* 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 -> (
|
Optional<UnifyPair> optAPair = a.stream().filter(x -> (
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//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 */
|
/* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
if (!oderConstraint) {//weiss nicht ob das wirklich stimmt
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
Optional<UnifyPair> optAPair = nSaL.stream().filter(x -> (
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
||||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
/*
|
/*
|
||||||
(x.getBasePair().getLhsType() instanceof PlaceholderType
|
(x.getBasePair().getLhsType() instanceof PlaceholderType
|
||||||
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|
||||||
@ -876,14 +895,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
x.getLhsType().equals(x.getBasePair().getRhsType())
|
x.getLhsType().equals(x.getBasePair().getRhsType())
|
||||||
).findFirst();
|
).findFirst();
|
||||||
|
|
||||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||||
UnifyPair aPair = optAPair.get();
|
UnifyPair aPair = optAPair.get();
|
||||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||||
nSaL = null;
|
nSaL = null;
|
||||||
noShortendElements++;
|
noShortendElements++;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* 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());
|
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 */
|
/* 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() != null && ist gegeben wenn variance != 2
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
||||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
@ -982,14 +1003,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
x.getLhsType().equals(x.getBasePair().getRhsType())
|
x.getLhsType().equals(x.getBasePair().getRhsType())
|
||||||
).findFirst();
|
).findFirst();
|
||||||
|
|
||||||
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a
|
||||||
UnifyPair aPair = optAPair.get();
|
UnifyPair aPair = optAPair.get();
|
||||||
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
//writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair());
|
||||||
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet);
|
||||||
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) {
|
||||||
nSaL = null;
|
nSaL = null;
|
||||||
noShortendElements++;
|
noShortendElements++;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* 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) {
|
else { if (variance == 0) {
|
||||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
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) {
|
else { if (variance == 2) {
|
||||||
/* vorgezogen vor das if
|
/* vorgezogen vor das if
|
||||||
if (parallel) {
|
if (parallel) {
|
||||||
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -14,6 +15,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.Match;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
|
||||||
@ -165,16 +167,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
left.add(p4);
|
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()
|
Set<UnifyPair> lefteq = left.stream()
|
||||||
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
@ -202,6 +195,56 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
||||||
// System.out.print("");
|
// 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) {
|
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user