forked from JavaTX/JavaCompilerCore
Merge branch 'unify' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into refactoring
This commit is contained in:
commit
e537a76cd9
@ -376,8 +376,8 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(!(typeDs instanceof ReferenceType))
|
if(!(typeDs instanceof ReferenceType))
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0)
|
/*if(typeD.getTypeParams().size() == 0 || typeDs.getTypeParams().size() == 0)
|
||||||
return Optional.empty();
|
return Optional.empty();*/
|
||||||
|
|
||||||
if(typeD.getName().equals(typeDs.getName()))
|
if(typeD.getName().equals(typeDs.getName()))
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@ -402,8 +402,8 @@ public class RuleSet implements IRuleSet{
|
|||||||
TypeParams typeDParams = typeD.getTypeParams();
|
TypeParams typeDParams = typeD.getTypeParams();
|
||||||
TypeParams typeDgenParams = typeDgen.getTypeParams();
|
TypeParams typeDgenParams = typeDgen.getTypeParams();
|
||||||
|
|
||||||
Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0));
|
Unifier unif = Unifier.Identity();
|
||||||
for(int i = 1; i < typeDParams.size(); i++)
|
for(int i = 0; i < typeDParams.size(); i++)
|
||||||
unif.Add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
|
unif.Add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
|
||||||
|
|
||||||
return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT));
|
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 class FunNType extends UnifyType {
|
||||||
|
|
||||||
public FunNType(TypeParams p) {
|
protected FunNType(TypeParams p) {
|
||||||
super("FuN", 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
|
@Override
|
||||||
public UnifyType setTypeParams(TypeParams newTp) {
|
public UnifyType setTypeParams(TypeParams newTp) {
|
||||||
if(newTp.size() == 0)
|
return getFunNType(newTp);
|
||||||
throw new IllegalArgumentException("Function types need at least one type parameter");
|
|
||||||
return new FunNType(newTp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getN() {
|
public int getN() {
|
||||||
|
@ -4,7 +4,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Node<T> {
|
class Node<T> {
|
||||||
private T content;
|
private T content;
|
||||||
|
|
||||||
private HashSet<Node<T>> predecessors = new HashSet<>();
|
private HashSet<Node<T>> predecessors = new HashSet<>();
|
||||||
|
@ -45,7 +45,7 @@ public class Unifier implements Function<UnifyType, UnifyType> /*, Set<MPair>*/
|
|||||||
return substitutions.containsKey(t);
|
return substitutions.containsKey(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyType getSubstitute(UnifyType t) {
|
public UnifyType getSubstitute(PlaceholderType t) {
|
||||||
return substitutions.get(t);
|
return substitutions.get(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,13 +380,39 @@ public class UnifyTest extends Unify {
|
|||||||
|
|
||||||
//System.out.println(actual);
|
//System.out.println(actual);
|
||||||
//Assert.assertEquals(actual, expected);
|
//Assert.assertEquals(actual, expected);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unifyTestComplex() {
|
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
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user