From fd3d4e97a1f23bf95fcffcb346ab13b66be28109 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 5 May 2020 17:14:52 +0200 Subject: [PATCH] =?UTF-8?q?=09modified:=20=20=20../../../../main/java/de/d?= =?UTF-8?q?hbwstuttgart/typeinference/typeAlgo/TYPEStmt.java=20isInherited?= =?UTF-8?q?=20f=C3=BCr=20=3F=20extends=20wieder=20mit=20gleich=20gesetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Variance = -1 und Oderconstraints Vererbung eingebaut Variance = 0 min/max eingebaut --- .../typeinference/typeAlgo/TYPEStmt.java | 2 +- .../typeinference/unify/TypeUnifyTask.java | 68 +++++++++++++++---- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 870a5d3bc..613b1c261 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -183,7 +183,7 @@ public class TYPEStmt implements StatementVisitor{ !(x.TA2 instanceof TypePlaceholder)) ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) : x) - .collect(Collectors.toCollection(() -> new Constraint(true))); + .collect(Collectors.toCollection(() -> new Constraint(oneMethodConstraint.isInherited()))); oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 02e2ed2a9..cc0fcbf19 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -633,8 +633,7 @@ public class TypeUnifyTask extends RecursiveTask>> { oderConstraint = true; } - UnifyPair oderRec = null; - if (oderConstraint) { + if (oderConstraint) {//Varianz-Bestimmung Oder-Constraints if (printtag) System.out.println("nextSetasList " + nextSetasList); Optional optVariance = nextSetasList.iterator() @@ -662,9 +661,10 @@ public class TypeUnifyTask extends RecursiveTask>> { /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ Set sameEqSet = new HashSet<>(); + Optional optOrigPair = null; //if (variance != 2) { if (!oderConstraint) { - Optional optOrigPair = nextSetElem.stream().filter(x -> ( + optOrigPair = nextSetElem.stream().filter(x -> ( //x.getBasePair() != null && ist gegeben wenn variance != 2 //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && (x.getPairOp().equals(PairOperator.EQUALSDOT) @@ -695,13 +695,16 @@ public class TypeUnifyTask extends RecursiveTask>> { /* sameEqSet-Bestimmung Ende */ Set a = null; - UnifyPair a_rec = null; while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a_last = a; + + //Liste der Faelle für die parallele Verarbeitung List> nextSetasListRest = new ArrayList<>(); + + //Liste der Faelle, bei dem Receiver jeweils "? extends" enthaelt bzw. nicht enthaelt + //In der Regel ein Element List> nextSetasListOderConstraints = new ArrayList<>(); - //List> nextSetasListRestMin = new ArrayList<>(); - //List> nextSetasListRestOder = new ArrayList<>(); + writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); if (variance == 1) { @@ -710,7 +713,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (oderConstraint) { nextSetasListOderConstraints.add(((Constraint)a).getExtendConstraint()); } - writeLog("nextSetasListOderConstraints: " + nextSetasListOderConstraints); + writeLog("nextSetasListOderConstraints 1: " + nextSetasListOderConstraints); nextSetasListRest = new ArrayList<>(nextSetasList); Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); while (nextSetasListItRest.hasNext()) { @@ -741,6 +744,10 @@ public class TypeUnifyTask extends RecursiveTask>> { else if (variance == -1) { a = oup.min(nextSetasList.iterator()); writeLog("Min: a in " + variance + " "+ a); + if (oderConstraint) { + nextSetasListOderConstraints.add(((Constraint)a).getExtendConstraint()); + } + writeLog("nextSetasListOderConstraints -1: " + nextSetasListOderConstraints); nextSetasList.remove(a); nextSetasListRest = new ArrayList<>(nextSetasList); Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); @@ -774,7 +781,20 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasListRest = new ArrayList<>(nextSetasList); } else if (variance == 0) { - a = nextSetasList.remove(0); + //wenn a <. theta dann ist ein maximales Element sehr wahrscheinlich + //wenn theta <. a dann ist ein minimales Element sehr wahrscheinlich + if (!oderConstraint && optOrigPair != null && optOrigPair.isPresent()) { + if (optOrigPair.get().getBasePair().getLhsType() instanceof PlaceholderType) { + a = oup.max(nextSetasList.iterator()); + } + else { + a = oup.min(nextSetasList.iterator()); + } + nextSetasList.remove(a); + } + else { + a = nextSetasList.remove(0); + } } //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); //nextSetasList.remove(a); @@ -898,7 +918,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } } /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - + else { + nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); + } Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -1006,7 +1028,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } } /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - + else { + nextSetasListOderConstraints.add(((Constraint)nSaL).getExtendConstraint()); + } Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -1296,6 +1320,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (oderConstraint) { nextSetasList.removeAll(nextSetasListOderConstraints); nextSetasListOderConstraints = new ArrayList<>(); + writeLog("Removed: " + nextSetasListOderConstraints); while(aParDefIt.hasNext()) { Set a_new = aParDefIt.next(); List> smallerSetasList = oup.smallerThan(a_new, nextSetasList); @@ -1376,14 +1401,31 @@ public class TypeUnifyTask extends RecursiveTask>> { aParDef.add(a); Iterator> aParDefIt = aParDef.iterator(); if (oderConstraint) { + nextSetasList.removeAll(nextSetasListOderConstraints); + writeLog("Removed: " + nextSetasListOderConstraints); + nextSetasListOderConstraints = new ArrayList<>(); while(aParDefIt.hasNext()) { Set a_new = aParDefIt.next(); - List> greaterSetasList = oup.greaterThan(a_new, nextSetasList); + List> greaterSetasList = oup.greaterThan(a_new, nextSetasList); + + //a_new muss hingefuegt werden, wenn es nicht vererbt ist, dann wird es spaeter wieder geloescht + if (!((Constraint)a_new).isInherited()) { + greaterSetasList.add(a_new); + } List> notInherited = greaterSetasList.stream() .filter(x -> !((Constraint)x).isInherited()) .collect(Collectors.toCollection(ArrayList::new)); List> notErased = new ArrayList<>(); - notInherited.stream().forEach(x -> { notErased.addAll(oup.greaterThan(x, greaterSetasList)); }); + + //Wenn x nicht vererbt ist, beginnt beim naechstgroesseren Element die naechste Ueberladung + notInherited.stream().forEach(x -> { notErased.addAll(oup.greaterEqThan(x, greaterSetasList)); }); + + //das kleineste Element ist das Element von dem a_new geerbt hat + //muss deshalb geloescht werden + Set min = oup.min(notErased.iterator()); + notErased.remove(min); + notErased.remove(((Constraint)min).getExtendConstraint()); + List> erased = new ArrayList<>(greaterSetasList); erased.removeAll(notErased); nextSetasList.removeAll(erased); @@ -1393,7 +1435,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Not Removed: " + nextSetasList); } - } + } else { while(aParDefIt.hasNext()) { //nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28