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

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

Links der substitierten Pare eingefuegt.
This commit is contained in:
Martin Plümicke 2018-03-15 17:00:26 +01:00
parent 7e6dee8e1d
commit de5b43d72b
3 changed files with 56 additions and 9 deletions

View File

@ -157,9 +157,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if(!undefinedPairs.isEmpty()) {
writeLog("UndefinedPairs; " + undefinedPairs);
Set<Set<UnifyPair>> error = new HashSet<>();
undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new));
error.add(undefinedPairs);
//return error;
return new HashSet<>();
return error;
}
/* Up to here, no cartesian products are calculated.
@ -297,7 +297,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
/*
* Step 7: Filter empty sets;
*/
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new));
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
if (!eqPrimePrimeSet.isEmpty())
writeLog("Result " + eqPrimePrimeSet.toString());
return eqPrimePrimeSet;
@ -363,11 +363,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
else {
result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
}
//if (result.size() == 1) {
// System.out.println(result.toString());
// result.remove(result.iterator().next());
//}
if (!result.isEmpty()) {
if (!result.isEmpty() && !isUndefinedPairSetSet(result)) {
if (variance == 1) {
if (a.iterator().next().getLhsType().getName().equals("WL"))
System.out.print("");
@ -396,10 +392,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
}
}
if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result)) {
return result;
}
//else result.stream().filter(y -> !isUndefinedPairSet(y));
}
return result;
}
protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
Optional<Boolean> res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y));
if (res.isPresent()) { return res.get(); }
else { return false; }
}
protected boolean isUndefinedPairSetSet(Set<Set<UnifyPair>> s) {
if (s.size() ==1) {
Optional<Boolean> res = s.stream().map(x -> isUndefinedPairSet(x)).reduce((x,y)-> (x == y));
if (res.isPresent()) { return res.get(); }
else { return false; }
}
return false;
}
/**
* Checks whether a set of pairs is in solved form.
* @param eqPrimePrime The set of pair

View File

@ -63,7 +63,7 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<P
* @return A new pair where the left and right-hand side are applied
*/
public UnifyPair apply(UnifyPair p) {
return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp());
return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp(), this, p);
}
/**

View File

@ -29,6 +29,18 @@ public class UnifyPair {
private byte variance = 0;
private boolean undefinedPair = false;
/**
* Unifier that generated this pair
* PL 2018-03-15
*/
private Unifier unifier;
/**
* Base on which the the unifier is applied
* PL 2018-03-15
*/
private UnifyPair basePair;
private final int hashCode;
@ -47,6 +59,18 @@ public class UnifyPair {
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
}
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Unifier uni, UnifyPair base) {
this.lhs = lhs;
this.rhs = rhs;
pairOp = op;
unifier = uni;
basePair = base;
// Caching hashcode
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
}
/**
* Returns the type on the left hand side of the pair.
*/
@ -75,6 +99,14 @@ public class UnifyPair {
public void setVariance(byte v) {
variance = v;
}
public void setUndefinedPair() {
undefinedPair = true;
}
public boolean isUndefinedPair() {
return undefinedPair;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof UnifyPair))