modified: src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java
modified: src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
This commit is contained in:
parent
831bf1fe17
commit
bb016e6417
@ -5,6 +5,7 @@ import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||
@ -62,5 +63,5 @@ public interface IFiniteClosure {
|
||||
public Set<UnifyType> getChildren(UnifyType t);
|
||||
public Set<UnifyType> getAllTypesByName(String typeName);
|
||||
|
||||
public int compare(UnifyType rhsType, UnifyType rhsType2);
|
||||
public int compare(UnifyType rhsType, UnifyType rhsType2, PairOperator pairop);
|
||||
}
|
||||
|
@ -435,7 +435,11 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
||||
}
|
||||
|
||||
public int compare (UnifyType left, UnifyType right) {
|
||||
UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT);
|
||||
return compare(left, right, PairOperator.SMALLERDOT);
|
||||
}
|
||||
|
||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||
UnifyPair up = new UnifyPair(left, right, pairop);
|
||||
TypeUnifyTask unifyTask = new TypeUnifyTask();
|
||||
HashSet<UnifyPair> hs = new HashSet<>();
|
||||
hs.add(up);
|
||||
@ -443,7 +447,7 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
||||
long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count();
|
||||
if (smallerLen == 0) return -1;
|
||||
else {
|
||||
up = new UnifyPair(right, left, PairOperator.SMALLERDOT);
|
||||
up = new UnifyPair(right, left, pairop);
|
||||
//TypeUnifyTask unifyTask = new TypeUnifyTask();
|
||||
hs = new HashSet<>();
|
||||
hs.add(up);
|
||||
|
@ -31,10 +31,10 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
if (left == null || right == null)
|
||||
System.out.println("Fehler");
|
||||
if (left.getLhsType() instanceof PlaceholderType) {
|
||||
return fc.compare(left.getRhsType(), right.getRhsType());
|
||||
return fc.compare(left.getRhsType(), right.getRhsType(), left.getPairOp());
|
||||
}
|
||||
else {
|
||||
return fc.compare(left.getLhsType(), right.getLhsType());
|
||||
return fc.compare(left.getLhsType(), right.getLhsType(), left.getPairOp());
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,12 +66,43 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> leftle = left.stream()
|
||||
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC))
|
||||
.filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)
|
||||
&& x.getPairOp() == PairOperator.SMALLERDOT))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> rightle = right.stream()
|
||||
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.SMALLERDOTWC))
|
||||
.filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)
|
||||
&& x.getPairOp() == PairOperator.SMALLERDOT))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
if (lefteq.size() > 1) {
|
||||
Set<UnifyPair> leftlewc = left.stream()
|
||||
.filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)
|
||||
&& x.getPairOp() == PairOperator.SMALLERDOTWC))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
Set<UnifyPair> rightlewc = right.stream()
|
||||
.filter(x -> ((x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)
|
||||
&& x.getPairOp() == PairOperator.SMALLERDOTWC))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
//Fall 2 und 3
|
||||
if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||
return 1;
|
||||
}
|
||||
//Fall 2 und 3
|
||||
if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 1) {
|
||||
return -1;
|
||||
}
|
||||
//Fall 5
|
||||
if (lefteq.size() == 1 && leftle.size() == 0 && righteq.size() == 1 && rightle.size() == 1) {
|
||||
return -1;
|
||||
}
|
||||
//Fall 5
|
||||
if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 0) {
|
||||
return 1;
|
||||
}
|
||||
//Fall 5
|
||||
if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 1) {
|
||||
return 0;
|
||||
}
|
||||
// Nur Paare a =. Theta
|
||||
if (leftle.size() == 0 && rightle.size() == 0 && leftlewc.size() == 0 && rightlewc.size() ==0) {
|
||||
Stream<UnifyPair> lseq = lefteq.stream(); //left.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
|
||||
Stream<UnifyPair> rseq = righteq.stream(); //right.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT));
|
||||
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
|
||||
@ -81,7 +112,8 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
if (!si.isPresent()) return 0;
|
||||
else return si.get();
|
||||
}
|
||||
if (lefteq.size() == 1 && righteq.size() == 1) {
|
||||
//Fall 1 und 4
|
||||
if (lefteq.size() == 1 && righteq.size() == 1 && (leftlewc.size() > 0 || rightlewc.size() > 0)) {
|
||||
//TODO 2018-03-02: hier muessen mehree =. eingefuegt werden und alle weiteren Faelle pruefen
|
||||
UnifyPair lseq = lefteq.iterator().next();
|
||||
UnifyPair rseq = righteq.iterator().next();
|
||||
@ -95,26 +127,28 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
Pair<Integer, Set<UnifyPair>> int_Unifier = compare(lseq.getRhsType(), rseq.getRhsType());
|
||||
Unifier uni = new Unifier();
|
||||
int_Unifier.getValue().stream().forEach(x -> uni.add((PlaceholderType) x.getLhsType(), x.getRhsType()));
|
||||
if (leftle.size() == 0) return int_Unifier.getKey();
|
||||
if (lseq.equals(rseq) || leftlewc.size() == 0 || rightlewc.size() == 0) return int_Unifier.getKey();
|
||||
else {
|
||||
Stream <UnifyPair> lslestr = leftle.stream().map(uni::apply);
|
||||
Stream <UnifyPair> rslestr = rightle.stream().map(uni::apply);
|
||||
Set <UnifyPair> lsleuni = leftlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new));
|
||||
Set <UnifyPair> rsleuni = rightlewc.stream().map(uni::apply).collect(Collectors.toCollection(HashSet::new));
|
||||
BinaryOperator<HashMap<UnifyType,UnifyPair>> combiner = (x,y) -> { x.putAll(y); return x;};
|
||||
|
||||
HashMap<UnifyType,UnifyPair> hm;
|
||||
Optional<Integer> si;
|
||||
if (leftle.iterator().next().getLhsType() instanceof PlaceholderType) {
|
||||
hm = rslestr.reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
|
||||
lslestr = lslestr.filter(x -> !(hm.get(x.getLhsType()) == null));
|
||||
si = lslestr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||
//1. Fall
|
||||
if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) {
|
||||
hm = rsleuni.stream().reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner);
|
||||
Stream<UnifyPair> lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null));
|
||||
si = lslewcstr.map(x -> compare(x, hm.get(x.getLhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||
}
|
||||
//4. Fall
|
||||
else {
|
||||
hm = rslestr.reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner);
|
||||
rslestr = rslestr.filter(x -> !(hm.get(x.getRhsType()) == null));
|
||||
si = rslestr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||
hm = rsleuni.stream().reduce(new HashMap<UnifyType,UnifyPair>(), (x, y)-> { x.put(y.getRhsType(),y); return x; }, combiner);
|
||||
Stream<UnifyPair> lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getRhsType()) == null));
|
||||
si = lslewcstr.map(x -> compare(x, hm.get(x.getRhsType()))).reduce((x,y)-> { if (x == y) return x; else return 0; } );
|
||||
}
|
||||
if (!si.isPresent()) return 0;
|
||||
else return si.get();
|
||||
else if (si.get() == int_Unifier.getKey()) return int_Unifier.getKey(); else return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user