forked from JavaTX/JavaCompilerCore
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:
parent
e0c5afcd6d
commit
b8e229cf3f
@ -938,7 +938,9 @@ public class RuleSet implements IRuleSet{
|
|||||||
else {
|
else {
|
||||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||||
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
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);
|
return Optional.of(result);
|
||||||
|
@ -13,6 +13,7 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.RecursiveTask;
|
import java.util.concurrent.RecursiveTask;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.BinaryOperator;
|
import java.util.function.BinaryOperator;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -447,6 +448,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
System.out.print("");
|
System.out.print("");
|
||||||
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
@ -488,6 +490,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
||||||
elems.add(a);
|
elems.add(a);
|
||||||
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
//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);
|
Set<Set<UnifyPair>> res = unify2(elems, eq, fc, parallel);
|
||||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
@ -513,6 +516,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
//result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
/* auskommentiert um alle Loesungen zu bekommen ANFANG
|
||||||
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
|
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)
|
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
@ -582,6 +586,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
// result.removeIf(y -> isUndefinedPairSet(y));
|
// result.removeIf(y -> isUndefinedPairSet(y));
|
||||||
//}
|
//}
|
||||||
//else result.stream().filter(y -> !isUndefinedPairSet(y));
|
//else result.stream().filter(y -> !isUndefinedPairSet(y));
|
||||||
|
* auskommentiert um alle Loesungen zu bekommen ENDE
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1094,7 +1100,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
UnifyType supAPrime = new SuperType(aPrime);
|
UnifyType supAPrime = new SuperType(aPrime);
|
||||||
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
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);
|
result.add(resultPrime);
|
||||||
//writeLog(resultPrime.toString());
|
//writeLog(resultPrime.toString());
|
||||||
|
|
||||||
@ -1124,14 +1130,34 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) {
|
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
Match match = new Match();
|
||||||
|
|
||||||
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
||||||
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
||||||
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||||
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
|
((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)
|
if(allGen)
|
||||||
@ -1165,9 +1191,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
((PlaceholderType)freshTph).setVariance(a.getVariance());
|
((PlaceholderType)freshTph).setVariance(a.getVariance());
|
||||||
resultPrime = new HashSet<>();
|
resultPrime = new HashSet<>();
|
||||||
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
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);
|
result.add(resultPrime);
|
||||||
//writeLog(resultPrime.toString());
|
writeLog("resultPrime: " + resultPrime.toString());
|
||||||
|
|
||||||
resultPrime = new HashSet<>();
|
resultPrime = new HashSet<>();
|
||||||
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||||
|
@ -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(), 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,6 +51,13 @@ public class UnifyPair {
|
|||||||
*/
|
*/
|
||||||
private UnifyPair basePair;
|
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;
|
private final int hashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,6 +89,12 @@ 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<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.
|
* Returns the type on the left hand side of the pair.
|
||||||
*/
|
*/
|
||||||
@ -138,6 +151,10 @@ public class UnifyPair {
|
|||||||
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<UnifyType> getfBounded() {
|
||||||
|
return this.fBounded;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if(!(obj instanceof UnifyPair))
|
if(!(obj instanceof UnifyPair))
|
||||||
@ -177,7 +194,7 @@ public class UnifyPair {
|
|||||||
if (rhs instanceof PlaceholderType) {
|
if (rhs instanceof PlaceholderType) {
|
||||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString();
|
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString();
|
||||||
}
|
}
|
||||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")";
|
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -15,9 +15,9 @@ class Matrix extends Vector<Vector<Integer>> {
|
|||||||
var erg = 0;
|
var erg = 0;
|
||||||
var k = 0;
|
var k = 0;
|
||||||
while(k < v1.size()) {
|
while(k < v1.size()) {
|
||||||
erg = erg + 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),
|
erg = add1(erg, mul1(v1.elementAt(k),
|
||||||
// m.elementAt(k).elementAt(j)));
|
m.elementAt(k).elementAt(j)));
|
||||||
k++; }
|
k++; }
|
||||||
v2.addElement(new Integer(erg));
|
v2.addElement(new Integer(erg));
|
||||||
j++; }
|
j++; }
|
||||||
|
Loading…
Reference in New Issue
Block a user