diff --git a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index ae3384ed..fb620046 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -22,7 +22,18 @@ public interface IFiniteClosure { */ public Set greater(Type type); + /** + * Wo passt Type rein? + * @param type + * @return + */ public Set grArg(Type type); + + /** + * Was passt in Type rein? + * @param type + * @return + */ public Set smArg(Type type); public Set grArg(SimpleType type); diff --git a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java index cc4c7dbf..2b642f43 100644 --- a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java @@ -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 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() diff --git a/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java index ff5b5b79..7a65fc30 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java @@ -11,7 +11,7 @@ public class ExtendsType extends Type { this.extendedType = extendedType; } - public Type GetExtendedType() { + public Type getExtendedType() { return extendedType; } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java index ff1c5106..0b1ee461 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java @@ -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 grArg(ExtendsType type) { - // TODO Auto-generated method stub - return null; + if(!inheritanceGraph.containsKey(type.getExtendedType().getName())) + return new HashSet(); + + Set result = new HashSet(); + + Type t = inheritanceGraph.get(type.getExtendedType().getName()).getContent(); + + greater(t).forEach(x -> result.add(new ExtendsType(x))); + + return result; } @Override public Set grArg(SuperType type) { - // TODO Auto-generated method stub - return null; + if(!inheritanceGraph.containsKey(type.getSuperedType().getName())) + return new HashSet(); + + Set result = new HashSet(); + + Type t = inheritanceGraph.get(type.getSuperedType().getName()).getContent(); + + smaller(t).forEach(x -> result.add(new SuperType(x))); + + return result; } @Override public Set 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 smArg(ExtendsType type) { - return null; + if(!inheritanceGraph.containsKey(type.getExtendedType().getName())) + return new HashSet(); + + Set result = new HashSet(); + + 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 smArg(SuperType type) { - // TODO Auto-generated method stub - return null; + if(!inheritanceGraph.containsKey(type.getSuperedType().getName())) + return new HashSet(); + + Set result = new HashSet(); + + 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 smArg(PlaceholderType type) { - // TODO Auto-generated method stub - return null; + return new HashSet<>(); } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java index d9116f08..d7f0f38a 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java @@ -12,7 +12,7 @@ public class SuperType extends Type { this.superedType = superedType; } - public Type GetSuperedType() { + public Type getSuperedType() { return superedType; }