From 1f269918fbc593eb365ee9c9223b88a8017dcb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 7 Feb 2018 16:53:24 +0100 Subject: [PATCH 01/91] nicht lauffaehig --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- .../typeinference/unify/TypeUnifyTask.java | 12 ++++---- test/javFiles/FC_Matrix.jav | 10 +++++++ test/javFiles/Matrix.jav | 28 +++++++++---------- .../FiniteClosureTest_Matrix.java | 9 ++++++ 5 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 test/javFiles/FC_Matrix.jav create mode 100644 test/typeinference/FiniteClosureTest_Matrix.java diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 8d381e377..9a66543a5 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -103,7 +103,7 @@ public class JavaTXCompiler { System.out.println(xConsSet); Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result.size()); - //results.addAll(result); + results.addAll(result); } return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index e51679e2c..31f79b1b4 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -156,15 +156,17 @@ public class TypeUnifyTask extends RecursiveTask>> { topLevelSets.add(flat); } + + Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); // Cartesian product over all (up to 10) top level sets - Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) - .stream().map(x -> new HashSet<>(x)) - .collect(Collectors.toCollection(HashSet::new)); + //Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) + //.stream().map(x -> new HashSet<>(x)) + //.collect(Collectors.toCollection(HashSet::new)); Set> eqPrimePrimeSet = new HashSet<>(); Set forks = new HashSet<>(); - for(Set> setToFlatten : eqPrimeSet) { + //for(Set> setToFlatten : eqPrimeSet) { // Flatten the cartesian product Set eqPrime = new HashSet<>(); setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); @@ -208,7 +210,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else eqPrimePrimeSet.addAll(unify(eqPrime, fc, false)); } - } + //} /* * Step 6 b) Build the union over everything. diff --git a/test/javFiles/FC_Matrix.jav b/test/javFiles/FC_Matrix.jav new file mode 100644 index 000000000..75ead472c --- /dev/null +++ b/test/javFiles/FC_Matrix.jav @@ -0,0 +1,10 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + methode(m) { + m.add(1); + Matrix i; + methode(i); + } + } diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index aa8966c9f..e11835359 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -6,21 +6,21 @@ class Matrix extends Vector> { mul(m) { var ret = new Matrix(); var i = 0; - //while(i < size()) { + while(i < size()) { var v1 = this.elementAt(i); - //var v2 = new Vector(); - //var j = 0; - //while(j < v1.size()) { - //var erg = 0; - //var k = 0; - //while(k < v1.size()) { - //erg = erg + v1.elementAt(k) - // * m.elementAt(k).elementAt(j); - //k++; } - //v2.addElement(new Integer(erg)); - //j++; } - //ret.addElement(v2); - //i++; } + var v2 = new Vector(); + var j = 0; + while(j < v1.size()) { + var erg = 0; + var k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k) + * m.elementAt(k).elementAt(j); + k++; } + v2.addElement(new Integer(erg)); + j++; } + ret.addElement(v2); + i++; } return ret; } } diff --git a/test/typeinference/FiniteClosureTest_Matrix.java b/test/typeinference/FiniteClosureTest_Matrix.java new file mode 100644 index 000000000..59a1b4787 --- /dev/null +++ b/test/typeinference/FiniteClosureTest_Matrix.java @@ -0,0 +1,9 @@ +package typeinference; + +import java.io.File; + +public class FiniteClosureTest_Matrix extends JavaTXCompilerTest{ + public FiniteClosureTest_Matrix() { + this.fileToTest = new File(rootDirectory+"FC_Matrix.jav"); + } +} \ No newline at end of file From e4fbd17a55f11872301f64b61502bc6c898e797d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 8 Feb 2018 00:02:27 +0100 Subject: [PATCH 02/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: test/javFiles/Matrix.jav Rekursive Berechnung des Kartesischen Produkts --- .../typeinference/unify/TypeUnifyTask.java | 27 +++++++++++++++++-- test/javFiles/Matrix.jav | 14 +++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 31f79b1b4..bbefe2bc4 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -155,9 +155,32 @@ public class TypeUnifyTask extends RecursiveTask>> { } topLevelSets.add(flat); } + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets)); + + } + + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> sets) { + ArrayList>> newSets = new ArrayList<>(sets); + Set> set = newSets.remove(0); + ArrayList> newSet = new ArrayList<>(set); + Set> result = null; + for(Set a : newSet) { + Set> elems = new HashSet>(fstElems); + elems.add(a); + if (newSets.isEmpty()) { + result = unify2(elems); + } + else { + result = computeCartesianRecursive(elems,newSets); + } + if (!result.isEmpty()) break; + } + return result; + } + + Set> unify2(Set> setToFlatten) { + //Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); - - Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); // Cartesian product over all (up to 10) top level sets //Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) //.stream().map(x -> new HashSet<>(x)) diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index e11835359..0133d43c9 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -11,13 +11,13 @@ class Matrix extends Vector> { var v2 = new Vector(); var j = 0; while(j < v1.size()) { - var erg = 0; - var k = 0; - while(k < v1.size()) { - erg = erg + v1.elementAt(k) - * m.elementAt(k).elementAt(j); - k++; } - v2.addElement(new Integer(erg)); + //var erg = 0; + //var k = 0; + //while(k < v1.size()) { + //erg = erg + v1.elementAt(k) + // * m.elementAt(k).elementAt(j); + //k++; } + //v2.addElement(new Integer(erg)); j++; } ret.addElement(v2); i++; } From f0610aeff127a9627e19683de13dfcebf032f0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 9 Feb 2018 21:32:15 +0100 Subject: [PATCH 03/91] Changes to be committed: modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: test/typeinference/JavaTXCompilerTest.java --- .../typeinference/typeAlgo/TYPEStmt.java | 2 +- .../typeinference/unify/TypeUnifyTask.java | 79 +++++++++++++++---- test/typeinference/JavaTXCompilerTest.java | 6 +- 3 files changed, 71 insertions(+), 16 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index a06062c00..3733b7dce 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -199,7 +199,7 @@ public class TYPEStmt implements StatementVisitor{ //@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2 //Expression muss zu Numeric Convertierbar sein. also von Numeric erben RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset()); - constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.EQUALSDOT)); + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT)); //The type of the postfix increment expression is the type of the variable constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT)); }else{ diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index bbefe2bc4..e037576db 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -99,7 +99,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // cartesian product of the sets created by pattern matching. List>> topLevelSets = new ArrayList<>(); - System.out.println(eq2s); + //System.out.println(eq2s); if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty. Set> wrap = new HashSet<>(); @@ -129,8 +129,10 @@ public class TypeUnifyTask extends RecursiveTask>> { //Typen getestet werden. // 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()) + if(!undefinedPairs.isEmpty()) { + System.out.println(undefinedPairs); return new HashSet<>(); + } /* Up to here, no cartesian products are calculated. * filters for pairs and sets can be applied here */ @@ -164,7 +166,9 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> set = newSets.remove(0); ArrayList> newSet = new ArrayList<>(set); Set> result = null; + int i = 0; for(Set a : newSet) { + i++; Set> elems = new HashSet>(fstElems); elems.add(a); if (newSets.isEmpty()) { @@ -197,7 +201,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 5: Substitution */ - System.out.println("vor Subst: " + eqPrime); + //System.out.println("vor Subst: " + eqPrime); Optional> eqPrimePrime = rules.subst(eqPrime); /* @@ -210,13 +214,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt. eqPrimePrimeSet.add(eqPrime); else if(eqPrimePrime.isPresent()) { - System.out.println("nextStep: " + eqPrimePrime.get()); + //System.out.println("nextStep: " + eqPrimePrime.get()); TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true); forks.add(fork); fork.fork(); } else { - System.out.println("nextStep: " + eqPrime); + //System.out.println("nextStep: " + eqPrime); TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true); forks.add(fork); fork.fork(); @@ -410,7 +414,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Init all 8 cases for(int i = 0; i < 8; i++) result.add(new HashSet<>()); - + Boolean first = true; for(UnifyPair pair : eq2s) { PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); @@ -418,18 +422,46 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 1: (a <. Theta') if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { - System.out.println(pair); - Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc); - System.out.println(x1); - result.get(0).add(x1); + //System.out.println(pair); + if (first) { + Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc); + //System.out.println(x1); + result.get(0).add(x1); + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(0).add(s2); + } + } // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) - result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); + if (first) { + result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(1).add(s2); + } // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) - result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc)); + if (first) { + result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc)); + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(2).add(s2); + } // Case 4 was replaced by an inference rule // Case 4: (a <.? Theta') @@ -438,7 +470,16 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) - result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc)); + if (first) { + result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc)); + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(4).add(s2); + } // Case 6 was replaced by an inference rule. // Case 6: (? ext Theta <.? a) @@ -452,7 +493,16 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 8: (Theta <.? a) else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - result.get(7).add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); + if (first) { + result.get(7).add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); + } + else { + Set s1 = new HashSet<>(); + s1.add(pair); + Set> s2 = new HashSet<>(); + s2.add(s1); + result.get(7).add(s2); + } // Case unknown: If a pair fits no other case, then the type unification has failed. // Through application of the rules, every pair should have one of the above forms. // Pairs that do not have one of the aboves form are contradictory. @@ -461,6 +511,7 @@ public class TypeUnifyTask extends RecursiveTask>> { undefined.add(pair); break; } + first = false; } // Filter empty sets or sets that only contain an empty set. diff --git a/test/typeinference/JavaTXCompilerTest.java b/test/typeinference/JavaTXCompilerTest.java index 03452018e..341017051 100644 --- a/test/typeinference/JavaTXCompilerTest.java +++ b/test/typeinference/JavaTXCompilerTest.java @@ -46,7 +46,11 @@ public class JavaTXCompilerTest { //filesToTest.add(new File(rootDirectory+"Matrix.jav")); //filesToTest.add(new File(rootDirectory+"Import.jav")); JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); - + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + } List results = compiler.typeInference(); for(File f : compiler.sourceFiles.keySet()){ From 87fe51767ccf3660f95851260820cbe49d64ec43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 9 Feb 2018 22:55:40 +0100 Subject: [PATCH 04/91] modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java Reduce 1 C und D koennen auch gleich sein. Muss nochmals ueberprueft werden. --- .../dhbwstuttgart/typeinference/unify/RuleSet.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 8c41660b5..d409d0dad 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -241,6 +241,20 @@ public class RuleSet implements IRuleSet{ UnifyType cFromFc = fc.getLeftHandedType(c.getName()).orElse(null); + NOCHMAL UEBERPRUEFEN + //PL 18-02-09 Eingfuegt Anfang + //C und D koennen auch gleich sein. + if (c.getName().equals(d.getName())) { + Set result = new HashSet<>(); + TypeParams rhsTypeParams = d.getTypeParams(); + TypeParams lhsTypeParams = c.getTypeParams(); + for(int rhsIdx = 0; rhsIdx < c.getTypeParams().size(); rhsIdx++) + result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC)); + + return Optional.of(result); + } + //PL 18-02-09 Eingfuegt ENDE + if(cFromFc == null || !cFromFc.getTypeParams().arePlaceholders()) return Optional.empty(); 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 05/91] 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 9a66543a5..4b2e8c9ce 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 d409d0dad..b699bdb27 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 e037576db..ef197e5e9 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 0133d43c9..4b5d259fd 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); From 89246ece5cae488e08d7f9a7fa5d4198558c4441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 21 Feb 2018 14:02:48 +0100 Subject: [PATCH 06/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: test/javFiles/Matrix.jav --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 4 ++-- src/de/dhbwstuttgart/typeinference/unify/RuleSet.java | 10 ++++++++-- test/javFiles/Matrix.jav | 10 +++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 4b2e8c9ce..e2dd56a1b 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -101,8 +101,8 @@ public class JavaTXCompiler { } System.out.println(xConsSet); - Set> result = unify.unifySequential(xConsSet, finiteClosure); - //Set> result = unify.unify(xConsSet, finiteClosure); + //Set> result = unify.unifySequential(xConsSet, finiteClosure); + Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result); results.addAll(result); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index b699bdb27..0b51a25e4 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -421,10 +421,16 @@ public class RuleSet implements IRuleSet{ TypeParams typeDParams = typeD.getTypeParams(); TypeParams typeDgenParams = typeDgen.getTypeParams(); + System.out.println("Pair: " +pair); + System.out.println("typeD: " +typeD); + //System.out.println("typeDParams: " +typeDParams); + System.out.println("typeDgen: " +typeD); + //System.out.println("typeDgenParams: " +typeDgenParams); Unifier unif = Unifier.identity(); - for(int i = 0; i < typeDParams.size(); i++) + for(int i = 0; i < typeDParams.size(); i++) { + System.out.println("ADAPT" +typeDgenParams); unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); - + } return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT)); } diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index 4b5d259fd..e11835359 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -13,11 +13,11 @@ class Matrix extends Vector> { while(j < v1.size()) { var erg = 0; var k = 0; - //while(k < v1.size()) { - //erg = erg + v1.elementAt(k) - // * m.elementAt(k).elementAt(j); - //k++; } - //v2.addElement(new Integer(erg)); + while(k < v1.size()) { + erg = erg + v1.elementAt(k) + * m.elementAt(k).elementAt(j); + k++; } + v2.addElement(new Integer(erg)); j++; } ret.addElement(v2); i++; } From 9c35f04a096183118ad01260bac8c3ba5507e98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 21 Feb 2018 17:22:23 +0100 Subject: [PATCH 07/91] modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java --- src/de/dhbwstuttgart/typeinference/unify/RuleSet.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 0b51a25e4..b3cb0dec0 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -429,7 +429,9 @@ public class RuleSet implements IRuleSet{ Unifier unif = Unifier.identity(); for(int i = 0; i < typeDParams.size(); i++) { System.out.println("ADAPT" +typeDgenParams); + if (typeDgenParams.get(i) instanceof PlaceholderType) unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); + else System.out.println("ERROR"); } return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT)); } From 5cd2ee7d802c6e58edfc83ebfd09ac35d3288aa0 Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Wed, 21 Feb 2018 17:54:26 +0100 Subject: [PATCH 08/91] =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20src/de/dhbwstut?= =?UTF-8?q?tgart/core/JavaTXCompiler.java=20=09ge=C3=A4ndert:=20=20=20src/?= =?UTF-8?q?de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java=20recur?= =?UTF-8?q?siveCartesionProduct=20wieder=20entfernt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 4 +- .../typeinference/unify/TypeUnifyTask.java | 73 ++++++++++++------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index e2dd56a1b..4b2e8c9ce 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -101,8 +101,8 @@ public class JavaTXCompiler { } System.out.println(xConsSet); - //Set> result = unify.unifySequential(xConsSet, finiteClosure); - Set> result = unify.unify(xConsSet, finiteClosure); + Set> result = unify.unifySequential(xConsSet, finiteClosure); + //Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result); results.addAll(result); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ef197e5e9..4c559a63d 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -161,44 +161,36 @@ public class TypeUnifyTask extends RecursiveTask>> { } //System.out.println(topLevelSets); System.out.println(); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); + + + //Aufruf von computeCartesianRecursive ANFANG + //return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); - } + //} - 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); - Set> result = null; - int i = 0; - for(Set a : newSet) { - i++; - Set> elems = new HashSet>(fstElems); - elems.add(a); - if (newSets.isEmpty()) { - result = unify2(elems, eq, fc, parallel); - } - else { - result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); - } - if (!result.isEmpty()) break; - } - return result; - } - Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + + //Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + //Aufruf von computeCartesianRecursive ENDE + + //Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG // Cartesian product over all (up to 10) top level sets - //Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) - //.stream().map(x -> new HashSet<>(x)) - //.collect(Collectors.toCollection(HashSet::new)); + Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) + .stream().map(x -> new HashSet<>(x)) + .collect(Collectors.toCollection(HashSet::new)); + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE Set> eqPrimePrimeSet = new HashSet<>(); Set forks = new HashSet<>(); - //for(Set> setToFlatten : eqPrimeSet) { + + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG + for(Set> setToFlatten : eqPrimeSet) { // Flatten the cartesian product + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE Set eqPrime = new HashSet<>(); setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); @@ -242,7 +234,9 @@ public class TypeUnifyTask extends RecursiveTask>> { else eqPrimePrimeSet.addAll(unify(eqPrime, fc, false)); } - //} + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG + } + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE /* * Step 6 b) Build the union over everything. @@ -259,6 +253,29 @@ public class TypeUnifyTask extends RecursiveTask>> { } + + + 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); + Set> result = null; + int i = 0; + for(Set a : newSet) { + i++; + Set> elems = new HashSet>(fstElems); + elems.add(a); + if (newSets.isEmpty()) { + //BEI BENUTZUNG EIKOMMENTIEREN result = unify2(elems, eq, fc, parallel); + } + else { + result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); + } + if (!result.isEmpty()) break; + } + return result; + } + /** * Checks whether a set of pairs is in solved form. * @param eqPrimePrime The set of pair From 8e198679c76abdabb81fb8dec051f5c4825e369e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 23 Feb 2018 00:37:59 +0100 Subject: [PATCH 09/91] Instabiler Zustand reduce funktionert nicht --- .../SyntaxTreeGenerator/FCGenerator.java | 2 +- .../typeinference/unify/RuleSet.java | 37 ++++++++- .../typeinference/unify/TypeUnifyTask.java | 82 ++++++++++++++----- .../unify/model/FiniteClosure.java | 1 + 4 files changed, 99 insertions(+), 23 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java index 7863c8ed6..37bfb4da1 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -24,7 +24,7 @@ public class FCGenerator { for(ClassOrInterface cly : availableClasses){ pairs.addAll(getSuperTypes(cly, availableClasses)); } - System.out.println(pairs); + System.out.println("Pairs: " + pairs); return pairs; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index b3cb0dec0..f5ddd32a1 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -25,12 +25,25 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.model.WildcardType; +import java.io.FileWriter; +import java.io.IOException; + /** * Implementation of the type inference rules. * @author Florian Steurer * */ -public class RuleSet implements IRuleSet{ +public class RuleSet implements IRuleSet{ + + FileWriter logFile; + + RuleSet() { + super(); + } + + RuleSet(FileWriter logFile) { + this.logFile = logFile; + } @Override public Optional reduceUp(UnifyPair pair) { @@ -236,10 +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) { } + 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. //NOCHMAL UEBERPRUEFEN //PL 18-02-09 Eingfuegt Anfang @@ -255,14 +275,27 @@ public class RuleSet implements IRuleSet{ } //PL 18-02-09 Eingfuegt ENDE + 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) { } + if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size()) return Optional.empty(); - + System.out.println("cFromFc: " + cFromFc); + System.out.println("dFromFc: " + dFromFc); int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams()); if(pi.length == 0) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 4c559a63d..bd1dad1ef 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -26,15 +26,23 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + /** * Implementation of the type unification algorithm * @author Florian Steurer */ -public class TypeUnifyTask extends RecursiveTask>> { +public class TypeUnifyTask extends RecursiveTask>> { private static final long serialVersionUID = 1L; private static int i = 0; + private boolean printtag = false; + + public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; + FileWriter logFile; /** * The implementation of setOps that will be used during the unification @@ -49,7 +57,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * The implementation of the rules that will be used during the unification. */ - protected IRuleSet rules = new RuleSet(); + protected IRuleSet rules; protected Set eq; @@ -61,6 +69,13 @@ public class TypeUnifyTask extends RecursiveTask>> { this.eq = eq; this.fc = fc; this.parallel = parallel; + try { + logFile = new FileWriter(new File(rootDirectory+"log")); + logFile.write("xxx"); + logFile.flush(); + rules = new RuleSet(logFile); + } + catch (IOException e) { } } @Override @@ -74,11 +89,11 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(Set eq, IFiniteClosure fc, boolean parallel) { + protected Set> unify(Set eq, IFiniteClosure fc, boolean parallel) { /* * Step 1: Repeated application of reduce, adapt, erase, swap */ - System.out.println("Unifikation: " + eq); + if (printtag) System.out.println("Unifikation: " + eq); Set eq0 = applyTypeUnificationRules(eq, fc); /* @@ -122,17 +137,17 @@ 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); + if (printtag) 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 (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()) { - System.out.println(undefinedPairs); + if (printtag) System.out.println("UndefinedPairs; " + undefinedPairs); return new HashSet<>(); } @@ -160,7 +175,7 @@ public class TypeUnifyTask extends RecursiveTask>> { topLevelSets.add(flat); } //System.out.println(topLevelSets); - System.out.println(); + //System.out.println(); //Aufruf von computeCartesianRecursive ANFANG @@ -173,7 +188,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { //Aufruf von computeCartesianRecursive ENDE - + //keine Ahnung woher das kommt //Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG @@ -223,16 +238,31 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { // sequentiell (Step 6b is included) - System.out.println("nextStep: " + eqPrime); + if (printtag) System.out.println("nextStep: " + eqPrimePrime); 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()) - eqPrimePrimeSet.addAll(unify(eqPrimePrime.get(), fc, false)); - else - eqPrimePrimeSet.addAll(unify(eqPrime, fc, false)); + else if(eqPrimePrime.isPresent()) { + Set> unifyres = unify(eqPrimePrime.get(), fc, false); + try { + logFile.write(unifyres.toString()+"\n"); + //logFile.flush(); + } + catch (IOException e) { } + eqPrimePrimeSet.addAll(unifyres); + } + else { + Set> unifyres = unify(eqPrime, fc, false); + try { + //logFile.write(unifyres.toString()+"\n"); + logFile.flush(); + } + catch (IOException e) { } + + eqPrimePrimeSet.addAll(unifyres); + } } //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG } @@ -352,6 +382,12 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq + try { + logFile.write("PAIR1 " + pair + "\n"); + logFile.flush(); + } + catch (IOException e) { } + Optional> optSet = rules.reduce1(pair, fc); optSet = optSet.isPresent() ? optSet : rules.reduce2(pair); optSet = optSet.isPresent() ? optSet : rules.reduceExt(pair, fc); @@ -375,6 +411,11 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Adapt, AdaptExt, AdaptSup + 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); @@ -445,7 +486,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 1: (a <. Theta') if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); - if (first) {System.out.println(pair); + if (first) {if (printtag) System.out.println(pair); Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc); //System.out.println(x1); result.get(0).add(x1); @@ -461,7 +502,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) - if (first) {System.out.println(pair); + if (first) {if (printtag) System.out.println(pair); result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); } else { @@ -474,7 +515,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) - if (first) {System.out.println(pair); + if (first) {if (printtag) System.out.println(pair); result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc)); } else { @@ -492,7 +533,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) - if (first) {System.out.println(pair); + if (first) {if (printtag) System.out.println(pair); result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc)); } else { @@ -515,8 +556,9 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 8: (Theta <.? a) else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - if (first) {System.out.println(pair); - result.get(7).add(unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); + if (first) {if (printtag) System.out.println(pair); + result.get(7).add( + unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); } else { Set s1 = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index dcffbee6f..704f600fd 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -37,6 +37,7 @@ 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. 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 10/91] 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 f5ddd32a1..fea551e92 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 bd1dad1ef..7319787bc 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 704f600fd..5613953aa 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(); From 6fcaafe47792c357228ef4cda70d4e6cfe921165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 28 Feb 2018 16:07:02 +0100 Subject: [PATCH 11/91] test --- .../typeinference/unify/TypeUnifyTask.java | 51 +++++++++++++------ .../unify/interfaces/IFiniteClosure.java | 4 +- .../unify/model/FiniteClosure.java | 25 ++++++++- .../unify/model/OrderingUnifyPair.java | 39 ++++++++++++++ .../typeinference/unify/model/UnifyPair.java | 1 + 5 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 7319787bc..79c0f329e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -25,11 +25,14 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams; import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import com.google.common.collect.Ordering; + /** * Implementation of the type unification algorithm @@ -63,11 +66,18 @@ public class TypeUnifyTask extends RecursiveTask>> { protected IFiniteClosure fc; + protected Ordering> oup; + protected boolean parallel; + public TypeUnifyTask() { + rules = new RuleSet(); + } + public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel) { this.eq = eq; this.fc = fc; + this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; try { logFile = new FileWriter(new File(rootDirectory+"log")); @@ -138,7 +148,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"); + writeLog("BufferSet: " + 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 @@ -180,13 +190,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG - //return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); - //} + } - //Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -194,9 +204,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG // Cartesian product over all (up to 10) top level sets - Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) - .stream().map(x -> new HashSet<>(x)) - .collect(Collectors.toCollection(HashSet::new)); + //Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) + // .stream().map(x -> new HashSet<>(x)) + // .collect(Collectors.toCollection(HashSet::new)); //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE Set> eqPrimePrimeSet = new HashSet<>(); @@ -204,7 +214,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG - for(Set> setToFlatten : eqPrimeSet) { + //for(Set> setToFlatten : eqPrimeSet) { // Flatten the cartesian product //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE Set eqPrime = new HashSet<>(); @@ -266,7 +276,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG - } + //} //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE /* @@ -292,17 +302,25 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList> newSet = new ArrayList<>(set); Set> result = null; int i = 0; - for(Set a : newSet) { + Set a_next = oup.min(newSet.iterator()); + while (newSet.size() != 0) { + Set a = a_next; + writeLog("NewSet: " + newSet.toString()+ "\n"); + newSet.remove(a); + if (newSet.size() > 0) a_next = oup.min(newSet.iterator()); + //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); elems.add(a); if (newSets.isEmpty()) { - //BEI BENUTZUNG EIKOMMENTIEREN result = unify2(elems, eq, fc, parallel); + result = unify2(elems, eq, fc, parallel); + System.out.println(""); } else { result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); } - if (!result.isEmpty()) break; + if (!result.isEmpty()) //&& (oup.compare(a, a_next) == -1)) break; + if (oup.compare(a, a_next) == -1) break; } return result; } @@ -332,7 +350,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * This is step one of the unification algorithm. * @return The set of pairs that results from repeated application of the inference rules. */ - protected Set applyTypeUnificationRules(Set eq, IFiniteClosure fc) { + public Set applyTypeUnificationRules(Set eq, IFiniteClosure fc) { /* * Rule Application Strategy: @@ -663,9 +681,10 @@ 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()); + writeLog("Substitution: " + substitutionSet.toString()); result.add(resultPrime); - writeLog(resultPrime.toString()); + writeLog("Result: " + resultPrime.toString()); + //writeLog("MAX: " + oup.max(resultPrime.iterator()).toString()); } } @@ -692,7 +711,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()); + writeLog("Result: " + resultPrime.toString()); return result; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index dcb6c4d1d..110ff4b8f 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -60,5 +60,7 @@ public interface IFiniteClosure { public Optional getLeftHandedType(String typeName); public Set getAncestors(UnifyType t); public Set getChildren(UnifyType t); - public Set getAllTypesByName(String typeName); + public Set getAllTypesByName(String typeName); + + public int compare(UnifyType rhsType, UnifyType rhsType2); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 5613953aa..6500abcf0 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -8,11 +8,14 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import com.google.common.collect.Ordering; + //PL 18-02-05 Unifier durch Matcher ersetzt //mus greater noch erstezt werden import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify; import de.dhbwstuttgart.typeinference.unify.Match; +import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; @@ -20,7 +23,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; * The finite closure for the type unification * @author Florian Steurer */ -public class FiniteClosure implements IFiniteClosure { +public class FiniteClosure extends Ordering implements IFiniteClosure { /** * A map that maps every type to the node in the inheritance graph that contains that type. @@ -430,4 +433,24 @@ public class FiniteClosure implements IFiniteClosure { public String toString(){ return this.inheritanceGraph.toString(); } + + public int compare (UnifyType left, UnifyType right) { + UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT); + TypeUnifyTask unifyTask = new TypeUnifyTask(); + HashSet hs = new HashSet<>(); + hs.add(up); + Set smallerRes = unifyTask.applyTypeUnificationRules(hs, this); + long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); + if (smallerLen == 0) return -1; + else { + up = new UnifyPair(right, left, PairOperator.SMALLERDOT); + //TypeUnifyTask unifyTask = new TypeUnifyTask(); + hs = new HashSet<>(); + hs.add(up); + Set greaterRes = unifyTask.applyTypeUnificationRules(hs, this); + long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); + if (greaterLen == 0) return 1; + else return 0; + } + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java new file mode 100644 index 000000000..5cf69f76b --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -0,0 +1,39 @@ +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.HashMap; +import java.util.Optional; +import java.util.Set; +import java.util.function.BinaryOperator; +import java.util.stream.Stream; + +import com.google.common.collect.Ordering; + +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; + + + +public class OrderingUnifyPair extends Ordering> { + + protected IFiniteClosure fc; + + public OrderingUnifyPair(IFiniteClosure fc) { + this.fc = fc; + } + + public int compare (UnifyPair left, UnifyPair right) { + if (left == null || right == null) + System.out.println("Fehler"); + return fc.compare(left.getRhsType(), right.getRhsType()); + } + + public int compare (Set left, Set right) { + Stream ls = left.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); + Stream rs = right.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); + BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; + HashMap hm = rs.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); + ls = ls.filter(x -> !(hm.get(x.getLhsType()) == null)); + Optional si = ls.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + if (!si.isPresent()) return 0; + else return si.get(); + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 0909690a2..8d038fd34 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; + /** * A pair which contains two types and an operator, e.q. (Integer <. a). * @author Florian Steurer From f31023b4fa55d8417a28db9bd3ccd01736658416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 28 Feb 2018 16:16:22 +0100 Subject: [PATCH 12/91] merge2 --- test/typeinference/FiniteClosureTest_Matrix.java | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 test/typeinference/FiniteClosureTest_Matrix.java diff --git a/test/typeinference/FiniteClosureTest_Matrix.java b/test/typeinference/FiniteClosureTest_Matrix.java deleted file mode 100644 index 59a1b4787..000000000 --- a/test/typeinference/FiniteClosureTest_Matrix.java +++ /dev/null @@ -1,9 +0,0 @@ -package typeinference; - -import java.io.File; - -public class FiniteClosureTest_Matrix extends JavaTXCompilerTest{ - public FiniteClosureTest_Matrix() { - this.fileToTest = new File(rootDirectory+"FC_Matrix.jav"); - } -} \ No newline at end of file From 67fe88215a5d817b8069d8d2ca77064aea9ff6f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 28 Feb 2018 16:25:45 +0100 Subject: [PATCH 13/91] eigenerTest --- test/typeinference/UnifyTest.java | 139 ++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 test/typeinference/UnifyTest.java diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java new file mode 100644 index 000000000..ee856496c --- /dev/null +++ b/test/typeinference/UnifyTest.java @@ -0,0 +1,139 @@ +package typeinference; + +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class JavaTXCompilerTest { + + public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; +/* + @Test + public void finiteClosure() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"fc.jav")); + } + @Test + public void lambda() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Lambda.jav")); + } + @Test + public void lambda2() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Lambda2.jav")); + } + @Test + public void lambda3() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Lambda3.jav")); + } + @Test + public void mathStruc() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"mathStruc.jav")); + } + @Test + public void generics() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Generics.jav")); + } + + @Test + public void faculty() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Faculty.jav")); + } + + @Test + public void facultyTyped() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"FacultyTyped.jav")); + } +*/ + @Test + public void matrix() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Matrix.jav")); + } +/* + @Test + public void vector() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Vector.jav")); + } + @Test + public void lambdaRunnable() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"LambdaRunnable.jav")); + } + @Test + public void expressions() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Expressions.jav")); + } + @Test + public void matrixFC() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"FC_Matrix.jav")); + } +*/ + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + //filesToTest.add(new File(rootDirectory+"fc.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); + //filesToTest.add(new File(rootDirectory+"Vector.jav")); + //filesToTest.add(new File(rootDirectory+"Generics.jav")); + //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); + //filesToTest.add(new File(rootDirectory+"Matrix.jav")); + //filesToTest.add(new File(rootDirectory+"Import.jav")); + // //filesToTest.add(new File(rootDirectory+"Faculty.jav")); + // //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); + // //filesToTest.add(new File(rootDirectory+"test.jav")); + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + } + List results = compiler.typeInference(); + + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } + +} + From cef82c6359f30f59cc7195a5e90e42435ae157e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 28 Feb 2018 16:27:08 +0100 Subject: [PATCH 14/91] Typgenerator auf alten Stand setzen, damit Matrix test lauft --- .../parser/SyntaxTreeGenerator/TypeGenerator.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index ccc7b3272..1dd259d0d 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -114,9 +114,7 @@ public class TypeGenerator { if(referenceTypeContext.classOrInterfaceType() != null){ if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){ Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType(); - //return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics); - if(ctx.typeArguments() != null)throw new NotImplementedException(); - return convertTypeName(referenceTypeContext.getText(), null,referenceTypeContext.getStart(), reg, generics); + return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics); }else{ throw new NotImplementedException(); } From aa631b509931230682fa72f45a91404c86f69ab4 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 28 Feb 2018 16:35:45 +0100 Subject: [PATCH 15/91] UnifyTest korrekt benennen --- test/typeinference/UnifyTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index ee856496c..c10fae05d 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -20,7 +20,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class JavaTXCompilerTest { +public class UnifyTest { public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; /* From 6256bdfe2e415ff43ed064fe277dcbf47a89fe0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 1 Mar 2018 12:27:38 +0100 Subject: [PATCH 16/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java In Unfy: - Bildung des kartesischen Produkts auf secondlevel-Ebene entfernt In computeCartesianRecursive: - Vereinigung der Ergebnisse ueber die Schleifen und die Rekursion eingefuegt - Minimumbestimmung korrigiert --- .../typeinference/unify/TypeUnifyTask.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 79c0f329e..d79da6285 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -165,9 +165,9 @@ public class TypeUnifyTask extends RecursiveTask>> { /* Up to here, no cartesian products are calculated. * filters for pairs and sets can be applied here */ - // Sub cartesian products of the second level (pattern matched) sets + // Alternative: Sub cartesian products of the second level (pattern matched) sets // "the big (x)" - for(Set>> secondLevelSet : secondLevelSets) { + /* for(Set>> secondLevelSet : secondLevelSets) { //System.out.println("secondLevelSet "+secondLevelSet.size()); List>> secondLevelSetList = new ArrayList<>(secondLevelSet); Set>> cartResult = setOps.cartesianProduct(secondLevelSetList); @@ -183,7 +183,15 @@ public class TypeUnifyTask extends RecursiveTask>> { flat1.addAll(s1); flat.add(flat1); } - topLevelSets.add(flat); + //topLevelSets.add(flat); + } + */ + + //Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden + for(Set>> secondLevelSet : secondLevelSets) { + for (Set> secondlevelelem : secondLevelSet) { + topLevelSets.add(secondlevelelem); + } } //System.out.println(topLevelSets); //System.out.println(); @@ -291,36 +299,41 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 7: Filter empty sets; */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); + if (!eqPrimePrimeSet.isEmpty()) + System.out.println(""); return eqPrimePrimeSet; } - 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); - Set> result = null; + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { + ArrayList>> remainingSets = new ArrayList<>(topLevelSets); + Set> nextSet = remainingSets.remove(0); + ArrayList> nextSetasList = new ArrayList<>(nextSet); + Set> result = new HashSet<>(); int i = 0; - Set a_next = oup.min(newSet.iterator()); - while (newSet.size() != 0) { + Set a_next = oup.min(nextSetasList.iterator()); + while (nextSetasList.size() != 0) { Set a = a_next; - writeLog("NewSet: " + newSet.toString()+ "\n"); - newSet.remove(a); - if (newSet.size() > 0) a_next = oup.min(newSet.iterator()); + writeLog("nextSet: " + nextSetasList.toString()+ "\n"); + nextSetasList.remove(a); + if (nextSetasList.size() > 0) + a_next = oup.min(nextSetasList.iterator()); //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); elems.add(a); - if (newSets.isEmpty()) { - result = unify2(elems, eq, fc, parallel); + if (remainingSets.isEmpty()) { + result.addAll(unify2(elems, eq, fc, parallel)); System.out.println(""); } else { - result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); + result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } if (!result.isEmpty()) //&& (oup.compare(a, a_next) == -1)) break; - if (oup.compare(a, a_next) == -1) break; + if (a.equals(a_next) || + (oup.compare(a, a_next) == -1)) + break; } return result; } From 356b8a7a34ed26a3e1580760662f316b09f50295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 1 Mar 2018 18:00:38 +0100 Subject: [PATCH 17/91] modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Eq for Unify vereinfachen noch nicht fertig --- .../typeinference/unify/RuleSet.java | 4 +- .../typeinference/unify/TypeUnifyTask.java | 66 +++++++++++++------ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index fea551e92..d739fdb6c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -294,8 +294,8 @@ public class RuleSet implements IRuleSet{ if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size()) return Optional.empty(); - System.out.println("cFromFc: " + cFromFc); - System.out.println("dFromFc: " + dFromFc); + //System.out.println("cFromFc: " + cFromFc); + //System.out.println("dFromFc: " + dFromFc); int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams()); if(pi.length == 0) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d79da6285..418a75b80 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.RecursiveTask; import java.util.stream.Collectors; +import java.util.stream.Stream; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; @@ -148,7 +149,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Sets of the "second level" Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); - writeLog("BufferSet: " + bufferSet.toString()+"\n"); + //writeLog("BufferSet: " + 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 @@ -158,7 +159,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // 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()) { - if (printtag) System.out.println("UndefinedPairs; " + undefinedPairs); + writeLog("UndefinedPairs; " + undefinedPairs); return new HashSet<>(); } @@ -202,6 +203,30 @@ public class TypeUnifyTask extends RecursiveTask>> { } + Set simplifyEq (Set eqs) { + Set leftVarSmaller = eqs.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType) + && !(x.getRhsType() instanceof PlaceholderType) + && x.getPairOp().equals(PairOperator.SMALLERDOT)).collect(Collectors.toCollection(HashSet::new)); + Set leftVarEq = eqs.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType) + && !(x.getRhsType() instanceof PlaceholderType) + && x.getPairOp().equals(PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); + Set rightVarSmaller = eqs.stream() + .filter(x -> (x.getRhsType() instanceof PlaceholderType) + && !(x.getLhsType() instanceof PlaceholderType) + && x.getPairOp().equals(PairOperator.SMALLERDOT)).collect(Collectors.toCollection(HashSet::new)); + Set rightVarEq = eqs.stream() + .filter(x -> (x.getRhsType() instanceof PlaceholderType) + && !(x.getLhsType() instanceof PlaceholderType) + && x.getPairOp().equals(PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); + Set ret = new HashSet<>(); + for (UnifyPair eq : leftVarSmaller) { + eqs.remove(eq); HIER WEITERMACHEN + Stream eqEqualLHS = leftVarSmaller.stream().filter(x -> x.getLhsType().equals(eq.getLhsType())); + } + return ret; + } Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { @@ -300,7 +325,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); if (!eqPrimePrimeSet.isEmpty()) - System.out.println(""); + writeLog("Result " + eqPrimePrimeSet.toString()); return eqPrimePrimeSet; } @@ -315,10 +340,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set a_next = oup.min(nextSetasList.iterator()); while (nextSetasList.size() != 0) { Set a = a_next; - writeLog("nextSet: " + nextSetasList.toString()+ "\n"); + //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); nextSetasList.remove(a); if (nextSetasList.size() > 0) a_next = oup.min(nextSetasList.iterator()); + //PL 2018-03-01 + //TODO: 1. Maximum und Minimum unterscheiden + //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); @@ -518,7 +546,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 1: (a <. Theta') if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); - if (first) { writeLog(pair.toString()+"\n"); + if (first) { //writeLog(pair.toString()+"\n"); Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc); //System.out.println(x1); result.get(0).add(x1); @@ -534,7 +562,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) - if (first) {writeLog(pair.toString()+"\n"); + if (first) { //writeLog(pair.toString()+"\n"); result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); } else { @@ -547,7 +575,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) - if (first) {writeLog(pair.toString()+"\n"); + if (first) { //writeLog(pair.toString()+"\n"); result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc)); } else { @@ -565,7 +593,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) - if (first) {writeLog(pair.toString()+"\n"); + if (first) { //writeLog(pair.toString()+"\n"); result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc)); } else { @@ -588,7 +616,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 8: (Theta <.? a) else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) - if (first) {writeLog(pair.toString()+"\n"); + if (first) { //writeLog(pair.toString()+"\n"); result.get(7).add( unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); } @@ -607,7 +635,7 @@ public class TypeUnifyTask extends RecursiveTask>> { undefined.add(pair); break; } - first = false; + first = true; } // Filter empty sets or sets that only contain an empty set. @@ -694,9 +722,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("Substitution: " + substitutionSet.toString()); + //writeLog("Substitution: " + substitutionSet.toString()); result.add(resultPrime); - writeLog("Result: " + resultPrime.toString()); + //writeLog("Result: " + resultPrime.toString()); //writeLog("MAX: " + oup.max(resultPrime.iterator()).toString()); } } @@ -724,7 +752,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("Result: " + resultPrime.toString()); + //writeLog("Result: " + resultPrime.toString()); return result; } @@ -740,13 +768,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT)); result.add(resultPrime); - writeLog(resultPrime.toString()); + //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()); + //writeLog(resultPrime.toString()); return result; } @@ -778,7 +806,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()); + //writeLog(resultPrime.toString()); } return result; @@ -793,20 +821,20 @@ public class TypeUnifyTask extends RecursiveTask>> { Set resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT)); result.add(resultPrime); - writeLog(resultPrime.toString()); + //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()); + //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()); + //writeLog(resultPrime.toString()); //} return result; From 9f3439a15e000a0908e360340c0a7c6c42e7b699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 2 Mar 2018 14:12:06 +0100 Subject: [PATCH 18/91] x --- .../typeinference/unify/RuleSet.java | 8 +- .../typeinference/unify/TypeUnifyTask.java | 27 +------ .../unify/model/OrderingUnifyPair.java | 75 ++++++++++++++++--- 3 files changed, 71 insertions(+), 39 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index d739fdb6c..d74ef01fb 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -454,14 +454,14 @@ public class RuleSet implements IRuleSet{ TypeParams typeDParams = typeD.getTypeParams(); TypeParams typeDgenParams = typeDgen.getTypeParams(); - System.out.println("Pair: " +pair); - System.out.println("typeD: " +typeD); + //System.out.println("Pair: " +pair); + //System.out.println("typeD: " +typeD); //System.out.println("typeDParams: " +typeDParams); - System.out.println("typeDgen: " +typeD); + //System.out.println("typeDgen: " +typeD); //System.out.println("typeDgenParams: " +typeDgenParams); Unifier unif = Unifier.identity(); for(int i = 0; i < typeDParams.size(); i++) { - System.out.println("ADAPT" +typeDgenParams); + //System.out.println("ADAPT" +typeDgenParams); if (typeDgenParams.get(i) instanceof PlaceholderType) unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); else System.out.println("ERROR"); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 418a75b80..091f7aef2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -203,31 +203,6 @@ public class TypeUnifyTask extends RecursiveTask>> { } - Set simplifyEq (Set eqs) { - Set leftVarSmaller = eqs.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType) - && !(x.getRhsType() instanceof PlaceholderType) - && x.getPairOp().equals(PairOperator.SMALLERDOT)).collect(Collectors.toCollection(HashSet::new)); - Set leftVarEq = eqs.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType) - && !(x.getRhsType() instanceof PlaceholderType) - && x.getPairOp().equals(PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); - Set rightVarSmaller = eqs.stream() - .filter(x -> (x.getRhsType() instanceof PlaceholderType) - && !(x.getLhsType() instanceof PlaceholderType) - && x.getPairOp().equals(PairOperator.SMALLERDOT)).collect(Collectors.toCollection(HashSet::new)); - Set rightVarEq = eqs.stream() - .filter(x -> (x.getRhsType() instanceof PlaceholderType) - && !(x.getLhsType() instanceof PlaceholderType) - && x.getPairOp().equals(PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); - Set ret = new HashSet<>(); - for (UnifyPair eq : leftVarSmaller) { - eqs.remove(eq); HIER WEITERMACHEN - Stream eqEqualLHS = leftVarSmaller.stream().filter(x -> x.getLhsType().equals(eq.getLhsType())); - } - return ret; - } - Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { //Aufruf von computeCartesianRecursive ENDE @@ -635,7 +610,7 @@ public class TypeUnifyTask extends RecursiveTask>> { undefined.add(pair); break; } - first = true; + first = false; } // Filter empty sets or sets that only contain an empty set. diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 5cf69f76b..6aa0e7d85 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -1,13 +1,20 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; import java.util.Optional; import java.util.Set; import java.util.function.BinaryOperator; +import java.util.stream.Collectors; import java.util.stream.Stream; +import javafx.util.Pair; + import com.google.common.collect.Ordering; +import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -26,14 +33,64 @@ public class OrderingUnifyPair extends Ordering> { return fc.compare(left.getRhsType(), right.getRhsType()); } - public int compare (Set left, Set right) { - Stream ls = left.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); - Stream rs = right.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); - BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; - HashMap hm = rs.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); - ls = ls.filter(x -> !(hm.get(x.getLhsType()) == null)); - Optional si = ls.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); - if (!si.isPresent()) return 0; - else return si.get(); + public Pair> compare (UnifyType left, UnifyType right) { + UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT); + TypeUnifyTask unifyTask = new TypeUnifyTask(); + HashSet hs = new HashSet<>(); + hs.add(up); + Set smallerRes = unifyTask.applyTypeUnificationRules(hs, fc); + long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); + if (smallerLen == 0) return new Pair<>(-1, smallerRes); + else { + up = new UnifyPair(right, left, PairOperator.SMALLERDOT); + //TypeUnifyTask unifyTask = new TypeUnifyTask(); + hs = new HashSet<>(); + hs.add(up); + Set greaterRes = unifyTask.applyTypeUnificationRules(hs, fc); + long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); + if (greaterLen == 0) return new Pair<>(1, smallerRes); + else return new Pair<>(0, new HashSet<>()); + } } + + public int compare (Set left, Set right) { + if (!true) { + Stream lseq = left.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); + Stream rseq = right.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); + BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; + HashMap hm = rseq.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); + lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null)); + Optional si = lseq.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + if (!si.isPresent()) return 0; + else return si.get(); + } + else { + Optional lseq = left.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)).findFirst(); + Optional rseq = right.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)).findFirst(); + Set lsle = left.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .collect(Collectors.toCollection(HashSet::new)); + Set rsle = right.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .collect(Collectors.toCollection(HashSet::new)); + Pair> int_Unifier = compare(lseq.get().getRhsType(), rseq.get().getRhsType()); + Unifier uni = new Unifier(); + int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); + if (lsle.size() == 0) return int_Unifier.getKey(); + else { + Stream lslestr = lsle.stream().map(uni::apply); + Stream rslestr = rsle.stream().map(uni::apply); + BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; + HashMap hm = rslestr.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); + lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null)); + Optional si = lslestr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + if (!si.isPresent()) return 0; + else return si.get(); + } + + } + } } + From cba489f279e111f6443abd0f27258f08ff967059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 3 Mar 2018 01:07:25 +0100 Subject: [PATCH 19/91] modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java eine Variable korrigiert TODO eingefuegt compare muss fuer ale moeglichen Faelle aus calculatePairSets erstellt werden --- .../typeinference/unify/model/OrderingUnifyPair.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 6aa0e7d85..7da91d428 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -48,7 +48,7 @@ public class OrderingUnifyPair extends Ordering> { hs.add(up); Set greaterRes = unifyTask.applyTypeUnificationRules(hs, fc); long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); - if (greaterLen == 0) return new Pair<>(1, smallerRes); + if (greaterLen == 0) return new Pair<>(1, greaterRes); else return new Pair<>(0, new HashSet<>()); } } @@ -65,6 +65,7 @@ public class OrderingUnifyPair extends Ordering> { else return si.get(); } else { + //TODO 2018-03-02: hier muessen mehree =. eingefuegt werden und alle weiteren Faelle pruefen Optional lseq = left.stream() .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)).findFirst(); Optional rseq = right.stream() From 831bf1fe17fc62893f9ea851e9d0907c6fc2df6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 4 Mar 2018 22:58:31 +0100 Subject: [PATCH 20/91] =?UTF-8?q?=09modified:=20=20=20src/de/dhbwstuttgart?= =?UTF-8?q?/typeinference/unify/model/OrderingUnifyPair.java=20weitere=20F?= =?UTF-8?q?=C3=A4lle=20in=20die=20Ordnung=20eingebaut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unify/model/OrderingUnifyPair.java | 65 +++++++++++++------ 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 7da91d428..7762af782 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -29,8 +29,13 @@ public class OrderingUnifyPair extends Ordering> { public int compare (UnifyPair left, UnifyPair right) { if (left == null || right == null) - System.out.println("Fehler"); - return fc.compare(left.getRhsType(), right.getRhsType()); + System.out.println("Fehler"); + if (left.getLhsType() instanceof PlaceholderType) { + return fc.compare(left.getRhsType(), right.getRhsType()); + } + else { + return fc.compare(left.getLhsType(), right.getLhsType()); + } } public Pair> compare (UnifyType left, UnifyType right) { @@ -54,9 +59,21 @@ public class OrderingUnifyPair extends Ordering> { } public int compare (Set left, Set right) { - if (!true) { - Stream lseq = left.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); - Stream rseq = right.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); + Set lefteq = left.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) + .collect(Collectors.toCollection(HashSet::new)); + Set righteq = right.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) + .collect(Collectors.toCollection(HashSet::new)); + Set leftle = left.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .collect(Collectors.toCollection(HashSet::new)); + Set rightle = right.stream() + .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .collect(Collectors.toCollection(HashSet::new)); + if (lefteq.size() > 1) { + Stream lseq = lefteq.stream(); //left.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); + Stream rseq = righteq.stream(); //right.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; HashMap hm = rseq.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null)); @@ -64,34 +81,44 @@ public class OrderingUnifyPair extends Ordering> { if (!si.isPresent()) return 0; else return si.get(); } - else { + if (lefteq.size() == 1 && righteq.size() == 1) { //TODO 2018-03-02: hier muessen mehree =. eingefuegt werden und alle weiteren Faelle pruefen - Optional lseq = left.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)).findFirst(); - Optional rseq = right.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)).findFirst(); - Set lsle = left.stream() + UnifyPair lseq = lefteq.iterator().next(); + UnifyPair rseq = righteq.iterator().next(); + /*Set lsle = left.stream() .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) .collect(Collectors.toCollection(HashSet::new)); Set rsle = right.stream() .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) .collect(Collectors.toCollection(HashSet::new)); - Pair> int_Unifier = compare(lseq.get().getRhsType(), rseq.get().getRhsType()); + */ + Pair> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType()); Unifier uni = new Unifier(); int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - if (lsle.size() == 0) return int_Unifier.getKey(); + if (leftle.size() == 0) return int_Unifier.getKey(); else { - Stream lslestr = lsle.stream().map(uni::apply); - Stream rslestr = rsle.stream().map(uni::apply); + Stream lslestr = leftle.stream().map(uni::apply); + Stream rslestr = rightle.stream().map(uni::apply); BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; - HashMap hm = rslestr.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); - lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null)); - Optional si = lslestr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + + HashMap hm; + Optional si; + if (leftle.iterator().next().getLhsType() instanceof PlaceholderType) { + hm = rslestr.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); + lslestr = lslestr.filter(x -> !(hm.get(x.getLhsType()) == null)); + si = lslestr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + } + else { + hm = rslestr.reduce(new HashMap(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner); + rslestr = rslestr.filter(x -> !(hm.get(x.getRhsType()) == null)); + si = rslestr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + } if (!si.isPresent()) return 0; else return si.get(); } - } + } + return 0; } } From bb016e6417c6487cdb400d1db30452b1f8774d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 5 Mar 2018 20:04:10 +0100 Subject: [PATCH 21/91] modified: src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java modified: src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java --- .../unify/interfaces/IFiniteClosure.java | 3 +- .../unify/model/FiniteClosure.java | 8 ++- .../unify/model/OrderingUnifyPair.java | 70 ++++++++++++++----- 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index 110ff4b8f..e97a40e86 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -5,6 +5,7 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; import de.dhbwstuttgart.typeinference.unify.model.SuperType; @@ -62,5 +63,5 @@ public interface IFiniteClosure { public Set getChildren(UnifyType t); public Set getAllTypesByName(String typeName); - public int compare(UnifyType rhsType, UnifyType rhsType2); + public int compare(UnifyType rhsType, UnifyType rhsType2, PairOperator pairop); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 6500abcf0..c7e197c30 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -435,7 +435,11 @@ public class FiniteClosure extends Ordering implements IFiniteClosure } public int compare (UnifyType left, UnifyType right) { - UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT); + return compare(left, right, PairOperator.SMALLERDOT); + } + + public int compare (UnifyType left, UnifyType right, PairOperator pairop) { + UnifyPair up = new UnifyPair(left, right, pairop); TypeUnifyTask unifyTask = new TypeUnifyTask(); HashSet hs = new HashSet<>(); hs.add(up); @@ -443,7 +447,7 @@ public class FiniteClosure extends Ordering implements IFiniteClosure long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); if (smallerLen == 0) return -1; else { - up = new UnifyPair(right, left, PairOperator.SMALLERDOT); + up = new UnifyPair(right, left, pairop); //TypeUnifyTask unifyTask = new TypeUnifyTask(); hs = new HashSet<>(); hs.add(up); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 7762af782..a95a790fa 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -31,10 +31,10 @@ public class OrderingUnifyPair extends Ordering> { if (left == null || right == null) System.out.println("Fehler"); if (left.getLhsType() instanceof PlaceholderType) { - return fc.compare(left.getRhsType(), right.getRhsType()); + return fc.compare(left.getRhsType(), right.getRhsType(), left.getPairOp()); } else { - return fc.compare(left.getLhsType(), right.getLhsType()); + return fc.compare(left.getLhsType(), right.getLhsType(), left.getPairOp()); } } @@ -66,12 +66,43 @@ public class OrderingUnifyPair extends Ordering> { .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) .collect(Collectors.toCollection(HashSet::new)); Set leftle = left.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType) + && x.getPairOp() == PairOperator.SMALLERDOT)) .collect(Collectors.toCollection(HashSet::new)); Set rightle = right.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType) + && x.getPairOp() == PairOperator.SMALLERDOT)) .collect(Collectors.toCollection(HashSet::new)); - if (lefteq.size() > 1) { + Set leftlewc = left.stream() + .filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType) + && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .collect(Collectors.toCollection(HashSet::new)); + Set rightlewc = right.stream() + .filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType) + && x.getPairOp() == PairOperator.SMALLERDOTWC)) + .collect(Collectors.toCollection(HashSet::new)); + //Fall 2 und 3 + if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { + return 1; + } + //Fall 2 und 3 + if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 1) { + return -1; + } + //Fall 5 + if (lefteq.size() == 1 && leftle.size() == 0 && righteq.size() == 1 && rightle.size() == 1) { + return -1; + } + //Fall 5 + if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 0) { + return 1; + } + //Fall 5 + if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 1) { + return 0; + } + // Nur Paare a =. Theta + if (leftle.size() == 0 && rightle.size() == 0 && leftlewc.size() == 0 && rightlewc.size() ==0) { Stream lseq = lefteq.stream(); //left.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); Stream rseq = righteq.stream(); //right.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; @@ -81,7 +112,8 @@ public class OrderingUnifyPair extends Ordering> { if (!si.isPresent()) return 0; else return si.get(); } - if (lefteq.size() == 1 && righteq.size() == 1) { + //Fall 1 und 4 + if (lefteq.size() == 1 && righteq.size() == 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) { //TODO 2018-03-02: hier muessen mehree =. eingefuegt werden und alle weiteren Faelle pruefen UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); @@ -95,26 +127,28 @@ public class OrderingUnifyPair extends Ordering> { Pair> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType()); Unifier uni = new Unifier(); int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - if (leftle.size() == 0) return int_Unifier.getKey(); + if (lseq.equals(rseq) || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); else { - Stream lslestr = leftle.stream().map(uni::apply); - Stream rslestr = rightle.stream().map(uni::apply); + Set lsleuni = leftlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); + Set rsleuni = rightlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; HashMap hm; Optional si; - if (leftle.iterator().next().getLhsType() instanceof PlaceholderType) { - hm = rslestr.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); - lslestr = lslestr.filter(x -> !(hm.get(x.getLhsType()) == null)); - si = lslestr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); - } + //1. Fall + if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) { + hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); + Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null)); + si = lslewcstr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + } + //4. Fall else { - hm = rslestr.reduce(new HashMap(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner); - rslestr = rslestr.filter(x -> !(hm.get(x.getRhsType()) == null)); - si = rslestr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner); + Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getRhsType()) == null)); + si = lslewcstr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); } if (!si.isPresent()) return 0; - else return si.get(); + else if (si.get() == int_Unifier.getKey()) return int_Unifier.getKey(); else return 0; } } From ccc16fd22b5f4d740069c10968fd8d1cb273448f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 7 Mar 2018 13:09:47 +0100 Subject: [PATCH 22/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java 1. Version mit compare von UnifyPairs --- .../dhbwstuttgart/typeinference/unify/RuleSet.java | 5 ++++- .../typeinference/unify/TypeUnifyTask.java | 7 ++++--- .../typeinference/unify/interfaces/IRuleSet.java | 4 ++++ .../typeinference/unify/model/FiniteClosure.java | 3 +++ .../unify/model/OrderingUnifyPair.java | 13 +++---------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index d74ef01fb..660ab38c9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -699,6 +699,8 @@ public class RuleSet implements IRuleSet{ return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC)); } + /* PL 2018-03-06 auskommentiert sind mutmaßlich falsch + * vgl. JAVA_BSP/Wildcard6.java @Override public Optional reduceWildcardLowUp(UnifyPair pair) { if(pair.getPairOp() != PairOperator.SMALLERDOTWC) @@ -725,6 +727,7 @@ public class RuleSet implements IRuleSet{ return Optional.of(new UnifyPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT)); } + @Override public Optional reduceWildcardLeft(UnifyPair pair) { if(pair.getPairOp() != PairOperator.SMALLERDOTWC) @@ -741,7 +744,7 @@ public class RuleSet implements IRuleSet{ return Optional.empty(); } - + */ @Override public Optional> reduceFunN(UnifyPair pair) { if((pair.getPairOp() != PairOperator.SMALLERDOT) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 091f7aef2..3a0dab309 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -403,9 +403,10 @@ public class TypeUnifyTask extends RecursiveTask>> { opt = opt.isPresent() ? opt : rules.reduceWildcardLowRight(pair); opt = opt.isPresent() ? opt : rules.reduceWildcardUp(pair); opt = opt.isPresent() ? opt : rules.reduceWildcardUpRight(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair); - opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair); + //PL 2018-03-06 auskommentiert muesste falsch sein vgl. JAVA_BSP/Wildcard6.java + //opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair); + //opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair); + //opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair); // Reduce TPH opt = opt.isPresent() ? opt : rules.reduceTph(pair); diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java index 62c9649f2..a2b647c60 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java @@ -27,9 +27,13 @@ public interface IRuleSet { public Optional reduceWildcardLowRight(UnifyPair pair); public Optional reduceWildcardUp(UnifyPair pair); public Optional reduceWildcardUpRight(UnifyPair pair); + + /* + * vgl. JAVA_BSP/Wildcard6.java public Optional reduceWildcardLowUp(UnifyPair pair); public Optional reduceWildcardUpLow(UnifyPair pair); public Optional reduceWildcardLeft(UnifyPair pair); + */ /* * Additional Rules which replace cases of the cartesian product diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index c7e197c30..2e4e7bc3d 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -439,6 +439,9 @@ public class FiniteClosure extends Ordering implements IFiniteClosure } public int compare (UnifyType left, UnifyType right, PairOperator pairop) { + if ((left instanceof ExtendsType && right instanceof ReferenceType) + || (right instanceof ExtendsType && left instanceof ReferenceType)) + System.out.println(""); UnifyPair up = new UnifyPair(left, right, pairop); TypeUnifyTask unifyTask = new TypeUnifyTask(); HashSet hs = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index a95a790fa..be561934a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -114,20 +114,13 @@ public class OrderingUnifyPair extends Ordering> { } //Fall 1 und 4 if (lefteq.size() == 1 && righteq.size() == 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) { - //TODO 2018-03-02: hier muessen mehree =. eingefuegt werden und alle weiteren Faelle pruefen UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); - /*Set lsle = left.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) - .collect(Collectors.toCollection(HashSet::new)); - Set rsle = right.stream() - .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC)) - .collect(Collectors.toCollection(HashSet::new)); - */ Pair> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType()); Unifier uni = new Unifier(); int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - if (lseq.equals(rseq) || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); + if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName()) + || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); else { Set lsleuni = leftlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); Set rsleuni = rightlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); @@ -148,7 +141,7 @@ public class OrderingUnifyPair extends Ordering> { si = lslewcstr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); } if (!si.isPresent()) return 0; - else if (si.get() == int_Unifier.getKey()) return int_Unifier.getKey(); else return 0; + else return si.get(); } } From 9862df9e6339fd51ce556ff5236538f0898029ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 8 Mar 2018 01:12:17 +0100 Subject: [PATCH 23/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Minimum funktion soweit --- .../typeinference/unify/TypeUnifyTask.java | 9 +++++++-- .../unify/model/OrderingUnifyPair.java | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 3a0dab309..9ebea45e7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -312,13 +312,18 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList> nextSetasList = new ArrayList<>(nextSet); Set> result = new HashSet<>(); int i = 0; - Set a_next = oup.min(nextSetasList.iterator()); + Set a_next; + if (nextSetasList.size()>1) + a_next = oup.min(nextSetasList.iterator()); + else a_next = nextSetasList.iterator().next(); while (nextSetasList.size() != 0) { Set a = a_next; //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); nextSetasList.remove(a); if (nextSetasList.size() > 0) - a_next = oup.min(nextSetasList.iterator()); + if (nextSetasList.size()>1) + a_next = oup.min(nextSetasList.iterator()); + else a_next = nextSetasList.iterator().next(); //PL 2018-03-01 //TODO: 1. Maximum und Minimum unterscheiden //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index be561934a..199e7c6a5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -26,8 +26,16 @@ public class OrderingUnifyPair extends Ordering> { public OrderingUnifyPair(IFiniteClosure fc) { this.fc = fc; } - - public int compare (UnifyPair left, UnifyPair right) { + public int compareEq (UnifyPair left, UnifyPair right) { + if (right.getRhsType() instanceof ExtendsType || right.getRhsType() instanceof SuperType) { + return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOTWC); + } + else { + return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOT); + } + } + /* + public int compareEq (UnifyPair left, UnifyPair right) { if (left == null || right == null) System.out.println("Fehler"); if (left.getLhsType() instanceof PlaceholderType) { @@ -37,6 +45,7 @@ public class OrderingUnifyPair extends Ordering> { return fc.compare(left.getLhsType(), right.getLhsType(), left.getPairOp()); } } + */ public Pair> compare (UnifyType left, UnifyType right) { UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT); @@ -108,7 +117,7 @@ public class OrderingUnifyPair extends Ordering> { BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; HashMap hm = rseq.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null)); - Optional si = lseq.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + Optional si = lseq.map(x -> compareEq(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); if (!si.isPresent()) return 0; else return si.get(); } @@ -132,13 +141,13 @@ public class OrderingUnifyPair extends Ordering> { if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) { hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null)); - si = lslewcstr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); } //4. Fall else { hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner); Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getRhsType()) == null)); - si = lslewcstr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + si = lslewcstr.map(x -> fc.compare(x.getLhsType(), hm.get(x.getRhsType()).getLhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); } if (!si.isPresent()) return 0; else return si.get(); From b5b5b5d9c9f5422df79bed63b4b3f10a998988cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 9 Mar 2018 01:23:02 +0100 Subject: [PATCH 24/91] modified: ../../src/de/dhbwstuttgart/typeinference/constraints/Pair.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Varinace in UnfyPair eingefuegt und Abfrage in computeCartesianRecursive eingefuegt Pruefen, ob Varianve bei Subst und andrene erhalten bleibt. --- .../typeinference/constraints/Pair.java | 1 + .../typeinference/unify/TypeUnifyTask.java | 93 ++++++++++++++----- .../typeinference/unify/model/UnifyPair.java | 9 ++ 3 files changed, 81 insertions(+), 22 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/constraints/Pair.java b/src/de/dhbwstuttgart/typeinference/constraints/Pair.java index ab0cb3ea7..eb3222744 100644 --- a/src/de/dhbwstuttgart/typeinference/constraints/Pair.java +++ b/src/de/dhbwstuttgart/typeinference/constraints/Pair.java @@ -11,6 +11,7 @@ public class Pair implements Serializable public final RefTypeOrTPHOrWildcardOrGeneric TA2; private PairOperator eOperator = PairOperator.SMALLER; + public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2 ) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 9ebea45e7..4f422d12f 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -312,18 +312,42 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList> nextSetasList = new ArrayList<>(nextSet); Set> result = new HashSet<>(); int i = 0; - Set a_next; - if (nextSetasList.size()>1) - a_next = oup.min(nextSetasList.iterator()); - else a_next = nextSetasList.iterator().next(); + byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); + Set a_next = null; + if (nextSetasList.size()>1) { + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else if (variance == 0) { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } while (nextSetasList.size() != 0) { Set a = a_next; //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); - nextSetasList.remove(a); - if (nextSetasList.size() > 0) - if (nextSetasList.size()>1) - a_next = oup.min(nextSetasList.iterator()); - else a_next = nextSetasList.iterator().next(); + nextSetasList.remove(a); + if (nextSetasList.size() > 0) { + if (nextSetasList.size()>1) { + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } + } //PL 2018-03-01 //TODO: 1. Maximum und Minimum unterscheiden //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern @@ -338,10 +362,30 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } - if (!result.isEmpty()) //&& (oup.compare(a, a_next) == -1)) break; - if (a.equals(a_next) || - (oup.compare(a, a_next) == -1)) + if (!result.isEmpty()) { + if (variance == 1) { + if (a.equals(a_next) || (oup.compare(a, a_next) == 1)) { + System.out.print(""); break; + } + else { + System.out.print(""); + } + } + else { if (variance == -1) { + if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) { + System.out.print(""); + break; + } + else { + System.out.print(""); + } + } + else if (variance == 0) { + break; + } + } + } } return result; } @@ -528,7 +572,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc); + Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), pair.getVariance(), fc); //System.out.println(x1); result.get(0).add(x1); } @@ -544,7 +588,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc)); + result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); @@ -557,7 +601,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc)); + result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); @@ -575,7 +619,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc)); + result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); @@ -599,7 +643,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); result.get(7).add( - unifyCase8(lhsType, (PlaceholderType) rhsType, fc)); + unifyCase8(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); @@ -627,7 +671,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian product Case 1: (a <. Theta') */ - protected Set> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) { + protected Set> unifyCase1(PlaceholderType a, UnifyType thetaPrime, byte variance, IFiniteClosure fc) { Set> result = new HashSet<>(); boolean allGen = thetaPrime.getTypeParams().size() > 0; @@ -704,6 +748,7 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT)); resultPrime.addAll(substitutionSet); //writeLog("Substitution: " + substitutionSet.toString()); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog("Result: " + resultPrime.toString()); //writeLog("MAX: " + oup.max(resultPrime.iterator()).toString()); @@ -719,7 +764,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 2: (a <.? ? ext Theta') */ - private Set> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) { + private Set> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, byte variance, IFiniteClosure fc) { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); @@ -732,6 +777,7 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog("Result: " + resultPrime.toString()); return result; @@ -740,7 +786,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 3: (a <.? ? sup Theta') */ - private Set> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) { + private Set> unifyCase3(PlaceholderType a, SuperType subThetaPrime, byte variance, IFiniteClosure fc) { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); @@ -754,6 +800,7 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); @@ -763,7 +810,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 5: (Theta <. a) */ - private Set> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) { + private Set> unifyCase5(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) { Set> result = new HashSet<>(); boolean allGen = theta.getTypeParams().size() > 0; @@ -786,6 +833,7 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT)); else resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); } @@ -796,7 +844,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 8: (Theta <.? a) */ - private Set> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) { + private Set> unifyCase8(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) { Set> result = new HashSet<>(); //for(UnifyType thetaS : fc.grArg(theta)) { Set resultPrime = new HashSet<>(); @@ -814,6 +862,7 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT)); resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT)); + resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); //} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 8d038fd34..abb7651c1 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -26,6 +26,8 @@ public class UnifyPair { */ private PairOperator pairOp; + private byte variance = 0; + private final int hashCode; /** @@ -64,6 +66,13 @@ public class UnifyPair { return pairOp; } + public byte getVariance() { + return variance; + } + + public void setVariance(byte v) { + variance = v; + } @Override public boolean equals(Object obj) { if(!(obj instanceof UnifyPair)) From 0315a1f144137025fbf462ac7d45dcaf1e626197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 10 Mar 2018 01:04:19 +0100 Subject: [PATCH 25/91] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java compare(Matrix, Vector, ? extends Vector> <.? gen_ab funktioniert nicht --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 35 ++++++++++++------- .../typeinference/unify/TypeUnify.java | 9 ++--- .../typeinference/unify/TypeUnifyTask.java | 20 +++++------ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 88743c257..a04f3c4cf 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -18,11 +18,13 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; +import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -94,21 +96,28 @@ public class JavaTXCompiler { TypeUnify unify = new TypeUnify(); Set> results = new HashSet<>(); - for (List> xCons : unifyCons.cartesianProduct()) { - Set xConsSet = new HashSet<>(); - for (Constraint constraint : xCons) { - xConsSet.addAll(constraint); - } + try { + FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log")); + for (List> xCons : unifyCons.cartesianProduct()) { + Set xConsSet = new HashSet<>(); + for (Constraint constraint : xCons) { + xConsSet.addAll(constraint); + } - System.out.println(xConsSet); - Set> result = unify.unifySequential(xConsSet, finiteClosure); - //Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); - results.addAll(result); + System.out.println(xConsSet); + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); + //Set> result = unify.unify(xConsSet, finiteClosure); + System.out.println("RESULT: " + result); + logFile.write("RES: " + result.toString()+"\n"); + logFile.flush(); + results.addAll(result); + } + } + catch (IOException e) { } + + return results.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } - return results.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); - } private Map generateTPHMap(ConstraintSet constraints) { HashMap ret = new HashMap<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index f457fbb8f..69ed93b27 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.unify; +import java.io.FileWriter; import java.util.Set; import java.util.concurrent.ForkJoinPool; @@ -7,16 +8,16 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set eq, IFiniteClosure fc) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true); + public Set> unify(Set eq, IFiniteClosure fc, FileWriter logFile) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } - public Set> unifySequential(Set eq, IFiniteClosure fc) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false); + public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile) { + TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile); Set> res = unifyTask.compute(); return res; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 4f422d12f..713ee9aaf 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -75,18 +75,13 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(); } - public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel) { + public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel, FileWriter logFile) { this.eq = eq; this.fc = fc; this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; - try { - logFile = new FileWriter(new File(rootDirectory+"log")); - logFile.write("xxx"); - logFile.flush(); - rules = new RuleSet(logFile); - } - catch (IOException e) { } + this.logFile = logFile; + rules = new RuleSet(logFile); } @Override @@ -105,6 +100,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 1: Repeated application of reduce, adapt, erase, swap */ writeLog("Unifikation: " + eq.toString()); + eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); Set eq0 = applyTypeUnificationRules(eq, fc); /* @@ -245,13 +241,13 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet.add(eqPrime); else if(eqPrimePrime.isPresent()) { //System.out.println("nextStep: " + eqPrimePrime.get()); - TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true); + TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile); forks.add(fork); fork.fork(); } else { //System.out.println("nextStep: " + eqPrime); - TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true); + TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile); forks.add(fork); fork.fork(); } @@ -314,6 +310,8 @@ public class TypeUnifyTask extends RecursiveTask>> { int i = 0; byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); Set a_next = null; + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("A")) + System.out.print(""); if (nextSetasList.size()>1) { if (variance == 1) { a_next = oup.max(nextSetasList.iterator()); @@ -373,6 +371,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { if (variance == -1) { + if (a.iterator().next().getLhsType().getName().equals("A")) + System.out.print(""); if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) { System.out.print(""); break; From 95943b1627ead9fd8eba3710b3db3c491fe42bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 10 Mar 2018 12:32:07 +0100 Subject: [PATCH 26/91] modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java compare(Matrix, Vector, ? extends Vector> <.? gen_ab eingefuegt. --- .../unify/model/OrderingUnifyPair.java | 90 +++++++++++++------ 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 199e7c6a5..8a269ca73 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -123,36 +123,72 @@ public class OrderingUnifyPair extends Ordering> { } //Fall 1 und 4 if (lefteq.size() == 1 && righteq.size() == 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) { + if (lefteq.iterator().next().getLhsType().getName().equals("A")) + System.out.print(""); UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); - Pair> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType()); - Unifier uni = new Unifier(); - int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName()) - || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); - else { - Set lsleuni = leftlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); - Set rsleuni = rightlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); - BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; - - HashMap hm; - Optional si; - //1. Fall - if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) { - hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); - Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null)); - si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); - } - //4. Fall - else { - hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner); - Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getRhsType()) == null)); - si = lslewcstr.map(x -> fc.compare(x.getLhsType(), hm.get(x.getRhsType()).getLhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); - } - if (!si.isPresent()) return 0; - else return si.get(); + if (lseq.getRhsType().getName().equals("Object")) { + if (rseq.getRhsType().getName().equals("Object")) return 0; + else return 1; + } + else { + if (rseq.getRhsType().getName().equals("Object")) return -1; + } + if (leftlewc.size() == rightlewc.size()) { + Pair> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType()); + Unifier uni = new Unifier(); + int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); + if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName()) + || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); + else { + Set lsleuni = leftlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); + Set rsleuni = rightlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); + BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; + + HashMap hm; + Optional si; + //1. Fall + if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) { + hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); + Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null)); + si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + } + //4. Fall + else { + hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner); + Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getRhsType()) == null)); + si = lslewcstr.map(x -> fc.compare(x.getLhsType(), hm.get(x.getRhsType()).getLhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + } + if (!si.isPresent()) return 0; + else return si.get(); + } + } else { + if (leftlewc.size() > 0) { + Set subst; + if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) { + subst = leftlewc.stream().map(x -> new UnifyPair(x.getLhsType(), x.getRhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); + } + else { + subst = leftlewc.stream().map(x -> new UnifyPair(x.getRhsType(), x.getLhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); + } + Unifier uni = new Unifier(); + subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); + lseq = uni.apply(lseq); + } + else { + Set subst; + if (rightlewc.iterator().next().getLhsType() instanceof PlaceholderType) { + subst = rightlewc.stream().map(x -> new UnifyPair(x.getLhsType(), x.getRhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); + } + else { + subst = rightlewc.stream().map(x -> new UnifyPair(x.getRhsType(), x.getLhsType(), PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new)); + } + Unifier uni = new Unifier(); + subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); + rseq = uni.apply(rseq); + } + return compareEq(lseq, rseq); } - } return 0; } From 1667b394f2e85341fe5f299afc262597ab303fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 11 Mar 2018 20:39:38 +0100 Subject: [PATCH 27/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Variancen gesetzt --- .../typeinference/unify/TypeUnifyTask.java | 12 +++++++----- .../typeinference/unify/model/OrderingUnifyPair.java | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 713ee9aaf..977516b1a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -572,7 +572,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), pair.getVariance(), fc); + Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), (byte)1, fc); //System.out.println(x1); result.get(0).add(x1); } @@ -588,7 +588,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), pair.getVariance(), fc)); + result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), (byte)0, fc)); } else { Set s1 = new HashSet<>(); @@ -601,7 +601,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, pair.getVariance(), fc)); + result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, (byte)0, fc)); } else { Set s1 = new HashSet<>(); @@ -619,7 +619,9 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); + if (rhsType.getName().equals("A")) + System.out.println(); + result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, (byte)-1, fc)); } else { Set s1 = new HashSet<>(); @@ -643,7 +645,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); result.get(7).add( - unifyCase8(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); + unifyCase8(lhsType, (PlaceholderType) rhsType, (byte)0, fc)); } else { Set s1 = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 8a269ca73..c382cdffa 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -90,6 +90,7 @@ public class OrderingUnifyPair extends Ordering> { .filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType) && x.getPairOp() == PairOperator.SMALLERDOTWC)) .collect(Collectors.toCollection(HashSet::new)); + //System.out.println(left.toString()); //Fall 2 und 3 if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { return 1; From 13c70148a8b81ce7695031fc7121ddc121b29565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 13 Mar 2018 08:46:25 +0100 Subject: [PATCH 28/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: ../javFiles/Matrix.jav mul1 und add ergaenzt. Fehler bei elementAt: Liefert Object als Returntyp --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 5 ++++- .../typeinference/unify/model/OrderingUnifyPair.java | 3 ++- test/javFiles/Matrix.jav | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 977516b1a..f8af5dd79 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -362,7 +362,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } if (!result.isEmpty()) { if (variance == 1) { - if (a.equals(a_next) || (oup.compare(a, a_next) == 1)) { + if (a.iterator().next().getLhsType().getName().equals("WL")) + System.out.print(""); + if (a.equals(a_next) || + (oup.compare(a, a_next) == 1)) { System.out.print(""); break; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index c382cdffa..0aa996831 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -117,7 +117,8 @@ public class OrderingUnifyPair extends Ordering> { Stream rseq = righteq.stream(); //right.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)); BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; HashMap hm = rseq.reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); - lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null)); + lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null));//NOCHMALS UEBERPRUEFEN!!!! + lseq = lseq.filter(x -> !x.equals(hm.get(x.getLhsType()))); //Elemente die gleich sind muessen nicht verglichen werden Optional si = lseq.map(x -> compareEq(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } ); if (!si.isPresent()) return 0; else return si.get(); diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index e11835359..e8178ad4e 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -3,6 +3,8 @@ import java.lang.Integer; import java.lang.Boolean; class Matrix extends Vector> { + Integer mul1(Integer x, Integer y) { return x;} + Integer add(Integer x, Integer y) { return x;} mul(m) { var ret = new Matrix(); var i = 0; @@ -14,8 +16,8 @@ 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 = add(erg, mul1(v1.elementAt(k), + m.elementAt(k).elementAt(j))); k++; } v2.addElement(new Integer(erg)); j++; } From 273ddb92d7155a750a7ab7599c45384c78d5064d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 14 Mar 2018 13:56:28 +0100 Subject: [PATCH 29/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java modified: ../javFiles/Matrix.jav --- .../typeinference/unify/TypeUnifyTask.java | 10 ++++++++-- .../typeinference/unify/model/UnifyPair.java | 2 ++ test/javFiles/Matrix.jav | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index f8af5dd79..4af7a62ce 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -156,7 +156,9 @@ public class TypeUnifyTask extends RecursiveTask>> { // those pairs are contradictory and the unification is impossible. if(!undefinedPairs.isEmpty()) { writeLog("UndefinedPairs; " + undefinedPairs); - return new HashSet<>(); + Set> error = new HashSet<>(); + error.add(undefinedPairs); + return error; } /* Up to here, no cartesian products are calculated. @@ -310,7 +312,7 @@ public class TypeUnifyTask extends RecursiveTask>> { int i = 0; byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); Set a_next = null; - if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("A")) + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) System.out.print(""); if (nextSetasList.size()>1) { if (variance == 1) { @@ -360,6 +362,10 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } + if (result.size() == 1) { + System.out.println(result.toString()); + result.remove(result.iterator().next()); + } if (!result.isEmpty()) { if (variance == 1) { if (a.iterator().next().getLhsType().getName().equals("WL")) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index abb7651c1..821943636 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -27,6 +27,8 @@ public class UnifyPair { private PairOperator pairOp; private byte variance = 0; + + private boolean undefinedPair = false; private final int hashCode; diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index e8178ad4e..6d73c1fc8 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -16,6 +16,7 @@ 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 = add(erg, mul1(v1.elementAt(k), m.elementAt(k).elementAt(j))); k++; } From 7e6dee8e1d9c8e097812f5954ab2fff9c972814e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 14 Mar 2018 17:48:04 +0100 Subject: [PATCH 30/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../javFiles/Matrix.jav --- .../typeinference/unify/TypeUnifyTask.java | 11 ++++++----- test/javFiles/Matrix.jav | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 4af7a62ce..b2c9f4587 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -158,7 +158,8 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("UndefinedPairs; " + undefinedPairs); Set> error = new HashSet<>(); error.add(undefinedPairs); - return error; + //return error; + return new HashSet<>(); } /* Up to here, no cartesian products are calculated. @@ -362,10 +363,10 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } - if (result.size() == 1) { - System.out.println(result.toString()); - result.remove(result.iterator().next()); - } + //if (result.size() == 1) { + // System.out.println(result.toString()); + // result.remove(result.iterator().next()); + //} if (!result.isEmpty()) { if (variance == 1) { if (a.iterator().next().getLhsType().getName().equals("WL")) diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index 6d73c1fc8..4ae776401 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -4,7 +4,7 @@ import java.lang.Boolean; class Matrix extends Vector> { Integer mul1(Integer x, Integer y) { return x;} - Integer add(Integer x, Integer y) { return x;} + Integer add1(Integer x, Integer y) { return x;} mul(m) { var ret = new Matrix(); var i = 0; @@ -16,9 +16,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 = add(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++; } From de5b43d72bbc7555bed05ebd118b47c423b56ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 15 Mar 2018 17:00:26 +0100 Subject: [PATCH 31/91] 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 Links der substitierten Pare eingefuegt. --- .../typeinference/unify/TypeUnifyTask.java | 31 +++++++++++++----- .../typeinference/unify/model/Unifier.java | 2 +- .../typeinference/unify/model/UnifyPair.java | 32 +++++++++++++++++++ 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index b2c9f4587..3f37add10 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -157,9 +157,9 @@ public class TypeUnifyTask extends RecursiveTask>> { if(!undefinedPairs.isEmpty()) { writeLog("UndefinedPairs; " + undefinedPairs); Set> error = new HashSet<>(); + undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); error.add(undefinedPairs); - //return error; - return new HashSet<>(); + return error; } /* Up to here, no cartesian products are calculated. @@ -297,7 +297,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 7: Filter empty sets; */ - eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); + eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); if (!eqPrimePrimeSet.isEmpty()) writeLog("Result " + eqPrimePrimeSet.toString()); return eqPrimePrimeSet; @@ -363,11 +363,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } - //if (result.size() == 1) { - // System.out.println(result.toString()); - // result.remove(result.iterator().next()); - //} - if (!result.isEmpty()) { + if (!result.isEmpty() && !isUndefinedPairSetSet(result)) { if (variance == 1) { if (a.iterator().next().getLhsType().getName().equals("WL")) System.out.print(""); @@ -396,10 +392,29 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } + if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result)) { + return result; + } + //else result.stream().filter(y -> !isUndefinedPairSet(y)); } return result; } + protected boolean isUndefinedPairSet(Set s) { + + Optional res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y)); + if (res.isPresent()) { return res.get(); } + else { return false; } + } + + protected boolean isUndefinedPairSetSet(Set> s) { + if (s.size() ==1) { + Optional res = s.stream().map(x -> isUndefinedPairSet(x)).reduce((x,y)-> (x == y)); + if (res.isPresent()) { return res.get(); } + else { return false; } + } + return false; + } /** * Checks whether a set of pairs is in solved form. * @param eqPrimePrime The set of pair diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 061ba5880..7b32864d8 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -63,7 +63,7 @@ public class Unifier implements Function, Iterable Date: Thu, 15 Mar 2018 20:47:16 +0100 Subject: [PATCH 32/91] modified: typeinference/unify/TypeUnifyTask.java modified: typeinference/unify/model/UnifyPair.java --- .../typeinference/unify/TypeUnifyTask.java | 15 +++++++++------ .../typeinference/unify/model/UnifyPair.java | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index b2c9f4587..15eef7c20 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -158,8 +158,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("UndefinedPairs; " + undefinedPairs); Set> error = new HashSet<>(); error.add(undefinedPairs); - //return error; - return new HashSet<>(); + return error; } /* Up to here, no cartesian products are calculated. @@ -363,10 +362,6 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } - //if (result.size() == 1) { - // System.out.println(result.toString()); - // result.remove(result.iterator().next()); - //} if (!result.isEmpty()) { if (variance == 1) { if (a.iterator().next().getLhsType().getName().equals("WL")) @@ -400,6 +395,14 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } + protected boolean isUndefinedPairSet(Set> s) { + boolean res = true; + if (s.size() ==1) { + s.iterator().next().stream().forEach(x -> { res = res && x.isUndefinedPair(); return; }); + return res; + } + + } /** * Checks whether a set of pairs is in solved form. * @param eqPrimePrime The set of pair diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 821943636..52dc605a9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -75,6 +75,10 @@ public class UnifyPair { public void setVariance(byte v) { variance = v; } + + public boolean isUndefinedPair() { + return undefinedPair; + } @Override public boolean equals(Object obj) { if(!(obj instanceof UnifyPair)) From 3638edfa73d097525be68db58c55c4dd4ae714ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 16 Mar 2018 14:10:40 +0100 Subject: [PATCH 33/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: test/javFiles/Matrix.jav Fehler entdeckt, in unifyCase1 fuer die Typen aus FC keine fresh TV getsetzt werden. --- .../typeinference/unify/TypeUnifyTask.java | 13 ++++++++----- test/javFiles/Matrix.jav | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index b741ad587..554c46a2c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -393,7 +393,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } - if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result)) { + if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { return result; } //else result.stream().filter(y -> !isUndefinedPairSet(y)); @@ -749,16 +749,19 @@ public class TypeUnifyTask extends RecursiveTask>> { //System.out.println(i); //if (i == 62) // System.out.println(tqp.toString()); - Optional opt = stdUnify.unify(tqp, thetaPrime); - if (!opt.isPresent()) + Optional opt = stdUnify.unify(tqp.setTypeParams(newTp), thetaPrime); + if (!opt.isPresent()) tpq muesse freshtv gesetzt werden PL 2018-03-16 continue; Unifier unifier = opt.get(); unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); - for (Entry sigma : unifier) + for (Entry sigma : unifier) { + if (tqp.getInvolvedPlaceholderTypes().contains(sigma.getKey())) { //PL eingefuegt 2018-03-16 + break; //TypePalceHolder aus dem FC nicht in das substitutionSet } + } substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT)); - + } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { Set smaller = fc.smaller(unifier.apply(tq)); diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index 4ae776401..a680370f4 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -17,8 +17,8 @@ class Matrix extends Vector> { 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 = add1(erg, mul1(v1.elementAt(k), + m.elementAt(k).elementAt(j))); k++; } v2.addElement(new Integer(erg)); j++; } From 103c7e4b148692f31dfe1a3013789b40bc261a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 17 Mar 2018 15:01:03 +0100 Subject: [PATCH 34/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java visitor freshPlaceholder implements UnifyTypeVisitor --- .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 5 +++-- .../typeinference/unify/model/ExtendsType.java | 6 ++++++ .../dhbwstuttgart/typeinference/unify/model/FunNType.java | 6 ++++++ .../typeinference/unify/model/PlaceholderType.java | 6 ++++++ .../typeinference/unify/model/ReferenceType.java | 7 +++++++ .../typeinference/unify/model/SuperType.java | 6 ++++++ .../typeinference/unify/model/TypeParams.java | 8 ++++++++ .../typeinference/unify/model/UnifyType.java | 6 ++++++ 8 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 554c46a2c..cae65fae6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -750,9 +750,10 @@ public class TypeUnifyTask extends RecursiveTask>> { //if (i == 62) // System.out.println(tqp.toString()); Optional opt = stdUnify.unify(tqp.setTypeParams(newTp), thetaPrime); - if (!opt.isPresent()) tpq muesse freshtv gesetzt werden PL 2018-03-16 + if (!opt.isPresent()) { //tpq muesse freshtv gesetzt werden PL 2018-03-16 continue; - + } + Unifier unifier = opt.get(); unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index 33f32e07b..510e41629 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -2,15 +2,21 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; +import java.util.Hashtable; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; /** * An extends wildcard type "? extends T". */ public final class ExtendsType extends WildcardType { + public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + return visitor.visit(this, ht); + } + /** * Creates a new extends wildcard type. * @param extendedType The extended type e.g. Integer in "? extends Integer" diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index cf2c86ae5..44a4fa715 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -1,8 +1,10 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.util.Hashtable; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; /** * A real function type in java. @@ -10,6 +12,10 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; */ public class FunNType extends UnifyType { + public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + return visitor.visit(this, ht); + } + /** * Creates a FunN-Type with the specified TypeParameters. */ diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index e9268d0d5..a85f356fc 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -3,10 +3,12 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.Hashtable; import java.util.Random; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; /** * An unbounded placeholder type. @@ -54,6 +56,10 @@ public final class PlaceholderType extends UnifyType{ IsGenerated = isGenerated; } + public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + return visitor.visit(this, ht); + } + /** * Creates a fresh placeholder type with a name that does so far not exist. * A user could later instantiate a type using the same name that is equivalent to this type. diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java index 02ab38a02..f10238626 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java @@ -1,8 +1,10 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.util.Hashtable; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; /** * A reference type e.q. Integer or List. @@ -16,6 +18,11 @@ public final class ReferenceType extends UnifyType { */ private final int hashCode; + + public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + return visitor.visit(this, ht); + } + public ReferenceType(String name, UnifyType... params) { super(name, new TypeParams(params)); hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index 4f78602f5..c746bd47b 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -1,8 +1,10 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.util.Hashtable; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; /** * A super wildcard type e.g. ? super Integer. @@ -10,6 +12,10 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; */ public final class SuperType extends WildcardType { + public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + return visitor.visit(this, ht); + } + /** * Creates a new instance "? extends superedType" * @param superedType The type that is supered e.g. Integer in "? super Integer" diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java index 3d5fc278e..973a2785c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java @@ -115,6 +115,14 @@ public final class TypeParams implements Iterable{ return typeParams[i]; } + /** + * Returns the parameters of this object. + * PL 2018-03-17 + */ + public UnifyType[] get() { + return typeParams; + } + /** * Sets the the type t as the i-th parameter and returns a new object * that equals this object, except for the i-th type. diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 1080f03b6..66bd80a85 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -2,10 +2,13 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; +import java.util.Hashtable; import java.util.List; import java.util.Set; +import de.dhbwstuttgart.syntaxtree.StatementVisitor; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; /** * Represents a java type. @@ -33,6 +36,9 @@ public abstract class UnifyType { typeParams = p; } + + abstract public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht); + /** * Returns the name of the type. * @return The name e.q. List for List, Integer or ? extends Integer From b0b1426e204727e567dded3fd73c3df2df801be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 18 Mar 2018 15:11:45 +0100 Subject: [PATCH 35/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java new file: src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java freshtypevraiable Vistor soweit fertig noch nicht getestet --- .../typeinference/unify/TypeUnifyTask.java | 8 +++- .../typeinference/unify/freshPlaceholder.java | 47 +++++++++++++++++++ .../unify/model/ExtendsType.java | 4 +- .../typeinference/unify/model/FunNType.java | 4 +- .../unify/model/PlaceholderType.java | 4 +- .../unify/model/ReferenceType.java | 4 +- .../typeinference/unify/model/SuperType.java | 4 +- .../typeinference/unify/model/UnifyType.java | 4 +- 8 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index cae65fae6..6eb74d167 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -11,6 +12,7 @@ import java.util.Map.Entry; import java.util.Optional; import java.util.Set; import java.util.concurrent.RecursiveTask; +import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -749,7 +751,11 @@ public class TypeUnifyTask extends RecursiveTask>> { //System.out.println(i); //if (i == 62) // System.out.println(tqp.toString()); - Optional opt = stdUnify.unify(tqp.setTypeParams(newTp), thetaPrime); + BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; + HashMap hm = tqp.getInvolvedPlaceholderTypes().stream() + .reduce(new HashMap(), + (x, y)-> { x.put(y,PlaceholderType.freshPlaceholder()); return x; }, combiner); + Optional opt = stdUnify.unify(tqp.accept(new freshPlaceholder(), hm), thetaPrime); if (!opt.isPresent()) { //tpq muesse freshtv gesetzt werden PL 2018-03-16 continue; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java b/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java new file mode 100644 index 000000000..45ccb6bb4 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java @@ -0,0 +1,47 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.HashMap; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; +import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import de.dhbwstuttgart.typeinference.unify.model.SuperType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; + +public class freshPlaceholder implements UnifyTypeVisitor { + + public ReferenceType visit(ReferenceType refty, HashMap ht) { + return new ReferenceType(refty.getName(), + new TypeParams( + Arrays.stream(refty.getTypeParams().get()) + .map(x -> x.accept(this, ht)) + .collect(Collectors.toCollection(ArrayList::new)))); + } + + public PlaceholderType visit(PlaceholderType phty, HashMap ht) { + return ht.get(phty); + } + + public FunNType visit(FunNType funnty, HashMap ht) { + return FunNType.getFunNType( + new TypeParams( + Arrays.stream(funnty.getTypeParams().get()) + .map(x -> x.accept(this, ht)) + .collect(Collectors.toCollection(ArrayList::new))) + ); + } + + public SuperType visit(SuperType suty, HashMap ht) { + return new SuperType(suty.getWildcardedType().accept(this, ht)); + } + + public ExtendsType visit(ExtendsType extty, HashMap ht) { + return new ExtendsType(extty.getWildcardedType().accept(this, ht)); + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index 510e41629..a97977c5a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -2,7 +2,7 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -13,7 +13,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public final class ExtendsType extends WildcardType { - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 44a4fa715..dd96dedde 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -1,6 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.model; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public class FunNType extends UnifyType { - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index a85f356fc..5aab8784c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -2,8 +2,8 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; -import java.util.Hashtable; import java.util.Random; import java.util.Set; @@ -56,7 +56,7 @@ public final class PlaceholderType extends UnifyType{ IsGenerated = isGenerated; } - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java index f10238626..133a87ed5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java @@ -1,6 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.model; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -19,7 +19,7 @@ public final class ReferenceType extends UnifyType { private final int hashCode; - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index c746bd47b..0b98c1593 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -1,6 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.model; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; @@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public final class SuperType extends WildcardType { - public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht) { + public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 66bd80a85..16986d65a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -2,7 +2,7 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; -import java.util.Hashtable; +import java.util.HashMap; import java.util.List; import java.util.Set; @@ -37,7 +37,7 @@ public abstract class UnifyType { } - abstract public UnifyType accept(UnifyTypeVisitor visitor, Hashtable ht); + abstract public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht); /** * Returns the name of the type. From 78db0f01777fd54f81f847924a01690d97ca4e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 19 Mar 2018 09:38:37 +0100 Subject: [PATCH 36/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Errorrueckgabe auskommentiert new file: src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java eingecheckt vorher vergessen modified: test/javFiles/Matrix.jav add und mul aktiviert --- .../typeinference/unify/TypeUnifyTask.java | 7 +++--- .../unify/interfaces/UnifyTypeVisitor.java | 23 +++++++++++++++++++ test/javFiles/Matrix.jav | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 6eb74d167..cd7288e8d 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -160,7 +160,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("UndefinedPairs; " + undefinedPairs); Set> error = new HashSet<>(); undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); - error.add(undefinedPairs); + //error.add(undefinedPairs); return error; } @@ -755,8 +755,9 @@ public class TypeUnifyTask extends RecursiveTask>> { HashMap hm = tqp.getInvolvedPlaceholderTypes().stream() .reduce(new HashMap(), (x, y)-> { x.put(y,PlaceholderType.freshPlaceholder()); return x; }, combiner); - Optional opt = stdUnify.unify(tqp.accept(new freshPlaceholder(), hm), thetaPrime); - if (!opt.isPresent()) { //tpq muesse freshtv gesetzt werden PL 2018-03-16 + Optional opt = stdUnify.unify( + tqp.accept(new freshPlaceholder(), hm), thetaPrime); + if (!opt.isPresent()) { //tqp muesse fresh Typvars gesetzt werden PL 2018-03-16 continue; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java new file mode 100644 index 000000000..bf435f9ca --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java @@ -0,0 +1,23 @@ +package de.dhbwstuttgart.typeinference.unify.interfaces; + +import java.util.HashMap; + +import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import de.dhbwstuttgart.typeinference.unify.model.SuperType; + +public interface UnifyTypeVisitor { + + public ReferenceType visit(ReferenceType refty, HashMap ht); + + public PlaceholderType visit(PlaceholderType phty, HashMap ht); + + public FunNType visit(FunNType funnty, HashMap ht); + + public SuperType visit(SuperType suty, HashMap ht); + + public ExtendsType visit(ExtendsType extty, HashMap ht); + +} diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index a680370f4..ec3fdb93a 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -17,7 +17,7 @@ class Matrix extends Vector> { var k = 0; while(k < v1.size()) { //erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j); - erg = add1(erg, mul1(v1.elementAt(k), + erg = add(erg, mul1(v1.elementAt(k), m.elementAt(k).elementAt(j))); k++; } v2.addElement(new Integer(erg)); From f4bc057afff3f0ba074f746691ac1acd65d123fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 19 Mar 2018 15:25:40 +0100 Subject: [PATCH 37/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java LogAusgabe FC modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java fresh TV in unifyCase1 auf alle cs ausgedehnt modified: test/javFiles/Matrix.jav --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 ++ .../typeinference/unify/TypeUnifyTask.java | 29 +++++++++---------- test/javFiles/Matrix.jav | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index a04f3c4cf..8c43c8266 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -98,6 +98,8 @@ public class JavaTXCompiler { Set> results = new HashSet<>(); try { FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log")); + logFile.write("FC:\\" + finiteClosure.toString()+"\n"); + logFile.flush(); for (List> xCons : unifyCons.cartesianProduct()) { Set xConsSet = new HashSet<>(); for (Constraint constraint : xCons) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index cd7288e8d..45a886c97 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -719,7 +719,17 @@ public class TypeUnifyTask extends RecursiveTask>> { //cs.add(thetaPrime); //PL 18-02-06 entfernt - for(UnifyType c : cs) { + //cs muessen fresh Typvars gesetzt werden PL 2018-03-18 + Set csPHRenamed = cs.stream().map(x -> { + BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; + HashMap hm = x.getInvolvedPlaceholderTypes().stream() + .reduce(new HashMap(), + (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return x.accept(new freshPlaceholder(), hm); + }).collect(Collectors.toCollection(HashSet::new)); + + + for(UnifyType c : csPHRenamed) { //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt. Set thetaQs = fc.smaller(c).stream().collect(Collectors.toCollection(HashSet::new)); //Set thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); @@ -746,18 +756,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } for(UnifyType tqp : thetaQPrimes) { - //System.out.println(tqp.toString()); - //i++; - //System.out.println(i); - //if (i == 62) - // System.out.println(tqp.toString()); - BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; - HashMap hm = tqp.getInvolvedPlaceholderTypes().stream() - .reduce(new HashMap(), - (x, y)-> { x.put(y,PlaceholderType.freshPlaceholder()); return x; }, combiner); - Optional opt = stdUnify.unify( - tqp.accept(new freshPlaceholder(), hm), thetaPrime); - if (!opt.isPresent()) { //tqp muesse fresh Typvars gesetzt werden PL 2018-03-16 + Optional opt = stdUnify.unify(tqp, thetaPrime); + if (!opt.isPresent()) { continue; } @@ -765,9 +765,6 @@ public class TypeUnifyTask extends RecursiveTask>> { unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); for (Entry sigma : unifier) { - if (tqp.getInvolvedPlaceholderTypes().contains(sigma.getKey())) { //PL eingefuegt 2018-03-16 - break; //TypePalceHolder aus dem FC nicht in das substitutionSet } - } substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT)); } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index ec3fdb93a..a680370f4 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -17,7 +17,7 @@ class Matrix extends Vector> { var k = 0; while(k < v1.size()) { //erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j); - erg = add(erg, mul1(v1.elementAt(k), + erg = add1(erg, mul1(v1.elementAt(k), m.elementAt(k).elementAt(j))); k++; } v2.addElement(new Integer(erg)); From 6faffdf90ccf39f95672362c096ecf602533b32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 19 Mar 2018 17:43:27 +0100 Subject: [PATCH 38/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 45a886c97..2f426a463 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -315,9 +315,9 @@ public class TypeUnifyTask extends RecursiveTask>> { int i = 0; byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); Set a_next = null; - if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) - System.out.print(""); if (nextSetasList.size()>1) { + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) + System.out.print(""); if (variance == 1) { a_next = oup.max(nextSetasList.iterator()); } @@ -331,6 +331,8 @@ public class TypeUnifyTask extends RecursiveTask>> { else { a_next = nextSetasList.iterator().next(); } + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D") && nextSetasList.size()>1) + System.out.print(""); while (nextSetasList.size() != 0) { Set a = a_next; //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); @@ -704,6 +706,9 @@ public class TypeUnifyTask extends RecursiveTask>> { * Cartesian product Case 1: (a <. Theta') */ protected Set> unifyCase1(PlaceholderType a, UnifyType thetaPrime, byte variance, IFiniteClosure fc) { + if (a.getName().equals("D")) { + System.out.print(""); + } Set> result = new HashSet<>(); boolean allGen = thetaPrime.getTypeParams().size() > 0; From 01dd4e57e63f118f1532257ed424a1febbbee637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 20 Mar 2018 10:14:01 +0100 Subject: [PATCH 39/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Letzte Version bevor MatchUnifyTask --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 1 + .../typeinference/unify/model/OrderingUnifyPair.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 2f426a463..fb3aa1abe 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -320,6 +320,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); if (variance == 1) { a_next = oup.max(nextSetasList.iterator()); + List> liup = oup.sortedCopy(nextSetasList); } else if (variance == -1) { a_next = oup.min(nextSetasList.iterator()); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 0aa996831..55576bf0b 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -92,6 +92,9 @@ public class OrderingUnifyPair extends Ordering> { .collect(Collectors.toCollection(HashSet::new)); //System.out.println(left.toString()); //Fall 2 und 3 + if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) { + System.out.print(""); + } if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { return 1; } From 5d39863cc6d251a824d742ec7c11796e63fe572b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 20 Mar 2018 22:30:57 +0100 Subject: [PATCH 40/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Maximumsbildung auf maximale Elemente soweit fertig Argument von mul funktion nicht, liefret nur Vec --- .../typeinference/unify/TypeUnifyTask.java | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index fb3aa1abe..73f6eff9f 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; @@ -310,17 +311,22 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { ArrayList>> remainingSets = new ArrayList<>(topLevelSets); Set> nextSet = remainingSets.remove(0); - ArrayList> nextSetasList = new ArrayList<>(nextSet); + List> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); Set> result = new HashSet<>(); - int i = 0; byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); - Set a_next = null; - if (nextSetasList.size()>1) { + if (variance == 1 && nextSetasList.size() > 1) { + List> al = new ArrayList<>(nextSetasList.size()); + for (int ii = 0; ii < nextSetasList.size();ii++) { + al.add(0,nextSetasList.get(ii)); + } + nextSetasList = al; + } + //Set a = nextSetasListIt.next(); + /*if (nextSetasList.size()>1) {zu loeschen if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) System.out.print(""); if (variance == 1) { a_next = oup.max(nextSetasList.iterator()); - List> liup = oup.sortedCopy(nextSetasList); } else if (variance == -1) { a_next = oup.min(nextSetasList.iterator()); @@ -332,12 +338,14 @@ public class TypeUnifyTask extends RecursiveTask>> { else { a_next = nextSetasList.iterator().next(); } + */ if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D") && nextSetasList.size()>1) System.out.print(""); - while (nextSetasList.size() != 0) { - Set a = a_next; + while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { + Set a = nextSetasList.remove(0); //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); - nextSetasList.remove(a); + //nextSetasList.remove(a); + /* zu loeschen if (nextSetasList.size() > 0) { if (nextSetasList.size()>1) { if (variance == 1) { @@ -354,6 +362,7 @@ public class TypeUnifyTask extends RecursiveTask>> { a_next = nextSetasList.iterator().next(); } } + */ //PL 2018-03-01 //TODO: 1. Maximum und Minimum unterscheiden //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern @@ -370,27 +379,23 @@ public class TypeUnifyTask extends RecursiveTask>> { } if (!result.isEmpty() && !isUndefinedPairSetSet(result)) { + Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { - if (a.iterator().next().getLhsType().getName().equals("WL")) - System.out.print(""); - if (a.equals(a_next) || + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a.equals(a_next) || (oup.compare(a, a_next) == 1)) { - System.out.print(""); - break; - } - else { - System.out.print(""); + nextSetasList.remove(a_next); + } } } else { if (variance == -1) { - if (a.iterator().next().getLhsType().getName().equals("A")) - System.out.print(""); - if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) { - System.out.print(""); - break; - } - else { - System.out.print(""); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a.equals(a_next) || + (oup.compare(a, a_next) == -1)) { + nextSetasList.remove(0); + } } } else if (variance == 0) { From 79810be94fd2f111f91e5971632dd080ffacc01b Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Wed, 21 Mar 2018 14:21:50 +0100 Subject: [PATCH 41/91] =?UTF-8?q?FC=20Generator=20ber=C3=BCcksichtig=20int?= =?UTF-8?q?erfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyntaxTreeGenerator/FCGenerator.java | 85 ++++++++++--------- .../SyntaxTreeGenerator.java | 14 +-- .../syntaxtree/ClassOrInterface.java | 9 +- 3 files changed, 60 insertions(+), 48 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java index 24abec67f..ceb3b8173 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -57,48 +57,55 @@ public class FCGenerator { params.add(gtvs.get(gtv.getName())); } - Optional hasSuperclass = availableClasses.stream().filter(cl -> forType.getSuperClass().getName().equals(cl.getClassName())).findAny(); - ClassOrInterface superClass; - if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception - { - superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(forType.getSuperClass().getName().toString())); - }else{ - superClass = hasSuperclass.get(); - } - /* - Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse - modifiziert werden - Beispie: Matrix extends Vector> - Den ersten Parameter mit Vector austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen - */ - //Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen - Iterator itGenParams = superClass.getGenerics().iterator(); - Iterator itSetParams = forType.getSuperClass().getParaList().iterator(); - while(itGenParams.hasNext()){ - RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next(); - //In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen: - RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs)); - newGTVs.put(itGenParams.next().getName(), setSetType); - } - RefTypeOrTPHOrWildcardOrGeneric superType = forType.getSuperClass().acceptTV(new TypeExchanger(newGTVs)); - - RefTypeOrTPHOrWildcardOrGeneric t1 = new RefType(forType.getClassName(), params, new NullToken()); - RefTypeOrTPHOrWildcardOrGeneric t2 = superType; - - Pair ret = new Pair(t1, t2, PairOperator.SMALLER); - - List superTypes; - //Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse: - if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){ - superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER)); - }else{ - superTypes = getSuperTypes(superClass, availableClasses, newGTVs); - } + List superClasses = new ArrayList<>(); + superClasses.add(forType.getSuperClass()); + superClasses.addAll(forType.getSuperInterfaces()); List retList = new ArrayList<>(); - retList.add(ret); - retList.addAll(superTypes); + for(RefType superType : superClasses){ + Optional hasSuperclass = availableClasses.stream().filter(cl -> superType.getName().equals(cl.getClassName())).findAny(); + ClassOrInterface superClass; + if(!hasSuperclass.isPresent()) //Wenn es die Klasse in den available Klasses nicht gibt wird sie im Classpath gesucht. Ansonsten Exception + { + superClass = ASTFactory.createClass(ClassLoader.getSystemClassLoader().loadClass(superType.getName().toString())); + }else{ + superClass = hasSuperclass.get(); + } + /* + Die Parameter der superklasse müssen jetzt nach den Angaben in der Subklasse + modifiziert werden + Beispie: Matrix extends Vector> + Den ersten Parameter mit Vector austauschen und dort alle Generics zu den Typplaceholdern in gtvs austauschen + */ + //Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen + Iterator itGenParams = superClass.getGenerics().iterator(); + Iterator itSetParams = superType.getParaList().iterator(); + while(itGenParams.hasNext()){ + RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next(); + //In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen: + RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs)); + newGTVs.put(itGenParams.next().getName(), setSetType); + } + + RefTypeOrTPHOrWildcardOrGeneric superRefType = superType.acceptTV(new TypeExchanger(newGTVs)); + + RefTypeOrTPHOrWildcardOrGeneric t1 = new RefType(forType.getClassName(), params, new NullToken()); + RefTypeOrTPHOrWildcardOrGeneric t2 = superRefType; + + Pair ret = new Pair(t1, t2, PairOperator.SMALLER); + + List superTypes; + //Rekursiver Aufruf. Abbruchbedingung ist Object als Superklasse: + if(superClass.getClassName().equals(ASTFactory.createObjectClass().getClassName())){ + superTypes = Arrays.asList(new Pair(ASTFactory.createObjectType(), ASTFactory.createObjectType(), PairOperator.SMALLER)); + }else{ + superTypes = getSuperTypes(superClass, availableClasses, newGTVs); + } + + retList.add(ret); + retList.addAll(superTypes); + } return retList; } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index ed96d2e67..726067132 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -203,20 +203,20 @@ public class SyntaxTreeGenerator{ } Boolean isInterface = false; - List implementedInterfaces = convert(ctx.superinterfaces(), generics); + List implementedInterfaces = convert(ctx.superinterfaces(), generics); return new ClassOrInterface(modifiers, name, fielddecl, methods, konstruktoren, genericClassParameters, superClass, isInterface, implementedInterfaces, offset); } - private List convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) { + private List convert(Java8Parser.SuperinterfacesContext ctx, GenericsRegistry generics) { if(ctx == null)return new ArrayList<>(); return convert(ctx.interfaceTypeList(), generics); } - private List convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) { - List ret = new ArrayList<>(); + private List convert(Java8Parser.InterfaceTypeListContext ctx, GenericsRegistry generics) { + List ret = new ArrayList<>(); for(Java8Parser.InterfaceTypeContext interfaceType : ctx.interfaceType()){ - ret.add(TypeGenerator.convert(interfaceType.classType(), reg, generics)); + ret.add((RefType) TypeGenerator.convert(interfaceType.classType(), reg, generics)); } return ret; } @@ -400,7 +400,7 @@ public class SyntaxTreeGenerator{ List fields = convertFields(ctx.interfaceBody()); List methods = convertMethods(ctx.interfaceBody(), name, superClass, generics); - List extendedInterfaces = convert(ctx.extendsInterfaces(), generics); + List extendedInterfaces = convert(ctx.extendsInterfaces(), generics); return new ClassOrInterface(modifiers, name, fields, methods, new ArrayList<>(), genericParams, superClass, true, extendedInterfaces, ctx.getStart()); @@ -423,7 +423,7 @@ public class SyntaxTreeGenerator{ return ret; } - private List convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) { + private List convert(Java8Parser.ExtendsInterfacesContext extendsInterfacesContext, GenericsRegistry generics) { if(extendsInterfacesContext == null)return new ArrayList<>(); return convert(extendsInterfacesContext.interfaceTypeList(), generics); } diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index 5d5fc3e2c..72097fc03 100644 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -13,6 +13,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import org.antlr.v4.runtime.Token; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -26,11 +27,11 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ private GenericDeclarationList genericClassParameters; private RefType superClass; protected boolean isInterface; - private List implementedInterfaces; + private List implementedInterfaces; private List constructors; public ClassOrInterface(int modifiers, JavaClassName name, List fielddecl, List methods, List constructors, GenericDeclarationList genericClassParameters, - RefType superClass, Boolean isInterface, List implementedInterfaces, Token offset){ + RefType superClass, Boolean isInterface, List implementedInterfaces, Token offset){ super(offset); this.modifiers = modifiers; this.name = name; @@ -101,4 +102,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ public void accept(ASTVisitor visitor) { visitor.visit(this); } + + public Collection getSuperInterfaces() { + return implementedInterfaces; + } } From 6b1a4eddfcf70eb29f9e0f1a2919cf0bcc59b667 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Wed, 21 Mar 2018 14:40:47 +0100 Subject: [PATCH 42/91] =?UTF-8?q?Java=209=20zu=20Java=208=20=C3=A4ndern.?= =?UTF-8?q?=20Sollte=20ausreichen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1b97e501c..6dcac2154 100644 --- a/pom.xml +++ b/pom.xml @@ -83,8 +83,8 @@ org.apache.maven.plugins maven-compiler-plugin - 9 - 9 + 8 + 8 From 161c1a1b53031cbbee47221504c6bc8461576c34 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Wed, 21 Mar 2018 15:15:31 +0100 Subject: [PATCH 43/91] =?UTF-8?q?Test=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/finiteClosure/SuperInterfacesTest.java | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/finiteClosure/SuperInterfacesTest.java diff --git a/test/finiteClosure/SuperInterfacesTest.java b/test/finiteClosure/SuperInterfacesTest.java new file mode 100644 index 000000000..f00bf0685 --- /dev/null +++ b/test/finiteClosure/SuperInterfacesTest.java @@ -0,0 +1,31 @@ +package finiteClosure; + +import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class SuperInterfacesTest { + @Test + public void test() throws ClassNotFoundException { + Collection classes = new ArrayList<>(); + classes.add(ASTFactory.createClass(TestClass.class)); + System.out.println(FCGenerator.toFC(classes)); + } +} + +class TestClass implements Test2, Test3{ + +} + +interface Test2 { + +} + +interface Test3{ + +} \ No newline at end of file From f107c8d1f7e019ced0b0fae8c2e2bec6c86cb65f Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Wed, 21 Mar 2018 17:03:32 +0100 Subject: [PATCH 44/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java Variancebestimmung fuer Argument- und Returntypen der Methoden eingefuegt. --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 46 ++++++++++++++++++- .../typeinference/unify/TypeUnifyTask.java | 13 +++--- .../unify/model/OrderingUnifyPair.java | 5 ++ .../typeinference/unify/model/UnifyPair.java | 9 +++- 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 8c43c8266..f31255e01 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -3,16 +3,19 @@ package de.dhbwstuttgart.core; import de.dhbwstuttgart.environment.CompilationEnvironment; import de.dhbwstuttgart.parser.JavaTXParser; +import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.scope.GenericsRegistry; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator; import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassRegistry; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; @@ -21,6 +24,7 @@ import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import java.io.File; @@ -28,6 +32,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; public class JavaTXCompiler { @@ -99,14 +104,53 @@ public class JavaTXCompiler { try { FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log")); logFile.write("FC:\\" + finiteClosure.toString()+"\n"); + for(SourceFile sf : this.sourceFiles.values()) { + logFile.write(ASTTypePrinter.print(sf)); + } logFile.flush(); for (List> xCons : unifyCons.cartesianProduct()) { Set xConsSet = new HashSet<>(); for (Constraint constraint : xCons) { xConsSet.addAll(constraint); } - + //.collect(Collectors.toCollection(ArrayList::new)))) System.out.println(xConsSet); + Set paraTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist() + .stream().filter(z -> z.getType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get()) + .reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + + xConsSet = xConsSet.stream().map(x -> { + if ((x.getLhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getLhsType().getName()) + && (!(x.getRhsType() instanceof PlaceholderType) + || ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) { + x.setVariance((byte)1); + } + if (returnTypeVarNames.contains(x.getLhsType().getName()) + && (!(x.getRhsType() instanceof PlaceholderType) + || ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) { + x.setVariance((byte)-1); + } + } + if ((x.getRhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getRhsType().getName()) + && (!(x.getLhsType() instanceof PlaceholderType) + || ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) { + x.setVariance((byte)1); + } + if (returnTypeVarNames.contains(x.getRhsType().getName()) + && (!(x.getLhsType() instanceof PlaceholderType) + || ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) { + x.setVariance((byte)-1); + } + } + return x; + }).collect(Collectors.toCollection(HashSet::new)); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 73f6eff9f..ec383afe2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -103,7 +103,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 1: Repeated application of reduce, adapt, erase, swap */ writeLog("Unifikation: " + eq.toString()); - eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); + //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); Set eq0 = applyTypeUnificationRules(eq, fc); /* @@ -311,6 +311,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { ArrayList>> remainingSets = new ArrayList<>(topLevelSets); Set> nextSet = remainingSets.remove(0); + writeLog("nextSet: " + nextSet.toString()); List> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); Set> result = new HashSet<>(); byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); @@ -610,7 +611,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), (byte)1, fc); + Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), pair.getVariance(), fc); //System.out.println(x1); result.get(0).add(x1); } @@ -626,7 +627,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), (byte)0, fc)); + result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); @@ -639,7 +640,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, (byte)0, fc)); + result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); @@ -659,7 +660,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (first) { //writeLog(pair.toString()+"\n"); if (rhsType.getName().equals("A")) System.out.println(); - result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, (byte)-1, fc)); + result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); @@ -683,7 +684,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); result.get(7).add( - unifyCase8(lhsType, (PlaceholderType) rhsType, (byte)0, fc)); + unifyCase8(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); } else { Set s1 = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 55576bf0b..129433056 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -67,6 +67,11 @@ public class OrderingUnifyPair extends Ordering> { } } + /* TODO muss noch verifiziert werden PL 2018-03-21 + * (non-Javadoc) + * fuehrt zu Fehlern bei Arrays.sort (contract nicht erfuellt) + * @see com.google.common.collect.Ordering#compare(java.lang.Object, java.lang.Object) + */ public int compare (Set left, Set right) { Set lefteq = left.stream() .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index b5bf13fac..780d05a5f 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -26,6 +26,13 @@ public class UnifyPair { */ private PairOperator pairOp; + /** + * variance shows the variance of the pair + * -1: contravariant + * 1 covariant + * 0 invariant + * PL 2018-03-21 + */ private byte variance = 0; private boolean undefinedPair = false; @@ -129,7 +136,7 @@ public class UnifyPair { @Override public String toString() { - return "(" + lhs + " " + pairOp + " " + rhs + ")"; + return "(" + lhs + " " + pairOp + " " + rhs + ", " + variance + ")"; } /* From dbe05bb718dacfc5280bcaaea8ed89e6fff9f4de Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Wed, 21 Mar 2018 17:37:34 +0100 Subject: [PATCH 45/91] modified: src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java Feher rausgemacht TODO: Varianven werden nicht uebertragen wahrscheinlich subst --- .../dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java index ceb3b8173..1714570e3 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/FCGenerator.java @@ -81,7 +81,7 @@ public class FCGenerator { //Hier vermerken, welche Typen im der Superklasse ausgetauscht werden müssen Iterator itGenParams = superClass.getGenerics().iterator(); Iterator itSetParams = superType.getParaList().iterator(); - while(itGenParams.hasNext()){ + while(itSetParams.hasNext()){ RefTypeOrTPHOrWildcardOrGeneric setType = itSetParams.next(); //In diesem Typ die GTVs durch TPHs und Einsetzungen austauschen: RefTypeOrTPHOrWildcardOrGeneric setSetType = setType.acceptTV(new TypeExchanger(gtvs)); From 95e9b2dbdaa1072219062e5bfafd35fa50830f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 22 Mar 2018 11:26:29 +0100 Subject: [PATCH 46/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Variance auf PlacehloderType uebertragen --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 28 +++++++------------ .../typeinference/unify/TypeUnifyTask.java | 12 +++++++- .../unify/model/PlaceholderType.java | 17 +++++++++++ .../typeinference/unify/model/UnifyPair.java | 1 + 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index f31255e01..23a2750c5 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -126,28 +126,20 @@ public class JavaTXCompiler { xConsSet = xConsSet.stream().map(x -> { if ((x.getLhsType() instanceof PlaceholderType)) { - if (paraTypeVarNames.contains(x.getLhsType().getName()) - && (!(x.getRhsType() instanceof PlaceholderType) - || ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) { - x.setVariance((byte)1); + if (paraTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)1); } - if (returnTypeVarNames.contains(x.getLhsType().getName()) - && (!(x.getRhsType() instanceof PlaceholderType) - || ((x.getRhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getRhsType().getName()) && !returnTypeVarNames.contains(x.getRhsType().getName())))) { - x.setVariance((byte)-1); + if (returnTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); } } if ((x.getRhsType() instanceof PlaceholderType)) { - if (paraTypeVarNames.contains(x.getRhsType().getName()) - && (!(x.getLhsType() instanceof PlaceholderType) - || ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) { - x.setVariance((byte)1); - } - if (returnTypeVarNames.contains(x.getRhsType().getName()) - && (!(x.getLhsType() instanceof PlaceholderType) - || ((x.getLhsType() instanceof PlaceholderType) && !paraTypeVarNames.contains(x.getLhsType().getName()) && !returnTypeVarNames.contains(x.getLhsType().getName())))) { - x.setVariance((byte)-1); - } + if (paraTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)1); + } + if (returnTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); + } } return x; }).collect(Collectors.toCollection(HashSet::new)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ec383afe2..24f16bc81 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -314,7 +314,17 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("nextSet: " + nextSet.toString()); List> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); Set> result = new HashSet<>(); - byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); + int variance = 0; + Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) + .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) + .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) + .reduce((a,b)-> a*b)) + .filter(d -> d.isPresent()) + .map(e -> e.get()) + .findAny(); + if (xi.isPresent()) { + variance = xi.get(); + } if (variance == 1 && nextSetasList.size() > 1) { List> al = new ArrayList<>(nextSetasList.size()); for (int ii = 0; ii < nextSetasList.size();ii++) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 5aab8784c..d9fd66998 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -37,6 +37,15 @@ public final class PlaceholderType extends UnifyType{ */ private final boolean IsGenerated; + /** + * variance shows the variance of the pair + * -1: contravariant + * 1 covariant + * 0 invariant + * PL 2018-03-21 + */ + private int variance = 0; + /** * Creates a new placeholder type with the specified name. */ @@ -80,6 +89,14 @@ public final class PlaceholderType extends UnifyType{ return IsGenerated; } + public void setVariance(int v) { + variance = v; + } + + public int getVariance() { + return variance; + } + @Override Set smArg(IFiniteClosure fc) { return fc.smArg(this); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 780d05a5f..e57c5e429 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -72,6 +72,7 @@ public class UnifyPair { pairOp = op; unifier = uni; basePair = base; + this.variance = variance; // Caching hashcode From 0b680f831dfd73ffbf10e333fc628d46386c181c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 22 Mar 2018 20:40:22 +0100 Subject: [PATCH 47/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java --- .../typeinference/unify/TypeUnifyTask.java | 24 ++++++++++++++----- .../typeinference/unify/model/UnifyPair.java | 9 ++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 24f16bc81..c848a0682 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -350,7 +350,9 @@ public class TypeUnifyTask extends RecursiveTask>> { a_next = nextSetasList.iterator().next(); } */ - if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D") && nextSetasList.size()>1) + if (!nextSetasList.iterator().hasNext()) + System.out.print(""); + if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a = nextSetasList.remove(0); @@ -388,8 +390,10 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } - + if (!result.isEmpty() && !isUndefinedPairSetSet(result)) { + if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) + System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { while (nextSetasListIt.hasNext()) { @@ -802,10 +806,18 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC)); } - if(allGen) - resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT)); - else - resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT)); + if(allGen) { + UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT); + Iterator upit = up.getRhsType().getTypeParams().iterator(); + while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); + resultPrime.add(up); + } + else { + UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT); + Iterator upit = up.getRhsType().getTypeParams().iterator(); + while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); + resultPrime.add(up); + } resultPrime.addAll(substitutionSet); //writeLog("Substitution: " + substitutionSet.toString()); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index e57c5e429..098ff9465 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -137,7 +137,14 @@ public class UnifyPair { @Override public String toString() { - return "(" + lhs + " " + pairOp + " " + rhs + ", " + variance + ")"; + String ret = ""; + if (lhs instanceof PlaceholderType) { + ret = new Integer(((PlaceholderType)lhs).getVariance()).toString(); + } + if (rhs instanceof PlaceholderType) { + ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString(); + } + return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; } /* From fae26a8f260b9e273b8c14c8c93937ec0ceeb563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 28 Mar 2018 12:06:23 +0200 Subject: [PATCH 48/91] modified: src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java modified: src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java Visitors verallgemeinert --- .../typeinference/unify/freshPlaceholder.java | 42 +++---------------- .../unify/interfaces/UnifyTypeVisitor.java | 12 +++--- .../unify/model/ExtendsType.java | 2 +- .../typeinference/unify/model/FunNType.java | 2 +- .../unify/model/PlaceholderType.java | 2 +- .../unify/model/ReferenceType.java | 2 +- .../typeinference/unify/model/SuperType.java | 2 +- .../typeinference/unify/model/UnifyType.java | 2 +- 8 files changed, 17 insertions(+), 49 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java b/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java index 45ccb6bb4..69870bd57 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java +++ b/src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.java @@ -1,47 +1,15 @@ package de.dhbwstuttgart.typeinference.unify; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; + import java.util.HashMap; -import java.util.stream.Collectors; -import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; -import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; -import de.dhbwstuttgart.typeinference.unify.model.FunNType; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; -import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; -import de.dhbwstuttgart.typeinference.unify.model.SuperType; -import de.dhbwstuttgart.typeinference.unify.model.TypeParams; -public class freshPlaceholder implements UnifyTypeVisitor { - public ReferenceType visit(ReferenceType refty, HashMap ht) { - return new ReferenceType(refty.getName(), - new TypeParams( - Arrays.stream(refty.getTypeParams().get()) - .map(x -> x.accept(this, ht)) - .collect(Collectors.toCollection(ArrayList::new)))); - } - +public class freshPlaceholder extends visitUnifyTypeVisitor> { + + @Override public PlaceholderType visit(PlaceholderType phty, HashMap ht) { return ht.get(phty); - } - - public FunNType visit(FunNType funnty, HashMap ht) { - return FunNType.getFunNType( - new TypeParams( - Arrays.stream(funnty.getTypeParams().get()) - .map(x -> x.accept(this, ht)) - .collect(Collectors.toCollection(ArrayList::new))) - ); - } - - public SuperType visit(SuperType suty, HashMap ht) { - return new SuperType(suty.getWildcardedType().accept(this, ht)); - } - - public ExtendsType visit(ExtendsType extty, HashMap ht) { - return new ExtendsType(extty.getWildcardedType().accept(this, ht)); - } + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java index bf435f9ca..8d06b3e18 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/UnifyTypeVisitor.java @@ -8,16 +8,16 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; import de.dhbwstuttgart.typeinference.unify.model.SuperType; -public interface UnifyTypeVisitor { +public interface UnifyTypeVisitor { - public ReferenceType visit(ReferenceType refty, HashMap ht); + public ReferenceType visit(ReferenceType refty, T ht); - public PlaceholderType visit(PlaceholderType phty, HashMap ht); + public PlaceholderType visit(PlaceholderType phty, T ht); - public FunNType visit(FunNType funnty, HashMap ht); + public FunNType visit(FunNType funnty, T ht); - public SuperType visit(SuperType suty, HashMap ht); + public SuperType visit(SuperType suty, T ht); - public ExtendsType visit(ExtendsType extty, HashMap ht); + public ExtendsType visit(ExtendsType extty, T ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index a97977c5a..a7ff3af83 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -13,7 +13,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public final class ExtendsType extends WildcardType { - public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index dd96dedde..37ec79d5d 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public class FunNType extends UnifyType { - public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index d9fd66998..21e8a66b7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -65,7 +65,7 @@ public final class PlaceholderType extends UnifyType{ IsGenerated = isGenerated; } - public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java index 133a87ed5..81f6c3b34 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java @@ -19,7 +19,7 @@ public final class ReferenceType extends UnifyType { private final int hashCode; - public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index 0b98c1593..53762f868 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; */ public final class SuperType extends WildcardType { - public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht) { + public UnifyType accept(UnifyTypeVisitor visitor, T ht) { return visitor.visit(this, ht); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 16986d65a..555083e8c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -37,7 +37,7 @@ public abstract class UnifyType { } - abstract public UnifyType accept(UnifyTypeVisitor visitor, HashMap ht); + abstract public UnifyType accept(UnifyTypeVisitor visitor, T ht); /** * Returns the name of the type. From 5680f913ef59e8411d5d89689af735a3c1386978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 28 Mar 2018 17:42:25 +0200 Subject: [PATCH 49/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java new file: src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java new file: src/de/dhbwstuttgart/typeinference/unify/visitUnifyTypeVisitor.java --- .../typeinference/unify/TypeUnifyTask.java | 23 ++++++++- .../unify/distributeVariance.java | 19 ++++++++ .../unify/model/PlaceholderType.java | 8 +++- .../unify/visitUnifyTypeVisitor.java | 47 +++++++++++++++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java create mode 100644 src/de/dhbwstuttgart/typeinference/unify/visitUnifyTypeVisitor.java diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index c848a0682..2c2ca6b20 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -312,7 +312,14 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingSets = new ArrayList<>(topLevelSets); Set> nextSet = remainingSets.remove(0); writeLog("nextSet: " + nextSet.toString()); - List> nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); + List> nextSetasList =new ArrayList<>(nextSet); + try { + //List> + nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); + } + catch (java.lang.IllegalArgumentException e) { + System.out.print(""); + } Set> result = new HashSet<>(); int variance = 0; Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) @@ -615,8 +622,20 @@ public class TypeUnifyTask extends RecursiveTask>> { // Init all 8 cases for(int i = 0; i < 8; i++) result.add(new HashSet<>()); + ArrayList eq2sprime = new ArrayList<>(eq2s); + Iterator eq2sprimeit = eq2sprime.iterator(); + ArrayList eq2sAsList = new ArrayList<>(); + while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben + UnifyPair up = eq2sprimeit.next(); + if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0) + || (up.getRhsType() instanceof PlaceholderType && ((PlaceholderType)up.getRhsType()).getVariance() != 0)) { + eq2sAsList.add(up); + eq2s.remove(up); + } + } + eq2sAsList.addAll(eq2s); Boolean first = true; - for(UnifyPair pair : eq2s) { + for(UnifyPair pair : eq2sAsList) { PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); UnifyType rhsType = pair.getRhsType(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java b/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java new file mode 100644 index 000000000..21fffde55 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java @@ -0,0 +1,19 @@ +package de.dhbwstuttgart.typeinference.unify; + +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; + +public class distributeVariance extends visitUnifyTypeVisitor { + + @Override + public PlaceholderType visit(PlaceholderType phty, Integer ht) { + if (ht != 0) { + if (phty.getVariance() == 0) { + phty.setVariance(ht); + } + else if (phty.getVariance() != ht) { + phty.setVariance(0); + } + } + return phty; + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 21e8a66b7..8d9b62df9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.Random; import java.util.Set; +import de.dhbwstuttgart.typeinference.unify.distributeVariance; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; @@ -119,8 +120,11 @@ public final class PlaceholderType extends UnifyType{ @Override UnifyType apply(Unifier unif) { - if(unif.hasSubstitute(this)) - return unif.getSubstitute(this); + if(unif.hasSubstitute(this)) { + UnifyType ret = unif.getSubstitute(this); + ret.accept(new distributeVariance(), this.getVariance()); + return ret; + } return this; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/visitUnifyTypeVisitor.java b/src/de/dhbwstuttgart/typeinference/unify/visitUnifyTypeVisitor.java new file mode 100644 index 000000000..9ea3dc598 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/visitUnifyTypeVisitor.java @@ -0,0 +1,47 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.HashMap; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor; +import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; +import de.dhbwstuttgart.typeinference.unify.model.SuperType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; + +public class visitUnifyTypeVisitor implements UnifyTypeVisitor { + + public ReferenceType visit(ReferenceType refty, T ht) { + return new ReferenceType(refty.getName(), + new TypeParams( + Arrays.stream(refty.getTypeParams().get()) + .map(x -> x.accept(this, ht)) + .collect(Collectors.toCollection(ArrayList::new)))); + } + + public PlaceholderType visit(PlaceholderType phty, T ht) { + return phty; + } + + public FunNType visit(FunNType funnty, T ht) { + return FunNType.getFunNType( + new TypeParams( + Arrays.stream(funnty.getTypeParams().get()) + .map(x -> x.accept(this, ht)) + .collect(Collectors.toCollection(ArrayList::new))) + ); + } + + public SuperType visit(SuperType suty, T ht) { + return new SuperType(suty.getWildcardedType().accept(this, ht)); + } + + public ExtendsType visit(ExtendsType extty, T ht) { + return new ExtendsType(extty.getWildcardedType().accept(this, ht)); + } +} From 117106a7b35f391b0ae90891feb543638f877272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 1 Apr 2018 17:07:58 +0200 Subject: [PATCH 50/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java ? ext theta bei smaller eingefuegt modified: src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java basiPair und Subsitution nur noch gefuegt, wen wirk etwas eingesetzt wurde modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java unifier umbenannt in substitution getBasePair und getSubsitutuon eingefuegt --- .../typeinference/unify/TypeUnifyTask.java | 12 +++++++++++- .../typeinference/unify/model/Unifier.java | 7 ++++++- .../typeinference/unify/model/UnifyPair.java | 16 +++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 2c2ca6b20..81c6da3a5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -315,7 +315,7 @@ public class TypeUnifyTask extends RecursiveTask>> { List> nextSetasList =new ArrayList<>(nextSet); try { //List> - nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); + //nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); } catch (java.lang.IllegalArgumentException e) { System.out.print(""); @@ -815,6 +815,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { Set smaller = fc.smaller(unifier.apply(tq)); + //eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen + Set smaller_ext = smaller.stream() + .map(x -> { + BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; + HashMap hm = x.getInvolvedPlaceholderTypes().stream() + .reduce(new HashMap(), + (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return new ExtendsType (x.accept(new freshPlaceholder(), hm));}).collect(Collectors.toCollection(HashSet::new)); + smaller.addAll(smaller_ext); + //eingefuegt PL 2018-03-29 Ende ? ext. theta hinzufuegen for(UnifyType theta : smaller) { List freshTphs = new ArrayList<>(); Set resultPrime = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 7b32864d8..1ee05264e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -63,7 +63,12 @@ public class Unifier implements Function, Iterable Date: Sun, 1 Apr 2018 22:04:10 +0200 Subject: [PATCH 51/91] modified: src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Substututions die eine UnifyPair erzeugen eingefuegt UnifyCase1-8 weitermachen --- .../unify/MartelliMontanariUnify.java | 3 +- .../typeinference/unify/RuleSet.java | 68 +++++++++---------- .../typeinference/unify/TypeUnifyTask.java | 35 +++++++--- .../unify/model/OrderingUnifyPair.java | 8 +-- .../typeinference/unify/model/Unifier.java | 9 ++- .../typeinference/unify/model/UnifyPair.java | 9 ++- 6 files changed, 78 insertions(+), 54 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java b/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java index 1c75ea99e..aa5f6ddd6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java @@ -94,7 +94,8 @@ public class MartelliMontanariUnify implements IUnify { // SUBST - Rule if(lhsType instanceof PlaceholderType) { mgu.add((PlaceholderType) lhsType, rhsType); - termsList = termsList.stream().map(mgu::apply).collect(Collectors.toCollection(ArrayList::new)); + //PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen. + termsList = termsList.stream().map(x -> mgu.apply(new HashSet<>(), x)).collect(Collectors.toCollection(ArrayList::new)); idx = idx+1 == termsList.size() ? 0 : idx+1; continue; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 660ab38c9..62473eff7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -60,7 +60,7 @@ public class RuleSet implements IRuleSet{ return Optional.empty(); // Rule is applicable, unpack the SuperType - return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT)); + return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -78,7 +78,7 @@ public class RuleSet implements IRuleSet{ return Optional.empty(); // Rule is applicable, unpack the ExtendsType - return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT)); + return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -96,7 +96,7 @@ public class RuleSet implements IRuleSet{ return Optional.empty(); // Rule is applicable, unpack both sides - return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT)); + return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -146,7 +146,7 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet<>(); for(int rhsIdx = 0; rhsIdx < extYParams.size(); rhsIdx++) - result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC)); + result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -197,7 +197,7 @@ public class RuleSet implements IRuleSet{ return Optional.empty(); for(int rhsIdx = 0; rhsIdx < supYParams.size(); rhsIdx++) - result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC)); + result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -228,7 +228,7 @@ public class RuleSet implements IRuleSet{ TypeParams rhsTypeParams = rhsType.getTypeParams(); for(int i = 0; i < lhsTypeParams.size(); i++) - result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT)); + result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -269,7 +269,7 @@ public class RuleSet implements IRuleSet{ TypeParams rhsTypeParams = d.getTypeParams(); TypeParams lhsTypeParams = c.getTypeParams(); for(int rhsIdx = 0; rhsIdx < c.getTypeParams().size(); rhsIdx++) - result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC)); + result.add(new UnifyPair(lhsTypeParams.get(rhsIdx), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -306,7 +306,7 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet<>(); for(int rhsIdx = 0; rhsIdx < rhsTypeParams.size(); rhsIdx++) - result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC)); + result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -361,7 +361,7 @@ public class RuleSet implements IRuleSet{ TypeParams rhsTypeParams = rhsSType.getTypeParams(); TypeParams lhsTypeParams = lhsSType.getTypeParams(); for(int i = 0; i < rhsTypeParams.size(); i++) - result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT)); + result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -412,7 +412,7 @@ public class RuleSet implements IRuleSet{ if(!(pair.getRhsType() instanceof PlaceholderType)) return Optional.empty(); - return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT)); + return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -466,7 +466,7 @@ public class RuleSet implements IRuleSet{ unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); else System.out.println("ERROR"); } - return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT)); + return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -512,7 +512,7 @@ public class RuleSet implements IRuleSet{ for(int i = 1; i < typeDParams.size(); i++) unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); - return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC)); + return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -564,7 +564,7 @@ public class RuleSet implements IRuleSet{ for(int i = 1; i < typeDParams.size(); i++) unif.add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i)); - return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC)); + return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); } /** @@ -636,8 +636,8 @@ public class RuleSet implements IRuleSet{ && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. && !rhsType.getTypeParams().occurs(lhsType)) { Unifier uni = new Unifier(lhsType, rhsType); - result = result.stream().map(uni::apply).collect(Collectors.toCollection(ArrayList::new)); - result1 = result1.stream().map(uni::apply).collect(Collectors.toCollection(LinkedList::new)); + result = result.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(ArrayList::new)); + result1 = result1.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(LinkedList::new)); applied = true; } @@ -657,7 +657,7 @@ public class RuleSet implements IRuleSet{ if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType)) return Optional.empty(); - return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT)); + return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -670,7 +670,7 @@ public class RuleSet implements IRuleSet{ if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType)) return Optional.empty(); - return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT)); + return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -683,7 +683,7 @@ public class RuleSet implements IRuleSet{ if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType)) return Optional.empty(); - return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT)); + return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -696,7 +696,7 @@ public class RuleSet implements IRuleSet{ if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType)) return Optional.empty(); - return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC)); + return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); } /* PL 2018-03-06 auskommentiert sind mutmaßlich falsch @@ -767,9 +767,9 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet(); - result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT)); + result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); for(int i = 1; i < funNLhsType.getTypeParams().size(); i++) - result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT)); + result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -793,10 +793,10 @@ public class RuleSet implements IRuleSet{ for(int i = 0; i < freshPlaceholders.length; i++) freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), freshPlaceholders[0], PairOperator.SMALLERDOT)); + result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), freshPlaceholders[0], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); for(int i = 1; i < funNLhsType.getTypeParams().size(); i++) - result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT)); - result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT)); + result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -820,10 +820,10 @@ public class RuleSet implements IRuleSet{ for(int i = 0; i < freshPlaceholders.length; i++) freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(freshPlaceholders[0], funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT)); + result.add(new UnifyPair(freshPlaceholders[0], funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); for(int i = 1; i < funNRhsType.getTypeParams().size(); i++) - result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT)); - result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT)); + result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); } @@ -838,7 +838,7 @@ public class RuleSet implements IRuleSet{ if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType)) return Optional.empty(); - return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT)); + return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); } @Override @@ -857,11 +857,11 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet<>(); if(isGen) - result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT)); + result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); else { UnifyType freshTph = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT)); - result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT)); + result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); } return Optional.of(result); @@ -883,11 +883,11 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet<>(); if(isGen) - result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT)); + result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); else { UnifyType freshTph = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT)); - result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT)); + 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())); } return Optional.of(result); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 81c6da3a5..c988d35fd 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -644,7 +644,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); - Set> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), pair.getVariance(), fc); + Set> x1 = unifyCase1(pair, fc); //System.out.println(x1); result.get(0).add(x1); } @@ -660,7 +660,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), pair.getVariance(), fc)); + result.get(1).add(unifyCase2(pair, fc)); } else { Set s1 = new HashSet<>(); @@ -673,7 +673,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, pair.getVariance(), fc)); + result.get(2).add(unifyCase3(pair, fc)); } else { Set s1 = new HashSet<>(); @@ -693,7 +693,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (first) { //writeLog(pair.toString()+"\n"); if (rhsType.getName().equals("A")) System.out.println(); - result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); + result.get(4).add(unifyCase5(pair, fc)); } else { Set s1 = new HashSet<>(); @@ -717,7 +717,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); result.get(7).add( - unifyCase8(lhsType, (PlaceholderType) rhsType, pair.getVariance(), fc)); + unifyCase8(pair, fc)); } else { Set s1 = new HashSet<>(); @@ -745,7 +745,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian product Case 1: (a <. Theta') */ - protected Set> unifyCase1(PlaceholderType a, UnifyType thetaPrime, byte variance, IFiniteClosure fc) { + protected Set> unifyCase1(UnifyPair pair, IFiniteClosure fc) { + PlaceholderType a = (PlaceholderType)pair.getLhsType(); + UnifyType thetaPrime = pair.getRhsType(); + byte variance = pair.getVariance(); if (a.getName().equals("D")) { System.out.print(""); } @@ -865,7 +868,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 2: (a <.? ? ext Theta') */ - private Set> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, byte variance, IFiniteClosure fc) { + private Set> unifyCase2(UnifyPair pair, IFiniteClosure fc) { + PlaceholderType a = (PlaceholderType) pair.getLhsType(); + ExtendsType extThetaPrime = (ExtendsType) pair.getRhsType(); + byte variance = pair.getVariance(); Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); @@ -887,7 +893,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 3: (a <.? ? sup Theta') */ - private Set> unifyCase3(PlaceholderType a, SuperType subThetaPrime, byte variance, IFiniteClosure fc) { + private Set> unifyCase3(UnifyPair pair, IFiniteClosure fc) { + PlaceholderType a = (PlaceholderType) pair.getLhsType(); + SuperType subThetaPrime = (SuperType) pair.getRhsType(); + byte variance = pair.getVariance(); Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); @@ -911,7 +920,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 5: (Theta <. a) */ - private Set> unifyCase5(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) { + private Set> unifyCase5(UnifyPair pair, IFiniteClosure fc) { + UnifyType theta = pair.getLhsType(); + PlaceholderType a = (PlaceholderType) pair.getRhsType(); + byte variance = pair.getVariance(); Set> result = new HashSet<>(); boolean allGen = theta.getTypeParams().size() > 0; @@ -945,7 +957,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 8: (Theta <.? a) */ - private Set> unifyCase8(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) { + private Set> unifyCase8(UnifyPair pair, IFiniteClosure fc) { + UnifyType theta = pair.getLhsType(); + PlaceholderType a = (PlaceholderType) pair.getRhsType(); + byte variance = pair.getVariance(); Set> result = new HashSet<>(); //for(UnifyType thetaS : fc.grArg(theta)) { Set resultPrime = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 129433056..e98966679 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -151,8 +151,8 @@ public class OrderingUnifyPair extends Ordering> { if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName()) || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); else { - Set lsleuni = leftlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); - Set rsleuni = rightlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new)); + Set lsleuni = leftlewc.stream().map(x -> uni.apply(new HashSet<>(),x)).collect(Collectors.toCollection(HashSet::new)); + Set rsleuni = rightlewc.stream().map(x -> uni.apply(new HashSet<>(),x)).collect(Collectors.toCollection(HashSet::new)); BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; HashMap hm; @@ -183,7 +183,7 @@ public class OrderingUnifyPair extends Ordering> { } Unifier uni = new Unifier(); subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - lseq = uni.apply(lseq); + lseq = uni.apply(new HashSet<>(), lseq); } else { Set subst; @@ -195,7 +195,7 @@ public class OrderingUnifyPair extends Ordering> { } Unifier uni = new Unifier(); subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - rseq = uni.apply(rseq); + rseq = uni.apply(new HashSet<>(), rseq); } return compareEq(lseq, rseq); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 1ee05264e..d9b31e243 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -1,8 +1,10 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map.Entry; +import java.util.Set; import java.util.function.Function; /** @@ -62,11 +64,14 @@ public class Unifier implements Function, Iterable suniSubstitution, UnifyPair p) { UnifyType newLhs = this.apply(p.getLhsType()); UnifyType newRhs = this.apply(p.getRhsType()); if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwedung von this hat was veraendert PL 2018-04-01 - return new UnifyPair(newLhs, newRhs, p.getPairOp(), this, p); + Set suniUnifyPair = new HashSet<>(); + suniUnifyPair.addAll(suniSubstitution); + suniUnifyPair.add(this); + return new UnifyPair(newLhs, newRhs, p.getPairOp(), suniUnifyPair, p); } return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair()); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 173b5f8cf..11d11ba1d 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -2,7 +2,9 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** @@ -41,7 +43,7 @@ public class UnifyPair { * Unifier/substitute that generated this pair * PL 2018-03-15 */ - private Unifier substitution; + private Set substitution; /** * Base on which the the unifier is applied @@ -61,12 +63,13 @@ public class UnifyPair { this.lhs = lhs; this.rhs = rhs; pairOp = op; + substitution = new HashSet<>(); // Caching hashcode hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); } - public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Unifier uni, UnifyPair base) { + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base) { this.lhs = lhs; this.rhs = rhs; pairOp = op; @@ -111,7 +114,7 @@ public class UnifyPair { public void setUndefinedPair() { undefinedPair = true; } - public Unifier getSubstitution() { + public Set getSubstitution() { return substitution; } From c271c689de3b3f0703298dcfefb84919619b61d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 3 Apr 2018 10:29:58 +0200 Subject: [PATCH 52/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java abhaengige Substitutionen auch bei Faellen 1 - 8 eingefuegt --- .../typeinference/unify/TypeUnifyTask.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index c988d35fd..e932de0dc 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -813,7 +813,7 @@ public class TypeUnifyTask extends RecursiveTask>> { unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); for (Entry sigma : unifier) { - substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT)); + substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { @@ -835,17 +835,17 @@ public class TypeUnifyTask extends RecursiveTask>> { for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { if(freshTphs.size()-1 < i) freshTphs.add(PlaceholderType.freshPlaceholder()); - resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC)); + resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); } if(allGen) { - UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT); + UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()); Iterator upit = up.getRhsType().getTypeParams().iterator(); while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } else { - UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT); + UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()); Iterator upit = up.getRhsType().getTypeParams().iterator(); while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); @@ -878,12 +878,12 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType extAPrime = new ExtendsType(aPrime); UnifyType thetaPrime = extThetaPrime.getExtendedType(); Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT)); + resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); result.add(resultPrime); resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT)); - resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT)); + resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog("Result: " + resultPrime.toString()); @@ -903,13 +903,13 @@ 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)); + resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); 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)); + resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); @@ -939,13 +939,13 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); - resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC)); + resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); } if(allGen) - resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT)); + resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); else - resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT)); + resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); @@ -964,20 +964,20 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> result = new HashSet<>(); //for(UnifyType thetaS : fc.grArg(theta)) { Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT)); + resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); 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)); + resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); 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)); + resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); From 9717c54d538d2480152a104c23a8ed1c6ddbbb88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 3 Apr 2018 14:16:38 +0200 Subject: [PATCH 53/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Mehrfacher Aufruf von computeCartesianRecursive entfernt --- .../typeinference/unify/TypeUnifyTask.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index e932de0dc..8fe9e4771 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -161,7 +161,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("UndefinedPairs; " + undefinedPairs); Set> error = new HashSet<>(); undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); - //error.add(undefinedPairs); + error.add(undefinedPairs); return error; } @@ -309,7 +309,14 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { - ArrayList>> remainingSets = new ArrayList<>(topLevelSets); + //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); + fstElems.addAll(topLevelSets.stream() + .filter(x -> x.size()==1) + .map(y -> y.stream().findFirst().get()) + .collect(Collectors.toCollection(HashSet::new))); + ArrayList>> remainingSets = topLevelSets.stream() + .filter(x -> x.size()>1) + .collect(Collectors.toCollection(ArrayList::new)); Set> nextSet = remainingSets.remove(0); writeLog("nextSet: " + nextSet.toString()); List> nextSetasList =new ArrayList<>(nextSet); @@ -394,7 +401,7 @@ public class TypeUnifyTask extends RecursiveTask>> { result.addAll(unify2(elems, eq, fc, parallel)); System.out.println(""); } - else { + else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } From 52f480147ec54e2d97826fbaf841ae407b36b1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 4 Apr 2018 01:14:30 +0200 Subject: [PATCH 54/91] modified: src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Subsitution auf UnifyPair umgestellt --- .../unify/MartelliMontanariUnify.java | 2 +- .../typeinference/unify/RuleSet.java | 4 ++-- .../unify/model/OrderingUnifyPair.java | 8 +++---- .../typeinference/unify/model/Unifier.java | 23 +++++++++++++++---- .../typeinference/unify/model/UnifyPair.java | 14 ++++++++--- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java b/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java index aa5f6ddd6..087b89430 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java @@ -95,7 +95,7 @@ public class MartelliMontanariUnify implements IUnify { if(lhsType instanceof PlaceholderType) { mgu.add((PlaceholderType) lhsType, rhsType); //PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen. - termsList = termsList.stream().map(x -> mgu.apply(new HashSet<>(), x)).collect(Collectors.toCollection(ArrayList::new)); + termsList = termsList.stream().map(x -> mgu.apply(x)).collect(Collectors.toCollection(ArrayList::new)); idx = idx+1 == termsList.size() ? 0 : idx+1; continue; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 62473eff7..0d77d48fe 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -636,8 +636,8 @@ public class RuleSet implements IRuleSet{ && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. && !rhsType.getTypeParams().occurs(lhsType)) { Unifier uni = new Unifier(lhsType, rhsType); - result = result.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(ArrayList::new)); - result1 = result1.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(LinkedList::new)); + result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); + result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); applied = true; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index e98966679..505c3c2b1 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -151,8 +151,8 @@ public class OrderingUnifyPair extends Ordering> { if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName()) || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey(); else { - Set lsleuni = leftlewc.stream().map(x -> uni.apply(new HashSet<>(),x)).collect(Collectors.toCollection(HashSet::new)); - Set rsleuni = rightlewc.stream().map(x -> uni.apply(new HashSet<>(),x)).collect(Collectors.toCollection(HashSet::new)); + Set lsleuni = leftlewc.stream().map(x -> uni.apply(x)).collect(Collectors.toCollection(HashSet::new)); + Set rsleuni = rightlewc.stream().map(x -> uni.apply(x)).collect(Collectors.toCollection(HashSet::new)); BinaryOperator> combiner = (x,y) -> { x.putAll(y); return x;}; HashMap hm; @@ -183,7 +183,7 @@ public class OrderingUnifyPair extends Ordering> { } Unifier uni = new Unifier(); subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - lseq = uni.apply(new HashSet<>(), lseq); + lseq = uni.apply(lseq); } else { Set subst; @@ -195,7 +195,7 @@ public class OrderingUnifyPair extends Ordering> { } Unifier uni = new Unifier(); subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); - rseq = uni.apply(new HashSet<>(), rseq); + rseq = uni.apply(rseq); } return compareEq(lseq, rseq); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index d9b31e243..cbe0053f7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -64,13 +64,26 @@ public class Unifier implements Function, Iterable suniSubstitution, UnifyPair p) { + public UnifyPair apply(UnifyPair p) { UnifyType newLhs = this.apply(p.getLhsType()); UnifyType newRhs = this.apply(p.getRhsType()); - if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwedung von this hat was veraendert PL 2018-04-01 - Set suniUnifyPair = new HashSet<>(); - suniUnifyPair.addAll(suniSubstitution); - suniUnifyPair.add(this); + return new UnifyPair(newLhs, newRhs, p.getPairOp()); + } + + /** + * Applies the unifier to the two terms of the pair. + * @return A new pair where the left and right-hand side are applied + */ + public UnifyPair apply(UnifyPair thisAsPair, UnifyPair p) { + UnifyType newLhs = this.apply(p.getLhsType()); + UnifyType newRhs = this.apply(p.getRhsType()); + if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwendung von this hat was veraendert PL 2018-04-01 + Set suniUnifyPair = new HashSet<>(); + suniUnifyPair.addAll(thisAsPair.getSubstitution()); + suniUnifyPair.add(thisAsPair); + if (p.getLhsType() instanceof PlaceholderType && newLhs instanceof PlaceholderType && p.getPairOp() == PairOperator.EQUALSDOT) { + suniUnifyPair.add(p); //p koennte auch subsitution sein + } return new UnifyPair(newLhs, newRhs, p.getPairOp(), suniUnifyPair, p); } return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair()); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 11d11ba1d..8f1c6d579 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -43,7 +43,7 @@ public class UnifyPair { * Unifier/substitute that generated this pair * PL 2018-03-15 */ - private Set substitution; + private Set substitution; /** * Base on which the the unifier is applied @@ -69,7 +69,7 @@ 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) { + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base) { this.lhs = lhs; this.rhs = rhs; pairOp = op; @@ -114,7 +114,7 @@ public class UnifyPair { public void setUndefinedPair() { undefinedPair = true; } - public Set getSubstitution() { + public Set getSubstitution() { return substitution; } @@ -124,6 +124,14 @@ public class UnifyPair { public boolean isUndefinedPair() { return undefinedPair; } + + Set getAllSubstitutions () { + Set ret = new HashSet<>(); + ret.addAll(getSubstitution()); + + return ret; + } + @Override public boolean equals(Object obj) { if(!(obj instanceof UnifyPair)) From 1baaf79f8c53e6806ecc3910e0a4e57e7f8c6724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 4 Apr 2018 21:47:07 +0200 Subject: [PATCH 55/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java UndefPairs werden zurueckgegegeben und die naechsten gefiltert protected boolean isUndefinedPairSet(Set s) hat Fehler --- .../typeinference/unify/TypeUnifyTask.java | 29 ++++++++++++++++++- .../typeinference/unify/model/UnifyPair.java | 6 ++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8fe9e4771..06783d9c9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -317,6 +317,10 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingSets = topLevelSets.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); + if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig + Set> result = unify2(fstElems, eq, fc, parallel); + return result; + } Set> nextSet = remainingSets.remove(0); writeLog("nextSet: " + nextSet.toString()); List> nextSetasList =new ArrayList<>(nextSet); @@ -432,9 +436,32 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } + if (isUndefinedPairSetSet(result)) { + Set abhSubst = result.stream().findFirst() + .get() + .stream() + .map(x -> x.getAllSubstitutions()) + .reduce((y,z) -> { y.addAll(z); return y;}).get(); + Set durchschnitt = abhSubst.stream() + .filter(x -> a.contains(x)) + .filter(y -> abhSubst.contains(y)) + .collect(Collectors.toCollection(HashSet::new)); + Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + nextSetasList = nextSetasList.stream().filter(x -> { + //Boolean ret = false; + //for (PlaceholderType var : vars) { + // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); + //} + return (!x.containsAll(durchschnitt)); + }).collect(Collectors.toCollection(ArrayList::new)); + System.out.println(""); + } if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { return result; } + else { + result.removeIf(y -> isUndefinedPairSet(y)); + } //else result.stream().filter(y -> !isUndefinedPairSet(y)); } return result; @@ -442,7 +469,7 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean isUndefinedPairSet(Set s) { - + Falsch! Optional res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y)); if (res.isPresent()) { return res.get(); } else { return false; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 8f1c6d579..b3d0c85a9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -125,10 +125,12 @@ public class UnifyPair { return undefinedPair; } - Set getAllSubstitutions () { + public Set getAllSubstitutions () { Set ret = new HashSet<>(); ret.addAll(getSubstitution()); - + if (basePair != null) { + ret.addAll(basePair.getAllSubstitutions()); + } return ret; } From baee0024e9b1670b7c15e978bad160042601a4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 5 Apr 2018 18:09:24 +0200 Subject: [PATCH 56/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Zu beginn von unify werden doppelte wildcard konstruktionen entfernt Variableneumbenennung bei smaller in Fall 1 weider entfernt modified: ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java In computeGreater unify durch match ersetzt modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java Abfrage ob eine doppelte wildcard konstruktion vorhanden ist eingefuegt --- .../typeinference/unify/TypeUnifyTask.java | 39 ++++++++++++------- .../unify/interfaces/IMatch.java | 16 +++----- .../unify/interfaces/IUnify.java | 8 ++-- .../unify/model/ExtendsType.java | 5 ++- .../unify/model/FiniteClosure.java | 14 +++++-- .../unify/model/OrderingUnifyPair.java | 6 +-- .../typeinference/unify/model/UnifyPair.java | 4 ++ .../typeinference/unify/model/UnifyType.java | 4 ++ .../unify/model/WildcardType.java | 5 +++ 9 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 06783d9c9..3435edd3e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -104,6 +104,19 @@ public class TypeUnifyTask extends RecursiveTask>> { */ writeLog("Unifikation: " + eq.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); + + /* + * ? extends ? extends Theta rausfiltern + */ + Set doubleExt = eq.stream().filter(x -> (x.doubleExtended())).map(x -> { x.setUndefinedPair(); return x;}) + .collect(Collectors.toCollection(HashSet::new)); + if (doubleExt.size() > 0) { + Set> ret = new HashSet<>(); + ret.add(doubleExt); + return ret; + } + + Set eq0 = applyTypeUnificationRules(eq, fc); /* @@ -301,7 +314,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 7: Filter empty sets; */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); - if (!eqPrimePrimeSet.isEmpty()) + if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) writeLog("Result " + eqPrimePrimeSet.toString()); return eqPrimePrimeSet; } @@ -469,17 +482,14 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean isUndefinedPairSet(Set s) { - Falsch! - Optional res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y)); - if (res.isPresent()) { return res.get(); } - else { return false; } + Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y)); + return ret; } protected boolean isUndefinedPairSetSet(Set> s) { if (s.size() ==1) { - Optional res = s.stream().map(x -> isUndefinedPairSet(x)).reduce((x,y)-> (x == y)); - if (res.isPresent()) { return res.get(); } - else { return false; } + Boolean ret = isUndefinedPairSet(s.stream().findFirst().get()); + return ret; } return false; @@ -853,13 +863,14 @@ public class TypeUnifyTask extends RecursiveTask>> { for (UnifyType tq : thetaQs) { Set smaller = fc.smaller(unifier.apply(tq)); //eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen - Set smaller_ext = smaller.stream() + Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) .map(x -> { - BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; - HashMap hm = x.getInvolvedPlaceholderTypes().stream() - .reduce(new HashMap(), - (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); - return new ExtendsType (x.accept(new freshPlaceholder(), hm));}).collect(Collectors.toCollection(HashSet::new)); + //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() + // .reduce(new HashMap(), + // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));} + .collect(Collectors.toCollection(HashSet::new)); smaller.addAll(smaller_ext); //eingefuegt PL 2018-03-29 Ende ? ext. theta hinzufuegen for(UnifyType theta : smaller) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java index 5e201dd7a..ab88f33b7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java @@ -13,23 +13,17 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; /** * Match * @author Martin Pluemicke + * abgeleitet aus IUnify.java */ public interface IMatch { /** - * Finds the most general unifier sigma of the set {t1,...,tn} so that - * sigma(t1) = sigma(t2) = ... = sigma(tn). - * @param terms The set of terms to be unified - * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. + * Finds the most general matcher sigma of the set {t1 =. t1',...,tn =. tn'} so that + * sigma(t1) = t1' , ... sigma(tn) = tn'. + * @param terms The set of terms to be matched + * @return An optional of the most general matcher if it exists or an empty optional if there is no matcher. */ public Optional match(ArrayList termsList); - - /** - * Finds the most general unifier sigma of the set {t1,...,tn} so that - * sigma(t1) = sigma(t2) = ... = sigma(tn). - * @param terms The set of terms to be unified - * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. - */ } diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java index 524608f5c..57b417362 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java @@ -15,16 +15,16 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier; public interface IUnify { /** - * Finds the most general unifier sigma of the set {t1,...,tn} so that - * sigma(t1) = sigma(t2) = ... = sigma(tn). + * Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that + * sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn'). * @param terms The set of terms to be unified * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. */ public Optional unify(Set terms); /** - * Finds the most general unifier sigma of the set {t1,...,tn} so that - * sigma(t1) = sigma(t2) = ... = sigma(tn). + * Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that + * sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn'). * @param terms The set of terms to be unified * @return An optional of the most general unifier if it exists or an empty optional if there is no unifier. */ diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index a7ff3af83..6c44d2ec6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -22,7 +22,10 @@ public final class ExtendsType extends WildcardType { * @param extendedType The extended type e.g. Integer in "? extends Integer" */ public ExtendsType(UnifyType extendedType) { - super("? extends " + extendedType.getName(), extendedType); + super("? extends " + extendedType.getName(), extendedType); + if (extendedType instanceof ExtendsType) { + System.out.print(""); + } } /** diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 2e4e7bc3d..4aa4ffb89 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -10,8 +10,8 @@ import java.util.stream.Collectors; import com.google.common.collect.Ordering; -//PL 18-02-05 Unifier durch Matcher ersetzt -//mus greater noch erstezt werden +//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt +//muss greater noch ersetzt werden ja erledigt 18--04-05 import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify; import de.dhbwstuttgart.typeinference.unify.Match; @@ -196,7 +196,9 @@ public class FiniteClosure extends Ordering implements IFiniteClosure protected Set computeGreater(Set types) { HashSet result = new HashSet<>(); - IUnify unify = new MartelliMontanariUnify(); + //PL 18-04-05 Unifier durch Matcher ersetzt + //IUnify unify = new MartelliMontanariUnify(); + Match match = new Match(); for(UnifyType t : types) { @@ -218,7 +220,11 @@ public class FiniteClosure extends Ordering implements IFiniteClosure Set> candidates = strInheritanceGraph.get(t.getName()); for(Node candidate : candidates) { UnifyType theta1 = candidate.getContent(); - Optional optSigma = unify.unify(theta1, t); + //PL 18-04-05 Unifier durch Matcher ersetzt ANFANG + ArrayList termList= new ArrayList(); + termList.add(new UnifyPair(theta1,t, PairOperator.EQUALSDOT)); + Optional optSigma = match.match(termList); + //PL 18-04-05 Unifier durch Matcher ersetzt ENDE if(!optSigma.isPresent()) continue; diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 505c3c2b1..9a018fb08 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -97,9 +97,9 @@ public class OrderingUnifyPair extends Ordering> { .collect(Collectors.toCollection(HashSet::new)); //System.out.println(left.toString()); //Fall 2 und 3 - if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) { - System.out.print(""); - } + //if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) { + // System.out.print(""); + //} if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { return 1; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index b3d0c85a9..dd24c28dc 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -134,6 +134,10 @@ public class UnifyPair { return ret; } + public Boolean doubleExtended() { + return lhs.doubleExtended() || rhs.doubleExtended(); + } + @Override public boolean equals(Object obj) { if(!(obj instanceof UnifyPair)) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 555083e8c..5beef2bf4 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -102,6 +102,10 @@ public abstract class UnifyType { ret.addAll(typeParams.getInvolvedPlaceholderTypes()); return ret; } + + public Boolean doubleExtended() {//default + return false; + } @Override public int hashCode() { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java index 2bc514601..e320bb9f1 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java @@ -40,6 +40,11 @@ public abstract class WildcardType extends UnifyType { return wildcardedType.getTypeParams(); } + @Override + public Boolean doubleExtended () {//This is an error + return (wildcardedType instanceof WildcardType); + } + @Override public int hashCode() { return wildcardedType.hashCode() + getName().hashCode() + 17; From 603c4c9c460643ea4ffb2089aa0e9eb56d8e42be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 6 Apr 2018 20:01:14 +0200 Subject: [PATCH 57/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java logging ergaenzt modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java getSubstitution() durch getAllSubstitutions() ersetzt --- .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 9 ++++++++- .../dhbwstuttgart/typeinference/unify/model/Unifier.java | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 3435edd3e..70db967aa 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -171,7 +171,10 @@ public class TypeUnifyTask extends RecursiveTask>> { // 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()) { - writeLog("UndefinedPairs; " + undefinedPairs); + for (UnifyPair up : undefinedPairs) { + writeLog("UndefinedPairs; " + up); + writeLog("BasePair; " + up.getBasePair()); + } Set> error = new HashSet<>(); undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); error.add(undefinedPairs); @@ -467,6 +470,10 @@ public class TypeUnifyTask extends RecursiveTask>> { //} return (!x.containsAll(durchschnitt)); }).collect(Collectors.toCollection(ArrayList::new)); + writeLog("abhSubst: " + abhSubst.toString()); + writeLog("nextSet: " + nextSet.toString()); + writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Durchschnitt: " + durchschnitt.toString()); System.out.println(""); } if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index cbe0053f7..8aa03a773 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -79,7 +79,7 @@ public class Unifier implements Function, Iterable suniUnifyPair = new HashSet<>(); - suniUnifyPair.addAll(thisAsPair.getSubstitution()); + suniUnifyPair.addAll(thisAsPair.getAllSubstitutions()); suniUnifyPair.add(thisAsPair); if (p.getLhsType() instanceof PlaceholderType && newLhs instanceof PlaceholderType && p.getPairOp() == PairOperator.EQUALSDOT) { suniUnifyPair.add(p); //p koennte auch subsitution sein From fef4d27d2130be251e880a98d254061fbdbd9523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 11 Apr 2018 11:10:08 +0200 Subject: [PATCH 58/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 70db967aa..c0fc93acf 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -453,14 +453,15 @@ public class TypeUnifyTask extends RecursiveTask>> { } } if (isUndefinedPairSetSet(result)) { - Set abhSubst = result.stream().findFirst() - .get() - .stream() + Set abhSubst = result.stream() + .map(b -> + b.stream() .map(x -> x.getAllSubstitutions()) + .reduce((y,z) -> { y.addAll(z); return y;}).get()) .reduce((y,z) -> { y.addAll(z); return y;}).get(); Set durchschnitt = abhSubst.stream() .filter(x -> a.contains(x)) - .filter(y -> abhSubst.contains(y)) + //.filter(y -> abhSubst.contains(y)) .collect(Collectors.toCollection(HashSet::new)); Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); nextSetasList = nextSetasList.stream().filter(x -> { From 21bc2a67a1b3eee6b9a1cf4a7c015947b2b6ef50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 11 Apr 2018 16:58:38 +0200 Subject: [PATCH 59/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../typeinference/unify/TypeUnifyTask.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index c0fc93acf..a66c4626e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -418,8 +418,11 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> elems = new HashSet>(fstElems); elems.add(a); if (remainingSets.isEmpty()) { - result.addAll(unify2(elems, eq, fc, parallel)); - System.out.println(""); + Set> res = unify2(elems, eq, fc, parallel); + if (!isUndefinedPairSetSet(res)) {// && isUndefinedPairSetSet(result)) {//wenn korektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = new HashSet<>(); + } + result.addAll(res); } else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); @@ -477,12 +480,12 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Durchschnitt: " + durchschnitt.toString()); System.out.println(""); } - if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { - return result; - } - else { - result.removeIf(y -> isUndefinedPairSet(y)); - } + //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { + // return result; + //} + //else { + // result.removeIf(y -> isUndefinedPairSet(y)); + //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); } return result; @@ -495,8 +498,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } protected boolean isUndefinedPairSetSet(Set> s) { - if (s.size() ==1) { - Boolean ret = isUndefinedPairSet(s.stream().findFirst().get()); + if (s.size() >= 1) { + Boolean ret = s.stream(). map(x -> isUndefinedPairSet(x)).reduce(true, (x,y)-> (x && y)); return ret; } return false; From 615983bf37a97cc78d0bb98b31fe8398848a56ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 13 Apr 2018 18:13:31 +0200 Subject: [PATCH 60/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java resuat add in cartesion angepasst modified: src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java equals in UnfyPair auf UndefinedPairs angepasst --- .../typeinference/unify/TypeUnifyTask.java | 26 +++++++++++++++---- .../typeinference/unify/model/Unifier.java | 3 ++- .../typeinference/unify/model/UnifyPair.java | 7 +++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index a66c4626e..386f3e725 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -318,7 +318,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) - writeLog("Result " + eqPrimePrimeSet.toString()); + writeLog("Result1 " + eqPrimePrimeSet.toString()); return eqPrimePrimeSet; } @@ -419,10 +419,25 @@ public class TypeUnifyTask extends RecursiveTask>> { elems.add(a); if (remainingSets.isEmpty()) { Set> res = unify2(elems, eq, fc, parallel); - if (!isUndefinedPairSetSet(res)) {// && isUndefinedPairSetSet(result)) {//wenn korektes Ergebnis gefunden alle Fehlerfaelle loeschen - result = new HashSet<>(); + if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = res; } - result.addAll(res); + else { + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + result.addAll(res); + } + //else { + //wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren + // if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { + // result = result; + // } + //} + } + } else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); @@ -475,9 +490,10 @@ public class TypeUnifyTask extends RecursiveTask>> { return (!x.containsAll(durchschnitt)); }).collect(Collectors.toCollection(ArrayList::new)); writeLog("abhSubst: " + abhSubst.toString()); + writeLog("a: " + a.toString()); + writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); - writeLog("Durchschnitt: " + durchschnitt.toString()); System.out.println(""); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 8aa03a773..dfb88bc72 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -81,7 +81,8 @@ public class Unifier implements Function, Iterable suniUnifyPair = new HashSet<>(); suniUnifyPair.addAll(thisAsPair.getAllSubstitutions()); suniUnifyPair.add(thisAsPair); - if (p.getLhsType() instanceof PlaceholderType && newLhs instanceof PlaceholderType && p.getPairOp() == PairOperator.EQUALSDOT) { + if (p.getLhsType() instanceof PlaceholderType //&& newLhs instanceof PlaceholderType entfernt PL 2018-04-13 + && p.getPairOp() == PairOperator.EQUALSDOT) { suniUnifyPair.add(p); //p koennte auch subsitution sein } return new UnifyPair(newLhs, newRhs, p.getPairOp(), suniUnifyPair, p); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index dd24c28dc..cabfbcc12 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -148,6 +148,13 @@ public class UnifyPair { UnifyPair other = (UnifyPair) obj; + if (isUndefinedPair()) { + if (!other.getBasePair().equals(basePair) || + !other.getAllSubstitutions().equals(getAllSubstitutions())) { + return false; + } + } + return other.getPairOp() == pairOp && other.getLhsType().equals(lhs) && other.getRhsType().equals(rhs); From 82b08c5aae85499f38ec123f26966a63ac8922d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 17 Apr 2018 14:25:52 +0200 Subject: [PATCH 61/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Wildcard Ordnung veraendert --- .../typeinference/unify/TypeUnifyTask.java | 52 ++++++++++++------- .../unify/model/OrderingUnifyPair.java | 2 +- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 386f3e725..5f7cea0d2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -389,7 +389,18 @@ public class TypeUnifyTask extends RecursiveTask>> { if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { - Set a = nextSetasList.remove(0); + Set a = null; + if (variance == 1) { + a = oup.max(nextSetasList.iterator()); + nextSetasList.remove(a); + } + else if (variance == -1) { + a = oup.min(nextSetasList.iterator()); + nextSetasList.remove(a); + } + else if (variance == 0) { + a = nextSetasList.remove(0); + } //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); //nextSetasList.remove(a); /* zu loeschen @@ -477,8 +488,9 @@ public class TypeUnifyTask extends RecursiveTask>> { .map(x -> x.getAllSubstitutions()) .reduce((y,z) -> { y.addAll(z); return y;}).get()) .reduce((y,z) -> { y.addAll(z); return y;}).get(); + Set b = a;//effective final a Set durchschnitt = abhSubst.stream() - .filter(x -> a.contains(x)) + .filter(x -> b.contains(x)) //.filter(y -> abhSubst.contains(y)) .collect(Collectors.toCollection(HashSet::new)); Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); @@ -884,7 +896,7 @@ public class TypeUnifyTask extends RecursiveTask>> { unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); for (Entry sigma : unifier) { - substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { @@ -907,17 +919,17 @@ public class TypeUnifyTask extends RecursiveTask>> { for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { if(freshTphs.size()-1 < i) freshTphs.add(PlaceholderType.freshPlaceholder()); - resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); } if(allGen) { - UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()); + UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } else { - UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()); + UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); @@ -950,12 +962,12 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType extAPrime = new ExtendsType(aPrime); UnifyType thetaPrime = extThetaPrime.getExtendedType(); Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); result.add(resultPrime); resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog("Result: " + resultPrime.toString()); @@ -975,13 +987,13 @@ 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.getBasePair())); + resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); result.add(resultPrime); //writeLog(resultPrime.toString()); resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); @@ -1011,13 +1023,13 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()]; for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); - resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); } if(allGen) - resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); else - resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); @@ -1036,20 +1048,20 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> result = new HashSet<>(); //for(UnifyType thetaS : fc.grArg(theta)) { Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); result.add(resultPrime); //writeLog(resultPrime.toString()); UnifyType freshTph = PlaceholderType.freshPlaceholder(); resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); result.add(resultPrime); //writeLog(resultPrime.toString()); resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); - resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT, pair.getSubstitution(), pair)); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); //writeLog(resultPrime.toString()); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 9a018fb08..ee78d6fa9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -27,7 +27,7 @@ public class OrderingUnifyPair extends Ordering> { this.fc = fc; } public int compareEq (UnifyPair left, UnifyPair right) { - if (right.getRhsType() instanceof ExtendsType || right.getRhsType() instanceof SuperType) { + if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) { return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOTWC); } else { From 59243d9f9480050fadb16a97f52fe10bfe8e7fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 17 Apr 2018 16:31:13 +0200 Subject: [PATCH 62/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 5f7cea0d2..d2b9c8f28 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -459,6 +459,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { + System.out.println(""); while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a.equals(a_next) || @@ -468,6 +469,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { if (variance == -1) { + System.out.println(""); while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a.equals(a_next) || From fc870fd706da5085be84ee0425e25749e5644b51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 18 Apr 2018 19:44:00 +0200 Subject: [PATCH 63/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../typeinference/unify/TypeUnifyTask.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d2b9c8f28..626ec74e6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -428,7 +428,7 @@ public class TypeUnifyTask extends RecursiveTask>> { i++; Set> elems = new HashSet>(fstElems); elems.add(a); - if (remainingSets.isEmpty()) { + //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt Set> res = unify2(elems, eq, fc, parallel); if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen @@ -449,12 +449,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //} } - } - else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 - result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); - } + //} + //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 + //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); + //} - if (!result.isEmpty() && !isUndefinedPairSetSet(result)) { + 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(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); @@ -483,8 +483,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } - if (isUndefinedPairSetSet(result)) { - Set abhSubst = result.stream() + if (isUndefinedPairSetSet(res)) { + Set abhSubst = res.stream() .map(b -> b.stream() .map(x -> x.getAllSubstitutions()) From 1f031149d3110d3fe014b653526dd111388ca050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 20 Apr 2018 01:08:35 +0200 Subject: [PATCH 64/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java Varianceweitergabe eingefuegt --- .../typeinference/unify/TypeUnifyTask.java | 5 ++++- .../typeinference/unify/model/FiniteClosure.java | 6 ++++-- .../unify/model/OrderingUnifyPair.java | 8 ++++++-- .../typeinference/unify/model/Unifier.java | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 626ec74e6..0ac9fe638 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -898,7 +898,10 @@ public class TypeUnifyTask extends RecursiveTask>> { unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); for (Entry sigma : unifier) { - substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, + //TODO: nochmals ueberlegen ob hier pair.getSubstitution() korrekt ist, oder ob leere Menge hin müsste + //alle folgenden New UnifyPair ebenfalls ueberpruefen PL 2018-04-19 + pair.getSubstitution(), pair)); } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 4aa4ffb89..b45309b84 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -453,7 +453,8 @@ public class FiniteClosure extends Ordering implements IFiniteClosure HashSet hs = new HashSet<>(); hs.add(up); Set smallerRes = unifyTask.applyTypeUnificationRules(hs, this); - long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); + //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. + long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); if (smallerLen == 0) return -1; else { up = new UnifyPair(right, left, pairop); @@ -461,7 +462,8 @@ public class FiniteClosure extends Ordering implements IFiniteClosure hs = new HashSet<>(); hs.add(up); Set greaterRes = unifyTask.applyTypeUnificationRules(hs, this); - long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); + //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. + long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); if (greaterLen == 0) return 1; else return 0; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index ee78d6fa9..9d948cdc1 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -132,9 +132,13 @@ public class OrderingUnifyPair extends Ordering> { else return si.get(); } //Fall 1 und 4 - if (lefteq.size() == 1 && righteq.size() == 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) { - if (lefteq.iterator().next().getLhsType().getName().equals("A")) + if (lefteq.size() >= 1 && righteq.size() >= 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) { + if (lefteq.iterator().next().getLhsType().getName().equals("D")) System.out.print(""); + Set varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + Set varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + lefteq.removeIf(x -> !varsright.contains(x.getLhsType())); + righteq.removeIf(x -> !varsleft.contains(x.getLhsType())); UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); if (lseq.getRhsType().getName().equals("Object")) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index dfb88bc72..f0f8164c7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -72,11 +72,26 @@ public class Unifier implements Function, Iterable suniUnifyPair = new HashSet<>(); suniUnifyPair.addAll(thisAsPair.getAllSubstitutions()); From 93d0caaefbe711be9f8c70dc2f6e8c34cae00451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 20 Apr 2018 09:36:29 +0200 Subject: [PATCH 65/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Varianceberechnung geaendert --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 0ac9fe638..69caef2c0 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -352,7 +352,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) - .reduce((a,b)-> a*b)) + .reduce((a,b)-> {if (a==b) return a; else return 0; })) .filter(d -> d.isPresent()) .map(e -> e.get()) .findAny(); From 087170bdbfa698c6e7d29a557a5d028cb149882c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 20 Apr 2018 13:16:49 +0200 Subject: [PATCH 66/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java Variance wieder auskommentiert modified: test/javFiles/Matrix.jav import String --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 38 +++++++++++++++++++ .../typeinference/unify/TypeUnifyTask.java | 1 + .../typeinference/unify/model/Unifier.java | 28 +++++++------- test/javFiles/Matrix.jav | 1 + 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 23a2750c5..5ef594134 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 69caef2c0..e590c3026 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 f0f8164c7..8f5948444 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 a680370f4..ad8d735e8 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;} From 0ae777b4ac1e6818751fb22e33b6d54847d600d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 20 Apr 2018 23:52:12 +0200 Subject: [PATCH 67/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java varianceInheritance nach TypeUnifyTask.java verschoben Kommentar eingefuegt TODO: 1. compare-Funktinen nochmals ueberpruefen 2. Undef-Pairs in JavaTXiCompiler.java abfangen 3. ? extends bei allen Argumenttypen und Returntypen rauslassen --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 39 +------------- .../typeinference/unify/TypeUnifyTask.java | 53 ++++++++++++++++++- .../unify/model/OrderingUnifyPair.java | 1 + 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 5ef594134..c8bf0018f 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -23,6 +23,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.unify.inheritVariance; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; @@ -143,7 +144,6 @@ 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); @@ -158,42 +158,7 @@ public class JavaTXCompiler { 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 e590c3026..c5e8281ca 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -86,7 +86,53 @@ public class TypeUnifyTask extends RecursiveTask>> { this.logFile = logFile; rules = new RuleSet(logFile); } - + + /** + * Vererbt alle Variancen + * @param eq The set of constraints + */ + private void varianceInheritance(Set eq) { + Set phSet = eq.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); + HashMap ht = new HashMap<>(); + ht.put(a, a.getVariance()); + eq.stream().forEach(x -> { + x.getLhsType().accept(new inheritVariance(), ht); + 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()); + //} + }; + }); + eq.stream().forEach(x -> { + x.getRhsType().accept(new inheritVariance(), ht); + 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()); + //} + }; + }); + } +} @Override protected Set> compute() { return unify(eq, fc, parallel); @@ -105,6 +151,11 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Unifikation: " + eq.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); + /* + * Variancen auf alle Gleichungen vererben + */ + varianceInheritance(eq); + /* * ? extends ? extends Theta rausfiltern */ diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 9d948cdc1..fa6b114d2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -149,6 +149,7 @@ public class OrderingUnifyPair extends Ordering> { if (rseq.getRhsType().getName().equals("Object")) return -1; } if (leftlewc.size() == rightlewc.size()) { + //TODO: Hier wird bei Wildcards nicht das richtige compare aufgerufen PL 18-04-20 Pair> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType()); Unifier uni = new Unifier(); int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType())); From 5f8c73f1769cb07a8bc3bdeeaef3761eb7833814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 22 Apr 2018 00:56:49 +0200 Subject: [PATCH 68/91] modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java In compare wird die Gleichung a =. Theta neu gefiltert --- .../typeinference/unify/TypeUnifyTask.java | 2 +- .../unify/model/OrderingUnifyPair.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index c5e8281ca..a9eb2daba 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -962,7 +962,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) .map(x -> { //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen - //HashMap hm = x.getInvolvedPlaceholderTypes().stream() + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben // .reduce(new HashMap(), // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index fa6b114d2..1a4f72cd8 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -26,6 +26,11 @@ public class OrderingUnifyPair extends Ordering> { public OrderingUnifyPair(IFiniteClosure fc) { this.fc = fc; } + + /* + * vergleicht Paare (a =. Theta) und (a =. Theta') + * in dem compare(Theta, Theta') aufgerufen wird. + */ public int compareEq (UnifyPair left, UnifyPair right) { if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) { return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOTWC); @@ -135,10 +140,13 @@ public class OrderingUnifyPair extends Ordering> { if (lefteq.size() >= 1 && righteq.size() >= 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) { if (lefteq.iterator().next().getLhsType().getName().equals("D")) System.out.print(""); - Set varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); - Set varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); - lefteq.removeIf(x -> !varsright.contains(x.getLhsType())); - righteq.removeIf(x -> !varsleft.contains(x.getLhsType())); + //Set varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + //Set varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + //filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant) + lefteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//removeIf(x -> !varsright.contains(x.getLhsType())); + righteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//.removeIf(x -> !varsleft.contains(x.getLhsType())); UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); if (lseq.getRhsType().getName().equals("Object")) { From 62d44eb15c25bd0f4b92219d7a6b51f84a3fc8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 24 Apr 2018 00:53:33 +0200 Subject: [PATCH 69/91] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Undefined Pairs auf oberster Ebene wird zu new HashTable<>() in compute new file: ../../src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Unterscheidung zw. <. { + //Hier muss ueberlegt werden, ob + //1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs + // mit disableWildcardtable() werden. + //2. alle Typvariablen mit Argument- oder Retuntyp-Variablen + //in Beziehung auch auf disableWildcardtable() gesetzt werden muessen + //PL 2018-04-23 if ((x.getLhsType() instanceof PlaceholderType)) { if (paraTypeVarNames.contains(x.getLhsType().getName())) { ((PlaceholderType)x.getLhsType()).setVariance((byte)1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } if (returnTypeVarNames.contains(x.getLhsType().getName())) { ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } } if ((x.getRhsType() instanceof PlaceholderType)) { if (paraTypeVarNames.contains(x.getRhsType().getName())) { ((PlaceholderType)x.getRhsType()).setVariance((byte)1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } if (returnTypeVarNames.contains(x.getRhsType().getName())) { ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } return x; diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index a9eb2daba..ff929fc0e 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -135,7 +135,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } @Override protected Set> compute() { - return unify(eq, fc, parallel); + Set> res = unify(eq, fc, parallel); + if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } + else return res; } /** @@ -547,6 +549,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //.filter(y -> abhSubst.contains(y)) .collect(Collectors.toCollection(HashSet::new)); Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + int len = nextSetasList.size(); nextSetasList = nextSetasList.stream().filter(x -> { //Boolean ret = false; //for (PlaceholderType var : vars) { @@ -559,6 +562,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); System.out.println(""); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { @@ -959,15 +963,17 @@ public class TypeUnifyTask extends RecursiveTask>> { for (UnifyType tq : thetaQs) { Set smaller = fc.smaller(unifier.apply(tq)); //eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen - Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) - .map(x -> { - //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen - //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben - // .reduce(new HashMap(), - // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); - return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));} - .collect(Collectors.toCollection(HashSet::new)); - smaller.addAll(smaller_ext); + if (a.isWildcardable()) { + Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) + .map(x -> { + //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben + // .reduce(new HashMap(), + // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));} + .collect(Collectors.toCollection(HashSet::new)); + smaller.addAll(smaller_ext); + } //eingefuegt PL 2018-03-29 Ende ? ext. theta hinzufuegen for(UnifyType theta : smaller) { List freshTphs = new ArrayList<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java b/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java new file mode 100644 index 000000000..1b6a4d108 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java @@ -0,0 +1,18 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.HashMap; + +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; + +public class inheritVariance extends visitUnifyTypeVisitor> { + + @Override + public PlaceholderType visit(PlaceholderType phty, HashMap ht) { + if (ht.containsKey(phty)) { + if (phty.getVariance() == 0) { + phty.setVariance(ht.get(phty)); + } + } + return phty; + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 1a4f72cd8..09992791c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -53,7 +53,13 @@ public class OrderingUnifyPair extends Ordering> { */ public Pair> compare (UnifyType left, UnifyType right) { - UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT); + UnifyPair up; + if (left instanceof WildcardType || right instanceof WildcardType) { + up = new UnifyPair(left, right, PairOperator.SMALLERDOTWC); + } + else { + up = new UnifyPair(left, right, PairOperator.SMALLERDOT); + } TypeUnifyTask unifyTask = new TypeUnifyTask(); HashSet hs = new HashSet<>(); hs.add(up); @@ -61,7 +67,12 @@ public class OrderingUnifyPair extends Ordering> { long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); if (smallerLen == 0) return new Pair<>(-1, smallerRes); else { - up = new UnifyPair(right, left, PairOperator.SMALLERDOT); + if (left instanceof WildcardType || right instanceof WildcardType) { + up = new UnifyPair(right, left, PairOperator.SMALLERDOTWC); + } + else { + up = new UnifyPair(right, left, PairOperator.SMALLERDOT); + } //TypeUnifyTask unifyTask = new TypeUnifyTask(); hs = new HashSet<>(); hs.add(up); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 8d9b62df9..fe7758bea 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -38,6 +38,12 @@ public final class PlaceholderType extends UnifyType{ */ private final boolean IsGenerated; + + /** + * isWildcardable gibt an, ob ein Wildcardtyp dem PlaceholderType zugeordnet werden darf + */ + private boolean wildcardable = true; + /** * variance shows the variance of the pair * -1: contravariant @@ -98,6 +104,13 @@ public final class PlaceholderType extends UnifyType{ return variance; } + public Boolean isWildcardable() { + return wildcardable; + } + public void disableWildcardtable() { + wildcardable = false; + } + @Override Set smArg(IFiniteClosure fc) { return fc.smArg(this); From 8be4f94edf9f137e39469623960720dc3de3a1d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 25 Apr 2018 23:32:12 +0200 Subject: [PATCH 70/91] modified: test/javFiles/Matrix.jav In Matrix.jav Binary-Operation eingefuegt. new file: test/javFiles/Meth_Gen.jav new file: test/typeinference/Meth_GenTest.java Test zu Constraints ueber eine Methode hinaus --- test/javFiles/Matrix.jav | 6 +- test/javFiles/Meth_Gen.jav | 11 +++ test/typeinference/Meth_GenTest.java | 139 +++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 test/javFiles/Meth_Gen.jav create mode 100644 test/typeinference/Meth_GenTest.java diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index ad8d735e8..f9a69ec56 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -17,9 +17,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++; } diff --git a/test/javFiles/Meth_Gen.jav b/test/javFiles/Meth_Gen.jav new file mode 100644 index 000000000..056dd82f8 --- /dev/null +++ b/test/javFiles/Meth_Gen.jav @@ -0,0 +1,11 @@ +class Meth_Gen { + + m1(x, y) { + m2(x); + x = y; + } + + m2(y) { + m1(y, y); + } +} \ No newline at end of file diff --git a/test/typeinference/Meth_GenTest.java b/test/typeinference/Meth_GenTest.java new file mode 100644 index 000000000..f5e64f9f9 --- /dev/null +++ b/test/typeinference/Meth_GenTest.java @@ -0,0 +1,139 @@ +package typeinference; + +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.syntaxtree.SourceFile; +import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; +import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; +import de.dhbwstuttgart.typedeployment.TypeInsert; +import de.dhbwstuttgart.typedeployment.TypeInsertFactory; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Meth_GenTest { + + public static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/"; +/* + @Test + public void finiteClosure() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"fc.jav")); + } + @Test + public void lambda() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Lambda.jav")); + } + @Test + public void lambda2() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Lambda2.jav")); + } + @Test + public void lambda3() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Lambda3.jav")); + } + @Test + public void mathStruc() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"mathStruc.jav")); + } + @Test + public void generics() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Generics.jav")); + } + + @Test + public void faculty() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Faculty.jav")); + } + + @Test + public void facultyTyped() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"FacultyTyped.jav")); + } +*/ + @Test + public void matrix() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Meth_Gen.jav")); + } +/* + @Test + public void vector() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Vector.jav")); + } + @Test + public void lambdaRunnable() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"LambdaRunnable.jav")); + } + @Test + public void expressions() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"Expressions.jav")); + } + @Test + public void matrixFC() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"FC_Matrix.jav")); + } +*/ + private static class TestResultSet{ + + } + + public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException { + //filesToTest.add(new File(rootDirectory+"fc.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda2.jav")); + //filesToTest.add(new File(rootDirectory+"Lambda3.jav")); + //filesToTest.add(new File(rootDirectory+"Vector.jav")); + //filesToTest.add(new File(rootDirectory+"Generics.jav")); + //filesToTest.add(new File(rootDirectory+"MethodsEasy.jav")); + //filesToTest.add(new File(rootDirectory+"Matrix.jav")); + //filesToTest.add(new File(rootDirectory+"Import.jav")); + // //filesToTest.add(new File(rootDirectory+"Faculty.jav")); + // //filesToTest.add(new File(rootDirectory+"mathStruc.jav")); + // //filesToTest.add(new File(rootDirectory+"test.jav")); + JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + } + List results = compiler.typeInference(); + + for(File f : compiler.sourceFiles.keySet()){ + SourceFile sf = compiler.sourceFiles.get(f); + System.out.println(ASTTypePrinter.print(sf)); + System.out.println(ASTPrinter.print(sf)); + //List results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen + assert results.size()>0; + Set insertedTypes = new HashSet<>(); + for(ResultSet resultSet : results){ + Set result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet); + assert result.size()>0; + String content = readFile(f.getPath(), StandardCharsets.UTF_8); + for(TypeInsert tip : result){ + insertedTypes.add(tip.insert(content)); + } + } + for(String s : insertedTypes){ + System.out.println(s); + } + } + return new TestResultSet(); + } + + static String readFile(String path, Charset encoding) + throws IOException + { + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); + } + +} + From ec2b501e6387c634b430cc681dec76423d9c2bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 26 Apr 2018 15:10:23 +0200 Subject: [PATCH 71/91] new file: test/javFiles/LambdaField.jav modified: test/typeinference/UnifyTest.java Lambda-Ausdruck als Attribute/field eingefuegt --- test/javFiles/LambdaField.jav | 6 ++++++ test/typeinference/UnifyTest.java | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 test/javFiles/LambdaField.jav diff --git a/test/javFiles/LambdaField.jav b/test/javFiles/LambdaField.jav new file mode 100644 index 000000000..4eb537380 --- /dev/null +++ b/test/javFiles/LambdaField.jav @@ -0,0 +1,6 @@ +public class LambdaField { + + f = x -> x; + +} + diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index c10fae05d..8e8291639 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -28,10 +28,12 @@ public class UnifyTest { public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav")); } + */ @Test public void lambda() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"Lambda.jav")); + execute(new File(rootDirectory+"LambdaField.jav")); } +/* @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); @@ -58,12 +60,14 @@ public class UnifyTest { public void facultyTyped() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FacultyTyped.jav")); } -*/ + @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); + //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); + //compiler.generateBytecode(); } -/* + @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); From 4738add4fc0e051481d3cb9cd756385473c51c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 7 May 2018 15:31:31 +0200 Subject: [PATCH 72/91] modified: ../../../../../test/javFiles/Matrix.jav modified: ../../../../../test/typeinference/UnifyTest.java --- test/javFiles/Matrix.jav | 6 +++--- test/typeinference/UnifyTest.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index f9a69ec56..ad8d735e8 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -17,9 +17,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++; } diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index 8e8291639..c3eca27d1 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -28,12 +28,12 @@ public class UnifyTest { public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav")); } - */ + @Test public void lambda() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"LambdaField.jav")); } -/* + @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); @@ -60,14 +60,14 @@ public class UnifyTest { public void facultyTyped() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FacultyTyped.jav")); } - + */ @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); //compiler.generateBytecode(); } - +/* @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); From 225dc16a899039787c3932508b795cc2d62cf187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 8 May 2018 09:23:20 +0200 Subject: [PATCH 73/91] modified: test/typeinference/UnifyTest.java --- test/typeinference/UnifyTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index c3eca27d1..2f7107d85 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -50,23 +50,27 @@ public class UnifyTest { public void generics() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Generics.jav")); } - +*/ @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); } +/* @Test public void facultyTyped() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FacultyTyped.jav")); } */ + + /* @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); //compiler.generateBytecode(); } + */ /* @Test public void vector() throws IOException, ClassNotFoundException { From da4c59f2cf83eab0f86473ae9b9292408b7132ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 9 May 2018 16:24:28 +0200 Subject: [PATCH 74/91] modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: ../../test/typeinference/UnifyTest.java --- .../typeinference/typeAlgo/TYPEStmt.java | 45 ++++++++++++++++--- test/typeinference/UnifyTest.java | 7 +-- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 108122acd..9c6cc76ed 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -184,7 +184,13 @@ public class TYPEStmt implements StatementVisitor{ receiver.expr.accept(this); } - private final RefType number = new RefType(ASTFactory.createClass(Integer.class).getClassName(), new NullToken()); + private final RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), new NullToken()); + private final RefType longg = new RefType(ASTFactory.createClass(Long.class).getClassName(), new NullToken()); + private final RefType integer = new RefType(ASTFactory.createClass(Integer.class).getClassName(), new NullToken()); + private final RefType shortt = new RefType(ASTFactory.createClass(Short.class).getClassName(), new NullToken()); + private final RefType bytee = new RefType(ASTFactory.createClass(Byte.class).getClassName(), new NullToken()); + private final RefType floatt = new RefType(ASTFactory.createClass(Float.class).getClassName(), new NullToken()); + private final RefType doublee = new RefType(ASTFactory.createClass(Double.class).getClassName(), new NullToken()); private final RefType string = new RefType(ASTFactory.createClass(String.class).getClassName(), new NullToken()); private final RefType bool = new RefType(ASTFactory.createClass(Boolean.class).getClassName(), new NullToken()); @Override @@ -205,18 +211,47 @@ public class TYPEStmt implements StatementVisitor{ @Override public void visit(BinaryExpr binary) { - + binary.lexpr.accept(this); + binary.rexpr.accept(this); if(binary.operation.equals(BinaryExpr.Operator.DIV) || binary.operation.equals(BinaryExpr.Operator.MUL)|| binary.operation.equals(BinaryExpr.Operator.MOD)|| binary.operation.equals(BinaryExpr.Operator.ADD)){ Set numericAdditionOrStringConcatenation = new HashSet<>(); - Constraint numeric = new Constraint<>(); + //Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer: //see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17 //Expression muss zu Numeric Convertierbar sein. also von Numeric erben - numeric.add(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT)); - numeric.add(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT)); + Constraint numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT)); + numericAdditionOrStringConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT)); + numericAdditionOrStringConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT)); + numericAdditionOrStringConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.getType(), longg, PairOperator.EQUALSDOT)); + numericAdditionOrStringConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.getType(), floatt, PairOperator.EQUALSDOT)); + numericAdditionOrStringConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.getType(), doublee, PairOperator.EQUALSDOT)); + numericAdditionOrStringConcatenation.add(numeric); /* In Java passiert bei den binären Operatoren eine sogenannte Type Promotion: https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2 diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index 2f7107d85..9d1c603b8 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -51,11 +51,12 @@ public class UnifyTest { execute(new File(rootDirectory+"Generics.jav")); } */ +/* @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); } - +*/ /* @Test public void facultyTyped() throws IOException, ClassNotFoundException { @@ -63,14 +64,14 @@ public class UnifyTest { } */ - /* + @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); //compiler.generateBytecode(); } - */ + /* @Test public void vector() throws IOException, ClassNotFoundException { From e4243b612c9f7d7f6c7594486422204f3d2a09e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 9 May 2018 18:05:06 +0200 Subject: [PATCH 75/91] modified: src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java Operatoren neue getypte Returnargument bei FUNN nach hinten verschoben modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java Returnargument bei FUNN nach hinten verschoben Wildcards in Argumenten von als Undefined Pairs (funktioniert noch nicht) Methode wrongWildcard eingefuegt modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Methode doubleWildcard ind wrongWildcard umbenannt modified: src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java Methode doubleWildcard ind wrongWildcard umbenannt modified: src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java Methode doubleWildcard ind wrongWildcard umbenannt --- .../typeinference/typeAlgo/TYPEStmt.java | 4 ++-- .../dhbwstuttgart/typeinference/unify/RuleSet.java | 12 ++++++------ .../typeinference/unify/TypeUnifyTask.java | 2 +- .../typeinference/unify/model/FunNType.java | 9 +++++++++ .../typeinference/unify/model/UnifyPair.java | 4 ++-- .../typeinference/unify/model/UnifyType.java | 2 +- .../typeinference/unify/model/WildcardType.java | 2 +- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 9c6cc76ed..2d6867ce9 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -57,8 +57,8 @@ public class TYPEStmt implements StatementVisitor{ public void visit(LambdaExpression lambdaExpression) { TypePlaceholder tphRetType = TypePlaceholder.fresh(new NullToken()); List lambdaParams = lambdaExpression.params.getFormalparalist().stream().map((formalParameter -> formalParameter.getType())).collect(Collectors.toList()); - //lambdaParams.add(tphRetType); - lambdaParams.add(0,tphRetType); + lambdaParams.add(tphRetType); + //lambdaParams.add(0,tphRetType); constraintsSet.addUndConstraint( new Pair(lambdaExpression.getType(), new FunN(lambdaParams),PairOperator.EQUALSDOT)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 0d77d48fe..cd6fb8e74 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -767,8 +767,8 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet(); - result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 1; i < funNLhsType.getTypeParams().size(); i++) + result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); return Optional.of(result); @@ -793,8 +793,8 @@ public class RuleSet implements IRuleSet{ for(int i = 0; i < freshPlaceholders.length; i++) freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), freshPlaceholders[0], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 1; i < funNLhsType.getTypeParams().size(); i++) + result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); @@ -820,8 +820,8 @@ public class RuleSet implements IRuleSet{ for(int i = 0; i < freshPlaceholders.length; i++) freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); - result.add(new UnifyPair(freshPlaceholders[0], funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 1; i < funNRhsType.getTypeParams().size(); i++) + result.add(new UnifyPair(freshPlaceholders[funNRhsType.getTypeParams().size()-1], funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ff929fc0e..aec5653c6 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -161,7 +161,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * ? extends ? extends Theta rausfiltern */ - Set doubleExt = eq.stream().filter(x -> (x.doubleExtended())).map(x -> { x.setUndefinedPair(); return x;}) + Set doubleExt = eq.stream().filter(x -> (x.wrongWildcard())).map(x -> { x.setUndefinedPair(); return x;}) .collect(Collectors.toCollection(HashSet::new)); if (doubleExt.size() > 0) { Set> ret = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 37ec79d5d..5d8077651 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -1,5 +1,7 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Set; @@ -73,11 +75,18 @@ public class FunNType extends UnifyType { return new FunNType(newParams); } + @Override + public Boolean wrongWildcard() { + return !(new ArrayList(Arrays.asList(getTypeParams() + .get())).stream().filter(x -> (x instanceof WildcardType)).findFirst().isPresent()); + } + @Override public int hashCode() { return 181 + typeParams.hashCode(); } + @Override public boolean equals(Object obj) { if(!(obj instanceof FunNType)) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index cabfbcc12..b631e5ec4 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -134,8 +134,8 @@ public class UnifyPair { return ret; } - public Boolean doubleExtended() { - return lhs.doubleExtended() || rhs.doubleExtended(); + public Boolean wrongWildcard() { + return lhs.wrongWildcard() || rhs.wrongWildcard(); } @Override diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index 5beef2bf4..715d9880a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -103,7 +103,7 @@ public abstract class UnifyType { return ret; } - public Boolean doubleExtended() {//default + public Boolean wrongWildcard() {//default return false; } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java index e320bb9f1..81999492b 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java @@ -41,7 +41,7 @@ public abstract class WildcardType extends UnifyType { } @Override - public Boolean doubleExtended () {//This is an error + public Boolean wrongWildcard () {//This is an error return (wildcardedType instanceof WildcardType); } From 8048af21066fdffc395f06a17b0964ca4f3315e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 9 May 2018 18:10:08 +0200 Subject: [PATCH 76/91] modified: ../../test/javFiles/Lambda2.jav modified: ../../test/typeinference/UnifyTest.java --- test/javFiles/Lambda2.jav | 1 + test/typeinference/UnifyTest.java | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/javFiles/Lambda2.jav b/test/javFiles/Lambda2.jav index fbcdaf55b..cf1e910b8 100644 --- a/test/javFiles/Lambda2.jav +++ b/test/javFiles/Lambda2.jav @@ -1,3 +1,4 @@ +import java.lang.String; public class Lambda2 { diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index 2f7107d85..ac7ef2217 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -33,11 +33,12 @@ public class UnifyTest { public void lambda() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"LambdaField.jav")); } - +*/ @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); } +/* @Test public void lambda3() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda3.jav")); @@ -51,11 +52,12 @@ public class UnifyTest { execute(new File(rootDirectory+"Generics.jav")); } */ +/* @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); } - +*/ /* @Test public void facultyTyped() throws IOException, ClassNotFoundException { From 5c797a44a18b329866cd562aacc31bf95b213595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 10 May 2018 09:07:33 +0200 Subject: [PATCH 77/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java disableWildcardtable in den FUNN-Regeln eingefuegt. --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- .../typeinference/unify/RuleSet.java | 19 +++++++++++++++++-- .../typeinference/unify/model/FunNType.java | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index f449a70ed..cbfb5e7ea 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -154,7 +154,7 @@ public class JavaTXCompiler { ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } - return x; + return x;HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE }).collect(Collectors.toCollection(HashSet::new)); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> result = unify.unify(xConsSet, finiteClosure); diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index cd6fb8e74..a576edc3c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -768,9 +768,14 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet(); result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) + for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - + } + result.stream().forEach(x -> { UnifyType l = x.getLhsType(); + if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } + UnifyType r = x.getRhsType(); + if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } + } ); return Optional.of(result); } @@ -798,6 +803,11 @@ public class RuleSet implements IRuleSet{ result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + result.stream().forEach(x -> { UnifyType l = x.getLhsType(); + if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } + UnifyType r = x.getRhsType(); + if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } + } ); return Optional.of(result); } @@ -825,6 +835,11 @@ public class RuleSet implements IRuleSet{ result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); + result.stream().forEach(x -> { UnifyType l = x.getLhsType(); + if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); } + UnifyType r = x.getRhsType(); + if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); } + } ); return Optional.of(result); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 5d8077651..95275a124 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -77,7 +77,7 @@ public class FunNType extends UnifyType { @Override public Boolean wrongWildcard() { - return !(new ArrayList(Arrays.asList(getTypeParams() + return (new ArrayList(Arrays.asList(getTypeParams() .get())).stream().filter(x -> (x instanceof WildcardType)).findFirst().isPresent()); } From 9575afd0b4ae1a0c9fcae45ea1c9e2664e0faece Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Tue, 15 May 2018 10:33:30 +0200 Subject: [PATCH 78/91] Fun umbenannt und Argumente umgedreht --- src/de/dhbwstuttgart/bytecode/BytecodeGen.java | 2 ++ src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java | 6 +++++- .../bytecode/descriptor/DescriptorToString.java | 10 +++++----- .../bytecode/descriptor/DescriptorVisitor.java | 10 +++++----- src/de/dhbwstuttgart/bytecode/signature/Signature.java | 8 +++++--- .../bytecode/{ => utilities}/KindOfLambda.java | 2 +- .../dhbwstuttgart/bytecode/{ => utilities}/Lambda.java | 2 +- .../bytecode/{ => utilities}/MethodFromMethodCall.java | 2 +- .../bytecode/{ => utilities}/NormalConstructor.java | 2 +- .../bytecode/{ => utilities}/NormalMethod.java | 2 +- .../bytecode/{ => utilities}/SamMethod.java | 2 +- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- .../parser/SyntaxTreeGenerator/StatementGenerator.java | 2 +- 13 files changed, 30 insertions(+), 22 deletions(-) rename src/de/dhbwstuttgart/bytecode/{ => utilities}/KindOfLambda.java (98%) rename src/de/dhbwstuttgart/bytecode/{ => utilities}/Lambda.java (93%) rename src/de/dhbwstuttgart/bytecode/{ => utilities}/MethodFromMethodCall.java (96%) rename src/de/dhbwstuttgart/bytecode/{ => utilities}/NormalConstructor.java (95%) rename src/de/dhbwstuttgart/bytecode/{ => utilities}/NormalMethod.java (97%) rename src/de/dhbwstuttgart/bytecode/{ => utilities}/SamMethod.java (94%) diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index 52feb6e5f..36c7173a5 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -17,6 +17,8 @@ import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString; import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor; import de.dhbwstuttgart.bytecode.signature.Signature; import de.dhbwstuttgart.bytecode.signature.TypeToString; +import de.dhbwstuttgart.bytecode.utilities.NormalConstructor; +import de.dhbwstuttgart.bytecode.utilities.NormalMethod; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.statement.Literal; diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index ce5d3deff..c00c152a2 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -31,6 +31,10 @@ import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor; import de.dhbwstuttgart.bytecode.signature.Signature; import de.dhbwstuttgart.bytecode.signature.TypeToSignature; import de.dhbwstuttgart.bytecode.signature.TypeToString; +import de.dhbwstuttgart.bytecode.utilities.KindOfLambda; +import de.dhbwstuttgart.bytecode.utilities.Lambda; +import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall; +import de.dhbwstuttgart.bytecode.utilities.SamMethod; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.Method; @@ -566,7 +570,7 @@ public class BytecodeGenMethod implements StatementVisitor { methSig.visitReturnType().visitTypeVariable("R"); // ")"+lam.getReturn.getBounds Signature sig = new Signature(lambdaExpression, numberOfParams); - String name = "Fun" + numberOfParams; + String name = "Fun" + numberOfParams + "$$"; classWriter.visit(Opcodes.V1_8, Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(), Type.getInternalName(Object.class), null); MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc, diff --git a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java index 65f48f71d..cba540f8b 100644 --- a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java +++ b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java @@ -2,12 +2,12 @@ package de.dhbwstuttgart.bytecode.descriptor; import java.util.Iterator; -import de.dhbwstuttgart.bytecode.Lambda; -import de.dhbwstuttgart.bytecode.MethodFromMethodCall; -import de.dhbwstuttgart.bytecode.NormalConstructor; -import de.dhbwstuttgart.bytecode.NormalMethod; -import de.dhbwstuttgart.bytecode.SamMethod; import de.dhbwstuttgart.bytecode.signature.TypeToSignature; +import de.dhbwstuttgart.bytecode.utilities.Lambda; +import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall; +import de.dhbwstuttgart.bytecode.utilities.NormalConstructor; +import de.dhbwstuttgart.bytecode.utilities.NormalMethod; +import de.dhbwstuttgart.bytecode.utilities.SamMethod; import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.statement.Expression; import de.dhbwstuttgart.syntaxtree.type.RefType; diff --git a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorVisitor.java b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorVisitor.java index 6bc57f212..35f1423eb 100644 --- a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorVisitor.java +++ b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorVisitor.java @@ -1,10 +1,10 @@ package de.dhbwstuttgart.bytecode.descriptor; -import de.dhbwstuttgart.bytecode.Lambda; -import de.dhbwstuttgart.bytecode.MethodFromMethodCall; -import de.dhbwstuttgart.bytecode.NormalConstructor; -import de.dhbwstuttgart.bytecode.NormalMethod; -import de.dhbwstuttgart.bytecode.SamMethod; +import de.dhbwstuttgart.bytecode.utilities.Lambda; +import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall; +import de.dhbwstuttgart.bytecode.utilities.NormalConstructor; +import de.dhbwstuttgart.bytecode.utilities.NormalMethod; +import de.dhbwstuttgart.bytecode.utilities.SamMethod; public interface DescriptorVisitor { public String visit(NormalMethod method); diff --git a/src/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/de/dhbwstuttgart/bytecode/signature/Signature.java index 46202cb11..8c2cc1d38 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -59,9 +59,6 @@ public class Signature { private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) { - sw.visitFormalTypeParameter("R"); - // getBounds vom Return-Type - sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); sw.visitClassBound().visitEnd(); for(int i = 0;i> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> result = unify.unify(xConsSet, finiteClosure); diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index aaa31f74c..15f2268de 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -904,7 +904,7 @@ public class StatementGenerator { funNParams.add(TypePlaceholder.fresh(expression.getStart()))); RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart()); //RefType lambdaType = new RefType(reg.getName("Fun"+params.getFormalparalist().size()), - //funNParams, name.getStart()); + //funNParams, name.getStart()); return new LambdaExpression(lambdaType, params, block, expression.getStart()); } } From dcc36f082f62603b17285f05b43a0b790cff5383 Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 16 May 2018 13:37:31 +0200 Subject: [PATCH 79/91] =?UTF-8?q?code=20aufr=C3=A4umen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/bytecode/AStatement.java | 30 +++++++++++ .../dhbwstuttgart/bytecode/ArgumentExpr.java | 11 ++++ src/de/dhbwstuttgart/bytecode/AssignStmt.java | 11 ++++ .../bytecode/BytecodeGenMethod.java | 52 +++++++------------ src/de/dhbwstuttgart/bytecode/IStatement.java | 9 ++++ src/de/dhbwstuttgart/bytecode/LoopStmt.java | 25 +++++++++ src/de/dhbwstuttgart/bytecode/ReturnStmt.java | 14 +++++ 7 files changed, 120 insertions(+), 32 deletions(-) create mode 100644 src/de/dhbwstuttgart/bytecode/AStatement.java create mode 100644 src/de/dhbwstuttgart/bytecode/ArgumentExpr.java create mode 100644 src/de/dhbwstuttgart/bytecode/AssignStmt.java create mode 100644 src/de/dhbwstuttgart/bytecode/IStatement.java create mode 100644 src/de/dhbwstuttgart/bytecode/LoopStmt.java create mode 100644 src/de/dhbwstuttgart/bytecode/ReturnStmt.java diff --git a/src/de/dhbwstuttgart/bytecode/AStatement.java b/src/de/dhbwstuttgart/bytecode/AStatement.java new file mode 100644 index 000000000..5c28bf43b --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/AStatement.java @@ -0,0 +1,30 @@ +package de.dhbwstuttgart.bytecode; + +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr; +import de.dhbwstuttgart.syntaxtree.statement.Expression; + +public abstract class AStatement implements IStatement { + protected Expression expr; + + public AStatement(Expression expr) { + this.expr = expr; + } + + @Override + public boolean isExprBinary() { + return (expr instanceof BinaryExpr); + } + + @Override + public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) { + mv.visitInsn(Opcodes.ICONST_1); + mv.visitJumpInsn(Opcodes.GOTO, endLabel); + mv.visitLabel(branchLabel); + mv.visitInsn(Opcodes.ICONST_0); + mv.visitLabel(endLabel); + } +} diff --git a/src/de/dhbwstuttgart/bytecode/ArgumentExpr.java b/src/de/dhbwstuttgart/bytecode/ArgumentExpr.java new file mode 100644 index 000000000..b396e8d14 --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/ArgumentExpr.java @@ -0,0 +1,11 @@ +package de.dhbwstuttgart.bytecode; + +import de.dhbwstuttgart.syntaxtree.statement.Expression; + +public class ArgumentExpr extends AStatement { + + public ArgumentExpr(Expression expr) { + super(expr); + } + +} diff --git a/src/de/dhbwstuttgart/bytecode/AssignStmt.java b/src/de/dhbwstuttgart/bytecode/AssignStmt.java new file mode 100644 index 000000000..366c450a0 --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/AssignStmt.java @@ -0,0 +1,11 @@ +package de.dhbwstuttgart.bytecode; + +import de.dhbwstuttgart.syntaxtree.statement.Expression; + +public class AssignStmt extends AStatement { + + public AssignStmt(Expression rightSide) { + super(rightSide); + } + +} diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index c00c152a2..8b928a312 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -55,6 +55,8 @@ public class BytecodeGenMethod implements StatementVisitor { HashMap genericsAndBoundsMethod; private HashMap genericsAndBounds; private boolean isBinaryExp = false; + + private IStatement statement; // for tests ** private String fieldName; @@ -148,6 +150,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(Assign assign) { + statement = new AssignStmt(assign.rightSide); isAssignStmt = true; // if the right side is a lambda => the left side must be a functional interface @@ -157,8 +160,7 @@ public class BytecodeGenMethod implements StatementVisitor { isRightSideALambda = false; } - if (assign.rightSide instanceof BinaryExpr) - isBinaryExp = true; + isBinaryExp = statement.isExprBinary(); if (assign.lefSide instanceof AssignToField) { @@ -198,7 +200,7 @@ public class BytecodeGenMethod implements StatementVisitor { Label endLabel = new Label(); // this case for while loops - if(!isAssignStmt) + if(statement instanceof LoopStmt) mv.visitLabel(endLabel); binary.lexpr.accept(this); @@ -341,18 +343,9 @@ public class BytecodeGenMethod implements StatementVisitor { default: break; } - if(isAssignStmt) { - mv.visitInsn(Opcodes.ICONST_1); - mv.visitJumpInsn(Opcodes.GOTO, endLabel); - mv.visitLabel(branchLabel); - mv.visitInsn(Opcodes.ICONST_0); - mv.visitLabel(endLabel); - } else { - loopBlock.accept(this); - mv.visitJumpInsn(Opcodes.GOTO, endLabel); - - mv.visitLabel(branchLabel); - } + + statement.genBCForRelOp(mv, branchLabel, endLabel,this); + break; } } @@ -375,18 +368,7 @@ public class BytecodeGenMethod implements StatementVisitor { default: break; } - if(isAssignStmt) { - mv.visitInsn(Opcodes.ICONST_1); - mv.visitJumpInsn(Opcodes.GOTO, endLabel); - mv.visitLabel(branchLabel); - mv.visitInsn(Opcodes.ICONST_0); - mv.visitLabel(endLabel); - } else { - loopBlock.accept(this); - mv.visitJumpInsn(Opcodes.GOTO, endLabel); - - mv.visitLabel(branchLabel); - } + statement.genBCForRelOp(mv, branchLabel, endLabel, this); } @@ -644,6 +626,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(MethodCall methodCall) { + methodCall.receiver.accept(this); methodCall.arglist.accept(this); @@ -667,7 +650,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(NewClass methodCall) { - + mv.visitTypeInsn(Opcodes.NEW, methodCall.name.replace(".", "/")); mv.visitInsn(Opcodes.DUP); // creates Descriptor @@ -776,8 +759,10 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(Return aReturn) { - if(aReturn.retexpr instanceof BinaryExpr) - isBinaryExp = true; + + statement = new ReturnStmt(aReturn.retexpr); + + isBinaryExp = statement.isExprBinary(); aReturn.retexpr.accept(this); @@ -818,10 +803,12 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(WhileStmt whileStmt) { + + statement = new LoopStmt(whileStmt.expr, whileStmt.loopBlock); this.loopBlock = whileStmt.loopBlock; - if(whileStmt.expr instanceof BinaryExpr) - isBinaryExp = true; + + isBinaryExp = statement.isExprBinary(); whileStmt.expr.accept(this); @@ -1030,6 +1017,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(ArgumentList argumentList) { for (Expression al : argumentList.getArguments()) { + statement = new ArgumentExpr(al); al.accept(this); } } diff --git a/src/de/dhbwstuttgart/bytecode/IStatement.java b/src/de/dhbwstuttgart/bytecode/IStatement.java new file mode 100644 index 000000000..f8d610973 --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/IStatement.java @@ -0,0 +1,9 @@ +package de.dhbwstuttgart.bytecode; + +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; + +public interface IStatement { + public boolean isExprBinary(); + public void genBCForRelOp(MethodVisitor mv, Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod); +} diff --git a/src/de/dhbwstuttgart/bytecode/LoopStmt.java b/src/de/dhbwstuttgart/bytecode/LoopStmt.java new file mode 100644 index 000000000..109efd345 --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/LoopStmt.java @@ -0,0 +1,25 @@ +package de.dhbwstuttgart.bytecode; + +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.Statement; + +public class LoopStmt extends AStatement { + + private Statement loopBlock; + + public LoopStmt(Expression expr, Statement loopBlock) { + super(expr); + this.loopBlock = loopBlock; + } + + @Override + public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) { + this.loopBlock.accept(bytecodeGenMethod); + mv.visitJumpInsn(Opcodes.GOTO, endLabel); + mv.visitLabel(branchLabel); + } +} diff --git a/src/de/dhbwstuttgart/bytecode/ReturnStmt.java b/src/de/dhbwstuttgart/bytecode/ReturnStmt.java new file mode 100644 index 000000000..bd7477207 --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/ReturnStmt.java @@ -0,0 +1,14 @@ +package de.dhbwstuttgart.bytecode; + +import org.objectweb.asm.MethodVisitor; + +import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr; +import de.dhbwstuttgart.syntaxtree.statement.Expression; + +public class ReturnStmt extends AStatement { + + public ReturnStmt(Expression retexpr) { + super(retexpr); + } + +} From 51a2acdbafb56dc0df6bf868af52a79350e4ff40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 17 May 2018 11:42:03 +0200 Subject: [PATCH 80/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: test/typeinference/UnifyTest.java --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 29 +++++++++++++++++-- test/typeinference/UnifyTest.java | 4 +-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index cbfb5e7ea..1fdf6e860 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -154,8 +154,33 @@ public class JavaTXCompiler { ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } - return x;HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - }).collect(Collectors.toCollection(HashSet::new)); + return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE + })//.map( y -> { + if ((y.getLhsType() instanceof PlaceholderType) && (x.getRhsType() instanceof PlaceholderType)) { + + if (paraTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + } + if (returnTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + } + } + if ((x.getRhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); + } + if (returnTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); + } + } + return x; + + if (y.getLhsType().getVariance() != 0) { y.getRhsType().setVariance(y.getLhsType().getVariance()); } }) + .collect(Collectors.toCollection(HashSet::new)); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result); diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index 413617511..ac7ef2217 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -65,14 +65,14 @@ public class UnifyTest { } */ - + /* @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); //compiler.generateBytecode(); } - + */ /* @Test public void vector() throws IOException, ClassNotFoundException { From bc2cab8c959a258ed74dfddc80f9522e38626502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 17 May 2018 18:07:21 +0200 Subject: [PATCH 81/91] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: test/javFiles/Lambda.jav modified: test/javFiles/Lambda3.jav --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 33 +++++-------------- .../syntaxtree/factory/UnifyTypeFactory.java | 12 ++++++- .../unify/model/PlaceholderType.java | 1 + test/javFiles/Lambda.jav | 10 +++--- test/javFiles/Lambda3.jav | 1 + 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 1fdf6e860..1790a1955 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -155,31 +155,16 @@ public class JavaTXCompiler { } } return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - })//.map( y -> { - if ((y.getLhsType() instanceof PlaceholderType) && (x.getRhsType() instanceof PlaceholderType)) { - - if (paraTypeVarNames.contains(x.getLhsType().getName())) { - ((PlaceholderType)x.getLhsType()).setVariance((byte)1); - ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + }).map( y -> { + if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { + if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) { + ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance()); + } + if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { + ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance()); + } } - if (returnTypeVarNames.contains(x.getLhsType().getName())) { - ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); - ((PlaceholderType)x.getLhsType()).disableWildcardtable(); - } - } - if ((x.getRhsType() instanceof PlaceholderType)) { - if (paraTypeVarNames.contains(x.getRhsType().getName())) { - ((PlaceholderType)x.getRhsType()).setVariance((byte)1); - ((PlaceholderType)x.getRhsType()).disableWildcardtable(); - } - if (returnTypeVarNames.contains(x.getRhsType().getName())) { - ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); - ((PlaceholderType)x.getRhsType()).disableWildcardtable(); - } - } - return x; - - if (y.getLhsType().getVariance() != 0) { y.getRhsType().setVariance(y.getLhsType().getVariance()); } }) + return y; } ) .collect(Collectors.toCollection(HashSet::new)); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> result = unify.unify(xConsSet, finiteClosure); diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index e58ce50f6..e3f4de884 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -26,6 +26,8 @@ import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.unify.model.*; public class UnifyTypeFactory { + + private static ArrayList PLACEHOLDERS = new ArrayList<>(); public static FiniteClosure generateFC(List fromClasses) throws ClassNotFoundException { /* @@ -113,7 +115,15 @@ public class UnifyTypeFactory { } public static UnifyType convert(TypePlaceholder tph){ - return new PlaceholderType(tph.getName()); + PlaceholderType ntph = new PlaceholderType(tph.getName()); + int in = PLACEHOLDERS.indexOf(ntph); + if (in == -1) { + PLACEHOLDERS.add(ntph); + return ntph; + } + else { + return PLACEHOLDERS.get(in); + } } public static UnifyType convert(GenericRefType t){ diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index fe7758bea..efd83b5d2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -89,6 +89,7 @@ public final class PlaceholderType extends UnifyType{ return new PlaceholderType(name, true); } + /** * True if this placeholder is auto-generated, false if it is user-generated. */ diff --git a/test/javFiles/Lambda.jav b/test/javFiles/Lambda.jav index 378eb4d3e..2a2d57150 100644 --- a/test/javFiles/Lambda.jav +++ b/test/javFiles/Lambda.jav @@ -1,8 +1,8 @@ -class Lambda{ +class Lambda { -methode(){ + method(){ return ((f) -> f); -} + } } /* interface Fun0{ @@ -12,7 +12,7 @@ interface Fun0{ interface Fun1{ A apply(B b); } -*/ interface Fun2{ A apply(B b, C c); -} \ No newline at end of file +} +*/ diff --git a/test/javFiles/Lambda3.jav b/test/javFiles/Lambda3.jav index 9c4e960cd..9e22f3027 100644 --- a/test/javFiles/Lambda3.jav +++ b/test/javFiles/Lambda3.jav @@ -1,3 +1,4 @@ +import java.lang.String; public class Lambda2 { From 8baff8f376fd423481ce727a53a876621e271148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 17 May 2018 22:51:41 +0200 Subject: [PATCH 82/91] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java Variancenvererbung eingefuegt modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Variancenvererbung geloescht modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: ../../test/typeinference/UnifyTest.java --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 33 ++++++++++++- .../typeinference/unify/TypeUnifyTask.java | 46 +++++++------------ .../unify/model/PlaceholderType.java | 4 +- test/typeinference/UnifyTest.java | 6 ++- 4 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 1790a1955..74c080e48 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -24,6 +24,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.unify.distributeVariance; import de.dhbwstuttgart.typeinference.unify.inheritVariance; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; @@ -166,6 +167,7 @@ public class JavaTXCompiler { } return y; } ) .collect(Collectors.toCollection(HashSet::new)); + varianceInheritance(xConsSet); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result); @@ -180,7 +182,36 @@ public class JavaTXCompiler { new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } - + /** + * Vererbt alle Variancen + * @param eq The set of constraints + */ + private void varianceInheritance(Set eq) { + Set usedTPH = new HashSet<>(); + Set phSet = eq.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); + usedTPH.add(a); + //HashMap ht = new HashMap<>(); + //ht.put(a, a.getVariance()); + Set eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());}); + eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); + phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); + } +} 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 aec5653c6..710f2095c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -87,11 +87,14 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(logFile); } + /** * Vererbt alle Variancen * @param eq The set of constraints */ + /* PL 2018-05- 17 verschoben nach JavaTXCompiler private void varianceInheritance(Set eq) { + Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { Set pair = new HashSet<>(); if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); @@ -103,36 +106,20 @@ public class TypeUnifyTask extends RecursiveTask>> { phSetVariance.removeIf(x -> (x.getVariance() == 0)); while(!phSetVariance.isEmpty()) { PlaceholderType a = phSetVariance.remove(0); - HashMap ht = new HashMap<>(); - ht.put(a, a.getVariance()); - eq.stream().forEach(x -> { - x.getLhsType().accept(new inheritVariance(), ht); - 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()); - //} - }; - }); - eq.stream().forEach(x -> { - x.getRhsType().accept(new inheritVariance(), ht); - 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()); - //} - }; - }); + usedTPH.add(a); + //HashMap ht = new HashMap<>(); + //ht.put(a, a.getVariance()); + Set eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());}); + eq1 = new HashSet<>(eq); + eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); + eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); + phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } } +*/ @Override protected Set> compute() { Set> res = unify(eq, fc, parallel); @@ -156,7 +143,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Variancen auf alle Gleichungen vererben */ - varianceInheritance(eq); + //PL 2018-05-17 nach JavaTXCompiler verschoben + //varianceInheritance(eq); /* * ? extends ? extends Theta rausfiltern diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index efd83b5d2..bbd3b3e13 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -136,7 +136,9 @@ public final class PlaceholderType extends UnifyType{ UnifyType apply(Unifier unif) { if(unif.hasSubstitute(this)) { UnifyType ret = unif.getSubstitute(this); - ret.accept(new distributeVariance(), this.getVariance()); + //PL 2018-05-17 Auskommentierung muesste korrekt sein, + //bereits in JavaTXComplier Variancen gesetzt werden. + //ret.accept(new distributeVariance(), this.getVariance()); return ret; } return this; diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index ac7ef2217..2d6064cdd 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -34,10 +34,12 @@ public class UnifyTest { execute(new File(rootDirectory+"LambdaField.jav")); } */ + /* @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); } + */ /* @Test public void lambda3() throws IOException, ClassNotFoundException { @@ -65,14 +67,14 @@ public class UnifyTest { } */ - /* + @Test public void matrix() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Matrix.jav")); //JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"Matrix.jav")); //compiler.generateBytecode(); } - */ + /* @Test public void vector() throws IOException, ClassNotFoundException { From d81c06cdd944ac2b4acb81a7b137d6f5e3fc664b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 18 May 2018 00:03:07 +0200 Subject: [PATCH 83/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java Implementierung fuer FuNN eingefuegt deleted: ../../src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java wahrscheinlich bei FuNN-Regeln Variance setzen. --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 1 - .../unify/distributeVariance.java | 36 +++++++++++++++++-- .../typeinference/unify/inheritVariance.java | 18 ---------- 3 files changed, 33 insertions(+), 22 deletions(-) delete mode 100644 src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 74c080e48..6ac13b20e 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -25,7 +25,6 @@ import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.distributeVariance; -import de.dhbwstuttgart.typeinference.unify.inheritVariance; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; diff --git a/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java b/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java index 21fffde55..fe2e02d4a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java +++ b/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java @@ -1,6 +1,14 @@ package de.dhbwstuttgart.typeinference.unify; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import de.dhbwstuttgart.typeinference.unify.model.FunNType; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; +import de.dhbwstuttgart.typeinference.unify.model.TypeParams; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; public class distributeVariance extends visitUnifyTypeVisitor { @@ -10,10 +18,32 @@ public class distributeVariance extends visitUnifyTypeVisitor { if (phty.getVariance() == 0) { phty.setVariance(ht); } - else if (phty.getVariance() != ht) { - phty.setVariance(0); - } + //PL 2018-05-17 urspruengliche Variance nicht veraendern + //else if (phty.getVariance() != ht) { + // phty.setVariance(0); + //} } return phty; } + + public FunNType visit(FunNType funnty, Integer ht) { + List param = new ArrayList<>(funnty.getTypeParams().get().length); + param.addAll(Arrays.asList(funnty.getTypeParams().get())); + UnifyType resultType = param.remove(param.size()-1); + Integer htInverse = 0; + if (ht == 1) { + htInverse = -1; + } + if (ht == -1) { + htInverse = 1; + } + Integer htInverse1 = htInverse; + param = param.stream() + .map(x -> x.accept(this, htInverse1)) + .collect(Collectors.toCollection(ArrayList::new)); + param.add(resultType.accept(this, ht)); + return FunNType.getFunNType(new TypeParams(param)); + } + + } diff --git a/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java b/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java deleted file mode 100644 index 1b6a4d108..000000000 --- a/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.dhbwstuttgart.typeinference.unify; - -import java.util.HashMap; - -import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; - -public class inheritVariance extends visitUnifyTypeVisitor> { - - @Override - public PlaceholderType visit(PlaceholderType phty, HashMap ht) { - if (ht.containsKey(phty)) { - if (phty.getVariance() == 0) { - phty.setVariance(ht.get(phty)); - } - } - return phty; - } -} From 6b1896f58cb66fc54315eb67a72cc545bd2f0937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 18 May 2018 09:55:45 +0200 Subject: [PATCH 84/91] modified: src/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java greaterFUNN und smallFUNN fuer generierte TPHs Variance gesetzt modified: test/javFiles/Lambda.jav vom bytecode ruebergeholt --- .../typeinference/unify/RuleSet.java | 35 +++++++++++++++---- .../unify/distributeVariance.java | 23 +++++++----- test/javFiles/Lambda.jav | 22 +++++------- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index a576edc3c..5631724b5 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -24,6 +24,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.model.WildcardType; +import de.dhbwstuttgart.typeinference.unify.distributeVariance; import java.io.FileWriter; import java.io.IOException; @@ -778,7 +779,8 @@ public class RuleSet implements IRuleSet{ } ); return Optional.of(result); } - + + @Override public Optional> greaterFunN(UnifyPair pair) { if(pair.getPairOp() != PairOperator.SMALLERDOT) @@ -794,13 +796,22 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet(); - UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()]; - for(int i = 0; i < freshPlaceholders.length; i++) - freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); + Integer variance = ((PlaceholderType)rhsType).getVariance(); + Integer inversVariance = distributeVariance.inverseVariance(variance); + UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()]; + for(int i = 0; i < freshPlaceholders.length-1; i++) { + freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance); + } + freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance); result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) + + for(int i = 0; i < funNLhsType.getTypeParams().size()-1; i++) { result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); result.stream().forEach(x -> { UnifyType l = x.getLhsType(); @@ -826,13 +837,23 @@ public class RuleSet implements IRuleSet{ Set result = new HashSet(); + Integer variance = ((PlaceholderType)lhsType).getVariance(); + Integer inversVariance = distributeVariance.inverseVariance(variance); + UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()]; - for(int i = 0; i < freshPlaceholders.length; i++) + for(int i = 0; i < freshPlaceholders.length-1; i++) { freshPlaceholders[i] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance); + } + freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance); result.add(new UnifyPair(freshPlaceholders[funNRhsType.getTypeParams().size()-1], funNRhsType.getTypeParams().get(funNRhsType.getTypeParams().size()-1), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); - for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) + + for(int i = 0; i < funNRhsType.getTypeParams().size()-1; i++) { result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); + } + result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); result.stream().forEach(x -> { UnifyType l = x.getLhsType(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java b/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java index fe2e02d4a..1779c9410 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java +++ b/src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java @@ -11,6 +11,18 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; public class distributeVariance extends visitUnifyTypeVisitor { + + public static int inverseVariance(int variance) { + Integer ret = 0; + if (variance == 1) { + ret = -1; + } + if (variance == -1) { + ret = 1; + } + return ret; + } + @Override public PlaceholderType visit(PlaceholderType phty, Integer ht) { @@ -30,16 +42,9 @@ public class distributeVariance extends visitUnifyTypeVisitor { List param = new ArrayList<>(funnty.getTypeParams().get().length); param.addAll(Arrays.asList(funnty.getTypeParams().get())); UnifyType resultType = param.remove(param.size()-1); - Integer htInverse = 0; - if (ht == 1) { - htInverse = -1; - } - if (ht == -1) { - htInverse = 1; - } - Integer htInverse1 = htInverse; + Integer htInverse = inverseVariance(ht); param = param.stream() - .map(x -> x.accept(this, htInverse1)) + .map(x -> x.accept(this, htInverse)) .collect(Collectors.toCollection(ArrayList::new)); param.add(resultType.accept(this, ht)); return FunNType.getFunNType(new TypeParams(param)); diff --git a/test/javFiles/Lambda.jav b/test/javFiles/Lambda.jav index 2a2d57150..3ff77fd18 100644 --- a/test/javFiles/Lambda.jav +++ b/test/javFiles/Lambda.jav @@ -1,18 +1,12 @@ -class Lambda { +import java.lang.Integer; - method(){ - return ((f) -> f); +public class Lambda { + + m () { + var lam1 = (Integer x) -> { + return x; + }; + return lam1; } } -/* -interface Fun0{ - A apply(); -} -interface Fun1{ - A apply(B b); -} -interface Fun2{ - A apply(B b, C c); -} -*/ From 7ea6777906f5523a63a844edd06c5333c6206791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 18 May 2018 13:12:49 +0200 Subject: [PATCH 85/91] modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../javFiles/Lambda.jav modified: ../typeinference/UnifyTest.java --- .../typeinference/unify/TypeUnifyTask.java | 16 ++++++++-------- test/javFiles/Lambda.jav | 3 ++- test/typeinference/UnifyTest.java | 11 +++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 710f2095c..1f9a67d16 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -297,10 +297,10 @@ 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 - //Begruendung: Wenn in der Substitution keine Veraenderung - //(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt. + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) + //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst + //eqPrimePrime Veraenderungen in subst repraesentieren. eqPrimePrimeSet.add(eqPrime); else if(eqPrimePrime.isPresent()) { //System.out.println("nextStep: " + eqPrimePrime.get()); @@ -317,10 +317,10 @@ 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 - //(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt - //Begruendung: Wenn in der Substitution keine Veraenderung - //(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt. + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) + //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst + //eqPrimePrime Veraenderungen in subst repraesentieren. try { if (isSolvedForm(eqPrime)) { logFile.write(eqPrime.toString()+"\n"); diff --git a/test/javFiles/Lambda.jav b/test/javFiles/Lambda.jav index 3ff77fd18..553dc496a 100644 --- a/test/javFiles/Lambda.jav +++ b/test/javFiles/Lambda.jav @@ -1,9 +1,10 @@ import java.lang.Integer; +import java.lang.Number; public class Lambda { m () { - var lam1 = (Integer x) -> { + var lam1 = (x) -> { return x; }; return lam1; diff --git a/test/typeinference/UnifyTest.java b/test/typeinference/UnifyTest.java index 2d6064cdd..2a496166b 100644 --- a/test/typeinference/UnifyTest.java +++ b/test/typeinference/UnifyTest.java @@ -28,10 +28,11 @@ public class UnifyTest { public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav")); } - + */ +/* @Test public void lambda() throws IOException, ClassNotFoundException { - execute(new File(rootDirectory+"LambdaField.jav")); + execute(new File(rootDirectory+"Lambda.jav")); } */ /* @@ -45,6 +46,12 @@ public class UnifyTest { public void lambda3() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda3.jav")); } + + @Test + public void lambdafield() throws IOException, ClassNotFoundException { + execute(new File(rootDirectory+"LambdaField.jav")); + } + @Test public void mathStruc() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"mathStruc.jav")); From b5a601d798250324360ad7221839c2c503dcd8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 19 May 2018 09:50:57 +0200 Subject: [PATCH 86/91] modified: TypeUnifyTask.java Varianceweitergabe in den verschiedenen Cases eingefuegt Erste Zaehlungen eingefuegt --- .../typeinference/unify/TypeUnifyTask.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1f9a67d16..4a7e27503 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -74,6 +74,12 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean parallel; + Integer nOfUnify = 0; + + Integer noUndefPair = 0; + + Integer noBacktracking = 0; + public TypeUnifyTask() { rules = new RuleSet(); } @@ -137,7 +143,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 1: Repeated application of reduce, adapt, erase, swap */ - writeLog("Unifikation: " + eq.toString()); + nOfUnify++; + writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); /* @@ -212,8 +219,9 @@ public class TypeUnifyTask extends RecursiveTask>> { // 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()) { + noUndefPair++; for (UnifyPair up : undefinedPairs) { - writeLog("UndefinedPairs; " + up); + writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); writeLog("BasePair; " + up.getBasePair()); } Set> error = new HashSet<>(); @@ -400,13 +408,13 @@ public class TypeUnifyTask extends RecursiveTask>> { if (xi.isPresent()) { variance = xi.get(); } - if (variance == 1 && nextSetasList.size() > 1) { - List> al = new ArrayList<>(nextSetasList.size()); - for (int ii = 0; ii < nextSetasList.size();ii++) { - al.add(0,nextSetasList.get(ii)); - } - nextSetasList = al; - } + //if (variance == 1 && nextSetasList.size() > 1) { + // List> al = new ArrayList<>(nextSetasList.size()); + // for (int ii = 0; ii < nextSetasList.size();ii++) { + // al.add(0,nextSetasList.get(ii)); + // } + // nextSetasList = al; + //} //Set a = nextSetasListIt.next(); /*if (nextSetasList.size()>1) {zu loeschen if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) @@ -552,6 +560,8 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("nextSetasList: " + nextSetasList.toString()); writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); System.out.println(""); + noBacktracking++; + writeLog("Number of Backtracking: " + noBacktracking); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { // return result; @@ -1010,6 +1020,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); UnifyType extAPrime = new ExtendsType(aPrime); UnifyType thetaPrime = extThetaPrime.getExtendedType(); Set resultPrime = new HashSet<>(); @@ -1035,6 +1046,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); + ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); UnifyType supAPrime = new SuperType(aPrime); UnifyType thetaPrime = subThetaPrime.getSuperedType(); Set resultPrime = new HashSet<>(); @@ -1074,6 +1086,7 @@ public class TypeUnifyTask extends RecursiveTask>> { 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)); } @@ -1104,6 +1117,8 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog(resultPrime.toString()); UnifyType freshTph = PlaceholderType.freshPlaceholder(); + + ((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)); From 06a0cb8eaf60ae1d8255eac78f510e6b20ba48cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 19 May 2018 10:13:08 +0200 Subject: [PATCH 87/91] modified: TypeUnifyTask.java noAllErasedElements eingefuegt --- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 4a7e27503..87798e421 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -78,6 +78,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Integer noUndefPair = 0; + Integer noAllErasedElements = 0; + Integer noBacktracking = 0; public TypeUnifyTask() { @@ -559,9 +561,11 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); - System.out.println(""); + noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); + writeLog("Number erased Elements (undef): " + noAllErasedElements.toString()); noBacktracking++; writeLog("Number of Backtracking: " + noBacktracking); + System.out.println(""); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { // return result; From c597b0430aaa4a3e1b68deb991716645bf49bbf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 22 May 2018 17:10:07 +0200 Subject: [PATCH 88/91] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java cardProd als Variable eingfuegt modified: ../../src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java toString() eingfuegt modified: ../../src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java toString() eingfuegt modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java BinaryOp <. statt =. modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Bei nicht importierten (result []) undefinPair gesetzt modified: ../javFiles/Matrix.jav falsche importe rausgenommen --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 3 +- .../syntaxtree/ClassOrInterface.java | 4 ++ .../syntaxtree/GenericDeclarationList.java | 4 ++ .../typeinference/typeAlgo/TYPEStmt.java | 36 ++++++++-------- .../typeinference/unify/TypeUnifyTask.java | 42 ++++++++++++++----- test/javFiles/Matrix.jav | 8 ++-- 6 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 6ac13b20e..68bb25853 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -111,7 +111,8 @@ public class JavaTXCompiler { logFile.write(ASTTypePrinter.print(sf)); } logFile.flush(); - for (List> xCons : unifyCons.cartesianProduct()) { + Set>> cardProd = unifyCons.cartesianProduct(); + for (List> xCons : cardProd ){ Set xConsSet = new HashSet<>(); for (Constraint constraint : xCons) { xConsSet.addAll(constraint); diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index 72097fc03..e0c09e92a 100644 --- a/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -106,4 +106,8 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ public Collection getSuperInterfaces() { return implementedInterfaces; } + + public String toString() { + return this.name.toString() + this.genericClassParameters.toString(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java index e316aa6b0..6a2646845 100644 --- a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java +++ b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java @@ -31,4 +31,8 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.getType(), integer, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.getType(), longg, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), longg, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.getType(), floatt, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), floatt, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); numeric = new Constraint<>(); - numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.EQUALSDOT)); - numeric.add(new Pair(binary.getType(), doublee, PairOperator.EQUALSDOT)); + numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), doublee, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); /* In Java passiert bei den binären Operatoren eine sogenannte Type Promotion: diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 87798e421..1d5ca5647 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -142,6 +142,12 @@ public class TypeUnifyTask extends RecursiveTask>> { * @return The set of all principal type unifiers */ protected Set> unify(Set eq, IFiniteClosure fc, boolean parallel) { + Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) + ).collect(Collectors.toCollection(HashSet::new)); + writeLog(nOfUnify.toString() + " AA: " + aas.toString()); + if (aas.isEmpty()) { + System.out.println(""); + } /* * Step 1: Repeated application of reduce, adapt, erase, swap */ @@ -789,6 +795,9 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> x1 = unifyCase1(pair, fc); //System.out.println(x1); result.get(0).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC => Abbruch + } } else { Set s1 = new HashSet<>(); @@ -802,7 +811,11 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 2: (a <.? ? ext Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(1).add(unifyCase2(pair, fc)); + Set> x1 = unifyCase2(pair, fc); + result.get(1).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } } else { Set s1 = new HashSet<>(); @@ -815,7 +828,11 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 3: (a <.? ? sup Theta') else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(2).add(unifyCase3(pair, fc)); + Set> x1 = unifyCase3(pair, fc); + result.get(2).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } } else { Set s1 = new HashSet<>(); @@ -833,9 +850,11 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 5: (Theta <. a) else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); - if (rhsType.getName().equals("A")) - System.out.println(); - result.get(4).add(unifyCase5(pair, fc)); + Set> x1 = unifyCase5(pair, fc); + result.get(4).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } } else { Set s1 = new HashSet<>(); @@ -858,8 +877,11 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case 8: (Theta <.? a) else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); - result.get(7).add( - unifyCase8(pair, fc)); + Set> x1 = unifyCase8(pair, fc); + result.get(7).add(x1); + if (x1.isEmpty()) { + undefined.add(pair); //Theta ist nicht im FC + } } else { Set s1 = new HashSet<>(); @@ -892,9 +914,7 @@ public class TypeUnifyTask extends RecursiveTask>> { PlaceholderType a = (PlaceholderType)pair.getLhsType(); UnifyType thetaPrime = pair.getRhsType(); byte variance = pair.getVariance(); - if (a.getName().equals("D")) { - System.out.print(""); - } + Set> result = new HashSet<>(); boolean allGen = thetaPrime.getTypeParams().size() > 0; @@ -906,6 +926,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] + + //PL 18-02-06 entfernt, kommt durch unify wieder rein //cs.add(thetaPrime); //PL 18-02-06 entfernt diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index ad8d735e8..8b01c235b 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -1,7 +1,5 @@ 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;} @@ -17,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++; } From 0f29bc038a8b1dc514ea9fbeed00258a7f21e3f5 Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 23 May 2018 15:38:41 +0200 Subject: [PATCH 89/91] =?UTF-8?q?Bugs=20gefixt.=20Tests=20f=C3=BCr=20relat?= =?UTF-8?q?ionalen=20Operatoren(GreaterEqualTest,=20...)=20laufen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Für Typplaceholder werden Generics verwendet. Neue Tests angefügt. --- .../dhbwstuttgart/bytecode/BytecodeGen.java | 7 +- .../bytecode/BytecodeGenMethod.java | 220 +++++++++--------- .../descriptor/DescriptorToString.java | 17 +- .../bytecode/descriptor/TypeToDescriptor.java | 5 +- .../bytecode/signature/Signature.java | 51 +++- .../bytecode/signature/TypeToSignature.java | 2 + test/bytecode/BinaryTest.java | 40 ++++ test/bytecode/FacTest.java | 44 ++++ test/bytecode/PlusTest.java | 2 +- test/bytecode/RelOpsTest.java | 44 ++++ test/bytecode/javFiles/BinaryInMeth.jav | 11 + test/bytecode/javFiles/Fac.jav | 16 ++ test/bytecode/javFiles/Gen.jav | 2 +- test/bytecode/javFiles/Matrix.jav | 26 +-- test/bytecode/javFiles/Op.jav | 2 +- test/bytecode/javFiles/Plus.jav | 2 +- test/bytecode/javFiles/RelOps.jav | 7 + test/bytecode/javFiles/While.jav | 4 + test/logFiles/log | 107 +++++++++ 19 files changed, 467 insertions(+), 142 deletions(-) create mode 100644 test/bytecode/BinaryTest.java create mode 100644 test/bytecode/FacTest.java create mode 100644 test/bytecode/RelOpsTest.java create mode 100644 test/bytecode/javFiles/BinaryInMeth.jav create mode 100644 test/bytecode/javFiles/Fac.jav create mode 100644 test/bytecode/javFiles/RelOps.jav create mode 100644 test/logFiles/log diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index 36c7173a5..f9bf72ed7 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -117,7 +117,7 @@ public class BytecodeGen implements ASTVisitor { boolean isConsWithNoParamsVisited = false; for(ResultSet rs : listOfResultSets) { resultSet = rs; - + for(Constructor c : classOrInterface.getConstructors()) { if(!isConsWithNoParamsVisited) c.accept(this); @@ -191,13 +191,13 @@ public class BytecodeGen implements ASTVisitor { System.out.println(acc); /*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/ - boolean hasGenInParameterList = genericsAndBounds.containsKey(resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())); + boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH "); /*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht, * prüfe, ob einer der Parameter Typ-Variable als Typ hat*/ if(!hasGenInParameterList) { for(String paramName : methodParamsAndTypes.keySet()) { String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor()); - if(genericsAndBounds.containsKey(typeOfParam)) { + if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")) { hasGenInParameterList = true; break; } @@ -213,6 +213,7 @@ public class BytecodeGen implements ASTVisitor { boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList; /* if method has generics or return type is TPH, create signature */ + // zwite operand muss weggelassen werden if(hasGen||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) { // resultset hier zum testen Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet); diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 8b928a312..8bb7dca14 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -29,8 +29,6 @@ import org.objectweb.asm.signature.SignatureWriter; import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString; import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor; import de.dhbwstuttgart.bytecode.signature.Signature; -import de.dhbwstuttgart.bytecode.signature.TypeToSignature; -import de.dhbwstuttgart.bytecode.signature.TypeToString; import de.dhbwstuttgart.bytecode.utilities.KindOfLambda; import de.dhbwstuttgart.bytecode.utilities.Lambda; import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall; @@ -55,20 +53,17 @@ public class BytecodeGenMethod implements StatementVisitor { HashMap genericsAndBoundsMethod; private HashMap genericsAndBounds; private boolean isBinaryExp = false; - - private IStatement statement; + + private IStatement statement = null; // for tests ** private String fieldName; private String fieldDesc; private Expression rightSideTemp; - + private boolean isRightSideALambda = false; private KindOfLambda kindOfLambda; private HashMap classFiles; - - private boolean isAssignStmt = false; - private Statement loopBlock; private ArrayList varsFunInterface = new ArrayList<>();; @@ -113,7 +108,7 @@ public class BytecodeGenMethod implements StatementVisitor { private String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) { return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor()); } - + @Override public void visit(Block block) { for (Statement stmt : block.getStatements()) { @@ -138,7 +133,7 @@ public class BytecodeGenMethod implements StatementVisitor { mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name)); if (isBinaryExp) { - getVlaueIns(getResolvedType(localVar.getType())); + doUnboxing(getResolvedType(localVar.getType())); } } @@ -151,8 +146,6 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(Assign assign) { statement = new AssignStmt(assign.rightSide); - isAssignStmt = true; - // if the right side is a lambda => the left side must be a functional interface if (assign.rightSide instanceof LambdaExpression) { isRightSideALambda = true; @@ -161,7 +154,6 @@ public class BytecodeGenMethod implements StatementVisitor { } isBinaryExp = statement.isExprBinary(); - if (assign.lefSide instanceof AssignToField) { // load_0, ldc or .. then putfield @@ -171,26 +163,24 @@ public class BytecodeGenMethod implements StatementVisitor { } if (isBinaryExp) { BinaryExpr binary = (BinaryExpr) assign.rightSide; - String lexpType = getResolvedType(binary.lexpr.getType()); - String rexpType = getResolvedType(binary.rexpr.getType()); - getValueOfIns(getLargerType(lexpType, rexpType)); + String binaryType = getResolvedType(binary.getType()); + doBoxing(binaryType); isBinaryExp = false; } assign.lefSide.accept(this); - - isAssignStmt =false; - } + statement = null; + } @Override public void visit(BinaryExpr binary) { - + String lexpType = getResolvedType(binary.lexpr.getType()); String rexpType = getResolvedType(binary.rexpr.getType()); - - String largerType = getLargerType(lexpType,rexpType); + + String largerType = getLargerType(lexpType, rexpType); String typeOfBinary = getResolvedType(binary.getType()); - + if (typeOfBinary.equals(Type.getInternalName(String.class))) { mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(StringBuilder.class)); mv.visitInsn(Opcodes.DUP); @@ -200,23 +190,21 @@ public class BytecodeGenMethod implements StatementVisitor { Label endLabel = new Label(); // this case for while loops - if(statement instanceof LoopStmt) + if (statement instanceof LoopStmt) mv.visitLabel(endLabel); - + binary.lexpr.accept(this); - - if(!lexpType.equals(rexpType) && - !lexpType.equals(largerType)) + + if (!lexpType.equals(rexpType) && !lexpType.equals(largerType)) doCast(lexpType, largerType); - + binary.rexpr.accept(this); - - if(!lexpType.equals(rexpType) && - !rexpType.equals(largerType)) + + if (!lexpType.equals(rexpType) && !rexpType.equals(largerType)) doCast(rexpType, largerType); - + Operator op = binary.operation; - + switch (op) { case ADD: doVisitAddOpInsn(largerType); @@ -243,28 +231,31 @@ public class BytecodeGenMethod implements StatementVisitor { case BIGGERTHAN: case BIGGEREQUAL: Label branchLabel = new Label(); - doVisitRelOpInsn(op,largerType, branchLabel, endLabel); + doVisitRelOpInsn(op, largerType, branchLabel, endLabel); break; - + default: break; } } + /* + * Diese Methode wird nicht mehr gebraucht, da es jetzt nicht möglich ist, dass + * solche Fälle: Integer -> Integer (OP) Short ,... usw, nicht vorkommen! + */ private String getLargerType(String lexpType, String rexpType) { - if(lexpType.equals(Type.getInternalName(String.class)) || - rexpType.equals(Type.getInternalName(String.class))) { + if (lexpType.equals(Type.getInternalName(String.class)) + || rexpType.equals(Type.getInternalName(String.class))) { return Type.getInternalName(String.class); - } else - if(lexpType.equals(Type.getInternalName(Double.class)) || - rexpType.equals(Type.getInternalName(Double.class))) { + } else if (lexpType.equals(Type.getInternalName(Double.class)) + || rexpType.equals(Type.getInternalName(Double.class))) { return Type.getInternalName(Double.class); - } else if(lexpType.equals(Type.getInternalName(Float.class)) || - rexpType.equals(Type.getInternalName(Float.class))) { + } else if (lexpType.equals(Type.getInternalName(Float.class)) + || rexpType.equals(Type.getInternalName(Float.class))) { return Type.getInternalName(Float.class); - } else if(lexpType.equals(Type.getInternalName(Long.class)) || - rexpType.equals(Type.getInternalName(Long.class))) { + } else if (lexpType.equals(Type.getInternalName(Long.class)) + || rexpType.equals(Type.getInternalName(Long.class))) { return Type.getInternalName(Long.class); } else { return Type.getInternalName(Integer.class); @@ -276,19 +267,19 @@ public class BytecodeGenMethod implements StatementVisitor { case "java/lang/Long": mv.visitInsn(Opcodes.I2L); break; - + case "java/lang/Double": - if(sourceType.equals(Type.getInternalName(Long.class))) { + if (sourceType.equals(Type.getInternalName(Long.class))) { mv.visitInsn(Opcodes.L2D); - } else if(sourceType.equals(Type.getInternalName(Float.class))) { + } else if (sourceType.equals(Type.getInternalName(Float.class))) { mv.visitInsn(Opcodes.F2D); } else { mv.visitInsn(Opcodes.I2D); } break; - + case "java/lang/Float": - if(sourceType.equals(Type.getInternalName(Long.class))) { + if (sourceType.equals(Type.getInternalName(Long.class))) { mv.visitInsn(Opcodes.L2F); } else { mv.visitInsn(Opcodes.I2F); @@ -296,14 +287,18 @@ public class BytecodeGenMethod implements StatementVisitor { break; // braucht man eigentlic nicht, muss getestet werden case "java/lang/String": - if(sourceType.equals(Type.getInternalName(Double.class))) { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", "(D)Ljava/lang/String;", false); - } else if(sourceType.equals(Type.getInternalName(Long.class))) { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", "(J)Ljava/lang/String;", false); - } else if(sourceType.equals(Type.getInternalName(Float.class))) { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", "(F)Ljava/lang/String;", false); + if (sourceType.equals(Type.getInternalName(Double.class))) { + mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", + "(D)Ljava/lang/String;", false); + } else if (sourceType.equals(Type.getInternalName(Long.class))) { + mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", + "(J)Ljava/lang/String;", false); + } else if (sourceType.equals(Type.getInternalName(Float.class))) { + mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", + "(F)Ljava/lang/String;", false); } else { - mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", "(I)Ljava/lang/String;", false); + mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "valueOf", + "(I)Ljava/lang/String;", false); } break; default: @@ -312,7 +307,7 @@ public class BytecodeGenMethod implements StatementVisitor { } private void doVisitRelOpInsn(Operator op, String typeOfBinary, Label branchLabel, Label endLabel) { - + switch (typeOfBinary) { case "java/lang/Long": mv.visitInsn(Opcodes.LCMP); @@ -343,9 +338,9 @@ public class BytecodeGenMethod implements StatementVisitor { default: break; } - - statement.genBCForRelOp(mv, branchLabel, endLabel,this); - + + statement.genBCForRelOp(mv, branchLabel, endLabel, this); + break; } } @@ -368,8 +363,8 @@ public class BytecodeGenMethod implements StatementVisitor { default: break; } + statement.genBCForRelOp(mv, branchLabel, endLabel, this); - } private void doVisitModOpInsn(String typeOfBinary) { @@ -532,7 +527,7 @@ public class BytecodeGenMethod implements StatementVisitor { cw.visitInnerClass("java/lang/invoke/MethodHandles$Lookup", "java/lang/invoke/MethodHandles", "Lookup", Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL); - generateBCForFunN(lambdaExpression,typeErasure); + generateBCForFunN(lambdaExpression, typeErasure); } private void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc) { @@ -626,7 +621,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(MethodCall methodCall) { - + methodCall.receiver.accept(this); methodCall.arglist.accept(this); @@ -634,7 +629,7 @@ public class BytecodeGenMethod implements StatementVisitor { genericsAndBoundsMethod, genericsAndBounds); String mDesc = method.accept(new DescriptorToString(resultSet)); - // is methodCall.receiver functional Interface)? + // is methodCall.receiver functional Interface)? if (varsFunInterface.contains(methodCall.receiver.getType())) { mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, getResolvedType(methodCall.receiver.getType()), methodCall.name, mDesc, false); @@ -650,7 +645,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(NewClass methodCall) { - + mv.visitTypeInsn(Opcodes.NEW, methodCall.name.replace(".", "/")); mv.visitInsn(Opcodes.DUP); // creates Descriptor @@ -679,40 +674,40 @@ public class BytecodeGenMethod implements StatementVisitor { public void visit(UnaryExpr unaryExpr) { unaryExpr.expr.accept(this); Operation op = unaryExpr.operation; - + String typeOfUnary = getResolvedType(unaryExpr.getType()); - + boolean isIncOrDec = false; - + switch (op) { case POSTDECREMENT: case POSTINCREMENT: - if(isAssignStmt) + if (statement instanceof AssignStmt) mv.visitInsn(Opcodes.DUP); genBCForIncAndDec(op, typeOfUnary); - getValueOfIns(typeOfUnary); + doBoxing(typeOfUnary); isIncOrDec = true; break; case PREDECREMENT: case PREINCREMENT: genBCForIncAndDec(op, typeOfUnary); - getValueOfIns(typeOfUnary); - if(isAssignStmt) + doBoxing(typeOfUnary); + if (statement instanceof AssignStmt) mv.visitInsn(Opcodes.DUP); isIncOrDec = true; break; - + case MINUS: doVisitNegIns(typeOfUnary); break; default: break; } - + // Für Byte und Short muss noch einen Cast geben i2b, i2s // das wird später gemacht, da bytecode für cast noch nicht erzeugt wird - - if(isIncOrDec && (unaryExpr.expr instanceof LocalVar)) { + + if (isIncOrDec && (unaryExpr.expr instanceof LocalVar)) { LocalVar local = (LocalVar) unaryExpr.expr; mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.get(local.name)); } @@ -733,14 +728,14 @@ public class BytecodeGenMethod implements StatementVisitor { mv.visitInsn(Opcodes.INEG); break; } - + } private void genBCForIncAndDec(Operation op, String typeOfUnary) { - - getVlaueIns(typeOfUnary); - doAssign(typeOfUnary, 1.0, true); - + + doUnboxing(typeOfUnary); + loadValue(typeOfUnary, 1.0, true); + switch (op) { case POSTDECREMENT: case PREDECREMENT: @@ -751,7 +746,7 @@ public class BytecodeGenMethod implements StatementVisitor { case PREINCREMENT: doVisitAddOpInsn(typeOfUnary); break; - + default: break; } @@ -759,22 +754,19 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(Return aReturn) { - statement = new ReturnStmt(aReturn.retexpr); - isBinaryExp = statement.isExprBinary(); - + aReturn.retexpr.accept(this); - + if (isBinaryExp) { BinaryExpr binary = (BinaryExpr) aReturn.retexpr; - String lexpType = getResolvedType(binary.lexpr.getType()); - String rexpType = getResolvedType(binary.rexpr.getType()); - getValueOfIns(getLargerType(lexpType, rexpType)); + doBoxing(getResolvedType(binary.getType())); isBinaryExp = false; } - + mv.visitInsn(Opcodes.ARETURN); + statement = null; } @Override @@ -787,7 +779,8 @@ public class BytecodeGenMethod implements StatementVisitor { // mv.visitMethodInsn(Opcodes.INVOKESTATIC, // staticClassName.getType().toString().replace(".", "/"), // staticClassName.toString(), staticClassName.getType().toString(), false); - //mv.visitFieldInsn(Opcodes.GETSTATIC, getResolvedType(staticClassName.getType()), fieldName, fieldDesc); + // mv.visitFieldInsn(Opcodes.GETSTATIC, + // getResolvedType(staticClassName.getType()), fieldName, fieldDesc); throw new NotImplementedException("Static noch nicht implementiert!"); } @@ -803,16 +796,11 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(WhileStmt whileStmt) { - statement = new LoopStmt(whileStmt.expr, whileStmt.loopBlock); - this.loopBlock = whileStmt.loopBlock; - - isBinaryExp = statement.isExprBinary(); - whileStmt.expr.accept(this); - isBinaryExp = false; + statement = null; } @Override @@ -825,12 +813,13 @@ public class BytecodeGenMethod implements StatementVisitor { public void visit(Literal literal) { Object value = literal.value; String typeOfLiteral = getResolvedType(literal.getType()); - // Name der Methode muss geändert werden - doAssign(typeOfLiteral, value, false); - + // Der Wert des Literals wird auf den Stack geladen und + // geboxt, wenn es nötig ist. + loadValue(typeOfLiteral, value, false); } - private void getVlaueIns(String type) { + // Unboxing: RefType -> prim + private void doUnboxing(String type) { switch (type) { case "java/lang/String": mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(StringBuilder.class), "append", @@ -860,11 +849,13 @@ public class BytecodeGenMethod implements StatementVisitor { case "java/lang/Character": break; default: + // mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", + // "()I", false); break; } } - private void doAssign(String type, Object value, boolean isOperator) { + private void loadValue(String type, Object value, boolean isOperator) { switch (type) { case "java/lang/String": mv.visitLdcInsn(String.valueOf(value)); @@ -895,17 +886,21 @@ public class BytecodeGenMethod implements StatementVisitor { visitCharLiteral((Character) value); break; default: + // wenn die Typ des Literals = Number ist, wird integer-value + // verwendet + // visitIntegerLiteral(((Double) value).intValue(), false); break; } - - if(!type.equals("java/lang/String")&&!type.equals("java/lang/Boolean")) { + // Boxing + if (!type.equals("java/lang/String") && !type.equals("java/lang/Boolean")) { if (!this.isBinaryExp && !isOperator) - getValueOfIns(type); + doBoxing(type); } - + } - private void getValueOfIns(String type) { + // Boxing: prim -> RefType + private void doBoxing(String type) { switch (type) { case "java/lang/String": mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", @@ -943,7 +938,7 @@ public class BytecodeGenMethod implements StatementVisitor { private void visitCharLiteral(Character value) { mv.visitIntInsn(Opcodes.BIPUSH, (int) value); - + } private void visitDoubleLiteral(Double value) { @@ -1019,6 +1014,7 @@ public class BytecodeGenMethod implements StatementVisitor { for (Expression al : argumentList.getArguments()) { statement = new ArgumentExpr(al); al.accept(this); + statement = null; } } @@ -1042,12 +1038,12 @@ public class BytecodeGenMethod implements StatementVisitor { varsFunInterface.add(assignLeftSide.localVar.getType()); int index = paramsAndLocals.size(); String var = assignLeftSide.localVar.name; - if(!paramsAndLocals.containsKey(var)) { + if (!paramsAndLocals.containsKey(var)) { paramsAndLocals.put(var, index + 1); - }else { + } else { paramsAndLocals.put(var, index); } - + mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.size()); // Debug::: diff --git a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java index cba540f8b..0e97ca4c3 100644 --- a/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java +++ b/src/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java @@ -46,12 +46,18 @@ public class DescriptorToString implements DescriptorVisitor{ }else if(method.getGenericsAndBounds().containsKey(fpDesc)){ desc += "L"+method.getGenericsAndBounds().get(fpDesc)+ ";"; }else { - desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; +// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; + String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()); + if(resType.subSequence(0, 4).equals("TPH ")) { + desc += "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";"; + } else { + desc += "L"+resType+ ";"; + } } } //TODO: generate a class java%% ... %% else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){ - desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "%").replace("<", "%%").replace(">", "%%")+ ";"; + desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";"; } else { desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; @@ -68,7 +74,12 @@ public class DescriptorToString implements DescriptorVisitor{ }else if(method.getGenericsAndBounds().containsKey(ret)){ desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";"; }else { - desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; + String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()); + if(resType.subSequence(0, 4).equals("TPH ")) { + desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";"; + } else { + desc += ")" + "L"+resType+ ";"; + } } }else { desc += ")" + "L"+resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";"; diff --git a/src/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java b/src/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java index e374bb930..e5c853b3d 100644 --- a/src/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java +++ b/src/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java @@ -13,6 +13,8 @@ public class TypeToDescriptor implements TypeVisitor{ @Override public String visit(RefType refType) { return refType.getName().toString().replace(".", "/"); +// String t = refType.getName().toString().replace(".", "/"); +// return t.equals("Fun1")?(t+"$$"):t; } @Override @@ -27,7 +29,8 @@ public class TypeToDescriptor implements TypeVisitor{ @Override public String visit(ExtendsWildcardType extendsWildcardType) { - throw new NotImplementedException(); + return extendsWildcardType.getInnerType().toString(); + //throw new NotImplementedException(); } @Override diff --git a/src/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/de/dhbwstuttgart/bytecode/signature/Signature.java index 8c2cc1d38..488046619 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -59,7 +59,7 @@ public class Signature { private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) { - sw.visitClassBound().visitEnd(); +// sw.visitClassBound().visitEnd(); for(int i = 0;i wird eine Formal Type Parameter K$ erzeugt und Bound = Object + String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()); + if(ret.substring(0,4).equals("TPH ")) { + String g = ret.substring(4)+"$"; + sw.visitFormalTypeParameter(g); + sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); + genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class)); + sw.visitClassBound().visitEnd(); + } + + for(String paramName : methodParamsAndTypes.keySet()) { + RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName); + String pT = t.acceptTV(new TypeToSignature()); + // S.o + if(pT.substring(0,4).equals("TPH ") && !genericsAndBoundsMethod.containsKey(pT)) { + String gP = pT.substring(4)+"$"; + sw.visitFormalTypeParameter(gP); + sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); + genericsAndBoundsMethod.put(gP, Type.getInternalName(Object.class)); + sw.visitClassBound().visitEnd(); + } + } + + // visit each method-parameter to create the signature for(String paramName : methodParamsAndTypes.keySet()) { RefTypeOrTPHOrWildcardOrGeneric t = methodParamsAndTypes.get(paramName); // parameter type deswegen ist true @@ -101,6 +125,15 @@ public class Signature { if(isConstructor) { sw.visitReturnType().visitBaseType('V'); }else { +// String ret = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()); +// if(ret.substring(0,4).equals("TPH ")) { +// String g = ret.substring(4); +// if(!genericsAndBoundsMethod.containsKey(g)) { +// genericsAndBoundsMethod.put(g, Type.getInternalName(Object.class)); +// } else { +// genericsAndBoundsMethod.put(g+"_", Type.getInternalName(Object.class)); +// } +// } RefTypeOrTPHOrWildcardOrGeneric returnType = method.getReturnType(); // return type deswegen ist false doVisitParamsOrReturn(returnType, false); @@ -132,10 +165,16 @@ public class Signature { break; case "TPH": RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType; - if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH ")) - sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature())); -// sv.visitClassType(r.acceptTV(new TypeToSignature())); - System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature())); + // der Fall wenn die Type eine Interface ist, muss betrachtet werden + // Deswegen muss in ResutSet noch enthalten werden, ob die Type eine + // Interface oder eine Klasse ist. + if(!r.acceptTV(new TypeToSignature()).substring(0, 4).equals("TPH ")) { +// sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature())); + sv.visitClassType(r.acceptTV(new TypeToSignature())); + } else { + System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature())); + sv.visitTypeVariable(r.acceptTV(new TypeToSignature()).substring(4)+"$"); + } break; default: if(!isParameterType) diff --git a/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java b/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java index 78b2fb22a..a1357d4cf 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java @@ -27,6 +27,8 @@ public class TypeToSignature implements TypeVisitor { } params += ";>"; } +// String t = refType.getName().toString().replace(".", "/"); +// return t.equals("Fun1")?t+"$$"+params+";":t+params+";"; return refType.getName().toString().replace(".", "/") + params+";"; } diff --git a/test/bytecode/BinaryTest.java b/test/bytecode/BinaryTest.java new file mode 100644 index 000000000..7f2f5fa41 --- /dev/null +++ b/test/bytecode/BinaryTest.java @@ -0,0 +1,40 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class BinaryTest { + private static String path; + private static File fileToTest; + private static JavaTXCompiler compiler; + private static ClassLoader loader; + private static Class classToTest; + private static String pathToClassFile; + private static Object instanceOfClass; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + path = System.getProperty("user.dir")+"/test/bytecode/javFiles/BinaryInMeth.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + compiler.generateBytecode(); + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("BinaryInMeth"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + } + + @Test + public void test() { + fail("Not yet implemented"); + } + +} diff --git a/test/bytecode/FacTest.java b/test/bytecode/FacTest.java new file mode 100644 index 000000000..b2840026d --- /dev/null +++ b/test/bytecode/FacTest.java @@ -0,0 +1,44 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class FacTest { + private static String path; + private static File fileToTest; + private static JavaTXCompiler compiler; + private static ClassLoader loader; + private static Class classToTest; + private static String pathToClassFile; + private static Object instanceOfClass; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Fac.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + compiler.generateBytecode(); + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("Fac"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + } + + @Test + public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method getFac = classToTest.getDeclaredMethod("getFac", Integer.class,Integer.class); + Integer result = (Integer) getFac.invoke(instanceOfClass,3); + assertEquals(result, 6); + } + +} diff --git a/test/bytecode/PlusTest.java b/test/bytecode/PlusTest.java index 016cb706d..51503c58c 100644 --- a/test/bytecode/PlusTest.java +++ b/test/bytecode/PlusTest.java @@ -29,7 +29,7 @@ public class PlusTest { compiler = new JavaTXCompiler(fileToTest); compiler.generateBytecode(); - pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/examples/"; + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("Plus"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); diff --git a/test/bytecode/RelOpsTest.java b/test/bytecode/RelOpsTest.java new file mode 100644 index 000000000..06b246305 --- /dev/null +++ b/test/bytecode/RelOpsTest.java @@ -0,0 +1,44 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class RelOpsTest { + private static String path; + private static File fileToTest; + private static JavaTXCompiler compiler; + private static ClassLoader loader; + private static Class classToTest; + private static String pathToClassFile; + private static Object instanceOfClass; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + path = System.getProperty("user.dir")+"/test/bytecode/javFiles/RelOps.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + compiler.generateBytecode(); + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("RelOps"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + } + + @Test + public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method m = classToTest.getDeclaredMethod("m", Integer.class,Integer.class); + Boolean result = (Boolean) m.invoke(instanceOfClass, 7,3); + assertFalse(result); + } + +} diff --git a/test/bytecode/javFiles/BinaryInMeth.jav b/test/bytecode/javFiles/BinaryInMeth.jav new file mode 100644 index 000000000..f5a117981 --- /dev/null +++ b/test/bytecode/javFiles/BinaryInMeth.jav @@ -0,0 +1,11 @@ +import java.lang.Integer; +public class BinaryInMeth { + + m(a){ + return ++a; + } + + m2(a,b){ + return m(a+b); + } +} \ No newline at end of file diff --git a/test/bytecode/javFiles/Fac.jav b/test/bytecode/javFiles/Fac.jav new file mode 100644 index 000000000..d3d1a8d97 --- /dev/null +++ b/test/bytecode/javFiles/Fac.jav @@ -0,0 +1,16 @@ +import java.lang.Integer; +import java.lang.Long; +import java.lang.Double; + +public class Fac { + + getFac(n){ + var res = 1; + var i = 1; + while(i<=n) { + res = res * i; + i++; + } + return res; + } +} \ No newline at end of file diff --git a/test/bytecode/javFiles/Gen.jav b/test/bytecode/javFiles/Gen.jav index 5d579eb8e..3b58b188d 100644 --- a/test/bytecode/javFiles/Gen.jav +++ b/test/bytecode/javFiles/Gen.jav @@ -2,7 +2,7 @@ import java.lang.Integer; import java.util.Vector; public class Gen{ - Vector m(Vector v){ + Vector m(Vector v){ return v; } } diff --git a/test/bytecode/javFiles/Matrix.jav b/test/bytecode/javFiles/Matrix.jav index 8120a7c5a..80f41b163 100644 --- a/test/bytecode/javFiles/Matrix.jav +++ b/test/bytecode/javFiles/Matrix.jav @@ -7,19 +7,19 @@ class Matrix extends Vector> { var ret = new Matrix(); var i = 0; while(i < size()) { - var v1 = this.elementAt(i); - var v2 = new Vector(); - var j = 0; - while(j < v1.size()) { - var erg = 0; - var k = 0; - while(k < v1.size()) { - erg = erg + v1.elementAt(k) - * m.elementAt(k).elementAt(j); - k++; } - v2.addElement(new Integer(erg)); - j++; } - ret.addElement(v2); +// var v1 = this.elementAt(i); +// var v2 = new Vector(); +// var j = 0; +// while(j < v1.size()) { +// var erg = 0; +// var k = 0; +// while(k < v1.size()) { +// erg = erg + v1.elementAt(k) +// * m.elementAt(k).elementAt(j); +// k++; } +// v2.addElement(new Integer(erg)); +// j++; } +// ret.addElement(v2); i++; } return ret; diff --git a/test/bytecode/javFiles/Op.jav b/test/bytecode/javFiles/Op.jav index c01e7e6e9..082f48d82 100644 --- a/test/bytecode/javFiles/Op.jav +++ b/test/bytecode/javFiles/Op.jav @@ -9,7 +9,7 @@ import java.lang.Byte; public class Op { - Integer m(Integer a, Integer b) { + m(a, b) { //var c = a+b; return a+b; } diff --git a/test/bytecode/javFiles/Plus.jav b/test/bytecode/javFiles/Plus.jav index 4d425bf06..86b4eb369 100644 --- a/test/bytecode/javFiles/Plus.jav +++ b/test/bytecode/javFiles/Plus.jav @@ -1,4 +1,4 @@ -import java.lang.Integer; +//import java.lang.Integer; public class Plus { diff --git a/test/bytecode/javFiles/RelOps.jav b/test/bytecode/javFiles/RelOps.jav new file mode 100644 index 000000000..d75ee2f34 --- /dev/null +++ b/test/bytecode/javFiles/RelOps.jav @@ -0,0 +1,7 @@ +import java.lang.Integer; + +public class RelOps { + m(a,b){ + return a Deswegen kann +// nicht auf den Stack geladen. +//import java.lang.Long; public class While { m(x) { diff --git a/test/logFiles/log b/test/logFiles/log new file mode 100644 index 000000000..5d17ab289 --- /dev/null +++ b/test/logFiles/log @@ -0,0 +1,107 @@ +FC:\{java.lang.Number=Elem: Node(java.lang.Number) +Prec: [java.lang.Object, java.io.Serializable] +Desc: [java.lang.Integer] + +, java.lang.Comparable=Elem: Node(java.lang.Comparable) +Prec: [] +Desc: [java.lang.Integer] + +, java.lang.Comparable=Elem: Node(java.lang.Comparable) +Prec: [java.lang.Object] +Desc: [] + +, java.lang.Integer=Elem: Node(java.lang.Integer) +Prec: [java.lang.Number, java.lang.Object, java.lang.Comparable, java.io.Serializable] +Desc: [] + +, java.lang.Iterable=Elem: Node(java.lang.Iterable) +Prec: [java.lang.Object] +Desc: [] + +, java.lang.Iterable=Elem: Node(java.lang.Iterable) +Prec: [java.lang.Object] +Desc: [] + +, java.util.Collection=Elem: Node(java.util.Collection) +Prec: [] +Desc: [java.util.AbstractList, java.util.Vector, java.util.List, java.util.AbstractCollection] + +, java.util.AbstractCollection=Elem: Node(java.util.AbstractCollection) +Prec: [java.lang.Object, java.util.Collection] +Desc: [java.util.AbstractList, java.util.Vector] + +, java.util.AbstractList=Elem: Node(java.util.AbstractList) +Prec: [java.lang.Object, java.util.Collection, java.util.AbstractCollection, java.util.List] +Desc: [java.util.Vector] + +, java.lang.Cloneable=Elem: Node(java.lang.Cloneable) +Prec: [java.lang.Object] +Desc: [java.util.Vector] + +, java.lang.Comparable=Elem: Node(java.lang.Comparable) +Prec: [java.lang.Object] +Desc: [] + +, java.lang.Object=Elem: Node(java.lang.Object) +Prec: [java.lang.Object] +Desc: [java.lang.Number, java.lang.Comparable, java.lang.Integer, java.lang.Iterable, java.lang.Iterable, java.util.AbstractCollection, java.util.AbstractList, java.lang.Cloneable, java.lang.Comparable, Gen, java.lang.Object, java.util.Vector, java.util.Collection, java.util.RandomAccess, java.util.Collection, java.util.List, java.io.Serializable, java.lang.Iterable, java.util.Collection] + +, java.util.Vector=Elem: Node(java.util.Vector) +Prec: [java.util.AbstractList, java.lang.Cloneable, java.lang.Object, java.util.Collection, java.util.RandomAccess, java.io.Serializable, java.util.AbstractCollection, java.util.List] +Desc: [] + +, Gen=Elem: Node(Gen) +Prec: [java.lang.Object] +Desc: [] + +, java.util.Collection=Elem: Node(java.util.Collection) +Prec: [java.lang.Object, java.lang.Iterable] +Desc: [] + +, java.util.RandomAccess=Elem: Node(java.util.RandomAccess) +Prec: [java.lang.Object] +Desc: [java.util.Vector] + +, java.util.List=Elem: Node(java.util.List) +Prec: [java.lang.Object, java.util.Collection] +Desc: [] + +, java.util.Collection=Elem: Node(java.util.Collection) +Prec: [java.lang.Object, java.lang.Iterable] +Desc: [] + +, java.io.Serializable=Elem: Node(java.io.Serializable) +Prec: [java.lang.Object] +Desc: [java.lang.Number, java.util.Vector, java.lang.Integer] + +, java.lang.Iterable=Elem: Node(java.lang.Iterable) +Prec: [java.lang.Object] +Desc: [] + +, java.lang.Iterable=Elem: Node(java.lang.Iterable) +Prec: [] +Desc: [java.util.Collection, java.util.Collection, java.util.Collection] + +, java.util.Collection=Elem: Node(java.util.Collection) +Prec: [java.lang.Object, java.lang.Iterable] +Desc: [] + +, java.util.List=Elem: Node(java.util.List) +Prec: [] +Desc: [java.util.AbstractList, java.util.Vector] + +} +class Gen { + + java.util.Vector m(java.util.Vector v)({ + return (v)::java.util.Vector; + })::TPH K + + Gen()({ + super(()); + })::TPH N + +}Unifikation: [(java.util.Vector <. java.util.Vector, )] +Unifikation: [] +[] +RES: [] From f617ad8946b5472b6c79f3513ed43c6083976e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 24 May 2018 10:28:22 +0200 Subject: [PATCH 90/91] modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java Relationen auf verschiedene Numeric-Typen umgestellt im equals Null abgefragt --- .../typeinference/typeAlgo/TYPEStmt.java | 44 +- .../typeinference/unify/model/UnifyPair.java | 3 + test/bytecode/javFiles/While.jav | 2 +- test/logFiles/log | 479 +++++++++++++++--- 4 files changed, 449 insertions(+), 79 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 4cf581211..4dad9de60 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -272,10 +272,48 @@ public class TYPEStmt implements StatementVisitor{ binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) || binary.operation.equals(BinaryExpr.Operator.BIGGERTHAN) || binary.operation.equals(BinaryExpr.Operator.LESSTHAN)){ - constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT)); - constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT)); + //eingefuegt PL 2018-05-24 + Set numericRelationConcatenation = new HashSet<>(); + Constraint numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); + numericRelationConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); + numericRelationConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); + numericRelationConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); + numericRelationConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); + numericRelationConcatenation.add(numeric); + numeric = new Constraint<>(); + numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT)); + numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); + numericRelationConcatenation.add(numeric); + + //***ACHTUNG: Moeglicherweise oder und und-Contraint falsch + constraintsSet.addOderConstraint(numericRelationConcatenation); + //***ACHTUNG: Moeglicherweise oder und und-Contraint falsch + + //auskommentiert PL 2018-05-24 + //constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT)); + //constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT)); //Rückgabetyp ist Boolean - constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT)); + //constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT)); }else{ throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index b631e5ec4..19dee99fc 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -149,6 +149,9 @@ public class UnifyPair { UnifyPair other = (UnifyPair) obj; if (isUndefinedPair()) { + if (other.getBasePair() != basePair || (other.getBasePair() == null && basePair == null)) { + return false; + } if (!other.getBasePair().equals(basePair) || !other.getAllSubstitutions().equals(getAllSubstitutions())) { return false; diff --git a/test/bytecode/javFiles/While.jav b/test/bytecode/javFiles/While.jav index 5b983f3eb..ed7e83567 100644 --- a/test/bytecode/javFiles/While.jav +++ b/test/bytecode/javFiles/While.jav @@ -2,7 +2,7 @@ import java.lang.Integer; // wenn nur ein Import da steht,wird die Type von // dem Literal 2 Number berechnet => Deswegen kann // nicht auf den Stack geladen. -//import java.lang.Long; +import java.lang.Long; public class While { m(x) { diff --git a/test/logFiles/log b/test/logFiles/log index 5d17ab289..03035949a 100644 --- a/test/logFiles/log +++ b/test/logFiles/log @@ -1,107 +1,436 @@ FC:\{java.lang.Number=Elem: Node(java.lang.Number) Prec: [java.lang.Object, java.io.Serializable] -Desc: [java.lang.Integer] +Desc: [java.lang.Integer, java.lang.Long] + +, java.lang.Object=Elem: Node(java.lang.Object) +Prec: [java.lang.Object] +Desc: [java.lang.Number, java.lang.Object, java.lang.Integer, java.lang.Comparable, java.lang.Long, java.lang.Comparable, While, java.io.Serializable, java.lang.Comparable] , java.lang.Comparable=Elem: Node(java.lang.Comparable) Prec: [] -Desc: [java.lang.Integer] - -, java.lang.Comparable=Elem: Node(java.lang.Comparable) -Prec: [java.lang.Object] -Desc: [] +Desc: [java.lang.Integer, java.lang.Long] , java.lang.Integer=Elem: Node(java.lang.Integer) Prec: [java.lang.Number, java.lang.Object, java.lang.Comparable, java.io.Serializable] Desc: [] -, java.lang.Iterable=Elem: Node(java.lang.Iterable) +, java.lang.Comparable=Elem: Node(java.lang.Comparable) Prec: [java.lang.Object] Desc: [] -, java.lang.Iterable=Elem: Node(java.lang.Iterable) -Prec: [java.lang.Object] +, java.lang.Long=Elem: Node(java.lang.Long) +Prec: [java.lang.Number, java.lang.Object, java.lang.Comparable, java.io.Serializable] Desc: [] -, java.util.Collection=Elem: Node(java.util.Collection) -Prec: [] -Desc: [java.util.AbstractList, java.util.Vector, java.util.List, java.util.AbstractCollection] - -, java.util.AbstractCollection=Elem: Node(java.util.AbstractCollection) -Prec: [java.lang.Object, java.util.Collection] -Desc: [java.util.AbstractList, java.util.Vector] - -, java.util.AbstractList=Elem: Node(java.util.AbstractList) -Prec: [java.lang.Object, java.util.Collection, java.util.AbstractCollection, java.util.List] -Desc: [java.util.Vector] - -, java.lang.Cloneable=Elem: Node(java.lang.Cloneable) +, java.lang.Comparable=Elem: Node(java.lang.Comparable) Prec: [java.lang.Object] -Desc: [java.util.Vector] - -, java.lang.Comparable=Elem: Node(java.lang.Comparable) -Prec: [java.lang.Object] -Desc: [] - -, java.lang.Object=Elem: Node(java.lang.Object) -Prec: [java.lang.Object] -Desc: [java.lang.Number, java.lang.Comparable, java.lang.Integer, java.lang.Iterable, java.lang.Iterable, java.util.AbstractCollection, java.util.AbstractList, java.lang.Cloneable, java.lang.Comparable, Gen, java.lang.Object, java.util.Vector, java.util.Collection, java.util.RandomAccess, java.util.Collection, java.util.List, java.io.Serializable, java.lang.Iterable, java.util.Collection] - -, java.util.Vector=Elem: Node(java.util.Vector) -Prec: [java.util.AbstractList, java.lang.Cloneable, java.lang.Object, java.util.Collection, java.util.RandomAccess, java.io.Serializable, java.util.AbstractCollection, java.util.List] -Desc: [] - -, Gen=Elem: Node(Gen) -Prec: [java.lang.Object] -Desc: [] - -, java.util.Collection=Elem: Node(java.util.Collection) -Prec: [java.lang.Object, java.lang.Iterable] -Desc: [] - -, java.util.RandomAccess=Elem: Node(java.util.RandomAccess) -Prec: [java.lang.Object] -Desc: [java.util.Vector] - -, java.util.List=Elem: Node(java.util.List) -Prec: [java.lang.Object, java.util.Collection] -Desc: [] - -, java.util.Collection=Elem: Node(java.util.Collection) -Prec: [java.lang.Object, java.lang.Iterable] Desc: [] , java.io.Serializable=Elem: Node(java.io.Serializable) Prec: [java.lang.Object] -Desc: [java.lang.Number, java.util.Vector, java.lang.Integer] +Desc: [java.lang.Number, java.lang.Integer, java.lang.Long] -, java.lang.Iterable=Elem: Node(java.lang.Iterable) +, While=Elem: Node(While) Prec: [java.lang.Object] Desc: [] -, java.lang.Iterable=Elem: Node(java.lang.Iterable) -Prec: [] -Desc: [java.util.Collection, java.util.Collection, java.util.Collection] - -, java.util.Collection=Elem: Node(java.util.Collection) -Prec: [java.lang.Object, java.lang.Iterable] +, java.lang.Comparable=Elem: Node(java.lang.Comparable) +Prec: [java.lang.Object] Desc: [] -, java.util.List=Elem: Node(java.util.List) -Prec: [] -Desc: [java.util.AbstractList, java.util.Vector] - } -class Gen { +class While { - java.util.Vector m(java.util.Vector v)({ - return (v)::java.util.Vector; - })::TPH K + TPH K m(TPH L x)({ + while((x)::TPH L | 2.0)({ + (x)::TPH L = (x)::TPH L | 1.0; + })::TPH Q; + return (x)::TPH L; + })::TPH S - Gen()({ + While()({ super(()); - })::TPH N + })::TPH V -}Unifikation: [(java.util.Vector <. java.util.Vector, )] -Unifikation: [] -[] +}0 AA: [] +1 Unifikation: [(O <. java.lang.Long, 0), (L <. java.lang.Float, 1), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Long, 0), (L <. java.lang.Integer, 1), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (N <. java.lang.Integer, 0)] +1 AA: [] +2 Unifikation: [(O <. java.lang.Long, 0), (java.lang.Integer <. K, , -1), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (P <. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Long, ), (N <. java.lang.Integer, 0)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Long, ) +BasePair; (L <. java.lang.Long, 1) +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1), (N <. java.lang.Integer, 0)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (P <. java.lang.Number, 1), (java.lang.Integer <. java.lang.Double, ), (P <. java.lang.Integer, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1), (N <. java.lang.Integer, 0)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) +BasePair; (L <. java.lang.Double, 1) +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (N <. java.lang.Integer, 0), (P =. java.lang.String, 1)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (java.lang.Integer =. java.lang.String, ), (M =. java.lang.Boolean, 0), (java.lang.String <. java.lang.Integer, ), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1), (N <. java.lang.Integer, 0)] +1 UndefinedPairs; (java.lang.Integer =. java.lang.String, ) +BasePair; (L =. java.lang.String, 1) +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (java.lang.Integer <. java.lang.Byte, ), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Byte, ) +BasePair; (L <. java.lang.Byte, 1) +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1), (N <. java.lang.Integer, 0)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Float, ), (O <. java.lang.Float, 0), (P <. java.lang.Integer, 1), (P <. java.lang.Float, 1), (N <. java.lang.Integer, 0)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Float, ) +BasePair; (L <. java.lang.Float, 1) +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +nextSet: [[(K =. java.lang.Object, -1)], [(K =. java.lang.Integer, -1)], [(K =. java.lang.Comparable, -1)], [(K =. java.lang.Number, -1)], [(K =. java.io.Serializable, -1)]] +2 AA: [] +3 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +nextSet: [[(P =. java.lang.Integer, 1)], [(P =. ? extends java.lang.Integer, 1)]] +3 AA: [] +4 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +nextSet: [[(O =. java.lang.Integer, 0)], [(O =. ? extends java.lang.Integer, 0)]] +4 AA: [] +5 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +nextSet: [[(N =. java.lang.Integer, 0)], [(N =. ? extends java.lang.Integer, 0)]] +5 AA: [] +6 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)] +[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)] +Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] +Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] +Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] +Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] +Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] +Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] +RES: [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Short, 0), (java.lang.Integer <. java.lang.Short, ), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Short, ) +BasePair; (L <. java.lang.Short, 1) +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1)] +nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +1 AA: [] +2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] +1 UndefinedPairs; (L <. java.lang.Short, 1) +BasePair; null +abhSubst: [] +a: [(P =. ? extends java.lang.Long, 1)] +Durchschnitt: [] +nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [] +Number erased Elements (undef): 1 +Number erased Elements (undef): 1 +Number of Backtracking: 1 +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] +1 UndefinedPairs; (L <. java.lang.Short, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] +1 UndefinedPairs; (L <. java.lang.Short, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Short, ), (N <. java.lang.Short, 0), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Short, ) +BasePair; (L <. java.lang.Short, 1) +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Short, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (N <. java.lang.Long, 0)] +nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +1 AA: [] +2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] +2 AA: [] +3 Unifikation: [(O <. java.lang.Long, 0), (M =. java.lang.Boolean, 0), (L =. java.lang.Long, 1), (java.lang.Long <. K, , -1), (java.lang.Long <. java.lang.Long, ), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] +nextSet: [[(K =. java.lang.Long, -1)], [(K =. java.lang.Object, -1)], [(K =. java.lang.Comparable, -1)], [(K =. java.lang.Number, -1)], [(K =. java.io.Serializable, -1)]] +3 AA: [] +4 Unifikation: [(O <. java.lang.Long, 0), (K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] +nextSet: [[(O =. java.lang.Long, 0)], [(O =. ? extends java.lang.Long, 0)]] +4 AA: [] +5 Unifikation: [(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] +nextSet: [[(N =. java.lang.Long, 0)], [(N =. ? extends java.lang.Long, 0)]] +5 AA: [] +6 Unifikation: [(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] +[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] +Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] +Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] +Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] +Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] +Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] +Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] +RES: [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1), (N <. java.lang.Long, 0)] +nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +1 AA: [] +2 Unifikation: [(M =. java.lang.Boolean, 0), (? extends java.lang.Number <. java.lang.Double, ), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (? extends java.lang.Number <. L, , 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P =. ? extends java.lang.Number, 1), (N <. java.lang.Long, 0)] +1 UndefinedPairs; (java.lang.Number <. java.lang.Double, ) +BasePair; (P <. java.lang.Double, 1) +1 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null +abhSubst: [(P =. ? extends java.lang.Number, 1)] +a: [(P =. ? extends java.lang.Number, 1)] +Durchschnitt: [(P =. ? extends java.lang.Number, 1)] +nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +Number erased Elements (undef): 0 +Number erased Elements (undef): 0 +Number of Backtracking: 1 +2 AA: [] +3 Unifikation: [(P =. java.lang.Number, 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (java.lang.Number <. java.lang.Double, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (java.lang.Number <. L, , 1), (N <. java.lang.Long, 0)] +2 UndefinedPairs; (java.lang.Number <. java.lang.Double, ) +BasePair; (P <. java.lang.Double, 1) +2 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null +abhSubst: [(P =. java.lang.Number, 1)] +a: [(P =. java.lang.Number, 1)] +Durchschnitt: [(P =. java.lang.Number, 1)] +nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [[(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +Number erased Elements (undef): 0 +Number erased Elements (undef): 0 +Number of Backtracking: 2 +3 AA: [] +4 Unifikation: [(M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (? extends java.lang.Integer <. java.lang.Double, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (? extends java.lang.Integer <. L, , 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P =. ? extends java.lang.Integer, 1), (N <. java.lang.Long, 0)] +3 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) +BasePair; (P <. java.lang.Double, 1) +abhSubst: [(P =. ? extends java.lang.Integer, 1)] +a: [(P =. ? extends java.lang.Integer, 1)] +Durchschnitt: [(P =. ? extends java.lang.Integer, 1)] +nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [[(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +Number erased Elements (undef): 0 +Number erased Elements (undef): 0 +Number of Backtracking: 3 +4 AA: [] +5 Unifikation: [(java.lang.Integer <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P =. java.lang.Integer, 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (java.lang.Integer <. java.lang.Double, ), (N <. java.lang.Long, 0)] +4 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) +BasePair; (P <. java.lang.Double, 1) +abhSubst: [(P =. java.lang.Integer, 1)] +a: [(P =. java.lang.Integer, 1)] +Durchschnitt: [(P =. java.lang.Integer, 1)] +nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +Number erased Elements (undef): 0 +Number erased Elements (undef): 0 +Number of Backtracking: 4 +5 AA: [] +6 Unifikation: [(? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (? extends java.lang.Long <. java.lang.Double, ), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] +5 UndefinedPairs; (java.lang.Long <. java.lang.Double, ) +BasePair; (P <. java.lang.Double, 1) +5 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null +abhSubst: [(P =. ? extends java.lang.Long, 1)] +a: [(P =. ? extends java.lang.Long, 1)] +Durchschnitt: [(P =. ? extends java.lang.Long, 1)] +nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [[(P =. java.lang.Long, 1)]] +Number erased Elements (undef): 0 +Number erased Elements (undef): 0 +Number of Backtracking: 5 +6 AA: [] +7 Unifikation: [(java.lang.Long <. java.lang.Double, ), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P =. java.lang.Long, 1), (java.lang.Long <. L, , 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (N <. java.lang.Long, 0)] +6 UndefinedPairs; (java.lang.Long <. java.lang.Double, ) +BasePair; (P <. java.lang.Double, 1) +6 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null +abhSubst: [(P =. java.lang.Long, 1)] +a: [(P =. java.lang.Long, 1)] +Durchschnitt: [(P =. java.lang.Long, 1)] +nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [] +Number erased Elements (undef): 0 +Number erased Elements (undef): 0 +Number of Backtracking: 6 +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (O =. java.lang.String, 0), (N <. java.lang.Long, 0), (P =. java.lang.String, 1)] +1 AA: [] +2 Unifikation: [(M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Long, 1), (java.lang.String <. java.lang.Long, ), (java.lang.Long <. K, , -1), (java.lang.Long =. java.lang.String, ), (O =. java.lang.String, 0), (P =. java.lang.String, 1), (N <. java.lang.Long, 0)] +1 UndefinedPairs; (java.lang.String <. java.lang.Long, ) +BasePair; (P <. java.lang.Long, 1) +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Long, 0)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (L <. java.lang.Long, 1), (P <. java.lang.Float, 1), (N <. java.lang.Long, 0)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (L <. java.lang.Long, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Long, 0)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Long, ), (N <. java.lang.Long, 0)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Long, ) +BasePair; (L <. java.lang.Long, 1) +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Long, 0)] +1 UndefinedPairs; (L <. java.lang.Short, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1)] +nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +1 AA: [] +2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (N <. java.lang.Byte, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +abhSubst: [] +a: [(P =. ? extends java.lang.Long, 1)] +Durchschnitt: [] +nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [] +Number erased Elements (undef): 1 +Number erased Elements (undef): 1 +Number of Backtracking: 1 +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Integer <. java.lang.Byte, ), (N <. java.lang.Byte, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Byte, ) +BasePair; (L <. java.lang.Byte, 1) +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (L <. java.lang.Long, 1)] +nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +1 AA: [] +2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (N <. java.lang.Double, 0), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] +1 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null +abhSubst: [] +a: [(P =. ? extends java.lang.Long, 1)] +Durchschnitt: [] +nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] +nextSetasList: [] +Number erased Elements (undef): 1 +Number erased Elements (undef): 1 +Number of Backtracking: 1 +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. java.lang.Number, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] +1 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (L =. java.lang.String, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] +1 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Byte, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] +1 UndefinedPairs; (L <. java.lang.Float, 1) +BasePair; null +RES: [] +0 AA: [] +1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] +1 AA: [] +2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (N <. java.lang.Double, 0), (O <. java.lang.Integer, 0), (java.lang.Integer <. java.lang.Double, ), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) +BasePair; (L <. java.lang.Double, 1) +RES: [] +0 AA: [] +1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (P <. java.lang.Integer, 1)] +1 UndefinedPairs; (L <. java.lang.Double, 1) +BasePair; null RES: [] From f5398fa8e93b7cf42f5fca0c10dcb86a1f2c0208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 24 May 2018 10:34:50 +0200 Subject: [PATCH 91/91] deleted: ../../test/logFiles/log --- test/logFiles/log | 436 ---------------------------------------------- 1 file changed, 436 deletions(-) delete mode 100644 test/logFiles/log diff --git a/test/logFiles/log b/test/logFiles/log deleted file mode 100644 index 03035949a..000000000 --- a/test/logFiles/log +++ /dev/null @@ -1,436 +0,0 @@ -FC:\{java.lang.Number=Elem: Node(java.lang.Number) -Prec: [java.lang.Object, java.io.Serializable] -Desc: [java.lang.Integer, java.lang.Long] - -, java.lang.Object=Elem: Node(java.lang.Object) -Prec: [java.lang.Object] -Desc: [java.lang.Number, java.lang.Object, java.lang.Integer, java.lang.Comparable, java.lang.Long, java.lang.Comparable, While, java.io.Serializable, java.lang.Comparable] - -, java.lang.Comparable=Elem: Node(java.lang.Comparable) -Prec: [] -Desc: [java.lang.Integer, java.lang.Long] - -, java.lang.Integer=Elem: Node(java.lang.Integer) -Prec: [java.lang.Number, java.lang.Object, java.lang.Comparable, java.io.Serializable] -Desc: [] - -, java.lang.Comparable=Elem: Node(java.lang.Comparable) -Prec: [java.lang.Object] -Desc: [] - -, java.lang.Long=Elem: Node(java.lang.Long) -Prec: [java.lang.Number, java.lang.Object, java.lang.Comparable, java.io.Serializable] -Desc: [] - -, java.lang.Comparable=Elem: Node(java.lang.Comparable) -Prec: [java.lang.Object] -Desc: [] - -, java.io.Serializable=Elem: Node(java.io.Serializable) -Prec: [java.lang.Object] -Desc: [java.lang.Number, java.lang.Integer, java.lang.Long] - -, While=Elem: Node(While) -Prec: [java.lang.Object] -Desc: [] - -, java.lang.Comparable=Elem: Node(java.lang.Comparable) -Prec: [java.lang.Object] -Desc: [] - -} -class While { - - TPH K m(TPH L x)({ - while((x)::TPH L | 2.0)({ - (x)::TPH L = (x)::TPH L | 1.0; - })::TPH Q; - return (x)::TPH L; - })::TPH S - - While()({ - super(()); - })::TPH V - -}0 AA: [] -1 Unifikation: [(O <. java.lang.Long, 0), (L <. java.lang.Float, 1), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (N <. java.lang.Float, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Long, 0), (L <. java.lang.Integer, 1), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (N <. java.lang.Integer, 0)] -1 AA: [] -2 Unifikation: [(O <. java.lang.Long, 0), (java.lang.Integer <. K, , -1), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (P <. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Long, ), (N <. java.lang.Integer, 0)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Long, ) -BasePair; (L <. java.lang.Long, 1) -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1), (N <. java.lang.Integer, 0)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (P <. java.lang.Number, 1), (java.lang.Integer <. java.lang.Double, ), (P <. java.lang.Integer, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1), (N <. java.lang.Integer, 0)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) -BasePair; (L <. java.lang.Double, 1) -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (N <. java.lang.Integer, 0), (P =. java.lang.String, 1)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (java.lang.Integer =. java.lang.String, ), (M =. java.lang.Boolean, 0), (java.lang.String <. java.lang.Integer, ), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1), (N <. java.lang.Integer, 0)] -1 UndefinedPairs; (java.lang.Integer =. java.lang.String, ) -BasePair; (L =. java.lang.String, 1) -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (java.lang.Integer <. java.lang.Byte, ), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Byte, ) -BasePair; (L <. java.lang.Byte, 1) -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1), (N <. java.lang.Integer, 0)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Float, ), (O <. java.lang.Float, 0), (P <. java.lang.Integer, 1), (P <. java.lang.Float, 1), (N <. java.lang.Integer, 0)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Float, ) -BasePair; (L <. java.lang.Float, 1) -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -nextSet: [[(K =. java.lang.Object, -1)], [(K =. java.lang.Integer, -1)], [(K =. java.lang.Comparable, -1)], [(K =. java.lang.Number, -1)], [(K =. java.io.Serializable, -1)]] -2 AA: [] -3 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -nextSet: [[(P =. java.lang.Integer, 1)], [(P =. ? extends java.lang.Integer, 1)]] -3 AA: [] -4 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -nextSet: [[(O =. java.lang.Integer, 0)], [(O =. ? extends java.lang.Integer, 0)]] -4 AA: [] -5 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -nextSet: [[(N =. java.lang.Integer, 0)], [(N =. ? extends java.lang.Integer, 0)]] -5 AA: [] -6 Unifikation: [(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)] -[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)] -Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] -Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] -Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] -Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] -Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] -Result1 [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] -RES: [[(M =. java.lang.Boolean, 0), (K =. java.lang.Integer, -1), (L =. java.lang.Integer, 1), (O =. java.lang.Integer, 0), (N =. java.lang.Integer, 0), (P =. ? extends java.lang.Integer, 1)]] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Short, 0), (java.lang.Integer <. java.lang.Short, ), (P <. java.lang.Integer, 1), (N <. java.lang.Integer, 0)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Short, ) -BasePair; (L <. java.lang.Short, 1) -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1)] -nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -1 AA: [] -2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] -1 UndefinedPairs; (L <. java.lang.Short, 1) -BasePair; null -abhSubst: [] -a: [(P =. ? extends java.lang.Long, 1)] -Durchschnitt: [] -nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [] -Number erased Elements (undef): 1 -Number erased Elements (undef): 1 -Number of Backtracking: 1 -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] -1 UndefinedPairs; (L <. java.lang.Short, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] -1 UndefinedPairs; (L <. java.lang.Short, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Short, ), (N <. java.lang.Short, 0), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Short, ) -BasePair; (L <. java.lang.Short, 1) -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (N <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Short, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (N <. java.lang.Long, 0)] -nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -1 AA: [] -2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] -2 AA: [] -3 Unifikation: [(O <. java.lang.Long, 0), (M =. java.lang.Boolean, 0), (L =. java.lang.Long, 1), (java.lang.Long <. K, , -1), (java.lang.Long <. java.lang.Long, ), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] -nextSet: [[(K =. java.lang.Long, -1)], [(K =. java.lang.Object, -1)], [(K =. java.lang.Comparable, -1)], [(K =. java.lang.Number, -1)], [(K =. java.io.Serializable, -1)]] -3 AA: [] -4 Unifikation: [(O <. java.lang.Long, 0), (K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] -nextSet: [[(O =. java.lang.Long, 0)], [(O =. ? extends java.lang.Long, 0)]] -4 AA: [] -5 Unifikation: [(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] -nextSet: [[(N =. java.lang.Long, 0)], [(N =. ? extends java.lang.Long, 0)]] -5 AA: [] -6 Unifikation: [(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] -[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] -Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] -Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] -Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] -Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] -Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] -Result1 [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] -RES: [[(K =. java.lang.Long, -1), (M =. java.lang.Boolean, 0), (O =. java.lang.Long, 0), (N =. java.lang.Long, 0), (L =. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)]] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1), (N <. java.lang.Long, 0)] -nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -1 AA: [] -2 Unifikation: [(M =. java.lang.Boolean, 0), (? extends java.lang.Number <. java.lang.Double, ), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (? extends java.lang.Number <. L, , 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P =. ? extends java.lang.Number, 1), (N <. java.lang.Long, 0)] -1 UndefinedPairs; (java.lang.Number <. java.lang.Double, ) -BasePair; (P <. java.lang.Double, 1) -1 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -abhSubst: [(P =. ? extends java.lang.Number, 1)] -a: [(P =. ? extends java.lang.Number, 1)] -Durchschnitt: [(P =. ? extends java.lang.Number, 1)] -nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -Number erased Elements (undef): 0 -Number erased Elements (undef): 0 -Number of Backtracking: 1 -2 AA: [] -3 Unifikation: [(P =. java.lang.Number, 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (java.lang.Number <. java.lang.Double, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (java.lang.Number <. L, , 1), (N <. java.lang.Long, 0)] -2 UndefinedPairs; (java.lang.Number <. java.lang.Double, ) -BasePair; (P <. java.lang.Double, 1) -2 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -abhSubst: [(P =. java.lang.Number, 1)] -a: [(P =. java.lang.Number, 1)] -Durchschnitt: [(P =. java.lang.Number, 1)] -nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [[(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -Number erased Elements (undef): 0 -Number erased Elements (undef): 0 -Number of Backtracking: 2 -3 AA: [] -4 Unifikation: [(M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (? extends java.lang.Integer <. java.lang.Double, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (? extends java.lang.Integer <. L, , 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P =. ? extends java.lang.Integer, 1), (N <. java.lang.Long, 0)] -3 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) -BasePair; (P <. java.lang.Double, 1) -abhSubst: [(P =. ? extends java.lang.Integer, 1)] -a: [(P =. ? extends java.lang.Integer, 1)] -Durchschnitt: [(P =. ? extends java.lang.Integer, 1)] -nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [[(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -Number erased Elements (undef): 0 -Number erased Elements (undef): 0 -Number of Backtracking: 3 -4 AA: [] -5 Unifikation: [(java.lang.Integer <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P =. java.lang.Integer, 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (java.lang.Integer <. java.lang.Double, ), (N <. java.lang.Long, 0)] -4 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) -BasePair; (P <. java.lang.Double, 1) -abhSubst: [(P =. java.lang.Integer, 1)] -a: [(P =. java.lang.Integer, 1)] -Durchschnitt: [(P =. java.lang.Integer, 1)] -nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -Number erased Elements (undef): 0 -Number erased Elements (undef): 0 -Number of Backtracking: 4 -5 AA: [] -6 Unifikation: [(? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (? extends java.lang.Long <. java.lang.Double, ), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (P =. ? extends java.lang.Long, 1), (N <. java.lang.Long, 0)] -5 UndefinedPairs; (java.lang.Long <. java.lang.Double, ) -BasePair; (P <. java.lang.Double, 1) -5 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -abhSubst: [(P =. ? extends java.lang.Long, 1)] -a: [(P =. ? extends java.lang.Long, 1)] -Durchschnitt: [(P =. ? extends java.lang.Long, 1)] -nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [[(P =. java.lang.Long, 1)]] -Number erased Elements (undef): 0 -Number erased Elements (undef): 0 -Number of Backtracking: 5 -6 AA: [] -7 Unifikation: [(java.lang.Long <. java.lang.Double, ), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P =. java.lang.Long, 1), (java.lang.Long <. L, , 1), (L <. java.lang.Long, 1), (O <. java.lang.Double, 0), (N <. java.lang.Long, 0)] -6 UndefinedPairs; (java.lang.Long <. java.lang.Double, ) -BasePair; (P <. java.lang.Double, 1) -6 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -abhSubst: [(P =. java.lang.Long, 1)] -a: [(P =. java.lang.Long, 1)] -Durchschnitt: [(P =. java.lang.Long, 1)] -nextSet: [[(P =. java.lang.Number, 1)], [(P =. java.lang.Integer, 1)], [(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Number, 1)], [(P =. ? extends java.lang.Integer, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [] -Number erased Elements (undef): 0 -Number erased Elements (undef): 0 -Number of Backtracking: 6 -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (O =. java.lang.String, 0), (N <. java.lang.Long, 0), (P =. java.lang.String, 1)] -1 AA: [] -2 Unifikation: [(M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Long, 1), (java.lang.String <. java.lang.Long, ), (java.lang.Long <. K, , -1), (java.lang.Long =. java.lang.String, ), (O =. java.lang.String, 0), (P =. java.lang.String, 1), (N <. java.lang.Long, 0)] -1 UndefinedPairs; (java.lang.String <. java.lang.Long, ) -BasePair; (P <. java.lang.Long, 1) -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Long, 0)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (L <. java.lang.Long, 1), (P <. java.lang.Float, 1), (N <. java.lang.Long, 0)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (L <. java.lang.Long, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Long, 0)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1), (java.lang.Integer <. java.lang.Long, ), (N <. java.lang.Long, 0)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Long, ) -BasePair; (L <. java.lang.Long, 1) -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (L <. java.lang.Long, 1), (P <. java.lang.Integer, 1), (N <. java.lang.Long, 0)] -1 UndefinedPairs; (L <. java.lang.Short, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (L <. java.lang.Long, 1)] -nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -1 AA: [] -2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (N <. java.lang.Byte, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -abhSubst: [] -a: [(P =. ? extends java.lang.Long, 1)] -Durchschnitt: [] -nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [] -Number erased Elements (undef): 1 -Number erased Elements (undef): 1 -Number of Backtracking: 1 -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. java.lang.Number, 1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (L =. java.lang.String, 1), (P <. L, 1, 1), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (L <. K, 1, -1), (P <. L, 1, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Integer <. java.lang.Byte, ), (N <. java.lang.Byte, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Byte, ) -BasePair; (L <. java.lang.Byte, 1) -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (N <. java.lang.Byte, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Long, 0), (P <. java.lang.Long, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (L <. java.lang.Long, 1)] -nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -1 AA: [] -2 Unifikation: [(O <. java.lang.Long, 0), (? extends java.lang.Long <. L, , 1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L <. K, 1, -1), (L <. java.lang.Double, 1), (N <. java.lang.Double, 0), (L <. java.lang.Long, 1), (P =. ? extends java.lang.Long, 1)] -1 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -abhSubst: [] -a: [(P =. ? extends java.lang.Long, 1)] -Durchschnitt: [] -nextSet: [[(P =. java.lang.Long, 1)], [(P =. ? extends java.lang.Long, 1)]] -nextSetasList: [] -Number erased Elements (undef): 1 -Number erased Elements (undef): 1 -Number of Backtracking: 1 -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. java.lang.Number, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O <. java.lang.Double, 0), (P <. java.lang.Double, 1)] -1 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (L =. java.lang.String, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O =. java.lang.String, 0), (P =. java.lang.String, 1)] -1 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(O <. java.lang.Byte, 0), (M =. java.lang.Boolean, 0), (L <. java.lang.Byte, 1), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Byte, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Float, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O <. java.lang.Float, 0), (P <. java.lang.Float, 1)] -1 UndefinedPairs; (L <. java.lang.Float, 1) -BasePair; null -RES: [] -0 AA: [] -1 Unifikation: [(L <. java.lang.Integer, 1), (M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (O <. java.lang.Integer, 0), (P <. java.lang.Integer, 1)] -1 AA: [] -2 Unifikation: [(java.lang.Integer <. K, , -1), (M =. java.lang.Boolean, 0), (java.lang.Boolean <. java.lang.Boolean, ), (L =. java.lang.Integer, 1), (N <. java.lang.Double, 0), (O <. java.lang.Integer, 0), (java.lang.Integer <. java.lang.Double, ), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (java.lang.Integer <. java.lang.Double, ) -BasePair; (L <. java.lang.Double, 1) -RES: [] -0 AA: [] -1 Unifikation: [(M =. java.lang.Boolean, 0), (M <. java.lang.Boolean, 0), (O <. java.lang.Short, 0), (L <. K, 1, -1), (L <. java.lang.Double, 1), (L <. java.lang.Short, 1), (P <. L, 1, 1), (N <. java.lang.Double, 0), (P <. java.lang.Integer, 1)] -1 UndefinedPairs; (L <. java.lang.Double, 1) -BasePair; null -RES: []