forked from JavaTX/JavaCompilerCore
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:
parent
9717c54d53
commit
52f480147e
@ -95,7 +95,7 @@ public class MartelliMontanariUnify implements IUnify {
|
|||||||
if(lhsType instanceof PlaceholderType) {
|
if(lhsType instanceof PlaceholderType) {
|
||||||
mgu.add((PlaceholderType) lhsType, rhsType);
|
mgu.add((PlaceholderType) lhsType, rhsType);
|
||||||
//PL 2018-04-01 nach checken, ob es richtig ist, dass keine Substitutionen uebergeben werden muessen.
|
//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;
|
idx = idx+1 == termsList.size() ? 0 : idx+1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
|
||||||
&& !rhsType.getTypeParams().occurs(lhsType)) {
|
&& !rhsType.getTypeParams().occurs(lhsType)) {
|
||||||
Unifier uni = new Unifier(lhsType, rhsType);
|
Unifier uni = new Unifier(lhsType, rhsType);
|
||||||
result = result.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(ArrayList::new));
|
result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new));
|
||||||
result1 = result1.stream().map(x -> uni.apply(pair.getSubstitution(),x)).collect(Collectors.toCollection(LinkedList::new));
|
result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new));
|
||||||
applied = true;
|
applied = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,8 +151,8 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName())
|
if (!lseq.getRhsType().getName().equals(rseq.getRhsType().getName())
|
||||||
|| leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey();
|
|| leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey();
|
||||||
else {
|
else {
|
||||||
Set <UnifyPair> lsleuni = leftlewc.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(new HashSet<>(),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;};
|
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
|
||||||
|
|
||||||
HashMap<UnifyType,UnifyPair> hm;
|
HashMap<UnifyType,UnifyPair> hm;
|
||||||
@ -183,7 +183,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
}
|
}
|
||||||
Unifier uni = new Unifier();
|
Unifier uni = new Unifier();
|
||||||
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
||||||
lseq = uni.apply(new HashSet<>(), lseq);
|
lseq = uni.apply(lseq);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<UnifyPair> subst;
|
Set<UnifyPair> subst;
|
||||||
@ -195,7 +195,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
}
|
}
|
||||||
Unifier uni = new Unifier();
|
Unifier uni = new Unifier();
|
||||||
subst.stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
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);
|
return compareEq(lseq, rseq);
|
||||||
}
|
}
|
||||||
|
@ -64,13 +64,26 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<P
|
|||||||
* Applies the unifier to the two terms of the pair.
|
* Applies the unifier to the two terms of the pair.
|
||||||
* @return A new pair where the left and right-hand side are applied
|
* @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 newLhs = this.apply(p.getLhsType());
|
||||||
UnifyType newRhs = this.apply(p.getRhsType());
|
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
|
return new UnifyPair(newLhs, newRhs, p.getPairOp());
|
||||||
Set<Unifier> suniUnifyPair = new HashSet<>();
|
}
|
||||||
suniUnifyPair.addAll(suniSubstitution);
|
|
||||||
suniUnifyPair.add(this);
|
/**
|
||||||
|
* 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(), suniUnifyPair, p);
|
||||||
}
|
}
|
||||||
return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair());
|
return new UnifyPair(newLhs, newRhs, p.getPairOp(), p.getSubstitution(), p.getBasePair());
|
||||||
|
@ -43,7 +43,7 @@ public class UnifyPair {
|
|||||||
* Unifier/substitute that generated this pair
|
* Unifier/substitute that generated this pair
|
||||||
* PL 2018-03-15
|
* PL 2018-03-15
|
||||||
*/
|
*/
|
||||||
private Set<Unifier> substitution;
|
private Set<UnifyPair> substitution;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base on which the the unifier is applied
|
* 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();
|
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.lhs = lhs;
|
||||||
this.rhs = rhs;
|
this.rhs = rhs;
|
||||||
pairOp = op;
|
pairOp = op;
|
||||||
@ -114,7 +114,7 @@ public class UnifyPair {
|
|||||||
public void setUndefinedPair() {
|
public void setUndefinedPair() {
|
||||||
undefinedPair = true;
|
undefinedPair = true;
|
||||||
}
|
}
|
||||||
public Set<Unifier> getSubstitution() {
|
public Set<UnifyPair> getSubstitution() {
|
||||||
return substitution;
|
return substitution;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +124,14 @@ public class UnifyPair {
|
|||||||
public boolean isUndefinedPair() {
|
public boolean isUndefinedPair() {
|
||||||
return undefinedPair;
|
return undefinedPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<UnifyPair> getAllSubstitutions () {
|
||||||
|
Set<UnifyPair> ret = new HashSet<>();
|
||||||
|
ret.addAll(getSubstitution());
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(!(obj instanceof UnifyPair))
|
if(!(obj instanceof UnifyPair))
|
||||||
|
Loading…
Reference in New Issue
Block a user