From b8e229cf3fbbab0c7f5c521f7e372a28eec8dd20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 2 Jul 2018 17:24:16 +0200 Subject: [PATCH] modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java modified: ../javFiles/Matrix.jav --- .../typeinference/unify/RuleSet.java | 4 +- .../typeinference/unify/TypeUnifyTask.java | 38 ++++++++++++++++--- .../typeinference/unify/model/Unifier.java | 2 +- .../typeinference/unify/model/UnifyPair.java | 19 +++++++++- test/javFiles/Matrix.jav | 6 +-- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index b40dee30..6c3cfaad 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -938,7 +938,9 @@ public class RuleSet implements IRuleSet{ else { UnifyType freshTph = PlaceholderType.freshPlaceholder(); result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + Set fBounded = pair.getfBounded(); + fBounded.add(lhsType); + result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded)); } return Optional.of(result); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 0545fb95..1519faa5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -13,6 +13,7 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.Set; import java.util.concurrent.RecursiveTask; +import java.util.function.BiFunction; import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -447,6 +448,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); + writeLog("nextSetasList: " + nextSetasList.toString()); while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a = null; if (variance == 1) { @@ -488,6 +490,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> elems = new HashSet>(fstElems); elems.add(a); //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt + writeLog("Vor unify2 Aufruf: " + eq.toString()); Set> res = unify2(elems, eq, fc, parallel); if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen @@ -512,7 +515,8 @@ public class TypeUnifyTask extends RecursiveTask>> { //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); //} - + + /* auskommentiert um alle Loesungen zu bekommen ANFANG if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); @@ -582,6 +586,8 @@ public class TypeUnifyTask extends RecursiveTask>> { // result.removeIf(y -> isUndefinedPairSet(y)); //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); + * auskommentiert um alle Loesungen zu bekommen ENDE + */ } return result; } @@ -1094,7 +1100,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType supAPrime = new SuperType(aPrime); UnifyType thetaPrime = subThetaPrime.getSuperedType(); Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); result.add(resultPrime); //writeLog(resultPrime.toString()); @@ -1124,14 +1130,34 @@ public class TypeUnifyTask extends RecursiveTask>> { break; } - for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) { + for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { Set resultPrime = new HashSet<>(); + Match match = new Match(); UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); - resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); + Set fBounded = pair.getfBounded(); + + int i_ef = i; + BiFunction f = (x,y) -> + { + ArrayList termList = new ArrayList(); + termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); + return ((match.match(termList).isPresent()) || x); + }; + //if (parai.getName().equals("java.lang.Integer")) { + // System.out.println(""); + //} + BinaryOperator bo = (x,y) -> (x || y); + if (fBounded.stream().reduce(false,f,bo)) { + resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + } + else { + fBounded.add(theta); + resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair, fBounded)); + } } if(allGen) @@ -1165,9 +1191,9 @@ public class TypeUnifyTask extends RecursiveTask>> { ((PlaceholderType)freshTph).setVariance(a.getVariance()); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); - resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); result.add(resultPrime); - //writeLog(resultPrime.toString()); + writeLog("resultPrime: " + resultPrime.toString()); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 8f594844..f2bc5277 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -102,7 +102,7 @@ public class Unifier implements Function, Iterable fBounded = new HashSet<>(); private final int hashCode; @@ -82,6 +89,12 @@ public class UnifyPair { hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); } + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded) { + this(lhs, rhs, op, uni, base); + + this.fBounded = fBounded; + } + /** * Returns the type on the left hand side of the pair. */ @@ -138,6 +151,10 @@ public class UnifyPair { return lhs.wrongWildcard() || rhs.wrongWildcard(); } + public Set getfBounded() { + return this.fBounded; + } + @Override public boolean equals(Object obj) { if(!(obj instanceof UnifyPair)) @@ -177,7 +194,7 @@ public class UnifyPair { if (rhs instanceof PlaceholderType) { ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString(); } - return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; + return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])"; } /* diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index 4c55c410..18120deb 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -15,9 +15,9 @@ class Matrix extends Vector> { var erg = 0; var k = 0; while(k < v1.size()) { - erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j); - // erg = add1(erg, mul1(v1.elementAt(k), - // m.elementAt(k).elementAt(j))); + //erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j); + erg = add1(erg, mul1(v1.elementAt(k), + m.elementAt(k).elementAt(j))); k++; } v2.addElement(new Integer(erg)); j++; }