rename mpair to unify pair / refactoring

This commit is contained in:
Florian Steurer 2016-04-04 11:23:14 +02:00
parent 2e30429252
commit 6793b0bd24
22 changed files with 472 additions and 800 deletions

View File

@ -55,7 +55,7 @@ import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.Unify;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
@ -261,9 +261,9 @@ public class SourceFile
UnifyConstraintsSet unifyConstraints = UnifyTypeFactory.convert(oderConstraints);
//UnmÃgliche ConstraintsSets aussortieren durch Unifizierung
Function<Menge<MPair>,Menge<Menge<MPair>>> unifier = (pairs)->{
Menge<Menge<MPair>> retValue = new Menge<>();
Set<Set<MPair>> unifiedPairs = new Unify().unify(pairs, finiteClosure);
Function<Menge<UnifyPair>,Menge<Menge<UnifyPair>>> unifier = (pairs)->{
Menge<Menge<UnifyPair>> retValue = new Menge<>();
Set<Set<UnifyPair>> unifiedPairs = new Unify().unify(pairs, finiteClosure);
return retValue;};
//oderConstraints.filterWrongConstraints(unifier);
@ -276,7 +276,7 @@ public class SourceFile
////////////////
//Karthesisches Produkt bilden:
////////////////
Set<Set<MPair>> xConstraints = unifyConstraints.cartesianProduct();
Set<Set<UnifyPair>> xConstraints = unifyConstraints.cartesianProduct();
@ -288,7 +288,7 @@ public class SourceFile
// Unifizierung der Constraints:
//////////////////////////////
boolean unifyFail = true;
for(Set<MPair> constraints : xConstraints){
for(Set<UnifyPair> constraints : xConstraints){
//Alle durch das Karthesische Produkt entstandenen glichkeiten durchgehen:
//Menge<Menge<Pair>> result = new Menge<Menge<Pair>>();
@ -358,16 +358,16 @@ public class SourceFile
return cardprodret;
});
*/
Set<Set<MPair>> unifyResult = new Unify().unify(constraints, finiteClosure);
Set<Set<UnifyPair>> unifyResult = new Unify().unify(constraints, finiteClosure);
Menge<Menge<Pair>> convertedResult = unifyResult.parallelStream().<Menge<Pair>>map((Set<MPair> resultSet)->{
Menge<Pair> innerConvert = resultSet.stream().map((MPair mp)->UnifyTypeFactory.convert(mp))
Menge<Menge<Pair>> convertedResult = unifyResult.parallelStream().<Menge<Pair>>map((Set<UnifyPair> resultSet)->{
Menge<Pair> innerConvert = resultSet.stream().map((UnifyPair mp)->UnifyTypeFactory.convert(mp))
.collect(Menge<Pair>::new, Menge::add, Menge::addAll);
return innerConvert;
}).collect(Menge::new, Menge::add, Menge::addAll);
Menge<Pair> convertedConstraints = constraints.stream().map(
(MPair mp)->{return UnifyTypeFactory.convert(mp);}
(UnifyPair mp)->{return UnifyTypeFactory.convert(mp);}
).collect(Menge<Pair>::new, Menge::add, Menge::addAll);
//Dann den Ergebnissen anfügen

View File

@ -29,7 +29,7 @@ import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
@ -43,7 +43,7 @@ public class UnifyTypeFactory {
private final static NullSyntaxTreeNode NULL_NODE = new NullSyntaxTreeNode();
public static FiniteClosure generateFC(TypeAssumptions fromAss){
HashSet<MPair> pairs = new HashSet<>();
HashSet<UnifyPair> pairs = new HashSet<>();
for(ClassAssumption cAss : fromAss.getClassAssumptions()){
UnifyType tl = UnifyTypeFactory.convert(cAss.getAssumedClass().getType());
RefType superClass = cAss.getAssumedClass().getSuperClass();
@ -55,8 +55,8 @@ public class UnifyTypeFactory {
return new FiniteClosure(pairs);
}
public static MPair smaller(UnifyType tl, UnifyType tr){
return new MPair(tl, tr, PairOperator.SMALLER);
public static UnifyPair smaller(UnifyType tl, UnifyType tr){
return new UnifyPair(tl, tr, PairOperator.SMALLER);
}
public static UnifyType convert(Type t){
@ -129,18 +129,18 @@ public class UnifyTypeFactory {
return ret;
}
public static MPair convert(EinzelElement<Pair> p) {
public static UnifyPair convert(EinzelElement<Pair> p) {
return convert(p.getItem());
}
public static MPair convert(Pair p) {
public static UnifyPair convert(Pair p) {
if(!p.OperatorSmaller())throw new NotImplementedException();
MPair ret = smaller(UnifyTypeFactory.convert(p.TA1)
UnifyPair ret = smaller(UnifyTypeFactory.convert(p.TA1)
, UnifyTypeFactory.convert(p.TA2));
return ret;
}
public static Pair convert(MPair mp) {
public static Pair convert(UnifyPair mp) {
Type tl = UnifyTypeFactory.convert(mp.getLhsType());
Type tr = UnifyTypeFactory.convert(mp.getRhsType());
return new Pair(tl, tr, mp.getPairOp());

View File

@ -6,9 +6,9 @@ import java.util.Vector;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class UnifyConstraintsSet extends UndMenge<MPair> implements Iterable<UnifyOderConstraint>{
public class UnifyConstraintsSet extends UndMenge<UnifyPair> implements Iterable<UnifyOderConstraint>{
private static final Logger log = Logger.getLogger(UnifyConstraintsSet.class.getName());
private Menge<UnifyOderConstraint> constraintsSet;
@ -53,18 +53,18 @@ public class UnifyConstraintsSet extends UndMenge<MPair> implements Iterable<Uni
*/
public void unifyUndConstraints(Unifier unifier) {
Vector<UnifyUndConstraint> uCons = this.filterUndConstraints();
Vector<MPair> alleUndConstraints = new Vector<>();
Vector<UnifyPair> alleUndConstraints = new Vector<>();
for(UnifyUndConstraint undConstraint : uCons){
alleUndConstraints.addAll(undConstraint.getConstraintPairs());
}
this.filterWrongConstraints(
(pairs)->{
Set<MPair> undConstraintsUndPairs = new Menge<>();
Set<UnifyPair> undConstraintsUndPairs = new Menge<>();
undConstraintsUndPairs.addAll(pairs);
undConstraintsUndPairs.addAll(alleUndConstraints);
log.debug("Versuche Pairs auszusondern:\n"+pairs, Section.TYPEINFERENCE);
log.debug("Unifiziere:\n"+undConstraintsUndPairs, Section.TYPEINFERENCE);
Set<Set<MPair>> unifyResult = unifier.apply(undConstraintsUndPairs);
Set<Set<UnifyPair>> unifyResult = unifier.apply(undConstraintsUndPairs);
return unifyResult;
});
}
@ -90,7 +90,7 @@ public class UnifyConstraintsSet extends UndMenge<MPair> implements Iterable<Uni
}
@Override
public Menge<? extends KomplexeMenge<MPair>> getSet() {
public Menge<? extends KomplexeMenge<UnifyPair>> getSet() {
return this.constraintsSet;
}
}

View File

@ -9,9 +9,9 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class UnifyOderConstraint extends OderMenge<MPair>{
public class UnifyOderConstraint extends OderMenge<UnifyPair>{
private Set<UnifyUndConstraint> oderConstraintPairs;
private final static Logger logger = Logger.getLogger(UnifyOderConstraint.class.getName());
@ -38,8 +38,8 @@ public class UnifyOderConstraint extends OderMenge<MPair>{
* Liefert alle in diesem OderConstraint enthaltene Constraints. Dabei gehen die Verkn<EFBFBD>pfungen (Oder/Und) verloren.
* @return
*/
public Menge<MPair> getConstraintPairs(){
Menge<MPair> ret = new Menge<MPair>();
public Menge<UnifyPair> getConstraintPairs(){
Menge<UnifyPair> ret = new Menge<UnifyPair>();
for(UnifyUndConstraint oC : this.oderConstraintPairs){
ret.addAll(oC.getConstraintPairs());
}
@ -50,7 +50,7 @@ public class UnifyOderConstraint extends OderMenge<MPair>{
* Falls die Type des toAdd-Pairs nicht vom Typ RefType bzw. TypePlaceholder sind, so werden sie in einen RefType umgewandelt.
* @param toAdd
*/
public void addConstraint(MPair toAdd){
public void addConstraint(UnifyPair toAdd){
oderConstraintPairs.add(new UnifySingleConstraint(toAdd));
}
@ -86,7 +86,7 @@ public class UnifyOderConstraint extends OderMenge<MPair>{
void filterWrongConstraints(Unifier unifier) {
Set<UnifyUndConstraint> filteredConstraints = new Menge<>();
for(UnifyUndConstraint cons : this.getUndConstraints()){
Set<Set<MPair>> unifierResult = unifier.apply(cons.getConstraintPairs());
Set<Set<UnifyPair>> unifierResult = unifier.apply(cons.getConstraintPairs());
if(!unifierResult.isEmpty()){
filteredConstraints.add(cons);
}else{
@ -104,7 +104,7 @@ public class UnifyOderConstraint extends OderMenge<MPair>{
}
@Override
public Set<? extends KomplexeMenge<MPair>> getSet() {
public Set<? extends KomplexeMenge<UnifyPair>> getSet() {
return this.oderConstraintPairs;
}

View File

@ -8,36 +8,36 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class UnifySingleConstraint extends UnifyUndConstraint{
private MPair constraintPair; //entspricht θ condition θ'
private UnifyPair constraintPair; //entspricht θ condition θ'
@Override
public Menge<? extends KomplexeMenge<MPair>> getSet() {
Menge<EinzelElement<MPair>> ret = new Menge<>();
public Menge<? extends KomplexeMenge<UnifyPair>> getSet() {
Menge<EinzelElement<UnifyPair>> ret = new Menge<>();
ret.add(new EinzelElement<>(constraintPair));
return ret;
}
public UnifySingleConstraint(MPair toAdd) {
public UnifySingleConstraint(UnifyPair toAdd) {
this.addConstraint(toAdd);
}
public MPair getPair(){
public UnifyPair getPair(){
return constraintPair;
}
@Override //Methode überschreiben, damit immer nur ein Vector mit nur einem Element zurückgeliefert wird.
public Menge<MPair> getConstraintPairs(){
Menge<MPair> ret = new Menge<>();
public Menge<UnifyPair> getConstraintPairs(){
Menge<UnifyPair> ret = new Menge<>();
ret.add(constraintPair);
return ret;
}
public void addConstraint(MPair toAdd){
public void addConstraint(UnifyPair toAdd){
if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
constraintPair = toAdd;

View File

@ -7,24 +7,24 @@ import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
/**
* Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft.
* @author janulrich
*
*/
public class UnifyUndConstraint extends UndMenge<MPair> {
public class UnifyUndConstraint extends UndMenge<UnifyPair> {
Menge<EinzelElement<MPair>> set = new Menge<>();
Menge<EinzelElement<UnifyPair>> set = new Menge<>();
@Override
public Menge<? extends KomplexeMenge<MPair>> getSet() {
public Menge<? extends KomplexeMenge<UnifyPair>> getSet() {
return set;
}
public Set<MPair> getConstraintPairs() {
Set<Set<MPair>> ret = this.cartesianProduct();
public Set<UnifyPair> getConstraintPairs() {
Set<Set<UnifyPair>> ret = this.cartesianProduct();
if(ret.size() != 1){
//UndConstraints enthalten nur SingleConstraints, wodurch das Karthesische Produkt nur aus einem Element bestehen kann.
throw new DebugException("Fehler in ConstraintPairs-Bildung");
@ -38,7 +38,7 @@ public class UnifyUndConstraint extends UndMenge<MPair> {
return ret;
}
public void add(MPair pair){
public void add(UnifyPair pair){
set.add(new EinzelElement<>(pair));
}

View File

@ -24,15 +24,15 @@ public class Mapping {
return forwardMap.get(type);
}
public de.dhbwstuttgart.typeinference.unify.model.MPair map(de.dhbwstuttgart.typeinference.Pair pair) {
return new de.dhbwstuttgart.typeinference.unify.model.MPair(forwardMap.get(pair.TA1), forwardMap.get(pair.TA2), mapOp(pair.GetOperator()));
public de.dhbwstuttgart.typeinference.unify.model.UnifyPair map(de.dhbwstuttgart.typeinference.Pair pair) {
return new de.dhbwstuttgart.typeinference.unify.model.UnifyPair(forwardMap.get(pair.TA1), forwardMap.get(pair.TA2), mapOp(pair.GetOperator()));
}
public Set<de.dhbwstuttgart.typeinference.unify.model.UnifyType> mapTypeSet(Set<de.dhbwstuttgart.syntaxtree.type.Type> types) {
return types.stream().map(this::map).collect(Collectors.toCollection(HashSet::new));
}
public Set<de.dhbwstuttgart.typeinference.unify.model.MPair> mapPairSet(Set<de.dhbwstuttgart.typeinference.Pair> pairs) {
public Set<de.dhbwstuttgart.typeinference.unify.model.UnifyPair> mapPairSet(Set<de.dhbwstuttgart.typeinference.Pair> pairs) {
return pairs.stream().map(this::map).collect(Collectors.toCollection(HashSet::new));
}
@ -40,7 +40,7 @@ public class Mapping {
return irreversible.contains(type) ? Optional.of(backwardMap.get(type)) : Optional.empty();
}
public Optional<Pair> unmap(de.dhbwstuttgart.typeinference.unify.model.MPair mpair) {
public Optional<Pair> unmap(de.dhbwstuttgart.typeinference.unify.model.UnifyPair mpair) {
de.dhbwstuttgart.typeinference.unify.model.UnifyType lhs = mpair.getLhsType();
de.dhbwstuttgart.typeinference.unify.model.UnifyType rhs = mpair.getRhsType();
@ -54,7 +54,7 @@ public class Mapping {
return result.size() == types.size() ? Optional.of(result) : Optional.empty();
}
public Optional<Set<de.dhbwstuttgart.typeinference.Pair>> unmapPairSet(Set<de.dhbwstuttgart.typeinference.unify.model.MPair> pairs) {
public Optional<Set<de.dhbwstuttgart.typeinference.Pair>> unmapPairSet(Set<de.dhbwstuttgart.typeinference.unify.model.UnifyPair> pairs) {
Set<de.dhbwstuttgart.typeinference.Pair> result = pairs.stream().map(this::unmap).filter(x -> x.isPresent()).map(x -> x.get()).collect(Collectors.toCollection(HashSet::new));
return result.size() == pairs.size() ? Optional.of(result) : Optional.empty();
}

View File

@ -10,7 +10,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
@ -28,12 +28,12 @@ public class MartelliMontanariUnify implements IUnify {
if(terms.size() < 2)
return Optional.of(Unifier.Identity());
ArrayList<MPair> termsQ = new ArrayList<MPair>();
ArrayList<UnifyPair> termsQ = new ArrayList<UnifyPair>();
Iterator<UnifyType> iter = terms.iterator();
UnifyType prev = iter.next();
while(iter.hasNext()) {
UnifyType next = iter.next();
termsQ.add(new MPair(prev, next, PairOperator.EQUALSDOT));
termsQ.add(new UnifyPair(prev, next, PairOperator.EQUALSDOT));
prev = next;
}
@ -41,14 +41,14 @@ public class MartelliMontanariUnify implements IUnify {
int idx = 0;
while(idx < termsQ.size()) {
MPair pair = termsQ.get(idx);
UnifyPair pair = termsQ.get(idx);
if(delete(pair)) {
termsQ.remove(idx);
continue;
}
Optional<Set<MPair>> optSet = decompose(pair);
Optional<Set<UnifyPair>> optSet = decompose(pair);
if(optSet == null)
return Optional.empty(); // Unification failed
@ -59,7 +59,7 @@ public class MartelliMontanariUnify implements IUnify {
continue;
}
Optional<MPair> optPair = swap(pair);
Optional<UnifyPair> optPair = swap(pair);
if(optPair.isPresent()) {
termsQ.add(optPair.get());
@ -88,12 +88,12 @@ public class MartelliMontanariUnify implements IUnify {
return Optional.of(mgu);
}
private boolean delete(MPair pair) {
private boolean delete(UnifyPair pair) {
return pair.getRhsType().equals(pair.getLhsType());
}
private Optional<Set<MPair>> decompose(MPair pair) {
Set<MPair> result = new HashSet<>();
private Optional<Set<UnifyPair>> decompose(UnifyPair pair) {
Set<UnifyPair> result = new HashSet<>();
UnifyType rhs = pair.getRhsType();
UnifyType lhs = pair.getLhsType();
@ -112,22 +112,22 @@ public class MartelliMontanariUnify implements IUnify {
return Optional.empty();
for(int i = 0; i < rhsTypeParams.size(); i++)
result.add(new MPair(rhsTypeParams.get(i), lhsTypeParams.get(i), PairOperator.EQUALSDOT));
result.add(new UnifyPair(rhsTypeParams.get(i), lhsTypeParams.get(i), PairOperator.EQUALSDOT));
return Optional.of(result);
}
private Optional<MPair> swap(MPair pair) {
private Optional<UnifyPair> swap(UnifyPair pair) {
UnifyType rhs = pair.getRhsType();
UnifyType lhs = pair.getLhsType();
if(!(lhs instanceof PlaceholderType) && (rhs instanceof PlaceholderType))
return Optional.of(new MPair(rhs, lhs, PairOperator.EQUALSDOT));
return Optional.of(new UnifyPair(rhs, lhs, PairOperator.EQUALSDOT));
return Optional.empty();
}
private Optional<Entry<PlaceholderType, UnifyType>> eliminate(MPair pair) {
private Optional<Entry<PlaceholderType, UnifyType>> eliminate(UnifyPair pair) {
UnifyType rhs = pair.getRhsType();
UnifyType lhs = pair.getLhsType();

View File

@ -15,7 +15,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
@ -34,7 +34,7 @@ public class RuleSet implements IRuleSet{
}
@Override
public Optional<MPair> reduceUp(MPair pair) {
public Optional<UnifyPair> reduceUp(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -46,11 +46,11 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType))
return Optional.empty();
return Optional.of(new MPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT));
return Optional.of(new UnifyPair(lhsType, ((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT));
}
@Override
public Optional<MPair> reduceLow(MPair pair) {
public Optional<UnifyPair> reduceLow(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -62,11 +62,11 @@ public class RuleSet implements IRuleSet{
if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
return Optional.empty();
return Optional.of(new MPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT));
return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), rhsType, PairOperator.SMALLERDOT));
}
@Override
public Optional<MPair> reduceUpLow(MPair pair) {
public Optional<UnifyPair> reduceUpLow(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -78,11 +78,11 @@ public class RuleSet implements IRuleSet{
if(!(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new MPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT));
return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(),((SuperType) rhsType).getSuperedType(), PairOperator.SMALLERDOT));
}
@Override
public Optional<Set<MPair>> reduceExt(MPair pair) {
public Optional<Set<UnifyPair>> reduceExt(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -125,16 +125,16 @@ public class RuleSet implements IRuleSet{
if(pi.length == 0)
return Optional.empty();
Set<MPair> result = new HashSet<>();
Set<UnifyPair> result = new HashSet<>();
for(int rhsIdx = 0; rhsIdx < extYParams.size(); rhsIdx++)
result.add(new MPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC));
result.add(new UnifyPair(xParams.get(pi[rhsIdx]), extYParams.get(rhsIdx), PairOperator.SMALLERDOTWC));
return Optional.of(result);
}
@Override
public Optional<Set<MPair>> reduceSup(MPair pair) {
public Optional<Set<UnifyPair>> reduceSup(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -171,7 +171,7 @@ public class RuleSet implements IRuleSet{
TypeParams supYParams = supY.getTypeParams();
TypeParams xParams = x.getTypeParams();
Set<MPair> result = new HashSet<>();
Set<UnifyPair> result = new HashSet<>();
int[] pi = pi(xParams, supYParams);
@ -179,13 +179,13 @@ public class RuleSet implements IRuleSet{
return Optional.empty();
for(int rhsIdx = 0; rhsIdx < supYParams.size(); rhsIdx++)
result.add(new MPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC));
result.add(new UnifyPair(supYParams.get(rhsIdx), xParams.get(pi[rhsIdx]), PairOperator.SMALLERDOTWC));
return Optional.of(result);
}
@Override
public Optional<Set<MPair>> reduceEq(MPair pair) {
public Optional<Set<UnifyPair>> reduceEq(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -205,18 +205,18 @@ public class RuleSet implements IRuleSet{
return Optional.empty();
// Keine Permutation wie im Paper nötig
Set<MPair> result = new HashSet<>();
Set<UnifyPair> result = new HashSet<>();
TypeParams lhsTypeParams = lhsType.getTypeParams();
TypeParams rhsTypeParams = rhsType.getTypeParams();
for(int i = 0; i < lhsTypeParams.size(); i++)
result.add(new MPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT));
result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT));
return Optional.of(result);
}
@Override
public Optional<Set<MPair>> reduce1(MPair pair) {
public Optional<Set<UnifyPair>> reduce1(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -251,16 +251,16 @@ public class RuleSet implements IRuleSet{
TypeParams rhsTypeParams = d.getTypeParams();
TypeParams lhsTypeParams = c.getTypeParams();
Set<MPair> result = new HashSet<>();
Set<UnifyPair> result = new HashSet<>();
for(int rhsIdx = 0; rhsIdx < rhsTypeParams.size(); rhsIdx++)
result.add(new MPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC));
result.add(new UnifyPair(lhsTypeParams.get(pi[rhsIdx]), rhsTypeParams.get(rhsIdx), PairOperator.SMALLERDOTWC));
return Optional.of(result);
}
@Override
public Optional<Set<MPair>> reduce2(MPair pair) {
public Optional<Set<UnifyPair>> reduce2(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return Optional.empty();
@ -304,18 +304,18 @@ public class RuleSet implements IRuleSet{
//if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
// return Optional.empty();
Set<MPair> result = new HashSet<>();
Set<UnifyPair> result = new HashSet<>();
TypeParams rhsTypeParams = rhsSType.getTypeParams();
TypeParams lhsTypeParams = lhsSType.getTypeParams();
for(int i = 0; i < rhsTypeParams.size(); i++)
result.add(new MPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT));
result.add(new UnifyPair(lhsTypeParams.get(i), rhsTypeParams.get(i), PairOperator.EQUALSDOT));
return Optional.of(result);
}
@Override
public boolean erase1(MPair pair) {
public boolean erase1(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return false;
@ -331,7 +331,7 @@ public class RuleSet implements IRuleSet{
}
@Override
public boolean erase2(MPair pair) {
public boolean erase2(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return false;
@ -342,7 +342,7 @@ public class RuleSet implements IRuleSet{
}
@Override
public boolean erase3(MPair pair) {
public boolean erase3(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return false;
@ -350,7 +350,7 @@ public class RuleSet implements IRuleSet{
}
@Override
public Optional<MPair> swap(MPair pair) {
public Optional<UnifyPair> swap(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return Optional.empty();
@ -360,11 +360,11 @@ public class RuleSet implements IRuleSet{
if(!(pair.getRhsType() instanceof PlaceholderType))
return Optional.empty();
return Optional.of(new MPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT));
return Optional.of(new UnifyPair(pair.getRhsType(), pair.getLhsType(), PairOperator.EQUALSDOT));
}
@Override
public Optional<MPair> adapt(MPair pair) {
public Optional<UnifyPair> adapt(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -406,11 +406,11 @@ public class RuleSet implements IRuleSet{
for(int i = 1; i < typeDParams.size(); i++)
unif.Add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
return Optional.of(new MPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT));
return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT));
}
@Override
public Optional<MPair> adaptExt(MPair pair) {
public Optional<UnifyPair> adaptExt(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -452,11 +452,11 @@ public class RuleSet implements IRuleSet{
for(int i = 1; i < typeDParams.size(); i++)
unif.Add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i));
return Optional.of(new MPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC));
return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC));
}
@Override
public Optional<MPair> adaptSup(MPair pair) {
public Optional<UnifyPair> adaptSup(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -504,7 +504,7 @@ public class RuleSet implements IRuleSet{
for(int i = 1; i < typeDParams.size(); i++)
unif.Add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i));
return Optional.of(new MPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC));
return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC));
}
/**
@ -534,12 +534,12 @@ public class RuleSet implements IRuleSet{
}
@Override
public Optional<Set<MPair>> subst(Set<MPair> pairs) {
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pairs) {
HashMap<UnifyType, Integer> typeMap = new HashMap<>();
Stack<UnifyType> occuringTypes = new Stack<>();
for(MPair pair : pairs) {
for(UnifyPair pair : pairs) {
occuringTypes.push(pair.getLhsType());
occuringTypes.push(pair.getRhsType());
}
@ -558,12 +558,12 @@ public class RuleSet implements IRuleSet{
t1.getTypeParams().forEach(x -> occuringTypes.push(x));
}
Queue<MPair> result1 = new LinkedList<MPair>(pairs);
ArrayList<MPair> result = new ArrayList<MPair>();
Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs);
ArrayList<UnifyPair> result = new ArrayList<UnifyPair>();
boolean applied = false;
while(!result1.isEmpty()) {
MPair pair = result1.poll();
UnifyPair pair = result1.poll();
PlaceholderType lhsType = null;
UnifyType rhsType;
@ -587,7 +587,7 @@ public class RuleSet implements IRuleSet{
}
@Override
public Optional<MPair> reduceWildcardLow(MPair pair) {
public Optional<UnifyPair> reduceWildcardLow(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -596,11 +596,11 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
return Optional.of(new MPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT));
return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT));
}
@Override
public Optional<MPair> reduceWildcardLowRight(MPair pair) {
public Optional<UnifyPair> reduceWildcardLowRight(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -609,11 +609,11 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
return Optional.of(new MPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT));
return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT));
}
@Override
public Optional<MPair> reduceWildcardUp(MPair pair) {
public Optional<UnifyPair> reduceWildcardUp(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -622,11 +622,11 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof SuperType) || !(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new MPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT));
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), ((SuperType) lhsType).getSuperedType(), PairOperator.SMALLERDOT));
}
@Override
public Optional<MPair> reduceWildcardUpRight(MPair pair) {
public Optional<UnifyPair> reduceWildcardUpRight(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -635,11 +635,11 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new MPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC));
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC));
}
@Override
public Optional<MPair> reduceWildcardLowUp(MPair pair) {
public Optional<UnifyPair> reduceWildcardLowUp(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -648,11 +648,11 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof ExtendsType) || !(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new MPair(((ExtendsType) lhsType).getExtendedType(), ((SuperType) rhsType).getSuperedType(), PairOperator.EQUALSDOT));
return Optional.of(new UnifyPair(((ExtendsType) lhsType).getExtendedType(), ((SuperType) rhsType).getSuperedType(), PairOperator.EQUALSDOT));
}
@Override
public Optional<MPair> reduceWildcardUpLow(MPair pair) {
public Optional<UnifyPair> reduceWildcardUpLow(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -661,11 +661,11 @@ public class RuleSet implements IRuleSet{
if(!(lhsType instanceof SuperType) || !(rhsType instanceof ExtendsType))
return Optional.empty();
return Optional.of(new MPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT));
return Optional.of(new UnifyPair(((SuperType) lhsType).getSuperedType(), ((ExtendsType) rhsType).getExtendedType(), PairOperator.EQUALSDOT));
}
@Override
public Optional<MPair> reduceWildcardLeft(MPair pair) {
public Optional<UnifyPair> reduceWildcardLeft(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
return Optional.empty();
@ -676,13 +676,13 @@ public class RuleSet implements IRuleSet{
UnifyType lhsType = pair.getLhsType();
if(lhsType instanceof WildcardType)
return Optional.of(new MPair(((WildcardType) lhsType).getWildcardedType(), rhsType, PairOperator.EQUALSDOT));
return Optional.of(new UnifyPair(((WildcardType) lhsType).getWildcardedType(), rhsType, PairOperator.EQUALSDOT));
return Optional.empty();
}
@Override
public Optional<Set<MPair>> reduceFunN(MPair pair) {
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -698,17 +698,17 @@ public class RuleSet implements IRuleSet{
if(funNLhsType.getN() != funNRhsType.getN())
return Optional.empty();
Set<MPair> result = new HashSet<MPair>();
Set<UnifyPair> result = new HashSet<UnifyPair>();
result.add(new MPair(funNLhsType.getTypeParams().get(0), funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT));
result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT));
for(int i = 1; i < funNLhsType.getTypeParams().size(); i++)
result.add(new MPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT));
result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT));
return Optional.of(result);
}
@Override
public Optional<Set<MPair>> greaterFunN(MPair pair) {
public Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -720,22 +720,22 @@ public class RuleSet implements IRuleSet{
FunNType funNLhsType = (FunNType) lhsType;
Set<MPair> result = new HashSet<MPair>();
Set<UnifyPair> result = new HashSet<UnifyPair>();
UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()];
for(int i = 0; i < freshPlaceholders.length; i++)
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
result.add(new MPair(funNLhsType.getTypeParams().get(0), freshPlaceholders[0], PairOperator.SMALLERDOT));
result.add(new UnifyPair(funNLhsType.getTypeParams().get(0), freshPlaceholders[0], PairOperator.SMALLERDOT));
for(int i = 1; i < funNLhsType.getTypeParams().size(); i++)
result.add(new MPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT));
result.add(new MPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT));
result.add(new UnifyPair(freshPlaceholders[i], funNLhsType.getTypeParams().get(i), PairOperator.SMALLERDOT));
result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT));
return Optional.of(result);
}
@Override
public Optional<Set<MPair>> smallerFunN(MPair pair) {
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
@ -747,16 +747,16 @@ public class RuleSet implements IRuleSet{
FunNType funNRhsType = (FunNType) rhsType;
Set<MPair> result = new HashSet<MPair>();
Set<UnifyPair> result = new HashSet<UnifyPair>();
UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()];
for(int i = 0; i < freshPlaceholders.length; i++)
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
result.add(new MPair(freshPlaceholders[0], funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT));
result.add(new UnifyPair(freshPlaceholders[0], funNRhsType.getTypeParams().get(0), PairOperator.SMALLERDOT));
for(int i = 1; i < funNRhsType.getTypeParams().size(); i++)
result.add(new MPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT));
result.add(new MPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT));
result.add(new UnifyPair(funNRhsType.getTypeParams().get(i), freshPlaceholders[i], PairOperator.SMALLERDOT));
result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT));
return Optional.of(result);
}

View File

@ -2,10 +2,10 @@ package de.dhbwstuttgart.typeinference.unify;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public interface Unifier {
public Set<Set<MPair>> apply (Set<MPair> E);
public Set<Set<UnifyPair>> apply (Set<UnifyPair> E);
}

View File

@ -17,7 +17,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
@ -32,19 +32,19 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
*/
public class Unify {
public Set<Set<MPair>> unify(Set<MPair> eq, IFiniteClosure fc) {
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc) {
/*
* Step 1: Repeated application of reduce, adapt, erase, swap
*/
Set<MPair> eq0 = applyTypeUnificationRules(eq, fc);
Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc);
/*
* Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs
*/
Set<MPair> eq1s = new HashSet<>();
Set<MPair> eq2s = new HashSet<>();
Set<UnifyPair> eq1s = new HashSet<>();
Set<UnifyPair> eq2s = new HashSet<>();
splitEq(eq0, eq1s, eq2s);
/*
@ -56,21 +56,21 @@ public class Unify {
// There are up to 10 toplevel set. 8 of 10 are the result of the
// cartesian product of the sets created by pattern matching.
List<Set<Set<MPair>>> topLevelSets = new ArrayList<>();
List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>();
if(eq1s.size() != 0) {
Set<Set<MPair>> wrap = new HashSet<>();
Set<Set<UnifyPair>> wrap = new HashSet<>();
wrap.add(eq1s);
topLevelSets.add(wrap); // Add Eq1'
}
// Add the set of [a =. Theta | (a=. Theta) in Eq2']
Set<MPair> bufferSet = eq2s.stream()
Set<UnifyPair> bufferSet = eq2s.stream()
.filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType)
.collect(Collectors.toSet());
if(bufferSet.size() != 0) {
Set<Set<MPair>> wrap = new HashSet<>();
Set<Set<UnifyPair>> wrap = new HashSet<>();
wrap.add(bufferSet);
topLevelSets.add(wrap);
eq2s.removeAll(bufferSet);
@ -78,8 +78,8 @@ public class Unify {
// Sets that originate from pair pattern matching
// Sets of the "second level"
Set<MPair> undefinedPairs = new HashSet<>();
Set<Set<Set<Set<MPair>>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs);
Set<UnifyPair> undefinedPairs = new HashSet<>();
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs);
// If pairs occured that did not match one of the cartesian product cases,
// those pairs are contradictory and the unification is impossible.
@ -92,17 +92,17 @@ public class Unify {
ISetOperations setOps = new GuavaSetOperations();
// Sub cartesian products of the second level (pattern matched) sets
for(Set<Set<Set<MPair>>> secondLevelSet : secondLevelSets) {
List<Set<Set<MPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet);
Set<List<Set<MPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList);
for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
List<Set<Set<UnifyPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet);
Set<List<Set<UnifyPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList);
Set<Set<MPair>> flat = new HashSet<>();
Set<Set<UnifyPair>> flat = new HashSet<>();
cartResult.stream().forEach(x -> flat.addAll(x));
topLevelSets.add(flat);
}
// Cartesian product over all (up to 10) top level sets
Set<Set<Set<MPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
.stream().map(x -> new HashSet<>(x))
.collect(Collectors.toCollection(HashSet::new));
//System.out.println(result);
@ -111,19 +111,19 @@ public class Unify {
* Step 5: Substitution
*/
Set<Set<MPair>> eqPrimeSetFlat = new HashSet<>();
for(Set<Set<MPair>> setToFlatten : eqPrimeSet) {
Set<MPair> buffer = new HashSet<>();
Set<Set<UnifyPair>> eqPrimeSetFlat = new HashSet<>();
for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
Set<UnifyPair> buffer = new HashSet<>();
setToFlatten.stream().forEach(x -> buffer.addAll(x));
eqPrimeSetFlat.add(buffer);
}
IRuleSet rules = new RuleSet(fc);
Set<Set<MPair>> changed = new HashSet<>();
Set<Set<MPair>> eqPrimePrimeSet = new HashSet<>();
Set<Set<UnifyPair>> changed = new HashSet<>();
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
for(Set<MPair> eqPrime : eqPrimeSetFlat) {
Optional<Set<MPair>> eqPrimePrime = rules.subst(eqPrime);
for(Set<UnifyPair> eqPrime : eqPrimeSetFlat) {
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
if(eqPrime.equals(eq))
eqPrimePrimeSet.add(eqPrime);
@ -142,7 +142,7 @@ public class Unify {
* b) Build the union over everything
*/
for(Set<MPair> eqss : changed)
for(Set<UnifyPair> eqss : changed)
eqPrimePrimeSet.addAll(this.unify(eqss, fc));
/*
@ -152,8 +152,8 @@ public class Unify {
}
protected boolean isSolvedForm(Set<MPair> eqPrimePrime) {
for(MPair pair : eqPrimePrime) {
protected boolean isSolvedForm(Set<UnifyPair> eqPrimePrime) {
for(UnifyPair pair : eqPrimePrime) {
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
@ -167,7 +167,7 @@ public class Unify {
return true;
}
protected Set<MPair> applyTypeUnificationRules(Set<MPair> eq, IFiniteClosure fc) {
protected Set<UnifyPair> applyTypeUnificationRules(Set<UnifyPair> eq, IFiniteClosure fc) {
/*
* Rule Application Strategy:
@ -182,8 +182,8 @@ public class Unify {
*/
LinkedHashSet<MPair> targetSet = new LinkedHashSet<MPair>();
LinkedList<MPair> eqQueue = new LinkedList<>();
LinkedHashSet<UnifyPair> targetSet = new LinkedHashSet<UnifyPair>();
LinkedList<UnifyPair> eqQueue = new LinkedList<>();
IRuleSet rules = new RuleSet(fc);
/*
@ -195,10 +195,10 @@ public class Unify {
* Apply rules until the queue is empty
*/
while(!eqQueue.isEmpty()) {
MPair pair = eqQueue.pollFirst();
UnifyPair pair = eqQueue.pollFirst();
// ReduceUp, ReduceLow, ReduceUpLow
Optional<MPair> opt = rules.reduceUpLow(pair);
Optional<UnifyPair> opt = rules.reduceUpLow(pair);
opt = opt.isPresent() ? opt : rules.reduceLow(pair);
opt = opt.isPresent() ? opt : rules.reduceUp(pair);
opt = opt.isPresent() ? opt : rules.reduceWildcardLow(pair);
@ -216,7 +216,7 @@ public class Unify {
}
// Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq
Optional<Set<MPair>> optSet = rules.reduce1(pair);
Optional<Set<UnifyPair>> optSet = rules.reduce1(pair);
optSet = optSet.isPresent() ? optSet : rules.reduce2(pair);
optSet = optSet.isPresent() ? optSet : rules.reduceExt(pair);
optSet = optSet.isPresent() ? optSet : rules.reduceSup(pair);
@ -246,9 +246,9 @@ public class Unify {
return targetSet;
}
protected void swapAddOrErase(MPair pair, IRuleSet rules, Collection<MPair> collection) {
Optional<MPair> opt = rules.swap(pair);
MPair pair2 = opt.isPresent() ? opt.get() : pair;
protected void swapAddOrErase(UnifyPair pair, IRuleSet rules, Collection<UnifyPair> collection) {
Optional<UnifyPair> opt = rules.swap(pair);
UnifyPair pair2 = opt.isPresent() ? opt.get() : pair;
if(rules.erase1(pair2) || rules.erase3(pair2) || rules.erase2(pair2))
return;
@ -256,8 +256,8 @@ public class Unify {
collection.add(pair2);
}
protected void splitEq(Set<MPair> eq, Set<MPair> eq1s, Set<MPair> eq2s) {
for(MPair pair : eq)
protected void splitEq(Set<UnifyPair> eq, Set<UnifyPair> eq1s, Set<UnifyPair> eq2s) {
for(UnifyPair pair : eq)
if(pair.getLhsType() instanceof PlaceholderType && pair.getRhsType() instanceof PlaceholderType)
eq1s.add(pair);
else
@ -265,14 +265,14 @@ public class Unify {
}
protected Set<Set<Set<Set<MPair>>>> calculatePairSets(Set<MPair> eq2s, IFiniteClosure fc, Set<MPair> undefined) {
List<Set<Set<Set<MPair>>>> result = new ArrayList<>();
protected Set<Set<Set<Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, IFiniteClosure fc, Set<UnifyPair> undefined) {
List<Set<Set<Set<UnifyPair>>>> result = new ArrayList<>();
// Init all 8 cases
for(int i = 0; i < 8; i++)
result.add(new HashSet<>());
for(MPair pair : eq2s) {
for(UnifyPair pair : eq2s) {
PairOperator pairOp = pair.getPairOp();
UnifyType lhsType = pair.getLhsType();
@ -321,8 +321,8 @@ public class Unify {
.filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new));
}
protected Set<Set<MPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
IUnify unify = new MartelliMontanariUnify();
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());
@ -352,15 +352,15 @@ public class Unify {
continue;
Unifier unifier = opt.get();
Set<MPair> substitutionSet = new HashSet<>();
Set<UnifyPair> substitutionSet = new HashSet<>();
for (Entry<PlaceholderType, UnifyType> sigma : unifier.getSubstitutions())
substitutionSet.add(new MPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
for (UnifyType tq : thetaQs) {
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
for(UnifyType theta : smaller) {
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, theta, PairOperator.EQUALSDOT));
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
resultPrime.addAll(substitutionSet);
result.add(resultPrime);
}
@ -372,8 +372,8 @@ public class Unify {
return result;
}
protected Set<Set<MPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
protected Set<Set<UnifyPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
IUnify unify = new MartelliMontanariUnify();
UnifyType thetaPrime = extThetaPrime.getExtendedType();
@ -405,16 +405,16 @@ public class Unify {
Unifier unifier = opt.get();
Set<MPair> substitutionSet = new HashSet<>();
Set<UnifyPair> substitutionSet = new HashSet<>();
for (Entry<PlaceholderType, UnifyType> sigma : unifier.getSubstitutions())
substitutionSet.add(new MPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
for (UnifyType tq : thetaQs) {
ExtendsType extTq = new ExtendsType(tq);
Set<UnifyType> smArg = fc.smArg(unifier.apply(extTq));
for(UnifyType theta : smArg) {
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, theta, PairOperator.EQUALSDOT));
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
resultPrime.addAll(substitutionSet);
result.add(resultPrime);
}
@ -426,60 +426,60 @@ public class Unify {
return result;
}
protected Set<Set<MPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
protected Set<Set<UnifyPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
UnifyType aPrime = PlaceholderType.freshPlaceholder();
UnifyType supAPrime = new SuperType(aPrime);
UnifyType thetaPrime = subThetaPrime.getSuperedType();
//for(UnifyType theta : fc.smArg(subThetaPrime)) {
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, aPrime, PairOperator.EQUALSDOT));
resultPrime.add(new MPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, aPrime, PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
result.add(resultPrime);
resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, supAPrime, PairOperator.EQUALSDOT));
resultPrime.add(new MPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT));
resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
result.add(resultPrime);
//}
return result;
}
protected Set<Set<MPair>> unifyCase4(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, thetaPrime, PairOperator.EQUALSDOT));
protected Set<Set<UnifyPair>> unifyCase4(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.EQUALSDOT));
result.add(resultPrime);
return result;
}
protected Set<Set<MPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
protected Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
for(UnifyType thetaS : fc.greater(theta)) {
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, thetaS, PairOperator.EQUALSDOT));
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
result.add(resultPrime);
}
return result;
}
protected Set<Set<MPair>> unifyCase6(ExtendsType extTheta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
protected Set<Set<UnifyPair>> unifyCase6(ExtendsType extTheta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
for(UnifyType thetaS : fc.grArg(extTheta)) {
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, thetaS, PairOperator.EQUALSDOT));
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
result.add(resultPrime);
}
return result;
}
protected Set<Set<MPair>> unifyCase7(SuperType supTheta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
protected Set<Set<UnifyPair>> unifyCase7(SuperType supTheta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
IUnify unify = new MartelliMontanariUnify();
UnifyType theta = supTheta.getSuperedType();
@ -511,16 +511,16 @@ public class Unify {
Unifier unifier = opt.get();
Set<MPair> substitutionSet = new HashSet<>();
Set<UnifyPair> substitutionSet = new HashSet<>();
for (Entry<PlaceholderType, UnifyType> sigma : unifier.getSubstitutions())
substitutionSet.add(new MPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
for (UnifyType tq : thetaQs) {
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
for(UnifyType thetaPrime : smaller) {
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, new SuperType(thetaPrime), PairOperator.EQUALSDOT));
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, new SuperType(thetaPrime), PairOperator.EQUALSDOT));
resultPrime.addAll(substitutionSet);
result.add(resultPrime);
}
@ -532,11 +532,11 @@ public class Unify {
return result;
}
protected Set<Set<MPair>> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<MPair>> result = new HashSet<>();
protected Set<Set<UnifyPair>> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) {
Set<Set<UnifyPair>> result = new HashSet<>();
for(UnifyType thetaS : fc.grArg(theta)) {
Set<MPair> resultPrime = new HashSet<>();
resultPrime.add(new MPair(a, thetaS, PairOperator.EQUALSDOT));
Set<UnifyPair> resultPrime = new HashSet<>();
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
result.add(resultPrime);
}

View File

@ -3,46 +3,46 @@ package de.dhbwstuttgart.typeinference.unify.interfaces;
import java.util.Optional;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public interface IRuleSet {
public Optional<MPair> reduceUp(MPair pair);
public Optional<MPair> reduceLow(MPair pair);
public Optional<MPair> reduceUpLow(MPair pair);
public Optional<Set<MPair>> reduceExt(MPair pair);
public Optional<Set<MPair>> reduceSup(MPair pair);
public Optional<Set<MPair>> reduceEq(MPair pair);
public Optional<Set<MPair>> reduce1(MPair pair);
public Optional<Set<MPair>> reduce2(MPair pair);
public Optional<UnifyPair> reduceUp(UnifyPair pair);
public Optional<UnifyPair> reduceLow(UnifyPair pair);
public Optional<UnifyPair> reduceUpLow(UnifyPair pair);
public Optional<Set<UnifyPair>> reduceExt(UnifyPair pair);
public Optional<Set<UnifyPair>> reduceSup(UnifyPair pair);
public Optional<Set<UnifyPair>> reduceEq(UnifyPair pair);
public Optional<Set<UnifyPair>> reduce1(UnifyPair pair);
public Optional<Set<UnifyPair>> reduce2(UnifyPair pair);
/*
* Missing Rules
*/
public Optional<MPair> reduceWildcardLow(MPair pair);
public Optional<MPair> reduceWildcardLowRight(MPair pair);
public Optional<MPair> reduceWildcardUp(MPair pair);
public Optional<MPair> reduceWildcardUpRight(MPair pair);
public Optional<MPair> reduceWildcardLowUp(MPair pair);
public Optional<MPair> reduceWildcardUpLow(MPair pair);
public Optional<MPair> reduceWildcardLeft(MPair pair);
public Optional<UnifyPair> reduceWildcardLow(UnifyPair pair);
public Optional<UnifyPair> reduceWildcardLowRight(UnifyPair pair);
public Optional<UnifyPair> reduceWildcardUp(UnifyPair pair);
public Optional<UnifyPair> reduceWildcardUpRight(UnifyPair pair);
public Optional<UnifyPair> reduceWildcardLowUp(UnifyPair pair);
public Optional<UnifyPair> reduceWildcardUpLow(UnifyPair pair);
public Optional<UnifyPair> reduceWildcardLeft(UnifyPair pair);
/*
* FunN Rules
*/
public Optional<Set<MPair>> reduceFunN(MPair pair);
public Optional<Set<MPair>> greaterFunN(MPair pair);
public Optional<Set<MPair>> smallerFunN(MPair pair);
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair);
public Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair);
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair);
public boolean erase1(MPair pair);
public boolean erase2(MPair pair);
public boolean erase3(MPair pair);
public boolean erase1(UnifyPair pair);
public boolean erase2(UnifyPair pair);
public boolean erase3(UnifyPair pair);
public Optional<MPair> swap(MPair pair);
public Optional<UnifyPair> swap(UnifyPair pair);
public Optional<MPair> adapt(MPair pair);
public Optional<MPair> adaptExt(MPair pair);
public Optional<MPair> adaptSup(MPair pair);
public Optional<UnifyPair> adapt(UnifyPair pair);
public Optional<UnifyPair> adaptExt(UnifyPair pair);
public Optional<UnifyPair> adaptSup(UnifyPair pair);
public Optional<Set<MPair>> subst(Set<MPair> pair);
public Optional<Set<UnifyPair>> subst(Set<UnifyPair> pair);
}

View File

@ -4,32 +4,30 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
public class FiniteClosure implements IFiniteClosure {
private HashMap<UnifyType, Node<UnifyType>> inheritanceGraph;
private HashMap<String, HashSet<Node<UnifyType>>> strInheritanceGraph;
private Set<MPair> pairs;
private Set<UnifyPair> pairs;
private Set<UnifyType> basicTypes;
//TODO im konstruktor mitgeben um typenabzuhandeln die keine extends beziehung haben. (Damit die FC diese Typen auch kennt)
//(ALternative: immer die extends zu object beziehung einfügen)
public FiniteClosure(Set<MPair> pairs) {
public FiniteClosure(Set<UnifyPair> pairs) {
this.pairs = new HashSet<>(pairs);
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
// Build the transitive closure of the inheritance tree
for(MPair pair : pairs) {
for(UnifyPair pair : pairs) {
if(pair.getPairOp() != PairOperator.SMALLER)
continue;
@ -328,7 +326,7 @@ public class FiniteClosure implements IFiniteClosure {
if(!strInheritanceGraph.containsKey(t.getName()))
return false;
for(MPair pair : pairs)
for(UnifyPair pair : pairs)
if(pair.getLhsType().equals(t))
return true;
@ -347,7 +345,7 @@ public class FiniteClosure implements IFiniteClosure {
if(!strInheritanceGraph.containsKey(t.getName()))
return Optional.empty();
for(MPair pair : pairs)
for(UnifyPair pair : pairs)
if(pair.getLhsType().getName().equals(t.getName()))
return Optional.of(pair.getLhsType());

View File

@ -37,8 +37,8 @@ public class Unifier implements Function<UnifyType, UnifyType> /*, Set<MPair>*/
return t.apply(this);
}
public MPair apply(MPair p) {
return new MPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp());
public UnifyPair apply(UnifyPair p) {
return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp());
}
public boolean hasSubstitute(PlaceholderType t) {

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.typeinference.unify.model;
public class MPair {
public class UnifyPair {
private UnifyType lhs;
private UnifyType rhs;
@ -12,7 +12,7 @@ public class MPair {
pairOp = PairOperator.SMALLER;
}*/
public MPair(UnifyType t1, UnifyType t2, PairOperator op) {
public UnifyPair(UnifyType t1, UnifyType t2, PairOperator op) {
lhs = t1;
rhs = t2;
pairOp = op;
@ -32,33 +32,16 @@ public class MPair {
@Override
public boolean equals(Object obj) {
if(!(obj instanceof MPair))
if(!(obj instanceof UnifyPair))
return false;
MPair other = (MPair) obj;
UnifyPair other = (UnifyPair) obj;
return other.getPairOp() == pairOp
&& other.getLhsType().equals(lhs)
&& other.getRhsType().equals(rhs);
}
/**
* Substitutes the occurrences of Type t on the left or right side of the pair with the Type subst.
* @param t Type to be replaced.
* @param subst The type replacing t.
* @return A pair where occurrences of t are replaced by subst.
*/
public MPair substitute(UnifyType t, UnifyType subst) {
UnifyType newlhs = lhs;
if(lhs.equals(t)) newlhs = subst;
UnifyType newrhs = rhs;
if(rhs.equals(t)) newrhs = subst;
if(newlhs == lhs && newrhs == rhs) return this;
return new MPair(newlhs, newrhs, pairOp);
}
@Override
public int hashCode() {
return 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();

View File

@ -5,16 +5,16 @@ import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
public class FiniteClosureBuilder {
private Set<MPair> pairs = new HashSet<>();
private Set<UnifyPair> pairs = new HashSet<>();
public void add(UnifyType sub, UnifyType sup) {
pairs.add(new MPair(sub, sup, PairOperator.SMALLER));
pairs.add(new UnifyPair(sub, sup, PairOperator.SMALLER));
}
public IFiniteClosure getFiniteClosure() {

View File

@ -10,7 +10,7 @@ import org.junit.Assert;
import org.junit.Test;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;

View File

@ -11,7 +11,7 @@ import org.junit.Test;
import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
@ -28,14 +28,14 @@ public class RuleSetTest {
* Positive Tests
*/
MPair reduce1 = new MPair(tf.getSimpleType("type"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair reduce2 = new MPair(tf.getPlaceholderType("T"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair reduce1 = new UnifyPair(tf.getSimpleType("type"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair reduce2 = new UnifyPair(tf.getPlaceholderType("T"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair expected1 = new MPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair expected2 = new MPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair expected1 = new UnifyPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair expected2 = new UnifyPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
Optional<MPair> opt1 = rules.reduceUp(reduce1);
Optional<MPair> opt2 = rules.reduceUp(reduce2);
Optional<UnifyPair> opt1 = rules.reduceUp(reduce1);
Optional<UnifyPair> opt2 = rules.reduceUp(reduce2);
Assert.assertTrue(opt1.isPresent());
Assert.assertTrue(opt2.isPresent());
@ -46,10 +46,10 @@ public class RuleSetTest {
* Negative Tests
*/
MPair noreduce1 = new MPair(tf.getSuperType(tf.getSimpleType("type")), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair noreduce2 = new MPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair noreduce3 = new MPair(tf.getPlaceholderType("T"), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair noreduce4 = new MPair(tf.getPlaceholderType("T"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.EQUALSDOT);
UnifyPair noreduce1 = new UnifyPair(tf.getSuperType(tf.getSimpleType("type")), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair noreduce2 = new UnifyPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair noreduce3 = new UnifyPair(tf.getPlaceholderType("T"), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair noreduce4 = new UnifyPair(tf.getPlaceholderType("T"), tf.getSuperType(tf.getSimpleType("type")), PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceUp(noreduce1).isPresent());
Assert.assertFalse(rules.reduceUp(noreduce2).isPresent());
@ -65,14 +65,14 @@ public class RuleSetTest {
/*
* Positive Tests
*/
MPair reduce1 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair reduce2 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getPlaceholderType("T"), PairOperator.SMALLERDOT);
UnifyPair reduce1 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair reduce2 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getPlaceholderType("T"), PairOperator.SMALLERDOT);
MPair expected1 = new MPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair expected2 = new MPair(tf.getSimpleType("type"), tf.getPlaceholderType("T"), PairOperator.SMALLERDOT);
UnifyPair expected1 = new UnifyPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair expected2 = new UnifyPair(tf.getSimpleType("type"), tf.getPlaceholderType("T"), PairOperator.SMALLERDOT);
Optional<MPair> opt1 = rules.reduceLow(reduce1);
Optional<MPair> opt2 = rules.reduceLow(reduce2);
Optional<UnifyPair> opt1 = rules.reduceLow(reduce1);
Optional<UnifyPair> opt2 = rules.reduceLow(reduce2);
Assert.assertTrue(opt1.isPresent());
Assert.assertTrue(opt2.isPresent());
@ -82,10 +82,10 @@ public class RuleSetTest {
/*
* Negative Tests
*/
MPair noreduce1 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair noreduce2 = new MPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair noreduce3 = new MPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair noreduce4 = new MPair(tf.getExtendsType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.EQUALSDOT);
UnifyPair noreduce1 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair noreduce2 = new UnifyPair(tf.getPlaceholderType("T"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair noreduce3 = new UnifyPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair noreduce4 = new UnifyPair(tf.getExtendsType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceLow(noreduce1).isPresent());
Assert.assertFalse(rules.reduceLow(noreduce2).isPresent());
@ -101,14 +101,14 @@ public class RuleSetTest {
/*
* Positive Tests
*/
MPair reduce1 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair reduce2 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSuperType(tf.getPlaceholderType("T")), PairOperator.SMALLERDOT);
UnifyPair reduce1 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSuperType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair reduce2 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getSuperType(tf.getPlaceholderType("T")), PairOperator.SMALLERDOT);
MPair expected1 = new MPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair expected2 = new MPair(tf.getSimpleType("type"), tf.getPlaceholderType("T"), PairOperator.SMALLERDOT);
UnifyPair expected1 = new UnifyPair(tf.getSimpleType("type"), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair expected2 = new UnifyPair(tf.getSimpleType("type"), tf.getPlaceholderType("T"), PairOperator.SMALLERDOT);
Optional<MPair> opt1 = rules.reduceUpLow(reduce1);
Optional<MPair> opt2 = rules.reduceUpLow(reduce2);
Optional<UnifyPair> opt1 = rules.reduceUpLow(reduce1);
Optional<UnifyPair> opt2 = rules.reduceUpLow(reduce2);
Assert.assertTrue(opt1.isPresent());
Assert.assertTrue(opt2.isPresent());
@ -118,10 +118,10 @@ public class RuleSetTest {
/*
* Negative Tests
*/
MPair noreduce1 = new MPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair noreduce2 = new MPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
MPair noreduce3 = new MPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
MPair noreduce4 = new MPair(tf.getExtendsType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.EQUALSDOT);
UnifyPair noreduce1 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("type")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair noreduce2 = new UnifyPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getExtendsType(tf.getSimpleType("type")), PairOperator.SMALLERDOT);
UnifyPair noreduce3 = new UnifyPair(tf.getSuperType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.SMALLERDOT);
UnifyPair noreduce4 = new UnifyPair(tf.getExtendsType(tf.getPlaceholderType("T")), tf.getSimpleType("type"), PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceUpLow(noreduce1).isPresent());
Assert.assertFalse(rules.reduceUpLow(noreduce2).isPresent());
@ -154,13 +154,13 @@ public class RuleSetTest {
fcb.add(buffer, d1);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
MPair pair = new MPair(c2, d2, PairOperator.SMALLERDOT);
UnifyPair pair = new UnifyPair(c2, d2, PairOperator.SMALLERDOT);
System.out.println("------ Reduce1 ------");
Optional<Set<MPair>> res = rules.reduce1(pair);
Optional<Set<UnifyPair>> res = rules.reduce1(pair);
System.out.println(res);
pair = new MPair(c2, c2, PairOperator.SMALLERDOT);
pair = new UnifyPair(c2, c2, PairOperator.SMALLERDOT);
res = rules.reduce1(pair);
System.out.println(res);
@ -169,17 +169,17 @@ public class RuleSetTest {
*/
// Case 1: D <. C and C <* D
pair = new MPair(d2, c2, PairOperator.SMALLERDOT);
pair = new UnifyPair(d2, c2, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.reduce1(pair).isPresent());
// Case 2: D =. C
pair = new MPair(c2, d2, PairOperator.EQUALSDOT);
pair = new UnifyPair(c2, d2, PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduce1(pair).isPresent());
// Case 3: C <. D and !(C <* D)
fcb.clear();
rules = new RuleSet(fcb.getFiniteClosure());
pair = new MPair(c1, d1, PairOperator.SMALLERDOT);
pair = new UnifyPair(c1, d1, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.reduce1(pair).isPresent());
}
@ -199,17 +199,17 @@ public class RuleSetTest {
// C<T2, SType2, ? extends SType2>
ReferenceType c2 = tf.getSimpleType("C", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2")));
MPair pair1 = new MPair(c1, c2, PairOperator.EQUALSDOT);
MPair pair2 = new MPair(tf.getExtendsType(c1), tf.getExtendsType(c2), PairOperator.EQUALSDOT);
MPair pair3 = new MPair(tf.getSuperType(c1), tf.getSuperType(c2), PairOperator.EQUALSDOT);
UnifyPair pair1 = new UnifyPair(c1, c2, PairOperator.EQUALSDOT);
UnifyPair pair2 = new UnifyPair(tf.getExtendsType(c1), tf.getExtendsType(c2), PairOperator.EQUALSDOT);
UnifyPair pair3 = new UnifyPair(tf.getSuperType(c1), tf.getSuperType(c2), PairOperator.EQUALSDOT);
Optional<Set<MPair>> opt1 = rules.reduce2(pair1);
Optional<Set<UnifyPair>> opt1 = rules.reduce2(pair1);
System.out.println(opt1);
Optional<Set<MPair>> opt2 = rules.reduce2(pair2);
Optional<Set<UnifyPair>> opt2 = rules.reduce2(pair2);
System.out.println(opt2);
Optional<Set<MPair>> opt3 = rules.reduce2(pair3);
Optional<Set<UnifyPair>> opt3 = rules.reduce2(pair3);
System.out.println(opt3);
@ -218,10 +218,10 @@ public class RuleSetTest {
*/
ReferenceType d1 = tf.getSimpleType("D", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2")));
pair1 = new MPair(d1, c1, PairOperator.EQUALSDOT); // Case 1: D =. C
pair2 = new MPair(tf.getExtendsType(c1), c2, PairOperator.EQUALSDOT); // Case 2: ? extends C =. C
pair3 = new MPair(tf.getExtendsType(c1), tf.getSuperType(c2), PairOperator.EQUALSDOT); // Case 3: ? extends C =. ? super C
MPair pair4 = new MPair(c1, c2, PairOperator.SMALLERDOT); // Case 4: C <. C
pair1 = new UnifyPair(d1, c1, PairOperator.EQUALSDOT); // Case 1: D =. C
pair2 = new UnifyPair(tf.getExtendsType(c1), c2, PairOperator.EQUALSDOT); // Case 2: ? extends C =. C
pair3 = new UnifyPair(tf.getExtendsType(c1), tf.getSuperType(c2), PairOperator.EQUALSDOT); // Case 3: ? extends C =. ? super C
UnifyPair pair4 = new UnifyPair(c1, c2, PairOperator.SMALLERDOT); // Case 4: C <. C
Assert.assertFalse(rules.reduceEq(pair1).isPresent());
Assert.assertFalse(rules.reduceEq(pair2).isPresent());
@ -254,18 +254,18 @@ public class RuleSetTest {
fcb.add(buffer, y1);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
MPair pair1 = new MPair(x2, extY1, PairOperator.SMALLERDOTWC);
MPair pair2 = new MPair(tf.getExtendsType(x2), extY1, PairOperator.SMALLERDOTWC);
MPair pair3 = new MPair(extY1, extY1, PairOperator.SMALLERDOTWC);
UnifyPair pair1 = new UnifyPair(x2, extY1, PairOperator.SMALLERDOTWC);
UnifyPair pair2 = new UnifyPair(tf.getExtendsType(x2), extY1, PairOperator.SMALLERDOTWC);
UnifyPair pair3 = new UnifyPair(extY1, extY1, PairOperator.SMALLERDOTWC);
System.out.println("------ ReduceExt ------");
Optional<Set<MPair>> opt1 = rules.reduceExt(pair1);
Optional<Set<UnifyPair>> opt1 = rules.reduceExt(pair1);
System.out.println(opt1);
Optional<Set<MPair>> opt2 = rules.reduceExt(pair2);
Optional<Set<UnifyPair>> opt2 = rules.reduceExt(pair2);
System.out.println(opt2);
Optional<Set<MPair>> opt3 = rules.reduceExt(pair3);
Optional<Set<UnifyPair>> opt3 = rules.reduceExt(pair3);
System.out.println(opt3);
/*
@ -273,21 +273,21 @@ public class RuleSetTest {
*/
// Case 1: X <.? Y
pair1 = new MPair(x2, extY1.getExtendedType(), PairOperator.SMALLERDOTWC);
pair1 = new UnifyPair(x2, extY1.getExtendedType(), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair1).isPresent());
// Case 2: X =. ? super Y
pair2 = new MPair(x2, extY1, PairOperator.EQUALSDOT);
pair2 = new UnifyPair(x2, extY1, PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceExt(pair2).isPresent());
// Case 3: ? extends Y <.? ? extends X
pair3 = new MPair(extY1, tf.getExtendsType(x2), PairOperator.SMALLERDOTWC);
pair3 = new UnifyPair(extY1, tf.getExtendsType(x2), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair3).isPresent());
// Case 4: X <. ? extends Y and ? extends Y not in grArg(X)
fcb.clear();
rules = new RuleSet(fcb.getFiniteClosure());
pair1 = new MPair(x2, extY1, PairOperator.SMALLERDOTWC);
pair1 = new UnifyPair(x2, extY1, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceExt(pair1).isPresent());
}
@ -316,18 +316,18 @@ public class RuleSetTest {
fcb.add(buffer, x1);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure());
MPair pair1 = new MPair(x2, supY1, PairOperator.SMALLERDOTWC);
MPair pair2 = new MPair(tf.getSuperType(x2), supY1, PairOperator.SMALLERDOTWC);
MPair pair3 = new MPair(supY1, supY1, PairOperator.SMALLERDOTWC);
UnifyPair pair1 = new UnifyPair(x2, supY1, PairOperator.SMALLERDOTWC);
UnifyPair pair2 = new UnifyPair(tf.getSuperType(x2), supY1, PairOperator.SMALLERDOTWC);
UnifyPair pair3 = new UnifyPair(supY1, supY1, PairOperator.SMALLERDOTWC);
System.out.println("------ ReduceSup ------");
Optional<Set<MPair>> opt1 = rules.reduceSup(pair1);
Optional<Set<UnifyPair>> opt1 = rules.reduceSup(pair1);
System.out.println(opt1);
Optional<Set<MPair>> opt2 = rules.reduceSup(pair2);
Optional<Set<UnifyPair>> opt2 = rules.reduceSup(pair2);
System.out.println(opt2);
Optional<Set<MPair>> opt3 = rules.reduceSup(pair3);
Optional<Set<UnifyPair>> opt3 = rules.reduceSup(pair3);
System.out.println(opt3);
/*
@ -335,21 +335,21 @@ public class RuleSetTest {
*/
// Case 1: X <.? Y
pair1 = new MPair(x2, supY1.getSuperedType(), PairOperator.SMALLERDOTWC);
pair1 = new UnifyPair(x2, supY1.getSuperedType(), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceSup(pair1).isPresent());
// Case 2: X =. ? super Y
pair2 = new MPair(x2, supY1, PairOperator.EQUALSDOT);
pair2 = new UnifyPair(x2, supY1, PairOperator.EQUALSDOT);
Assert.assertFalse(rules.reduceSup(pair2).isPresent());
// Case 3: ? super Y <.? ? super X
pair3 = new MPair(supY1, tf.getSuperType(x2), PairOperator.SMALLERDOTWC);
pair3 = new UnifyPair(supY1, tf.getSuperType(x2), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceSup(pair3).isPresent());
// Case 4: X <. ? super Y and ? super Y not in grArg(X)
fcb.clear();
rules = new RuleSet(fcb.getFiniteClosure());
pair1 = new MPair(x2, supY1, PairOperator.SMALLERDOTWC);
pair1 = new UnifyPair(x2, supY1, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceSup(pair1).isPresent());
}
@ -369,8 +369,8 @@ public class RuleSetTest {
// C<T2, SType2, ? extends SType2>
ReferenceType c2 = tf.getSimpleType("C", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2")));
MPair pair = new MPair(c1, c2, PairOperator.SMALLERDOTWC);
Optional<Set<MPair>> res = rules.reduceEq(pair);
UnifyPair pair = new UnifyPair(c1, c2, PairOperator.SMALLERDOTWC);
Optional<Set<UnifyPair>> res = rules.reduceEq(pair);
System.out.println(res);
/*
@ -379,11 +379,11 @@ public class RuleSetTest {
// Case 1: D <.? C
ReferenceType d1 = tf.getSimpleType("D", tf.getPlaceholderType("T2"), tf.getSimpleType("SType2"), tf.getExtendsType(tf.getSimpleType("SType2")));
pair = new MPair(d1, c1, PairOperator.SMALLERDOTWC);
pair = new UnifyPair(d1, c1, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.reduceEq(pair).isPresent());
// Case 2: C <. C
pair = new MPair(c1, c2, PairOperator.SMALLERDOT);
pair = new UnifyPair(c1, c2, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.reduceEq(pair).isPresent());
}
@ -395,9 +395,9 @@ public class RuleSetTest {
/*
* Positive Tests
*/
MPair erase1 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOT);
MPair erase2 = new MPair(tf.getSimpleType("HashSet", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOT);
MPair erase3 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
UnifyPair erase1 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOT);
UnifyPair erase2 = new UnifyPair(tf.getSimpleType("HashSet", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOT);
UnifyPair erase3 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
Assert.assertTrue(rules.erase1(erase1));
Assert.assertTrue(rules.erase1(erase2));
@ -406,9 +406,9 @@ public class RuleSetTest {
/*
* Negative Tests
*/
MPair noerase1 = new MPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
MPair noerase2 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.EQUALSDOT);
MPair noerase3 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOTWC);
UnifyPair noerase1 = new UnifyPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
UnifyPair noerase2 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.EQUALSDOT);
UnifyPair noerase3 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("Collection"), PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.erase1(noerase1));
Assert.assertFalse(rules.erase1(noerase2));
@ -423,11 +423,11 @@ public class RuleSetTest {
/*
* Positive Tests
*/
MPair erase1 = new MPair(tf.getSimpleType("List", "T"), tf.getExtendsType(tf.getSimpleType("Collection")), PairOperator.SMALLERDOTWC);
MPair erase2 = new MPair(tf.getSimpleType("Collection"), tf.getSuperType(tf.getSimpleType("HashSet", "T")), PairOperator.SMALLERDOTWC);
MPair erase3 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOTWC);
MPair erase4 = new MPair(tf.getExtendsType(tf.getSimpleType("LinkedList", "T")), tf.getExtendsType(tf.getSimpleType("List", "T")), PairOperator.SMALLERDOTWC);
MPair erase5 = new MPair(tf.getSuperType(tf.getSimpleType("List", "T")), tf.getSuperType(tf.getSimpleType("Stack", "T")), PairOperator.SMALLERDOTWC);
UnifyPair erase1 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getExtendsType(tf.getSimpleType("Collection")), PairOperator.SMALLERDOTWC);
UnifyPair erase2 = new UnifyPair(tf.getSimpleType("Collection"), tf.getSuperType(tf.getSimpleType("HashSet", "T")), PairOperator.SMALLERDOTWC);
UnifyPair erase3 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOTWC);
UnifyPair erase4 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("LinkedList", "T")), tf.getExtendsType(tf.getSimpleType("List", "T")), PairOperator.SMALLERDOTWC);
UnifyPair erase5 = new UnifyPair(tf.getSuperType(tf.getSimpleType("List", "T")), tf.getSuperType(tf.getSimpleType("Stack", "T")), PairOperator.SMALLERDOTWC);
Assert.assertTrue(rules.erase2(erase1));
@ -439,10 +439,10 @@ public class RuleSetTest {
/*
* Negative Tests
*/
MPair noerase1 = new MPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOTWC);
MPair noerase2 = new MPair(tf.getSuperType(tf.getSimpleType("List", "T")), tf.getSimpleType("ArrayList", "T"), PairOperator.SMALLERDOTWC);
MPair noerase3 = new MPair(tf.getExtendsType(tf.getSimpleType("List", "T")), tf.getSuperType(tf.getSimpleType("List", "T")), PairOperator.SMALLERDOTWC);
MPair noerase4 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
UnifyPair noerase1 = new UnifyPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOTWC);
UnifyPair noerase2 = new UnifyPair(tf.getSuperType(tf.getSimpleType("List", "T")), tf.getSimpleType("ArrayList", "T"), PairOperator.SMALLERDOTWC);
UnifyPair noerase3 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("List", "T")), tf.getSuperType(tf.getSimpleType("List", "T")), PairOperator.SMALLERDOTWC);
UnifyPair noerase4 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
Assert.assertFalse(rules.erase2(noerase1));
Assert.assertFalse(rules.erase2(noerase2));
@ -458,8 +458,8 @@ public class RuleSetTest {
/*
* Positive Tests
*/
MPair erase1 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.EQUALSDOT);
MPair erase2 = new MPair(tf.getPlaceholderType("W"), tf.getPlaceholderType("W"), PairOperator.EQUALSDOT);
UnifyPair erase1 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.EQUALSDOT);
UnifyPair erase2 = new UnifyPair(tf.getPlaceholderType("W"), tf.getPlaceholderType("W"), PairOperator.EQUALSDOT);
Assert.assertTrue(rules.erase3(erase1));
Assert.assertTrue(rules.erase3(erase2));
@ -467,8 +467,8 @@ public class RuleSetTest {
/*
* Negative Tests
*/
MPair noerase1 = new MPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.EQUALSDOT);
MPair noerase2 = new MPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
UnifyPair noerase1 = new UnifyPair(tf.getSimpleType("Collection"), tf.getSimpleType("List", "T"), PairOperator.EQUALSDOT);
UnifyPair noerase2 = new UnifyPair(tf.getSimpleType("List", "T"), tf.getSimpleType("List", "T"), PairOperator.SMALLERDOT);
Assert.assertFalse(rules.erase3(noerase1));
Assert.assertFalse(rules.erase3(noerase2));
@ -482,14 +482,14 @@ public class RuleSetTest {
/*
* Positive Tests
*/
MPair swap1 = new MPair(tf.getExtendsType(tf.getSimpleType("MyClass")), tf.getPlaceholderType("P"), PairOperator.EQUALSDOT);
MPair swap2 = new MPair(tf.getSimpleType("MyClass"), tf.getPlaceholderType("X"), PairOperator.EQUALSDOT);
UnifyPair swap1 = new UnifyPair(tf.getExtendsType(tf.getSimpleType("MyClass")), tf.getPlaceholderType("P"), PairOperator.EQUALSDOT);
UnifyPair swap2 = new UnifyPair(tf.getSimpleType("MyClass"), tf.getPlaceholderType("X"), PairOperator.EQUALSDOT);
MPair expected1 = new MPair(tf.getPlaceholderType("P"), tf.getExtendsType(tf.getSimpleType("MyClass")), PairOperator.EQUALSDOT);
MPair expected2 = new MPair(tf.getPlaceholderType("X"), tf.getSimpleType("MyClass"), PairOperator.EQUALSDOT);
UnifyPair expected1 = new UnifyPair(tf.getPlaceholderType("P"), tf.getExtendsType(tf.getSimpleType("MyClass")), PairOperator.EQUALSDOT);
UnifyPair expected2 = new UnifyPair(tf.getPlaceholderType("X"), tf.getSimpleType("MyClass"), PairOperator.EQUALSDOT);
Optional<MPair> opt1 = rules.swap(swap1);
Optional<MPair> opt2 = rules.swap(swap2);
Optional<UnifyPair> opt1 = rules.swap(swap1);
Optional<UnifyPair> opt2 = rules.swap(swap2);
// swap((? extends MyClass =. P)) = (P =. MyClass)
Assert.assertEquals(opt1.get(), expected1);
@ -500,15 +500,15 @@ public class RuleSetTest {
/*
* Negative Tests
*/
MPair noswap1 = new MPair(tf.getPlaceholderType("Z"), tf.getPlaceholderType("X"), PairOperator.EQUALSDOT);
MPair noswap2 = new MPair(tf.getSimpleType("MyClass"), tf.getExtendsType(tf.getPlaceholderType("X")), PairOperator.EQUALSDOT);
MPair noswap3 = new MPair( tf.getPlaceholderType("X"), tf.getSimpleType("MyClass"), PairOperator.EQUALSDOT);
MPair noswap4 = new MPair(tf.getSimpleType("MyClass"), tf.getPlaceholderType("X"), PairOperator.SMALLERDOT);
UnifyPair noswap1 = new UnifyPair(tf.getPlaceholderType("Z"), tf.getPlaceholderType("X"), PairOperator.EQUALSDOT);
UnifyPair noswap2 = new UnifyPair(tf.getSimpleType("MyClass"), tf.getExtendsType(tf.getPlaceholderType("X")), PairOperator.EQUALSDOT);
UnifyPair noswap3 = new UnifyPair( tf.getPlaceholderType("X"), tf.getSimpleType("MyClass"), PairOperator.EQUALSDOT);
UnifyPair noswap4 = new UnifyPair(tf.getSimpleType("MyClass"), tf.getPlaceholderType("X"), PairOperator.SMALLERDOT);
opt1 = rules.swap(noswap1);
opt2 = rules.swap(noswap2);
Optional<MPair> opt3 = rules.swap(noswap3);
Optional<MPair> opt4 = rules.swap(noswap4);
Optional<UnifyPair> opt3 = rules.swap(noswap3);
Optional<UnifyPair> opt4 = rules.swap(noswap4);
Assert.assertFalse(opt1.isPresent());
Assert.assertFalse(opt2.isPresent());
@ -538,9 +538,9 @@ public class RuleSetTest {
ReferenceType c2 = tf.getSimpleType("Type2", "Object");
ReferenceType c3 = tf.getSimpleType("Type3", "Object", "Number");
MPair pair1 = new MPair(c1, c2, PairOperator.SMALLERDOT);
MPair pair2 = new MPair(c2, c3, PairOperator.SMALLERDOT);
MPair pair3 = new MPair(c1, c3, PairOperator.SMALLERDOT);
UnifyPair pair1 = new UnifyPair(c1, c2, PairOperator.SMALLERDOT);
UnifyPair pair2 = new UnifyPair(c2, c3, PairOperator.SMALLERDOT);
UnifyPair pair3 = new UnifyPair(c1, c3, PairOperator.SMALLERDOT);
System.out.println("------ Adapt ------");
System.out.println(rules.adapt(pair1));
@ -551,9 +551,9 @@ public class RuleSetTest {
* Negative Tests
*/
MPair noAdapt1 = new MPair(c2, c1, PairOperator.SMALLERDOT);
MPair noAdapt2 = new MPair(c1, c1, PairOperator.SMALLERDOT);
MPair noAdapt3 = new MPair(c1, c2, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt1 = new UnifyPair(c2, c1, PairOperator.SMALLERDOT);
UnifyPair noAdapt2 = new UnifyPair(c1, c1, PairOperator.SMALLERDOT);
UnifyPair noAdapt3 = new UnifyPair(c1, c2, PairOperator.SMALLERDOTWC);
Assert.assertFalse(rules.adapt(noAdapt1).isPresent());
Assert.assertFalse(rules.adapt(noAdapt2).isPresent());
@ -588,13 +588,13 @@ public class RuleSetTest {
ExtendsType extc2 = new ExtendsType(c2);
ExtendsType extc3 = new ExtendsType(c3);
MPair pair1 = new MPair(c1, extc2, PairOperator.SMALLERDOTWC);
MPair pair2 = new MPair(c2, extc3, PairOperator.SMALLERDOTWC);
MPair pair3 = new MPair(c1, extc3, PairOperator.SMALLERDOTWC);
MPair pair4 = new MPair(extc1, extc2, PairOperator.SMALLERDOTWC);
MPair pair5 = new MPair(extc2, extc3, PairOperator.SMALLERDOTWC);
MPair pair6 = new MPair(extc1, extc3, PairOperator.SMALLERDOTWC);
MPair pair7 = new MPair(extc1, extc1, PairOperator.SMALLERDOTWC);
UnifyPair pair1 = new UnifyPair(c1, extc2, PairOperator.SMALLERDOTWC);
UnifyPair pair2 = new UnifyPair(c2, extc3, PairOperator.SMALLERDOTWC);
UnifyPair pair3 = new UnifyPair(c1, extc3, PairOperator.SMALLERDOTWC);
UnifyPair pair4 = new UnifyPair(extc1, extc2, PairOperator.SMALLERDOTWC);
UnifyPair pair5 = new UnifyPair(extc2, extc3, PairOperator.SMALLERDOTWC);
UnifyPair pair6 = new UnifyPair(extc1, extc3, PairOperator.SMALLERDOTWC);
UnifyPair pair7 = new UnifyPair(extc1, extc1, PairOperator.SMALLERDOTWC);
System.out.println("------ AdaptExt ------");
System.out.println(rules.adaptExt(pair1));
@ -609,11 +609,11 @@ public class RuleSetTest {
* Negative Tests
*/
MPair noAdapt1 = new MPair(extc2, extc1, PairOperator.SMALLERDOTWC);
MPair noAdapt2 = new MPair(extc1, c2, PairOperator.SMALLERDOTWC);
MPair noAdapt3 = new MPair(tf.getSuperType(c1), extc2, PairOperator.SMALLERDOTWC);
MPair noAdapt4 = new MPair(extc3, extc1, PairOperator.SMALLERDOTWC);
MPair noAdapt5 = new MPair(c1, extc2, PairOperator.SMALLERDOT);
UnifyPair noAdapt1 = new UnifyPair(extc2, extc1, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt2 = new UnifyPair(extc1, c2, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt3 = new UnifyPair(tf.getSuperType(c1), extc2, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt4 = new UnifyPair(extc3, extc1, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt5 = new UnifyPair(c1, extc2, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.adaptExt(noAdapt1).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt2).isPresent());
@ -650,13 +650,13 @@ public class RuleSetTest {
SuperType supc2 = new SuperType(c2);
SuperType supc3 = new SuperType(c3);
MPair pair1 = new MPair(c2, supc1, PairOperator.SMALLERDOTWC);
MPair pair2 = new MPair(c3, supc2, PairOperator.SMALLERDOTWC);
MPair pair3 = new MPair(c3, supc1, PairOperator.SMALLERDOTWC);
MPair pair4 = new MPair(supc2, supc1, PairOperator.SMALLERDOTWC);
MPair pair5 = new MPair(supc3, supc2, PairOperator.SMALLERDOTWC);
MPair pair6 = new MPair(supc3, supc1, PairOperator.SMALLERDOTWC);
MPair pair7 = new MPair(supc1, supc1, PairOperator.SMALLERDOTWC);
UnifyPair pair1 = new UnifyPair(c2, supc1, PairOperator.SMALLERDOTWC);
UnifyPair pair2 = new UnifyPair(c3, supc2, PairOperator.SMALLERDOTWC);
UnifyPair pair3 = new UnifyPair(c3, supc1, PairOperator.SMALLERDOTWC);
UnifyPair pair4 = new UnifyPair(supc2, supc1, PairOperator.SMALLERDOTWC);
UnifyPair pair5 = new UnifyPair(supc3, supc2, PairOperator.SMALLERDOTWC);
UnifyPair pair6 = new UnifyPair(supc3, supc1, PairOperator.SMALLERDOTWC);
UnifyPair pair7 = new UnifyPair(supc1, supc1, PairOperator.SMALLERDOTWC);
System.out.println("------ AdaptSup ------");
System.out.println(rules.adaptSup(pair1));
@ -671,11 +671,11 @@ public class RuleSetTest {
* Negative Tests
*/
MPair noAdapt1 = new MPair(supc2, supc1, PairOperator.SMALLERDOTWC);
MPair noAdapt2 = new MPair(supc1, c2, PairOperator.SMALLERDOTWC);
MPair noAdapt3 = new MPair(tf.getExtendsType(c1), supc2, PairOperator.SMALLERDOTWC);
MPair noAdapt4 = new MPair(supc3, supc1, PairOperator.SMALLERDOTWC);
MPair noAdapt5 = new MPair(c1, supc2, PairOperator.SMALLERDOT);
UnifyPair noAdapt1 = new UnifyPair(supc2, supc1, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt2 = new UnifyPair(supc1, c2, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt3 = new UnifyPair(tf.getExtendsType(c1), supc2, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt4 = new UnifyPair(supc3, supc1, PairOperator.SMALLERDOTWC);
UnifyPair noAdapt5 = new UnifyPair(c1, supc2, PairOperator.SMALLERDOT);
Assert.assertFalse(rules.adaptExt(noAdapt1).isPresent());
Assert.assertFalse(rules.adaptExt(noAdapt2).isPresent());

View File

@ -9,7 +9,7 @@ import org.junit.Test;
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
public class StandardUnifyTest {
@ -28,7 +28,7 @@ public class StandardUnifyTest {
UnifyType f = tf.getSimpleType("f", x);
// {f<x> = y}
Set<MPair> terms = new HashSet<MPair>();
Set<UnifyPair> terms = new HashSet<UnifyPair>();
System.out.println(unify.unify(f, y).get());

View File

@ -7,15 +7,10 @@ import org.junit.Test;
import de.dhbwstuttgart.syntaxtree.factory.UnifyPairMengenBuilder;
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
import de.dhbwstuttgart.syntaxtree.factory.Unify_FC_TTO_Builder;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -25,318 +20,15 @@ public class UnifyOldTest {
@Test
public void unifyTest1() {
// Init Factories and Builders
UnifyTypeFactory typeFactory = new UnifyTypeFactory();
Unify_FC_TTO_Builder fcBuilder = new Unify_FC_TTO_Builder();
UnifyPairMengenBuilder assumptionBuilder = new UnifyPairMengenBuilder();
UnifyPairMengenBuilder resultBuilder = new UnifyPairMengenBuilder();
<<<<<<< HEAD
/*
* Test a <. Boolean
*/
// Init Types
RefType boolT = this.GetSimpleType("java.lang.Boolean");
TypePlaceholder aTph = this.GetTypePlaceholder("a");
// Expected Result
resultBuilder.clear();
resultBuilder.addPair(aTph, boolT, PairOperator.Equal);
resultBuilder.addPair(aTph, this.GetExtendsType(boolT),
PairOperator.Equal);
Menge<Menge<Pair>> expectedResult = resultBuilder.getNestedPairMenge();
// Actual Result
assumptionBuilder.clear();
assumptionBuilder.addPair(aTph, boolT);
Menge<Menge<Pair>> actualResult = Unify.unify(
assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
// System.out.println(expectedResult);
// System.out.println(actualResult);
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
/*
* Test b <. a, a <. Boolean
*/
// Init Types
boolT = this.GetSimpleType("java.lang.Boolean");
aTph = this.GetTypePlaceholder("a");
TypePlaceholder bTph = this.GetTypePlaceholder("b");
// Expected Result
resultBuilder.clear();
resultBuilder.addPair(aTph, boolT, PairOperator.Equal);
resultBuilder.addPair(aTph, this.GetExtendsType(boolT),
PairOperator.Equal);
resultBuilder.addPair(bTph, boolT, PairOperator.Equal);
resultBuilder.addPair(bTph, this.GetExtendsType(boolT),
PairOperator.Equal);
expectedResult = resultBuilder.getNestedPairMenge();
// Actual Result
assumptionBuilder.clear();
assumptionBuilder.addPair(bTph, aTph);
assumptionBuilder.addPair(aTph, boolT);
actualResult = Unify.unify(assumptionBuilder.getPairMenge(),
fcBuilder.Get_FC_TTO());
// System.out.println(expectedResult);
// System.out.println(actualResult);
// NOTE: Elemente im actualResult sind nicht unique
// Assert.assertTrue(mengeEquals(expectedResult, actualResult));
/*
* Test b <. a, a <. b
*/
aTph = this.GetTypePlaceholder("a");
bTph = this.GetTypePlaceholder("b");
// Expected Result
resultBuilder.clear();
resultBuilder.addPair(bTph, aTph);
resultBuilder.addPair(aTph, bTph);
Menge<Pair> buffer = resultBuilder.getPairMenge();
expectedResult = new Menge<Menge<Pair>>();
expectedResult.add(buffer);
// Actual Result
assumptionBuilder.clear();
assumptionBuilder.addPair(bTph, aTph);
assumptionBuilder.addPair(aTph, bTph);
actualResult = Unify.unify(assumptionBuilder.getPairMenge(),
fcBuilder.Get_FC_TTO());
// System.out.println(expectedResult);
// System.out.println(actualResult);
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
/*
* Test Integer <. a, a <. Boolean
*/
RefType intT = this.GetSimpleType("java.lang.Integer");
boolT = this.GetSimpleType("java.lang.Boolean");
aTph = this.GetTypePlaceholder("a");
bTph = this.GetTypePlaceholder("b");
// Expected Result
resultBuilder.clear();
expectedResult = resultBuilder.getNestedPairMenge();
// Actual Result
assumptionBuilder.clear();
assumptionBuilder.addPair(intT, aTph);
assumptionBuilder.addPair(aTph, boolT);
actualResult = Unify.unify(assumptionBuilder.getPairMenge(),
fcBuilder.Get_FC_TTO());
// System.out.println(expectedResult);
// System.out.println(actualResult);
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
}
@Test
public void unifyTestGenerics() {
// Init Factories and Builders
Unify_FC_TTO_Builder fcBuilder = new Unify_FC_TTO_Builder();
UnifyPairMengenBuilder assumptionBuilder = new UnifyPairMengenBuilder();
UnifyPairMengenBuilder resultBuilder = new UnifyPairMengenBuilder();
/*
* Test a <. MyClass<T, F>
*/
TypePlaceholder aTph = this.GetTypePlaceholder("a");
RefType myType = this.GetSimpleType("MyClass",
this.GetTypePlaceholder("T"),
this.GetTypePlaceholder("F"));
// Expected Result
resultBuilder.clear();
resultBuilder.addPair(aTph, myType, PairOperator.Equal);
resultBuilder.addPair(aTph, this.GetExtendsType(myType));
Menge<Menge<Pair>> expectedResult = resultBuilder.getNestedPairMenge();
// Actual Result
assumptionBuilder.clear();
assumptionBuilder.addPair(aTph, myType);
Menge<Menge<Pair>> actualResult = Unify.unify(
assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
// System.out.println(expectedResult);
// System.out.println(actualResult);
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
/*
* Test List<List<T>> <. List<T>
*/
TypePlaceholder tTph = this.GetTypePlaceholder("T");
RefType list = this.GetSimpleType("List", tTph);
RefType listlist = this.GetSimpleType("List", list);
// Expected Result
resultBuilder.clear();
resultBuilder.addPair(this.GetExtendsType(list), tTph,
PairOperator.Equal);
expectedResult = resultBuilder.getNestedPairMenge();
// Actual Result
assumptionBuilder.clear();
assumptionBuilder.addPair(listlist, list);
actualResult = Unify.unify(assumptionBuilder.getPairMenge(),
fcBuilder.Get_FC_TTO());
System.out.println(expectedResult);
System.out.println(actualResult);
Assert.assertTrue(mengeEquals(expectedResult, actualResult));
/*
* Test List<T> <. List<List<T>>
*/
}
@Test
public void unifyTestInheritance() {
// Init Factories and Builders
Unify_FC_TTO_Builder fcBuilder = new Unify_FC_TTO_Builder();
UnifyPairMengenBuilder assumptionBuilder = new UnifyPairMengenBuilder();
UnifyPairMengenBuilder resultBuilder = new UnifyPairMengenBuilder();
// Init Types
RefType tBool = this.GetSimpleType("java.lang.Boolean");
RefType tString = this.GetSimpleType("java.lang.String");
RefType tInt = this.GetSimpleType("java.lang.Integer");
TypePlaceholder tphA = this.GetTypePlaceholder("a");
// Build inheritance hierachy
// Bool <. String <. Int
fcBuilder.AddInheritance(tBool, tString);
fcBuilder.AddInheritance(tString, tInt);
// Build Assumptions
assumptionBuilder.addPair(tphA, tString);
// Build expected result
resultBuilder.addPair(tphA, tBool, PairOperator.Equal);
resultBuilder.addPair(tphA, this.GetExtendsType(tBool),
PairOperator.Equal);
resultBuilder.addPair(tphA, tString, PairOperator.Equal);
resultBuilder.addPair(tphA, this.GetExtendsType(tString),
PairOperator.Equal);
// Assert
Menge<Menge<Pair>> actualResult = Unify.unify(
assumptionBuilder.getPairMenge(), fcBuilder.Get_FC_TTO());
// System.out.println(actualResult);
// System.out.println("-------------------");
// System.out.println(resultBuilder.getNestedPairMenge());
Assert.assertTrue(mengeEquals(resultBuilder.getNestedPairMenge(),
actualResult));
}
@Test
public void unifyTestWildcards() {
}
private static boolean mengeEquals(Menge<Menge<Pair>> m1,
Menge<Menge<Pair>> m2) {
if (m1.size() != m2.size())
return false;
return containsAll(m1, m2) && containsAll(m2, m1);
}
private static boolean containsAll(Menge<Menge<Pair>> m1,
Menge<Menge<Pair>> m2) {
for (Menge<Pair> elem : m2)
if (!contains(m1, elem))
return false;
return true;
}
private static boolean contains(Menge<Menge<Pair>> m1, Menge<Pair> m2) {
for (Menge<Pair> elem : m1)
if (mengePairEquals(elem, m2))
return true;
return false;
}
private static boolean mengePairEquals(Menge<Pair> m1, Menge<Pair> m2) {
if (m1.size() != m2.size())
return false;
return containsAllPair(m1, m2) && containsAllPair(m2, m1);
}
private static boolean containsAllPair(Menge<Pair> m1, Menge<Pair> m2) {
for (Pair elem : m1)
if (contains(m2, elem))
return true;
return false;
}
private static boolean contains(Menge<Pair> m, Pair p) {
for (Pair elem : m)
if (pairEquals(elem, p))
return true;
return false;
}
private static boolean pairEquals(Pair p1, Pair p2) {
return (p1.TA1.equals(p2.TA1) && p1.TA2.equals(p2.TA2))
|| (p1.TA1.equals(p2.TA2) && p1.TA2.equals(p2.TA1));
}
private RefType GetSimpleType(String name, Type... parameters) {
if(parameters.length == 0)
return new RefType(name, null, 0);
Menge<Type> typeParams = new Menge<Type>();
for(Type t : parameters)
typeParams.add(t);
return new RefType(name, typeParams, null, 0);
}
private ExtendsWildcardType GetExtendsType(ObjectType extendedType) {
return new ExtendsWildcardType(extendedType);
}
private SuperWildcardType GetSuperType(ObjectType superedType) {
return new SuperWildcardType(superedType);
}
private WildcardType GetWildcardType() {
return new WildcardType(null, null, 0);
}
private TypePlaceholder GetTypePlaceholder(String name) {
return TypePlaceholder.backdoorCreate(name);
}
=======
TypePlaceholder a = typeFactory.GetTypePlaceholder("a");
ExtendsWildcardType extA = typeFactory.GetExtendsType(a);
TypePlaceholder b = typeFactory.GetTypePlaceholder("b");
ExtendsWildcardType extB = typeFactory.GetExtendsType(b);
TypePlaceholder b = typeFactory.GetTypePlaceholder("a");
ExtendsWildcardType extB = typeFactory.GetExtendsType(a);
RefType integer = typeFactory.GetSimpleType("Integer");
SuperWildcardType supInt = typeFactory.GetSuperType(integer);
RefType listsupint = typeFactory.GetSimpleType("List", supInt);
@ -643,6 +335,5 @@ public class UnifyOldTest {
// return (p1.TA1.equals(p2.TA1) && p1.TA2.equals(p2.TA2))
// || (p1.TA1.equals(p2.TA2) && p1.TA2.equals(p2.TA1));
// }
>>>>>>> d89d06797e17a7a95f007fe24e9b6133b3b13179
}

View File

@ -10,7 +10,7 @@ import org.junit.Test;
import de.dhbwstuttgart.typeinference.unify.Unify;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
@ -48,10 +48,10 @@ public class UnifyTest extends Unify {
* unify({ }) = { }
*/
Set<MPair> eq = new HashSet<MPair>();
Set<Set<MPair>> expected = new HashSet<>();
Set<UnifyPair> eq = new HashSet<UnifyPair>();
Set<Set<UnifyPair>> expected = new HashSet<>();
expected.add(new HashSet<>());
Set<Set<MPair>> actual = unify(eq, fc);
Set<Set<UnifyPair>> actual = unify(eq, fc);
Assert.assertEquals(expected, actual);
/*
@ -62,12 +62,12 @@ public class UnifyTest extends Unify {
UnifyType tphA = tf.getPlaceholderType("a");
eq = new HashSet<>();
eq.add(new MPair(tphA, number, PairOperator.SMALLERDOT));
eq.add(new UnifyPair(tphA, number, PairOperator.SMALLERDOT));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, doubl, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, doubl, PairOperator.EQUALSDOT));
actual = unify(eq, fc);
@ -80,12 +80,12 @@ public class UnifyTest extends Unify {
*/
eq = new HashSet<>();
eq.add(new MPair(integer, tphA, PairOperator.SMALLERDOT));
eq.add(new UnifyPair(integer, tphA, PairOperator.SMALLERDOT));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, object, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, object, PairOperator.EQUALSDOT));
actual = unify(eq, fc);
@ -99,10 +99,10 @@ public class UnifyTest extends Unify {
*/
eq = new HashSet<>();
eq.add(new MPair(tphA, number, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(tphA, number, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, number, PairOperator.EQUALSDOT));
actual = unify(eq, fc);
@ -118,15 +118,15 @@ public class UnifyTest extends Unify {
UnifyType supNumber = tf.getSuperType(number);
UnifyType supObject = tf.getSuperType(object);
eq = new HashSet<>();
eq.add(new MPair(tphA, supInteger, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(tphA, supInteger, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, object, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, supInteger, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, supNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, supObject, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, object, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, supInteger, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, supNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, supObject, PairOperator.EQUALSDOT));
actual = unify(eq, fc);
actual = filterGeneratedTPHsMultiple(actual);
@ -144,15 +144,15 @@ public class UnifyTest extends Unify {
UnifyType extNumber = tf.getExtendsType(number);
UnifyType extObject = tf.getExtendsType(object);
UnifyType supDouble = tf.getSuperType(doubl);
eq.add(new MPair(number, tphA, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(number, tphA, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, extNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, extObject, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, supInteger, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, supDouble, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, supNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, extNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, extObject, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, supInteger, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, supDouble, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, supNumber, PairOperator.EQUALSDOT));
actual = unify(eq, fc);
@ -165,11 +165,11 @@ public class UnifyTest extends Unify {
*/
eq = new HashSet<>();
eq.add(new MPair(extNumber, tphA, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(extNumber, tphA, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, extNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, extObject, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, extNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, extObject, PairOperator.EQUALSDOT));
actual = unify(eq, fc);
@ -186,15 +186,15 @@ public class UnifyTest extends Unify {
UnifyType extDouble = tf.getExtendsType(doubl);
eq = new HashSet<>();
eq.add(new MPair(tphA, extNumber, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(tphA, extNumber, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, extNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, extInteger, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, extDouble, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, doubl, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new MPair(tphA, number, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, extNumber, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, extInteger, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, extDouble, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, doubl, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, integer, PairOperator.EQUALSDOT));
addAsSet(expected, new UnifyPair(tphA, number, PairOperator.EQUALSDOT));
actual = unify(eq, fc);
@ -207,7 +207,7 @@ public class UnifyTest extends Unify {
*/
eq = new HashSet<>();
eq.add(new MPair(integer, number, PairOperator.SMALLERDOT));
eq.add(new UnifyPair(integer, number, PairOperator.SMALLERDOT));
expected = new HashSet<>();
expected.add(new HashSet<>());
@ -223,7 +223,7 @@ public class UnifyTest extends Unify {
*/
eq = new HashSet<>();
eq.add(new MPair(integer, number, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(integer, number, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
@ -239,10 +239,10 @@ public class UnifyTest extends Unify {
UnifyType tphB = tf.getPlaceholderType("b");
eq = new HashSet<>();
eq.add(new MPair(tphA, tphB, PairOperator.SMALLERDOT));
eq.add(new UnifyPair(tphA, tphB, PairOperator.SMALLERDOT));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, tphB, PairOperator.SMALLERDOT));
addAsSet(expected, new UnifyPair(tphA, tphB, PairOperator.SMALLERDOT));
actual = unify(eq, fc);
@ -255,10 +255,10 @@ public class UnifyTest extends Unify {
*/
eq = new HashSet<>();
eq.add(new MPair(tphA, tphB, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(tphA, tphB, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
addAsSet(expected, new MPair(tphA, tphB, PairOperator.SMALLERDOTWC));
addAsSet(expected, new UnifyPair(tphA, tphB, PairOperator.SMALLERDOTWC));
actual = unify(eq, fc);
@ -296,12 +296,12 @@ public class UnifyTest extends Unify {
UnifyType extB = tf.getExtendsType(tphB);
UnifyType extNum = tf.getExtendsType(number);
Set<MPair> eq = new HashSet<MPair>();
eq.add(new MPair(tf.getSimpleType("Vector", tphA), tf.getSimpleType("Vector", extB), PairOperator.SMALLERDOT));
eq.add(new MPair(tf.getSimpleType("List", tphB), tf.getSimpleType("List", extNum), PairOperator.SMALLERDOT));
Set<UnifyPair> eq = new HashSet<UnifyPair>();
eq.add(new UnifyPair(tf.getSimpleType("Vector", tphA), tf.getSimpleType("Vector", extB), PairOperator.SMALLERDOT));
eq.add(new UnifyPair(tf.getSimpleType("List", tphB), tf.getSimpleType("List", extNum), PairOperator.SMALLERDOT));
Set<Set<MPair>> expected = new HashSet<>();
Set<Set<MPair>> actual = unify(eq, fc);
Set<Set<UnifyPair>> expected = new HashSet<>();
Set<Set<UnifyPair>> actual = unify(eq, fc);
System.out.println(actual);
//Assert.assertEquals(actual, expected);
@ -315,8 +315,8 @@ public class UnifyTest extends Unify {
UnifyType supB = tf.getSuperType(tphB);
eq = new HashSet<>();
eq.add(new MPair(tphA, supB, PairOperator.SMALLERDOTWC));
eq.add(new MPair(tphB, number, PairOperator.EQUALSDOT));
eq.add(new UnifyPair(tphA, supB, PairOperator.SMALLERDOTWC));
eq.add(new UnifyPair(tphB, number, PairOperator.EQUALSDOT));
expected = new HashSet<>();
@ -335,8 +335,8 @@ public class UnifyTest extends Unify {
UnifyType extA = tf.getExtendsType(tphA);
eq = new HashSet<MPair>();
eq.add(new MPair(tf.getSimpleType("Vector", extA), tf.getSimpleType("Vector", extNum), PairOperator.SMALLERDOT));
eq = new HashSet<UnifyPair>();
eq.add(new UnifyPair(tf.getSimpleType("Vector", extA), tf.getSimpleType("Vector", extNum), PairOperator.SMALLERDOT));
expected = new HashSet<>();
actual = unify(eq, fc);
@ -351,8 +351,8 @@ public class UnifyTest extends Unify {
*
*/
eq = new HashSet<MPair>();
eq.add(new MPair(tf.getSimpleType("Vector", extNum), tf.getSimpleType("Vector", extA), PairOperator.SMALLERDOT));
eq = new HashSet<UnifyPair>();
eq.add(new UnifyPair(tf.getSimpleType("Vector", extNum), tf.getSimpleType("Vector", extA), PairOperator.SMALLERDOT));
expected = new HashSet<>();
actual = unify(eq, fc);
@ -370,10 +370,10 @@ public class UnifyTest extends Unify {
* ? extends Number <.? b
*/
eq = new HashSet<MPair>();
eq.add(new MPair(tf.getSimpleType("LinkedList", number), tf.getSimpleType("Deque", tphA), PairOperator.SMALLERDOT));
eq.add(new MPair(tf.getSimpleType("Deque", tphA), tf.getSimpleType("Queue", tphB), PairOperator.SMALLERDOT));
eq.add(new MPair(extNum, tphB, PairOperator.SMALLERDOTWC));
eq = new HashSet<UnifyPair>();
eq.add(new UnifyPair(tf.getSimpleType("LinkedList", number), tf.getSimpleType("Deque", tphA), PairOperator.SMALLERDOT));
eq.add(new UnifyPair(tf.getSimpleType("Deque", tphA), tf.getSimpleType("Queue", tphB), PairOperator.SMALLERDOT));
eq.add(new UnifyPair(extNum, tphB, PairOperator.SMALLERDOTWC));
expected = new HashSet<>();
actual = unify(eq, fc);
@ -446,16 +446,16 @@ public class UnifyTest extends Unify {
Assert.assertEquals(expected, actual);
}
private Set<Set<MPair>> filterGeneratedTPHsMultiple(Set<Set<MPair>> set) {
private Set<Set<UnifyPair>> filterGeneratedTPHsMultiple(Set<Set<UnifyPair>> set) {
return set.stream().map(x -> filterGeneratedTPHs(x)).collect(Collectors.toSet());
}
private Set<MPair> filterGeneratedTPHs(Set<MPair> set) {
private Set<UnifyPair> filterGeneratedTPHs(Set<UnifyPair> set) {
return set.stream().filter(x -> !((x.getRhsType() instanceof PlaceholderType) && ((PlaceholderType) x.getRhsType()).isGenerated())).
filter(x -> !((x.getLhsType() instanceof PlaceholderType) && ((PlaceholderType) x.getLhsType()).isGenerated())).collect(Collectors.toSet());
}
private void addAsSet(Set<Set<MPair>> addTo, MPair... mPairs) {
private void addAsSet(Set<Set<UnifyPair>> addTo, UnifyPair... mPairs) {
addTo.add(new HashSet<>(Arrays.stream(mPairs).collect(Collectors.toSet())));
}
}

View File

@ -21,7 +21,7 @@ import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
@ -45,24 +45,24 @@ public class UnifyTypeFactoryTest {
@Test
public void convertMPair() {
MPair mp1 = getSimpleMPair();
UnifyPair mp1 = getSimpleMPair();
checkConvertMPair(mp1);
TypePlaceholder tph1 = TypePlaceholder.fresh(new NullSyntaxTreeNode());
TypePlaceholder tph2 = TypePlaceholder.fresh(new NullSyntaxTreeNode());
MPair mp2 = new MPair(getSimpleType(), tf.getPlaceholderType(tph1.getName().toString()), PairOperator.SMALLERDOT);
UnifyPair mp2 = new UnifyPair(getSimpleType(), tf.getPlaceholderType(tph1.getName().toString()), PairOperator.SMALLERDOT);
checkConvertMPair(mp2);
MPair mp3 = new MPair(tf.getSuperType(getSimpleType()), getSimpleType(), PairOperator.SMALLERDOT);
UnifyPair mp3 = new UnifyPair(tf.getSuperType(getSimpleType()), getSimpleType(), PairOperator.SMALLERDOT);
checkConvertMPair(mp3);
MPair mp4 = new MPair(tf.getPlaceholderType(tph2.getName().toString()), tf.getPlaceholderType(tph1.getName().toString()), PairOperator.SMALLERDOT);
UnifyPair mp4 = new UnifyPair(tf.getPlaceholderType(tph2.getName().toString()), tf.getPlaceholderType(tph1.getName().toString()), PairOperator.SMALLERDOT);
checkConvertMPair(mp4);
ReferenceType typeWithParams = tf.getSimpleType("Test", getSimpleType());
ReferenceType typeWithTPHParams = tf.getSimpleType("Test", tf.getPlaceholderType("Test"));
MPair mp5 = new MPair(typeWithTPHParams, typeWithParams, PairOperator.SMALLERDOT);
UnifyPair mp5 = new UnifyPair(typeWithTPHParams, typeWithParams, PairOperator.SMALLERDOT);
checkConvertMPair(mp5);
}
@ -97,15 +97,15 @@ public class UnifyTypeFactoryTest {
Set<Set<Pair>> check = cons.cartesianProduct();
UnifyConstraintsSet converted = UnifyTypeFactory.convert(cons);
Set<Set<MPair>> cartesianProductOfConverted = converted.cartesianProduct();
Set<Set<UnifyPair>> cartesianProductOfConverted = converted.cartesianProduct();
assertTrue(cartesianProductOfConverted.size()==check.size());
assertTrue(cartesianProductOfConverted.iterator().next().size()==check.iterator().next().size());
Set<Set<Pair>> controlSet = new Menge<>();
for(Set<MPair> pairs : cartesianProductOfConverted){
for(Set<UnifyPair> pairs : cartesianProductOfConverted){
Set<Pair> tmpSet = new Menge<>();
for(MPair mp : pairs){
for(UnifyPair mp : pairs){
Pair p = checkConvertMPair(mp);
tmpSet.add(p);
}
@ -114,15 +114,15 @@ public class UnifyTypeFactoryTest {
assertTrue(controlSet.equals(check));
}
private static MPair checkConvertPair(Pair p){
private static UnifyPair checkConvertPair(Pair p){
System.out.println("Checking Pair: "+p);
MPair mp = UnifyTypeFactory.convert(p);
UnifyPair mp = UnifyTypeFactory.convert(p);
assertTrue(p.TA1.get_Name().equals(mp.getLhsType().getName()));
assertTrue(p.TA2.get_Name().equals(mp.getRhsType().getName()));
return mp;
}
private static Pair checkConvertMPair(MPair mp){
private static Pair checkConvertMPair(UnifyPair mp){
System.out.println("Checking Pair: "+mp);
Pair p = UnifyTypeFactory.convert(mp);
assertTrue(p.TA1.get_Name().equals(mp.getLhsType().getName()));
@ -134,10 +134,10 @@ public class UnifyTypeFactoryTest {
return tf.getSimpleType("String");
}
private static MPair getSimpleMPair(){
private static UnifyPair getSimpleMPair(){
UnifyType lt = tf.getSimpleType("String");
UnifyType rt = tf.getSimpleType("String");
MPair ret = new MPair(lt, rt, PairOperator.SMALLERDOT);
UnifyPair ret = new UnifyPair(lt, rt, PairOperator.SMALLERDOT);
return ret;
}