Merge branch 'unify' of ssh://i13029@gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into unify
This commit is contained in:
commit
fbcd0cd8a5
@ -360,7 +360,9 @@ public class SourceFile
|
||||
});
|
||||
*/
|
||||
typinferenzLog.debug("\nUnifiziere Constraints:\n"+constraints, Section.TYPEINFERENCE);
|
||||
typinferenzLog.debug("\nFC:\n"+finiteClosure, Section.TYPEINFERENCE);
|
||||
Set<Set<UnifyPair>> unifyResult = new TypeUnify().unify(constraints, finiteClosure);
|
||||
typinferenzLog.debug("\nErgebnis der Unifizierung:\n"+unifyResult, Section.TYPEINFERENCE);
|
||||
|
||||
Menge<Menge<Pair>> convertedResult = unifyResult.parallelStream().<Menge<Pair>>map((Set<UnifyPair> resultSet)->{
|
||||
Menge<Pair> innerConvert = resultSet.stream().map((UnifyPair mp)->UnifyTypeFactory.convert(mp))
|
||||
@ -373,7 +375,7 @@ public class SourceFile
|
||||
).collect(Menge<Pair>::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);
|
||||
|
@ -59,6 +59,10 @@ public class UnifyTypeFactory {
|
||||
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;
|
||||
}
|
||||
|
@ -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<Set<UnifyPair>> expected = new HashSet<>();
|
||||
Set<UnifyPair> solution = new HashSet<UnifyPair>();
|
||||
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<Set<UnifyPair>> 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<UnifyPair> eq = new HashSet<UnifyPair>();
|
||||
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<UnifyPair> expectedSolution = new HashSet<UnifyPair>();
|
||||
expectedSolution.add(new UnifyPair(tphT1, ol, PairOperator.EQUALSDOT));
|
||||
|
||||
|
||||
Set<Set<UnifyPair>> actual = unify(eq, fc);
|
||||
|
||||
System.out.println("Test Overloading:");
|
||||
System.out.println(actual);
|
||||
|
||||
for(Set<UnifyPair> actualSolution : actual){
|
||||
Assert.assertTrue(actualSolution.containsAll(expectedSolution));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user