From 62d44eb15c25bd0f4b92219d7a6b51f84a3fc8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 24 Apr 2018 00:53:33 +0200 Subject: [PATCH] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Undefined Pairs auf oberster Ebene wird zu new HashTable<>() in compute new file: ../../src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Unterscheidung zw. <. { + //Hier muss ueberlegt werden, ob + //1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs + // mit disableWildcardtable() werden. + //2. alle Typvariablen mit Argument- oder Retuntyp-Variablen + //in Beziehung auch auf disableWildcardtable() gesetzt werden muessen + //PL 2018-04-23 if ((x.getLhsType() instanceof PlaceholderType)) { if (paraTypeVarNames.contains(x.getLhsType().getName())) { ((PlaceholderType)x.getLhsType()).setVariance((byte)1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } if (returnTypeVarNames.contains(x.getLhsType().getName())) { ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } } if ((x.getRhsType() instanceof PlaceholderType)) { if (paraTypeVarNames.contains(x.getRhsType().getName())) { ((PlaceholderType)x.getRhsType()).setVariance((byte)1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } if (returnTypeVarNames.contains(x.getRhsType().getName())) { ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } return x; diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index a9eb2dab..ff929fc0 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -135,7 +135,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } @Override protected Set> compute() { - return unify(eq, fc, parallel); + Set> res = unify(eq, fc, parallel); + if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } + else return res; } /** @@ -547,6 +549,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //.filter(y -> abhSubst.contains(y)) .collect(Collectors.toCollection(HashSet::new)); Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + int len = nextSetasList.size(); nextSetasList = nextSetasList.stream().filter(x -> { //Boolean ret = false; //for (PlaceholderType var : vars) { @@ -559,6 +562,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); System.out.println(""); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { @@ -959,15 +963,17 @@ public class TypeUnifyTask extends RecursiveTask>> { for (UnifyType tq : thetaQs) { Set smaller = fc.smaller(unifier.apply(tq)); //eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen - Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) - .map(x -> { - //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen - //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben - // .reduce(new HashMap(), - // (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); + if (a.isWildcardable()) { + Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) + .map(x -> { + //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben + // .reduce(new HashMap(), + // (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) { List freshTphs = new ArrayList<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java b/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java new file mode 100644 index 00000000..1b6a4d10 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java @@ -0,0 +1,18 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.HashMap; + +import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; + +public class inheritVariance extends visitUnifyTypeVisitor> { + + @Override + public PlaceholderType visit(PlaceholderType phty, HashMap ht) { + if (ht.containsKey(phty)) { + if (phty.getVariance() == 0) { + phty.setVariance(ht.get(phty)); + } + } + return phty; + } +} diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 1a4f72cd..09992791 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -53,7 +53,13 @@ public class OrderingUnifyPair extends Ordering> { */ public Pair> compare (UnifyType left, UnifyType right) { - UnifyPair up = new UnifyPair(left, right, PairOperator.SMALLERDOT); + UnifyPair up; + if (left instanceof WildcardType || right instanceof WildcardType) { + up = new UnifyPair(left, right, PairOperator.SMALLERDOTWC); + } + else { + up = new UnifyPair(left, right, PairOperator.SMALLERDOT); + } TypeUnifyTask unifyTask = new TypeUnifyTask(); HashSet hs = new HashSet<>(); hs.add(up); @@ -61,7 +67,12 @@ public class OrderingUnifyPair extends Ordering> { long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof PlaceholderType)).count(); if (smallerLen == 0) return new Pair<>(-1, smallerRes); else { - up = new UnifyPair(right, left, PairOperator.SMALLERDOT); + if (left instanceof WildcardType || right instanceof WildcardType) { + up = new UnifyPair(right, left, PairOperator.SMALLERDOTWC); + } + else { + up = new UnifyPair(right, left, PairOperator.SMALLERDOT); + } //TypeUnifyTask unifyTask = new TypeUnifyTask(); hs = new HashSet<>(); hs.add(up); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 8d9b62df..fe7758be 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -38,6 +38,12 @@ public final class PlaceholderType extends UnifyType{ */ private final boolean IsGenerated; + + /** + * isWildcardable gibt an, ob ein Wildcardtyp dem PlaceholderType zugeordnet werden darf + */ + private boolean wildcardable = true; + /** * variance shows the variance of the pair * -1: contravariant @@ -98,6 +104,13 @@ public final class PlaceholderType extends UnifyType{ return variance; } + public Boolean isWildcardable() { + return wildcardable; + } + public void disableWildcardtable() { + wildcardable = false; + } + @Override Set smArg(IFiniteClosure fc) { return fc.smArg(this);