forked from JavaTX/JavaCompilerCore
adapt
This commit is contained in:
parent
82c0736fee
commit
3739747eca
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user