modified: src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java

modified:   src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java

Subsitution auf UnifyPair umgestellt
This commit is contained in:
Martin Plümicke 2018-04-04 01:14:30 +02:00
parent 9717c54d53
commit 52f480147e
5 changed files with 36 additions and 15 deletions

View File

@ -95,7 +95,7 @@ public class MartelliMontanariUnify implements IUnify {
if(lhsType instanceof PlaceholderType) {
mgu.add((PlaceholderType) lhsType, rhsType);
//PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen.
termsList = termsList.stream().map(x -> mgu.apply(new HashSet<>(), x)).collect(Collectors.toCollection(ArrayList::new));
termsList = termsList.stream().map(x -> mgu.apply(x)).collect(Collectors.toCollection(ArrayList::new));
idx = idx+1 == termsList.size() ? 0 : idx+1;
continue;
}

View File

@ -636,8 +636,8 @@ public class RuleSet implements IRuleSet{
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
&& !rhsType.getTypeParams().occurs(lhsType)) {
Unifier uni = new Unifier(lhsType, rhsType);
result = result.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(ArrayList::new));
result1 = result1.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(LinkedList::new));
result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
applied = true;
}

View File

@ -151,8 +151,8 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName())
|| leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey();
else {
Set <UnifyPair> lsleuni = leftlewc.stream().map(x -> uni.apply(new HashSet<>(),x)).collect(Collectors.toCollection(HashSet::new));
Set <UnifyPair> rsleuni = rightlewc.stream().map(x -> uni.apply(new HashSet<>(),x)).collect(Collectors.toCollection(HashSet::new));
Set <UnifyPair> lsleuni = leftlewc.stream().map(x -> uni.apply(x)).collect(Collectors.toCollection(HashSet::new));
Set <UnifyPair> rsleuni = rightlewc.stream().map(x -> uni.apply(x)).collect(Collectors.toCollection(HashSet::new));
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
HashMap<UnifyType,UnifyPair> hm;
@ -183,7 +183,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
}
Unifier uni = new Unifier();
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
lseq = uni.apply(new HashSet<>(), lseq);
lseq = uni.apply(lseq);
}
else {
Set<UnifyPair> subst;
@ -195,7 +195,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
}
Unifier uni = new Unifier();
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
rseq = uni.apply(new HashSet<>(), rseq);
rseq = uni.apply(rseq);
}
return compareEq(lseq, rseq);
}

View File

@ -64,13 +64,26 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<P
* Applies the unifier to the two terms of the pair.
* @return A new pair where the left and right-hand side are applied
*/
public UnifyPair apply(Set<Unifier> suniSubstitution, UnifyPair p) {
public UnifyPair apply(UnifyPair p) {
UnifyType newLhs = this.apply(p.getLhsType());
UnifyType newRhs = this.apply(p.getRhsType());
if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwedung von this hat was veraendert PL 2018-04-01
Set<Unifier> suniUnifyPair = new HashSet<>();
suniUnifyPair.addAll(suniSubstitution);
suniUnifyPair.add(this);
return new UnifyPair(newLhs, newRhs, p.getPairOp());
}
/**
* Applies the unifier to the two terms of the pair.
* @return A new pair where the left and right-hand side are applied
*/
public UnifyPair apply(UnifyPair thisAsPair, UnifyPair p) {
UnifyType newLhs = this.apply(p.getLhsType());
UnifyType newRhs = this.apply(p.getRhsType());
if (!(p.getLhsType().equals(newLhs)) || !(p.getRhsType().equals(newRhs))) {//Die Anwendung von this hat was veraendert PL 2018-04-01
Set<UnifyPair> suniUnifyPair = new HashSet<>();
suniUnifyPair.addAll(thisAsPair.getSubstitution());
suniUnifyPair.add(thisAsPair);
if (p.getLhsType() instanceof PlaceholderType && newLhs instanceof PlaceholderType && p.getPairOp() == PairOperator.EQUALSDOT) {
suniUnifyPair.add(p); //p koennte auch subsitution sein
}
return new UnifyPair(newLhs, newRhs, p.getPairOp(), suniUnifyPair, p);
}
return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair());

View File

@ -43,7 +43,7 @@ public class UnifyPair {
* Unifier/substitute that generated this pair
* PL 2018-03-15
*/
private Set<Unifier> substitution;
private Set<UnifyPair> substitution;
/**
* Base on which the the unifier is applied
@ -69,7 +69,7 @@ public class UnifyPair {
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
}
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set<Unifier> uni, UnifyPair base) {
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set<UnifyPair> uni, UnifyPair base) {
this.lhs = lhs;
this.rhs = rhs;
pairOp = op;
@ -114,7 +114,7 @@ public class UnifyPair {
public void setUndefinedPair() {
undefinedPair = true;
}
public Set<Unifier> getSubstitution() {
public Set<UnifyPair> getSubstitution() {
return substitution;
}
@ -124,6 +124,14 @@ public class UnifyPair {
public boolean isUndefinedPair() {
return undefinedPair;
}
Set<UnifyPair> getAllSubstitutions () {
Set<UnifyPair> ret = new HashSet<>();
ret.addAll(getSubstitution());
return ret;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof UnifyPair))