forked from JavaTX/JavaCompilerCore
unifyTest
This commit is contained in:
parent
7ff9554d78
commit
97e0e2fc72
@ -30,14 +30,13 @@ import de.dhbwstuttgart.typinference.unify.model.Type;
|
||||
*/
|
||||
public class Unify {
|
||||
|
||||
public Menge<Menge<Pair>> unify(Menge<MPair> eq, IFiniteClosure fc) {
|
||||
public Menge<Menge<Pair>> unify(Set<MPair> eq, IFiniteClosure fc) {
|
||||
/*
|
||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||
*/
|
||||
|
||||
Set<MPair> eq0 = applyTypeUnificationRules(eq, fc);
|
||||
|
||||
|
||||
/*
|
||||
* Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs
|
||||
*/
|
||||
@ -52,7 +51,7 @@ public class Unify {
|
||||
|
||||
// Sets that originate from pair pattern matching
|
||||
// Sets of the "second level"
|
||||
List<List<Set<MPair>>> pairSets = calculatePairSets(eq2s, fc);
|
||||
List<List<Set<MPair>>> pairSetsSet = calculatePairSets(eq2s, fc);
|
||||
|
||||
// The sets of the "first level"
|
||||
Set<Set<MPair>> sets = new HashSet<Set<MPair>>();
|
||||
@ -70,15 +69,15 @@ public class Unify {
|
||||
|
||||
// Calculate the inner cartesian products
|
||||
// Cartesian products of the second level
|
||||
for(List<Set<MPair>> pairSet : pairSets) // Prüfen ob addAll stimmt oder ob hier eigentlich nur 1 set sein sollte
|
||||
setOps.cartesianProduct(pairSet).forEach(x -> sets.add(new HashSet<MPair>(x)));
|
||||
for(List<Set<MPair>> pairSets : pairSetsSet) // Prüfen ob addAll stimmt oder ob hier eigentlich nur 1 set sein sollte
|
||||
setOps.cartesianProduct(pairSets).forEach(x -> sets.add(new HashSet<MPair>(x)));
|
||||
|
||||
// Calculate the outer cartesian products
|
||||
// Cartesian products of the first level
|
||||
Set<List<MPair>> eqsSet = setOps.cartesianProduct(new ArrayList<>(sets));
|
||||
|
||||
/*
|
||||
* Step 5: Repeated substitution
|
||||
* Step 5: Substitution
|
||||
*/
|
||||
|
||||
|
||||
@ -122,7 +121,7 @@ public class Unify {
|
||||
* Apply rules until the queue is empty
|
||||
*/
|
||||
while(!eqQueue.isEmpty()) {
|
||||
MPair pair = eqQueue.getFirst();
|
||||
MPair pair = eqQueue.pollFirst();
|
||||
|
||||
// ReduceUp, ReduceLow, ReduceUpLow
|
||||
Optional<MPair> opt = rules.reduceUpLow(pair);
|
||||
|
@ -1,7 +1,51 @@
|
||||
package unify;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||
import de.dhbwstuttgart.typeinference.unifynew.Unify;
|
||||
import de.dhbwstuttgart.typinference.unify.model.MPair;
|
||||
import de.dhbwstuttgart.typinference.unify.model.MPair.PairOperator;
|
||||
|
||||
public class UnifyTest extends Unify {
|
||||
|
||||
|
||||
@Test
|
||||
public void unifyTest() {
|
||||
TypeFactory tf = new TypeFactory();
|
||||
FiniteClosureBuilder fcb = new FiniteClosureBuilder();
|
||||
Set<MPair> eq = new HashSet<MPair>();
|
||||
|
||||
fcb.add(tf.getSimpleType("Number"), tf.getSimpleType("Object"));
|
||||
fcb.add(tf.getSimpleType("Integer"), tf.getSimpleType("Number"));
|
||||
fcb.add(tf.getSimpleType("Double"), tf.getSimpleType("Number"));
|
||||
|
||||
IFiniteClosure fc = fcb.getCollectionExample();
|
||||
|
||||
// Vector<Integer> <. Vector<A>
|
||||
// A <. Number
|
||||
// Double <. B
|
||||
// B <. Object
|
||||
eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT));
|
||||
eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("Number"), PairOperator.SMALLERDOT));
|
||||
eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT));
|
||||
eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT));
|
||||
eq.add(new MPair(tf.getPlaceholderType("B"), tf.getSimpleType("Object"), PairOperator.EQUALSDOT));
|
||||
|
||||
this.unify(eq, fc);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyTypeUnificationRulesTest() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calculatePairSetsTest() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user