diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 23a2750c..5ef59413 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -143,6 +143,7 @@ public class JavaTXCompiler { } return x; }).collect(Collectors.toCollection(HashSet::new)); + varianceInferitance(xConsSet); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> 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 xConsSet) { + Set phSet = xConsSet.stream().map(x -> { + Set 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 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 generateTPHMap(ConstraintSet constraints) { HashMap ret = new HashMap<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 69caef2c..e590c302 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -827,6 +827,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .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') */ diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index f0f8164c..8f594844 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -78,20 +78,20 @@ public class Unifier implements Function, Iterable suniUnifyPair = new HashSet<>(); suniUnifyPair.addAll(thisAsPair.getAllSubstitutions()); diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index a680370f..ad8d735e 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -1,6 +1,7 @@ import java.util.Vector; import java.lang.Integer; import java.lang.Boolean; +import java.lang.String; class Matrix extends Vector> { Integer mul1(Integer x, Integer y) { return x;}