This commit is contained in:
Martin Plümicke 2018-03-02 14:12:06 +01:00
parent 356b8a7a34
commit 9f3439a15e
3 changed files with 71 additions and 39 deletions

View File

@ -454,14 +454,14 @@ public class RuleSet implements IRuleSet{
TypeParams typeDParams = typeD.getTypeParams();
TypeParams typeDgenParams = typeDgen.getTypeParams();
System.out.println("Pair: " +pair);
System.out.println("typeD: " +typeD);
//System.out.println("Pair: " +pair);
//System.out.println("typeD: " +typeD);
//System.out.println("typeDParams: " +typeDParams);
System.out.println("typeDgen: " +typeD);
//System.out.println("typeDgen: " +typeD);
//System.out.println("typeDgenParams: " +typeDgenParams);
Unifier unif = Unifier.identity();
for(int i = 0; i < typeDParams.size(); i++) {
System.out.println("ADAPT" +typeDgenParams);
//System.out.println("ADAPT" +typeDgenParams);
if (typeDgenParams.get(i) instanceof PlaceholderType)
unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
else System.out.println("ERROR");

View File

@ -203,31 +203,6 @@ 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) {
//Aufruf von computeCartesianRecursive ENDE
@ -635,7 +610,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
undefined.add(pair);
break;
}
first = true;
first = false;
}
// Filter empty sets or sets that only contain an empty set.

View File

@ -1,13 +1,20 @@
package de.dhbwstuttgart.typeinference.unify.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Set;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javafx.util.Pair;
import com.google.common.collect.Ordering;
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
@ -26,14 +33,64 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
return fc.compare(left.getRhsType(), right.getRhsType());
}
public Pair<Integer,Set<UnifyPair>> compare (UnifyType left, UnifyType right) {
UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT);
TypeUnifyTask unifyTask = new TypeUnifyTask();
HashSet<UnifyPair> hs = new HashSet<>();
hs.add(up);
Set<UnifyPair> smallerRes = unifyTask.applyTypeUnificationRules(hs, fc);
long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count();
if (smallerLen == 0) return new Pair<>(-1, smallerRes);
else {
up = new UnifyPair(right, left, PairOperator.SMALLERDOT);
//TypeUnifyTask unifyTask = new TypeUnifyTask();
hs = new HashSet<>();
hs.add(up);
Set<UnifyPair> greaterRes = unifyTask.applyTypeUnificationRules(hs, fc);
long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count();
if (greaterLen == 0) return new Pair<>(1, smallerRes);
else return new Pair<>(0, new HashSet<>());
}
}
public int compare (Set<UnifyPair> left, Set<UnifyPair> right) {
Stream<UnifyPair> ls = left.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
Stream<UnifyPair> rs = right.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
HashMap<UnifyType,UnifyPair> hm = rs.reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
ls = ls.filter(x -> !(hm.get(x.getLhsType()) == null));
Optional<Integer> si = ls.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
if (!si.isPresent()) return 0;
else return si.get();
if (!true) {
Stream<UnifyPair> lseq = left.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
Stream<UnifyPair> rseq = right.stream().filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
HashMap<UnifyType,UnifyPair> hm = rseq.reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null));
Optional<Integer> si = lseq.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
if (!si.isPresent()) return 0;
else return si.get();
}
else {
Optional<UnifyPair> lseq = left.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)).findFirst();
Optional<UnifyPair> rseq = right.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)).findFirst();
Set<UnifyPair> lsle = left.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC))
.collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> rsle = right.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC))
.collect(Collectors.toCollection(HashSet::new));
Pair<Integer, Set<UnifyPair>> int_Unifier = compare(lseq.get().getRhsType(), rseq.get().getRhsType());
Unifier uni = new Unifier();
int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
if (lsle.size() == 0) return int_Unifier.getKey();
else {
Stream <UnifyPair> lslestr = lsle.stream().map(uni::apply);
Stream <UnifyPair> rslestr = rsle.stream().map(uni::apply);
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
HashMap<UnifyType,UnifyPair> hm = rslestr.reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
lseq = lseq.filter(x -> !(hm.get(x.getLhsType()) == null));
Optional<Integer> si = lslestr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
if (!si.isPresent()) return 0;
else return si.get();
}
}
}
}