diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index fb4e14dac..adc86d348 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -590,10 +590,14 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren //Typen getestet werden. writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); + writeLog(nOfUnify.toString() + " collectErr: " + collectErr.toString()); if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); // If pairs occured that did not match one of the cartesian product cases, // those pairs are contradictory and the unification is impossible. if(!undefinedPairs.isEmpty()) { + Set flatCollectErr = new HashSet<>(); + collectErr.forEach(x -> flatCollectErr.addAll(x)); + undefinedPairs.addAll(flatCollectErr); noUndefPair++; for (UnifyPair up : undefinedPairs) { writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); @@ -602,6 +606,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> error = new HashSet<>(); undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); error.add(undefinedPairs); + undefinedPairs.forEach(x -> writeLog("AllSubst: " +x.getAllSubstitutions().toString())); return error; } @@ -642,7 +647,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, collectErr); } @@ -764,7 +769,7 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set> collectErr) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -1208,7 +1213,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES Fst:" + result.toString() + " " + res.toString()); + writeLog("RES Fst:" + result.toString() + " " + res.toString() + " " + collectErr.toString()); + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen + result.addAll(collectErr); + } result.addAll(res); } } @@ -1239,6 +1247,9 @@ public class TypeUnifyTask extends RecursiveTask>> { || result.isEmpty()) { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen + result.addAll(collectErr); + } result.addAll(par_res); } } @@ -1787,7 +1798,11 @@ public class TypeUnifyTask extends RecursiveTask>> { Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution hinzufuegen */ + Set consideredElements = new HashSet<>(); for(UnifyPair pair : eq2sAsList) { + if (consideredElements.contains(pair)) { + continue; + } PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); UnifyType rhsType = pair.getRhsType(); @@ -1815,19 +1830,30 @@ public class TypeUnifyTask extends RecursiveTask>> { Set sameEqSet = eq2sAsList.stream() .filter(x -> ((x.getLhsType().equals(lhsType) || x.getRhsType().equals(lhsType)) && !x.equals(pair))) .collect(Collectors.toCollection(HashSet::new)); + consideredElements.addAll(sameEqSet); Set> x2 = x1; + Set> x1Res = new HashSet<>(); + writeLog("pair:\n" + pair.toString()); + writeLog("x1 Start:\n" + x1.toString()); + writeLog("sameEqSet:\n" + sameEqSet.toString()); for (UnifyPair sameEq : sameEqSet) { writeLog("x1 Original:\n" + x1.toString()); if (sameEq.getLhsType() instanceof PlaceholderType) { x1 = x1.stream().filter(y -> { UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); - localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp())); + Set unitedSubst = new HashSet<>(type.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); Boolean localCorr = !isUndefinedPairSetSet(localRes); if (!localCorr) { collectErr.addAll(localRes); } + else { + localRes.forEach(z -> z.addAll(y)); + x1Res.addAll(localRes); + } return localCorr; } ).collect(Collectors.toCollection(HashSet::new)); @@ -1836,20 +1862,33 @@ public class TypeUnifyTask extends RecursiveTask>> { x1 = x1.stream().filter(y -> { UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); - localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp())); + Set unitedSubst = new HashSet<>(type.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); Boolean localCorr = !isUndefinedPairSetSet(localRes); if (!localCorr) { collectErr.addAll(localRes); } + else { + localRes.forEach(z -> z.addAll(y)); + x1Res.addAll(localRes); + } return localCorr; } ).collect(Collectors.toCollection(HashSet::new)); } - writeLog("x1 nach Lösung von " + sameEq.toString()+" :\n" + x1.toString()); + writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); } - result.get(0).add(x1); - if (x1.isEmpty()) { + Set> x1ResPrime; + if (sameEqSet.isEmpty()) { + x1ResPrime = x1; + } + else { + x1ResPrime = x1Res; + } + result.get(0).add(x1ResPrime); + if (x1ResPrime.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC => Abbruch } }