forked from JavaTX/JavaCompilerCore
support for extended case 1 // tests // bugfix in "big" cases
This commit is contained in:
parent
e06888f5f7
commit
5c73224f8f
@ -327,12 +327,9 @@ public class Unify {
|
|||||||
|
|
||||||
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
||||||
|
|
||||||
for(UnifyType c : cs) {
|
for(UnifyType c : cs) {
|
||||||
|
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
// Wenn die fc nach spezifikation funktioniert ist das hier nicht mehr nötig?
|
|
||||||
Set<UnifyType> thetaQs = fc.getChildren(c).stream().filter(x -> x.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
thetaQs.add(c); // reflexive
|
|
||||||
|
|
||||||
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
||||||
TypeParams cParams = c.getTypeParams();
|
TypeParams cParams = c.getTypeParams();
|
||||||
if(cParams.size() == 0)
|
if(cParams.size() == 0)
|
||||||
@ -352,6 +349,7 @@ public class Unify {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Unifier unifier = opt.get();
|
Unifier unifier = opt.get();
|
||||||
|
unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams().toArray());
|
||||||
Set<UnifyPair> substitutionSet = new HashSet<>();
|
Set<UnifyPair> substitutionSet = new HashSet<>();
|
||||||
for (Entry<PlaceholderType, UnifyType> sigma : unifier.getSubstitutions())
|
for (Entry<PlaceholderType, UnifyType> sigma : unifier.getSubstitutions())
|
||||||
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
|
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
|
||||||
@ -360,7 +358,15 @@ public class Unify {
|
|||||||
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
|
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
|
||||||
for(UnifyType theta : smaller) {
|
for(UnifyType theta : smaller) {
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
|
|
||||||
|
UnifyType[] freshTphs = new UnifyType[theta.getTypeParams().size()];
|
||||||
|
for(int i = 0; i < freshTphs.length; i++) {
|
||||||
|
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||||
|
resultPrime.add(new UnifyPair(freshTphs[i], theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC));
|
||||||
|
}
|
||||||
|
|
||||||
|
UnifyType freshTheta = theta.setTypeParams(new TypeParams(freshTphs));
|
||||||
|
resultPrime.add(new UnifyPair(a, freshTheta, PairOperator.EQUALSDOT));
|
||||||
resultPrime.addAll(substitutionSet);
|
resultPrime.addAll(substitutionSet);
|
||||||
result.add(resultPrime);
|
result.add(resultPrime);
|
||||||
}
|
}
|
||||||
@ -379,12 +385,9 @@ public class Unify {
|
|||||||
UnifyType thetaPrime = extThetaPrime.getExtendedType();
|
UnifyType thetaPrime = extThetaPrime.getExtendedType();
|
||||||
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
|
||||||
|
|
||||||
for(UnifyType c : cs) {
|
for(UnifyType c : cs) {
|
||||||
|
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
// Wenn die fc nach spezifikation funktioniert ist das hier nicht mehr nötig?
|
|
||||||
Set<UnifyType> thetaQs = fc.getChildren(c).stream().filter(x -> x.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
thetaQs.add(c); // reflexive
|
|
||||||
|
|
||||||
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
||||||
TypeParams cParams = c.getTypeParams();
|
TypeParams cParams = c.getTypeParams();
|
||||||
if(cParams.size() == 0)
|
if(cParams.size() == 0)
|
||||||
@ -485,12 +488,9 @@ public class Unify {
|
|||||||
UnifyType theta = supTheta.getSuperedType();
|
UnifyType theta = supTheta.getSuperedType();
|
||||||
Set<UnifyType> cs = fc.getAllTypesByName(theta.getName());
|
Set<UnifyType> cs = fc.getAllTypesByName(theta.getName());
|
||||||
|
|
||||||
for(UnifyType c : cs) {
|
for(UnifyType c : cs) {
|
||||||
|
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
// Wenn die fc nach spezifikation funktioniert ist das hier nicht mehr nötig?
|
|
||||||
Set<UnifyType> thetaQs = fc.getChildren(c).stream().filter(x -> x.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
thetaQs.add(c); // reflexive
|
|
||||||
|
|
||||||
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
||||||
TypeParams cParams = c.getTypeParams();
|
TypeParams cParams = c.getTypeParams();
|
||||||
if(cParams.size() == 0)
|
if(cParams.size() == 0)
|
||||||
|
@ -129,6 +129,8 @@ public class UnifyTest extends Unify {
|
|||||||
addAsSet(expected, new UnifyPair(tphA, supObject, PairOperator.EQUALSDOT));
|
addAsSet(expected, new UnifyPair(tphA, supObject, PairOperator.EQUALSDOT));
|
||||||
|
|
||||||
actual = unify(eq, fc);
|
actual = unify(eq, fc);
|
||||||
|
System.out.println("? super Integer");
|
||||||
|
System.out.println(actual);
|
||||||
actual = filterGeneratedTPHsMultiple(actual);
|
actual = filterGeneratedTPHsMultiple(actual);
|
||||||
|
|
||||||
Assert.assertEquals(expected, actual);
|
Assert.assertEquals(expected, actual);
|
||||||
@ -278,9 +280,9 @@ public class UnifyTest extends Unify {
|
|||||||
UnifyType integer = tf.getSimpleType("Integer");
|
UnifyType integer = tf.getSimpleType("Integer");
|
||||||
UnifyType doubl = tf.getSimpleType("Double");
|
UnifyType doubl = tf.getSimpleType("Double");
|
||||||
|
|
||||||
fcb.add(number, object);
|
//fcb.add(number, object);
|
||||||
fcb.add(integer, number);
|
fcb.add(integer, number);
|
||||||
fcb.add(doubl, number);
|
//fcb.add(doubl, number);
|
||||||
|
|
||||||
IFiniteClosure fc = fcb.getCollectionExample();
|
IFiniteClosure fc = fcb.getCollectionExample();
|
||||||
|
|
||||||
@ -289,6 +291,10 @@ public class UnifyTest extends Unify {
|
|||||||
*
|
*
|
||||||
* (Vector<a> <. Vector<? extends b>)
|
* (Vector<a> <. Vector<? extends b>)
|
||||||
* (List<b> <. List<? extends Number>)
|
* (List<b> <. List<? extends Number>)
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* {(b = Number), (a = Number)}, {(b = Number), (a = Integer)}, {(b = Number), (a = Integer)}
|
||||||
|
* (b = Integer),
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UnifyType tphA = tf.getPlaceholderType("a");
|
UnifyType tphA = tf.getPlaceholderType("a");
|
||||||
@ -305,26 +311,7 @@ public class UnifyTest extends Unify {
|
|||||||
|
|
||||||
System.out.println(actual);
|
System.out.println(actual);
|
||||||
//Assert.assertEquals(actual, expected);
|
//Assert.assertEquals(actual, expected);
|
||||||
|
|
||||||
/*
|
|
||||||
* Test 8:
|
|
||||||
*
|
|
||||||
* (a <.? ? sup b)
|
|
||||||
* (b = Number)
|
|
||||||
*/
|
|
||||||
|
|
||||||
UnifyType supB = tf.getSuperType(tphB);
|
|
||||||
eq = new HashSet<>();
|
|
||||||
eq.add(new UnifyPair(tphA, supB, PairOperator.SMALLERDOTWC));
|
|
||||||
eq.add(new UnifyPair(tphB, number, PairOperator.EQUALSDOT));
|
|
||||||
|
|
||||||
expected = new HashSet<>();
|
|
||||||
|
|
||||||
actual = unify(eq, fc);
|
|
||||||
|
|
||||||
System.out.println(actual);
|
|
||||||
//Assert.assertEquals(expected, actual);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test 2:
|
* Test 2:
|
||||||
@ -382,6 +369,101 @@ public class UnifyTest extends Unify {
|
|||||||
//Assert.assertEquals(actual, expected);
|
//Assert.assertEquals(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These are tests that specifically test cases where the old unify algorithm was incomplete.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void unifyTestExtension() {
|
||||||
|
/*
|
||||||
|
* INIT
|
||||||
|
*/
|
||||||
|
TypeFactory tf = new TypeFactory();
|
||||||
|
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
||||||
|
|
||||||
|
UnifyType number = tf.getSimpleType("Number");
|
||||||
|
UnifyType object = tf.getSimpleType("Object");
|
||||||
|
UnifyType integer = tf.getSimpleType("Integer");
|
||||||
|
UnifyType doubl = tf.getSimpleType("Double");
|
||||||
|
|
||||||
|
//fcb.add(number, object);
|
||||||
|
fcb.add(integer, number);
|
||||||
|
//fcb.add(doubl, number);
|
||||||
|
|
||||||
|
IFiniteClosure fc = fcb.getCollectionExample();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 1:
|
||||||
|
* This is a Test for the extension of case 1 in the cartesian product of step 4.
|
||||||
|
*
|
||||||
|
* (a <. Vector<b>)
|
||||||
|
* (List<Integer> <. List<b>)
|
||||||
|
*
|
||||||
|
* Expected:
|
||||||
|
* (b = Integer), (a = Vector<Integer>)
|
||||||
|
* (b = ? extends Integer), (a = Vector<Integer>),
|
||||||
|
* (b = ? extends Integer), (a = Vector<? extends Integer>),
|
||||||
|
* (b = ? super Integer), (a = Vector<Integer>)
|
||||||
|
* (b = ? super Integer), (a = Vector<Number>)
|
||||||
|
* (b = ? super Integer), (a = Vector<? super Integer>)
|
||||||
|
* (b = ? super Integer), (a = Vector<? super Number>)
|
||||||
|
* (b = ? extends Number), (a = Vector<Integer>)
|
||||||
|
* (b = ? extends Number), (a = Vector<Number>)
|
||||||
|
* (b = ? extends Number), (a = Vector<? extends Integer>)
|
||||||
|
* (b = ? extends Number), (a = Vector<? extends Number>)
|
||||||
|
*/
|
||||||
|
|
||||||
|
UnifyType tphA = tf.getPlaceholderType("a");
|
||||||
|
UnifyType tphB = tf.getPlaceholderType("b");
|
||||||
|
UnifyType extB = tf.getExtendsType(tphB);
|
||||||
|
UnifyType extNum = tf.getExtendsType(number);
|
||||||
|
|
||||||
|
Set<UnifyPair> eq = new HashSet<UnifyPair>();
|
||||||
|
eq.add(new UnifyPair(tphA, tf.getSimpleType("Stack", tphB), PairOperator.SMALLERDOT));
|
||||||
|
eq.add(new UnifyPair(tf.getSimpleType("List", integer), tf.getSimpleType("List", tphB), PairOperator.SMALLERDOT));
|
||||||
|
|
||||||
|
Set<Set<UnifyPair>> expected = new HashSet<>();
|
||||||
|
Set<Set<UnifyPair>> actual = unify(eq, fc);
|
||||||
|
|
||||||
|
System.out.println(actual);
|
||||||
|
//Assert.assertEquals(actual, expected);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 2:
|
||||||
|
*
|
||||||
|
* This is a test for th extension of case 2 of the cartesian product of step 4.
|
||||||
|
*
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 3:
|
||||||
|
* This is a test for the extension of case 3 of the cartesian product of step 4.
|
||||||
|
*
|
||||||
|
* (a <.? ? sup b)
|
||||||
|
* (b = Number)
|
||||||
|
*/
|
||||||
|
|
||||||
|
UnifyType supB = tf.getSuperType(tphB);
|
||||||
|
eq = new HashSet<>();
|
||||||
|
eq.add(new UnifyPair(tphA, supB, PairOperator.SMALLERDOTWC));
|
||||||
|
eq.add(new UnifyPair(tphB, number, PairOperator.EQUALSDOT));
|
||||||
|
|
||||||
|
expected = new HashSet<>();
|
||||||
|
|
||||||
|
actual = unify(eq, fc);
|
||||||
|
|
||||||
|
System.out.println(actual);
|
||||||
|
//Assert.assertEquals(expected, actual);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test 4:
|
||||||
|
* This is a test for the extension of case 4 of the cartesian product of step 4.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unifyTestComplex() {
|
public void unifyTestComplex() {
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user