implemented grArg and smArg

This commit is contained in:
Florian Steurer 2015-11-07 14:53:23 +01:00
parent 28e0e8e94d
commit e49c2a35de
5 changed files with 79 additions and 31 deletions

View File

@ -22,7 +22,18 @@ public interface IFiniteClosure {
*/
public Set<Type> greater(Type type);
/**
* Wo passt Type rein?
* @param type
* @return
*/
public Set<Type> grArg(Type type);
/**
* Was passt in Type rein?
* @param type
* @return
*/
public Set<Type> smArg(Type type);
public Set<Type> grArg(SimpleType type);

View File

@ -36,7 +36,7 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof SimpleType) && !(lhsType instanceof PlaceholderType))
return Optional.empty();
return Optional.of(new MPair(lhsType, ((SuperType) rhsType).GetSuperedType(), PairOperator.SMALLERDOT));
return Optional.of(new MPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT));
}
@Override
@ -52,7 +52,7 @@ public class RuleSet implements IRuleSet{
if(!(rhsType instanceof SimpleType) && !(rhsType instanceof PlaceholderType))
return Optional.empty();
return Optional.of(new MPair(((ExtendsType) lhsType).GetExtendedType(), rhsType, PairOperator.SMALLERDOT));
return Optional.of(new MPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT));
}
@Override
@ -68,7 +68,7 @@ public class RuleSet implements IRuleSet{
if(!(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new MPair(((ExtendsType) lhsType).GetExtendedType(),((SuperType) rhsType).GetSuperedType(), PairOperator.SMALLERDOT));
return Optional.of(new MPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT));
}
@Override
@ -82,7 +82,7 @@ public class RuleSet implements IRuleSet{
if(lhsType instanceof SimpleType)
lhsSType = (SimpleType) lhsType;
else if(lhsType instanceof ExtendsType)
lhsSType = (SimpleType) ((ExtendsType) lhsType).GetExtendedType();
lhsSType = (SimpleType) ((ExtendsType) lhsType).getExtendedType();
else
return Optional.empty();
@ -94,7 +94,7 @@ public class RuleSet implements IRuleSet{
if(!(rhsType instanceof ExtendsType))
return Optional.empty();
SimpleType rhsSType = (SimpleType) ((ExtendsType) rhsType).GetExtendedType();
SimpleType rhsSType = (SimpleType) ((ExtendsType) rhsType).getExtendedType();
if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
return Optional.empty();
@ -171,9 +171,9 @@ public class RuleSet implements IRuleSet{
if(lhsType instanceof SimpleType)
lhsSType = (SimpleType) lhsType;
else if(lhsType instanceof ExtendsType)
lhsSType = (SimpleType) ((ExtendsType) lhsType).GetExtendedType();
lhsSType = (SimpleType) ((ExtendsType) lhsType).getExtendedType();
else if(lhsType instanceof SuperType)
lhsSType = (SimpleType) ((SuperType) lhsType).GetSuperedType();
lhsSType = (SimpleType) ((SuperType) lhsType).getSuperedType();
else
return Optional.empty();
@ -186,9 +186,9 @@ public class RuleSet implements IRuleSet{
if(rhsType instanceof SimpleType)
rhsSType = (SimpleType) rhsType;
else if(rhsType instanceof ExtendsType)
rhsSType = (SimpleType) ((ExtendsType) rhsType).GetExtendedType();
rhsSType = (SimpleType) ((ExtendsType) rhsType).getExtendedType();
else if(rhsType instanceof SuperType)
rhsSType = (SimpleType) ((SuperType) rhsType).GetSuperedType();
rhsSType = (SimpleType) ((SuperType) rhsType).getSuperedType();
else
return Optional.empty();
@ -222,7 +222,7 @@ public class RuleSet implements IRuleSet{
if(!(rhsType instanceof SimpleType) && !(rhsType instanceof PlaceholderType))
return false;
return finiteClosure.isSubtype(lhsType, rhsType);
return finiteClosure.smaller(lhsType).contains(rhsType);
}
@Override
@ -238,7 +238,7 @@ public class RuleSet implements IRuleSet{
if(!(rhsType instanceof ExtendsType))
return false;
return finiteClosure.isInGrArg(lhsType, ((ExtendsType) rhsType).GetExtendedType());
return finiteClosure.grArg(lhsType).contains(((ExtendsType) rhsType).getExtendedType());
}
@Override
@ -294,16 +294,16 @@ public class RuleSet implements IRuleSet{
Optional<Type> opt = Optional.empty();
if(D instanceof ExtendsType) {
SimpleType dSType = (SimpleType) ((ExtendsType) D).GetExtendedType();
SimpleType dSType = (SimpleType) ((ExtendsType) D).getExtendedType();
opt = finiteClosure.grArg(cFromFc).stream()
.filter(x -> x instanceof ExtendsType)
.filter(x -> ((ExtendsType) x).GetExtendedType().equals(dSType.getName())).findAny();
.filter(x -> ((ExtendsType) x).getExtendedType().equals(dSType.getName())).findAny();
}
else if(D instanceof SuperType) {
SimpleType dSType = (SimpleType) ((SuperType) D).GetSuperedType();
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().equals(dSType.getName())).findAny();
}
else if (D instanceof SimpleType)
opt = finiteClosure.greater(cFromFc).stream()

View File

@ -11,7 +11,7 @@ public class ExtendsType extends Type {
this.extendedType = extendedType;
}
public Type GetExtendedType() {
public Type getExtendedType() {
return extendedType;
}

View File

@ -4,7 +4,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typinference.unify.model.MPair.PairOperator;
@ -18,7 +17,6 @@ public class FiniteClosure implements IFiniteClosure {
// Build the transitive closure of the inheritance tree
for(MPair pair : pairs) {
// TODO smaller oder smallerExtends?
if(pair.getPairOp() != PairOperator.SMALLER)
continue;
@ -100,20 +98,35 @@ public class FiniteClosure implements IFiniteClosure {
@Override
public Set<Type> grArg(ExtendsType type) {
// TODO Auto-generated method stub
return null;
if(!inheritanceGraph.containsKey(type.getExtendedType().getName()))
return new HashSet<Type>();
Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getExtendedType().getName()).getContent();
greater(t).forEach(x -> result.add(new ExtendsType(x)));
return result;
}
@Override
public Set<Type> grArg(SuperType type) {
// TODO Auto-generated method stub
return null;
if(!inheritanceGraph.containsKey(type.getSuperedType().getName()))
return new HashSet<Type>();
Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getSuperedType().getName()).getContent();
smaller(t).forEach(x -> result.add(new SuperType(x)));
return result;
}
@Override
public Set<Type> grArg(PlaceholderType type) {
// TODO Auto-generated method stub
return null;
return new HashSet<>();
}
@Override
@ -132,24 +145,48 @@ public class FiniteClosure implements IFiniteClosure {
result.add(t);
smaller(type).forEach(x -> result.add(new ExtendsType(x)));
greater(type).forEach(x -> result.add(new ExtendsType(x)));
return result;
}
public Set<Type> smArg(ExtendsType type) {
return null;
if(!inheritanceGraph.containsKey(type.getExtendedType().getName()))
return new HashSet<Type>();
Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getExtendedType().getName()).getContent();
result.add(t);
smaller(t).forEach(x -> {
result.add(new ExtendsType(x));
result.add(x);
});
return result;
}
@Override
public Set<Type> smArg(SuperType type) {
// TODO Auto-generated method stub
return null;
if(!inheritanceGraph.containsKey(type.getSuperedType().getName()))
return new HashSet<Type>();
Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getSuperedType().getName()).getContent();
result.add(t);
greater(t).forEach(x -> {
result.add(new SuperType(x));
result.add(x);
});
return result;
}
@Override
public Set<Type> smArg(PlaceholderType type) {
// TODO Auto-generated method stub
return null;
return new HashSet<>();
}
}

View File

@ -12,7 +12,7 @@ public class SuperType extends Type {
this.superedType = superedType;
}
public Type GetSuperedType() {
public Type getSuperedType() {
return superedType;
}