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

Zu beginn von unify werden doppelte wildcard konstruktionen entfernt
Variableneumbenennung bei smaller in Fall 1 weider entfernt

	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IMatch.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IUnify.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
In computeGreater unify durch match ersetzt

	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java

	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java
Abfrage ob eine doppelte wildcard konstruktion vorhanden ist eingefuegt
This commit is contained in:
Martin Plümicke 2018-04-05 18:09:24 +02:00
parent 1baaf79f8c
commit baee0024e9
9 changed files with 64 additions and 37 deletions

View File

@ -104,6 +104,19 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/
writeLog("Unifikation: " + eq.toString());
//eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new));
/*
* ? extends ? extends Theta rausfiltern
*/
Set<UnifyPair> doubleExt = eq.stream().filter(x -> (x.doubleExtended())).map(x -> { x.setUndefinedPair(); return x;})
.collect(Collectors.toCollection(HashSet::new));
if (doubleExt.size() > 0) {
Set<Set<UnifyPair>> ret = new HashSet<>();
ret.add(doubleExt);
return ret;
}
Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc);
/*
@ -301,7 +314,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* Step 7: Filter empty sets;
*/
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
if (!eqPrimePrimeSet.isEmpty())
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet))
writeLog("Result " + eqPrimePrimeSet.toString());
return eqPrimePrimeSet;
}
@ -469,17 +482,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
Falsch!
Optional<Boolean> res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y));
if (res.isPresent()) { return res.get(); }
else { return false; }
Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y));
return ret;
}
protected boolean isUndefinedPairSetSet(Set<Set<UnifyPair>> s) {
if (s.size() ==1) {
Optional<Boolean> res = s.stream().map(x -> isUndefinedPairSet(x)).reduce((x,y)-> (x == y));
if (res.isPresent()) { return res.get(); }
else { return false; }
Boolean ret = isUndefinedPairSet(s.stream().findFirst().get());
return ret;
}
return false;
@ -853,13 +863,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
for (UnifyType tq : thetaQs) {
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
//eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen
Set<UnifyType> smaller_ext = smaller.stream()
Set<UnifyType> smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType))
.map(x -> {
BinaryOperator<HashMap<PlaceholderType,PlaceholderType>> combiner = (aa,b) -> { aa.putAll(b); return aa;};
HashMap<PlaceholderType,PlaceholderType> hm = x.getInvolvedPlaceholderTypes().stream()
.reduce(new HashMap<PlaceholderType,PlaceholderType>(),
(aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner);
return new ExtendsType (x.accept(new freshPlaceholder(), hm));}).collect(Collectors.toCollection(HashSet::new));
//BinaryOperator<HashMap<PlaceholderType,PlaceholderType>> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen
//HashMap<PlaceholderType,PlaceholderType> hm = x.getInvolvedPlaceholderTypes().stream()
// .reduce(new HashMap<PlaceholderType,PlaceholderType>(),
// (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner);
return new ExtendsType (x);})//.accept(new freshPlaceholder(), hm));}
.collect(Collectors.toCollection(HashSet::new));
smaller.addAll(smaller_ext);
//eingefuegt PL 2018-03-29 Ende ? ext. theta hinzufuegen
for(UnifyType theta : smaller) {

View File

@ -13,23 +13,17 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
/**
* Match
* @author Martin Pluemicke
* abgeleitet aus IUnify.java
*/
public interface IMatch {
/**
* Finds the most general unifier sigma of the set {t1,...,tn} so that
* sigma(t1) = sigma(t2) = ... = sigma(tn).
* @param terms The set of terms to be unified
* @return An optional of the most general unifier if it exists or an empty optional if there is no unifier.
* Finds the most general matcher sigma of the set {t1 =. t1',...,tn =. tn'} so that
* sigma(t1) = t1' , ... sigma(tn) = tn'.
* @param terms The set of terms to be matched
* @return An optional of the most general matcher if it exists or an empty optional if there is no matcher.
*/
public Optional<Unifier> match(ArrayList<UnifyPair> termsList);
/**
* Finds the most general unifier sigma of the set {t1,...,tn} so that
* sigma(t1) = sigma(t2) = ... = sigma(tn).
* @param terms The set of terms to be unified
* @return An optional of the most general unifier if it exists or an empty optional if there is no unifier.
*/
}

View File

@ -15,16 +15,16 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
public interface IUnify {
/**
* Finds the most general unifier sigma of the set {t1,...,tn} so that
* sigma(t1) = sigma(t2) = ... = sigma(tn).
* Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that
* sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn').
* @param terms The set of terms to be unified
* @return An optional of the most general unifier if it exists or an empty optional if there is no unifier.
*/
public Optional<Unifier> unify(Set<UnifyType> terms);
/**
* Finds the most general unifier sigma of the set {t1,...,tn} so that
* sigma(t1) = sigma(t2) = ... = sigma(tn).
* Finds the most general unifier sigma of the set {t1 =. t1',...,tn =. tn'} so that
* sigma(t1) = sigma(t1') , ... sigma(tn) = sigma(tn').
* @param terms The set of terms to be unified
* @return An optional of the most general unifier if it exists or an empty optional if there is no unifier.
*/

View File

@ -23,6 +23,9 @@ public final class ExtendsType extends WildcardType {
*/
public ExtendsType(UnifyType extendedType) {
super("? extends " + extendedType.getName(), extendedType);
if (extendedType instanceof ExtendsType) {
System.out.print("");
}
}
/**

View File

@ -10,8 +10,8 @@ import java.util.stream.Collectors;
import com.google.common.collect.Ordering;
//PL 18-02-05 Unifier durch Matcher ersetzt
//mus greater noch erstezt werden
//PL 18-02-05/18-04-05 Unifier durch Matcher ersetzt
//muss greater noch ersetzt werden ja erledigt 18--04-05
import de.dhbwstuttgart.typeinference.unify.MartelliMontanariUnify;
import de.dhbwstuttgart.typeinference.unify.Match;
@ -196,7 +196,9 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
protected Set<UnifyType> computeGreater(Set<UnifyType> types) {
HashSet<UnifyType> result = new HashSet<>();
IUnify unify = new MartelliMontanariUnify();
//PL 18-04-05 Unifier durch Matcher ersetzt
//IUnify unify = new MartelliMontanariUnify();
Match match = new Match();
for(UnifyType t : types) {
@ -218,7 +220,11 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(t.getName());
for(Node<UnifyType> candidate : candidates) {
UnifyType theta1 = candidate.getContent();
Optional<Unifier> optSigma = unify.unify(theta1, t);
//PL 18-04-05 Unifier durch Matcher ersetzt ANFANG
ArrayList<UnifyPair> termList= new ArrayList<UnifyPair>();
termList.add(new UnifyPair(theta1,t, PairOperator.EQUALSDOT));
Optional<Unifier> optSigma = match.match(termList);
//PL 18-04-05 Unifier durch Matcher ersetzt ENDE
if(!optSigma.isPresent())
continue;

View File

@ -97,9 +97,9 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
.collect(Collectors.toCollection(HashSet::new));
//System.out.println(left.toString());
//Fall 2 und 3
if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
System.out.print("");
}
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
// System.out.print("");
//}
if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
return 1;
}

View File

@ -134,6 +134,10 @@ public class UnifyPair {
return ret;
}
public Boolean doubleExtended() {
return lhs.doubleExtended() || rhs.doubleExtended();
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof UnifyPair))

View File

@ -103,6 +103,10 @@ public abstract class UnifyType {
return ret;
}
public Boolean doubleExtended() {//default
return false;
}
@Override
public int hashCode() {
return this.toString().hashCode();

View File

@ -40,6 +40,11 @@ public abstract class WildcardType extends UnifyType {
return wildcardedType.getTypeParams();
}
@Override
public Boolean doubleExtended () {//This is an error
return (wildcardedType instanceof WildcardType);
}
@Override
public int hashCode() {
return wildcardedType.hashCode() + getName().hashCode() + 17;