Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
318f6e1cc5 | ||
|
005ed60c26 | ||
|
78794e377a |
@@ -287,7 +287,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(lhsSType.getTypeParams().empty())
|
if(lhsSType.getTypeParams().empty())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
UnifyType rhsType = pair.getLhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
ReferenceType rhsSType;
|
ReferenceType rhsSType;
|
||||||
|
|
||||||
if(rhsType instanceof ReferenceType)
|
if(rhsType instanceof ReferenceType)
|
||||||
|
@@ -410,8 +410,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
// Case unknown: If a pair fits no other case, then the type unification has failed.
|
// 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.
|
// 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.
|
// Pairs that do not have one of the aboves form are contradictory.
|
||||||
else
|
else {
|
||||||
undefined.add(pair);
|
// If a pair is not defined, the unificiation will fail, so the loop can be stopped here.
|
||||||
|
undefined.add(pair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter empty sets or sets that only contain an empty set.
|
// Filter empty sets or sets that only contain an empty set.
|
||||||
@@ -425,9 +428,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
|
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
boolean allGen = true;
|
boolean allGen = thetaPrime.getTypeParams().size() > 0;
|
||||||
for(UnifyType t : thetaPrime.getTypeParams())
|
for(UnifyType t : thetaPrime.getTypeParams())
|
||||||
if(t instanceof PlaceholderType && !((PlaceholderType) t).isGenerated()) {
|
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||||
allGen = false;
|
allGen = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -437,7 +440,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
for(UnifyType c : cs) {
|
for(UnifyType c : cs) {
|
||||||
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
thetaQs.add(thetaPrime);
|
//thetaQs.add(thetaPrime);
|
||||||
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)
|
||||||
@@ -493,7 +496,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/**
|
/**
|
||||||
* Cartesian Product Case 2: (a <.? ? ext Theta')
|
* Cartesian Product Case 2: (a <.? ? ext Theta')
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) {
|
private Set<Set<UnifyPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) {
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||||
@@ -513,7 +516,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/**
|
/**
|
||||||
* Cartesian Product Case 3: (a <.? ? sup Theta')
|
* Cartesian Product Case 3: (a <.? ? sup Theta')
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) {
|
private Set<Set<UnifyPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) {
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||||
@@ -531,27 +534,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Cartesian Product Case 4: (a <.? Theta')
|
|
||||||
*/
|
|
||||||
protected Set<Set<UnifyPair>> unifyCase4(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
|
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
|
||||||
resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.EQUALSDOT));
|
|
||||||
result.add(resultPrime);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cartesian Product Case 5: (Theta <. a)
|
* Cartesian Product Case 5: (Theta <. a)
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
private Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
boolean allGen = true;
|
boolean allGen = theta.getTypeParams().size() > 0;
|
||||||
for(UnifyType t : theta.getTypeParams())
|
for(UnifyType t : theta.getTypeParams())
|
||||||
if(t instanceof PlaceholderType && !((PlaceholderType) t).isGenerated()) {
|
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||||
allGen = false;
|
allGen = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -574,44 +565,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Cartesian Product Case 6: (? ext Theta <.? a)
|
|
||||||
*/
|
|
||||||
protected Set<Set<UnifyPair>> unifyCase6(ExtendsType extTheta, PlaceholderType a, IFiniteClosure fc) {
|
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
|
||||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
|
||||||
UnifyType extFreshTph = new ExtendsType(freshTph);
|
|
||||||
|
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
|
||||||
resultPrime.add(new UnifyPair(a, extFreshTph, PairOperator.EQUALSDOT));
|
|
||||||
resultPrime.add(new UnifyPair(extTheta.getExtendedType(), freshTph, PairOperator.SMALLERDOT));
|
|
||||||
result.add(resultPrime);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cartesian Product Case 7: (? sup Theta <.? a)
|
|
||||||
*/
|
|
||||||
protected Set<Set<UnifyPair>> unifyCase7(SuperType supTheta, PlaceholderType a, IFiniteClosure fc) {
|
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
|
||||||
|
|
||||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
|
||||||
UnifyType supAPrime = new SuperType(aPrime);
|
|
||||||
UnifyType theta = supTheta.getSuperedType();
|
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
|
||||||
resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT));
|
|
||||||
resultPrime.add(new UnifyPair(aPrime, theta, PairOperator.SMALLERDOT));
|
|
||||||
result.add(resultPrime);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cartesian Product Case 8: (Theta <.? a)
|
* Cartesian Product Case 8: (Theta <.? a)
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
private Set<Set<UnifyPair>> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
//for(UnifyType thetaS : fc.grArg(theta)) {
|
//for(UnifyType thetaS : fc.grArg(theta)) {
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
@@ -26,7 +26,7 @@ public class FiniteClosure implements IFiniteClosure {
|
|||||||
/**
|
/**
|
||||||
* A map that maps every typename to the nodes of the inheritance graph that contain a type with that name.
|
* A map that maps every typename to the nodes of the inheritance graph that contain a type with that name.
|
||||||
*/
|
*/
|
||||||
private HashMap<String, HashSet<Node<UnifyType>>> strInheritanceGraph;
|
private HashMap<String, Set<Node<UnifyType>>> strInheritanceGraph;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The initial pairs of that define the inheritance tree
|
* The initial pairs of that define the inheritance tree
|
||||||
@@ -251,7 +251,6 @@ public class FiniteClosure implements IFiniteClosure {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> grArg(FunNType type) {
|
public Set<UnifyType> grArg(FunNType type) {
|
||||||
// TODO ist das richtig?
|
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
smaller(type).forEach(x -> result.add(new SuperType(x)));
|
smaller(type).forEach(x -> result.add(new SuperType(x)));
|
||||||
@@ -298,7 +297,6 @@ public class FiniteClosure implements IFiniteClosure {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smArg(FunNType type) {
|
public Set<UnifyType> smArg(FunNType type) {
|
||||||
// TODO ist das richtig?
|
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
return result;
|
return result;
|
||||||
|
@@ -862,13 +862,12 @@ public class UnifyTest {
|
|||||||
UnifyType tphT1 = tf.getPlaceholderType("T1");
|
UnifyType tphT1 = tf.getPlaceholderType("T1");
|
||||||
UnifyType tphT2 = tf.getPlaceholderType("T2");
|
UnifyType tphT2 = tf.getPlaceholderType("T2");
|
||||||
|
|
||||||
UnifyType gtv = tf.getSimpleType("gtv");
|
UnifyType vector = tf.getSimpleType("Vector", "T");
|
||||||
UnifyType vector = tf.getSimpleType("Vector", gtv);
|
|
||||||
UnifyType vectorE = tf.getSimpleType("Vector", tphT2);
|
UnifyType vectorE = tf.getSimpleType("Vector", tphT2);
|
||||||
UnifyType string = tf.getSimpleType("String");
|
UnifyType string = tf.getSimpleType("String");
|
||||||
UnifyType vectorString = tf.getSimpleType("Vector", string);
|
UnifyType vectorString = tf.getSimpleType("Vector", string);
|
||||||
|
|
||||||
fcb.add(vector, vector);
|
fcb.add(vector, tf.getSimpleType("java.lang.Object"));
|
||||||
|
|
||||||
IFiniteClosure fc = fcb.getFiniteClosure();
|
IFiniteClosure fc = fcb.getFiniteClosure();
|
||||||
|
|
||||||
@@ -879,7 +878,7 @@ public class UnifyTest {
|
|||||||
Set<Set<UnifyPair>> actual = new TypeUnify().unifySequential(eq, fc);
|
Set<Set<UnifyPair>> actual = new TypeUnify().unifySequential(eq, fc);
|
||||||
|
|
||||||
System.out.println("Test OverloadingVector:");
|
System.out.println("Test OverloadingVector:");
|
||||||
System.out.println(actual);
|
System.out.println(actual + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user