forked from JavaTX/JavaCompilerCore
modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Undefined Pairs auf oberster Ebene wird zu new HashTable<>() in compute new file: ../../src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Unterscheidung zw. <. <? ein compere eingefuegt modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java Attribut wildcardable eingefuegt
This commit is contained in:
parent
5f8c73f176
commit
62d44eb15c
@ -126,20 +126,30 @@ public class JavaTXCompiler {
|
||||
|
||||
|
||||
xConsSet = xConsSet.stream().map(x -> {
|
||||
//Hier muss ueberlegt werden, ob
|
||||
//1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
||||
// mit disableWildcardtable() werden.
|
||||
//2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
||||
//in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
||||
//PL 2018-04-23
|
||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
||||
((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
||||
((PlaceholderType)x.getLhsType()).disableWildcardtable();
|
||||
}
|
||||
}
|
||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||
}
|
||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
||||
((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
||||
((PlaceholderType)x.getRhsType()).disableWildcardtable();
|
||||
}
|
||||
}
|
||||
return x;
|
||||
|
@ -135,7 +135,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
@Override
|
||||
protected Set<Set<UnifyPair>> compute() {
|
||||
return unify(eq, fc, parallel);
|
||||
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
||||
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
||||
else return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -547,6 +549,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//.filter(y -> abhSubst.contains(y))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<PlaceholderType> vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||
int len = nextSetasList.size();
|
||||
nextSetasList = nextSetasList.stream().filter(x -> {
|
||||
//Boolean ret = false;
|
||||
//for (PlaceholderType var : vars) {
|
||||
@ -559,6 +562,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
writeLog("Durchschnitt: " + durchschnitt.toString());
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size()));
|
||||
System.out.println("");
|
||||
}
|
||||
//if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) {
|
||||
@ -959,15 +963,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
for (UnifyType tq : thetaQs) {
|
||||
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
|
||||
//eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen
|
||||
Set<UnifyType> smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType))
|
||||
.map(x -> {
|
||||
//BinaryOperator<HashMap<PlaceholderType,PlaceholderType>> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen
|
||||
//HashMap<PlaceholderType,PlaceholderType> hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben
|
||||
// .reduce(new HashMap<PlaceholderType,PlaceholderType>(),
|
||||
// (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner);
|
||||
return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));}
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
smaller.addAll(smaller_ext);
|
||||
if (a.isWildcardable()) {
|
||||
Set<UnifyType> smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType))
|
||||
.map(x -> {
|
||||
//BinaryOperator<HashMap<PlaceholderType,PlaceholderType>> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen
|
||||
//HashMap<PlaceholderType,PlaceholderType> hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben
|
||||
// .reduce(new HashMap<PlaceholderType,PlaceholderType>(),
|
||||
// (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner);
|
||||
return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));}
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
smaller.addAll(smaller_ext);
|
||||
}
|
||||
//eingefuegt PL 2018-03-29 Ende ? ext. theta hinzufuegen
|
||||
for(UnifyType theta : smaller) {
|
||||
List<UnifyType> freshTphs = new ArrayList<>();
|
||||
|
@ -0,0 +1,18 @@
|
||||
package de.dhbwstuttgart.typeinference.unify;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
|
||||
public class inheritVariance extends visitUnifyTypeVisitor<HashMap<PlaceholderType,Integer>> {
|
||||
|
||||
@Override
|
||||
public PlaceholderType visit(PlaceholderType phty, HashMap<PlaceholderType,Integer> ht) {
|
||||
if (ht.containsKey(phty)) {
|
||||
if (phty.getVariance() == 0) {
|
||||
phty.setVariance(ht.get(phty));
|
||||
}
|
||||
}
|
||||
return phty;
|
||||
}
|
||||
}
|
@ -53,7 +53,13 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
*/
|
||||
|
||||
public Pair<Integer,Set<UnifyPair>> compare (UnifyType left, UnifyType right) {
|
||||
UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT);
|
||||
UnifyPair up;
|
||||
if (left instanceof WildcardType || right instanceof WildcardType) {
|
||||
up = new UnifyPair(left, right, PairOperator.SMALLERDOTWC);
|
||||
}
|
||||
else {
|
||||
up = new UnifyPair(left, right, PairOperator.SMALLERDOT);
|
||||
}
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask();
|
||||
HashSet<UnifyPair> hs = new HashSet<>();
|
||||
hs.add(up);
|
||||
@ -61,7 +67,12 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count();
|
||||
if (smallerLen == 0) return new Pair<>(-1, smallerRes);
|
||||
else {
|
||||
up = new UnifyPair(right, left, PairOperator.SMALLERDOT);
|
||||
if (left instanceof WildcardType || right instanceof WildcardType) {
|
||||
up = new UnifyPair(right, left, PairOperator.SMALLERDOTWC);
|
||||
}
|
||||
else {
|
||||
up = new UnifyPair(right, left, PairOperator.SMALLERDOT);
|
||||
}
|
||||
//TypeUnifyTask unifyTask = new TypeUnifyTask();
|
||||
hs = new HashSet<>();
|
||||
hs.add(up);
|
||||
|
@ -38,6 +38,12 @@ public final class PlaceholderType extends UnifyType{
|
||||
*/
|
||||
private final boolean IsGenerated;
|
||||
|
||||
|
||||
/**
|
||||
* isWildcardable gibt an, ob ein Wildcardtyp dem PlaceholderType zugeordnet werden darf
|
||||
*/
|
||||
private boolean wildcardable = true;
|
||||
|
||||
/**
|
||||
* variance shows the variance of the pair
|
||||
* -1: contravariant
|
||||
@ -98,6 +104,13 @@ public final class PlaceholderType extends UnifyType{
|
||||
return variance;
|
||||
}
|
||||
|
||||
public Boolean isWildcardable() {
|
||||
return wildcardable;
|
||||
}
|
||||
public void disableWildcardtable() {
|
||||
wildcardable = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
||||
return fc.smArg(this);
|
||||
|
Loading…
Reference in New Issue
Block a user