forked from JavaTX/JavaCompilerCore
reduceSup
This commit is contained in:
parent
4765c2afe0
commit
a263ba5fd4
@ -36,6 +36,9 @@ Gilt reduce f
|
||||
|
||||
- Typen sind anhand ihres identifiers durchgängig identifizierbar
|
||||
|
||||
- ReduceEq nur auf SimpleTypes oder auf alles anwenden? (Momentan alles)
|
||||
- ReduceEq Permutation?
|
||||
|
||||
EED UP
|
||||
- Anwendungsreihenfolge der Regeln (wahrscheinlichste zuerst, evtl ist nach regel 1 regel 2 nie möglich etc...)
|
||||
- Erase vor Reduce
|
||||
|
@ -116,14 +116,72 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
@Override
|
||||
public Optional<Set<MPair>> reduceSup(MPair pair) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
|
||||
return Optional.empty();
|
||||
|
||||
Type lhsType = pair.getLhsType();
|
||||
SimpleType lhsSType;
|
||||
|
||||
if(lhsType instanceof SimpleType)
|
||||
lhsSType = (SimpleType) lhsType;
|
||||
else if(lhsType instanceof SuperType)
|
||||
lhsSType = (SimpleType) ((SuperType) lhsType).getSuperedType();
|
||||
else
|
||||
return Optional.empty();
|
||||
|
||||
if(lhsSType.getTypeParams().empty())
|
||||
return Optional.empty();
|
||||
|
||||
Type rhsType = pair.getRhsType();
|
||||
|
||||
if(!(rhsType instanceof SuperType))
|
||||
return Optional.empty();
|
||||
|
||||
SimpleType rhsSType = (SimpleType) ((SuperType) rhsType).getSuperedType();
|
||||
|
||||
if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
|
||||
return Optional.empty();
|
||||
|
||||
int[] pi = pi(lhsSType, rhsType);
|
||||
|
||||
if(pi.length == 0)
|
||||
return Optional.empty();
|
||||
|
||||
Type[] rhsTypeParams = rhsSType.getTypeParams().asArray();
|
||||
Type[] lhsTypeParams = lhsSType.getTypeParams().asArray();
|
||||
Set<MPair> result = new HashSet<>();
|
||||
|
||||
for(int rhsIdx = 0; rhsIdx < rhsTypeParams.length; rhsIdx++)
|
||||
result.add(new MPair(lhsTypeParams[rhsIdx], rhsTypeParams[pi[rhsIdx]], PairOperator.SMALLERDOTWC));
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<MPair>> reduceEq(MPair pair) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
|
||||
return Optional.empty();
|
||||
|
||||
Type lhsType = pair.getLhsType();
|
||||
if(lhsType instanceof PlaceholderType || lhsType.getTypeParams().empty())
|
||||
return Optional.empty();
|
||||
|
||||
Type rhsType = pair.getRhsType();
|
||||
if(rhsType instanceof PlaceholderType || rhsType.getTypeParams().empty())
|
||||
return Optional.empty();
|
||||
|
||||
if(rhsType.getTypeParams().size() != lhsType.getTypeParams().size())
|
||||
return Optional.empty();
|
||||
|
||||
// TODO Permutation?
|
||||
Set<MPair> result = new HashSet<>();
|
||||
Type[] lhsTypeParams = lhsType.getTypeParams().asArray();
|
||||
Type[] rhsTypeParams = rhsType.getTypeParams().asArray();
|
||||
|
||||
for(int i = 0; i < lhsTypeParams.length; i++)
|
||||
result.add(new MPair(lhsTypeParams[i], rhsTypeParams[i], PairOperator.EQUALSDOT));
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -295,15 +353,17 @@ public class RuleSet implements IRuleSet{
|
||||
Optional<Type> opt = Optional.empty();
|
||||
if(D instanceof ExtendsType) {
|
||||
SimpleType dSType = (SimpleType) ((ExtendsType) D).getExtendedType();
|
||||
|
||||
Set<Type> t = finiteClosure.grArg(cFromFc);
|
||||
opt = finiteClosure.grArg(cFromFc).stream()
|
||||
.filter(x -> x instanceof ExtendsType)
|
||||
.filter(x -> ((ExtendsType) x).getExtendedType().equals(dSType.getName())).findAny();
|
||||
.filter(x -> ((ExtendsType) x).getExtendedType().getName().equals(dSType.getName())).findAny();
|
||||
}
|
||||
else if(D instanceof SuperType) {
|
||||
SimpleType dSType = (SimpleType) ((SuperType) D).getSuperedType();
|
||||
opt = finiteClosure.grArg(cFromFc).stream()
|
||||
.filter(x -> x instanceof SuperType)
|
||||
.filter(x -> ((SuperType) x).getSuperedType().equals(dSType.getName())).findAny();
|
||||
.filter(x -> ((SuperType) x).getSuperedType().getName().equals(dSType.getName())).findAny();
|
||||
}
|
||||
else if (D instanceof SimpleType)
|
||||
opt = finiteClosure.greater(cFromFc).stream()
|
||||
|
@ -9,6 +9,7 @@ import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
||||
import de.dhbwstuttgart.typeinference.unifynew.RuleSet;
|
||||
import de.dhbwstuttgart.typinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typinference.unify.model.FiniteClosure;
|
||||
import de.dhbwstuttgart.typinference.unify.model.MPair;
|
||||
import de.dhbwstuttgart.typinference.unify.model.MPair.PairOperator;
|
||||
@ -42,6 +43,16 @@ public class RuleSetTest {
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceLow() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceUpLow() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduce1() {
|
||||
Set<MPair> pairs = new HashSet<MPair>();
|
||||
@ -74,5 +85,85 @@ public class RuleSetTest {
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduce2() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceExt() {
|
||||
Set<MPair> pairs = new HashSet<MPair>();
|
||||
|
||||
SimpleType t1 = new SimpleType("t1");
|
||||
SimpleType t2 = new SimpleType("t2");
|
||||
SimpleType t3 = new SimpleType("t3");
|
||||
SimpleType t4 = new SimpleType("t4");
|
||||
SimpleType t5 = new SimpleType("t5");
|
||||
SimpleType t6 = new SimpleType("t6");
|
||||
SimpleType t7 = new SimpleType("t7");
|
||||
SimpleType t8 = new SimpleType("t8");
|
||||
SimpleType t9 = new SimpleType("t9");
|
||||
|
||||
SimpleType ta = new SimpleType("a", t1, t2, t3);
|
||||
SimpleType taa = new SimpleType("a", t4, t5, t6);
|
||||
SimpleType tb = new SimpleType("b", t3, t1, t2);
|
||||
SimpleType tbb = new SimpleType("b", t7, t8, t9);
|
||||
|
||||
|
||||
pairs.add(new MPair(ta, tb, PairOperator.SMALLER));
|
||||
FiniteClosure fc = new FiniteClosure(pairs);
|
||||
|
||||
IRuleSet rules = new RuleSet(fc);
|
||||
|
||||
MPair test = new MPair(taa, new ExtendsType(tbb), PairOperator.SMALLERDOTWC);
|
||||
|
||||
Optional<Set<MPair>> res = rules.reduceExt(test);
|
||||
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceSup() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReduceEq() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErase1() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErase2() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErase3() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwap() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapt() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdaptExt() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdaptSup() {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user