AdaptExt and Sup revisit

This commit is contained in:
Florian Steurer 2015-11-22 15:54:18 +01:00
parent 3f4f2cd27b
commit 9552831d4e

View File

@ -354,43 +354,45 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
if(!(lhsType instanceof SimpleType) && !(lhsType instanceof ExtendsType))
Type typeD = pair.getLhsType();
if(!(typeD instanceof SimpleType) && !(typeD instanceof ExtendsType))
return Optional.empty();
Type rhsType = pair.getRhsType();
if(!(rhsType instanceof ExtendsType))
Type typeExtDs = pair.getRhsType();
if(!(typeExtDs instanceof ExtendsType))
return Optional.empty();
if(lhsType.getTypeParams().size() == 0 || rhsType.getTypeParams().size() == 0)
if(typeD.getTypeParams().size() == 0 || typeExtDs.getTypeParams().size() == 0)
return Optional.empty();
Type lhsFromFc;
if(lhsType instanceof SimpleType)
lhsFromFc = finiteClosure.getType(lhsType);
else
lhsFromFc = new ExtendsType(finiteClosure.getType(((ExtendsType) lhsType).getExtendedType()));
if(lhsFromFc == null)
Type typeDgen;
if(typeD instanceof SimpleType)
typeDgen = finiteClosure.getGenericType(typeD.getName()).orElse(null);
else {
Optional<Type> opt = finiteClosure.getGenericType(((ExtendsType) typeD).getExtendedType().getName());
typeDgen = opt.isPresent() ? new ExtendsType(opt.get()) : null;
}
if(typeDgen == null)
return Optional.empty();
Set<Type> grArg = finiteClosure.grArg(lhsFromFc);
Set<Type> grArg = finiteClosure.grArg(typeDgen);
Optional<Type> opt = grArg.stream().filter(x -> x.getName().equals(rhsType.getName())).findAny();
Optional<Type> opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
Type newLhs = ((ExtendsType) opt.get()).getExtendedType();
TypeParams lhsTypeParams = lhsType.getTypeParams();
TypeParams lhsFromFcTypeParams = lhsFromFc.getTypeParams();
TypeParams typeDParams = typeD.getTypeParams();
TypeParams typeDgenParams = typeDgen.getTypeParams();
Unifier unif = new Unifier(lhsFromFcTypeParams.get(0), lhsTypeParams.get(0));
for(int i = 1; i < lhsTypeParams.size(); i++)
unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i)));
Unifier unif = new Unifier(typeDgenParams.get(0), typeDParams.get(0));
for(int i = 1; i < typeDParams.size(); i++)
unif.andThen(new Unifier(typeDgenParams.get(i), typeDParams.get(i)));
return Optional.of(new MPair(newLhs.apply(unif), rhsType, PairOperator.SMALLERDOTWC));
return Optional.of(new MPair(newLhs.apply(unif), typeExtDs, PairOperator.SMALLERDOTWC));
}
@Override
@ -398,51 +400,51 @@ public class RuleSet implements IRuleSet{
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
Type lhsType = pair.getLhsType();
if(!(lhsType instanceof SimpleType) && !(lhsType instanceof SuperType))
Type typeDs = pair.getLhsType();
if(!(typeDs instanceof SimpleType) && !(typeDs instanceof SuperType))
return Optional.empty();
Type rhsType = pair.getRhsType();
if(!(rhsType instanceof SuperType))
Type typeSupD = pair.getRhsType();
if(!(typeSupD instanceof SuperType))
return Optional.empty();
if(lhsType.getTypeParams().size() == 0 || rhsType.getTypeParams().size() == 0)
if(typeDs.getTypeParams().size() == 0 || typeSupD.getTypeParams().size() == 0)
return Optional.empty();
Type lhsFromFc;
Type newRhs;
if(lhsType instanceof SimpleType) {
lhsFromFc = finiteClosure.getType(lhsType);
newRhs = new ExtendsType(lhsType);
}
else {
lhsFromFc = new SuperType(finiteClosure.getType(((SuperType) lhsType).getSuperedType()));
newRhs = new ExtendsType(((SuperType) lhsType).getSuperedType());
}
Type rhsFromFc = finiteClosure.getType(((SuperType) rhsType).getSuperedType());
Optional<Type> opt = finiteClosure.getGenericType(((SuperType) typeDs).getSuperedType().getName());
if(lhsFromFc == null || rhsFromFc == null)
if(!opt.isPresent())
return Optional.empty();
Set<Type> smArg = finiteClosure.smArg(new SuperType(rhsFromFc));
Optional<Type> opt = smArg.stream().filter(x -> x.getName().equals(lhsType.getName())).findAny();
Type typeDsgen = opt.get();
Type typeSupDsgen = new SuperType(typeDsgen);
// Use of smArg instead of grArg because
// a in grArg(b) => b in smArg(a)
Set<Type> smArg = finiteClosure.smArg(typeSupDsgen);
opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
if(!opt.isPresent())
return Optional.empty();
// New RHS
Type newRhs = null;
if(typeDs instanceof SimpleType)
newRhs = new ExtendsType(typeDs);
else
newRhs = new ExtendsType(((SuperType) typeDs).getSuperedType());
// New LHS
Type newLhs = opt.get();
TypeParams typeDParams = typeSupD.getTypeParams();
TypeParams typeSupDsgenParams = typeSupDsgen.getTypeParams();
TypeParams lhsTypeParams = lhsType.getTypeParams();
TypeParams lhsFromFcTypeParams = lhsFromFc.getTypeParams();
Unifier unif = new Unifier(lhsFromFcTypeParams.get(0), lhsTypeParams.get(0));
for(int i = 1; i < lhsTypeParams.size(); i++)
unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i)));
Unifier unif = new Unifier(typeSupDsgenParams.get(0), typeDParams.get(0));
for(int i = 1; i < typeDParams.size(); i++)
unif.andThen(new Unifier(typeSupDsgenParams.get(i), typeDParams.get(i)));
return Optional.of(new MPair(newLhs.apply(unif), newRhs, PairOperator.SMALLERDOTWC));
}
/**