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

modified:   src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Eq for Unify vereinfachen noch nicht fertig
This commit is contained in:
Martin Plümicke 2018-03-01 18:00:38 +01:00
parent 6256bdfe2e
commit 356b8a7a34
2 changed files with 49 additions and 21 deletions

View File

@ -294,8 +294,8 @@ public class RuleSet implements IRuleSet{
if(dFromFc == null || !dFromFc.getTypeParams().arePlaceholders() || dFromFc.getTypeParams().size() != cFromFc.getTypeParams().size())
return Optional.empty();
System.out.println("cFromFc: " + cFromFc);
System.out.println("dFromFc: " + dFromFc);
//System.out.println("cFromFc: " + cFromFc);
//System.out.println("dFromFc: " + dFromFc);
int[] pi = pi(cFromFc.getTypeParams(), dFromFc.getTypeParams());
if(pi.length == 0)

View File

@ -12,6 +12,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.RecursiveTask;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
@ -148,7 +149,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Sets of the "second level"
Set<UnifyPair> undefinedPairs = new HashSet<>();
if (printtag) System.out.println("eq2s " + eq2s);
writeLog("BufferSet: " + bufferSet.toString()+"\n");
//writeLog("BufferSet: " + bufferSet.toString()+"\n");
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs);
//PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer
//nicht ausgewertet Faculty Beispiel im 1. Schritt
@ -158,7 +159,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// If pairs occured that did not match one of the cartesian product cases,
// those pairs are contradictory and the unification is impossible.
if(!undefinedPairs.isEmpty()) {
if (printtag) System.out.println("UndefinedPairs; " + undefinedPairs);
writeLog("UndefinedPairs; " + undefinedPairs);
return new HashSet<>();
}
@ -202,6 +203,30 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
Set<UnifyPair> simplifyEq (Set<UnifyPair> eqs) {
Set<UnifyPair> leftVarSmaller = eqs.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType)
&& !(x.getRhsType() instanceof PlaceholderType)
&& x.getPairOp().equals(PairOperator.SMALLERDOT)).collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> leftVarEq = eqs.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType)
&& !(x.getRhsType() instanceof PlaceholderType)
&& x.getPairOp().equals(PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> rightVarSmaller = eqs.stream()
.filter(x -> (x.getRhsType() instanceof PlaceholderType)
&& !(x.getLhsType() instanceof PlaceholderType)
&& x.getPairOp().equals(PairOperator.SMALLERDOT)).collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> rightVarEq = eqs.stream()
.filter(x -> (x.getRhsType() instanceof PlaceholderType)
&& !(x.getLhsType() instanceof PlaceholderType)
&& x.getPairOp().equals(PairOperator.EQUALSDOT)).collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> ret = new HashSet<>();
for (UnifyPair eq : leftVarSmaller) {
eqs.remove(eq); HIER WEITERMACHEN
Stream eqEqualLHS = leftVarSmaller.stream().filter(x -> x.getLhsType().equals(eq.getLhsType()));
}
return ret;
}
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
@ -300,7 +325,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new));
if (!eqPrimePrimeSet.isEmpty())
System.out.println("");
writeLog("Result " + eqPrimePrimeSet.toString());
return eqPrimePrimeSet;
}
@ -315,10 +340,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<UnifyPair> a_next = oup.min(nextSetasList.iterator());
while (nextSetasList.size() != 0) {
Set<UnifyPair> a = a_next;
writeLog("nextSet: " + nextSetasList.toString()+ "\n");
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
nextSetasList.remove(a);
if (nextSetasList.size() > 0)
a_next = oup.min(nextSetasList.iterator());
//PL 2018-03-01
//TODO: 1. Maximum und Minimum unterscheiden
//TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern
//for(Set<UnifyPair> a : newSet) {
i++;
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
@ -518,7 +546,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 1: (a <. Theta')
if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) {
//System.out.println(pair);
if (first) { writeLog(pair.toString()+"\n");
if (first) { //writeLog(pair.toString()+"\n");
Set<Set<UnifyPair>> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), fc);
//System.out.println(x1);
result.get(0).add(x1);
@ -534,7 +562,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
// Case 2: (a <.? ? ext Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
if (first) {writeLog(pair.toString()+"\n");
if (first) { //writeLog(pair.toString()+"\n");
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), fc));
}
else {
@ -547,7 +575,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 3: (a <.? ? sup Theta')
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
if (first) {writeLog(pair.toString()+"\n");
if (first) { //writeLog(pair.toString()+"\n");
result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, fc));
}
else {
@ -565,7 +593,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 5: (Theta <. a)
else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType)
if (first) {writeLog(pair.toString()+"\n");
if (first) { //writeLog(pair.toString()+"\n");
result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, fc));
}
else {
@ -588,7 +616,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
// Case 8: (Theta <.? a)
else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
if (first) {writeLog(pair.toString()+"\n");
if (first) { //writeLog(pair.toString()+"\n");
result.get(7).add(
unifyCase8(lhsType, (PlaceholderType) rhsType, fc));
}
@ -607,7 +635,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
undefined.add(pair);
break;
}
first = false;
first = true;
}
// Filter empty sets or sets that only contain an empty set.
@ -694,9 +722,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
else
resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT));
resultPrime.addAll(substitutionSet);
writeLog("Substitution: " + substitutionSet.toString());
//writeLog("Substitution: " + substitutionSet.toString());
result.add(resultPrime);
writeLog("Result: " + resultPrime.toString());
//writeLog("Result: " + resultPrime.toString());
//writeLog("MAX: " + oup.max(resultPrime.iterator()).toString());
}
}
@ -724,7 +752,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT));
result.add(resultPrime);
writeLog("Result: " + resultPrime.toString());
//writeLog("Result: " + resultPrime.toString());
return result;
}
@ -740,13 +768,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT));
result.add(resultPrime);
writeLog(resultPrime.toString());
//writeLog(resultPrime.toString());
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
result.add(resultPrime);
writeLog(resultPrime.toString());
//writeLog(resultPrime.toString());
return result;
}
@ -778,7 +806,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
else
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT));
result.add(resultPrime);
writeLog(resultPrime.toString());
//writeLog(resultPrime.toString());
}
return result;
@ -793,20 +821,20 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
result.add(resultPrime);
writeLog(resultPrime.toString());
//writeLog(resultPrime.toString());
UnifyType freshTph = PlaceholderType.freshPlaceholder();
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT));
result.add(resultPrime);
writeLog(resultPrime.toString());
//writeLog(resultPrime.toString());
resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT));
result.add(resultPrime);
writeLog(resultPrime.toString());
//writeLog(resultPrime.toString());
//}
return result;