diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 6ac13b20..68bb2585 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 72097fc0..e0c09e92 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 e316aa6b..6a264684 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 87798e42..1d5ca564 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 ad8d735e..8b01c235 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++; }