From e52181a0c7325fecf329a3c5c7e31f48f767be28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 4 Feb 2019 23:32:52 +0100 Subject: [PATCH 01/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../resources/bytecode/javFiles/Matrix.jav --- .../typeinference/unify/TypeUnify2Task.java | 7 +- .../typeinference/unify/TypeUnifyTask.java | 87 ++++++++++++------- .../resources/bytecode/javFiles/Matrix.jav | 2 +- 3 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 6916f6dc..cdc1e040 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -15,9 +15,14 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); this.setToFlatten = setToFlatten; + this.nextSetElement = nextSetElement; + } + + Set getNextSetElement() { + return nextSetElement; } @Override diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index eb81e200..1e762b8a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -59,6 +59,11 @@ public class TypeUnifyTask extends RecursiveTask>> { private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + /** + * Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde + */ + Set nextSetElement; + /** * Fuer die Threads */ @@ -142,6 +147,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.nextSetElement = nextSetElement; this.fc = fc; this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; @@ -918,15 +924,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("Vor unify2 Aufruf: " + elems.toString()); Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); + Set> aParDef = new HashSet<>(); if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -944,7 +951,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -960,24 +967,27 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } }; } } else { if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -995,7 +1005,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1011,12 +1021,15 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } }; } } else { @@ -1029,7 +1042,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1045,7 +1058,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1230,18 +1243,24 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == 1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); + 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)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); + } + else { + writeLog("Not Removed: " + a_next.toString()); + System.out.println(""); + } } - else { - writeLog("Not Removed: " + a_next.toString()); - System.out.println(""); - } - } + } } else { if (variance == -1) { /* vorgezogen vor das if @@ -1272,19 +1291,25 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == -1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); //PL geaendert 2019-01-09 - } - else { - System.out.println(""); - writeLog("Not Removed: " + a_next.toString()); + 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)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); //PL geaendert 2019-01-09 + } + else { + System.out.println(""); + writeLog("Not Removed: " + a_next.toString()); } } } + } else { if (variance == 0) { writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); break; } diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 29505161..9e87c1e6 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -import java.lang.Float; +//import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; From db91e737500bb400ec6d25d02d871a4a31128b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 6 Feb 2019 18:15:39 +0100 Subject: [PATCH 02/31] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java aParDef wird auch ausgewertet modified: src/test/resources/bytecode/javFiles/MatrixOP.jav --- .../typeinference/unify/TypeUnifyTask.java | 21 +++++++++++-------- .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1e762b8a..5a3d4862 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -692,15 +692,14 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst //eqPrimePrime Veraenderungen in subst repraesentieren. - try { + //try { if (isSolvedForm(eqPrime)) { - logFile.write("eqPrime:" + eqPrime.toString()+"\n"); - logFile.flush(); + writeLog("eqPrime:" + eqPrime.toString()+"\n"); } - } - catch (IOException e) { + //} + //catch (IOException e) { System.err.println("log-File nicht vorhanden"); - } + //} eqPrimePrimeSet.add(eqPrime); Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { Optional> res = new RuleSet().subst(x.stream().map(y -> { @@ -971,7 +970,9 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben + //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); @@ -1026,6 +1027,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); @@ -1209,7 +1212,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ - if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { + if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) { if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); @@ -1343,7 +1346,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ - if (isUndefinedPairSetSet(res)) { + if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) { int nofstred= 0; Set abhSubst = res.stream() .map(b -> diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 828a270b..c78c42c7 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> { From 396efb52de12c53413c7eb3bfccb138fbb051f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 15 Feb 2019 00:00:41 +0100 Subject: [PATCH 03/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java subst-Anwendung auf oderconstraints eingebaut --- .../typeinference/unify/RuleSet.java | 30 +++++++++++++++++-- .../typeinference/unify/TypeUnifyTask.java | 5 +++- .../unify/interfaces/IRuleSet.java | 8 +++++ .../resources/bytecode/javFiles/Matrix.jav | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index a8c0675d..bd35376d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -4,10 +4,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.Stack; +import java.util.function.Function; import java.util.stream.Collectors; import de.dhbwstuttgart.exceptions.DebugException; @@ -619,8 +621,12 @@ public class RuleSet implements IRuleSet{ return succ ? permutation : new int[0]; } - @Override public Optional> subst(Set pairs) { + return subst(pairs, new ArrayList<>()); + } + + @Override + public Optional> subst(Set pairs, List>> oderConstraints) { HashMap typeMap = new HashMap<>(); Stack occuringTypes = new Stack<>(); @@ -664,9 +670,29 @@ public class RuleSet implements IRuleSet{ Unifier uni = new Unifier(lhsType, rhsType); result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); + + Function,? extends HashSet> applyUni = b -> b.stream().map( + x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new)); + 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( + a -> a.stream().map(applyUni + //b -> b.stream().map( + // x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new) ) + ).collect(Collectors.toCollection(HashSet::new)) + ).collect(Collectors.toList(ArrayList::new)); + } + */ applied = true; } - result.add(pair); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 5a3d4862..59dd208a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -656,9 +656,12 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 5: Substitution */ //writeLog("vor Subst: " + eqPrime); - Optional> eqPrimePrime = rules.subst(eqPrime); + writeLog("vor Subst: " + oderConstraints); + String ocString = oderConstraints.toString(); + Optional> eqPrimePrime = rules.subst(eqPrime, oderConstraints); Set> unifyres1 = null; Set> unifyres2 = null; + if (!ocString.equals(oderConstraints.toString())) writeLog("nach Subst: " + oderConstraints); //writeLog("nach Subst: " + eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java index a2b647c6..1ed46cb0 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.interfaces; +import java.util.List; import java.util.Optional; import java.util.Set; @@ -85,6 +86,13 @@ public interface IRuleSet { public Optional adaptExt(UnifyPair pair, IFiniteClosure fc); public Optional adaptSup(UnifyPair pair, IFiniteClosure fc); + /** + * Applies the subst-Rule to a set of pairs (usually Eq'). + * @param pairs The set of pairs where the subst rule should apply. + * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. + */ + public Optional> subst(Set pairs, List>> oderConstraints); + /** * Applies the subst-Rule to a set of pairs (usually Eq'). * @param pairs The set of pairs where the subst rule should apply. diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 9e87c1e6..29505161 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Float; +import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; From 08d69ce6e385d3ec707e279a7b170dc946b52536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 17 Feb 2019 08:51:23 +0100 Subject: [PATCH 04/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java zurueckumwandlung von den Unifytypen in UnifyResultModel verlegt. --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 13 ++-- .../typeinference/unify/TypeUnify.java | 59 +++++++++++++--- .../typeinference/unify/TypeUnify2Task.java | 4 +- .../typeinference/unify/TypeUnifyTask.java | 68 ++++++++++++------- .../typeinference/unify/UnifyResultModel.java | 33 ++++++++- .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 6 files changed, 136 insertions(+), 43 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 2c19d8b3..1dfa1163 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -284,12 +284,13 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); - UnifyResultModel urm = new UnifyResultModel(); + UnifyResultModel urm = null; try { FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); + urm = new UnifyResultModel(cons, finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); Function distributeInnerVars = @@ -401,7 +402,7 @@ public class JavaTXCompiler { } return ret; }).collect(Collectors.toCollection(ArrayList::new)); - unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm); } catch (IOException e) { System.err.println("kein LogFile"); @@ -538,10 +539,10 @@ public class JavaTXCompiler { }).collect(Collectors.toCollection(ArrayList::new)); if (resultmodel) { /* UnifyResultModel Anfang */ - UnifyResultModel urm = new UnifyResultModel(); + UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure); UnifyResultListenerImpl li = new UnifyResultListenerImpl(); urm.addUnifyResultListener(li); - unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm); System.out.println("RESULT Final: " + li.getResults()); logFile.write("RES_FINAL: " + li.getResults().toString()+"\n"); logFile.flush(); @@ -549,8 +550,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index d1fc2afe..75012b64 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -13,23 +13,56 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, new UnifyResultModel(), cons); + + /** + * unify parallel ohne result modell + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @return + */ + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + /** + * unify asynchron mit Rückgabe UnifyResultModel ohne dass alle results gesammelt sind + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @param ret + * @return + */ + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); return ret; } - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + /** + * unify parallel mit Rückgabe UnifyResultModel nachdem alle results gesammelt sind + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @param ret + * @return + */ + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -44,8 +77,18 @@ public class TypeUnify { } */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, new UnifyResultModel(), cons); + /** + * unify sequentiell mit oderconstraints + * @param undConstrains + * @param oderConstraints + * @param fc + * @param logFile + * @param log + * @param cons + * @return + */ + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret); Set> res = unifyTask.compute(); return res; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index cdc1e040..0ed9fb5c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -15,8 +15,8 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 59dd208a..1f5dec47 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -68,7 +68,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Fuer die Threads */ UnifyResultModel urm; - ConstraintSet cons; + //ConstraintSet cons; protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; @@ -133,7 +133,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons2) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { synchronized (this) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); @@ -153,16 +153,21 @@ public class TypeUnifyTask extends RecursiveTask>> { this.parallel = parallel; this.logFile = logFile; this.log = log; + + noOfThread++; + totalnoOfThread++; + //writeLog("thNo1 " + thNo); + thNo = totalnoOfThread; + writeLog("thNo2 " + thNo); + try { + this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo)); + } + catch (IOException e) { + System.err.println("log-File nicht vorhanden"); + } rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; this.urm = urm; - this.cons = cons2; - - noOfThread++; - totalnoOfThread++; - writeLog("thNo1 " + thNo); - thNo = totalnoOfThread; - writeLog("thNo2 " + thNo); } } @@ -658,10 +663,11 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("vor Subst: " + eqPrime); writeLog("vor Subst: " + oderConstraints); String ocString = oderConstraints.toString(); - Optional> eqPrimePrime = rules.subst(eqPrime, oderConstraints); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + Optional> eqPrimePrime = rules.subst(eqPrime, newOderConstraints); Set> unifyres1 = null; Set> unifyres2 = null; - if (!ocString.equals(oderConstraints.toString())) writeLog("nach Subst: " + oderConstraints); + if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints); //writeLog("nach Subst: " + eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied @@ -714,16 +720,17 @@ public class TypeUnifyTask extends RecursiveTask>> { } else return x; //wenn nichts veraendert wurde wird x zurueckgegeben }).collect(Collectors.toCollection(HashSet::new)); - urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); + urm.notify(eqPrimePrimeSetRet); + //urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> + // new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), oderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unifyres2 = unify(eqPrime, oderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); @@ -935,7 +942,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -953,7 +960,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm); forks.add(fork); fork.fork(); } @@ -961,6 +968,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); @@ -969,6 +978,7 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ + forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -981,7 +991,8 @@ public class TypeUnifyTask extends RecursiveTask>> { aParDef.add(fork.getNextSetElement()); } }; - } + } + noOfThread++; } else { if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { Set forks = new HashSet<>(); @@ -991,7 +1002,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1009,7 +1020,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm); forks.add(fork); fork.fork(); } @@ -1017,6 +1028,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); @@ -1025,6 +1038,7 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ + forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -1038,6 +1052,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } }; } + noOfThread++; } else { if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { writeLog("var2einstieg"); @@ -1048,7 +1063,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1064,7 +1079,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm); forks.add(fork); fork.fork(); } @@ -1072,6 +1087,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /* FORK ANFANG */ synchronized (this) { + noOfThread--; + writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); @@ -1079,7 +1096,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //add_res.add(fork_res); //vermutlich falsch }; /* FORK ENDE */ - + forks.forEach(x -> writeLog("wait: " + x.thNo)); for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -1087,8 +1104,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; - }} - else { + } + noOfThread++; + } else { //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index fe72bfea..7a4f0ccf 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -1,13 +1,31 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class UnifyResultModel { + ConstraintSet cons; + + IFiniteClosure fc; + + public UnifyResultModel(ConstraintSet cons, + IFiniteClosure fc) { + this.cons = cons; + this.fc = fc; + } + private List listeners = new ArrayList<>(); public void addUnifyResultListener(UnifyResultListener listenerToAdd) { @@ -18,7 +36,20 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(List newResult) { + public void notify(Set> eqPrimePrimeSet) { + Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + List newResult = eqPrimePrimeSetRet.stream().map(unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons)))) + .collect(Collectors.toList()); UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index c78c42c7..828a270b 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> { From 1f12aaec8213e48f099450fba0f57a812d9b88b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 18 Feb 2019 22:36:06 +0100 Subject: [PATCH 05/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Einen Fall ? extends/super a <.? a ergaenzt bei dem compare falsches Ergbnis geliefret hat --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +-- .../typeinference/unify/RuleSet.java | 8 +++- .../typeinference/unify/TypeUnifyTask.java | 18 ++------ .../unify/model/FiniteClosure.java | 19 +++++++-- .../unify/model/OrderingUnifyPair.java | 42 ++++++++++++++++++- 5 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 1dfa1163..bc2265bf 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -51,7 +51,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = true; + Boolean resultmodel = false; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -550,8 +550,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index bd35376d..2e77b787 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -666,7 +666,9 @@ public class RuleSet implements IRuleSet{ if(lhsType != null //&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden. && typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair. - && !rhsType.getTypeParams().occurs(lhsType)) { + && !rhsType.getTypeParams().occurs(lhsType) + && !((rhsType instanceof WildcardType) && ((WildcardType)rhsType).getWildcardedType().equals(lhsType))) //PL eigefuegt 2018-02-18 + { Unifier uni = new Unifier(lhsType, rhsType); result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); @@ -971,6 +973,8 @@ public class RuleSet implements IRuleSet{ UnifyType extendedType = ((ExtendsType)lhsType).getExtendedType(); + if (extendedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? extends a <.? a + boolean isGen = extendedType instanceof PlaceholderType && !((PlaceholderType) extendedType).isGenerated(); Set result = new HashSet<>(); @@ -997,6 +1001,8 @@ public class RuleSet implements IRuleSet{ UnifyType superedType = ((SuperType)lhsType).getSuperedType(); + if (superedType.equals(rhsType)) return Optional.empty(); //PL 2019-02-18 eingefügt ? super a <.? a + boolean isGen = superedType instanceof PlaceholderType && !((PlaceholderType) superedType).isGenerated(); Set result = new HashSet<>(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1f5dec47..d726544e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -68,7 +68,6 @@ public class TypeUnifyTask extends RecursiveTask>> { * Fuer die Threads */ UnifyResultModel urm; - //ConstraintSet cons; protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; @@ -553,6 +552,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Add the set of [a =. Theta | (a=. Theta) in Eq2'] + //TODO: Occurscheck anwenden als Fehler identifizieren Set bufferSet = eq2s.stream() .filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType) .collect(Collectors.toSet()); @@ -707,22 +707,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } //} //catch (IOException e) { - System.err.println("log-File nicht vorhanden"); + // System.err.println("log-File nicht vorhanden"); //} eqPrimePrimeSet.add(eqPrime); - Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { - Optional> res = new RuleSet().subst(x.stream().map(y -> { - if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); - return y; //alle Paare a <.? b erden durch a =. b ersetzt - }).collect(Collectors.toCollection(HashSet::new))); - if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert - return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc); - } - else return x; //wenn nichts veraendert wurde wird x zurueckgegeben - }).collect(Collectors.toCollection(HashSet::new)); - urm.notify(eqPrimePrimeSetRet); - //urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> - // new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); + urm.notify(eqPrimePrimeSet); } else if(eqPrimePrime.isPresent()) { Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index c52f47a7..d0497823 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; import java.util.function.BinaryOperator; +import java.util.function.Predicate; import java.util.stream.Collectors; import com.google.common.collect.Ordering; @@ -656,11 +657,16 @@ implements IFiniteClosure { if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) System.out.println(""); /* + pairop = PairOperator.SMALLERDOTWC; List al = new ArrayList<>(); PlaceholderType xx =new PlaceholderType("xx"); al.add(xx); left = new ExtendsType(new ReferenceType("Vector", new TypeParams(al))); - right = new ReferenceType("Vector", new TypeParams(new ArrayList<>(al))); + + List alr = new ArrayList<>(); + UnifyType exx = new ExtendsType(xx); + alr.add(exx); + right = new ExtendsType(new ReferenceType("Vector", new TypeParams(alr))); */ /* List al = new ArrayList<>(); @@ -711,8 +717,13 @@ implements IFiniteClosure { } catch (IOException e) { System.err.println("no LogFile");}} - //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. - long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); + //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. + Predicate delFun = x -> !((x.getLhsType() instanceof PlaceholderType || + x.getRhsType() instanceof PlaceholderType) + && !((x.getLhsType() instanceof WildcardType) && //? extends/super a <.? a + ((WildcardType)x.getLhsType()).getWildcardedType().equals(x.getRhsType())) + ); + long smallerLen = smallerRes.stream().filter(delFun).count(); if (smallerLen == 0) return -1; else { up = new UnifyPair(right, left, pairop); @@ -728,7 +739,7 @@ implements IFiniteClosure { catch (IOException e) { System.err.println("no LogFile");}} //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. - long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); + long greaterLen = greaterRes.stream().filter(delFun).count(); if (greaterLen == 0) return 1; else return 0; } 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 490826cc..28da9a80 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.function.BinaryOperator; @@ -115,6 +116,43 @@ public class OrderingUnifyPair extends Ordering> { * @see com.google.common.collect.Ordering#compare(java.lang.Object, java.lang.Object) */ public int compare (Set left, Set right) { + /* + //pairop = PairOperator.SMALLERDOTWC; + List al = new ArrayList<>(); + PlaceholderType xx = PlaceholderType.freshPlaceholder(); + al.add(xx); + UnifyType t1 = new ExtendsType(new ReferenceType("Vector", new TypeParams(al))); + + //PlaceholderType yy =new PlaceholderType("yy"); + List alr = new ArrayList<>(); + UnifyType exx = new ExtendsType(xx); + alr.add(exx); + UnifyType t2 = new ExtendsType(new ReferenceType("Vector", new TypeParams(alr))); + + PlaceholderType a = PlaceholderType.freshPlaceholder(); + a.setInnerType(true); + UnifyPair p1 = new UnifyPair(a, t1, PairOperator.SMALLERDOTWC); + PlaceholderType b = PlaceholderType.freshPlaceholder(); + b.setInnerType(true); + UnifyPair p2 = new UnifyPair(b, t2, PairOperator.SMALLERDOTWC); + + List al3 = new ArrayList<>(); + al3.add(a); + + List al4 = new ArrayList<>(); + al4.add(b); + + UnifyPair p3 = new UnifyPair(new PlaceholderType("c"), new ReferenceType("Vector", new TypeParams(al3)), PairOperator.EQUALSDOT); + UnifyPair p4 = new UnifyPair(new PlaceholderType("c"), new ReferenceType("Vector", new TypeParams(al4)), PairOperator.EQUALSDOT); + + right = new HashSet<>(); + right.add(p1); + right.add(p3); + left = new HashSet<>(); + left.add(p2); + left.add(p4); + */ + if ((left.size() == 1) && right.size() == 1) { if (left.iterator().next().getLhsType().getName().equals("AFS")) { System.out.println(""); @@ -198,9 +236,9 @@ public class OrderingUnifyPair extends Ordering> { //Set varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); //Set varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); //filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant) andere Substitutioen werden rausgefiltert - lefteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + lefteq.removeIf(x -> (x.getBasePair()!=null) && !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//removeIf(x -> !varsright.contains(x.getLhsType())); - righteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + righteq.removeIf(x -> (x.getBasePair()!=null) && !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//.removeIf(x -> !varsleft.contains(x.getLhsType())); UnifyPair lseq = lefteq.iterator().next(); UnifyPair rseq = righteq.iterator().next(); From 362e797b100f30541090dcff55aae6a2df32bdfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 19 Feb 2019 17:51:11 +0100 Subject: [PATCH 06/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +++--- .../de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index bc2265bf..1dfa1163 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -51,7 +51,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = false; + Boolean resultmodel = true; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -550,8 +550,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d726544e..3feed6cc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -959,6 +959,7 @@ public class TypeUnifyTask extends RecursiveTask>> { noOfThread--; writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); + forkOrig.writeLog("final Orig 1"); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -978,6 +979,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); } + fork.writeLog("final 1"); }; } noOfThread++; @@ -1019,6 +1021,7 @@ public class TypeUnifyTask extends RecursiveTask>> { noOfThread--; writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); + forkOrig.writeLog("final Orig -1"); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1038,6 +1041,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (!isUndefinedPairSetSet(fork_res)) { aParDef.add(fork.getNextSetElement()); } + fork.writeLog("final -1"); }; } noOfThread++; @@ -1078,6 +1082,7 @@ public class TypeUnifyTask extends RecursiveTask>> { noOfThread--; writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); + forkOrig.writeLog("final Orig 2"); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1091,6 +1096,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); + fork.writeLog("final 2"); }; } noOfThread++; From 72705ac8689aa3d283d170e673ca6663b9676ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Feb 2019 09:40:06 +0100 Subject: [PATCH 07/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java close log-Files TypeUnifyTask in TypeUnify2Task bei Abarbeitung oderconstraints umgetauscht --- .../typeinference/unify/TypeUnify2Task.java | 14 +++++++++++++- .../typeinference/unify/TypeUnifyTask.java | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 0ed9fb5c..43b294ad 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -37,6 +38,17 @@ public class TypeUnify2Task extends TypeUnifyTask { else */ noOfThread--; - return res; + return res; + } + + public void closeLogFile() { + + try { + logFile.close(); + } + catch (IOException ioE) { + System.err.println("no log-File" + thNo); + } + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 3feed6cc..c9dcbcaa 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -218,6 +218,12 @@ public class TypeUnifyTask extends RecursiveTask>> { .collect(Collectors.toCollection(ArrayList::new)); Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); noOfThread--; + try { + logFile.close(); + } + catch (IOException ioE) { + System.err.println("no log-File"); + } if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } @@ -960,6 +966,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); forkOrig.writeLog("final Orig 1"); + forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -980,6 +987,7 @@ public class TypeUnifyTask extends RecursiveTask>> { aParDef.add(fork.getNextSetElement()); } fork.writeLog("final 1"); + fork.closeLogFile(); }; } noOfThread++; @@ -1022,6 +1030,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); forkOrig.writeLog("final Orig -1"); + forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1042,13 +1051,14 @@ public class TypeUnifyTask extends RecursiveTask>> { aParDef.add(fork.getNextSetElement()); } fork.writeLog("final -1"); + fork.closeLogFile(); }; } noOfThread++; } else { if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { writeLog("var2einstieg"); - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); @@ -1083,6 +1093,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); res = forkOrig.join(); forkOrig.writeLog("final Orig 2"); + forkOrig.closeLogFile(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1090,13 +1101,14 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ forks.forEach(x -> writeLog("wait: " + x.thNo)); - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); fork.writeLog("final 2"); + fork.closeLogFile(); }; } noOfThread++; From 926d911d21e0f486ccfa02f2e839ec10b7263f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Feb 2019 15:08:06 +0100 Subject: [PATCH 08/31] modified: ../bytecode/MatrixTest.java --- src/test/java/bytecode/MatrixTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/test/java/bytecode/MatrixTest.java diff --git a/src/test/java/bytecode/MatrixTest.java b/src/test/java/bytecode/MatrixTest.java old mode 100644 new mode 100755 From 9c648546e417a64f392938fb430be6a7554dc6a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Feb 2019 17:36:07 +0100 Subject: [PATCH 09/31] modified: de/dhbwstuttgart/core/JavaTXCompiler.java modified: de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java modified: de/dhbwstuttgart/typeinference/unify/RuleSet.java modified: de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java FileWriter durch Writer ersetzt --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 5 +++-- .../syntaxtree/factory/UnifyTypeFactory.java | 3 ++- .../de/dhbwstuttgart/typeinference/unify/RuleSet.java | 5 +++-- .../de/dhbwstuttgart/typeinference/unify/TypeUnify.java | 9 +++++---- .../typeinference/unify/TypeUnify2Task.java | 3 ++- .../dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 1dfa1163..0be50fb5 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -41,6 +41,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -286,7 +287,7 @@ public class JavaTXCompiler { Set> results = new HashSet<>(); UnifyResultModel urm = null; try { - FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + Writer logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); @@ -422,7 +423,7 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); try { - FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + Writer logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index f3fbdd63..a764db6e 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree.factory; import java.io.FileWriter; +import java.io.Writer; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -30,7 +31,7 @@ public class UnifyTypeFactory { private static ArrayList PLACEHOLDERS = new ArrayList<>(); - public static FiniteClosure generateFC(List fromClasses, FileWriter logFile) throws ClassNotFoundException { + public static FiniteClosure generateFC(List fromClasses, Writer logFile) throws ClassNotFoundException { /* Die transitive Hülle muss funktionieren. Man darf schreiben List extends AL diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 2e77b787..da8998d2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.unify.distributeVariance; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; /** * Implementation of the type inference rules. @@ -38,13 +39,13 @@ import java.io.IOException; */ public class RuleSet implements IRuleSet{ - FileWriter logFile; + Writer logFile; public RuleSet() { super(); } - RuleSet(FileWriter logFile) { + RuleSet(Writer logFile) { this.logFile = logFile; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 75012b64..2cea2184 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.io.Writer; import java.util.List; import java.util.Set; import java.util.concurrent.ForkJoinPool; @@ -24,7 +25,7 @@ public class TypeUnify { * @param cons * @return */ - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); @@ -43,7 +44,7 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); @@ -61,7 +62,7 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); @@ -87,7 +88,7 @@ public class TypeUnify { * @param cons * @return */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) { + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret); Set> res = unifyTask.compute(); return res; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 43b294ad..31247aef 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -16,7 +17,7 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index c9dcbcaa..1d383c66 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -44,6 +44,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Pair; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import com.google.common.collect.Ordering; @@ -75,7 +76,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Integer MaxNoOfThreads = 8; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; - FileWriter logFile; + Writer logFile; /** * The implementation of setOps that will be used during the unification @@ -132,7 +133,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { synchronized (this) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); From fcad60996ccc99bc7b610243543bf06e9b257aa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Feb 2019 17:53:45 +0100 Subject: [PATCH 10/31] modified: de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java --- .../typeinference/unify/model/FiniteClosure.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index d0497823..6ce7b541 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -33,7 +34,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; public class FiniteClosure //extends Ordering //entfernt PL 2018-12-11 implements IFiniteClosure { - FileWriter logFile; + Writer logFile; static Boolean log = false; public void setLogTrue() { log = true; @@ -67,7 +68,7 @@ implements IFiniteClosure { /** * Creates a new instance using the inheritance tree defined in the pairs. */ - public FiniteClosure(Set pairs, FileWriter logFile) { + public FiniteClosure(Set pairs, Writer logFile) { this.logFile = logFile; this.pairs = new HashSet<>(pairs); inheritanceGraph = new HashMap>(); From 88ec8823fd41af604404159d8b88bab6d6202575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 27 Feb 2019 16:04:55 +0100 Subject: [PATCH 11/31] =?UTF-8?q?=09modified:=20=20=20../../../main/java/d?= =?UTF-8?q?e/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java?= =?UTF-8?q?=20=09modified:=20=20=20../../../main/java/de/dhbwstuttgart/syn?= =?UTF-8?q?taxtree/factory/UnifyTypeFactory.java=20=09deleted:=20=20=20=20?= =?UTF-8?q?../../../main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java?= =?UTF-8?q?=20=09modified:=20=20=20../../../main/java/de/dhbwstuttgart/typ?= =?UTF-8?q?einference/assumptions/FunNClass.java=20=09modified:=20=20=20..?= =?UTF-8?q?/../../main/java/de/dhbwstuttgart/typeinference/assumptions/Met?= =?UTF-8?q?hodAssumption.java=20=09modified:=20=20=20../../../main/java/de?= =?UTF-8?q?/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java=20=09modifi?= =?UTF-8?q?ed:=20=20=20../../../main/java/de/dhbwstuttgart/typeinference/u?= =?UTF-8?q?nify/model/FunNType.java=20Es=20wird=20jetzt=20FunN-Type=20FunN?= =?UTF-8?q?$$=20geparst=20Der=20Typ=20FunN=20wurde=20entfernt=20Der=20Name?= =?UTF-8?q?=20des=20Typs=20FunNType=20wurde=20um=20$$=20am=20Ende=20erg?= =?UTF-8?q?=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyntaxTreeGenerator/TypeGenerator.java | 11 ++++- .../syntaxtree/factory/UnifyTypeFactory.java | 15 +++---- .../dhbwstuttgart/syntaxtree/type/FunN.java | 41 ------------------- .../typeinference/assumptions/FunNClass.java | 2 +- .../assumptions/MethodAssumption.java | 4 +- .../typeinference/typeAlgo/TYPEStmt.java | 4 +- .../typeinference/unify/model/FunNType.java | 2 +- .../resources/bytecode/javFiles/MatrixOP.jav | 6 +-- .../resources/bytecode/javFiles/Sorting.jav | 6 +-- src/test/resources/javFiles/Faculty.jav | 9 ++-- src/test/resources/javFiles/mathStruc.jav | 17 +++----- 11 files changed, 39 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index ad07ca0f..ce85bf6d 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -18,6 +18,8 @@ import org.antlr.v4.runtime.Token; import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class TypeGenerator { @@ -139,12 +141,17 @@ public class TypeGenerator { public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName( String name, Java8Parser.TypeArgumentsContext typeArguments, Token offset, JavaClassRegistry reg, GenericsRegistry generics){ - if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein + if(!reg.contains(name)){ //Dann könnte es ein generischer Type oder ein FunN$$-Type sein if(generics.contains(name)){ return new GenericRefType(name, offset); }else{ + Pattern p = Pattern.compile("Fun(\\d+)[$][$]"); + Matcher m = p.matcher(name); + if (m.matches()) {//es ist FunN$$-Type + return new RefType(new JavaClassName(name), convert(typeArguments, reg, generics), offset); + } else { throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",offset); - } + }} } if(typeArguments == null){ List params = new ArrayList<>(); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index a764db6e..7166d0c4 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -68,9 +68,6 @@ public class UnifyTypeFactory { public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){ if(t instanceof GenericRefType){ return UnifyTypeFactory.convert((GenericRefType)t, innerType); - }else - if(t instanceof FunN){ - return UnifyTypeFactory.convert((FunN)t, innerType); }else if(t instanceof TypePlaceholder){ return UnifyTypeFactory.convert((TypePlaceholder)t, innerType); }else if(t instanceof ExtendsWildcardType){ @@ -86,13 +83,13 @@ public class UnifyTypeFactory { public static UnifyType convert(RefType t, Boolean innerType){ //Check if it is a FunN Type: - Pattern p = Pattern.compile("Fun(\\d+)"); + Pattern p = Pattern.compile("Fun(\\d+)[$][$]"); Matcher m = p.matcher(t.getName().toString()); boolean b = m.matches(); if(b){ Integer N = Integer.valueOf(m.group(1)); if((N + 1) == t.getParaList().size()){ - return convert(new FunN(t.getParaList()), false); + return convertFunN(t.getParaList(), false); } } UnifyType ret; @@ -108,11 +105,11 @@ public class UnifyTypeFactory { return ret; } - public static UnifyType convert(FunN t, Boolean innerType){ + public static UnifyType convertFunN(List paraList, Boolean innerType){ UnifyType ret; List params = new ArrayList<>(); - if(t.getParaList() != null && t.getParaList().size() > 0){ - for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ + if(paraList != null && paraList.size() > 0){ + for(RefTypeOrTPHOrWildcardOrGeneric pT : paraList){ params.add(UnifyTypeFactory.convert(pT, false)); } } @@ -236,7 +233,7 @@ public class UnifyTypeFactory { } public static RefTypeOrTPHOrWildcardOrGeneric convert(FunNType t, Map tphs) { - RefType ret = new RefType(new JavaClassName(t.getName()+"$$"), convert(t.getTypeParams(), tphs), new NullToken()); + RefType ret = new RefType(new JavaClassName(t.getName()), convert(t.getTypeParams(), tphs), new NullToken()); return ret; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java deleted file mode 100644 index dc521b87..00000000 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/FunN.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.type; - - -import de.dhbwstuttgart.parser.NullToken; -import de.dhbwstuttgart.parser.scope.JavaClassName; - -import java.util.List; - -/** - * @see Spezifikation "Complete Typeinference in Java 8" von Martin Plümicke - * "interface FunN { R apply(T1 arg1, T2 arg2, ... , TN argN); }" - * @author A10023 - Andreas Stadelmeier - * - * Bemerkung: - * FunN ist ein RefType. Der RefType ist nicht mit einem FunNInterface verbunden. - * - */ -public class FunN extends RefType { - /** - * @author Andreas Stadelmeier, a10023 - * Benötigt für den Typinferenzalgorithmus für Java 8 - * Generiert einen RefType auf eine FunN - Klasse. - * @param params - * @return - */ - public FunN(List params) { - super(new JavaClassName("Fun"+(params.size()-1)), params, new NullToken()); - } - - /** - * Spezieller Konstruktor um eine FunN ohne Returntype zu generieren - - protected FunN(List list){ - super("",0); - if(list==null)throw new NullPointerException(); - setT(list); - this.name = new JavaClassName("Fun"+list.size());//getName(); - } - */ - -} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java index 6067851e..d41baa06 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/FunNClass.java @@ -21,7 +21,7 @@ import java.util.Optional; public class FunNClass extends ClassOrInterface { public FunNClass(List funNParams) { - super(0, new JavaClassName("Fun"+(funNParams.size())), new ArrayList<>(), Optional.empty() /* eingefuegt PL 2018-11-24 */, + super(0, new JavaClassName("Fun"+(funNParams.size()-1)), new ArrayList<>(), Optional.empty() /* eingefuegt PL 2018-11-24 */, createMethods(funNParams), new ArrayList<>(), createGenerics(funNParams), ASTFactory.createObjectType(), true, new ArrayList<>(), new NullToken()); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index 3862d0eb..c1a6d449 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -1,10 +1,10 @@ package de.dhbwstuttgart.typeinference.assumptions; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.TypeScope; -import de.dhbwstuttgart.syntaxtree.type.FunN; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; @@ -63,7 +63,7 @@ public class MethodAssumption extends Assumption{ } RefTypeOrTPHOrWildcardOrGeneric receiverType; if(receiver instanceof FunNClass){ - receiverType = new FunN(params); + receiverType = new RefType(new JavaClassName(receiver.getClassName().toString()+"$$"), params, new NullToken()); // new FunN(params); }else{ receiverType = new RefType(receiver.getClassName(), params, new NullToken()); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 4fd14fbc..f1332cd4 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -65,7 +65,9 @@ public class TYPEStmt implements StatementVisitor{ //lambdaParams.add(0,tphRetType); constraintsSet.addUndConstraint( new Pair(lambdaExpression.getType(), - new FunN(lambdaParams),PairOperator.EQUALSDOT)); + new RefType(new JavaClassName("Fun"+(lambdaParams.size()-1)+"$$"), lambdaParams, new NullToken()), + //new FunN(lambdaParams), + PairOperator.EQUALSDOT)); constraintsSet.addUndConstraint( new Pair(lambdaExpression.getReturnType(), tphRetType,PairOperator.EQUALSDOT)); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index 3e9f2ae6..37cf6a0a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -22,7 +22,7 @@ public class FunNType extends UnifyType { * Creates a FunN-Type with the specified TypeParameters. */ protected FunNType(TypeParams p) { - super("Fun"+(p.size()-1), p); + super("Fun"+(p.size()-1)+"$$", p); } /** diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 828a270b..c439c3ca 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -3,7 +3,7 @@ import java.lang.Integer; //import java.lang.Byte; import java.lang.Boolean; -public class MatrixOP extends Vector> { +public class MatrixOP extends Vector> { MatrixOP () { } @@ -18,10 +18,10 @@ public class MatrixOP extends Vector> { } } - mul = (m1, m2) -> { + Fun2$$>, java.util.Vector>, MatrixOP> mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; - while(i < size()) { + while(i < m1.size()) { var v1 = m1.elementAt(i); var v2 = new Vector(); var j = 0; diff --git a/src/test/resources/bytecode/javFiles/Sorting.jav b/src/test/resources/bytecode/javFiles/Sorting.jav index 341a1a6b..486bfd71 100644 --- a/src/test/resources/bytecode/javFiles/Sorting.jav +++ b/src/test/resources/bytecode/javFiles/Sorting.jav @@ -14,10 +14,10 @@ sort(in){ return merge(sort(firstHalf), sort(secondHalf)); } */ -/* + - void sort(ArrayList a){ + void sort(a){ a = merge(a,a); } -*/ + } diff --git a/src/test/resources/javFiles/Faculty.jav b/src/test/resources/javFiles/Faculty.jav index 71f40515..ed201ff9 100644 --- a/src/test/resources/javFiles/Faculty.jav +++ b/src/test/resources/javFiles/Faculty.jav @@ -1,13 +1,14 @@ import java.lang.Integer; class Faculty { - - Integer mul(Integer x, Integer y) { + //fact; + + Integer mul(Integer x, Integer y) { return x; } - + m () { - var fact = (Integer x) -> { + var fact = (Integer x) -> { return mul(x, fact.apply(x)); }; return fact; diff --git a/src/test/resources/javFiles/mathStruc.jav b/src/test/resources/javFiles/mathStruc.jav index 93f901ce..c8518e5d 100644 --- a/src/test/resources/javFiles/mathStruc.jav +++ b/src/test/resources/javFiles/mathStruc.jav @@ -1,13 +1,8 @@ +class MathStruc { -class mathStruc { + A model; + + innerOp = o -> ms -> new MathStruc(o.apply(this.model, ms.model)); -mathStruc(A a) { } - -A model(){ A a; return a; } - -methode(){ -var innerOp = o -> ms -> - new mathStruc(o.apply(this.model(),ms.model())); - return innerOp; - } -} \ No newline at end of file + MathStruc(A m) { model=m; } + } \ No newline at end of file From b46e0b855c323b4e02e2b106a5247fe688078276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 28 Feb 2019 15:38:30 +0100 Subject: [PATCH 12/31] modified: ../../resources/bytecode/javFiles/MatrixOP.jav --- src/test/resources/bytecode/javFiles/MatrixOP.jav | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index c439c3ca..638cff35 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -18,7 +18,7 @@ public class MatrixOP extends Vector> { } } - Fun2$$>, java.util.Vector>, MatrixOP> mul = (m1, m2) -> { + mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; while(i < m1.size()) { From fc14cf98939b78e322464462ff00dbb748755a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 28 Feb 2019 18:29:08 +0100 Subject: [PATCH 13/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java subst-Anwendung gleich am Anfang von unify eingefuehrt --- .../java/de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +++--- .../typeinference/unify/TypeUnifyTask.java | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 0be50fb5..03567487 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -52,7 +52,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = true; + Boolean resultmodel = false; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -551,8 +551,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1d383c66..3ef3f8d4 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -529,8 +529,14 @@ public class TypeUnifyTask extends RecursiveTask>> { return ret; } - - Set eq0 = applyTypeUnificationRules(eq, fc); + Set eq0; + Set eq0Prime; + Optional> eqSubst = Optional.of(eq); + do { + eq0Prime = eqSubst.get(); + eq0 = applyTypeUnificationRules(eq0Prime, fc); + eqSubst = rules.subst(eq0, oderConstraints); + } while (eqSubst.isPresent()); /* * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs From 27c6351aedc34665592321f89f9d46dcc1c2d694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 1 Mar 2019 16:52:59 +0100 Subject: [PATCH 14/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Anfang Paare zusammenfassen --- .../typeinference/unify/TypeUnifyTask.java | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 3ef3f8d4..fb4e14da 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -583,7 +583,8 @@ public class TypeUnifyTask extends RecursiveTask>> { if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); - Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); + Set> collectErr = new HashSet<>(); + Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput, collectErr); //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer //nicht ausgewertet Faculty Beispiel im 1. Schritt //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren @@ -1727,7 +1728,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements * (as in case 1 where sigma is added to the innermost set). */ - protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput, Set> collectErr) { oderConstraintsOutput.addAll(oderConstraintsInput); List>>> result = new ArrayList<>(9); @@ -1811,6 +1812,42 @@ public class TypeUnifyTask extends RecursiveTask>> { x1.remove(remElem); } //System.out.println(x1); + Set sameEqSet = eq2sAsList.stream() + .filter(x -> ((x.getLhsType().equals(lhsType) || x.getRhsType().equals(lhsType)) && !x.equals(pair))) + .collect(Collectors.toCollection(HashSet::new)); + Set> x2 = x1; + for (UnifyPair sameEq : sameEqSet) { + writeLog("x1 Original:\n" + x1.toString()); + if (sameEq.getLhsType() instanceof PlaceholderType) { + x1 = x1.stream().filter(y -> { + UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp())); + Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); + Boolean localCorr = !isUndefinedPairSetSet(localRes); + if (!localCorr) { + collectErr.addAll(localRes); + } + return localCorr; + } + ).collect(Collectors.toCollection(HashSet::new)); + } + else { + x1 = x1.stream().filter(y -> { + UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp())); + Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); + Boolean localCorr = !isUndefinedPairSetSet(localRes); + if (!localCorr) { + collectErr.addAll(localRes); + } + return localCorr; + } + ).collect(Collectors.toCollection(HashSet::new)); + } + writeLog("x1 nach Lösung von " + sameEq.toString()+" :\n" + x1.toString()); + } result.get(0).add(x1); if (x1.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC => Abbruch @@ -1919,6 +1956,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Filter empty sets or sets that only contain an empty set. + writeLog("collectErr: " + collectErr); return result.stream().map(x -> x.stream().filter(y -> y.size() > 0).collect(Collectors.toCollection(HashSet::new))) .filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new)); } From 728b729f081690aa1c81b149e7332b9287a93b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 5 Mar 2019 00:24:11 +0100 Subject: [PATCH 15/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java in calculatePairSets werden andere Constraints fuer die gleiche Variable betrachtet Sollte aber nach computeCartesianRecursive verschoben werden. --- .../typeinference/unify/TypeUnifyTask.java | 55 ++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index fb4e14da..adc86d34 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -590,10 +590,14 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren //Typen getestet werden. writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); + writeLog(nOfUnify.toString() + " collectErr: " + collectErr.toString()); if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); // If pairs occured that did not match one of the cartesian product cases, // those pairs are contradictory and the unification is impossible. if(!undefinedPairs.isEmpty()) { + Set flatCollectErr = new HashSet<>(); + collectErr.forEach(x -> flatCollectErr.addAll(x)); + undefinedPairs.addAll(flatCollectErr); noUndefPair++; for (UnifyPair up : undefinedPairs) { writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); @@ -602,6 +606,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> error = new HashSet<>(); undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); error.add(undefinedPairs); + undefinedPairs.forEach(x -> writeLog("AllSubst: " +x.getAllSubstitutions().toString())); return error; } @@ -642,7 +647,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, collectErr); } @@ -764,7 +769,7 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set> collectErr) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -1208,7 +1213,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES Fst:" + result.toString() + " " + res.toString()); + writeLog("RES Fst:" + result.toString() + " " + res.toString() + " " + collectErr.toString()); + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen + result.addAll(collectErr); + } result.addAll(res); } } @@ -1239,6 +1247,9 @@ public class TypeUnifyTask extends RecursiveTask>> { || result.isEmpty()) { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen + result.addAll(collectErr); + } result.addAll(par_res); } } @@ -1787,7 +1798,11 @@ public class TypeUnifyTask extends RecursiveTask>> { Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution hinzufuegen */ + Set consideredElements = new HashSet<>(); for(UnifyPair pair : eq2sAsList) { + if (consideredElements.contains(pair)) { + continue; + } PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); UnifyType rhsType = pair.getRhsType(); @@ -1815,19 +1830,30 @@ public class TypeUnifyTask extends RecursiveTask>> { Set sameEqSet = eq2sAsList.stream() .filter(x -> ((x.getLhsType().equals(lhsType) || x.getRhsType().equals(lhsType)) && !x.equals(pair))) .collect(Collectors.toCollection(HashSet::new)); + consideredElements.addAll(sameEqSet); Set> x2 = x1; + Set> x1Res = new HashSet<>(); + writeLog("pair:\n" + pair.toString()); + writeLog("x1 Start:\n" + x1.toString()); + writeLog("sameEqSet:\n" + sameEqSet.toString()); for (UnifyPair sameEq : sameEqSet) { writeLog("x1 Original:\n" + x1.toString()); if (sameEq.getLhsType() instanceof PlaceholderType) { x1 = x1.stream().filter(y -> { UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); - localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp())); + Set unitedSubst = new HashSet<>(type.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); Boolean localCorr = !isUndefinedPairSetSet(localRes); if (!localCorr) { collectErr.addAll(localRes); } + else { + localRes.forEach(z -> z.addAll(y)); + x1Res.addAll(localRes); + } return localCorr; } ).collect(Collectors.toCollection(HashSet::new)); @@ -1836,20 +1862,33 @@ public class TypeUnifyTask extends RecursiveTask>> { x1 = x1.stream().filter(y -> { UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); - localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp())); + Set unitedSubst = new HashSet<>(type.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); Boolean localCorr = !isUndefinedPairSetSet(localRes); if (!localCorr) { collectErr.addAll(localRes); } + else { + localRes.forEach(z -> z.addAll(y)); + x1Res.addAll(localRes); + } return localCorr; } ).collect(Collectors.toCollection(HashSet::new)); } - writeLog("x1 nach Lösung von " + sameEq.toString()+" :\n" + x1.toString()); + writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); } - result.get(0).add(x1); - if (x1.isEmpty()) { + Set> x1ResPrime; + if (sameEqSet.isEmpty()) { + x1ResPrime = x1; + } + else { + x1ResPrime = x1Res; + } + result.get(0).add(x1ResPrime); + if (x1ResPrime.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC => Abbruch } } From 2bd61475173f4f31d4c41c16fc57d5e089dd88b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 7 Mar 2019 09:14:41 +0100 Subject: [PATCH 16/31] modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Noch einige Fehler --- .../typeinference/unify/TypeUnify2Task.java | 2 +- .../typeinference/unify/TypeUnifyTask.java | 279 ++---------------- .../unify/model/OrderingUnifyPair.java | 12 + .../typeinference/unify/model/UnifyPair.java | 16 +- 4 files changed, 47 insertions(+), 262 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 31247aef..315c01e7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -33,7 +33,7 @@ public class TypeUnify2Task extends TypeUnifyTask { System.out.println("two"); } one = true; - Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField); + Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true); /*if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index adc86d34..22e596ab 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -217,7 +217,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); - Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true); noOfThread--; try { logFile.close(); @@ -240,253 +240,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ - public Set> computeCartesianRecursiveOderConstraints(Set> fstElems, List>> topLevelSets, IFiniteClosure fc, boolean parallel, int rekTiefe) { - //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); - fstElems.addAll(topLevelSets.stream() - .filter(x -> x.size()==1) - .map(y -> y.stream().findFirst().get()) - .collect(Collectors.toCollection(HashSet::new))); - ArrayList>> remainingSets = topLevelSets.stream() - .filter(x -> x.size()>1) - .collect(Collectors.toCollection(ArrayList::new)); - if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set eq = new HashSet<>(); - fstElems.stream().forEach(x -> eq.addAll(x)); - Set> result = unify(eq, new ArrayList<>(), fc, parallel, rekTiefe); - return result; - } - Set> nextSet = remainingSets.remove(0); - writeLog("nextSet: " + nextSet.toString()); - List> nextSetasList =new ArrayList<>(nextSet); - try { - //List> - //nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); - } - catch (java.lang.IllegalArgumentException e) { - System.out.print(""); - } - Set> result = new HashSet<>(); - int variance = 0; - Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) - .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) - .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) - .reduce((a,b)-> {if (a==b) return a; else return 0; })) - .filter(d -> d.isPresent()) - .map(e -> e.get()) - .findAny(); - if (xi.isPresent()) { - variance = xi.get(); - } - //if (variance == 1 && nextSetasList.size() > 1) { - // List> al = new ArrayList<>(nextSetasList.size()); - // for (int ii = 0; ii < nextSetasList.size();ii++) { - // al.add(0,nextSetasList.get(ii)); - // } - // nextSetasList = al; - //} - //Set a = nextSetasListIt.next(); - /*if (nextSetasList.size()>1) {zu loeschen - if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) - System.out.print(""); - if (variance == 1) { - a_next = oup.max(nextSetasList.iterator()); - } - else if (variance == -1) { - a_next = oup.min(nextSetasList.iterator()); - } - else if (variance == 0) { - a_next = nextSetasList.iterator().next(); - } - } - else { - a_next = nextSetasList.iterator().next(); - } - */ - if (!nextSetasList.iterator().hasNext()) - System.out.print(""); - if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) - System.out.print(""); - writeLog("nextSetasList: " + nextSetasList.toString()); - while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { - Set a = null; - if (variance == 1) { - a = oup.max(nextSetasList.iterator()); - nextSetasList.remove(a); - } - else if (variance == -1) { - a = oup.min(nextSetasList.iterator()); - nextSetasList.remove(a); - } - else if (variance == 0) { - a = nextSetasList.remove(0); - } - //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); - //nextSetasList.remove(a); - /* zu loeschen - if (nextSetasList.size() > 0) { - if (nextSetasList.size()>1) { - if (variance == 1) { - a_next = oup.max(nextSetasList.iterator()); - } - else if (variance == -1) { - a_next = oup.min(nextSetasList.iterator()); - } - else { - a_next = nextSetasList.iterator().next(); - } - } - else { - a_next = nextSetasList.iterator().next(); - } - } - */ - //PL 2018-03-01 - //TODO: 1. Maximum und Minimum unterscheiden - //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern - //for(Set a : newSet) { - i++; - Set> elems = new HashSet>(fstElems); - elems.add(a); - Set> res = new HashSet<>(); - if (remainingSets.isEmpty()) { - noou++; - writeLog("Vor unify Aufruf: " + eq.toString()); - writeLog("No of Unify " + noou); - System.out.println(noou); - Set eq = new HashSet<>(); - elems.stream().forEach(x -> eq.addAll(x)); - res = unify(eq, new ArrayList<>(), fc, parallel, rekTiefe); - } - else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 - res = computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel, rekTiefe); - - } - if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { - //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen - result = res; - } - else { - if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) - || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) - || result.isEmpty()) { - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - result.addAll(res); - } - //else { - //wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren - // if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { - // result = result; - // } - //} - } - - - - - /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ - if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { - if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) - System.out.print(""); - Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); - if (variance == 1) { - System.out.println(""); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == 1)) { - nextSetasList.remove(a_next); - } - else { - System.out.println(""); - } - } - } - else { if (variance == -1) { - System.out.println(""); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == -1)) { - nextSetasList.remove(0); - } - else { - System.out.println(""); - } - } - } - else if (variance == 0) { - //break; - }} - } - /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ - - /* PL 2018-11-05 wird falsch weil es auf der obersten Ebene ist. - if (isUndefinedPairSetSet(res)) { - int nofstred= 0; - Set abhSubst = res.stream() - .map(b -> - b.stream() - .map(x -> x.getAllSubstitutions()) - .reduce((y,z) -> { y.addAll(z); return y;}).get()) - .reduce((y,z) -> { y.addAll(z); return y;}).get(); - Set b = a;//effective final a - Set durchschnitt = abhSubst.stream() - .filter(x -> b.contains(x)) - //.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(); - Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results - Set, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() - .map(x -> { Set su = x.getAllSubstitutions(); //alle benutzten Substitutionen - su.add(x.getGroundBasePair()); // urspruengliches Paar - su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen - return new Pair<>(su, x.getGroundBasePair());}) - .collect(Collectors.toCollection(HashSet::new)); - if (res.size() > 1) { - System.out.println(); - } - nextSetasList = nextSetasList.stream().filter(x -> { - //Boolean ret = false; - //for (PlaceholderType var : vars) { - // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); - //} - return (!x.containsAll(durchschnitt));//Was passiert wenn durchschnitt leer ist?? - })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 - .collect(Collectors.toCollection(ArrayList::new)); - nofstred = nextSetasList.size(); - //NOCH NICHT korrekt PL 2018-10-12 - //nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) - // .collect(Collectors.toCollection(ArrayList::new)); - writeLog("res (undef): " + res.toString()); - writeLog("abhSubst: " + abhSubst.toString()); - writeLog("a: " + a.toString()); - writeLog("Durchschnitt: " + durchschnitt.toString()); - writeLog("nextSet: " + nextSet.toString()); - writeLog("nextSetasList: " + nextSetasList.toString()); - writeLog("Number first erased Elements (undef): " + (len - nofstred)); - writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size())); - writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); - noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); - writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString()); - noBacktracking++; - writeLog("Number of Backtracking: " + noBacktracking); - System.out.println(""); - } - */ - //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { - // return result; - //} - //else { - // result.removeIf(y -> isUndefinedPairSet(y)); - //} - //else result.stream().filter(y -> !isUndefinedPairSet(y)); - - - } // End of while (nextSetasList.size() > 0) - return result; - } - + /** * Computes all principal type unifiers for a set of constraints. @@ -494,7 +248,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) // ).collect(Collectors.toCollection(HashSet::new)); //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); @@ -647,12 +401,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, collectErr); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, collectErr, finalresult); } - Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -729,15 +483,17 @@ public class TypeUnifyTask extends RecursiveTask>> { // System.err.println("log-File nicht vorhanden"); //} eqPrimePrimeSet.add(eqPrime); - urm.notify(eqPrimePrimeSet); + if (finalresult) { + urm.notify(eqPrimePrimeSet); + } } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, finalresult); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, finalresult); eqPrimePrimeSet.addAll(unifyres); @@ -769,7 +525,7 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set> collectErr) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set> collectErr, Boolean finalresult) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -779,7 +535,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe); + Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); return result; } Set> nextSet = remainingSets.remove(0); @@ -1128,7 +884,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 - res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); + res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); }}} if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen @@ -1164,6 +920,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last //System.out.println(a_last); a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());}); + try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen List varsLast_a = a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) @@ -1210,6 +967,10 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("RES var=1 ADD:" + result.toString() + " " + res.toString()); result.addAll(res); }}} + } + catch (NullPointerException e) { + writeLog("NullPointerException: " + a_last.toString()); + } } else { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden @@ -1845,7 +1606,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set unitedSubst = new HashSet<>(type.getSubstitution()); unitedSubst.addAll(sameEq.getSubstitution()); localEq.add(new UnifyPair(type.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); Boolean localCorr = !isUndefinedPairSetSet(localRes); if (!localCorr) { collectErr.addAll(localRes); @@ -1865,7 +1626,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set unitedSubst = new HashSet<>(type.getSubstitution()); unitedSubst.addAll(sameEq.getSubstitution()); localEq.add(new UnifyPair(sameEq.getLhsType(), type.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, parallel, 0); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); Boolean localCorr = !isUndefinedPairSetSet(localRes); if (!localCorr) { collectErr.addAll(localRes); 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 28da9a80..736186d5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -31,14 +32,25 @@ public class OrderingUnifyPair extends Ordering> { * in dem compare(Theta, Theta') aufgerufen wird. */ public int compareEq (UnifyPair left, UnifyPair right) { + try { //if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) {//PL 2019-01-12 ausgetauscht if (((PlaceholderType)left.getLhsType()).isInnerType() && ((PlaceholderType)right.getLhsType()).isInnerType()) { return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOTWC); } else { return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOT); + }} + catch (ClassCastException e) { + try { + ((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() +"\n\n"); + ((FiniteClosure)fc).logFile.flush(); + } + catch (IOException ie) { + } + return -99; } } + /* public int compareEq (UnifyPair left, UnifyPair right) { if (left == null || right == null) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 19f6010f..b1fecd2c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -177,6 +177,16 @@ public class UnifyPair { } } + public void disableCondWildcards() { + if (lhs instanceof PlaceholderType && rhs instanceof PlaceholderType + && (!((PlaceholderType)lhs).isWildcardable() || !((PlaceholderType)rhs).isWildcardable())) + { + ((PlaceholderType)lhs).disableWildcardtable(); + ((PlaceholderType)rhs).disableWildcardtable(); + } + + } + public Boolean wrongWildcard() { return lhs.wrongWildcard() || rhs.wrongWildcard(); } @@ -219,10 +229,12 @@ public class UnifyPair { public String toString() { String ret = ""; if (lhs instanceof PlaceholderType) { - ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType(); + ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType() + + " " + ((PlaceholderType)lhs).isWildcardable(); } if (rhs instanceof PlaceholderType) { - ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType(); + ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType() + + " " + ((PlaceholderType)rhs).isWildcardable(); } return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; } From 6175fb3ee38e5a064d5860bd5d7ad1d716c22500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 7 Mar 2019 09:17:05 +0100 Subject: [PATCH 17/31] modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java --- .../typeinference/unify/model/UnifyPair.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index b1fecd2c..dcbf2f51 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -177,16 +177,6 @@ public class UnifyPair { } } - public void disableCondWildcards() { - if (lhs instanceof PlaceholderType && rhs instanceof PlaceholderType - && (!((PlaceholderType)lhs).isWildcardable() || !((PlaceholderType)rhs).isWildcardable())) - { - ((PlaceholderType)lhs).disableWildcardtable(); - ((PlaceholderType)rhs).disableWildcardtable(); - } - - } - public Boolean wrongWildcard() { return lhs.wrongWildcard() || rhs.wrongWildcard(); } From 94c32609c6eb343a9d1faea436ec3c900e734c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 7 Mar 2019 13:37:08 +0100 Subject: [PATCH 18/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java disableCondWildcards wird aufgerufen modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java /** * wenn in einem Paar bestehend aus 2 Typvariablen eine nicht wildcardtable ist, * so beide auf nicht wildcardtable setzen */ public void disableCondWildcards() eingefuegt --- .../typeinference/unify/TypeUnifyTask.java | 1 + .../typeinference/unify/model/UnifyPair.java | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1d383c66..b26ee13b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -531,6 +531,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set eq0 = applyTypeUnificationRules(eq, fc); + eq0.forEach(x -> x.disableCondWildcards()); /* * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index 19f6010f..d03b9f85 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -177,6 +177,16 @@ public class UnifyPair { } } + public void disableCondWildcards() { + if (lhs instanceof PlaceholderType && rhs instanceof PlaceholderType + && (!((PlaceholderType)lhs).isWildcardable() || !((PlaceholderType)rhs).isWildcardable())) + { + ((PlaceholderType)lhs).disableWildcardtable(); + ((PlaceholderType)rhs).disableWildcardtable(); + } + + } + public Boolean wrongWildcard() { return lhs.wrongWildcard() || rhs.wrongWildcard(); } From 411629279d21e5afdd4bc40637666f44d654e4ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 7 Mar 2019 13:44:29 +0100 Subject: [PATCH 19/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java Kommentar eingefuegt --- .../de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index d03b9f85..362b08ec 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -177,6 +177,10 @@ public class UnifyPair { } } + /** + * wenn in einem Paar bestehend aus 2 Typvariablen eine nicht wildcardtable ist, + * so beide auf nicht wildcardtable setzen + */ public void disableCondWildcards() { if (lhs instanceof PlaceholderType && rhs instanceof PlaceholderType && (!((PlaceholderType)lhs).isWildcardable() || !((PlaceholderType)rhs).isWildcardable())) From 44ed1d8e8d9a27e3adf109653cf57cfc487cfc10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 14 Mar 2019 00:20:19 +0100 Subject: [PATCH 20/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Die Ueberpruefung von a bzw. nSaL in Methode checkA ausgelagert und für die Faelle a <. th und ty <. a implementiert. --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +- .../typeinference/unify/TypeUnify.java | 22 ++ .../typeinference/unify/TypeUnifyTask.java | 317 ++++++++++++++++-- .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 4 files changed, 315 insertions(+), 32 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 03567487..0be50fb5 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -52,7 +52,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = false; + Boolean resultmodel = true; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -551,8 +551,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 2cea2184..ecef0e14 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.io.IOException; import java.io.Writer; import java.util.List; import java.util.Set; @@ -30,6 +31,13 @@ public class TypeUnify { ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); + try { + logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements + "\n"); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no log-File"); + } return res; } @@ -67,6 +75,13 @@ public class TypeUnify { ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); + try { + logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no log-File"); + } return ret; } @@ -91,6 +106,13 @@ public class TypeUnify { public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret); Set> res = unifyTask.compute(); + try { + logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no log-File"); + } return res; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ea1c8410..2cd36b41 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -115,6 +115,8 @@ public class TypeUnifyTask extends RecursiveTask>> { static int noBacktracking; + Integer noShortendElements = 0; + public TypeUnifyTask() { rules = new RuleSet(); } @@ -293,6 +295,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } while (eqSubst.isPresent()); eq0.forEach(x -> x.disableCondWildcards()); + + writeLog(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq.toString()); + writeLog(nOfUnify.toString() + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString()); /* * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs @@ -339,21 +344,16 @@ public class TypeUnifyTask extends RecursiveTask>> { if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); - Set> collectErr = new HashSet<>(); - Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput, collectErr); + Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer //nicht ausgewertet Faculty Beispiel im 1. Schritt //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren //Typen getestet werden. writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); - writeLog(nOfUnify.toString() + " collectErr: " + collectErr.toString()); if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); // If pairs occured that did not match one of the cartesian product cases, // those pairs are contradictory and the unification is impossible. if(!undefinedPairs.isEmpty()) { - Set flatCollectErr = new HashSet<>(); - collectErr.forEach(x -> flatCollectErr.addAll(x)); - undefinedPairs.addAll(flatCollectErr); noUndefPair++; for (UnifyPair up : undefinedPairs) { writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); @@ -403,7 +403,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, collectErr, finalresult); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult); } @@ -527,7 +527,7 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Set> collectErr, Boolean finalresult) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -552,16 +552,35 @@ public class TypeUnifyTask extends RecursiveTask>> { } Set> result = new HashSet<>(); int variance = 0; - Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) - .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) - .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) - .reduce((a,b)-> {if (a==b) return a; else return 2; })) //2 kommt insbesondere bei Oder-Constraints vor - .filter(d -> d.isPresent()) - .map(e -> e.get()) - .findAny(); - if (xi.isPresent()) { - variance = xi.get(); - } + + ArrayList zeroNextElem = new ArrayList<>(nextSetasList.get(0)); + UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair(); + + if (fstBasePair != null) { + Boolean sameBase = true; + for (UnifyPair ele : nextSetasList.get(0)) {//check ob a <. ty base oder ob Ueberladung + sameBase = sameBase && ele.getBasePair() != null && ele.getBasePair().equals(fstBasePair); + } + if (sameBase) { + Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) + .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) + .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) + .reduce((a,b)-> {if (a==b) return a; else return 0; })) //2 kommt insbesondere bei Oder-Constraints vor + .filter(d -> d.isPresent()) + .map(e -> e.get()) + .findAny(); + if (xi.isPresent()) { + variance = xi.get(); + } + } + else { + variance = 2; + } + + } + else { + variance = 2; + } //if (variance == 1 && nextSetasList.size() > 1) { // List> al = new ArrayList<>(nextSetasList.size()); // for (int ii = 0; ii < nextSetasList.size();ii++) { @@ -592,6 +611,32 @@ public class TypeUnifyTask extends RecursiveTask>> { if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); writeLog("nextSetasList: " + nextSetasList.toString()); + Set nextSetElem = nextSetasList.get(0); + writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); + + /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ + Optional optOrigPair = nextSetElem.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && (x.getPairOp().equals(PairOperator.EQUALSDOT)) + /* (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()))) + */ + )).findFirst(); + Set sameEqSet = null; + if (optOrigPair.isPresent()) { + UnifyPair origPair = optOrigPair.get(); + UnifyType tyVar; + if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { + tyVar = origPair.getRhsType(); + } + UnifyType tyVarEF = tyVar; + sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) + .filter(x -> ((x.getLhsType().equals(tyVarEF) || x.getRhsType().equals(tyVarEF)))) + .collect(Collectors.toCollection(HashSet::new)); + } + /* sameEqSet-Bestimmung Ende */ + Set a = null; while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a_last = a; @@ -699,6 +744,30 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); Set> aParDef = new HashSet<>(); + + /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + Optional optAPair = a.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && (x.getPairOp().equals(PairOperator.EQUALSDOT)) + /* + (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()))) + */ + )).findFirst(); + + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + a = null; + noShortendElements++; + continue; + } + } + /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); @@ -721,6 +790,82 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { nextSetasList.remove(nSaL); writeLog("1 RM" + nSaL.toString()); } + /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && ((x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()))) + )).findFirst(); + + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + nSaL = null; + noShortendElements++; + continue; + } + } + /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + + /* LOESCHEN, WENN KEINE FEHLER AUFTRETEN + optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null + && x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType()))).findFirst(); + if (optAPair.isPresent()) { + UnifyPair aPair = optAPair.get(); + if (aPair.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT)) { + //Set sameEqSet = elems.stream().map(xx -> xx.iterator().next()) + // .filter(x -> ((x.getLhsType().equals(aPair.getLhsType()) || x.getRhsType().equals(aPair.getLhsType())))) + // .collect(Collectors.toCollection(HashSet::new)); + //consideredElements.addAll(sameEqSet); + Boolean wrong = false; + writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("nSaL: " + nSaL + " " + nSaL.iterator().next().getBasePair()); + for (UnifyPair sameEq : sameEqSet) { + //writeLog("x1 Original:\n" + x1.toString()); + if (sameEq.getLhsType() instanceof PlaceholderType) { + //UnifyPair type = a.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + wrong = true; + break; + } + } + else { + //UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + wrong = true; + break; + } + } + //writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); + } + if (wrong) { + nSaL = null; + noShortendElements++; + continue; + } + }} + */ + Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -785,6 +930,81 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { nextSetasList.remove(nSaL); writeLog("-1 RM" + nSaL.toString()); } + + /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && ((x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()))) + )).findFirst(); + + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + nSaL = null; + noShortendElements++; + continue; + } + } + /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + + /* LOESCHEN, WENN KEINE FEHLER AUFTRETEN + optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null + && x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType()))).findFirst(); + if (optAPair.isPresent()) { + UnifyPair aPair = optAPair.get(); + if (aPair.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT)) { + //Set sameEqSet = elems.stream().map(xx -> xx.iterator().next()) + // .filter(x -> ((x.getLhsType().equals(aPair.getLhsType()) || x.getRhsType().equals(aPair.getLhsType())))) + // .collect(Collectors.toCollection(HashSet::new)); + //consideredElements.addAll(sameEqSet); + Boolean wrong = false; + for (UnifyPair sameEq : sameEqSet) { + //writeLog("x1 Original:\n" + x1.toString()); + if (sameEq.getLhsType() instanceof PlaceholderType) { + //UnifyPair type = a.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + wrong = true; + break; + } + } + else { + //UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + wrong = true; + break; + } + } + //writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); + } + if (wrong) { + nSaL = null; + noShortendElements++; + continue; + } + }} + */ + Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -976,10 +1196,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES Fst:" + result.toString() + " " + res.toString() + " " + collectErr.toString()); - if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen - result.addAll(collectErr); - } + writeLog("RES Fst:" + result.toString() + " " + res.toString()); result.addAll(res); } } @@ -1010,9 +1227,6 @@ public class TypeUnifyTask extends RecursiveTask>> { || result.isEmpty()) { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); - if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))) {//Wenn Fehlerfall: dann die Fehler aus calculatePairSets hinzufuegen - result.addAll(collectErr); - } result.addAll(par_res); } } @@ -1229,6 +1443,51 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } + protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { + //if (aPair.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT)) + //{ + writeLog("checkA: " + aPair); + //Set sameEqSet = elems.stream().map(xx -> xx.iterator().next()) + // .filter(x -> ((x.getLhsType().equals(aPair.getLhsType()) || x.getRhsType().equals(aPair.getLhsType())))) + // .collect(Collectors.toCollection(HashSet::new)); + //consideredElements.addAll(sameEqSet); + Boolean wrong = false; + for (UnifyPair sameEq : sameEqSet) { + //writeLog("x1 Original:\n" + x1.toString()); + if (sameEq.getLhsType() instanceof PlaceholderType) { + //UnifyPair type = a.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + return false; + } + } + else { + //UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); + Set localEq = new HashSet<>(); + Set unitedSubst = new HashSet<>(aPair.getSubstitution()); + unitedSubst.addAll(sameEq.getSubstitution()); + localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); + if (isUndefinedPairSetSet(localRes)) { + if (result.isEmpty() || isUndefinedPairSetSet(result)) { + result.addAll(localRes); + } + return false; + } + } + //writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); + } + //} + return true; + } + protected boolean couldBecorrect(Set, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set nextElem) { return reducedUndefResSubstGroundedBasePair.stream() .map(pair -> { @@ -1502,7 +1761,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements * (as in case 1 where sigma is added to the innermost set). */ - protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput, Set> collectErr) { + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { oderConstraintsOutput.addAll(oderConstraintsInput); List>>> result = new ArrayList<>(9); @@ -1589,6 +1848,7 @@ public class TypeUnifyTask extends RecursiveTask>> { remElem.add(new UnifyPair(pair.getLhsType(), new SuperType(pair.getRhsType()), PairOperator.EQUALSDOT)); x1.remove(remElem); } + /* ZU LOESCHEN ANFANG //System.out.println(x1); Set sameEqSet = eq2sAsList.stream() .filter(x -> ((x.getLhsType().equals(lhsType) || x.getRhsType().equals(lhsType)) && !x.equals(pair))) @@ -1651,7 +1911,9 @@ public class TypeUnifyTask extends RecursiveTask>> { x1ResPrime = x1Res; } result.get(0).add(x1ResPrime); - if (x1ResPrime.isEmpty()) { + ZU LOESCHEN ENDE */ + result.get(0).add(x1); + if (x1.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC => Abbruch } } @@ -1758,7 +2020,6 @@ public class TypeUnifyTask extends RecursiveTask>> { } // Filter empty sets or sets that only contain an empty set. - writeLog("collectErr: " + collectErr); return result.stream().map(x -> x.stream().filter(y -> y.size() > 0).collect(Collectors.toCollection(HashSet::new))) .filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new)); } diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 638cff35..8be24d17 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> { From a01779d6df00ec9b9ba092fa1e558f2da542a5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 14 Mar 2019 00:27:21 +0100 Subject: [PATCH 21/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java auskommentierter Code der nach checkA verschoben wurde geloescht --- .../typeinference/unify/TypeUnifyTask.java | 119 +----------------- 1 file changed, 5 insertions(+), 114 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 2cd36b41..bcc6ba80 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -790,7 +790,8 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { nextSetasList.remove(nSaL); writeLog("1 RM" + nSaL.toString()); } - /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + + /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && ((x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) @@ -808,63 +809,7 @@ public class TypeUnifyTask extends RecursiveTask>> { continue; } } - /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - - /* LOESCHEN, WENN KEINE FEHLER AUFTRETEN - optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null - && x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType()))).findFirst(); - if (optAPair.isPresent()) { - UnifyPair aPair = optAPair.get(); - if (aPair.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT)) { - //Set sameEqSet = elems.stream().map(xx -> xx.iterator().next()) - // .filter(x -> ((x.getLhsType().equals(aPair.getLhsType()) || x.getRhsType().equals(aPair.getLhsType())))) - // .collect(Collectors.toCollection(HashSet::new)); - //consideredElements.addAll(sameEqSet); - Boolean wrong = false; - writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("nSaL: " + nSaL + " " + nSaL.iterator().next().getBasePair()); - for (UnifyPair sameEq : sameEqSet) { - //writeLog("x1 Original:\n" + x1.toString()); - if (sameEq.getLhsType() instanceof PlaceholderType) { - //UnifyPair type = a.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); - localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - wrong = true; - break; - } - } - else { - //UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); - localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - wrong = true; - break; - } - } - //writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); - } - if (wrong) { - nSaL = null; - noShortendElements++; - continue; - } - }} - */ + /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); @@ -931,7 +876,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("-1 RM" + nSaL.toString()); } - /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ + /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && ((x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) @@ -949,61 +894,7 @@ public class TypeUnifyTask extends RecursiveTask>> { continue; } } - /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - - /* LOESCHEN, WENN KEINE FEHLER AUFTRETEN - optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null - && x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType()))).findFirst(); - if (optAPair.isPresent()) { - UnifyPair aPair = optAPair.get(); - if (aPair.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT)) { - //Set sameEqSet = elems.stream().map(xx -> xx.iterator().next()) - // .filter(x -> ((x.getLhsType().equals(aPair.getLhsType()) || x.getRhsType().equals(aPair.getLhsType())))) - // .collect(Collectors.toCollection(HashSet::new)); - //consideredElements.addAll(sameEqSet); - Boolean wrong = false; - for (UnifyPair sameEq : sameEqSet) { - //writeLog("x1 Original:\n" + x1.toString()); - if (sameEq.getLhsType() instanceof PlaceholderType) { - //UnifyPair type = a.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); - localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - wrong = true; - break; - } - } - else { - //UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); - Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); - localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); - if (isUndefinedPairSetSet(localRes)) { - if (result.isEmpty() || isUndefinedPairSetSet(result)) { - result.addAll(localRes); - } - wrong = true; - break; - } - } - //writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); - } - if (wrong) { - nSaL = null; - noShortendElements++; - continue; - } - }} - */ + /* PL 2019-03-13 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); From 82f330eab5dc4af8b096d9c68ecce3b8f4867191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 17 Mar 2019 17:44:09 +0100 Subject: [PATCH 22/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../resources/bytecode/javFiles/Matrix.jav --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +- .../typeinference/unify/TypeUnifyTask.java | 83 +++++++++---------- .../resources/bytecode/javFiles/Matrix.jav | 4 +- 3 files changed, 43 insertions(+), 50 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 0be50fb5..03567487 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -52,7 +52,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = true; + Boolean resultmodel = false; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -551,8 +551,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index bcc6ba80..804d497e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -115,7 +115,7 @@ public class TypeUnifyTask extends RecursiveTask>> { static int noBacktracking; - Integer noShortendElements = 0; + static Integer noShortendElements = 0; public TypeUnifyTask() { rules = new RuleSet(); @@ -615,25 +615,27 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ - Optional optOrigPair = nextSetElem.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && (x.getPairOp().equals(PairOperator.EQUALSDOT)) - /* (x.getBasePair().getLhsType() instanceof PlaceholderType + Set sameEqSet = null; + if (variance != 2) { + Optional optOrigPair = nextSetElem.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && //(x.getPairOp().equals(PairOperator.EQUALSDOT)) + (x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()))) - */ + && x.getLhsType().equals(x.getBasePair().getRhsType())) )).findFirst(); - Set sameEqSet = null; - if (optOrigPair.isPresent()) { - UnifyPair origPair = optOrigPair.get(); - UnifyType tyVar; - if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { - tyVar = origPair.getRhsType(); - } - UnifyType tyVarEF = tyVar; - sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) - .filter(x -> ((x.getLhsType().equals(tyVarEF) || x.getRhsType().equals(tyVarEF)))) + if (optOrigPair.isPresent()) { + UnifyPair origPair = optOrigPair.get(); + UnifyType tyVar; + if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { + tyVar = origPair.getRhsType(); + } + UnifyType tyVarEF = tyVar; + sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) + .filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType)) + || (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType))))) .collect(Collectors.toCollection(HashSet::new)); + } } /* sameEqSet-Bestimmung Ende */ @@ -746,24 +748,24 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> aParDef = new HashSet<>(); /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = a.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && (x.getPairOp().equals(PairOperator.EQUALSDOT)) - /* + if (variance != 2) { + Optional optAPair = a.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && //(x.getPairOp().equals(PairOperator.EQUALSDOT)) (x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()))) - */ + && x.getLhsType().equals(x.getBasePair().getRhsType())) )).findFirst(); - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - a = null; - noShortendElements++; - continue; + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + a = null; + noShortendElements++; + continue; + } } } /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ @@ -792,7 +794,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + Optional optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && ((x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType @@ -877,7 +879,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + Optional optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && ((x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType @@ -888,7 +890,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyPair aPair = optAPair.get(); //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { nSaL = null; noShortendElements++; continue; @@ -1335,18 +1337,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { - //if (aPair.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT)) - //{ - writeLog("checkA: " + aPair); - //Set sameEqSet = elems.stream().map(xx -> xx.iterator().next()) - // .filter(x -> ((x.getLhsType().equals(aPair.getLhsType()) || x.getRhsType().equals(aPair.getLhsType())))) - // .collect(Collectors.toCollection(HashSet::new)); - //consideredElements.addAll(sameEqSet); - Boolean wrong = false; + writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); for (UnifyPair sameEq : sameEqSet) { - //writeLog("x1 Original:\n" + x1.toString()); if (sameEq.getLhsType() instanceof PlaceholderType) { - //UnifyPair type = a.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); Set unitedSubst = new HashSet<>(aPair.getSubstitution()); unitedSubst.addAll(sameEq.getSubstitution()); @@ -1356,11 +1349,11 @@ public class TypeUnifyTask extends RecursiveTask>> { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); } + //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); return false; } } else { - //UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); Set unitedSubst = new HashSet<>(aPair.getSubstitution()); unitedSubst.addAll(sameEq.getSubstitution()); @@ -1370,12 +1363,12 @@ public class TypeUnifyTask extends RecursiveTask>> { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); } + //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); return false; } } - //writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); } - //} + //writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); return true; } diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 29505161..0f45a91b 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -4,7 +4,7 @@ import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; -public class Matrix extends Vector> { +public class Matrix extends Vector> { Matrix () { } @@ -16,7 +16,7 @@ public class Matrix extends Vector> { // Boolean a = this.add(vv.elementAt(i)); this.add(vv.elementAt(i)); i=i+1; - } + } } mul(m) { From 212aeaa3a088a5e200b88dbe2a92febf4b191f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Mon, 18 Mar 2019 16:14:13 +0100 Subject: [PATCH 23/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 4 +- .../typeinference/unify/TypeUnifyTask.java | 81 +++++++++++++------ 2 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 03567487..16012826 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -551,8 +551,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 804d497e..6d1e813e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -615,15 +615,23 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ - Set sameEqSet = null; + Set sameEqSet = new HashSet<>(); if (variance != 2) { - Optional optOrigPair = nextSetElem.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && //(x.getPairOp().equals(PairOperator.EQUALSDOT)) + Optional optOrigPair = nextSetElem.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* (x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType())) - )).findFirst(); + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); + writeLog("optOrigPair: " + optOrigPair); if (optOrigPair.isPresent()) { UnifyPair origPair = optOrigPair.get(); UnifyType tyVar; @@ -748,20 +756,27 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> aParDef = new HashSet<>(); /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - if (variance != 2) { - Optional optAPair = a.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && //(x.getPairOp().equals(PairOperator.EQUALSDOT)) + if (variance != 2 && !sameEqSet.isEmpty()) { + Optional optAPair = a.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* (x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType())) - )).findFirst(); + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a UnifyPair aPair = optAPair.get(); //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + if (!checkA(aPair, sameEqSet, elems, result)) { a = null; noShortendElements++; continue; @@ -794,12 +809,20 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && ((x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()))) - )).findFirst(); + Optional optAPair = nSaL.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* + (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a UnifyPair aPair = optAPair.get(); @@ -879,12 +902,20 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && ((x.getBasePair().getLhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getLhsType())) - || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()))) - )).findFirst(); + Optional optAPair = nSaL.stream().filter(x -> ( + //x.getBasePair() != null && ist gegeben wenn variance != 2 + //x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && + (x.getPairOp().equals(PairOperator.EQUALSDOT) + /* + (x.getBasePair().getLhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getLhsType())) + || (x.getBasePair().getRhsType() instanceof PlaceholderType + && x.getLhsType().equals(x.getBasePair().getRhsType()) + */ + ))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist + x.getLhsType().equals(x.getBasePair().getLhsType()) || + x.getLhsType().equals(x.getBasePair().getRhsType()) + ).findFirst(); if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a UnifyPair aPair = optAPair.get(); From 850fe3942689042fa056f90ce881522bc1c097b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 19 Mar 2019 16:31:04 +0100 Subject: [PATCH 24/31] modified: ../../../main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java Typen mit Argumenten korrgiert --- .../SyntaxTreeGenerator/TypeGenerator.java | 44 +++++++++++++++++-- .../resources/bytecode/javFiles/Matrix.jav | 4 +- .../resources/bytecode/javFiles/MatrixOP.jav | 4 +- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index ce85bf6d..d55e9349 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -3,16 +3,18 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.antlr.Java8Parser; +import de.dhbwstuttgart.parser.antlr.Java8Parser.UnannClassType_lfno_unannClassOrInterfaceTypeContext; import de.dhbwstuttgart.parser.scope.GenericsRegistry; import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassRegistry; import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; import de.dhbwstuttgart.syntaxtree.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; +import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.GenericRefType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; - +import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import org.antlr.v4.runtime.Token; @@ -24,12 +26,14 @@ import java.util.regex.Pattern; public class TypeGenerator { public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) { - Java8Parser.TypeArgumentsContext arguments; + Java8Parser.TypeArgumentsContext arguments=null; + /* PL 2019-03-19 auskommentiert ANFANG if(unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType() != null){ arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments(); }else{// if(unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType() != null){ arguments = unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().typeArguments(); } + PL 2019-03-19 auskommentiert ENDE */ /** * Problem sind hier die verschachtelten Typen mit verschachtelten Typargumenten * Beispiel: Typ.InnererTyp @@ -37,6 +41,28 @@ public class TypeGenerator { String name = unannClassOrInterfaceTypeContext.getText(); if(name.contains("<")){ name = name.split("<")[0]; //Der Typ ist alles vor den ersten Argumenten + /* Fuer Debug-Zwecke + unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType(); + unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().getText(); + //unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().unannClassType_lfno_unannClassOrInterfaceType().typeArguments(); + //UnannClassType_lfno_unannClassOrInterfaceTypeContext + unannClassOrInterfaceTypeContext.unannClassType_lf_unannClassOrInterfaceType(0); + unannClassOrInterfaceTypeContext.unannClassType_lf_unannClassOrInterfaceType(0).getText(); + unannClassOrInterfaceTypeContext.unannClassType_lf_unannClassOrInterfaceType(1); + unannClassOrInterfaceTypeContext.unannClassType_lf_unannClassOrInterfaceType(1).getText(); + unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().getText(); + //unannClassOrInterfaceTypeContext.unannInterfaceType_lf_unannClassOrInterfaceType(); + //unannClassOrInterfaceTypeContext.unannInterfaceType_lf_unannClassOrInterfaceType(0).getText(); + //unannClassOrInterfaceTypeContext.unannInterfaceType_lf_unannClassOrInterfaceType(1).getText(); + //unannClassOrInterfaceTypeContext.unannInterfaceType_lfno_unannClassOrInterfaceType().getText(); + */ + int lastElement = new ArrayList<>(unannClassOrInterfaceTypeContext.unannClassType_lf_unannClassOrInterfaceType()).size()-1; + if (lastElement >=0) {//qualifizierter Name z.B.: java.util.Vector + arguments = unannClassOrInterfaceTypeContext.unannClassType_lf_unannClassOrInterfaceType(lastElement).typeArguments(); + } + else { //unqualifizierter Name z.B.: Vector + arguments = unannClassOrInterfaceTypeContext.unannClassType_lfno_unannClassOrInterfaceType().typeArguments(); + } } return convertTypeName(name, arguments, unannClassOrInterfaceTypeContext.getStart(), reg, generics); } @@ -134,6 +160,18 @@ public class TypeGenerator { throw new NotImplementedException(); } } + + public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.WildcardContext wildcardContext, JavaClassRegistry reg, GenericsRegistry generics) { + if(wildcardContext.wildcardBounds() != null){ + if(wildcardContext.wildcardBounds().getText().substring(0, 7).equals("extends")){ + return new ExtendsWildcardType(convert(wildcardContext.wildcardBounds().referenceType(), reg, generics), wildcardContext.getStart()); + }else{ + return new SuperWildcardType(convert(wildcardContext.wildcardBounds().referenceType(), reg, generics), wildcardContext.getStart()); + } + }else{ + throw new NotImplementedException(); //Wildcard ohne Bound + } + } public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(String name, Token offset, JavaClassRegistry reg, GenericsRegistry generics){ return convertTypeName(name, null, offset, reg, generics); @@ -169,7 +207,7 @@ public class TypeGenerator { List ret = new ArrayList<>(); for(Java8Parser.TypeArgumentContext arg : typeArguments.typeArgumentList().typeArgument()){ if(arg.wildcard() != null){ - throw new NotImplementedException(); + ret.add(convert(arg.wildcard(), reg, generics)); }else{ ret.add(convert(arg.referenceType(), reg, generics)); } diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 29505161..cfab616b 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -4,7 +4,7 @@ import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; -public class Matrix extends Vector> { +public class Matrix extends Vector> { Matrix () { } @@ -19,7 +19,7 @@ public class Matrix extends Vector> { } } - mul(m) { + mul(java.util.Vector> m) { var ret = new Matrix(); var i = 0; while(i < size()) { diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 638cff35..37172184 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -3,7 +3,7 @@ import java.lang.Integer; //import java.lang.Byte; import java.lang.Boolean; -public class MatrixOP extends Vector> { +public class MatrixOP extends Vector> { MatrixOP () { } @@ -18,7 +18,7 @@ public class MatrixOP extends Vector> { } } - mul = (m1, m2) -> { + Fun2$$>, java.util.Vector>, MatrixOP> mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; while(i < m1.size()) { From 66cd1e7012d85eb2bc49ef4a4913f4e1ad269b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Mar 2019 12:45:17 +0100 Subject: [PATCH 25/31] modified: ../../bytecode/javFiles/MatrixOP.jav --- src/test/resources/bytecode/javFiles/MatrixOP.jav | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 37172184..daa11349 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -18,7 +18,7 @@ public class MatrixOP extends Vector> { } } - Fun2$$>, java.util.Vector>, MatrixOP> mul = (m1, m2) -> { + mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; while(i < m1.size()) { From 8a6646bd7c162ac33317e7538744510fde7f958c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Mar 2019 13:00:08 +0100 Subject: [PATCH 26/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java --- .../java/de/dhbwstuttgart/core/JavaTXCompiler.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index bbe8c257..8c088804 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -291,21 +291,14 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); -<<<<<<< HEAD UnifyResultModel urm = null; - try { - Writer logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); - -======= - UnifyResultModel urm = new UnifyResultModel(); - urm.addUnifyResultListener(resultListener); + //urm.addUnifyResultListener(resultListener); try { logFile = logFile == null ? new FileWriter(new File("log_"+sourceFiles.keySet().iterator().next().getName())) : logFile; - ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); urm = new UnifyResultModel(cons, finiteClosure); + urm.addUnifyResultListener(resultListener); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); Function distributeInnerVars = From 986ce8e6e03057cc6251fa1f486b32bbd19d11c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Mar 2019 14:35:50 +0100 Subject: [PATCH 27/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 8 -------- .../typeinference/unify/TypeUnify.java | 15 --------------- .../typeinference/unify/TypeUnify2Task.java | 8 -------- .../typeinference/unify/TypeUnifyTask.java | 5 +---- 4 files changed, 1 insertion(+), 35 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 8c088804..162b90e8 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -42,10 +42,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; -<<<<<<< HEAD -======= import java.io.OutputStreamWriter; ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 import java.io.Writer; import java.util.*; import java.util.function.Function; @@ -430,13 +427,8 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); try { -<<<<<<< HEAD - Writer logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); -======= Writer logFile = new OutputStreamWriter(new NullOutputStream()); //new FileWriter(new File("log_"+sourceFiles.keySet().iterator().next().getName())); ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 - IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index df47e43f..2cea2184 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -14,7 +14,6 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { -<<<<<<< HEAD /** * unify parallel ohne result modell @@ -28,17 +27,12 @@ public class TypeUnify { */ public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); -======= - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, ConstraintSet cons) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, new UnifyResultModel(), cons); ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } -<<<<<<< HEAD /** * unify asynchron mit Rückgabe UnifyResultModel ohne dass alle results gesammelt sind * @param undConstrains @@ -52,16 +46,11 @@ public class TypeUnify { */ public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); -======= - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); return ret; } -<<<<<<< HEAD /** * unify parallel mit Rückgabe UnifyResultModel nachdem alle results gesammelt sind * @param undConstrains @@ -75,10 +64,6 @@ public class TypeUnify { */ public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); -======= - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index e18be625..31247aef 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -1,10 +1,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; -<<<<<<< HEAD import java.io.IOException; -======= ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 import java.io.Writer; import java.util.HashSet; import java.util.List; @@ -20,13 +17,8 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; -<<<<<<< HEAD public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm); -======= - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index fc8e9b2d..40ce4531 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -133,11 +133,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ -<<<<<<< HEAD + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { -======= - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons2) { ->>>>>>> 7cb2eed36edfe2d9f3ec4ce5c0ca40702dcff7f2 synchronized (this) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); From 57b5a5189556c2dad16b8c3dd54d1f5dfeda3fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Mar 2019 16:24:55 +0100 Subject: [PATCH 28/31] modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 162b90e8..3b7905f3 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -50,7 +50,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; -import org.apache.commons.io.output.NullOutputStream; +//import org.apache.commons.io.output.NullOutputStream; public class JavaTXCompiler { @@ -427,8 +427,8 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); try { - Writer logFile = new OutputStreamWriter(new NullOutputStream()); - //new FileWriter(new File("log_"+sourceFiles.keySet().iterator().next().getName())); + Writer logFile = //new OutputStreamWriter(new NullOutputStream()); + new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); From 0f1526daa20a275757de0aa54a7075917b7e8754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 28 Mar 2019 15:44:03 +0100 Subject: [PATCH 29/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java deleted: .gitignore --- .../typeinference/unify/TypeUnifyTask.java | 14 +++++++++----- src/test/java/logFiles/.gitignore | 5 ----- src/test/resources/bytecode/javFiles/Id.jav | 4 ++-- src/test/resources/bytecode/javFiles/MatrixOP.jav | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 src/test/java/logFiles/.gitignore diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index cb5d2ca1..8eb49691 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1121,7 +1121,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RES Fst:" + result.toString() + " " + res.toString()); + writeLog("RES Fst: reuslt: " + result.toString() + " res: " + res.toString()); result.addAll(res); } } @@ -1373,8 +1373,10 @@ public class TypeUnifyTask extends RecursiveTask>> { for (UnifyPair sameEq : sameEqSet) { if (sameEq.getLhsType() instanceof PlaceholderType) { Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); + Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); + unitedSubst.addAll(aPair.getAllBases()); + unitedSubst.addAll(sameEq.getAllSubstitutions()); + unitedSubst.addAll(sameEq.getAllBases()); localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); if (isUndefinedPairSetSet(localRes)) { @@ -1387,8 +1389,10 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { Set localEq = new HashSet<>(); - Set unitedSubst = new HashSet<>(aPair.getSubstitution()); - unitedSubst.addAll(sameEq.getSubstitution()); + Set unitedSubst = new HashSet<>(aPair.getAllSubstitutions()); + unitedSubst.addAll(aPair.getAllBases()); + unitedSubst.addAll(sameEq.getAllSubstitutions()); + unitedSubst.addAll(sameEq.getAllBases()); localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false); if (isUndefinedPairSetSet(localRes)) { diff --git a/src/test/java/logFiles/.gitignore b/src/test/java/logFiles/.gitignore deleted file mode 100644 index 76bedaea..00000000 --- a/src/test/java/logFiles/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore - diff --git a/src/test/resources/bytecode/javFiles/Id.jav b/src/test/resources/bytecode/javFiles/Id.jav index 6cb5d4b0..de6bd7d7 100644 --- a/src/test/resources/bytecode/javFiles/Id.jav +++ b/src/test/resources/bytecode/javFiles/Id.jav @@ -1,6 +1,6 @@ -public class Id { +public class Id { - id(b){ + id(FTU b){ return b; } } \ No newline at end of file diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 494453cb..4de9dc6c 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -3,7 +3,7 @@ import java.lang.Integer; import java.lang.Byte; import java.lang.Boolean; -public class MatrixOP extends Vector> { +public class MatrixOP extends Vector> { MatrixOP () { } @@ -18,7 +18,7 @@ public class MatrixOP extends Vector> { } } - public mul = (m1, m2) -> { + Fun2$$>, java.util.Vector>, MatrixOP> mul = (m1, m2) -> { var ret = new MatrixOP(); var i = 0; while(i < m1.size()) { From df0f26c0217fc614d2666090a80d3538075e69f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 28 Mar 2019 16:55:48 +0100 Subject: [PATCH 30/31] :w:wq --- src/test/resources/bytecode/javFiles/Id.jav | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/resources/bytecode/javFiles/Id.jav b/src/test/resources/bytecode/javFiles/Id.jav index de6bd7d7..e2393354 100644 --- a/src/test/resources/bytecode/javFiles/Id.jav +++ b/src/test/resources/bytecode/javFiles/Id.jav @@ -1,6 +1,6 @@ public class Id { - - id(FTU b){ - return b; - } -} \ No newline at end of file + + id(FTU b){ + return b; + } + } \ No newline at end of file From e53c29f58205c1d97516c46c886f240e0ceec8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sat, 6 Apr 2019 00:53:35 +0200 Subject: [PATCH 31/31] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Typeinference-Exception eingefuegt, wenn kein korrekter Typ inferierbar ist. modified: ../../resources/bytecode/javFiles/Id.jav --- .../typeinference/unify/TypeUnifyTask.java | 15 ++++++++++----- src/test/resources/bytecode/javFiles/Id.jav | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8eb49691..f1e3b7a7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -19,6 +19,8 @@ import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; +import de.dhbwstuttgart.exceptions.TypeinferenceException; +import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; @@ -228,7 +230,9 @@ public class TypeUnifyTask extends RecursiveTask>> { catch (IOException ioE) { System.err.println("no log-File"); } - if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } + if (isUndefinedPairSetSet(res)) { + throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>(); + } else return res; } /* @@ -478,15 +482,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst //eqPrimePrime Veraenderungen in subst repraesentieren. //try { - if (isSolvedForm(eqPrime)) { - writeLog("eqPrime:" + eqPrime.toString()+"\n"); - } + //if (isSolvedForm(eqPrime)) { + // writeLog("eqPrime:" + eqPrime.toString()+"\n"); + //} //} //catch (IOException e) { // System.err.println("log-File nicht vorhanden"); //} eqPrimePrimeSet.add(eqPrime); - if (finalresult) { + if (finalresult && isSolvedForm(eqPrime)) { + writeLog("eqPrime:" + eqPrime.toString()+"\n"); urm.notify(eqPrimePrimeSet); } } diff --git a/src/test/resources/bytecode/javFiles/Id.jav b/src/test/resources/bytecode/javFiles/Id.jav index 43718582..a8d85dfd 100644 --- a/src/test/resources/bytecode/javFiles/Id.jav +++ b/src/test/resources/bytecode/javFiles/Id.jav @@ -1,6 +1,6 @@ public class Id { - id(A b){ + B id(A b){ return b; } }