modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Variance auf PlacehloderType uebertragen
This commit is contained in:
parent
dbe05bb718
commit
95e9b2dbda
@ -126,27 +126,19 @@ public class JavaTXCompiler {
|
||||
|
||||
xConsSet = xConsSet.stream().map(x -> {
|
||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getLhsType().getName())
|
||||
&& (!(x.getRhsType() instanceof PlaceholderType)
|
||||
|| ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) {
|
||||
x.setVariance((byte)1);
|
||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getLhsType().getName())
|
||||
&& (!(x.getRhsType() instanceof PlaceholderType)
|
||||
|| ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) {
|
||||
x.setVariance((byte)-1);
|
||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||
}
|
||||
}
|
||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getRhsType().getName())
|
||||
&& (!(x.getLhsType() instanceof PlaceholderType)
|
||||
|| ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) {
|
||||
x.setVariance((byte)1);
|
||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getRhsType().getName())
|
||||
&& (!(x.getLhsType() instanceof PlaceholderType)
|
||||
|| ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) {
|
||||
x.setVariance((byte)-1);
|
||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
|
@ -314,7 +314,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
List<Set<UnifyPair>> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
byte variance = nextSetasList.iterator().next().iterator().next().getVariance();
|
||||
int variance = 0;
|
||||
Optional<Integer> xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType)
|
||||
.filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0)
|
||||
.map(c -> ((PlaceholderType)c.getLhsType()).getVariance())
|
||||
.reduce((a,b)-> a*b))
|
||||
.filter(d -> d.isPresent())
|
||||
.map(e -> e.get())
|
||||
.findAny();
|
||||
if (xi.isPresent()) {
|
||||
variance = xi.get();
|
||||
}
|
||||
if (variance == 1 && nextSetasList.size() > 1) {
|
||||
List<Set<UnifyPair>> al = new ArrayList<>(nextSetasList.size());
|
||||
for (int ii = 0; ii < nextSetasList.size();ii++) {
|
||||
|
@ -37,6 +37,15 @@ public final class PlaceholderType extends UnifyType{
|
||||
*/
|
||||
private final boolean IsGenerated;
|
||||
|
||||
/**
|
||||
* variance shows the variance of the pair
|
||||
* -1: contravariant
|
||||
* 1 covariant
|
||||
* 0 invariant
|
||||
* PL 2018-03-21
|
||||
*/
|
||||
private int variance = 0;
|
||||
|
||||
/**
|
||||
* Creates a new placeholder type with the specified name.
|
||||
*/
|
||||
@ -80,6 +89,14 @@ public final class PlaceholderType extends UnifyType{
|
||||
return IsGenerated;
|
||||
}
|
||||
|
||||
public void setVariance(int v) {
|
||||
variance = v;
|
||||
}
|
||||
|
||||
public int getVariance() {
|
||||
return variance;
|
||||
}
|
||||
|
||||
@Override
|
||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
||||
return fc.smArg(this);
|
||||
|
@ -72,6 +72,7 @@ public class UnifyPair {
|
||||
pairOp = op;
|
||||
unifier = uni;
|
||||
basePair = base;
|
||||
this.variance = variance;
|
||||
|
||||
|
||||
// Caching hashcode
|
||||
|
Loading…
Reference in New Issue
Block a user