From 4b9eda962ee0f3d75c21f3322ebe43340b023668 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 14 Apr 2016 14:22:41 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Tests=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unify/UnifyTest.java | 74 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/test/unify/UnifyTest.java b/test/unify/UnifyTest.java index ebae5e0a..af6e044f 100644 --- a/test/unify/UnifyTest.java +++ b/test/unify/UnifyTest.java @@ -618,6 +618,15 @@ public class UnifyTest extends TypeUnify { public void unifyTestVoid() { /* * Constraints Set mit "void" Typen + * T1 < Integer + * Integer < Integer + * T1 < T2 + * T3 < Bool + * void < T4 + * OL < Object + * void < void + * ol < T5 + * T5 < ol */ TypeFactory tf = new TypeFactory(); FiniteClosureBuilder fcb = new FiniteClosureBuilder(); @@ -626,7 +635,7 @@ public class UnifyTest extends TypeUnify { UnifyType tphT2 = tf.getPlaceholderType("T2"); UnifyType tphT3 = tf.getPlaceholderType("T3"); UnifyType tphT4 = tf.getPlaceholderType("T4"); - UnifyType tphT5 = tf.getPlaceholderType("T4"); + UnifyType tphT5 = tf.getPlaceholderType("T5"); UnifyType integer = tf.getSimpleType("java.lang.Integer"); UnifyType voidType = tf.getSimpleType("void"); @@ -638,7 +647,7 @@ public class UnifyTest extends TypeUnify { fcb.add(integer, object); fcb.add(main, object); fcb.add(bool, object); - fcb.add(voidType, object); + fcb.add(voidType, voidType); fcb.add(ol, object); IFiniteClosure fc = fcb.getFiniteClosure(); @@ -657,10 +666,71 @@ public class UnifyTest extends TypeUnify { eq.add(new UnifyPair(tphT5, ol, PairOperator.SMALLERDOT)); Set> expected = new HashSet<>(); + Set solution = new HashSet(); + solution.add(new UnifyPair(tphT3, bool, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT5, ol, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT2, integer, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT1, integer, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT4, voidType, PairOperator.EQUALSDOT)); + expected.add(solution); + + Set> actual = unify(eq, fc); System.out.println("Test Void:"); System.out.println(actual); + + Assert.assertEquals(expected, actual); + } + + @Test + public void unifyTestOverloading(){ + /* + * Constraints Set mit "void" Typen + * OL < T1 + * T1 < T1 + * T1 < T2 + * T1 < OL + */ + TypeFactory tf = new TypeFactory(); + FiniteClosureBuilder fcb = new FiniteClosureBuilder(); + + UnifyType tphT1 = tf.getPlaceholderType("T1"); + UnifyType tphT2 = tf.getPlaceholderType("T2"); + + UnifyType integer = tf.getSimpleType("java.lang.Integer"); + UnifyType voidType = tf.getSimpleType("void"); + UnifyType bool = tf.getSimpleType("java.lang.Boolean"); + UnifyType object = tf.getSimpleType("Object"); + UnifyType main = tf.getSimpleType("Main"); + UnifyType ol = tf.getSimpleType("OL"); + + fcb.add(integer, object); + fcb.add(main, object); + fcb.add(bool, object); + fcb.add(voidType, voidType); + fcb.add(ol, object); + + IFiniteClosure fc = fcb.getFiniteClosure(); + + Set eq = new HashSet(); + eq.add(new UnifyPair(ol, tphT1, PairOperator.SMALLERDOT)); + eq.add(new UnifyPair(tphT1, tphT1, PairOperator.SMALLERDOT)); + eq.add(new UnifyPair(tphT1, tphT2, PairOperator.SMALLERDOT)); + eq.add(new UnifyPair(tphT1, ol, PairOperator.SMALLERDOT)); + + Set expectedSolution = new HashSet(); + expectedSolution.add(new UnifyPair(tphT1, ol, PairOperator.EQUALSDOT)); + + + Set> actual = unify(eq, fc); + + System.out.println("Test Overloading:"); + System.out.println(actual); + + for(Set actualSolution : actual){ + Assert.assertTrue(actualSolution.containsAll(expectedSolution)); + } } @Test From 9e114207ce09c872b73a2a0fc48839fcfde58f13 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 14 Apr 2016 14:50:31 +0200 Subject: [PATCH 2/2] Fehler mit SMALLER und SMALLERDOT behoben --- src/de/dhbwstuttgart/syntaxtree/SourceFile.java | 6 ++++-- .../syntaxtree/factory/UnifyTypeFactory.java | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 533fe929..71e82930 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -360,8 +360,10 @@ public class SourceFile }); */ typinferenzLog.debug("\nUnifiziere Constraints:\n"+constraints, Section.TYPEINFERENCE); + typinferenzLog.debug("\nFC:\n"+finiteClosure, Section.TYPEINFERENCE); Set> unifyResult = new TypeUnify().unify(constraints, finiteClosure); - + typinferenzLog.debug("\nErgebnis der Unifizierung:\n"+unifyResult, Section.TYPEINFERENCE); + Menge> convertedResult = unifyResult.parallelStream().>map((Set resultSet)->{ Menge innerConvert = resultSet.stream().map((UnifyPair mp)->UnifyTypeFactory.convert(mp)) .collect(Menge::new, Menge::add, Menge::addAll); @@ -373,7 +375,7 @@ public class SourceFile ).collect(Menge::new, Menge::add, Menge::addAll); //Dann den Ergebnissen anfügen - typinferenzLog.debug("\nErgebnis der Unifizierung:\n"+unifyResult, Section.TYPEINFERENCE); + typinferenzLog.debug("\nErgebnis der Unifizierung (Konvertiert):\n"+convertedResult, Section.TYPEINFERENCE); //result.addAll(convertedResult); typinferenzLog.debug("\nJavaFiles:\n", Section.TYPEINFERENCE); diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 1f14bb34..4ba6fee4 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -54,11 +54,15 @@ public class UnifyTypeFactory { } return new FiniteClosure(pairs); } - + public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){ return new UnifyPair(tl, tr, PairOperator.SMALLER); } + public static UnifyPair generateSmallerDotPair(UnifyType tl, UnifyType tr){ + return new UnifyPair(tl, tr, PairOperator.SMALLERDOT); + } + public static UnifyType convert(Type t){ //Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist if(t instanceof GenericTypeVar){ @@ -135,7 +139,7 @@ public class UnifyTypeFactory { public static UnifyPair convert(Pair p) { if(!p.OperatorSmaller())throw new NotImplementedException(); - UnifyPair ret = generateSmallerPair(UnifyTypeFactory.convert(p.TA1) + UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1) , UnifyTypeFactory.convert(p.TA2)); return ret; }