diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 39b0de33..1669b760 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -439,7 +439,7 @@ public class RuleSet implements IRuleSet{ if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType)) return false; - return fc.greater(lhsType, new HashSet<>()).contains(rhsType); + return fc.greater(lhsType, new HashSet<>(), pair.getLocation()).contains(rhsType); } @Override diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index 557b664a..5868f0ea 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -10,6 +10,7 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; import de.dhbwstuttgart.typeinference.unify.model.SuperType; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import org.antlr.v4.runtime.Token; /** * @@ -22,13 +23,19 @@ public interface IFiniteClosure { * Returns all types of the finite closure that are subtypes of the argument. * @return The set of subtypes of the argument. */ - public Set smaller(UnifyType type, Set fBounded); + public Set smaller(UnifyType type, Set fBounded, Token position); + public default Set smaller(UnifyType type, Set fBounded) { + return this.smaller(type, fBounded, null); + } /** * Returns all types of the finite closure that are supertypes of the argument. * @return The set of supertypes of the argument. */ - public Set greater(UnifyType type, Set fBounded); + public Set greater(UnifyType type, Set fBounded, Token position); + public default Set greater(UnifyType type, Set fBounded) { + return this.greater(type, fBounded, null); + } /** * Wo passt Type rein? diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 55340fdc..f5671686 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -27,6 +27,7 @@ import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; import de.dhbwstuttgart.util.Pair; +import org.antlr.v4.runtime.Token; /** * The finite closure for the type unification @@ -145,7 +146,7 @@ implements IFiniteClosure { * @return The set of subtypes of the argument. */ @Override - public Set smaller(UnifyType type, Set fBounded) { + public Set smaller(UnifyType type, Set fBounded, Token position) { Set ret; if ((ret = smallerHash.get(new hashKeyType(type))) != null) { @@ -260,8 +261,7 @@ implements IFiniteClosure { */ @Override //Eingefuegt PL 2018-05-24 F-Bounded Problematik - public Set greater(UnifyType type, Set fBounded) { - + public Set greater(UnifyType type, Set fBounded, Token location) { Set ret; if ((ret = greaterHash.get(new hashKeyType(type))) != null) { //System.out.println(greaterHash); @@ -302,7 +302,7 @@ implements IFiniteClosure { //PL 18-04-05 Unifier durch Matcher ersetzt ANFANG ArrayList termList= new ArrayList(); - termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT)); + termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT, location)); Optional optSigma = match.match(termList); //PL 18-04-05 Unifier durch Matcher ersetzt ENDE if(!optSigma.isPresent()) { @@ -344,7 +344,7 @@ implements IFiniteClosure { BiFunction f = (x,y) -> { ArrayList termList = new ArrayList(); - termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); + termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT, location)); return ((match.match(termList).isPresent()) || x); }; //if (parai.getName().equals("java.lang.Integer")) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 8cfac643..db050c03 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -102,7 +102,7 @@ public class Unifier implements Function, Iterable uni, UnifyPair base) { + this(lhs, rhs, op, uni, base, null); + } + + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded) { + this(lhs, rhs, op, uni, base, fBounded, null); + } + + public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded, Token location) { this.lhs = lhs; this.rhs = rhs; pairOp = op; substitution = uni; basePair = base; - - + this.location = location; + // Caching hashcode hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode(); - } - - public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set uni, UnifyPair base, Set fBounded) { - this(lhs, rhs, op, uni, base); - - this.fBounded = fBounded; } public Token getLocation() { if (location != null) return location; - else if (basePair != null) return basePair.getLocation();; + else if (basePair != null) return basePair.getLocation(); return null; }