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:
Martin Plümicke 2018-04-20 13:16:49 +02:00
parent 93d0caaefb
commit 087170bdbf
4 changed files with 54 additions and 14 deletions

View File

@ -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);
@ -156,6 +157,43 @@ public class JavaTXCompiler {
return results.stream().map((unifyPairs ->
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<>();

View File

@ -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')
*/

View File

@ -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());

View File

@ -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;}