From b38340fc602f447de882d2e1e9497b01ce384273 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 9 Mar 2020 14:06:41 +0100 Subject: [PATCH] modified: ../../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java toString veraendert modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/Match.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Fall A <. theta' veraendert. modified: ../../bytecode/javFiles/MatrixOP.jav --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 9 +++--- .../constraints/ConstraintSet.java | 6 +++- .../typeinference/unify/Match.java | 1 + .../typeinference/unify/TypeUnifyTask.java | 30 +++++++++++++++---- .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 5f510946..4c065abb 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -480,15 +480,15 @@ 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); - + System.out.println("xxx1"); Function distributeInnerVars = x -> { UnifyType lhs, rhs; if (((lhs = x.getLhsType()) instanceof PlaceholderType) @@ -500,6 +500,7 @@ public class JavaTXCompiler { return x; }; + logFile.write("Unify:" + unifyCons.toString()); System.out.println("Unify:" + unifyCons.toString()); unifyCons = unifyCons.map(distributeInnerVars); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 1dda8dc5..bc0ad928 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import java.util.*; +import java.util.function.BinaryOperator; import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -29,7 +30,10 @@ public class ConstraintSet { @Override public String toString(){ - return cartesianProduct().toString(); + BinaryOperator b = (x,y) -> x+y; + return "\nUND:" + this.undConstraints.toString() + "\n" + + "ODER:" + this.oderConstraints.stream().reduce("", (x,y) -> x.toString()+ "\n" +y, b); + //cartesianProduct().toString(); } public Set>> cartesianProduct(){ diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java index 75469f64..91406612 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java @@ -22,6 +22,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType; public class Match implements IMatch { @Override + //vorne muss das Pattern stehen //A =. A ==> True //A =. A ==> False public Optional match(ArrayList termsList) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 74c71706..0362a5a0 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -28,6 +28,7 @@ import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; @@ -172,9 +173,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) { @@ -2033,6 +2034,14 @@ public class TypeUnifyTask extends RecursiveTask>> { PlaceholderType a = (PlaceholderType)pair.getLhsType(); UnifyType thetaPrime = pair.getRhsType(); + if (thetaPrime instanceof ExtendsType) { + thetaPrime = ((ExtendsType)thetaPrime).getExtendedType(); + } + + if (thetaPrime instanceof SuperType) { + //HIER MUSS NOCH WAS UEBERLEGT WERDEN + } + Set> result = new HashSet<>(); boolean allGen = thetaPrime.getTypeParams().size() > 0; @@ -2064,13 +2073,18 @@ public class TypeUnifyTask extends RecursiveTask>> { return x.accept(new freshPlaceholder(), hm); }).collect(Collectors.toCollection(HashSet::new)); - + IMatch match = new Match(); for(UnifyType c : csPHRenamed) { //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt. Set thetaQs = new HashSet<>(); //TODO smaller wieder reinnehmen? //thetaQs.add(c);// thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); + ArrayList ml = new ArrayList<>(); + ml.add(new UnifyPair(c, thetaPrime, PairOperator.EQUALSDOT)); + if (!(match.match(ml)).isPresent()) { + thetaQs.remove(c); + } //Set thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); //thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert, @@ -2078,7 +2092,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 18-02-06: eingefuegt, thetaQs der Form V> <. V'> werden entfernt //TODO PL 19-01-14 wieder reinnehmen kurzfristig auskommentiert - thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new)); + //thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new)); //PL 18-02-06: eingefuegt Set thetaQPrimes = new HashSet<>(); @@ -2095,7 +2109,7 @@ public class TypeUnifyTask extends RecursiveTask>> { thetaQPrimes.add(c.setTypeParams(tp)); } - for(UnifyType tqp : thetaQPrimes) { + for(UnifyType tqp : thetaQPrimes) {//PL 2020-03-08 umbauen in der Schleife wird nur unifizierbarer Typ gesucht break am Ende Collection tphs = tqp.getInvolvedPlaceholderTypes(); Optional opt = stdUnify.unify(tqp, thetaPrime); if (!opt.isPresent()) { @@ -2114,7 +2128,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { - Set smaller = fc.smaller(unifier.apply(tq), new HashSet<>()); + //geaendert PL 20-03-07 + Set smaller = new HashSet<>(); + smaller.add(unifier.apply(tq)); + //Set smaller = fc.smaller(unifier.apply(tq), new HashSet<>()); //eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen if (a.isWildcardable()) { Set smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) @@ -2161,6 +2178,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("MAX: " + oup.max(resultPrime.iterator()).toString()); } } + break;//Wenn ein unifier gefunden ist reicht es aus PL 2020-03-07 } } diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 21d37347..52c3fe96 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Byte; +import java.lang.Byte; import java.lang.Boolean; public class MatrixOP extends Vector> {