diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index a06062c0..3733b7dc 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 bbefe2bc..e037576d 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 03452018..34101705 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()){