diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 4710a02e..4d4a2af2 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -562,11 +562,11 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); try { - Writer logFile = new OutputStreamWriter(new NullOutputStream()); + Writer logFile = //new OutputStreamWriter(new NullOutputStream()); // new FileWriter(new // File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); - //new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" - // + sourceFiles.keySet().iterator().next().getName())); + new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" + + sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index fbccd8b8..8159f181 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -26,6 +26,6 @@ public class Constraint extends HashSet { } public String toString() { - return super.toString() + " isInherited = " + isInherited; + return super.toString() + " isInherited = " + isInherited + "\n"; } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 364077f2..221d1016 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -169,14 +169,15 @@ public class TYPEStmt implements StatementVisitor{ for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){ GenericsResolver resolver = getResolverInstance(); methodConstraints.add(generateConstraint(methodCall, m, info, resolver)); + /* geloescht PL 2020-05-01 resolver = getResolverInstance(); Constraint oneMethodConstraint = generateConstraint(methodCall, m, info, resolver); oneMethodConstraint = oneMethodConstraint.stream().map(x -> (x.TA1 instanceof TypePlaceholder && x.GetOperator() == PairOperator.EQUALSDOT && !(x.TA2 instanceof TypePlaceholder)) ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) : - x).collect(Collectors.toCollection(Constraint::new)); - oneMethodConstraint.setIsInherited(m.isInherited()); + x).collect(Collectors.toCollection(() -> new Constraint(true))); methodConstraints.add(oneMethodConstraint); + */ } if(methodConstraints.size()<1){ throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset()); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index c7c6c6cc..98d59b54 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -681,14 +681,6 @@ public class RuleSet implements IRuleSet{ Function,? extends Constraint> applyUni = b -> b.stream().map( x -> uni.apply(pair,x)).collect(Collectors.toCollection(() -> new Constraint(b.isInherited()))); - List>> oderConstraintsRet = new ArrayList<>(); - for(Set> oc : oderConstraints) { - //Set> ocRet = new HashSet<>(); - //for(Set cs : oc) { - Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)); - oderConstraintsRet.add(csRet); - //} - } oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); /* oderConstraints = oderConstraints.stream().map( diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 19a6c48b..63a68773 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -34,6 +34,7 @@ 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.FunNType; +import de.dhbwstuttgart.typeinference.unify.model.OrderingExtend; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.ReferenceType; @@ -105,7 +106,7 @@ public class TypeUnifyTask extends RecursiveTask>> { protected IFiniteClosure fc; - protected Ordering> oup; + protected OrderingExtend> oup; protected boolean parallel; @@ -173,9 +174,9 @@ public class TypeUnifyTask extends RecursiveTask>> { thNo = totalnoOfThread; writeLog("thNo2 " + thNo); try { - this.logFile = new OutputStreamWriter(new NullOutputStream()); + this.logFile = //new OutputStreamWriter(new NullOutputStream()); //new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo)); - //new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo)); + new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo)); logFile.write(""); } catch (IOException e) { @@ -630,6 +631,7 @@ public class TypeUnifyTask extends RecursiveTask>> { oderConstraint = true; } + UnifyPair oderRec = null; if (oderConstraint) { if (printtag) System.out.println("nextSetasList " + nextSetasList); Optional optVariance = @@ -691,9 +693,11 @@ 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; List> nextSetasListRest = new ArrayList<>(); + List> nextSetasListOderConstraints = new ArrayList<>(); //List> nextSetasListRestMin = new ArrayList<>(); //List> nextSetasListRestOder = new ArrayList<>(); writeLog("qextSet: " + nextSet.toString()); @@ -701,6 +705,47 @@ public class TypeUnifyTask extends RecursiveTask>> { if (variance == 1) { a = oup.max(nextSetasList.iterator()); nextSetasList.remove(a); + if (oderConstraint && nextSetasListOderConstraints.isEmpty()) { + Set a_final = a; + Optional opt_a_rec = a + .stream() + .filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType && + ! (x.getRhsType() instanceof PlaceholderType) && + x.getPairOp() == PairOperator.EQUALSDOT).findAny(); + if (opt_a_rec.isPresent()) { + a_rec = opt_a_rec.get(); + PlaceholderType phd; + if ((phd = ((PlaceholderType)a_rec.getGroundBasePair().getLhsType())).isWildcardable()) { + Set a_super = a.stream() + .map(x -> new UnifyPair(x.getLhsType(), x.getRhsType(), x.getPairOp())) + .collect(Collectors.toCollection(() -> new Constraint<>(((Constraint)a_final).isInherited()))); + a_super.remove(a_rec); + a_super.add(new UnifyPair(a_rec.getLhsType(), new SuperType(a_rec.getRhsType()), a_rec.getPairOp())); + Set a_extends = a.stream() + .map(x -> new UnifyPair(x.getLhsType(), x.getRhsType(), x.getPairOp())) + .collect(Collectors.toCollection(() -> new Constraint<>(((Constraint)a_final).isInherited()))); + a_extends.remove(a_rec); + a_extends.add(new UnifyPair(a_rec.getLhsType(), new ExtendsType(a_rec.getRhsType()), a_rec.getPairOp())); + if (phd.isInnerType()) { + nextSetasList.add(a_super); + nextSetasListOderConstraints.add(a_super); + nextSetasList.add(a); + nextSetasListOderConstraints.add(a); + a = a_extends; + } + else { + nextSetasList.add(a_extends); + nextSetasListOderConstraints.add(a_extends); + nextSetasList.add(a); + nextSetasListOderConstraints.add(a); + a = a_super; + } + } + } + } + else { + nextSetasListOderConstraints.remove(a); + } nextSetasListRest = new ArrayList<>(nextSetasList); Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); while (nextSetasListItRest.hasNext()) { @@ -1283,22 +1328,55 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("aParDef: " + aParDef.toString()); aParDef.add(a); Iterator> aParDefIt = aParDef.iterator(); - while(aParDefIt.hasNext()) { - Set a_new = aParDefIt.next(); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a_new.equals(a_next) || - ((oup.compare(a_new, a_next) == 1) && - (!oderConstraint || ((Constraint)a_next).isInherited()))) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); - } - else { - writeLog("Not Removed: " + a_next.toString()); - System.out.println(""); + if (oderConstraint) { + nextSetasList.removeAll(nextSetasListOderConstraints); + nextSetasListOderConstraints = new ArrayList<>(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + List> smallerSetasList = oup.smallerThan(a_new, nextSetasList); + List> notInherited = smallerSetasList.stream() + .filter(x -> !((Constraint)x).isInherited()) + .collect(Collectors.toCollection(ArrayList::new)); + List> notErased = new ArrayList<>(); + notInherited.stream().forEach(x -> { notErased.addAll(oup.smallerEqThan(x, smallerSetasList)); }); + List> erased = new ArrayList<>(smallerSetasList); + erased.removeAll(notErased); + nextSetasList.removeAll(erased); + + writeLog("Removed: " + erased); + + writeLog("Not Removed: " + nextSetasList); + } } - } + else { + while(aParDefIt.hasNext()) { + //nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28 + Set a_new = aParDefIt.next(); + List> erased = oup.smallerEqThan(a_new, nextSetasList); + + /* loeschen + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a_new.equals(a_next) || + ((oup.compare(a_new, a_next) == 1) && + (!oderConstraint || ((Constraint)a_next).isInherited()))) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); + } + else { + writeLog("Not Removed: " + a_next.toString()); + System.out.println(""); + } + } + Ende loeschen */ + nextSetasList.removeAll(erased); + + writeLog("Removed: " + erased); + + writeLog("Not Removed: " + nextSetasList); + } + } } else { if (variance == -1) { /* vorgezogen vor das if @@ -1332,8 +1410,32 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("aParDef: " + aParDef.toString()); aParDef.add(a); Iterator> aParDefIt = aParDef.iterator(); - while(aParDefIt.hasNext()) { - Set a_new = aParDefIt.next(); + if (oderConstraint) { + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + List> greaterSetasList = oup.greaterThan(a_new, nextSetasList); + 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)); }); + List> erased = new ArrayList<>(greaterSetasList); + erased.removeAll(notErased); + nextSetasList.removeAll(erased); + + writeLog("Removed: " + erased); + + writeLog("Not Removed: " + nextSetasList); + + } + } + else { + while(aParDefIt.hasNext()) { + //nextSetasListIt = nextSetasList.iterator(); Sollte eingefuegt werden PL 2020-04-28 + Set a_new = aParDefIt.next(); + List> erased = oup.greaterEqThan(a_new, nextSetasList); + + /* zu loeschen while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a_new.equals(a_next) || @@ -1345,16 +1447,28 @@ public class TypeUnifyTask extends RecursiveTask>> { else { System.out.println(""); writeLog("Not Removed: " + a_next.toString()); + } } + Ende zu loeschen */ + nextSetasList.removeAll(erased); + + writeLog("Removed: " + erased); + + writeLog("Not Removed: " + nextSetasList); + } } } - } else { if (variance == 0) { writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); if (!oderConstraint) { break; } - else {//TODO: Hier muessen alle kleineren und größeren Elemente von a geloescht werden + else { + nextSetasList = nextSetasList.stream() + .filter(x -> !((Constraint)x).isInherited()) + .collect(Collectors.toCollection(ArrayList::new)); + /* + //TODO: Hier muessen alle kleineren und größeren Elemente von a geloescht werden writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); writeLog("aParDef: " + aParDef.toString()); aParDef.add(a); @@ -1395,8 +1509,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } + */ } - + } else { if (variance == 2) { /* vorgezogen vor das if diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 9681f589..d139cb88 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -22,7 +22,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; -public class OrderingUnifyPair extends Ordering> { +public class OrderingUnifyPair extends OrderingExtend> { protected IFiniteClosure fc;