modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
new file: src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java new file: src/de/dhbwstuttgart/typeinference/unify/visitUnifyTypeVisitor.java
This commit is contained in:
parent
fae26a8f26
commit
5680f913ef
@ -312,7 +312,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||
Set<Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
List<Set<UnifyPair>> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
||||
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
||||
try {
|
||||
//List<Set<UnifyPair>>
|
||||
nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
||||
}
|
||||
catch (java.lang.IllegalArgumentException e) {
|
||||
System.out.print("");
|
||||
}
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
int variance = 0;
|
||||
Optional<Integer> xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType)
|
||||
@ -615,8 +622,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// Init all 8 cases
|
||||
for(int i = 0; i < 8; i++)
|
||||
result.add(new HashSet<>());
|
||||
ArrayList<UnifyPair> eq2sprime = new ArrayList<>(eq2s);
|
||||
Iterator<UnifyPair> eq2sprimeit = eq2sprime.iterator();
|
||||
ArrayList<UnifyPair> eq2sAsList = new ArrayList<>();
|
||||
while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben
|
||||
UnifyPair up = eq2sprimeit.next();
|
||||
if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0)
|
||||
|| (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0)) {
|
||||
eq2sAsList.add(up);
|
||||
eq2s.remove(up);
|
||||
}
|
||||
}
|
||||
eq2sAsList.addAll(eq2s);
|
||||
Boolean first = true;
|
||||
for(UnifyPair pair : eq2s) {
|
||||
for(UnifyPair pair : eq2sAsList) {
|
||||
PairOperator pairOp = pair.getPairOp();
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
|
@ -0,0 +1,19 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
|
||||
public class distributeVariance extends visitUnifyTypeVisitor<Integer> {
|
||||
|
||||
@Override
|
||||
public PlaceholderType visit(PlaceholderType phty, Integer ht) {
|
||||
if (ht != 0) {
|
||||
if (phty.getVariance() == 0) {
|
||||
phty.setVariance(ht);
|
||||
}
|
||||
else if (phty.getVariance() != ht) {
|
||||
phty.setVariance(0);
|
||||
}
|
||||
}
|
||||
return phty;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
||||
|
||||
@ -119,8 +120,11 @@ public final class PlaceholderType extends UnifyType{
|
||||
|
||||
@Override
|
||||
UnifyType apply(Unifier unif) {
|
||||
if(unif.hasSubstitute(this))
|
||||
return unif.getSubstitute(this);
|
||||
if(unif.hasSubstitute(this)) {
|
||||
UnifyType ret = unif.getSubstitute(this);
|
||||
ret.accept(new distributeVariance(), this.getVariance());
|
||||
return ret;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||
|
||||
public class visitUnifyTypeVisitor<T> implements UnifyTypeVisitor<T> {
|
||||
|
||||
public ReferenceType visit(ReferenceType refty, T ht) {
|
||||
return new ReferenceType(refty.getName(),
|
||||
new TypeParams(
|
||||
Arrays.stream(refty.getTypeParams().get())
|
||||
.map(x -> x.accept(this, ht))
|
||||
.collect(Collectors.toCollection(ArrayList::new))));
|
||||
}
|
||||
|
||||
public PlaceholderType visit(PlaceholderType phty, T ht) {
|
||||
return phty;
|
||||
}
|
||||
|
||||
public FunNType visit(FunNType funnty, T ht) {
|
||||
return FunNType.getFunNType(
|
||||
new TypeParams(
|
||||
Arrays.stream(funnty.getTypeParams().get())
|
||||
.map(x -> x.accept(this, ht))
|
||||
.collect(Collectors.toCollection(ArrayList::new)))
|
||||
);
|
||||
}
|
||||
|
||||
public SuperType visit(SuperType suty, T ht) {
|
||||
return new SuperType(suty.getWildcardedType().accept(this, ht));
|
||||
}
|
||||
|
||||
public ExtendsType visit(ExtendsType extty, T ht) {
|
||||
return new ExtendsType(extty.getWildcardedType().accept(this, ht));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user