This commit is contained in:
Florian Steurer 2015-11-14 18:51:46 +01:00
parent 82c0736fee
commit 3739747eca
8 changed files with 36 additions and 9 deletions

View File

@ -340,7 +340,7 @@ public class RuleSet implements IRuleSet{
for(int i = 0; i < lhsTypeParams.size(); i++)
unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i)));
return Optional.of(new MPair(newLhs.applyToTypeParams(unif), rhsType, PairOperator.SMALLERDOT));
return Optional.of(new MPair(newLhs.apply(unif), rhsType, PairOperator.SMALLERDOT));
}
@Override

View File

@ -52,7 +52,7 @@ public final class ExtendsType extends Type {
}
@Override
public Type applyToTypeParams(Unifier unif) {
return new ExtendsType(extendedType.applyToTypeParams(unif));
public Type apply(Unifier unif) {
return new ExtendsType(extendedType.apply(unif));
}
}

View File

@ -35,7 +35,10 @@ public final class PlaceholderType extends Type{
}
@Override
public Type applyToTypeParams(Unifier unif) {
public Type apply(Unifier unif) {
if(this.equals(unif.getSource()))
return unif.getTarget();
return this;
}
}

View File

@ -43,7 +43,10 @@ public final class SimpleType extends Type {
}
@Override
public Type applyToTypeParams(Unifier unif) {
public Type apply(Unifier unif) {
if(this.equals(unif.getSource()))
return unif.getTarget();
return new SimpleType(typeName, typeParams.apply(unif));
}
}

View File

@ -53,7 +53,7 @@ public final class SuperType extends Type {
}
@Override
public Type applyToTypeParams(Unifier unif) {
return new SuperType(superedType.applyToTypeParams(unif));
public Type apply(Unifier unif) {
return new SuperType(superedType.apply(unif));
}
}

View File

@ -32,7 +32,7 @@ public abstract class Type {
public abstract Set<Type> grArg(IFiniteClosure fc);
public abstract Type applyToTypeParams(Unifier unif);
public abstract Type apply(Unifier unif);
@Override
public String toString() {

View File

@ -31,7 +31,7 @@ public final class TypeParams implements Iterable<Type>{
public TypeParams apply(Unifier unif) {
Type[] newParams = new Type[typeParams.length];
for(int i = 0; i < typeParams.length; i++)
newParams[i] = typeParams[i].applyToTypeParams(unif);
newParams[i] = typeParams[i].apply(unif);
return new TypeParams(newParams);
}

View File

@ -518,6 +518,27 @@ public class RuleSetTest {
@Test
public void testAdapt() {
TypeFactory tf = new TypeFactory();
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
SimpleType t1 = tf.getSimpleType("Type1", "T", "U");
SimpleType t2 = tf.getSimpleType("Type2", "T");
SimpleType t3 = tf.getSimpleType("Type3", tf.getPlaceholderType("T"), tf.getSimpleType("Integer"));
fcb.add(t1, t2);
fcb.add(t2, t3);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
SimpleType c1 = tf.getSimpleType("Type1", "String", "Double");
SimpleType c2 = tf.getSimpleType("Type2", "Object");
SimpleType c3 = tf.getSimpleType("Type3", "Object", "Number");
MPair pair1 = new MPair(c1, c2, PairOperator.SMALLERDOT);
MPair pair2 = new MPair(c1, c3, PairOperator.SMALLERDOT);
System.out.println("------ Adapt ------");
System.out.println(rules.adapt(pair1));
System.out.println(rules.adapt(pair2)); // Not working yet
}