forked from JavaTX/JavaCompilerCore
adapt rule fixed
This commit is contained in:
parent
6793b0bd24
commit
8d69f6c82b
@ -376,8 +376,8 @@ public class RuleSet implements IRuleSet{
|
||||
if(!(typeDs instanceof ReferenceType))
|
||||
return Optional.empty();
|
||||
|
||||
if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0)
|
||||
return Optional.empty();
|
||||
/*if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0)
|
||||
return Optional.empty();*/
|
||||
|
||||
if(typeD.getName().equals(typeDs.getName()))
|
||||
return Optional.empty();
|
||||
@ -402,8 +402,8 @@ public class RuleSet implements IRuleSet{
|
||||
TypeParams typeDParams = typeD.getTypeParams();
|
||||
TypeParams typeDgenParams = typeDgen.getTypeParams();
|
||||
|
||||
Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0));
|
||||
for(int i = 1; i < typeDParams.size(); i++)
|
||||
Unifier unif = Unifier.Identity();
|
||||
for(int i = 0; i < typeDParams.size(); i++)
|
||||
unif.Add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
|
||||
|
||||
return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT));
|
||||
|
@ -6,17 +6,28 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
|
||||
public class FunNType extends UnifyType {
|
||||
|
||||
public FunNType(TypeParams p) {
|
||||
protected FunNType(TypeParams p) {
|
||||
super("FuN", p);
|
||||
if(p.size() == 0)
|
||||
throw new IllegalArgumentException("Function types need at least one type parameter");
|
||||
}
|
||||
|
||||
public static FunNType getFunNType(TypeParams tp) {
|
||||
if(!validateTypeParams(tp))
|
||||
throw new IllegalArgumentException("Invalid TypeParams for a FunNType: " + tp);
|
||||
return new FunNType(tp);
|
||||
}
|
||||
|
||||
private static boolean validateTypeParams(TypeParams tp) {
|
||||
if(tp.size() == 0)
|
||||
return false;
|
||||
for(UnifyType t : tp)
|
||||
if(t instanceof WildcardType)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnifyType setTypeParams(TypeParams newTp) {
|
||||
if(newTp.size() == 0)
|
||||
throw new IllegalArgumentException("Function types need at least one type parameter");
|
||||
return new FunNType(newTp);
|
||||
return getFunNType(newTp);
|
||||
}
|
||||
|
||||
public int getN() {
|
||||
|
@ -4,7 +4,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Node<T> {
|
||||
class Node<T> {
|
||||
private T content;
|
||||
|
||||
private HashSet<Node<T>> predecessors = new HashSet<>();
|
||||
|
@ -45,7 +45,7 @@ public class Unifier implements Function<UnifyType, UnifyType> /*, Set<MPair>*/
|
||||
return substitutions.containsKey(t);
|
||||
}
|
||||
|
||||
public UnifyType getSubstitute(UnifyType t) {
|
||||
public UnifyType getSubstitute(PlaceholderType t) {
|
||||
return substitutions.get(t);
|
||||
}
|
||||
|
||||
|
@ -380,13 +380,39 @@ public class UnifyTest extends Unify {
|
||||
|
||||
//System.out.println(actual);
|
||||
//Assert.assertEquals(actual, expected);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unifyTestComplex() {
|
||||
/*
|
||||
* INIT
|
||||
*/
|
||||
TypeFactory tf = new TypeFactory();
|
||||
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
||||
|
||||
UnifyType tphT = tf.getPlaceholderType("T");
|
||||
UnifyType vector = tf.getSimpleType("Vector", tphT);
|
||||
UnifyType number = tf.getSimpleType("Number");
|
||||
UnifyType integer = tf.getSimpleType("Integer");
|
||||
UnifyType object = tf.getSimpleType("Object");
|
||||
UnifyType matrix = tf.getSimpleType("Matrix");
|
||||
UnifyType vectorvectorint = tf.getSimpleType("Vector", tf.getSimpleType("Vector", integer));
|
||||
|
||||
|
||||
fcb.add(integer, number);
|
||||
fcb.add(matrix, vectorvectorint);
|
||||
fcb.add(vector, object);
|
||||
|
||||
IFiniteClosure fc = fcb.getFiniteClosure();
|
||||
|
||||
Set<UnifyPair> eq = new HashSet<UnifyPair>();
|
||||
eq.add(new UnifyPair(tf.getSimpleType("Matrix"), tf.getSimpleType("Vector", tf.getPlaceholderType("a")), PairOperator.SMALLERDOT));
|
||||
|
||||
Set<Set<UnifyPair>> expected = new HashSet<>();
|
||||
Set<Set<UnifyPair>> actual = unify(eq, fc);
|
||||
|
||||
System.out.println("Test Matrix:");
|
||||
System.out.println(actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user