From 5270cecec9beca2a52f38b221597fb57467030d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 14 Feb 2018 17:45:08 +0100 Subject: [PATCH] Changes to be committed: modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: test/javFiles/Matrix.jav Fehler in der Aufteilung von Unify korrigiert. Equalcheck in Schritt 6 wiedre eingefuegt. --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 5 +-- .../typeinference/unify/RuleSet.java | 2 +- .../typeinference/unify/TypeUnifyTask.java | 35 +++++++++++-------- test/javFiles/Matrix.jav | 4 +-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 9a66543a..4b2e8c9c 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -101,8 +101,9 @@ public class JavaTXCompiler { } System.out.println(xConsSet); - Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result.size()); + Set> result = unify.unifySequential(xConsSet, finiteClosure); + //Set> result = unify.unify(xConsSet, finiteClosure); + System.out.println("RESULT: " + result); results.addAll(result); } return results.stream().map((unifyPairs -> diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index d409d0da..b699bdb2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -241,7 +241,7 @@ public class RuleSet implements IRuleSet{ UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null); - NOCHMAL UEBERPRUEFEN + //NOCHMAL UEBERPRUEFEN //PL 18-02-09 Eingfuegt Anfang //C und D koennen auch gleich sein. if (c.getName().equals(d.getName())) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index e037576d..ef197e5e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -78,7 +78,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 1: Repeated application of reduce, adapt, erase, swap */ - //System.out.println("Unifikation: " + eq); + System.out.println("Unifikation: " + eq); Set eq0 = applyTypeUnificationRules(eq, fc); /* @@ -122,11 +122,13 @@ public class TypeUnifyTask extends RecursiveTask>> { // Sets that originate from pair pattern matching // Sets of the "second level" Set undefinedPairs = new HashSet<>(); + System.out.println("eq2s " + eq2s); 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 //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren //Typen getestet werden. + 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()) { @@ -157,11 +159,13 @@ public class TypeUnifyTask extends RecursiveTask>> { } topLevelSets.add(flat); } - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets)); + //System.out.println(topLevelSets); + System.out.println(); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); } - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> sets) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> sets, Set eq, IFiniteClosure fc, boolean parallel) { ArrayList>> newSets = new ArrayList<>(sets); Set> set = newSets.remove(0); ArrayList> newSet = new ArrayList<>(set); @@ -172,17 +176,17 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> elems = new HashSet>(fstElems); elems.add(a); if (newSets.isEmpty()) { - result = unify2(elems); + result = unify2(elems, eq, fc, parallel); } else { - result = computeCartesianRecursive(elems,newSets); + result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); } if (!result.isEmpty()) break; } return result; } - Set> unify2(Set> setToFlatten) { + Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { //Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); // Cartesian product over all (up to 10) top level sets @@ -208,8 +212,8 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 6 a) Restart (fork) for pairs where subst was applied */ if(parallel) { - if //(eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch - (!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt + 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); @@ -227,8 +231,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { // sequentiell (Step 6b is included) - if //(eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch - (!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt + System.out.println("nextStep: " + eqPrime); + 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); @@ -423,7 +428,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 1: (a <. Theta') if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); - if (first) { + if (first) {System.out.println(pair); Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc); //System.out.println(x1); result.get(0).add(x1); @@ -439,7 +444,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 (first) {System.out.println(pair); result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); } else { @@ -452,7 +457,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 (first) {System.out.println(pair); result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc)); } else { @@ -470,7 +475,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) - if (first) { + if (first) {System.out.println(pair); result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc)); } else { @@ -493,7 +498,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 8: (Theta <.? a) else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - if (first) { + if (first) {System.out.println(pair); result.get(7).add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); } else { diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index 0133d43c..4b5d259f 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -11,8 +11,8 @@ class Matrix extends Vector> { var v2 = new Vector(); var j = 0; while(j < v1.size()) { - //var erg = 0; - //var k = 0; + var erg = 0; + var k = 0; //while(k < v1.size()) { //erg = erg + v1.elementAt(k) // * m.elementAt(k).elementAt(j);