forked from JavaTX/JavaCompilerCore
modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
varianceInheritance nach TypeUnifyTask.java verschoben Kommentar eingefuegt TODO: 1. compare-Funktinen nochmals ueberpruefen 2. Undef-Pairs in JavaTXiCompiler.java abfangen 3. ? extends bei allen Argumenttypen und Returntypen rauslassen
This commit is contained in:
parent
087170bdbf
commit
0ae777b4ac
@ -23,6 +23,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||||
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
import de.dhbwstuttgart.typeinference.unify.RuleSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.inheritVariance;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
@ -143,7 +144,6 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
varianceInferitance(xConsSet);
|
|
||||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile);
|
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile);
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
@ -158,42 +158,7 @@ public class JavaTXCompiler {
|
|||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void varianceInferitance(Set<UnifyPair> xConsSet) {
|
|
||||||
Set<PlaceholderType> phSet = xConsSet.stream().map(x -> {
|
|
||||||
Set<PlaceholderType> pair = new HashSet<>();
|
|
||||||
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
|
||||||
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
|
||||||
return pair;
|
|
||||||
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
|
||||||
|
|
||||||
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
|
||||||
while(!phSetVariance.isEmpty()) {
|
|
||||||
PlaceholderType a = phSetVariance.remove(0);
|
|
||||||
xConsSet.stream().forEach(x -> { if (x.getLhsType() instanceof PlaceholderType
|
|
||||||
&& ((PlaceholderType)x.getLhsType()).equals(a)) {
|
|
||||||
((PlaceholderType)x.getLhsType()).setVariance(a.getVariance());
|
|
||||||
if (x.getRhsType() instanceof PlaceholderType
|
|
||||||
&& ((PlaceholderType)x.getRhsType()).getVariance() == 0) {
|
|
||||||
((PlaceholderType)x.getRhsType()).setVariance(a.getVariance());
|
|
||||||
phSetVariance.add((PlaceholderType)x.getRhsType());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
xConsSet.stream().forEach(x -> { if (x.getRhsType() instanceof PlaceholderType
|
|
||||||
&& ((PlaceholderType)x.getRhsType()).equals(a)) {
|
|
||||||
((PlaceholderType)x.getRhsType()).setVariance(a.getVariance());
|
|
||||||
if (x.getLhsType() instanceof PlaceholderType
|
|
||||||
&& ((PlaceholderType)x.getLhsType()).getVariance() == 0) {
|
|
||||||
((PlaceholderType)x.getLhsType()).setVariance(a.getVariance());
|
|
||||||
phSetVariance.add((PlaceholderType)x.getLhsType());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
|
||||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||||
|
@ -86,7 +86,53 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
rules = new RuleSet(logFile);
|
rules = new RuleSet(logFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vererbt alle Variancen
|
||||||
|
* @param eq The set of constraints
|
||||||
|
*/
|
||||||
|
private void varianceInheritance(Set<UnifyPair> eq) {
|
||||||
|
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||||
|
Set<PlaceholderType> pair = new HashSet<>();
|
||||||
|
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
||||||
|
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
||||||
|
return pair;
|
||||||
|
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
||||||
|
|
||||||
|
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
||||||
|
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
||||||
|
while(!phSetVariance.isEmpty()) {
|
||||||
|
PlaceholderType a = phSetVariance.remove(0);
|
||||||
|
HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
||||||
|
ht.put(a, a.getVariance());
|
||||||
|
eq.stream().forEach(x -> {
|
||||||
|
x.getLhsType().accept(new inheritVariance(), ht);
|
||||||
|
if (x.getLhsType() instanceof PlaceholderType
|
||||||
|
&& ((PlaceholderType)x.getLhsType()).equals(a)//) {
|
||||||
|
//((PlaceholderType)x.getLhsType()).setVariance(a.getVariance());
|
||||||
|
//if
|
||||||
|
&& x.getRhsType() instanceof PlaceholderType
|
||||||
|
&& ((PlaceholderType)x.getRhsType()).getVariance() == 0) {
|
||||||
|
((PlaceholderType)x.getRhsType()).setVariance(a.getVariance());
|
||||||
|
phSetVariance.add((PlaceholderType)x.getRhsType());
|
||||||
|
//}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
eq.stream().forEach(x -> {
|
||||||
|
x.getRhsType().accept(new inheritVariance(), ht);
|
||||||
|
if (x.getRhsType() instanceof PlaceholderType
|
||||||
|
&& ((PlaceholderType)x.getRhsType()).equals(a)//) {
|
||||||
|
//((PlaceholderType)x.getRhsType()).setVariance(a.getVariance());
|
||||||
|
//if
|
||||||
|
&& x.getLhsType() instanceof PlaceholderType
|
||||||
|
&& ((PlaceholderType)x.getLhsType()).getVariance() == 0) {
|
||||||
|
((PlaceholderType)x.getLhsType()).setVariance(a.getVariance());
|
||||||
|
phSetVariance.add((PlaceholderType)x.getLhsType());
|
||||||
|
//}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
return unify(eq, fc, parallel);
|
return unify(eq, fc, parallel);
|
||||||
@ -105,6 +151,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("Unifikation: " + eq.toString());
|
writeLog("Unifikation: " + eq.toString());
|
||||||
//eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new));
|
//eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Variancen auf alle Gleichungen vererben
|
||||||
|
*/
|
||||||
|
varianceInheritance(eq);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ? extends ? extends Theta rausfiltern
|
* ? extends ? extends Theta rausfiltern
|
||||||
*/
|
*/
|
||||||
|
@ -149,6 +149,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
if (rseq.getRhsType().getName().equals("Object")) return -1;
|
if (rseq.getRhsType().getName().equals("Object")) return -1;
|
||||||
}
|
}
|
||||||
if (leftlewc.size() == rightlewc.size()) {
|
if (leftlewc.size() == rightlewc.size()) {
|
||||||
|
//TODO: Hier wird bei Wildcards nicht das richtige compare aufgerufen PL 18-04-20
|
||||||
Pair<Integer, Set<UnifyPair>> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType());
|
Pair<Integer, Set<UnifyPair>> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType());
|
||||||
Unifier uni = new Unifier();
|
Unifier uni = new Unifier();
|
||||||
int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
||||||
|
Loading…
Reference in New Issue
Block a user