forked from JavaTX/JavaCompilerCore
modified: ../../src/de/dhbwstuttgart/typeinference/constraints/Pair.java
modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Varinace in UnfyPair eingefuegt und Abfrage in computeCartesianRecursive eingefuegt Pruefen, ob Varianve bei Subst und andrene erhalten bleibt.
This commit is contained in:
parent
9862df9e63
commit
b5b5b5d9c9
@ -11,6 +11,7 @@ public class Pair implements Serializable
|
||||
public final RefTypeOrTPHOrWildcardOrGeneric TA2;
|
||||
|
||||
private PairOperator eOperator = PairOperator.SMALLER;
|
||||
|
||||
|
||||
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2 )
|
||||
{
|
||||
|
@ -312,18 +312,42 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
ArrayList<Set<UnifyPair>> nextSetasList = new ArrayList<>(nextSet);
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
int i = 0;
|
||||
Set<UnifyPair> a_next;
|
||||
if (nextSetasList.size()>1)
|
||||
a_next = oup.min(nextSetasList.iterator());
|
||||
else a_next = nextSetasList.iterator().next();
|
||||
byte variance = nextSetasList.iterator().next().iterator().next().getVariance();
|
||||
Set<UnifyPair> a_next = null;
|
||||
if (nextSetasList.size()>1) {
|
||||
if (variance == 1) {
|
||||
a_next = oup.max(nextSetasList.iterator());
|
||||
}
|
||||
else if (variance == -1) {
|
||||
a_next = oup.min(nextSetasList.iterator());
|
||||
}
|
||||
else if (variance == 0) {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
while (nextSetasList.size() != 0) {
|
||||
Set<UnifyPair> a = a_next;
|
||||
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
|
||||
nextSetasList.remove(a);
|
||||
if (nextSetasList.size() > 0)
|
||||
if (nextSetasList.size()>1)
|
||||
a_next = oup.min(nextSetasList.iterator());
|
||||
else a_next = nextSetasList.iterator().next();
|
||||
nextSetasList.remove(a);
|
||||
if (nextSetasList.size() > 0) {
|
||||
if (nextSetasList.size()>1) {
|
||||
if (variance == 1) {
|
||||
a_next = oup.max(nextSetasList.iterator());
|
||||
}
|
||||
else if (variance == -1) {
|
||||
a_next = oup.min(nextSetasList.iterator());
|
||||
}
|
||||
else {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
a_next = nextSetasList.iterator().next();
|
||||
}
|
||||
}
|
||||
//PL 2018-03-01
|
||||
//TODO: 1. Maximum und Minimum unterscheiden
|
||||
//TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern
|
||||
@ -338,10 +362,30 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
else {
|
||||
result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
||||
}
|
||||
if (!result.isEmpty()) //&& (oup.compare(a, a_next) == -1)) break;
|
||||
if (a.equals(a_next) ||
|
||||
(oup.compare(a, a_next) == -1))
|
||||
if (!result.isEmpty()) {
|
||||
if (variance == 1) {
|
||||
if (a.equals(a_next) || (oup.compare(a, a_next) == 1)) {
|
||||
System.out.print("");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
else { if (variance == -1) {
|
||||
if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) {
|
||||
System.out.print("");
|
||||
break;
|
||||
}
|
||||
else {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
else if (variance == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -528,7 +572,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) {
|
||||
//System.out.println(pair);
|
||||
if (first) { //writeLog(pair.toString()+"\n");
|
||||
Set<Set<UnifyPair>> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc);
|
||||
Set<Set<UnifyPair>> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), pair.getVariance(), fc);
|
||||
//System.out.println(x1);
|
||||
result.get(0).add(x1);
|
||||
}
|
||||
@ -544,7 +588,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// Case 2: (a <.? ? ext Theta')
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
|
||||
if (first) { //writeLog(pair.toString()+"\n");
|
||||
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc));
|
||||
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), pair.getVariance(), fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
@ -557,7 +601,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// Case 3: (a <.? ? sup Theta')
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
|
||||
if (first) { //writeLog(pair.toString()+"\n");
|
||||
result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc));
|
||||
result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, pair.getVariance(), fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
@ -575,7 +619,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// Case 5: (Theta <. a)
|
||||
else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType)
|
||||
if (first) { //writeLog(pair.toString()+"\n");
|
||||
result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc));
|
||||
result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
@ -599,7 +643,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
|
||||
if (first) { //writeLog(pair.toString()+"\n");
|
||||
result.get(7).add(
|
||||
unifyCase8(lhsType, (PlaceholderType) rhsType, fc));
|
||||
unifyCase8(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc));
|
||||
}
|
||||
else {
|
||||
Set<UnifyPair> s1 = new HashSet<>();
|
||||
@ -627,7 +671,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/**
|
||||
* Cartesian product Case 1: (a <. Theta')
|
||||
*/
|
||||
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
|
||||
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, byte variance, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
boolean allGen = thetaPrime.getTypeParams().size() > 0;
|
||||
@ -704,6 +748,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT));
|
||||
resultPrime.addAll(substitutionSet);
|
||||
//writeLog("Substitution: " + substitutionSet.toString());
|
||||
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
result.add(resultPrime);
|
||||
//writeLog("Result: " + resultPrime.toString());
|
||||
//writeLog("MAX: " + oup.max(resultPrime.iterator()).toString());
|
||||
@ -719,7 +764,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/**
|
||||
* Cartesian Product Case 2: (a <.? ? ext Theta')
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) {
|
||||
private Set<Set<UnifyPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, byte variance, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||
@ -732,6 +777,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT));
|
||||
resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT));
|
||||
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
result.add(resultPrime);
|
||||
//writeLog("Result: " + resultPrime.toString());
|
||||
return result;
|
||||
@ -740,7 +786,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/**
|
||||
* Cartesian Product Case 3: (a <.? ? sup Theta')
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) {
|
||||
private Set<Set<UnifyPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, byte variance, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||
@ -754,6 +800,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT));
|
||||
resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
|
||||
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
result.add(resultPrime);
|
||||
//writeLog(resultPrime.toString());
|
||||
|
||||
@ -763,7 +810,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/**
|
||||
* Cartesian Product Case 5: (Theta <. a)
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
||||
private Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
boolean allGen = theta.getTypeParams().size() > 0;
|
||||
@ -786,6 +833,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
|
||||
else
|
||||
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT));
|
||||
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
result.add(resultPrime);
|
||||
//writeLog(resultPrime.toString());
|
||||
}
|
||||
@ -796,7 +844,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
/**
|
||||
* Cartesian Product Case 8: (Theta <.? a)
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
||||
private Set<Set<UnifyPair>> unifyCase8(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) {
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
//for(UnifyType thetaS : fc.grArg(theta)) {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
@ -814,6 +862,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
resultPrime = new HashSet<>();
|
||||
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT));
|
||||
resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT));
|
||||
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
result.add(resultPrime);
|
||||
//writeLog(resultPrime.toString());
|
||||
//}
|
||||
|
@ -26,6 +26,8 @@ public class UnifyPair {
|
||||
*/
|
||||
private PairOperator pairOp;
|
||||
|
||||
private byte variance = 0;
|
||||
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
@ -64,6 +66,13 @@ public class UnifyPair {
|
||||
return pairOp;
|
||||
}
|
||||
|
||||
public byte getVariance() {
|
||||
return variance;
|
||||
}
|
||||
|
||||
public void setVariance(byte v) {
|
||||
variance = v;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof UnifyPair))
|
||||
|
Loading…
Reference in New Issue
Block a user