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

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
	modified:   ../javFiles/Matrix.jav
This commit is contained in:
Martin Plümicke 2018-07-02 17:24:16 +02:00
parent e0c5afcd6d
commit b8e229cf3f
5 changed files with 57 additions and 12 deletions

View File

@ -938,7 +938,9 @@ public class RuleSet implements IRuleSet{
else {
UnifyType freshTph = PlaceholderType.freshPlaceholder();
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
Set<UnifyType> fBounded = pair.getfBounded();
fBounded.add(lhsType);
result.add(new UnifyPair(freshTph, superedType, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair(), fBounded));
}
return Optional.of(result);

View File

@ -13,6 +13,7 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.RecursiveTask;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -447,6 +448,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
System.out.print("");
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
System.out.print("");
writeLog("nextSetasList: " + nextSetasList.toString());
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
Set<UnifyPair> a = null;
if (variance == 1) {
@ -488,6 +490,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
elems.add(a);
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
writeLog("Vor unify2 Aufruf: " + eq.toString());
Set<Set<UnifyPair>> res = unify2(elems, eq, fc, parallel);
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
@ -512,7 +515,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
//}
/* auskommentiert um alle Loesungen zu bekommen ANFANG
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
System.out.print("");
@ -582,6 +586,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// result.removeIf(y -> isUndefinedPairSet(y));
//}
//else result.stream().filter(y -> !isUndefinedPairSet(y));
* auskommentiert um alle Loesungen zu bekommen ENDE
*/
}
return result;
}
@ -1094,7 +1100,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
UnifyType supAPrime = new SuperType(aPrime);
UnifyType thetaPrime = subThetaPrime.getSuperedType();
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
result.add(resultPrime);
//writeLog(resultPrime.toString());
@ -1124,14 +1130,34 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
break;
}
for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) {
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
Set<UnifyPair> resultPrime = new HashSet<>();
Match match = new Match();
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
for(int i = 0; !allGen && i < freshTphs.length; i++) {
freshTphs[i] = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
Set<UnifyType> fBounded = pair.getfBounded();
int i_ef = i;
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
{
ArrayList<UnifyPair> termList = new ArrayList<UnifyPair>();
termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT));
return ((match.match(termList).isPresent()) || x);
};
//if (parai.getName().equals("java.lang.Integer")) {
// System.out.println("");
//}
BinaryOperator<Boolean> bo = (x,y) -> (x || y);
if (fBounded.stream().reduce(false,f,bo)) {
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
}
else {
fBounded.add(theta);
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair, fBounded));
}
}
if(allGen)
@ -1165,9 +1191,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
((PlaceholderType)freshTph).setVariance(a.getVariance());
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair));
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded()));
result.add(resultPrime);
//writeLog(resultPrime.toString());
writeLog("resultPrime: " + resultPrime.toString());
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));

View File

@ -102,7 +102,7 @@ public class Unifier implements Function<UnifyType, UnifyType>, Iterable<Entry<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(), p.getfBounded());
}
/**

View File

@ -50,6 +50,13 @@ public class UnifyPair {
* PL 2018-03-15
*/
private UnifyPair basePair;
/**
* For pairs a <. Theta generated in the rule reduceTphSup
* to store the f-Bouned Elements to avoid endless recursion
* PL 2018-03-15
*/
private Set<UnifyType> fBounded = new HashSet<>();
private final int hashCode;
@ -82,6 +89,12 @@ public class UnifyPair {
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
}
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op, Set<UnifyPair> uni, UnifyPair base, Set<UnifyType> fBounded) {
this(lhs, rhs, op, uni, base);
this.fBounded = fBounded;
}
/**
* Returns the type on the left hand side of the pair.
*/
@ -138,6 +151,10 @@ public class UnifyPair {
return lhs.wrongWildcard() || rhs.wrongWildcard();
}
public Set<UnifyType> getfBounded() {
return this.fBounded;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof UnifyPair))
@ -177,7 +194,7 @@ public class UnifyPair {
if (rhs instanceof PlaceholderType) {
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString();
}
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")";
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])";
}
/*

View File

@ -15,9 +15,9 @@ class Matrix extends Vector<Vector<Integer>> {
var erg = 0;
var k = 0;
while(k < v1.size()) {
erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
// erg = add1(erg, mul1(v1.elementAt(k),
// m.elementAt(k).elementAt(j)));
//erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
erg = add1(erg, mul1(v1.elementAt(k),
m.elementAt(k).elementAt(j)));
k++; }
v2.addElement(new Integer(erg));
j++; }