forked from JavaTX/JavaCompilerCore
subst rule
This commit is contained in:
parent
3ff45a01de
commit
8eecda2a8f
@ -2,9 +2,12 @@ package de.dhbwstuttgart.typeinference.unifynew;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
@ -516,9 +519,42 @@ public class RuleSet implements IRuleSet{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<MPair> subst(Set<MPair> pair) {
|
public Set<MPair> subst(Set<MPair> pairs) {
|
||||||
// TODO Auto-generated method stub
|
HashSet<Type> allTypes = new HashSet<>();
|
||||||
return null;
|
pairs.forEach(x -> { allTypes.add(x.getLhsType()); allTypes.add(x.getRhsType()); });
|
||||||
|
|
||||||
|
Queue<MPair> result = new LinkedList<MPair>(pairs);
|
||||||
|
|
||||||
|
for(int i = 0; i < result.size(); i++) {
|
||||||
|
MPair pair = result.poll();
|
||||||
|
Type lhsType;
|
||||||
|
Type rhsType;
|
||||||
|
if(pair.getPairOp() == PairOperator.EQUALSDOT
|
||||||
|
&& ((lhsType = pair.getLhsType()) instanceof PlaceholderType)
|
||||||
|
&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
|
||||||
|
&& occursInSet(lhsType, allTypes)
|
||||||
|
&& !occurs(lhsType, rhsType)) {
|
||||||
|
Unifier uni = new Unifier(lhsType, rhsType);
|
||||||
|
result = result.stream().map(uni::apply).collect(Collectors.toCollection(LinkedList::new));
|
||||||
|
}
|
||||||
|
result.add(pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HashSet<>(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean occursInSet(Type t, Set<Type> types) {
|
||||||
|
int origSize = types.size();
|
||||||
|
types.add(t);
|
||||||
|
return types.size() == origSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean occurs(Type t1, Type t2) {
|
||||||
|
TypeParams t2Params = t2.getTypeParams();
|
||||||
|
for(Type t2Param : t2Params)
|
||||||
|
if(t1.equals(t2Param) || occurs(t1, t2Param))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,16 @@ public class Unify {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
* Im Paper wird Eq'' genannt, es wird also von einer Menge in einer Menge in einer Menge ausgegangen.
|
||||||
|
* Durch das flache Kartesische Produkt gibt es hier aber nur Mengen in Mengen.
|
||||||
|
* Richtig so?
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step 6: a) Restart for pairs where subst was applied
|
* Step 6: a) Restart for pairs where subst was applied
|
||||||
* b) Union over everything
|
* b) Union over everything
|
||||||
|
Loading…
x
Reference in New Issue
Block a user