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