|
|
|
@@ -1,8 +1,13 @@
|
|
|
|
|
package typeinference;
|
|
|
|
|
|
|
|
|
|
import com.google.common.base.Optional;
|
|
|
|
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
|
|
|
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
|
|
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
|
|
|
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
|
|
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
|
|
|
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
|
|
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
|
|
|
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
|
|
|
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
|
|
|
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
|
|
|
@@ -34,68 +39,56 @@ public class UnifyTest {
|
|
|
|
|
|
|
|
|
|
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/";
|
|
|
|
|
|
|
|
|
|
private UnifyPair genPairListOfInteger(String name){
|
|
|
|
|
|
|
|
|
|
UnifyType type1 = new PlaceholderType(name);
|
|
|
|
|
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("Integer")));
|
|
|
|
|
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
|
|
return pair1;
|
|
|
|
|
}
|
|
|
|
|
private UnifyPair genPairListOfString(String name){
|
|
|
|
|
|
|
|
|
|
PlaceholderType type1 = new PlaceholderType(name);
|
|
|
|
|
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("String")));
|
|
|
|
|
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
|
|
return pair1;
|
|
|
|
|
}
|
|
|
|
|
@Test
|
|
|
|
|
public void unifyTest(){
|
|
|
|
|
UnifyType type1;
|
|
|
|
|
UnifyType type2;
|
|
|
|
|
UnifyType type1 = new PlaceholderType("a");
|
|
|
|
|
UnifyType type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("b")));
|
|
|
|
|
UnifyPair pair1 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
|
|
type1 = new ReferenceType("List", new TypeParams(new PlaceholderType("c")));
|
|
|
|
|
type2 = new PlaceholderType("a");
|
|
|
|
|
UnifyPair pair2 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
|
|
type1 = new ReferenceType("String");
|
|
|
|
|
type2 = new PlaceholderType("b");
|
|
|
|
|
UnifyPair pair3 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
|
|
type1 = new ReferenceType("Integer");
|
|
|
|
|
type2 = new PlaceholderType("c");
|
|
|
|
|
UnifyPair pair4 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
|
|
|
|
|
|
|
|
|
|
Set<UnifyPair> undConstraints = new HashSet<>();
|
|
|
|
|
undConstraints.add(genPairListOfInteger("a"));
|
|
|
|
|
undConstraints.add(genPairListOfString("a"));
|
|
|
|
|
|
|
|
|
|
undConstraints.add(genPairListOfInteger("b"));
|
|
|
|
|
undConstraints.add(genPairListOfString("b"));
|
|
|
|
|
undConstraints.add(genPairListOfInteger("c"));
|
|
|
|
|
undConstraints.add(genPairListOfString("c"));
|
|
|
|
|
undConstraints.add(genPairListOfInteger("d"));
|
|
|
|
|
undConstraints.add(genPairListOfString("d"));
|
|
|
|
|
undConstraints.add(genPairListOfInteger("e"));
|
|
|
|
|
undConstraints.add(genPairListOfString("e"));
|
|
|
|
|
undConstraints.add(genPairListOfInteger("e1"));
|
|
|
|
|
undConstraints.add(genPairListOfString("e1"));
|
|
|
|
|
undConstraints.add(genPairListOfInteger("e2"));
|
|
|
|
|
undConstraints.add(genPairListOfString("e2"));
|
|
|
|
|
undConstraints.add(genPairListOfInteger("e3"));
|
|
|
|
|
undConstraints.add(genPairListOfString("e3"));
|
|
|
|
|
undConstraints.add(pair1);
|
|
|
|
|
undConstraints.add(pair2);
|
|
|
|
|
undConstraints.add(pair3);
|
|
|
|
|
undConstraints.add(pair4);
|
|
|
|
|
|
|
|
|
|
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
Set<UnifyPair> constraints = new HashSet<>();
|
|
|
|
|
type1 = new ReferenceType("Object");
|
|
|
|
|
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
|
|
|
|
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
|
|
|
|
type1 = new ReferenceType("Object");
|
|
|
|
|
type2 = new ReferenceType("Integer");
|
|
|
|
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
|
|
|
|
type1 = new ReferenceType("Object");
|
|
|
|
|
type2 = new ReferenceType("String");
|
|
|
|
|
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
|
|
|
|
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
|
|
|
|
type1 = new ReferenceType("Number");
|
|
|
|
|
type2 = new ReferenceType("Integer");
|
|
|
|
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
|
|
|
|
type1 = new ReferenceType("Object");
|
|
|
|
|
type2 = new ReferenceType("Number");
|
|
|
|
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
|
|
|
|
type1 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
|
|
|
|
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
|
|
|
|
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
|
|
|
|
type1 = new ReferenceType("Object");
|
|
|
|
|
type2 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
|
|
|
|
|
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
|
|
|
|
|
|
|
|
|
|
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
|
|
|
|
|
|
|
|
|
|
TypeUnify unifyAlgo = new TypeUnify();
|
|
|
|
|
ConstraintSet<Pair> cons = new ConstraintSet<>();
|
|
|
|
|
ConstraintSet< Pair> cons = new ConstraintSet<>();
|
|
|
|
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
|
|
|
|
UnifyTaskModel tasks = new UnifyTaskModel();
|
|
|
|
|
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
|
|
|
|
System.out.println(solution.size());
|
|
|
|
|
System.out.println(solution);
|
|
|
|
|
urm = unifyAlgo.unifyParallel(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
@Test
|
|
|
|
|