From 1c0fa6a8206d6aa4e0a9bfa5c87b7580e17c061d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 24 Feb 2018 19:56:22 +0100 Subject: [PATCH] modified: de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java logFile eingefuegt --- .../typeinference/unify/RuleSet.java | 32 ++++---- .../typeinference/unify/TypeUnifyTask.java | 77 ++++++++++++------- .../unify/model/FiniteClosure.java | 3 +- 3 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index f5ddd32a..fea551e9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -249,17 +249,17 @@ public class RuleSet implements IRuleSet{ ReferenceType lhsSType = (ReferenceType) c; ReferenceType rhsSType = (ReferenceType) d; - try { - logFile.write("PAIR Rules: " + pair + "\n"); - logFile.flush(); - } - catch (IOException e) { } + //try { + // logFile.write("PAIR Rules: " + pair + "\n"); + // logFile.flush(); + //} + //catch (IOException e) { } if(lhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size()) return Optional.empty(); UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null); - 2018-02-23: liefert Vector>: Das kann nicht sein. + //2018-02-23: liefert Vector>: Das kann nicht sein. //NOCHMAL UEBERPRUEFEN //PL 18-02-09 Eingfuegt Anfang @@ -275,22 +275,22 @@ public class RuleSet implements IRuleSet{ } //PL 18-02-09 Eingfuegt ENDE - try { - logFile.write("cFromFc: " + cFromFc); - logFile.flush(); - } - catch (IOException e) { } + //try { + // logFile.write("cFromFc: " + cFromFc); + // logFile.flush(); + //} + //catch (IOException e) { } if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders()) return Optional.empty(); UnifyType dFromFc = fc.getAncestors(cFromFc).stream().filter(x -> x.getName().equals(d.getName())).findAny().orElse(null); - try { - logFile.write("cFromFc: " + cFromFc); - logFile.flush(); - } - catch (IOException e) { } + //try { + // logFile.write("cFromFc: " + cFromFc); + // logFile.flush(); + //} + //catch (IOException e) { } if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size()) return Optional.empty(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index bd1dad1e..7319787b 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -93,7 +93,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 1: Repeated application of reduce, adapt, erase, swap */ - if (printtag) System.out.println("Unifikation: " + eq); + writeLog("Unifikation: " + eq.toString()); Set eq0 = applyTypeUnificationRules(eq, fc); /* @@ -138,6 +138,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Sets of the "second level" Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); + writeLog(bufferSet.toString()+"\n"); Set>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs); //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer //nicht ausgewertet Faculty Beispiel im 1. Schritt @@ -239,27 +240,27 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { // sequentiell (Step 6b is included) if (printtag) System.out.println("nextStep: " + eqPrimePrime); - if (eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch + if (eqPrime.equals(eq)) { //PL 2017-09-29 auskommentiert und durch //(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt //Begruendung: Wenn in der Substitution keine Veraenderung //(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt. - eqPrimePrimeSet.add(eqPrime); - else if(eqPrimePrime.isPresent()) { - Set> unifyres = unify(eqPrimePrime.get(), fc, false); try { - logFile.write(unifyres.toString()+"\n"); - //logFile.flush(); + if (isSolvedForm(eqPrime)) { + logFile.write(eqPrime.toString()+"\n"); + logFile.flush(); + } } catch (IOException e) { } + eqPrimePrimeSet.add(eqPrime); + } + else if(eqPrimePrime.isPresent()) { + Set> unifyres = unify(eqPrimePrime.get(), fc, false); + eqPrimePrimeSet.addAll(unifyres); } else { Set> unifyres = unify(eqPrime, fc, false); - try { - //logFile.write(unifyres.toString()+"\n"); - logFile.flush(); - } - catch (IOException e) { } + eqPrimePrimeSet.addAll(unifyres); } @@ -279,8 +280,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 7: Filter empty sets; */ - return eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); - + eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); + return eqPrimePrimeSet; } @@ -382,11 +383,11 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq - try { - logFile.write("PAIR1 " + pair + "\n"); - logFile.flush(); - } - catch (IOException e) { } + //try { + // logFile.write("PAIR1 " + pair + "\n"); + // logFile.flush(); + //} + //catch (IOException e) { } Optional> optSet = rules.reduce1(pair, fc); optSet = optSet.isPresent() ? optSet : rules.reduce2(pair); @@ -411,11 +412,11 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Adapt, AdaptExt, AdaptSup - try { - logFile.write("PAIR2 " + pair + "\n"); - logFile.flush(); - } - catch (IOException e) { } + //try { + // logFile.write("PAIR2 " + pair + "\n"); + // logFile.flush(); + //} + //catch (IOException e) { } opt = rules.adapt(pair, fc); opt = opt.isPresent() ? opt : rules.adaptExt(pair, fc); opt = opt.isPresent() ? opt : rules.adaptSup(pair, fc); @@ -486,7 +487,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 1: (a <. Theta') if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); - if (first) {if (printtag) System.out.println(pair); + if (first) { writeLog(pair.toString()+"\n"); Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc); //System.out.println(x1); result.get(0).add(x1); @@ -502,7 +503,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) - if (first) {if (printtag) System.out.println(pair); + if (first) {writeLog(pair.toString()+"\n"); result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); } else { @@ -515,7 +516,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) - if (first) {if (printtag) System.out.println(pair); + if (first) {writeLog(pair.toString()+"\n"); result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc)); } else { @@ -533,7 +534,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) - if (first) {if (printtag) System.out.println(pair); + if (first) {writeLog(pair.toString()+"\n"); result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc)); } else { @@ -556,7 +557,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 8: (Theta <.? a) else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - if (first) {if (printtag) System.out.println(pair); + if (first) {writeLog(pair.toString()+"\n"); result.get(7).add( unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); } @@ -662,7 +663,9 @@ public class TypeUnifyTask extends RecursiveTask>> { else resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT)); resultPrime.addAll(substitutionSet); + writeLog(substitutionSet.toString()); result.add(resultPrime); + writeLog(resultPrime.toString()); } } @@ -689,6 +692,7 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT)); result.add(resultPrime); + writeLog(resultPrime.toString()); return result; } @@ -704,11 +708,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT)); result.add(resultPrime); + writeLog(resultPrime.toString()); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT)); result.add(resultPrime); + writeLog(resultPrime.toString()); return result; } @@ -740,6 +746,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT)); result.add(resultPrime); + writeLog(resultPrime.toString()); } return result; @@ -754,17 +761,20 @@ public class TypeUnifyTask extends RecursiveTask>> { Set resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT)); result.add(resultPrime); + writeLog(resultPrime.toString()); UnifyType freshTph = PlaceholderType.freshPlaceholder(); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT)); result.add(resultPrime); + writeLog(resultPrime.toString()); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT)); result.add(resultPrime); + writeLog(resultPrime.toString()); //} return result; @@ -802,4 +812,13 @@ public class TypeUnifyTask extends RecursiveTask>> { permuteParams(candidates, idx+1, result, current); } } + + void writeLog(String str) { + try { + logFile.write(str+"\n"); + logFile.flush(); + + } + catch (IOException e) { } + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 704f600f..5613953a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -37,7 +37,6 @@ public class FiniteClosure implements IFiniteClosure { * The initial pairs of that define the inheritance tree */ private Set pairs; - 2018-02-23: Muessten hier NUR die initiale Piars rein? /** * Creates a new instance using the inheritance tree defined in the pairs. @@ -370,7 +369,7 @@ public class FiniteClosure implements IFiniteClosure { return Optional.empty(); for(UnifyPair pair : pairs) - if(pair.getLhsType().getName().equals(typeName)) + if(pair.getLhsType().getName().equals(typeName) && pair.getLhsType().typeParams.arePlaceholders()) return Optional.of(pair.getLhsType()); return Optional.empty();