modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java Variance wieder auskommentiert modified: test/javFiles/Matrix.jav import String
This commit is contained in:
parent
93d0caaefb
commit
087170bdbf
@ -143,6 +143,7 @@ public class JavaTXCompiler {
|
||||
}
|
||||
return x;
|
||||
}).collect(Collectors.toCollection(HashSet::new));
|
||||
varianceInferitance(xConsSet);
|
||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile);
|
||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||
System.out.println("RESULT: " + result);
|
||||
@ -157,6 +158,43 @@ public class JavaTXCompiler {
|
||||
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) {
|
||||
HashMap<String, TypePlaceholder> ret = new HashMap<>();
|
||||
constraints.map((Pair p) -> {
|
||||
|
@ -827,6 +827,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
.filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
//TODO: Wenn Theta' nicht im FC muss ein Fehler produziert werden PL 18-04-20
|
||||
/**
|
||||
* Cartesian product Case 1: (a <. Theta')
|
||||
*/
|
||||
|
@ -78,20 +78,20 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<P
|
||||
public UnifyPair apply(UnifyPair thisAsPair, UnifyPair p) {
|
||||
UnifyType newLhs = this.apply(p.getLhsType());
|
||||
UnifyType newRhs = this.apply(p.getRhsType());
|
||||
//Varianceweitergabe
|
||||
PlaceholderType lhsph = (PlaceholderType)thisAsPair.getLhsType();
|
||||
if (lhsph.getVariance() != 0) {
|
||||
if (p.getLhsType().equals(lhsph)) {
|
||||
if (p.getRhsType() instanceof PlaceholderType) {
|
||||
((PlaceholderType)p.getRhsType()).setVariance(lhsph.getVariance());
|
||||
}
|
||||
}
|
||||
if (p.getRhsType().equals(lhsph)) {
|
||||
if (p.getLhsType() instanceof PlaceholderType) {
|
||||
((PlaceholderType)p.getLhsType()).setVariance(lhsph.getVariance());
|
||||
}
|
||||
}
|
||||
}
|
||||
//Varianceweitergabe wird nicht benoetigt.
|
||||
//PlaceholderType lhsph = (PlaceholderType)thisAsPair.getLhsType();
|
||||
//if (lhsph.getVariance() != 0) {
|
||||
// if (p.getLhsType().equals(lhsph)) {
|
||||
// if (p.getRhsType() instanceof PlaceholderType) {
|
||||
// ((PlaceholderType)p.getRhsType()).setVariance(lhsph.getVariance());
|
||||
// }
|
||||
// }
|
||||
// if (p.getRhsType().equals(lhsph)) {
|
||||
// if (p.getLhsType() instanceof PlaceholderType) {
|
||||
// ((PlaceholderType)p.getLhsType()).setVariance(lhsph.getVariance());
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwendung von this hat was veraendert PL 2018-04-01
|
||||
Set<UnifyPair> suniUnifyPair = new HashSet<>();
|
||||
suniUnifyPair.addAll(thisAsPair.getAllSubstitutions());
|
||||
|
@ -1,6 +1,7 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Boolean;
|
||||
import java.lang.String;
|
||||
|
||||
class Matrix extends Vector<Vector<Integer>> {
|
||||
Integer mul1(Integer x, Integer y) { return x;}
|
||||
|
Loading…
Reference in New Issue
Block a user