forked from JavaTX/JavaCompilerCore
modified: ../../../../main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
isInherited für ? extends wieder mit gleich gesetzt modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Variance = -1 und Oderconstraints Vererbung eingebaut Variance = 0 min/max eingebaut
This commit is contained in:
parent
6deeb4105f
commit
fd3d4e97a1
@ -183,7 +183,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
!(x.TA2 instanceof TypePlaceholder))
|
!(x.TA2 instanceof TypePlaceholder))
|
||||||
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
|
||||||
: x)
|
: x)
|
||||||
.collect(Collectors.toCollection(() -> new Constraint<Pair>(true)));
|
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
|
||||||
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
|
||||||
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
|
||||||
methodConstraints.add(extendsOneMethodConstraint);
|
methodConstraints.add(extendsOneMethodConstraint);
|
||||||
|
@ -633,8 +633,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
oderConstraint = true;
|
oderConstraint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnifyPair oderRec = null;
|
if (oderConstraint) {//Varianz-Bestimmung Oder-Constraints
|
||||||
if (oderConstraint) {
|
|
||||||
if (printtag) System.out.println("nextSetasList " + nextSetasList);
|
if (printtag) System.out.println("nextSetasList " + nextSetasList);
|
||||||
Optional<Integer> optVariance =
|
Optional<Integer> optVariance =
|
||||||
nextSetasList.iterator()
|
nextSetasList.iterator()
|
||||||
@ -662,9 +661,10 @@ 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<>();
|
||||||
|
Optional<UnifyPair> optOrigPair = null;
|
||||||
//if (variance != 2) {
|
//if (variance != 2) {
|
||||||
if (!oderConstraint) {
|
if (!oderConstraint) {
|
||||||
Optional<UnifyPair> optOrigPair = nextSetElem.stream().filter(x -> (
|
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) &&
|
||||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
@ -695,13 +695,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/* sameEqSet-Bestimmung Ende */
|
/* sameEqSet-Bestimmung Ende */
|
||||||
|
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
UnifyPair a_rec = null;
|
|
||||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||||
Set<UnifyPair> a_last = a;
|
Set<UnifyPair> a_last = a;
|
||||||
|
|
||||||
|
//Liste der Faelle für die parallele Verarbeitung
|
||||||
List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
|
List<Set<UnifyPair>> nextSetasListRest = new ArrayList<>();
|
||||||
|
|
||||||
|
//Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt
|
||||||
|
//In der Regel ein Element
|
||||||
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
|
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
|
||||||
//List<Set<UnifyPair>> nextSetasListRestMin = new ArrayList<>();
|
|
||||||
//List<Set<UnifyPair>> nextSetasListRestOder = new ArrayList<>();
|
|
||||||
writeLog("nextSet: " + nextSet.toString());
|
writeLog("nextSet: " + nextSet.toString());
|
||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
@ -710,7 +713,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (oderConstraint) {
|
if (oderConstraint) {
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||||
}
|
}
|
||||||
writeLog("nextSetasListOderConstraints: " + nextSetasListOderConstraints);
|
writeLog("nextSetasListOderConstraints 1: " + nextSetasListOderConstraints);
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||||
while (nextSetasListItRest.hasNext()) {
|
while (nextSetasListItRest.hasNext()) {
|
||||||
@ -741,6 +744,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
else if (variance == -1) {
|
else if (variance == -1) {
|
||||||
a = oup.min(nextSetasList.iterator());
|
a = oup.min(nextSetasList.iterator());
|
||||||
writeLog("Min: a in " + variance + " "+ a);
|
writeLog("Min: a in " + variance + " "+ a);
|
||||||
|
if (oderConstraint) {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
||||||
|
}
|
||||||
|
writeLog("nextSetasListOderConstraints -1: " + nextSetasListOderConstraints);
|
||||||
nextSetasList.remove(a);
|
nextSetasList.remove(a);
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||||
@ -774,7 +781,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
}
|
}
|
||||||
else if (variance == 0) {
|
else if (variance == 0) {
|
||||||
a = nextSetasList.remove(0);
|
//wenn a <. theta dann ist ein maximales Element sehr wahrscheinlich
|
||||||
|
//wenn theta <. a dann ist ein minimales Element sehr wahrscheinlich
|
||||||
|
if (!oderConstraint && optOrigPair != null && optOrigPair.isPresent()) {
|
||||||
|
if (optOrigPair.get().getBasePair().getLhsType() instanceof PlaceholderType) {
|
||||||
|
a = oup.max(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a = oup.min(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
nextSetasList.remove(a);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a = nextSetasList.remove(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
|
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
|
||||||
//nextSetasList.remove(a);
|
//nextSetasList.remove(a);
|
||||||
@ -898,7 +918,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
|
else {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
|
}
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
@ -1006,7 +1028,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
|
else {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
||||||
|
}
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
@ -1296,6 +1320,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (oderConstraint) {
|
if (oderConstraint) {
|
||||||
nextSetasList.removeAll(nextSetasListOderConstraints);
|
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||||
nextSetasListOderConstraints = new ArrayList<>();
|
nextSetasListOderConstraints = new ArrayList<>();
|
||||||
|
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||||
while(aParDefIt.hasNext()) {
|
while(aParDefIt.hasNext()) {
|
||||||
Set<UnifyPair> a_new = aParDefIt.next();
|
Set<UnifyPair> a_new = aParDefIt.next();
|
||||||
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a_new, nextSetasList);
|
List<Set<UnifyPair>> smallerSetasList = oup.smallerThan(a_new, nextSetasList);
|
||||||
@ -1376,14 +1401,31 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
aParDef.add(a);
|
aParDef.add(a);
|
||||||
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
Iterator<Set<UnifyPair>> aParDefIt = aParDef.iterator();
|
||||||
if (oderConstraint) {
|
if (oderConstraint) {
|
||||||
|
nextSetasList.removeAll(nextSetasListOderConstraints);
|
||||||
|
writeLog("Removed: " + nextSetasListOderConstraints);
|
||||||
|
nextSetasListOderConstraints = new ArrayList<>();
|
||||||
while(aParDefIt.hasNext()) {
|
while(aParDefIt.hasNext()) {
|
||||||
Set<UnifyPair> a_new = aParDefIt.next();
|
Set<UnifyPair> a_new = aParDefIt.next();
|
||||||
List<Set<UnifyPair>> greaterSetasList = oup.greaterThan(a_new, nextSetasList);
|
List<Set<UnifyPair>> greaterSetasList = oup.greaterThan(a_new, nextSetasList);
|
||||||
|
|
||||||
|
//a_new muss hingefuegt werden, wenn es nicht vererbt ist, dann wird es spaeter wieder geloescht
|
||||||
|
if (!((Constraint<UnifyPair>)a_new).isInherited()) {
|
||||||
|
greaterSetasList.add(a_new);
|
||||||
|
}
|
||||||
List<Set<UnifyPair>> notInherited = greaterSetasList.stream()
|
List<Set<UnifyPair>> notInherited = greaterSetasList.stream()
|
||||||
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
.filter(x -> !((Constraint<UnifyPair>)x).isInherited())
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
List<Set<UnifyPair>> notErased = new ArrayList<>();
|
||||||
notInherited.stream().forEach(x -> { notErased.addAll(oup.greaterThan(x, greaterSetasList)); });
|
|
||||||
|
//Wenn x nicht vererbt ist, beginnt beim naechstgroesseren Element die naechste Ueberladung
|
||||||
|
notInherited.stream().forEach(x -> { notErased.addAll(oup.greaterEqThan(x, greaterSetasList)); });
|
||||||
|
|
||||||
|
//das kleineste Element ist das Element von dem a_new geerbt hat
|
||||||
|
//muss deshalb geloescht werden
|
||||||
|
Set<UnifyPair> min = oup.min(notErased.iterator());
|
||||||
|
notErased.remove(min);
|
||||||
|
notErased.remove(((Constraint<UnifyPair>)min).getExtendConstraint());
|
||||||
|
|
||||||
List<Set<UnifyPair>> erased = new ArrayList<>(greaterSetasList);
|
List<Set<UnifyPair>> erased = new ArrayList<>(greaterSetasList);
|
||||||
erased.removeAll(notErased);
|
erased.removeAll(notErased);
|
||||||
nextSetasList.removeAll(erased);
|
nextSetasList.removeAll(erased);
|
||||||
@ -1393,7 +1435,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("Not Removed: " + nextSetasList);
|
writeLog("Not Removed: " + nextSetasList);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
while(aParDefIt.hasNext()) {
|
while(aParDefIt.hasNext()) {
|
||||||
//nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28
|
//nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28
|
||||||
|
Loading…
Reference in New Issue
Block a user