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/14] 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/14] 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/14] 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/14] 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/14] 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/14] 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 87547fdcd61aadf026c309784e86209b88af833e Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Wed, 20 Feb 2019 09:25:10 +0100 Subject: [PATCH 07/14] modified: src/test/resources/bytecode/javFiles/Id.jav modified: src/test/resources/bytecode/javFiles/Matrix.jav modified: src/test/resources/bytecode/javFiles/OL.jav --- src/test/resources/bytecode/javFiles/Id.jav | 4 ++-- src/test/resources/bytecode/javFiles/Matrix.jav | 4 ++-- src/test/resources/bytecode/javFiles/OL.jav | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/resources/bytecode/javFiles/Id.jav b/src/test/resources/bytecode/javFiles/Id.jav index 6cb5d4b0..919b0ced 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){ + BVKZ id(BVLA b){ return b; } } \ No newline at end of file diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 48f6eda2..ffd73a57 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -4,7 +4,7 @@ import java.lang.Integer; //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/OL.jav b/src/test/resources/bytecode/javFiles/OL.jav index 700e50f0..d0afad3f 100644 --- a/src/test/resources/bytecode/javFiles/OL.jav +++ b/src/test/resources/bytecode/javFiles/OL.jav @@ -4,9 +4,9 @@ import java.lang.Double; -public class OL { +public class OL { - m(x) { return x + x; } + mjava.lang.String (java.lang.String x) { return x + x; } } 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 08/14] 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 09/14] 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 10/14] 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 82d8ecba74c00dd90584c7b674c2013fb744b35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Feb 2019 17:50:06 +0100 Subject: [PATCH 11/14] BigRefacoring branch hard rueberkopiert --- src/main/java/de/dhbwstuttgart/.DS_Store | Bin 6148 -> 0 bytes .../bytecode/BytecodeGenMethod.java | 4 +- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 49 +- .../syntaxtree/factory/UnifyTypeFactory.java | 90 ++- .../constraints/ConstraintSet.java | 26 + .../typeinference/typeAlgo/TYPEStmt.java | 8 + .../typeinference/unify/Match.java | 2 + .../typeinference/unify/RuleSet.java | 22 +- .../typeinference/unify/TypeUnify.java | 24 +- .../typeinference/unify/TypeUnify2Task.java | 3 +- .../typeinference/unify/TypeUnifyTask.java | 631 ++++++++++++++---- .../unify/interfaces/IFiniteClosure.java | 1 + .../unify/model/FiniteClosure.java | 94 ++- .../unify/model/OrderingUnifyPair.java | 49 +- .../unify/model/PlaceholderType.java | 32 +- .../typeinference/unify/model/UnifyPair.java | 19 +- .../typeinference/unify/model/UnifyType.java | 2 +- .../unify/model/WildcardType.java | 2 +- src/test/java/asp/gencay/GeneratorTest.java | 2 - src/test/java/bytecode/MatrixTest.java | 0 src/test/java/bytecode/YTest.java | 4 +- src/test/java/javFiles/AddLong.jav | 9 - src/test/java/javFiles/EmptyClass.jav | 3 - src/test/java/javFiles/EmptyMethod.jav | 37 - src/test/java/javFiles/Expressions.jav | 8 - src/test/java/javFiles/FC_Matrix.jav | 10 - src/test/java/javFiles/Faculty.jav | 15 - src/test/java/javFiles/FacultyIf.jav | 17 - src/test/java/javFiles/FacultyTyped.jav | 19 - src/test/java/javFiles/Fields.jav | 11 - src/test/java/javFiles/Generics.jav | 22 - src/test/java/javFiles/IfTest.jav | 14 - src/test/java/javFiles/Import.jav | 8 - src/test/java/javFiles/Lambda.jav | 13 - src/test/java/javFiles/Lambda2.jav | 33 - src/test/java/javFiles/Lambda3.jav | 24 - src/test/java/javFiles/LambdaField.jav | 6 - src/test/java/javFiles/LambdaRunnable.jav | 14 - src/test/java/javFiles/ListenerOverload.jav | 20 - src/test/java/javFiles/Matrix.jav | 28 - src/test/java/javFiles/Meth_Gen.jav | 11 - src/test/java/javFiles/MethodCallGenerics.jav | 14 - src/test/java/javFiles/Methods.jav | 17 - src/test/java/javFiles/MethodsEasy.jav | 7 - src/test/java/javFiles/Op1.jav | 11 - src/test/java/javFiles/Package.jav | 5 - src/test/java/javFiles/Sorting.jav | 8 - src/test/java/javFiles/Subclass.jav | 6 - src/test/java/javFiles/Superclass.jav | 6 - src/test/java/javFiles/Vector.jav | 23 - src/test/java/javFiles/fc.jav | 18 - src/test/java/javFiles/mathStruc.jav | 13 - src/test/java/javFiles/test.jav | 15 - src/test/java/javFiles/test1.jav | 7 - .../resources/bytecode/LambdaCapturetest.java | 43 -- src/test/resources/bytecode/javFiles/Id.jav | 4 +- .../resources/bytecode/javFiles/Matrix.jav | 8 +- .../resources/bytecode/javFiles/Merge.jav | 4 +- src/test/resources/bytecode/javFiles/OL.jav | 4 +- .../bytecode/simplifyalgo/CycleTest.java | 76 --- .../bytecode/simplifyalgo/SameLeftSide.java | 97 --- .../bytecode/simplifyalgo/SimpleCycle.java | 79 --- src/test/resources/javFiles/Faculty.jav | 2 +- .../javFiles/bytecode/AssignToLit.jav | 30 - .../javFiles/bytecode/BinaryInMeth.jav | 17 - .../resources/javFiles/bytecode/DuMethod.jav | 11 - .../javFiles/bytecode/EmptyMethod.jav | 8 - .../resources/javFiles/bytecode/Example.jav | 9 - .../javFiles/bytecode/Exceptions.jav | 3 - src/test/resources/javFiles/bytecode/Fac.jav | 15 - .../resources/javFiles/bytecode/Faculty.jav | 48 -- .../resources/javFiles/bytecode/Faculty2.jav | 10 - .../resources/javFiles/bytecode/Field.jav | 9 - src/test/resources/javFiles/bytecode/For.jav | 30 - .../resources/javFiles/bytecode/FunOL.jav | 12 - src/test/resources/javFiles/bytecode/Gen.jav | 8 - .../resources/javFiles/bytecode/Generics.jav | 17 - .../resources/javFiles/bytecode/Generics2.jav | 6 - .../javFiles/bytecode/GreaterEqual.jav | 57 -- .../javFiles/bytecode/GreaterThan.jav | 56 -- .../resources/javFiles/bytecode/IfTest.jav | 15 - .../resources/javFiles/bytecode/Import.jav | 8 - .../javFiles/bytecode/Interface1.jav | 3 - .../javFiles/bytecode/LamRunnable.jav | 9 - .../resources/javFiles/bytecode/Lambda.jav | 10 - .../resources/javFiles/bytecode/Lambda2.jav | 35 - .../resources/javFiles/bytecode/Lambda3.jav | 23 - .../resources/javFiles/bytecode/Lambda4.jav | 18 - .../javFiles/bytecode/LambdaCapture.jav | 12 - .../javFiles/bytecode/LambdaVoid.jav | 9 - .../resources/javFiles/bytecode/LessEqual.jav | 56 -- .../resources/javFiles/bytecode/LessThan.jav | 57 -- .../resources/javFiles/bytecode/Matrix.jav | 44 -- .../resources/javFiles/bytecode/MatrixOP.jav | 43 -- .../resources/javFiles/bytecode/Merge.jav | 20 - .../resources/javFiles/bytecode/Methods.jav | 14 - src/test/resources/javFiles/bytecode/OL.jav | 22 - src/test/resources/javFiles/bytecode/Op.jav | 16 - src/test/resources/javFiles/bytecode/Op2.jav | 11 - .../javFiles/bytecode/OverlaodGen.jav | 11 - .../javFiles/bytecode/Overloading.jav | 18 - src/test/resources/javFiles/bytecode/Plus.jav | 9 - .../javFiles/bytecode/PostIncDec.jav | 27 - .../resources/javFiles/bytecode/PreInc.jav | 28 - .../javFiles/bytecode/RecursiveMeth.jav | 5 - .../resources/javFiles/bytecode/RelOps.jav | 8 - .../javFiles/bytecode/ReturnMethod.jav | 6 - .../resources/javFiles/bytecode/Sorting.jav | 23 - .../resources/javFiles/bytecode/StaticM.jav | 10 - .../resources/javFiles/bytecode/SubMatrix.jav | 13 - src/test/resources/javFiles/bytecode/Tph.jav | 12 - src/test/resources/javFiles/bytecode/Tph2.jav | 10 - src/test/resources/javFiles/bytecode/Tph3.jav | 13 - src/test/resources/javFiles/bytecode/Tph4.jav | 12 - src/test/resources/javFiles/bytecode/Tph5.jav | 13 - .../resources/javFiles/bytecode/VectorAdd.jav | 19 - .../resources/javFiles/bytecode/VoidMeth.jav | 4 - src/test/resources/javFiles/bytecode/WC.jav | 8 - .../resources/javFiles/bytecode/While.jav | 12 - src/test/resources/javFiles/bytecode/Y.jav | 28 - .../javFiles/bytecode/applyLambda.jav | 16 - .../resources/javFiles/parser/AntlrTest.jav | 6 - .../javFiles/parser/BoundedParameter.jav | 3 - .../resources/javFiles/parser/CastTest.jav | 8 - .../resources/javFiles/parser/ExtendsTest.jav | 4 - .../javFiles/parser/FeatherWeightJava.jav | 11 - .../parser/FieldInitializationTest.jav | 3 - .../javFiles/parser/FieldVarTest.jav | 5 - .../javFiles/parser/GenericFieldVarTest.jav | 3 - .../resources/javFiles/parser/ImportTest.jav | 4 - .../resources/javFiles/parser/ImportTest2.jav | 4 - .../javFiles/parser/ImportTestGeneric.jav | 5 - .../resources/javFiles/parser/NewTest.jav | 5 - .../resources/javFiles/parser/OpratorTest.jav | 12 - .../javFiles/parser/PackageNameTest.jav | 9 - .../javFiles/parser/StatementsTest.jav | 8 - .../javFiles/parser/StructuralTypes.jav | 5 - .../resources/javFiles/parser/WhileTest.jav | 14 - src/test/resources/testBytecode/Field.java | 6 - src/test/resources/testBytecode/Import.java | 8 - src/test/resources/testBytecode/Lam1.java | 10 - src/test/resources/testBytecode/LamRun.java | 8 - .../resources/testBytecode/MethFieldVar.java | 38 -- src/test/resources/testBytecode/Subclass.java | 6 - .../resources/testBytecode/SuperTest.java | 14 - .../resources/testBytecode/Superclass.java | 6 - .../resources/testBytecode/TestMyTest.java | 11 - src/test/resources/testBytecode/testF.java | 5 - src/test/resources/testBytecode/testTets.java | 5 - .../resources/testBytecode/testTetsF.java | 5 - 150 files changed, 845 insertions(+), 2315 deletions(-) delete mode 100644 src/main/java/de/dhbwstuttgart/.DS_Store mode change 100644 => 100755 src/test/java/bytecode/MatrixTest.java delete mode 100644 src/test/java/javFiles/AddLong.jav delete mode 100644 src/test/java/javFiles/EmptyClass.jav delete mode 100644 src/test/java/javFiles/EmptyMethod.jav delete mode 100644 src/test/java/javFiles/Expressions.jav delete mode 100644 src/test/java/javFiles/FC_Matrix.jav delete mode 100644 src/test/java/javFiles/Faculty.jav delete mode 100644 src/test/java/javFiles/FacultyIf.jav delete mode 100644 src/test/java/javFiles/FacultyTyped.jav delete mode 100644 src/test/java/javFiles/Fields.jav delete mode 100644 src/test/java/javFiles/Generics.jav delete mode 100644 src/test/java/javFiles/IfTest.jav delete mode 100644 src/test/java/javFiles/Import.jav delete mode 100644 src/test/java/javFiles/Lambda.jav delete mode 100644 src/test/java/javFiles/Lambda2.jav delete mode 100644 src/test/java/javFiles/Lambda3.jav delete mode 100644 src/test/java/javFiles/LambdaField.jav delete mode 100644 src/test/java/javFiles/LambdaRunnable.jav delete mode 100644 src/test/java/javFiles/ListenerOverload.jav delete mode 100644 src/test/java/javFiles/Matrix.jav delete mode 100644 src/test/java/javFiles/Meth_Gen.jav delete mode 100644 src/test/java/javFiles/MethodCallGenerics.jav delete mode 100644 src/test/java/javFiles/Methods.jav delete mode 100644 src/test/java/javFiles/MethodsEasy.jav delete mode 100644 src/test/java/javFiles/Op1.jav delete mode 100644 src/test/java/javFiles/Package.jav delete mode 100644 src/test/java/javFiles/Sorting.jav delete mode 100644 src/test/java/javFiles/Subclass.jav delete mode 100644 src/test/java/javFiles/Superclass.jav delete mode 100644 src/test/java/javFiles/Vector.jav delete mode 100644 src/test/java/javFiles/fc.jav delete mode 100644 src/test/java/javFiles/mathStruc.jav delete mode 100644 src/test/java/javFiles/test.jav delete mode 100644 src/test/java/javFiles/test1.jav delete mode 100644 src/test/resources/bytecode/LambdaCapturetest.java delete mode 100644 src/test/resources/bytecode/simplifyalgo/CycleTest.java delete mode 100644 src/test/resources/bytecode/simplifyalgo/SameLeftSide.java delete mode 100644 src/test/resources/bytecode/simplifyalgo/SimpleCycle.java delete mode 100644 src/test/resources/javFiles/bytecode/AssignToLit.jav delete mode 100644 src/test/resources/javFiles/bytecode/BinaryInMeth.jav delete mode 100644 src/test/resources/javFiles/bytecode/DuMethod.jav delete mode 100644 src/test/resources/javFiles/bytecode/EmptyMethod.jav delete mode 100644 src/test/resources/javFiles/bytecode/Example.jav delete mode 100644 src/test/resources/javFiles/bytecode/Exceptions.jav delete mode 100644 src/test/resources/javFiles/bytecode/Fac.jav delete mode 100644 src/test/resources/javFiles/bytecode/Faculty.jav delete mode 100644 src/test/resources/javFiles/bytecode/Faculty2.jav delete mode 100644 src/test/resources/javFiles/bytecode/Field.jav delete mode 100644 src/test/resources/javFiles/bytecode/For.jav delete mode 100644 src/test/resources/javFiles/bytecode/FunOL.jav delete mode 100644 src/test/resources/javFiles/bytecode/Gen.jav delete mode 100644 src/test/resources/javFiles/bytecode/Generics.jav delete mode 100644 src/test/resources/javFiles/bytecode/Generics2.jav delete mode 100644 src/test/resources/javFiles/bytecode/GreaterEqual.jav delete mode 100644 src/test/resources/javFiles/bytecode/GreaterThan.jav delete mode 100644 src/test/resources/javFiles/bytecode/IfTest.jav delete mode 100644 src/test/resources/javFiles/bytecode/Import.jav delete mode 100644 src/test/resources/javFiles/bytecode/Interface1.jav delete mode 100644 src/test/resources/javFiles/bytecode/LamRunnable.jav delete mode 100644 src/test/resources/javFiles/bytecode/Lambda.jav delete mode 100644 src/test/resources/javFiles/bytecode/Lambda2.jav delete mode 100644 src/test/resources/javFiles/bytecode/Lambda3.jav delete mode 100644 src/test/resources/javFiles/bytecode/Lambda4.jav delete mode 100644 src/test/resources/javFiles/bytecode/LambdaCapture.jav delete mode 100644 src/test/resources/javFiles/bytecode/LambdaVoid.jav delete mode 100644 src/test/resources/javFiles/bytecode/LessEqual.jav delete mode 100644 src/test/resources/javFiles/bytecode/LessThan.jav delete mode 100644 src/test/resources/javFiles/bytecode/Matrix.jav delete mode 100644 src/test/resources/javFiles/bytecode/MatrixOP.jav delete mode 100644 src/test/resources/javFiles/bytecode/Merge.jav delete mode 100644 src/test/resources/javFiles/bytecode/Methods.jav delete mode 100644 src/test/resources/javFiles/bytecode/OL.jav delete mode 100644 src/test/resources/javFiles/bytecode/Op.jav delete mode 100644 src/test/resources/javFiles/bytecode/Op2.jav delete mode 100644 src/test/resources/javFiles/bytecode/OverlaodGen.jav delete mode 100644 src/test/resources/javFiles/bytecode/Overloading.jav delete mode 100644 src/test/resources/javFiles/bytecode/Plus.jav delete mode 100644 src/test/resources/javFiles/bytecode/PostIncDec.jav delete mode 100644 src/test/resources/javFiles/bytecode/PreInc.jav delete mode 100644 src/test/resources/javFiles/bytecode/RecursiveMeth.jav delete mode 100644 src/test/resources/javFiles/bytecode/RelOps.jav delete mode 100644 src/test/resources/javFiles/bytecode/ReturnMethod.jav delete mode 100644 src/test/resources/javFiles/bytecode/Sorting.jav delete mode 100644 src/test/resources/javFiles/bytecode/StaticM.jav delete mode 100644 src/test/resources/javFiles/bytecode/SubMatrix.jav delete mode 100644 src/test/resources/javFiles/bytecode/Tph.jav delete mode 100644 src/test/resources/javFiles/bytecode/Tph2.jav delete mode 100644 src/test/resources/javFiles/bytecode/Tph3.jav delete mode 100644 src/test/resources/javFiles/bytecode/Tph4.jav delete mode 100644 src/test/resources/javFiles/bytecode/Tph5.jav delete mode 100644 src/test/resources/javFiles/bytecode/VectorAdd.jav delete mode 100644 src/test/resources/javFiles/bytecode/VoidMeth.jav delete mode 100644 src/test/resources/javFiles/bytecode/WC.jav delete mode 100644 src/test/resources/javFiles/bytecode/While.jav delete mode 100644 src/test/resources/javFiles/bytecode/Y.jav delete mode 100644 src/test/resources/javFiles/bytecode/applyLambda.jav delete mode 100644 src/test/resources/javFiles/parser/AntlrTest.jav delete mode 100644 src/test/resources/javFiles/parser/BoundedParameter.jav delete mode 100644 src/test/resources/javFiles/parser/CastTest.jav delete mode 100644 src/test/resources/javFiles/parser/ExtendsTest.jav delete mode 100644 src/test/resources/javFiles/parser/FeatherWeightJava.jav delete mode 100644 src/test/resources/javFiles/parser/FieldInitializationTest.jav delete mode 100644 src/test/resources/javFiles/parser/FieldVarTest.jav delete mode 100644 src/test/resources/javFiles/parser/GenericFieldVarTest.jav delete mode 100644 src/test/resources/javFiles/parser/ImportTest.jav delete mode 100644 src/test/resources/javFiles/parser/ImportTest2.jav delete mode 100644 src/test/resources/javFiles/parser/ImportTestGeneric.jav delete mode 100644 src/test/resources/javFiles/parser/NewTest.jav delete mode 100644 src/test/resources/javFiles/parser/OpratorTest.jav delete mode 100644 src/test/resources/javFiles/parser/PackageNameTest.jav delete mode 100644 src/test/resources/javFiles/parser/StatementsTest.jav delete mode 100644 src/test/resources/javFiles/parser/StructuralTypes.jav delete mode 100644 src/test/resources/javFiles/parser/WhileTest.jav delete mode 100644 src/test/resources/testBytecode/Field.java delete mode 100644 src/test/resources/testBytecode/Import.java delete mode 100644 src/test/resources/testBytecode/Lam1.java delete mode 100644 src/test/resources/testBytecode/LamRun.java delete mode 100644 src/test/resources/testBytecode/MethFieldVar.java delete mode 100644 src/test/resources/testBytecode/Subclass.java delete mode 100644 src/test/resources/testBytecode/SuperTest.java delete mode 100644 src/test/resources/testBytecode/Superclass.java delete mode 100644 src/test/resources/testBytecode/TestMyTest.java delete mode 100644 src/test/resources/testBytecode/testF.java delete mode 100644 src/test/resources/testBytecode/testTets.java delete mode 100644 src/test/resources/testBytecode/testTetsF.java diff --git a/src/main/java/de/dhbwstuttgart/.DS_Store b/src/main/java/de/dhbwstuttgart/.DS_Store deleted file mode 100644 index aa8a1074b6c8b435c3b9b58fbf5afc60d45b908c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T317w-vDmL65n3>!GEhCm~clcoQOeP_ao9G!V1Wq!z7}JchoJZ{X`V zv%3`~dK0lS1GC>`em2=JVK)N+qB{)R01W_;sDzao4qphxNlQ|(o;gIJ=jeli5Tam| z-ITJ~@fR7OcPAl$JIEn|5AQEXRDiLU;3kQ)yw!RYmAUHt!lIOQSzoT7dsk}Y<$gZQ zy8hslt`7bDDzNsEQpvmR2gh+Vx@fHKsx?BS@HR`Hi8fJPP&jh5b z$=XF@Z9ML@noei4J!v}Q?QOI-J6n@UO|EUUcMf{jclYCm$>WnDSKxQ3WyRtYp3x|+ zGtBx)fKN(ArQoeMNE4M_Vr)9;bTUR}fEi#0W}E@Lt;wYsUk5)vGr$b|JOi{pIH-iK z#loQ8I&jb}0Ady0TF|Cmf@&O#uEoM2Mo@$)MKqcqu;T4uEoNjDF sourceFiles = new HashMap<>(); - Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile)); @@ -109,7 +113,8 @@ public class JavaTXCompiler { return new ArrayList<>(allClasses); } - public List typeInference() throws ClassNotFoundException { +/* + public List typeInferenceOld() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { @@ -193,10 +198,7 @@ public class JavaTXCompiler { } } return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - }) - /* PL 2018-11-07 wird in varianceInheritance erledigt - .map( y -> { - + }).map( y -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) { ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance()); @@ -206,20 +208,16 @@ public class JavaTXCompiler { } } return y; } ) - */ .collect(Collectors.toCollection(HashSet::new)); - varianceInheritance(xConsSet); - - - - Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); - //Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); - logFile.write("RES: " + result.toString()+"\n"); - logFile.flush(); - results.addAll(result); + varianceInheritance(xConsSet); + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + System.out.println("RESULT: " + result); + logFile.write("RES: " + result.toString()+"\n"); + logFile.flush(); + results.addAll(result); } - + results = results.stream().map(x -> { Optional> res = new RuleSet().subst(x.stream().map(y -> { if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); @@ -242,12 +240,14 @@ public class JavaTXCompiler { return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } - + */ /** - * Vererbt alle Variancen + * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) + * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ - private void varianceInheritance(Set eq) { + /* + private void varianceInheritance(Set eq) { Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { Set pair = new HashSet<>(); @@ -273,8 +273,6 @@ public class JavaTXCompiler { phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } } -<<<<<<< HEAD -======= */ public UnifyResultModel typeInferenceAsync() throws ClassNotFoundException { @@ -289,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); @@ -425,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); @@ -630,7 +628,6 @@ public class JavaTXCompiler { return usedTPH; } ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 71985334..a764db6e 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -1,5 +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; @@ -29,7 +31,7 @@ public class UnifyTypeFactory { private static ArrayList PLACEHOLDERS = new ArrayList<>(); - public static FiniteClosure generateFC(List fromClasses) throws ClassNotFoundException { + public static FiniteClosure generateFC(List fromClasses, Writer logFile) throws ClassNotFoundException { /* Die transitive Hülle muss funktionieren. Man darf schreiben List extends AL @@ -40,7 +42,7 @@ public class UnifyTypeFactory { Generell dürfen sie immer die gleichen Namen haben. TODO: die transitive Hülle bilden */ - return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses)); + return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses), logFile); } public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){ @@ -63,26 +65,26 @@ public class UnifyTypeFactory { * Convert from * ASTType -> UnifyType */ - public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t){ + public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){ if(t instanceof GenericRefType){ - return UnifyTypeFactory.convert((GenericRefType)t); + return UnifyTypeFactory.convert((GenericRefType)t, innerType); }else if(t instanceof FunN){ - return UnifyTypeFactory.convert((FunN)t); + return UnifyTypeFactory.convert((FunN)t, innerType); }else if(t instanceof TypePlaceholder){ - return UnifyTypeFactory.convert((TypePlaceholder)t); + return UnifyTypeFactory.convert((TypePlaceholder)t, innerType); }else if(t instanceof ExtendsWildcardType){ - return UnifyTypeFactory.convert((ExtendsWildcardType)t); + return UnifyTypeFactory.convert((ExtendsWildcardType)t, innerType); }else if(t instanceof SuperWildcardType){ - return UnifyTypeFactory.convert((SuperWildcardType)t); + return UnifyTypeFactory.convert((SuperWildcardType)t, innerType); }else if(t instanceof RefType){ - return UnifyTypeFactory.convert((RefType)t); + return UnifyTypeFactory.convert((RefType)t, innerType); } //Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden"); } - public static UnifyType convert(RefType t){ + public static UnifyType convert(RefType t, Boolean innerType){ //Check if it is a FunN Type: Pattern p = Pattern.compile("Fun(\\d+)"); Matcher m = p.matcher(t.getName().toString()); @@ -90,14 +92,14 @@ public class UnifyTypeFactory { if(b){ Integer N = Integer.valueOf(m.group(1)); if((N + 1) == t.getParaList().size()){ - return convert(new FunN(t.getParaList())); + return convert(new FunN(t.getParaList()), false); } } UnifyType ret; if(t.getParaList() != null && t.getParaList().size() > 0){ List params = new ArrayList<>(); for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ - params.add(UnifyTypeFactory.convert(pT)); + params.add(UnifyTypeFactory.convert(pT, true)); } ret = new ReferenceType(t.getName().toString(),new TypeParams(params)); }else{ @@ -106,39 +108,45 @@ public class UnifyTypeFactory { return ret; } - public static UnifyType convert(FunN t){ + public static UnifyType convert(FunN t, Boolean innerType){ UnifyType ret; List params = new ArrayList<>(); if(t.getParaList() != null && t.getParaList().size() > 0){ for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ - params.add(UnifyTypeFactory.convert(pT)); + params.add(UnifyTypeFactory.convert(pT, false)); } } ret = FunNType.getFunNType(new TypeParams(params)); return ret; } - public static UnifyType convert(TypePlaceholder tph){ + public static UnifyType convert(TypePlaceholder tph, Boolean innerType){ + if (tph.getName().equals("AFR")) { + System.out.println("XXX"+innerType); + } PlaceholderType ntph = new PlaceholderType(tph.getName()); int in = PLACEHOLDERS.indexOf(ntph); if (in == -1) { PLACEHOLDERS.add(ntph); + ntph.setInnerType(innerType); return ntph; } else { - return PLACEHOLDERS.get(in); + PlaceholderType oldpht = PLACEHOLDERS.get(in); + oldpht.setInnerType(oldpht.isInnerType() || innerType); + return oldpht; } } - public static UnifyType convert(GenericRefType t){ + public static UnifyType convert(GenericRefType t, Boolean innerType){ return new ReferenceType(t.getParsedName()); } - public static UnifyType convert(WildcardType t){ + public static UnifyType convert(WildcardType t, Boolean innerType){ if(t.isExtends()) - return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType())); + return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType(), false)); else if(t.isSuper()) - return new SuperType(UnifyTypeFactory.convert(t.getInnerType())); + return new SuperType(UnifyTypeFactory.convert(t.getInnerType(), false)); else throw new NotImplementedException(); } @@ -152,22 +160,42 @@ public class UnifyTypeFactory { } public static UnifyPair convert(Pair p) { + UnifyPair ret = null; if(p.GetOperator().equals(PairOperator.SMALLERDOT)) { - UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1) - , UnifyTypeFactory.convert(p.TA2)); - return ret; + ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1, false) + , UnifyTypeFactory.convert(p.TA2, false)); + //return ret; }else if(p.GetOperator().equals(PairOperator.SMALLERNEQDOT)) { - UnifyPair ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1) - , UnifyTypeFactory.convert(p.TA2)); - return ret; + ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1, false) + , UnifyTypeFactory.convert(p.TA2, false)); + //return ret; }else if(p.GetOperator().equals(PairOperator.EQUALSDOT)) { - UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1) - , UnifyTypeFactory.convert(p.TA2)); - return ret; + ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1, false) + , UnifyTypeFactory.convert(p.TA2, false)); + //return ret; }else if(p.GetOperator().equals(PairOperator.SMALLER)){ - return generateSmallerPair(UnifyTypeFactory.convert(p.TA1), - UnifyTypeFactory.convert(p.TA2)); + ret = generateSmallerPair(UnifyTypeFactory.convert(p.TA1, false), + UnifyTypeFactory.convert(p.TA2, false)); }else throw new NotImplementedException(); + UnifyType lhs, rhs; + if (((lhs = ret.getLhsType()) instanceof PlaceholderType) + && ((PlaceholderType)lhs).isWildcardable() + && (rhs = ret.getLhsType()) instanceof PlaceholderType) { + if (lhs.getName().equals("AQ")) { + System.out.println(""); + } + ((PlaceholderType)rhs).enableWildcardtable(); + } + + if (((rhs = ret.getLhsType()) instanceof PlaceholderType) + && ((PlaceholderType)rhs).isWildcardable() + && (lhs = ret.getLhsType()) instanceof PlaceholderType) { + if (rhs.getName().equals("AQ")) { + System.out.println(""); + } + ((PlaceholderType)lhs).enableWildcardtable(); + } + return ret; } /** diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 581f9fbd..1dda8dc5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import java.util.*; +import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -53,4 +54,29 @@ public class ConstraintSet { ret.oderConstraints = newOder; return ret; } + + public void forEach (Consumer c) { + undConstraints.stream().forEach(c); + for(Set> oderConstraint : oderConstraints){ + oderConstraint.parallelStream().forEach((Constraint as) -> + as.stream().forEach(c)); + } + } + + public Set getAll () { + Set ret = new HashSet<>(); + ret.addAll(undConstraints); + for(Set> oderConstraint : oderConstraints){ + oderConstraint.parallelStream().forEach((Constraint as) -> ret.addAll(as)); + } + return ret; + } + + public List>> getOderConstraints() { + return oderConstraints; + } + + public Set getUndConstraints() { + return undConstraints; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 2f705c67..4fd14fbc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -1,3 +1,4 @@ +//PL 2018-12-19: Merge chekcen package de.dhbwstuttgart.typeinference.typeAlgo; import de.dhbwstuttgart.exceptions.NotImplementedException; @@ -228,6 +229,13 @@ public class TYPEStmt implements StatementVisitor{ binary.operation.equals(BinaryExpr.Operator.ADD)|| binary.operation.equals(BinaryExpr.Operator.SUB)){ Set> numericAdditionOrStringConcatenation = new HashSet<>(); + +// TODO PL 2018-11-06 + + // Auf importierte Typen einschraenken + // pruefen, ob Typen richtig bestimmt werden. + + //Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer: //see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17 diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java index 78f7360f..3e995607 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java @@ -22,6 +22,8 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType; public class Match implements IMatch { @Override + //A =. A ==> True + //A =. A ==> False public Optional match(ArrayList termsList) { // Start with the identity unifier. Substitutions will be added later. diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index acb6afbb..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; } @@ -321,20 +322,21 @@ public class RuleSet implements IRuleSet{ UnifyType lhsType = pair.getLhsType(); ReferenceType lhsSType; + UnifyType rhsType = pair.getRhsType(); + ReferenceType rhsSType; - if(lhsType instanceof ReferenceType) + if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) { lhsSType = (ReferenceType) lhsType; -<<<<<<< HEAD - else if(lhsType instanceof WildcardType) { -======= rhsSType = (ReferenceType) rhsType; } else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) || ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) { ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType(); - if(lhsSTypeRaw instanceof ReferenceType) + UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); + if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) { lhsSType = (ReferenceType) lhsSTypeRaw; + rhsSType = (ReferenceType) rhsSTypeRaw; + } else return Optional.empty(); } @@ -343,7 +345,8 @@ public class RuleSet implements IRuleSet{ if(lhsSType.getTypeParams().empty()) return Optional.empty(); - + + /* PL 2018-01-22 in obere Teil integriert UnifyType rhsType = pair.getRhsType(); ReferenceType rhsSType; @@ -358,6 +361,7 @@ public class RuleSet implements IRuleSet{ } else return Optional.empty(); + */ if(!rhsSType.getName().equals(lhsSType.getName())) return Optional.empty(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index c89803fd..2cea2184 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,24 +1,19 @@ 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; -<<<<<<< HEAD -======= import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { -<<<<<<< HEAD - public Set> unify(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log); -======= /** * unify parallel ohne result modell @@ -30,17 +25,14 @@ 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); ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 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,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); @@ -70,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); @@ -79,14 +71,11 @@ public class TypeUnify { } /* ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); Set> res = unifyTask.compute(); return res; } -<<<<<<< HEAD -======= */ /** @@ -99,11 +88,10 @@ 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; } ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 } 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 b4b671fa..1d383c66 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1,3 +1,4 @@ +//PL 2018-12-19: Merge checken package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; @@ -18,13 +19,10 @@ import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; -<<<<<<< HEAD -======= import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.result.ResultSet; ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; @@ -39,12 +37,14 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams; import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.WildcardType; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; 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; @@ -60,8 +60,6 @@ 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? -<<<<<<< HEAD -======= /** * Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde */ @@ -77,9 +75,8 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean one = false; Integer MaxNoOfThreads = 8; ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 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 @@ -96,7 +93,9 @@ public class TypeUnifyTask extends RecursiveTask>> { */ protected IRuleSet rules; - protected Set eq; + protected Set eq; //und-constraints + + protected List>> oderConstraintsField; protected IFiniteClosure fc; @@ -104,18 +103,23 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean parallel; + int rekTiefeField; + Integer nOfUnify = 0; Integer noUndefPair = 0; Integer noAllErasedElements = 0; + static Integer noou = 0; + static int noBacktracking; public TypeUnifyTask() { rules = new RuleSet(); } + /* public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { this.eq = eq; this.fc = fc; @@ -124,11 +128,12 @@ public class TypeUnifyTask extends RecursiveTask>> { this.logFile = logFile; this.log = log; rules = new RuleSet(logFile); + noOfThread++; + thNo = noOfThread; } + */ -<<<<<<< HEAD -======= - 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)); @@ -165,7 +170,6 @@ public class TypeUnifyTask extends RecursiveTask>> { this.urm = urm; } } ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 /** * Vererbt alle Variancen @@ -199,8 +203,6 @@ public class TypeUnifyTask extends RecursiveTask>> { } } */ -<<<<<<< HEAD -======= protected Set> compute() { if (one) { @@ -227,13 +229,264 @@ public class TypeUnifyTask extends RecursiveTask>> { else return res; } /* ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 @Override protected Set> compute() { - Set> res = unify(eq, fc, parallel); + Set> fstElems = new HashSet<>(); + fstElems.add(eq); + Set> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } +*/ + + + 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. @@ -241,18 +494,22 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(Set eq, IFiniteClosure fc, boolean parallel) { + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //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()); //if (aas.isEmpty()) { // System.out.println(""); //} + + //.collect(Collectors.toCollection(HashSet::new))); /* * Step 1: Repeated application of reduce, adapt, erase, swap */ + rekTiefe++; nOfUnify++; writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); + writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); /* @@ -319,11 +576,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); - Set>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs); + List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); + 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()); 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. @@ -375,12 +634,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); + //writeLog("topLevelSets: " + topLevelSets.toString()); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); } - Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -407,11 +667,6 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 5: Substitution */ -<<<<<<< HEAD - //System.out.println("vor Subst: " + eqPrime); - Optional> eqPrimePrime = rules.subst(eqPrime); - -======= //writeLog("vor Subst: " + eqPrime); writeLog("vor Subst: " + oderConstraints); String ocString = oderConstraints.toString(); @@ -421,12 +676,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> unifyres2 = null; if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints); //writeLog("nach Subst: " + eqPrimePrime); ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 /* * Step 6 a) Restart (fork) for pairs where subst was applied */ + /* if(parallel) { - if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() + && oderConstraints.isEmpty()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch //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. @@ -444,46 +700,32 @@ public class TypeUnifyTask extends RecursiveTask>> { fork.fork(); } } - else { // sequentiell (Step 6b is included) + else */ + {// sequentiell (Step 6b is included) if (printtag) System.out.println("nextStep: " + eqPrimePrime); - if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() + && oderConstraints.isEmpty()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch //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 { if (isSolvedForm(eqPrime)) { -<<<<<<< HEAD - logFile.write(eqPrime.toString()+"\n"); - logFile.flush(); - } - } - catch (IOException e) { } -======= writeLog("eqPrime:" + eqPrime.toString()+"\n"); } //} //catch (IOException e) { // System.err.println("log-File nicht vorhanden"); //} ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 eqPrimePrimeSet.add(eqPrime); urm.notify(eqPrimePrimeSet); } else if(eqPrimePrime.isPresent()) { -<<<<<<< HEAD - Set> unifyres = unify(eqPrimePrime.get(), fc, false); -======= Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 eqPrimePrimeSet.addAll(unifyres); } else { -<<<<<<< HEAD - Set> unifyres = unify(eqPrime, fc, false); -======= Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe); ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 eqPrimePrimeSet.addAll(unifyres); @@ -496,23 +738,26 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 6 b) Build the union over everything. */ + /* + * PL 2019-01-22: geloescht if(parallel) for(TypeUnifyTask fork : forks) eqPrimePrimeSet.addAll(fork.join()); - + */ /* * Step 7: Filter empty sets; */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); - if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) + if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) { writeLog("Result1 " + eqPrimePrimeSet.toString()); + } return eqPrimePrimeSet; } - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -522,7 +767,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, fc, parallel); + Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe); return result; } Set> nextSet = remainingSets.remove(0); @@ -540,7 +785,7 @@ public class TypeUnifyTask extends RecursiveTask>> { 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; })) + .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(); @@ -580,11 +825,12 @@ public class TypeUnifyTask extends RecursiveTask>> { Set a = null; while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a_last = a; + List> nextSetasListRest = new ArrayList<>(); + //List> nextSetasListRestMin = new ArrayList<>(); + //List> nextSetasListRestOder = new ArrayList<>(); if (variance == 1) { a = oup.max(nextSetasList.iterator()); nextSetasList.remove(a); -<<<<<<< HEAD -======= nextSetasListRest = new ArrayList<>(nextSetasList); Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); while (nextSetasListItRest.hasNext()) { @@ -611,13 +857,10 @@ public class TypeUnifyTask extends RecursiveTask>> { }} } while(!nextSetasListRestTest.equals(nextSetasListRest)); ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 } else if (variance == -1) { a = oup.min(nextSetasList.iterator()); nextSetasList.remove(a); -<<<<<<< HEAD -======= nextSetasListRest = new ArrayList<>(nextSetasList); Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); while (nextSetasListItRest.hasNext()) { @@ -644,8 +887,11 @@ public class TypeUnifyTask extends RecursiveTask>> { }} } while(!nextSetasListRestTest.equals(nextSetasListRest)); ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 } + else if (variance == 2) { + a = nextSetasList.remove(0); + nextSetasListRest = new ArrayList<>(nextSetasList); + } else if (variance == 0) { a = nextSetasList.remove(0); } @@ -675,12 +921,6 @@ public class TypeUnifyTask extends RecursiveTask>> { //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); -<<<<<<< HEAD - elems.add(a); - //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt - //writeLog("Vor unify2 Aufruf: " + eq.toString()); - Set> res = unify2(elems, eq, fc, parallel); -======= writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); //elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall //im else-Zweig @@ -878,32 +1118,54 @@ public class TypeUnifyTask extends RecursiveTask>> { 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); }}} ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; + if (res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } } else { if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) || result.isEmpty()) { - if (!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { + if ((!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) //korrekte Loesungen aus und-constraints + && (a.stream().map(x-> (x.getBasePair() != null)).reduce(true, (x, y) -> (x && y)))) //bei oder-Constraints nicht ausfuehren + { + //TODO: PL 2019-01-15: Bug 129: Im Moment wird nur das Maximum und das Minimum des aktuellen Elements betrachtet. + //Die zu vereinigenden Mengen können mehrere Elemente enthalten. Das ist bisher nicht berücksichtigt //Alle Variablen bestimmen die nicht hinzugefügt wurden in a - List vars_a = a.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) - ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + //PL 2018-12-28: Hier gab es eine ClassCastException, war nicht reproduzierbar + System.out.println(""); + List vars_a = + a.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) + || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) + ) + .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); Set fstElemRes = res.iterator().next(); Set compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new)); //Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last - List varsLast_a = a_last.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) - ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + //System.out.println(a_last); + a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());}); + 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)) + || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) + .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + //[(java.util.Vector <. gen_aq, , 1), (CEK =. ? extends gen_aq, 1)] KANN VORKOMMEN //erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen Set fstElemResult = result.iterator().next(); Set compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));; - if (variance == 1) { + writeLog("a_last:" + a_last + " a: " + a); + writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); + writeLog("compResult:" + compResult + " compRes: " + compRes); int resOfCompare = oup.compare(compResult, compRes); if (resOfCompare == -1) { writeLog("Geloescht result: " + result); @@ -917,6 +1179,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //result = result; }}} else { if (variance == -1) { + writeLog("a_last:" + a_last + " a: " + a); + writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); + writeLog("compResult:" + compResult + " compRes: " + compRes); int resOfCompare = oup.compare(compResult, compRes); if (resOfCompare == 1) { writeLog("Geloescht result: " + result); @@ -930,11 +1195,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //result = result; }}}} else { if (variance == 0) { + writeLog("RES var=1 ADD:" + result.toString() + " " + res.toString()); result.addAll(res); - }}} - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + }}} } else { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES Fst:" + result.toString() + " " + res.toString()); result.addAll(res); } } @@ -950,6 +1217,27 @@ public class TypeUnifyTask extends RecursiveTask>> { //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); //} + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + //break; + } /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) { @@ -957,17 +1245,34 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { - System.out.println(""); -<<<<<<< HEAD - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == 1)) { - nextSetasList.remove(a_next); + /* vorgezogen vor das if + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } } - else { - System.out.println(""); -======= + //break; + */ + + /* nextSetasList = nextSetasListRest; */ + /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet + */ + + System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); writeLog("aParDef: " + aParDef.toString()); aParDef.add(a); @@ -985,28 +1290,37 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Not Removed: " + a_next.toString()); System.out.println(""); } ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 } } } else { if (variance == -1) { - System.out.println(""); -<<<<<<< HEAD - 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(""); + /* vorgezogen vor das if + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var-1 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } } + //break; } + } - else if (variance == 0) { - break; - } -======= + */ + + System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); writeLog("aParDef: " + aParDef.toString()); aParDef.add(a); @@ -1056,7 +1370,6 @@ public class TypeUnifyTask extends RecursiveTask>> { */ }}} writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 } } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ @@ -1069,6 +1382,14 @@ public class TypeUnifyTask extends RecursiveTask>> { .map(x -> x.getAllSubstitutions()) .reduce((y,z) -> { y.addAll(z); return y;}).get()) .reduce((y,z) -> { y.addAll(z); return y;}).get(); + abhSubst.addAll( + res.stream() + .map(b -> + b.stream() + .map(x -> x.getAllBases()) + .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)) @@ -1100,7 +1421,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // .collect(Collectors.toCollection(ArrayList::new)); writeLog("res (undef): " + res.toString()); writeLog("abhSubst: " + abhSubst.toString()); - writeLog("a: " + a.toString()); + writeLog("a2: " + rekTiefe + " " + a.toString()); writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); @@ -1120,7 +1441,10 @@ public class TypeUnifyTask extends RecursiveTask>> { // result.removeIf(y -> isUndefinedPairSet(y)); //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); + writeLog("res: " + res.toString()); } + + writeLog("Return computeCR: " + result.toString()); return result; } @@ -1397,15 +1721,18 @@ 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, IFiniteClosure fc, Set undefined) { - List>>> result = new ArrayList<>(8); + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { + oderConstraintsOutput.addAll(oderConstraintsInput); + List>>> result = new ArrayList<>(9); - // Init all 8 cases - for(int i = 0; i < 8; i++) + // Init all 8 cases + 9. Case: oderConstraints + for(int i = 0; i < 9; i++) result.add(new HashSet<>()); + ArrayList eq2sprime = new ArrayList<>(eq2s); Iterator eq2sprimeit = eq2sprime.iterator(); ArrayList eq2sAsList = new ArrayList<>(); + Boolean first = true; while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben UnifyPair up = eq2sprimeit.next(); if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0) @@ -1414,8 +1741,45 @@ public class TypeUnifyTask extends RecursiveTask>> { eq2s.remove(up); } } + if (eq2sAsList.isEmpty()) { + List>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind + .filter(x -> x.stream() + .filter(y -> + y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getLhsType())).getVariance() != 0)) + || ((z.getRhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getRhsType())).getVariance() != 0)) + ).findFirst().isPresent() + ).findFirst().isPresent()).collect(Collectors.toList()); + if (!oderConstraintsVariance.isEmpty()) { + Set> ret = oderConstraintsVariance.get(0); + oderConstraintsOutput.remove(ret); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); + result.get(8).add(ret); + first = false; + } + } + eq2sAsList.addAll(eq2s); - Boolean first = true; + + if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet + if (!oderConstraintsOutput.isEmpty()) { + Set> ret = oderConstraintsOutput.remove(0); + //if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M")) + // System.out.println("M"); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); + result.get(8).add(ret); + first = false; + } + } + /* + Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution + hinzufuegen + */ for(UnifyPair pair : eq2sAsList) { PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); @@ -1425,6 +1789,9 @@ public class TypeUnifyTask extends RecursiveTask>> { if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); + if (((PlaceholderType)(pair.getLhsType())).getName().equals("AR")) { + System.out.println("AR"); + } Set> x1 = unifyCase1(pair, fc); if (pairOp == PairOperator.SMALLERNEQDOT) { Set remElem = new HashSet<>(); @@ -1567,9 +1934,6 @@ public class TypeUnifyTask extends RecursiveTask>> { allGen = false; break; } -<<<<<<< HEAD - -======= //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 // && thetaPrime instanceof ReferenceType // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next() instanceof PlaceholderType) //.getName().equals("java.util.Vector")) @@ -1577,11 +1941,9 @@ public class TypeUnifyTask extends RecursiveTask>> { // { // System.out.println(""); //} ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] - //PL 18-02-06 entfernt, kommt durch unify wieder rein //cs.add(thetaPrime); //PL 18-02-06 entfernt @@ -1627,19 +1989,21 @@ public class TypeUnifyTask extends RecursiveTask>> { } for(UnifyType tqp : thetaQPrimes) { + Collection tphs = tqp.getInvolvedPlaceholderTypes(); Optional opt = stdUnify.unify(tqp, thetaPrime); if (!opt.isPresent()) { continue; } - Unifier unifier = opt.get(); unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); for (Entry sigma : unifier) { - substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, + if (!tphs.contains(sigma.getKey())) {//eingefuegt PL 2019-02-02 Bug 127 + substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, //TODO: nochmals ueberlegen ob hier pair.getSubstitution() korrekt ist, oder ob leere Menge hin müsste //alle folgenden New UnifyPair ebenfalls ueberpruefen PL 2018-04-19 pair.getSubstitution(), pair)); + } } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { @@ -1664,6 +2028,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12 freshTphs.add(PlaceholderType.freshPlaceholder()); + freshTphs.forEach(x -> ((PlaceholderType)x).setInnerType(true)); resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); } @@ -1708,6 +2073,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType aPrime = PlaceholderType.freshPlaceholder(); ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); + ((PlaceholderType)aPrime).disableWildcardtable(); UnifyType extAPrime = new ExtendsType(aPrime); UnifyType thetaPrime = extThetaPrime.getExtendedType(); Set resultPrime = new HashSet<>(); @@ -1728,12 +2094,14 @@ public class TypeUnifyTask extends RecursiveTask>> { */ private Set> unifyCase3(UnifyPair pair, IFiniteClosure fc) { PlaceholderType a = (PlaceholderType) pair.getLhsType(); + a.reversVariance(); SuperType subThetaPrime = (SuperType) pair.getRhsType(); byte variance = pair.getVariance(); Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); + ((PlaceholderType)aPrime).disableWildcardtable(); UnifyType supAPrime = new SuperType(aPrime); UnifyType thetaPrime = subThetaPrime.getSuperedType(); Set resultPrime = new HashSet<>(); @@ -1767,7 +2135,27 @@ public class TypeUnifyTask extends RecursiveTask>> { break; } - for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { + //eingefuegt PL 2019-01-03 ANFANG + //fc.setLogTrue(); + //writeLog("FBOUNDED: " + pair.getfBounded()); + //writeLog("Pair: " + pair); + Set greater = fc.greater(theta, pair.getfBounded()); + //writeLog("GREATER: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " "); + if (a.isWildcardable()) { + Set greater_ext = greater.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) + .map(x -> { + //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben + // .reduce(new HashMap(), + // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return new SuperType (x);})//.accept(new freshPlaceholder(), hm));} + .collect(Collectors.toCollection(HashSet::new)); + greater.addAll(greater_ext); + } + //eingefuegt PL 2019-01-03 ENDE + + //for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { + for(UnifyType thetaS : greater) { Set resultPrime = new HashSet<>(); Match match = new Match(); @@ -1775,7 +2163,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); - Set fBounded = pair.getfBounded(); + Set fBounded = new HashSet<>(pair.getfBounded()); //PL 2019-01-09 new HashSet eingefuegt int i_ef = i; BiFunction f = (x,y) -> @@ -1789,7 +2177,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //} BinaryOperator bo = (x,y) -> (x || y); if (fBounded.stream().reduce(false,f,bo)) { - resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(freshTphs[i], thetaS.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); } else { fBounded.add(thetaS.getTypeParams().get(i)); @@ -1803,7 +2191,8 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); - //writeLog(resultPrime.toString()); + //writeLog("FBOUNDED2: " + pair.getfBounded()); + //writeLog("resultPrime Theta < a: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " " + resultPrime.toString()); } return result; @@ -1826,6 +2215,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType freshTph = PlaceholderType.freshPlaceholder(); ((PlaceholderType)freshTph).setVariance(a.getVariance()); + ((PlaceholderType)freshTph).disableWildcardtable(); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); @@ -1877,15 +2267,20 @@ public class TypeUnifyTask extends RecursiveTask>> { } void writeLog(String str) { - /* + synchronized ( this ) { if (log) { try { - logFile.write(str+"\n"); + logFile.write("Thread no.:" + thNo + "\n"); + logFile.write("noOfThread:" + noOfThread + "\n"); + logFile.write("parallel:" + parallel + "\n"); + logFile.write(str+"\n\n"); logFile.flush(); } - catch (IOException e) { } + catch (IOException e) { + System.err.println("kein LogFile"); } - */ + } + } } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index 3e20f433..37d70d55 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType; */ public interface IFiniteClosure { + public void setLogTrue(); /** * Returns all types of the finite closure that are subtypes of the argument. * @return The set of subtypes of the argument. 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 87c1e821..d0497823 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -1,5 +1,7 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -31,6 +33,11 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; public class FiniteClosure //extends Ordering //entfernt PL 2018-12-11 implements IFiniteClosure { + FileWriter logFile; + static Boolean log = false; + public void setLogTrue() { + log = true; + } /** * A map that maps every type to the node in the inheritance graph that contains that type. */ @@ -47,10 +54,21 @@ implements IFiniteClosure { */ private Set pairs; + /** + * Hastable fuer die greater-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> greaterHash = new Hashtable<>(); + + /** + * Hastable fuer die smaller-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> smallerHash = new Hashtable<>(); + /** * Creates a new instance using the inheritance tree defined in the pairs. */ - public FiniteClosure(Set pairs) { + public FiniteClosure(Set pairs, FileWriter logFile) { + this.logFile = logFile; this.pairs = new HashSet<>(pairs); inheritanceGraph = new HashMap>(); @@ -111,12 +129,29 @@ implements IFiniteClosure { */ @Override public Set smaller(UnifyType type, Set fBounded) { + + Set ret; + if ((ret = smallerHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + if(type instanceof FunNType) return computeSmallerFunN((FunNType) type, fBounded); Set>> ts = new HashSet<>(); ts.add(new Pair<>(type, fBounded)); - return computeSmaller(ts); + Set result = computeSmaller(ts); + smallerHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ + return result; } /** @@ -210,6 +245,13 @@ implements IFiniteClosure { //Eingefuegt PL 2018-05-24 F-Bounded Problematik public Set greater(UnifyType type, Set fBounded) { + Set ret; + if ((ret = greaterHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + + if(type instanceof FunNType) { return computeGreaterFunN((FunNType) type, fBounded); } @@ -227,6 +269,17 @@ implements IFiniteClosure { // if T <* T' then sigma(T) <* sigma(T') Set> candidates = strInheritanceGraph.get(type.getName()); + + /* + try { + if (log) logFile.write(candidates.toString()); + //log = false; + } + catch (IOException e) { + System.err.println("no LogFile"); + } + */ + for(Node candidate : candidates) { UnifyType theta1 = candidate.getContent(); @@ -235,9 +288,9 @@ implements IFiniteClosure { termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT)); Optional optSigma = match.match(termList); //PL 18-04-05 Unifier durch Matcher ersetzt ENDE - if(!optSigma.isPresent()) + if(!optSigma.isPresent()) { continue; - + } Unifier sigma = optSigma.get(); sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams()); @@ -250,7 +303,15 @@ implements IFiniteClosure { PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew)); } } - + /* + try { + if (log) logFile.write(PairResultFBounded.toString()); + log = false; + } + catch (IOException e) { + System.err.println("no LogFile"); + } + */ for(Pair> pt : PairResultFBounded) { UnifyType t = pt.getKey(); Set lfBounded = pt.getValue().get(); @@ -286,6 +347,16 @@ implements IFiniteClosure { //System.out.println(""); } } + + greaterHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"greaterHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ return result; } @@ -500,7 +571,7 @@ implements IFiniteClosure { result.add(type); return result; } - + @Override public Set getAllTypesByName(String typeName) { if(!strInheritanceGraph.containsKey(typeName)) @@ -624,8 +695,15 @@ implements IFiniteClosure { return 0; } } - if ((right instanceof PlaceholderType) && (left instanceof WildcardType)) { - return 0; + if (right instanceof PlaceholderType) {//&& (left instanceof WildcardType)) {PL geloescht 2019-01-15 analog zu oben + if ((left instanceof WildcardType) //PL eingefuegt 2019-01-15 analog zu oben + && ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType) + && ((PlaceholderType)right).getName().equals(((PlaceholderType)ex).getName())) {// ? extends a <. a oder ? super a <. a + return 1; + } + else { + return 0; + } } UnifyPair up = new UnifyPair(left, right, pairop); TypeUnifyTask unifyTask = new TypeUnifyTask(); 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 29b1c59c..28da9a80 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -31,7 +31,8 @@ public class OrderingUnifyPair extends Ordering> { * in dem compare(Theta, Theta') aufgerufen wird. */ public int compareEq (UnifyPair left, UnifyPair right) { - if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) { + //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 { @@ -55,6 +56,20 @@ public class OrderingUnifyPair extends Ordering> { UnifyPair up; if (left instanceof WildcardType || right instanceof WildcardType) { up = new UnifyPair(left, right, PairOperator.SMALLERDOTWC); + if (((left instanceof ExtendsType) + && (((ExtendsType)left).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)left).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType)) || + ((right instanceof ExtendsType) + && (((ExtendsType)right).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)right).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType))) + { + System.out.println(""); + } + if (((right instanceof SuperType) && (((SuperType)right).getSuperedType().getName().equals("java.lang.Object"))) + ||((left instanceof SuperType) && (((SuperType)left).getSuperedType().getName().equals("java.lang.Object")))) +{ + System.out.println(""); + } } else { up = new UnifyPair(left, right, PairOperator.SMALLERDOT); @@ -68,6 +83,19 @@ public class OrderingUnifyPair extends Ordering> { else { if (left instanceof WildcardType || right instanceof WildcardType) { up = new UnifyPair(right, left, PairOperator.SMALLERDOTWC); + if (((left instanceof ExtendsType) + && (((ExtendsType)left).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)left).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType)) || + ((right instanceof ExtendsType) + && (((ExtendsType)right).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)right).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType))) + { + System.out.println(""); + } + if (right instanceof SuperType) + { + System.out.println(""); + } } else { up = new UnifyPair(right, left, PairOperator.SMALLERDOT); @@ -88,8 +116,6 @@ 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) { -<<<<<<< HEAD -======= /* //pairop = PairOperator.SMALLERDOTWC; List al = new ArrayList<>(); @@ -137,7 +163,6 @@ public class OrderingUnifyPair extends Ordering> { System.out.println(""); } } ->>>>>>> 72705ac8689aa3d283d170e673ca6663b9676ce8 Set lefteq = left.stream() .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) .collect(Collectors.toCollection(HashSet::new)); @@ -161,17 +186,25 @@ public class OrderingUnifyPair extends Ordering> { && x.getPairOp() == PairOperator.SMALLERDOTWC)) .collect(Collectors.toCollection(HashSet::new)); //System.out.println(left.toString()); - //Fall 2 und 3 + //Fall 2 //if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) { // System.out.print(""); //} - if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { + if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { return 1; } - //Fall 2 und 3 - if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 1) { + //Fall 2 + if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof ExtendsType && rightle.size() == 1) { return -1; } + //Fall 3 + if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof SuperType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { + return -1; + } + //Fall 3 + if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof SuperType && rightle.size() == 1) { + return 1; + } //Fall 5 if (lefteq.size() == 1 && leftle.size() == 0 && righteq.size() == 1 && rightle.size() == 1) { return -1; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 01209998..60cf342f 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -46,6 +46,11 @@ public final class PlaceholderType extends UnifyType{ */ private boolean wildcardable = true; + /** + * is innerType gibt an, ob der Type des PlaceholderType innerhalb eines Typkonstruktorsverwendet wird + */ + private boolean innerType = false; + /** * variance shows the variance of the pair * -1: contravariant @@ -108,6 +113,15 @@ public final class PlaceholderType extends UnifyType{ return variance; } + public void reversVariance() { + if (variance == 1) { + setVariance(-1); + } else { + if (variance == -1) { + setVariance(1); + }} + } + public Boolean isWildcardable() { return wildcardable; } @@ -115,6 +129,22 @@ public final class PlaceholderType extends UnifyType{ wildcardable = false; } + public void enableWildcardtable() { + wildcardable = true; + } + + public void setWildcardtable(Boolean wildcardable) { + this.wildcardable = wildcardable; + } + + public Boolean isInnerType() { + return innerType; + } + + public void setInnerType(Boolean innerType) { + this.innerType = innerType; + } + @Override Set smArg(IFiniteClosure fc, Set fBounded) { return fc.smArg(this, fBounded); @@ -157,7 +187,7 @@ public final class PlaceholderType extends UnifyType{ @Override - public Collection getInvolvedPlaceholderTypes() { + public Collection getInvolvedPlaceholderTypes() { ArrayList ret = new ArrayList<>(); ret.add(this); return ret; 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 d69138a7..19f6010f 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -121,6 +121,10 @@ public class UnifyPair { pairOp = po; } + public void addSubstitutions(Set sup) { + substitution.addAll(sup); + } + public byte getVariance() { return variance; } @@ -152,6 +156,15 @@ public class UnifyPair { return ret; } + public Set getAllBases () { + Set ret = new HashSet<>(); + if (basePair != null) { + ret.add(getBasePair()); + ret.addAll(basePair.getAllBases()); + } + return ret; + } + public UnifyPair getGroundBasePair () { if (basePair == null) { return this; @@ -206,12 +219,12 @@ public class UnifyPair { public String toString() { String ret = ""; if (lhs instanceof PlaceholderType) { - ret = new Integer(((PlaceholderType)lhs).getVariance()).toString(); + ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType(); } if (rhs instanceof PlaceholderType) { - ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString(); + ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType(); } - return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])"; + return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; } /* diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index bb7bc1c6..298f87e7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -97,7 +97,7 @@ public abstract class UnifyType { return typeName + params; } - public Collection getInvolvedPlaceholderTypes() { + public Collection getInvolvedPlaceholderTypes() { ArrayList ret = new ArrayList<>(); ret.addAll(typeParams.getInvolvedPlaceholderTypes()); return ret; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java index 81999492..ea70139f 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java @@ -64,7 +64,7 @@ public abstract class WildcardType extends UnifyType { @Override - public Collection getInvolvedPlaceholderTypes() { + public Collection getInvolvedPlaceholderTypes() { ArrayList ret = new ArrayList<>(); ret.addAll(wildcardedType.getInvolvedPlaceholderTypes()); return ret; diff --git a/src/test/java/asp/gencay/GeneratorTest.java b/src/test/java/asp/gencay/GeneratorTest.java index bd268a4b..2c9fc46f 100644 --- a/src/test/java/asp/gencay/GeneratorTest.java +++ b/src/test/java/asp/gencay/GeneratorTest.java @@ -17,8 +17,6 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; - -import org.junit.Ignore; import org.junit.Test; import java.io.File; diff --git a/src/test/java/bytecode/MatrixTest.java b/src/test/java/bytecode/MatrixTest.java old mode 100644 new mode 100755 diff --git a/src/test/java/bytecode/YTest.java b/src/test/java/bytecode/YTest.java index 2a63a3ed..524170eb 100644 --- a/src/test/java/bytecode/YTest.java +++ b/src/test/java/bytecode/YTest.java @@ -26,8 +26,8 @@ public class YTest { path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Y.jav"; fileToTest = new File(path); // compiler = new JavaTXCompiler(fileToTest); -// compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/"); -// pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; +// compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"); +// pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; // loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); // classToTest = loader.loadClass("Y"); /* diff --git a/src/test/java/javFiles/AddLong.jav b/src/test/java/javFiles/AddLong.jav deleted file mode 100644 index d6d47e9f..00000000 --- a/src/test/java/javFiles/AddLong.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.Integer; -import java.lang.Long; - -public class AddLong{ - Long add(Integer a, Long b) { - Long c = a+b; - return c; - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/EmptyClass.jav b/src/test/java/javFiles/EmptyClass.jav deleted file mode 100644 index 8160d7da..00000000 --- a/src/test/java/javFiles/EmptyClass.jav +++ /dev/null @@ -1,3 +0,0 @@ -public class EmptyClass{ - -} \ No newline at end of file diff --git a/src/test/java/javFiles/EmptyMethod.jav b/src/test/java/javFiles/EmptyMethod.jav deleted file mode 100644 index dd28fc69..00000000 --- a/src/test/java/javFiles/EmptyMethod.jav +++ /dev/null @@ -1,37 +0,0 @@ -public class EmptyMethod{ - static String s1 =""; - String s2; - public void m1(){ - //String s = ""; - System.out.println("test"); - //Integer ab = Math.abs(1); - //Math.abs(1); - //String lV = "local"; - //s1 = "1"; - //s1.concat("2"); - s2 = s1; - //m2(); - Clazz i = new Clazz(); - Integer i = new Integer(1); - } - - public void m2(){} -} - -class Clazz{} -/* -public class EmptyMethod2{ - public static test = "5"; - public void m1(Integer i, String j, Boolean b){ - //String s = ""; - EmptyMethod em = new EmptyMethod(); - em.m1(); - em.s1 = ""; - //Integer ab = Math.abs(1); - //Math.abs(1); - //String lV = "local"; - //s1 = "1"; - //s1.concat("2"); - //s2 = s1; - } -}*/ \ No newline at end of file diff --git a/src/test/java/javFiles/Expressions.jav b/src/test/java/javFiles/Expressions.jav deleted file mode 100644 index e2e992a1..00000000 --- a/src/test/java/javFiles/Expressions.jav +++ /dev/null @@ -1,8 +0,0 @@ -class Expressions{ - -void test(){ - var x = 2; - x = x + 2; -} - -} \ No newline at end of file diff --git a/src/test/java/javFiles/FC_Matrix.jav b/src/test/java/javFiles/FC_Matrix.jav deleted file mode 100644 index 75ead472..00000000 --- a/src/test/java/javFiles/FC_Matrix.jav +++ /dev/null @@ -1,10 +0,0 @@ -import java.util.Vector; - -class Matrix extends Vector> { - - methode(m) { - m.add(1); - Matrix i; - methode(i); - } - } diff --git a/src/test/java/javFiles/Faculty.jav b/src/test/java/javFiles/Faculty.jav deleted file mode 100644 index ca539add..00000000 --- a/src/test/java/javFiles/Faculty.jav +++ /dev/null @@ -1,15 +0,0 @@ -import java.lang.Integer; - -class Faculty { - - Integer mul(Integer x, Integer y) { - return x; - } - - m () { - var fact = (Integer x) -> { - return mul(x, fact.apply(x)); - }; - return fact; - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/FacultyIf.jav b/src/test/java/javFiles/FacultyIf.jav deleted file mode 100644 index 3c368923..00000000 --- a/src/test/java/javFiles/FacultyIf.jav +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.Integer; - -class Faculty { - - m () { - - var fact = (Integer x) -> { - if (x == 1) { - return x; - } - else { - return x * (fact.apply(x-1)); - } - }; - return fact; - } -} diff --git a/src/test/java/javFiles/FacultyTyped.jav b/src/test/java/javFiles/FacultyTyped.jav deleted file mode 100644 index 089d2f33..00000000 --- a/src/test/java/javFiles/FacultyTyped.jav +++ /dev/null @@ -1,19 +0,0 @@ -import java.lang.Integer; - -class Faculty { - - Integer mul(Integer x, Integer y) { - return x; - } - - Fun1 m () { - var fact = (Integer x) -> { - return mul(x, fact.apply(x)); - }; - return fact; - } -} - -interface Fun1{ - B apply(A a); -} \ No newline at end of file diff --git a/src/test/java/javFiles/Fields.jav b/src/test/java/javFiles/Fields.jav deleted file mode 100644 index cd2add71..00000000 --- a/src/test/java/javFiles/Fields.jav +++ /dev/null @@ -1,11 +0,0 @@ -import java.lang.String; - -class Fields{ -test2 = "test"; -test; -m(){ - var test3; - return test; -} - -} \ No newline at end of file diff --git a/src/test/java/javFiles/Generics.jav b/src/test/java/javFiles/Generics.jav deleted file mode 100644 index dd7b4eba..00000000 --- a/src/test/java/javFiles/Generics.jav +++ /dev/null @@ -1,22 +0,0 @@ -import java.lang.String; - -class Generics { - // A mt1(A a, B b){ - B mt1(B a, B b){ - return mt1(a, a); - } -} - -class Test { - methode(String s){ - return new Generics().mt1(s,s); - } -} - -/* -Problem: -auto test = new List(); -auto test2 = new List(); -... //code, welcher möglicherweise test und test2 vertauscht -test.add("hallo"); -*/ \ No newline at end of file diff --git a/src/test/java/javFiles/IfTest.jav b/src/test/java/javFiles/IfTest.jav deleted file mode 100644 index 1e1141df..00000000 --- a/src/test/java/javFiles/IfTest.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; -import java.lang.Object; - -public class IfTest{ - Object m1(b) { - Integer i; - if(b) { - return i; - }else{ - return b; - } - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Import.jav b/src/test/java/javFiles/Import.jav deleted file mode 100644 index c48082ba..00000000 --- a/src/test/java/javFiles/Import.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.Vector; - -class Import { - void methode(){ - Vector v; - v.add(v); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Lambda.jav b/src/test/java/javFiles/Lambda.jav deleted file mode 100644 index 5bd67a0b..00000000 --- a/src/test/java/javFiles/Lambda.jav +++ /dev/null @@ -1,13 +0,0 @@ - -class Apply { } - -public class Lambda { - - m () { - var lam1 = (x) -> { - return x; - }; - return lam1.apply(new Apply()); - } -} - diff --git a/src/test/java/javFiles/Lambda2.jav b/src/test/java/javFiles/Lambda2.jav deleted file mode 100644 index cf1e910b..00000000 --- a/src/test/java/javFiles/Lambda2.jav +++ /dev/null @@ -1,33 +0,0 @@ -import java.lang.String; - -public class Lambda2 -{ - public static void main(List args){ - var listOfStrings = new List(); - var listOfObjects; - listOfObjects = map(listOfStrings, (a) -> a); -} - -public map(a , b){ - b.apply(a); - return a; -} - -/* -public static List map(List input, Function func) { - List output; - output = new List(); - output.add(func.apply(input.get())); - return output; -} -*/ -} - -class List{ - A get(); - void add(A); -} - -class Function{ - B apply(A a); -} \ No newline at end of file diff --git a/src/test/java/javFiles/Lambda3.jav b/src/test/java/javFiles/Lambda3.jav deleted file mode 100644 index 9e22f302..00000000 --- a/src/test/java/javFiles/Lambda3.jav +++ /dev/null @@ -1,24 +0,0 @@ -import java.lang.String; - -public class Lambda2 -{ - /* - public static List map(List input, - Function func){ - input.add(func.apply(input.get())); - } - */ - public map(input,func){ - input.add(func.apply(input.get())); - return map(new List(), func); - } -} - -class List{ - A get(); - void add(A); -} - -class Function{ - B apply(A a); -} \ No newline at end of file diff --git a/src/test/java/javFiles/LambdaField.jav b/src/test/java/javFiles/LambdaField.jav deleted file mode 100644 index 4eb53738..00000000 --- a/src/test/java/javFiles/LambdaField.jav +++ /dev/null @@ -1,6 +0,0 @@ -public class LambdaField { - - f = x -> x; - -} - diff --git a/src/test/java/javFiles/LambdaRunnable.jav b/src/test/java/javFiles/LambdaRunnable.jav deleted file mode 100644 index 37924ea2..00000000 --- a/src/test/java/javFiles/LambdaRunnable.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.Runnable; -import java.lang.String; -import java.lang.System; - -public class LamRunnable{ - - public LamRunnable(){ - - - Runnable lam = () -> {System.out.println("lambda");}; - lam.run(); - } -} - diff --git a/src/test/java/javFiles/ListenerOverload.jav b/src/test/java/javFiles/ListenerOverload.jav deleted file mode 100644 index e1a8d65d..00000000 --- a/src/test/java/javFiles/ListenerOverload.jav +++ /dev/null @@ -1,20 +0,0 @@ -import java.lang.Integer; -import java.lang.String; - -class ListenerOverload{ - -call(p){ - call(p.left); - call(p.right); -} - -call(Integer i){} - -call(String s){} - -} - -class Pair{ - A left; - B right; -} \ No newline at end of file diff --git a/src/test/java/javFiles/Matrix.jav b/src/test/java/javFiles/Matrix.jav deleted file mode 100644 index 5e1eac08..00000000 --- a/src/test/java/javFiles/Matrix.jav +++ /dev/null @@ -1,28 +0,0 @@ -import java.util.Vector; -import java.lang.Integer; - -class Matrix extends Vector> { - Integer mul1(Integer x, Integer y) { return x;} - Integer add1(Integer x, Integer y) { return x;} - mul(m) { - var ret = new Matrix(); - var i = 0; - while(i < size()) { - var v1 = this.elementAt(i); - var v2 = new Vector(); - var j = 0; - while(j < v1.size()) { - var erg = 0; - var k = 0; - while(k < v1.size()) { - erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j); - //erg = add1(erg, mul1(v1.elementAt(k), - // m.elementAt(k).elementAt(j))); - k++; } - v2.addElement(new Integer(erg)); - j++; } - ret.addElement(v2); - i++; } - return ret; - } -} diff --git a/src/test/java/javFiles/Meth_Gen.jav b/src/test/java/javFiles/Meth_Gen.jav deleted file mode 100644 index 056dd82f..00000000 --- a/src/test/java/javFiles/Meth_Gen.jav +++ /dev/null @@ -1,11 +0,0 @@ -class Meth_Gen { - - m1(x, y) { - m2(x); - x = y; - } - - m2(y) { - m1(y, y); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/MethodCallGenerics.jav b/src/test/java/javFiles/MethodCallGenerics.jav deleted file mode 100644 index 0d02509b..00000000 --- a/src/test/java/javFiles/MethodCallGenerics.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.String; - -class Generics { - // A mt1(A a, B b){ - B mt1(B a, B b){ - return mt1(a, a); - } -} - -class Test { - methode(String s){ - return new Generics().mt1(s,s); - } -} diff --git a/src/test/java/javFiles/Methods.jav b/src/test/java/javFiles/Methods.jav deleted file mode 100644 index e45d9830..00000000 --- a/src/test/java/javFiles/Methods.jav +++ /dev/null @@ -1,17 +0,0 @@ - -class Methods { - mt4(a,b,c) { return a.add(b).sub(c) ; } - - mt1(a) {return a;} - - mt2(a) {return a.f; } - - mt3(a) {return a.add(); } -} - -class Test { - java.lang.Object f; - add(){} - add(b){return b;} - sub(b){} -} \ No newline at end of file diff --git a/src/test/java/javFiles/MethodsEasy.jav b/src/test/java/javFiles/MethodsEasy.jav deleted file mode 100644 index ee6f9daf..00000000 --- a/src/test/java/javFiles/MethodsEasy.jav +++ /dev/null @@ -1,7 +0,0 @@ - -class Methods { - mt4(a,b,c) { return a.mt3(b).mt3(c) ; } - - mt3(a) {return a.mt3(a); } -} - diff --git a/src/test/java/javFiles/Op1.jav b/src/test/java/javFiles/Op1.jav deleted file mode 100644 index 800f58b8..00000000 --- a/src/test/java/javFiles/Op1.jav +++ /dev/null @@ -1,11 +0,0 @@ -public class Op1{ - public Op1() { - - Runnable lam = () -> { - String test = ""; - String b = "b"; - test = b; - System.out.println(test);}; - //lam.run(); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Package.jav b/src/test/java/javFiles/Package.jav deleted file mode 100644 index bbc1e51d..00000000 --- a/src/test/java/javFiles/Package.jav +++ /dev/null @@ -1,5 +0,0 @@ -package strucType.input; - -class Neu -{ -} \ No newline at end of file diff --git a/src/test/java/javFiles/Sorting.jav b/src/test/java/javFiles/Sorting.jav deleted file mode 100644 index 04ef23e5..00000000 --- a/src/test/java/javFiles/Sorting.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.List; -import java.util.Collection; - -class Sorting{ - void merge(a, b){ - a.addAll(b); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Subclass.jav b/src/test/java/javFiles/Subclass.jav deleted file mode 100644 index fe6e9208..00000000 --- a/src/test/java/javFiles/Subclass.jav +++ /dev/null @@ -1,6 +0,0 @@ -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Superclass.jav b/src/test/java/javFiles/Superclass.jav deleted file mode 100644 index d58089de..00000000 --- a/src/test/java/javFiles/Superclass.jav +++ /dev/null @@ -1,6 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} diff --git a/src/test/java/javFiles/Vector.jav b/src/test/java/javFiles/Vector.jav deleted file mode 100644 index 5c21cfff..00000000 --- a/src/test/java/javFiles/Vector.jav +++ /dev/null @@ -1,23 +0,0 @@ -import java.util.ArrayList; -import java.util.Vector; -import java.lang.Object; - -class MyVector{ - -id(x){ - Object i; - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - return x; -} -} \ No newline at end of file diff --git a/src/test/java/javFiles/fc.jav b/src/test/java/javFiles/fc.jav deleted file mode 100644 index a3278cbc..00000000 --- a/src/test/java/javFiles/fc.jav +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.List; - -class Test{ - methode(param1, param2, param3) { - param2.add(param3); - return param1.meth(param2); - } -} - -interface Klasse1{ - Klasse1 meth(List p); - Klasse1 meth(Klasse2 p); -} - -interface Klasse2{ - Klasse1 meth(Klasse1 p); - Klasse2 meth(Klasse2 p); -} \ No newline at end of file diff --git a/src/test/java/javFiles/mathStruc.jav b/src/test/java/javFiles/mathStruc.jav deleted file mode 100644 index 93f901ce..00000000 --- a/src/test/java/javFiles/mathStruc.jav +++ /dev/null @@ -1,13 +0,0 @@ - -class mathStruc { - -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 diff --git a/src/test/java/javFiles/test.jav b/src/test/java/javFiles/test.jav deleted file mode 100644 index 303d167a..00000000 --- a/src/test/java/javFiles/test.jav +++ /dev/null @@ -1,15 +0,0 @@ -class Test{ - methode(param1, param2, param3) { - return param1.meth(param2.meth(param3)); - } -} - -interface Klasse1{ - Klasse1 meth(Klasse1 p); - Klasse1 meth(Klasse2 p); -} - -interface Klasse2{ - Klasse1 meth(Klasse1 p); - Klasse2 meth(Klasse2 p); -} \ No newline at end of file diff --git a/src/test/java/javFiles/test1.jav b/src/test/java/javFiles/test1.jav deleted file mode 100644 index 4b34948e..00000000 --- a/src/test/java/javFiles/test1.jav +++ /dev/null @@ -1,7 +0,0 @@ -class Faculty { - - int a; - m (int x) { - return a+x; - } -} diff --git a/src/test/resources/bytecode/LambdaCapturetest.java b/src/test/resources/bytecode/LambdaCapturetest.java deleted file mode 100644 index 438c2315..00000000 --- a/src/test/resources/bytecode/LambdaCapturetest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - */ -package bytecode; - -import static org.junit.Assert.*; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; - -import org.junit.BeforeClass; -import org.junit.Test; - -import de.dhbwstuttgart.core.JavaTXCompiler; - -/** - * @author fayez - * - */ -public class LambdaCapturetest { - private static String path; - private static File fileToTest; - private static JavaTXCompiler compiler; - private static ClassLoader loader; - private static Class classToTest; - private static String pathToClassFile; - private static Object instanceOfClass; - - @Test - public void generateBC() throws Exception { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LambdaCapture.jav"; - fileToTest = new File(path); - compiler = new JavaTXCompiler(fileToTest); - compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/"); - pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; - loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); - classToTest = loader.loadClass("LambdaCapture"); - instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); - } - -} diff --git a/src/test/resources/bytecode/javFiles/Id.jav b/src/test/resources/bytecode/javFiles/Id.jav index 919b0ced..6cb5d4b0 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 { - BVKZ id(BVLA b){ + id(b){ return b; } } \ No newline at end of file diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index ffd73a57..29505161 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,10 +1,10 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Float; +import java.lang.Float; //import java.lang.Byte; -import java.lang.Boolean; +//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(java.util.Vector> m) { + mul(m) { var ret = new Matrix(); var i = 0; while(i < size()) { diff --git a/src/test/resources/bytecode/javFiles/Merge.jav b/src/test/resources/bytecode/javFiles/Merge.jav index 9240146e..ad5e103e 100644 --- a/src/test/resources/bytecode/javFiles/Merge.jav +++ b/src/test/resources/bytecode/javFiles/Merge.jav @@ -1,8 +1,8 @@ import java.util.List; import java.lang.Integer; -import java.util.Collection; +//import java.util.Collection; -class Merge { +class Merge { merge(a, b) { a.addAll(b); diff --git a/src/test/resources/bytecode/javFiles/OL.jav b/src/test/resources/bytecode/javFiles/OL.jav index d0afad3f..700e50f0 100644 --- a/src/test/resources/bytecode/javFiles/OL.jav +++ b/src/test/resources/bytecode/javFiles/OL.jav @@ -4,9 +4,9 @@ import java.lang.Double; -public class OL { +public class OL { - mjava.lang.String (java.lang.String x) { return x + x; } + m(x) { return x + x; } } diff --git a/src/test/resources/bytecode/simplifyalgo/CycleTest.java b/src/test/resources/bytecode/simplifyalgo/CycleTest.java deleted file mode 100644 index 88697e6d..00000000 --- a/src/test/resources/bytecode/simplifyalgo/CycleTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - */ -package bytecode.simplifyalgo; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.HashSet; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.objectweb.asm.Type; - -import de.dhbwstuttgart.bytecode.TPHExtractor; -import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; -import de.dhbwstuttgart.bytecode.utilities.Simplify; - -/** - * @author Fayez Abu Alia - * - */ -public class CycleTest { - - private static TPHExtractor tphExtractor; - private static String methName; - - /** - * @throws java.lang.Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - tphExtractor = new TPHExtractor(); - // A < B - TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS); - // B < C - TPHConstraint c2 = new ExtendsConstraint("B", "C", Relation.EXTENDS); - // C < D - TPHConstraint c3 = new ExtendsConstraint("C", "D", Relation.EXTENDS); - // D < A - TPHConstraint c4 = new ExtendsConstraint("D", "A", Relation.EXTENDS); - // name - methName = "m"; - MethodAndTPH mtph = new MethodAndTPH("m"); - mtph.getTphs().add("A"); - mtph.getTphs().add("B"); - mtph.getTphs().add("C"); - mtph.getTphs().add("D"); - tphExtractor.ListOfMethodsAndTph.add(mtph); - tphExtractor.allCons.add(c1); - tphExtractor.allCons.add(c2); - tphExtractor.allCons.add(c3); - tphExtractor.allCons.add(c4); - - } - - @Test - public void test() { - HashMap> result = new HashMap<>(); - HashSet equals = new HashSet<>(); - equals.add("A"); - equals.add("B"); - equals.add("C"); - equals.add("D"); - TPHConstraint k = new ExtendsConstraint("A", Type.getInternalName(Object.class), Relation.EXTENDS); - result.put(k, equals); - - HashMap> sim = Simplify.simplifyConstraints(methName, tphExtractor); - boolean areEquals = SimpleCycle.areMapsEqual(result, sim); - assertTrue(areEquals); - } - -} diff --git a/src/test/resources/bytecode/simplifyalgo/SameLeftSide.java b/src/test/resources/bytecode/simplifyalgo/SameLeftSide.java deleted file mode 100644 index b5c4e875..00000000 --- a/src/test/resources/bytecode/simplifyalgo/SameLeftSide.java +++ /dev/null @@ -1,97 +0,0 @@ -package bytecode.simplifyalgo; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.HashSet; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.objectweb.asm.Type; - -import de.dhbwstuttgart.bytecode.TPHExtractor; -import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH; -import de.dhbwstuttgart.bytecode.utilities.Simplify; -import de.dhbwstuttgart.typedeployment.TypeInsertPlacer; - -/** -* -* @author Fayez Abu Alia -* -*/ -public class SameLeftSide { - // Typeplaceholders können nicht definiert werden, da die Konstruktor - // private ist => Test geht nicht - private static TPHExtractor tphExtractor; - private static String methName; - private static String methName2; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - tphExtractor = new TPHExtractor(); - // A < B - TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS); - // A < C - TPHConstraint c2 = new ExtendsConstraint("A", "C", Relation.EXTENDS); - // B < D - TPHConstraint c3 = new ExtendsConstraint("B", "D", Relation.EXTENDS); - // C < E - TPHConstraint c4 = new ExtendsConstraint("C", "E", Relation.EXTENDS); - // name - methName = "m1"; - MethodAndTPH m1 = new MethodAndTPH("m1"); - - methName2 = "m2"; - MethodAndTPH m2 = new MethodAndTPH("m2"); - - m1.getTphs().add("A"); - m1.getTphs().add("B"); - m1.getTphs().add("D"); - - m2.getTphs().add("C"); - m2.getTphs().add("E"); - - tphExtractor.ListOfMethodsAndTph.add(m1); - tphExtractor.ListOfMethodsAndTph.add(m2); - - tphExtractor.allCons.add(c1); - tphExtractor.allCons.add(c2); - tphExtractor.allCons.add(c3); - tphExtractor.allCons.add(c4); - } - - @Test - public void testM1() { - HashMap> result = new HashMap<>(); - - TPHConstraint d = new ExtendsConstraint("D", Type.getInternalName(Object.class), Relation.EXTENDS); - TPHConstraint a = new ExtendsConstraint("A", "D", Relation.EXTENDS); - TPHConstraint b = new ExtendsConstraint("B", "D", Relation.EXTENDS); - result.put(d, null); - result.put(a, null); - result.put(b, null); - - HashMap> sim = Simplify.simplifyConstraints(methName, tphExtractor); - boolean areEquals = SimpleCycle.areMapsEqual(result, sim); - assertTrue(areEquals); - } - - @Test - public void testM2() { - HashMap> result = new HashMap<>(); - - TPHConstraint e = new ExtendsConstraint("E", Type.getInternalName(Object.class), Relation.EXTENDS); - TPHConstraint c = new ExtendsConstraint("C", "E", Relation.EXTENDS); - - result.put(e, null); - result.put(c, null); - - HashMap> sim = Simplify.simplifyConstraints(methName2, tphExtractor); - boolean areEquals = SimpleCycle.areMapsEqual(result, sim); - assertTrue(areEquals); - } - -} diff --git a/src/test/resources/bytecode/simplifyalgo/SimpleCycle.java b/src/test/resources/bytecode/simplifyalgo/SimpleCycle.java deleted file mode 100644 index 636eb026..00000000 --- a/src/test/resources/bytecode/simplifyalgo/SimpleCycle.java +++ /dev/null @@ -1,79 +0,0 @@ -package bytecode.simplifyalgo; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.HashSet; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.objectweb.asm.Type; - -import de.dhbwstuttgart.bytecode.TPHExtractor; -import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; -import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; -import de.dhbwstuttgart.bytecode.utilities.Simplify; -/** - * - * @author Fayez Abu Alia - * - */ -public class SimpleCycle { - private static TPHExtractor tphExtractor; - private static String methName; - @BeforeClass - public static void setUpBeforeClass() throws Exception { - tphExtractor = new TPHExtractor(); - // A < B - TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS); - // B < A - TPHConstraint c2 = new ExtendsConstraint("B", "A", Relation.EXTENDS); - // name - methName = "m"; - tphExtractor.allCons.add(c1); - tphExtractor.allCons.add(c2); - - } - - @Test - public void test() { - HashMap> result = new HashMap<>(); - HashSet equals = new HashSet<>(); - equals.add("A"); - equals.add("B"); - TPHConstraint k = new ExtendsConstraint("B", Type.getInternalName(Object.class), Relation.EXTENDS); - result.put(k, equals); - - HashMap> sim = Simplify.simplifyConstraints(methName, tphExtractor); - boolean areEquals = areMapsEqual(result, sim); - assertTrue(areEquals); - } - - public static boolean areMapsEqual(HashMap> m1, HashMap> m2) { - - for(TPHConstraint c : m1.keySet()) { - for(TPHConstraint c2 : m2.keySet()) { - if(c.getLeft().equals(c2.getLeft()) && c.getRight().equals(c2.getRight()) && c.getRel()==c2.getRel()) { - HashSet eq1 = m1.get(c); - HashSet eq2 = m2.get(c2); - - if((eq1 == null && eq2 != null) || (eq1 != null && eq2 == null)) - return false; - if(eq1 != null) { - if(eq1.size() != eq2.size()) - return false; - - for(String tph:eq1) { - if(!eq2.contains(tph)) - return false; - } - } - } - } - - } - return true; - } - -} diff --git a/src/test/resources/javFiles/Faculty.jav b/src/test/resources/javFiles/Faculty.jav index ca539add..71f40515 100644 --- a/src/test/resources/javFiles/Faculty.jav +++ b/src/test/resources/javFiles/Faculty.jav @@ -5,7 +5,7 @@ class Faculty { Integer mul(Integer x, Integer y) { return x; } - + m () { var fact = (Integer x) -> { return mul(x, fact.apply(x)); diff --git a/src/test/resources/javFiles/bytecode/AssignToLit.jav b/src/test/resources/javFiles/bytecode/AssignToLit.jav deleted file mode 100644 index 873828ed..00000000 --- a/src/test/resources/javFiles/bytecode/AssignToLit.jav +++ /dev/null @@ -1,30 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; -import java.lang.String; -import java.lang.Byte; -import java.lang.Short; -import java.lang.Long; -import java.lang.Float; -import java.lang.Double; -import java.lang.Character; - -class AssignToLit { - void m(){ -// String s = "Test"; -// Boolean b = false; -// Byte byte1 = 5; -// Byte byte2 = 55; -// Short short1 = 5; -// Short short2 = 55; -// Integer int1 = 5; -// Integer int2 = 8888888; -// Long long1 = 1; -// Long long2 = 5; -// Long long3 = 89989898; -// Float float1 = 1; -// Float float2 = 55; -// Double d1 = 1; -// Double d2 = 55; - Character c = 'A'; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/BinaryInMeth.jav b/src/test/resources/javFiles/bytecode/BinaryInMeth.jav deleted file mode 100644 index 3b5fa77b..00000000 --- a/src/test/resources/javFiles/bytecode/BinaryInMeth.jav +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.Integer; -import java.lang.Double; - -public class BinaryInMeth { - - m(a){ - return ++a; - } - - m2(a,b){ - return m(a+b); - } - - m3(a) { - return m(++a); - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/DuMethod.jav b/src/test/resources/javFiles/bytecode/DuMethod.jav deleted file mode 100644 index 3898a7ba..00000000 --- a/src/test/resources/javFiles/bytecode/DuMethod.jav +++ /dev/null @@ -1,11 +0,0 @@ -public class DuMethod{ - - method(a){ - return a+a; - } - - method(a){ - return a; - } - -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/EmptyMethod.jav b/src/test/resources/javFiles/bytecode/EmptyMethod.jav deleted file mode 100644 index 961989df..00000000 --- a/src/test/resources/javFiles/bytecode/EmptyMethod.jav +++ /dev/null @@ -1,8 +0,0 @@ -public class EmptyMethod{ - - public void m1(){ - System.out.println("test"); - } - - public void m2(){} -} diff --git a/src/test/resources/javFiles/bytecode/Example.jav b/src/test/resources/javFiles/bytecode/Example.jav deleted file mode 100644 index b7455a3f..00000000 --- a/src/test/resources/javFiles/bytecode/Example.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.String; - -public class Example { - - public m() { - String x = "X"; - return x; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Exceptions.jav b/src/test/resources/javFiles/bytecode/Exceptions.jav deleted file mode 100644 index 9903511c..00000000 --- a/src/test/resources/javFiles/bytecode/Exceptions.jav +++ /dev/null @@ -1,3 +0,0 @@ -public class Exceptions { -// m(Integer i) throws -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Fac.jav b/src/test/resources/javFiles/bytecode/Fac.jav deleted file mode 100644 index 28650b45..00000000 --- a/src/test/resources/javFiles/bytecode/Fac.jav +++ /dev/null @@ -1,15 +0,0 @@ -import java.lang.Integer; -//import java.lang.Double; - -public class Fac { - - getFac(n){ - var res = 1; - var i = 1; - while(i<=n) { - res = res * i; - i++; - } - return res; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Faculty.jav b/src/test/resources/javFiles/bytecode/Faculty.jav deleted file mode 100644 index 2754b7f8..00000000 --- a/src/test/resources/javFiles/bytecode/Faculty.jav +++ /dev/null @@ -1,48 +0,0 @@ -import java.lang.Integer; - -public class Faculty { - public fact; - Faculty() { - fact = (x) -> { - if (x == 1) { - return 1; - } - else { - return x * (fact.apply(x-1)); - } - }; - } - - - public getFact(x) { - return fact.apply(x); - } -// m (x) { -// -//// var fact = (x) -> { -//// if (x == 1) { -//// return x; -//// } -//// else { -//// return x * (fact.apply(x-1)); -//// } -//// }; -//// return fact; -//// var x = 13; -//// if(x>22) { -//// return 0; -//// }else if(x <1){ -//// return x; -//// }else { -//// return 1; -//// } -// -// if (x < 0) { -// return 0; -// }else if(x<2) { -// return x; -// } else { -// return x * m(x-1); -// } -// } -} diff --git a/src/test/resources/javFiles/bytecode/Faculty2.jav b/src/test/resources/javFiles/bytecode/Faculty2.jav deleted file mode 100644 index 828f06f5..00000000 --- a/src/test/resources/javFiles/bytecode/Faculty2.jav +++ /dev/null @@ -1,10 +0,0 @@ -class Faculty2 { - - m () { - - var fact = (Integer x) -> { - return x; - }; - return fact; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Field.jav b/src/test/resources/javFiles/bytecode/Field.jav deleted file mode 100644 index b19b2308..00000000 --- a/src/test/resources/javFiles/bytecode/Field.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.Integer; - -public class Field { - public Integer x = 5; - - m(){ - return x; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/For.jav b/src/test/resources/javFiles/bytecode/For.jav deleted file mode 100644 index c4bd6677..00000000 --- a/src/test/resources/javFiles/bytecode/For.jav +++ /dev/null @@ -1,30 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; - -class For{ - Integer m(Integer x){ - var c = x + 2; -// Boolean b = true; -// c = 5; -// c++; -// ++c; -// c--; -// --c; -// while(x<2){ -// x = x +1; -// b = false; -// } - return c; -// for(int i = 0;i<10;i++) { -// x = x + 5; -// } - } - -// m2(Integer x){ -// if(x<2) { -// return 1; -// }else { -// return 2; -// } -// } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/FunOL.jav b/src/test/resources/javFiles/bytecode/FunOL.jav deleted file mode 100644 index 60736e1f..00000000 --- a/src/test/resources/javFiles/bytecode/FunOL.jav +++ /dev/null @@ -1,12 +0,0 @@ -import java.util.Vector; -import java.lang.Integer; -import java.lang.String; -//import java.lang.Byte; -//import java.lang.Boolean; - -public class FunOL { - - add(f, y) { - return f.apply() + y; - } -} diff --git a/src/test/resources/javFiles/bytecode/Gen.jav b/src/test/resources/javFiles/bytecode/Gen.jav deleted file mode 100644 index 3b58b188..00000000 --- a/src/test/resources/javFiles/bytecode/Gen.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.lang.Integer; -import java.util.Vector; - -public class Gen{ - Vector m(Vector v){ - return v; - } -} diff --git a/src/test/resources/javFiles/bytecode/Generics.jav b/src/test/resources/javFiles/bytecode/Generics.jav deleted file mode 100644 index bb7b2af5..00000000 --- a/src/test/resources/javFiles/bytecode/Generics.jav +++ /dev/null @@ -1,17 +0,0 @@ - -class Generics { - Generics(B b){ - } - B mt1(B b){ - return mt1(b); - } -} - - -/* -Problem: -auto test = new List(); -auto test2 = new List(); -... //code, welcher möglicherweise test und test2 vertauscht -test.add("hallo"); -*/ \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Generics2.jav b/src/test/resources/javFiles/bytecode/Generics2.jav deleted file mode 100644 index 52d5caa2..00000000 --- a/src/test/resources/javFiles/bytecode/Generics2.jav +++ /dev/null @@ -1,6 +0,0 @@ -class Generics2{ - B m1(B b){ - return b; - } - -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/GreaterEqual.jav b/src/test/resources/javFiles/bytecode/GreaterEqual.jav deleted file mode 100644 index 3ec69e8a..00000000 --- a/src/test/resources/javFiles/bytecode/GreaterEqual.jav +++ /dev/null @@ -1,57 +0,0 @@ -import java.lang.Integer; -import java.lang.Long; -import java.lang.Float; -import java.lang.Double; - -public class GreaterEqual { - - gE(Integer a, Integer b){ - var c = a>=b; - return c; - } - - gE(Long a, Long b){ - var c = a>=b; - return c; - } - - gE(Float a, Float b){ - var c = a>=b; - return c; - } - - gE(Double a, Double b){ - var c = a>=b; - return c; - } - - gE(Long a, Integer b){ - var c = a>=b; - return c; - } - - gE(Float a, Integer b){ - var c = a>=b; - return c; - } - - gE(Double a, Integer b){ - var c = a>=b; - return c; - } - - gE(Float a, Long b){ - var c = a>=b; - return c; - } - - gE(Double a, Long b){ - var c = a>=b; - return c; - } - - gE(Double a, Float b){ - var c = a>=b; - return c; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/GreaterThan.jav b/src/test/resources/javFiles/bytecode/GreaterThan.jav deleted file mode 100644 index 9077f5b1..00000000 --- a/src/test/resources/javFiles/bytecode/GreaterThan.jav +++ /dev/null @@ -1,56 +0,0 @@ -import java.lang.Integer; -import java.lang.Long; -import java.lang.Float; -import java.lang.Double; - -public class GreaterThan { - gT(Integer a, Integer b){ - var c = a>b; - return c; - } - - gT(Long a, Long b){ - var c = a>b; - return c; - } - - gT(Float a, Float b){ - var c = a>b; - return c; - } - - gT(Double a, Double b){ - var c = a>b; - return c; - } - - gT(Long a, Integer b){ - var c = a>b; - return c; - } - - gT(Float a, Integer b){ - var c = a>b; - return c; - } - - gT(Double a, Integer b){ - var c = a>b; - return c; - } - - gT(Float a, Long b){ - var c = a>b; - return c; - } - - gT(Double a, Long b){ - var c = a>b; - return c; - } - - gT(Double a, Float b){ - var c = a>b; - return c; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/IfTest.jav b/src/test/resources/javFiles/bytecode/IfTest.jav deleted file mode 100644 index bbcda96c..00000000 --- a/src/test/resources/javFiles/bytecode/IfTest.jav +++ /dev/null @@ -1,15 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; -import java.lang.String; - -public class IfTest{ - Integer m1(Boolean b) { - Integer i; - String b; - if(b) { - return i; - }else{ - return b; - } - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Import.jav b/src/test/resources/javFiles/bytecode/Import.jav deleted file mode 100644 index c658568f..00000000 --- a/src/test/resources/javFiles/bytecode/Import.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.Vector; - -class Import { - void methode(){ - Vector v = new Vector<>(); - v.add("X"); - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Interface1.jav b/src/test/resources/javFiles/bytecode/Interface1.jav deleted file mode 100644 index b741819c..00000000 --- a/src/test/resources/javFiles/bytecode/Interface1.jav +++ /dev/null @@ -1,3 +0,0 @@ -public interface Interface1{ - public void test(); -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/LamRunnable.jav b/src/test/resources/javFiles/bytecode/LamRunnable.jav deleted file mode 100644 index 451858f2..00000000 --- a/src/test/resources/javFiles/bytecode/LamRunnable.jav +++ /dev/null @@ -1,9 +0,0 @@ -public class LamRunnable{ - - public LamRunnable(){ - - Runnable lam = () -> {System.out.println("lambda");}; - lam.run(); - } -} - \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Lambda.jav b/src/test/resources/javFiles/bytecode/Lambda.jav deleted file mode 100644 index b0321fc2..00000000 --- a/src/test/resources/javFiles/bytecode/Lambda.jav +++ /dev/null @@ -1,10 +0,0 @@ -import java.lang.Integer; - -public class Lambda { - - m () { - var lam1 = (x) -> { - return x; - }; - return lam1; -} diff --git a/src/test/resources/javFiles/bytecode/Lambda2.jav b/src/test/resources/javFiles/bytecode/Lambda2.jav deleted file mode 100644 index 92f32b71..00000000 --- a/src/test/resources/javFiles/bytecode/Lambda2.jav +++ /dev/null @@ -1,35 +0,0 @@ -import java.lang.String; - -public class Lambda2 -{ - public static void main(List args){ - var listOfStrings = new List(); - var listOfObjects; - listOfObjects = map(listOfStrings, (a) -> a); -} - -public map(a , b){ - b.apply(a); - return a; -} - -/* -public static List map(List input, Function func) { - List output; - output = new List(); - output.add(func.apply(input.get())); - return output; -} -*/ -} - -class List{ - /* A get(); - void add(A); - */ -} -/* -class Function{ - B apply(A a); -} -*/ \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Lambda3.jav b/src/test/resources/javFiles/bytecode/Lambda3.jav deleted file mode 100644 index 9c4e960c..00000000 --- a/src/test/resources/javFiles/bytecode/Lambda3.jav +++ /dev/null @@ -1,23 +0,0 @@ - -public class Lambda2 -{ - /* - public static List map(List input, - Function func){ - input.add(func.apply(input.get())); - } - */ - public map(input,func){ - input.add(func.apply(input.get())); - return map(new List(), func); - } -} - -class List{ - A get(); - void add(A); -} - -class Function{ - B apply(A a); -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Lambda4.jav b/src/test/resources/javFiles/bytecode/Lambda4.jav deleted file mode 100644 index 378eb4d3..00000000 --- a/src/test/resources/javFiles/bytecode/Lambda4.jav +++ /dev/null @@ -1,18 +0,0 @@ -class Lambda{ - -methode(){ - return ((f) -> f); -} -} -/* -interface Fun0{ - A apply(); -} - -interface Fun1{ - A apply(B b); -} -*/ -interface Fun2{ - A apply(B b, C c); -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/LambdaCapture.jav b/src/test/resources/javFiles/bytecode/LambdaCapture.jav deleted file mode 100644 index ab1751f4..00000000 --- a/src/test/resources/javFiles/bytecode/LambdaCapture.jav +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.Integer; -public class LambdaCapture { - Integer i = 8; - f; - public LambdaCapture(){ - Integer w = 7; - f = j ->{ - return w+i;}; - - } - -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/LambdaVoid.jav b/src/test/resources/javFiles/bytecode/LambdaVoid.jav deleted file mode 100644 index dc16fcbf..00000000 --- a/src/test/resources/javFiles/bytecode/LambdaVoid.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.Integer; - -public class Lambda { - - m () { - var lam1 = (x) -> { }; - return lam1; - } -} diff --git a/src/test/resources/javFiles/bytecode/LessEqual.jav b/src/test/resources/javFiles/bytecode/LessEqual.jav deleted file mode 100644 index 2e3b7024..00000000 --- a/src/test/resources/javFiles/bytecode/LessEqual.jav +++ /dev/null @@ -1,56 +0,0 @@ -import java.lang.Integer; -import java.lang.Long; -import java.lang.Float; -import java.lang.Double; - -public class LessEqual { - lessEqual(Integer a, Integer b){ - var c = a<=b; - return c; - } - - lessEqual(Long a, Long b){ - var c = a<=b; - return c; - } - - lessEqual(Float a, Float b){ - var c = a<=b; - return c; - } - - lessEqual(Double a, Double b){ - var c = a<=b; - return c; - } - - lessEqual(Long a, Integer b){ - var c = a<=b; - return c; - } - - lessEqual(Float a, Integer b){ - var c = a<=b; - return c; - } - - lessEqual(Double a, Integer b){ - var c = a<=b; - return c; - } - - lessEqual(Float a, Long b){ - var c = a<=b; - return c; - } - - lessEqual(Double a, Long b){ - var c = a<=b; - return c; - } - - lessEqual(Double a, Float b){ - var c = a<=b; - return c; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/LessThan.jav b/src/test/resources/javFiles/bytecode/LessThan.jav deleted file mode 100644 index 04e1e83e..00000000 --- a/src/test/resources/javFiles/bytecode/LessThan.jav +++ /dev/null @@ -1,57 +0,0 @@ -import java.lang.Integer; -import java.lang.Long; -import java.lang.Float; -import java.lang.Double; - -public class LessThan { - - lessThan(Integer a, Integer b){ - var c = a> { - - Matrix () { - } - - Matrix(vv) { - Integer i; - i = 0; - while(i < vv.size()) { -// Boolean a = this.add(vv.elementAt(i)); - this.add(vv.elementAt(i)); - i=i+1; - } - } - - mul(m) { - var ret = new Matrix(); - var i = 0; - while(i < size()) { - var v1 = this.elementAt(i); - var v2 = new Vector(); - var j = 0; - while(j < v1.size()) { - var erg = 0; - var k = 0; - while(k < v1.size()) { - erg = erg + v1.elementAt(k) - * m.elementAt(k).elementAt(j); - k++; } -// v2.addElement(new Integer(erg)); - v2.addElement(erg); - j++; } - ret.addElement(v2); - i++; - } - return ret; - } -} diff --git a/src/test/resources/javFiles/bytecode/MatrixOP.jav b/src/test/resources/javFiles/bytecode/MatrixOP.jav deleted file mode 100644 index 828a270b..00000000 --- a/src/test/resources/javFiles/bytecode/MatrixOP.jav +++ /dev/null @@ -1,43 +0,0 @@ -import java.util.Vector; -import java.lang.Integer; -//import java.lang.Byte; -import java.lang.Boolean; - -public class MatrixOP extends Vector> { - - MatrixOP () { - } - - MatrixOP(vv) { - Integer i; - i = 0; - while(i < vv.size()) { -// Boolean a = this.add(vv.elementAt(i)); - this.add(vv.elementAt(i)); - i=i+1; - } - } - - mul = (m1, m2) -> { - var ret = new MatrixOP(); - var i = 0; - while(i < size()) { - var v1 = m1.elementAt(i); - var v2 = new Vector(); - var j = 0; - while(j < v1.size()) { - var erg = 0; - var k = 0; - while(k < v1.size()) { - erg = erg + v1.elementAt(k) - * m2.elementAt(k).elementAt(j); - k++; } -// v2.addElement(new Integer(erg)); - v2.addElement(erg); - j++; } - ret.addElement(v2); - i++; - } - return ret; - }; -} diff --git a/src/test/resources/javFiles/bytecode/Merge.jav b/src/test/resources/javFiles/bytecode/Merge.jav deleted file mode 100644 index 9240146e..00000000 --- a/src/test/resources/javFiles/bytecode/Merge.jav +++ /dev/null @@ -1,20 +0,0 @@ -import java.util.List; -import java.lang.Integer; -import java.util.Collection; - -class Merge { - - merge(a, b) { - a.addAll(b); - return a; - } - - - - sort(in){ - var firstHalf = in.subList(1,2); - var secondHalf = in.subList(1,2); - return merge(sort(firstHalf), sort(secondHalf)); - } - -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Methods.jav b/src/test/resources/javFiles/bytecode/Methods.jav deleted file mode 100644 index 3c46739d..00000000 --- a/src/test/resources/javFiles/bytecode/Methods.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.Integer; - -class Methods { - - m(a,b){ - var c=a+b; - return c; - } - - method2(x){ - Integer i = this.m(x,2); - return i; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/OL.jav b/src/test/resources/javFiles/bytecode/OL.jav deleted file mode 100644 index 700e50f0..00000000 --- a/src/test/resources/javFiles/bytecode/OL.jav +++ /dev/null @@ -1,22 +0,0 @@ -import java.lang.String; -import java.lang.Integer; -import java.lang.Double; - - - -public class OL { - - m(x) { return x + x; } - -} - - - -public class OLMain { - - main(x) { - var ol; - ol = new OL(); - return ol.m(x); - } -} diff --git a/src/test/resources/javFiles/bytecode/Op.jav b/src/test/resources/javFiles/bytecode/Op.jav deleted file mode 100644 index 082f48d8..00000000 --- a/src/test/resources/javFiles/bytecode/Op.jav +++ /dev/null @@ -1,16 +0,0 @@ -import java.lang.Integer; -import java.lang.String; -import java.lang.Long; -import java.lang.Float; -import java.lang.Double; -import java.lang.Boolean; -import java.lang.Short; -import java.lang.Byte; - -public class Op { - - m(a, b) { - //var c = a+b; - return a+b; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Op2.jav b/src/test/resources/javFiles/bytecode/Op2.jav deleted file mode 100644 index 9d446eb2..00000000 --- a/src/test/resources/javFiles/bytecode/Op2.jav +++ /dev/null @@ -1,11 +0,0 @@ -import java.lang.Integer; -import java.lang.String; - -public class Op2 { - m(){ - var x = ""; - var a = 5+x; - - return a; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/OverlaodGen.jav b/src/test/resources/javFiles/bytecode/OverlaodGen.jav deleted file mode 100644 index d5946496..00000000 --- a/src/test/resources/javFiles/bytecode/OverlaodGen.jav +++ /dev/null @@ -1,11 +0,0 @@ -import java.util.Vector; - -class OverlaodGen { - void method(Vector v) { -// Integer i = v.get(0); - } - - void method(Vector v) { -// String s = v.get(0); - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Overloading.jav b/src/test/resources/javFiles/bytecode/Overloading.jav deleted file mode 100644 index fb48fe0f..00000000 --- a/src/test/resources/javFiles/bytecode/Overloading.jav +++ /dev/null @@ -1,18 +0,0 @@ -import java.lang.String; - -public class Overloading{ - - test(x){ - return x.methode(); - } - - methode(){ - return "Overloading"; - } -} - -public class Overloading2{ - methode(){ - return "Overloading2"; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Plus.jav b/src/test/resources/javFiles/bytecode/Plus.jav deleted file mode 100644 index 1cdecc8c..00000000 --- a/src/test/resources/javFiles/bytecode/Plus.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.Integer; -import java.lang.String; - -public class Plus { - - m(a,b) { - return a+b; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/PostIncDec.jav b/src/test/resources/javFiles/bytecode/PostIncDec.jav deleted file mode 100644 index 29c2ef17..00000000 --- a/src/test/resources/javFiles/bytecode/PostIncDec.jav +++ /dev/null @@ -1,27 +0,0 @@ -import java.lang.Integer; - -public class PostIncDec { - m() { - var i = 0; - i++; - return i; - } - - m2() { - var i = 0; - var j = i++; - return j; - } - - d() { - var i = 0; - i--; - return i; - } - - d2() { - var i = 0; - var j = i--; - return j; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/PreInc.jav b/src/test/resources/javFiles/bytecode/PreInc.jav deleted file mode 100644 index 011501f1..00000000 --- a/src/test/resources/javFiles/bytecode/PreInc.jav +++ /dev/null @@ -1,28 +0,0 @@ -import java.lang.Integer; - -public class PreInc { - m() { - var i = 0; - ++i; - return i; - } - - m2() { - var i = 0; - var j = ++i; - return j; - } - - d() { - var i = 0; - --i; - return i; - } - - d2() { - var i = 0; - var j = --i; - return j; - } - -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/RecursiveMeth.jav b/src/test/resources/javFiles/bytecode/RecursiveMeth.jav deleted file mode 100644 index be35a43c..00000000 --- a/src/test/resources/javFiles/bytecode/RecursiveMeth.jav +++ /dev/null @@ -1,5 +0,0 @@ -public class RecursiveMeth{ - public Integer test(){ - return this.test(); - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/RelOps.jav b/src/test/resources/javFiles/bytecode/RelOps.jav deleted file mode 100644 index 0fdd2cff..00000000 --- a/src/test/resources/javFiles/bytecode/RelOps.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; - -public class RelOps { - m(a,b){ - return a a){ - a = merge(a,a); - } -*/ -} diff --git a/src/test/resources/javFiles/bytecode/StaticM.jav b/src/test/resources/javFiles/bytecode/StaticM.jav deleted file mode 100644 index 66890033..00000000 --- a/src/test/resources/javFiles/bytecode/StaticM.jav +++ /dev/null @@ -1,10 +0,0 @@ -public class StaticM { - - public static void m() { - System.out.println("Test"); - } - - public static void m2() { - m(); - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/SubMatrix.jav b/src/test/resources/javFiles/bytecode/SubMatrix.jav deleted file mode 100644 index f761321c..00000000 --- a/src/test/resources/javFiles/bytecode/SubMatrix.jav +++ /dev/null @@ -1,13 +0,0 @@ -import java.util.Vector; -import java.lang.Integer; - -public class Matrix2 extends Vector { - -} - -public class SubMatrix extends Matrix2 { - m(){ - Vector v = new Vector(); - v.add(1); - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Tph.jav b/src/test/resources/javFiles/bytecode/Tph.jav deleted file mode 100644 index 4a49ac46..00000000 --- a/src/test/resources/javFiles/bytecode/Tph.jav +++ /dev/null @@ -1,12 +0,0 @@ -public class Tph { - - m(a,b){ - var c = m2(b); -// return a; - return m2(b); - } - - m2(b){ - return b; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Tph2.jav b/src/test/resources/javFiles/bytecode/Tph2.jav deleted file mode 100644 index c957eae6..00000000 --- a/src/test/resources/javFiles/bytecode/Tph2.jav +++ /dev/null @@ -1,10 +0,0 @@ -public class Tph2 { - m(a,b){ - var c = m2(a,b); - return a; - } - - m2(a,b){ - return b; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Tph3.jav b/src/test/resources/javFiles/bytecode/Tph3.jav deleted file mode 100644 index f2bcd2ef..00000000 --- a/src/test/resources/javFiles/bytecode/Tph3.jav +++ /dev/null @@ -1,13 +0,0 @@ -public class Tph3 { -// m(a,b){ -// var c = m2(a,b); -// return c; -// } -// -// m2(a,b){ -// return m(a,b); -// } - m1(x, y) { m2(x); x = y; } - - m2(y) { m1(y, y); } -} diff --git a/src/test/resources/javFiles/bytecode/Tph4.jav b/src/test/resources/javFiles/bytecode/Tph4.jav deleted file mode 100644 index 1eb529de..00000000 --- a/src/test/resources/javFiles/bytecode/Tph4.jav +++ /dev/null @@ -1,12 +0,0 @@ -public class Tph4{ - m(a,b){ - var c = m2(b); - var d = m2(c); - return a; - } - - m2(b){ - return b - } - -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Tph5.jav b/src/test/resources/javFiles/bytecode/Tph5.jav deleted file mode 100644 index e73cfa2c..00000000 --- a/src/test/resources/javFiles/bytecode/Tph5.jav +++ /dev/null @@ -1,13 +0,0 @@ -public class Tph5 { -// m(a,b,c){ -// a = c; -// b = c; -// return a; -// } - - m(x,y){ - x = m2(y); - } - - m2(y) { return y; } -} diff --git a/src/test/resources/javFiles/bytecode/VectorAdd.jav b/src/test/resources/javFiles/bytecode/VectorAdd.jav deleted file mode 100644 index 814f46c2..00000000 --- a/src/test/resources/javFiles/bytecode/VectorAdd.jav +++ /dev/null @@ -1,19 +0,0 @@ -import java.util.Vector; -import java.lang.Integer; -import java.lang.String; -//import java.lang.Byte; -//import java.lang.Boolean; - -public class VectorAdd { - - add(v1, v2) { - var ret = new Vector(); - var i = 0; - var erg; - while(i < v1.size()) { - erg = v1.elementAt(i) + v2.elementAt(i); - ret.addElement(erg); - } - return ret; - } -} diff --git a/src/test/resources/javFiles/bytecode/VoidMeth.jav b/src/test/resources/javFiles/bytecode/VoidMeth.jav deleted file mode 100644 index 6b3ab212..00000000 --- a/src/test/resources/javFiles/bytecode/VoidMeth.jav +++ /dev/null @@ -1,4 +0,0 @@ -public class VoidMeth{ - public void test(){ - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/WC.jav b/src/test/resources/javFiles/bytecode/WC.jav deleted file mode 100644 index 389a4fcd..00000000 --- a/src/test/resources/javFiles/bytecode/WC.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.lang.Integer; -import java.util.List; -public class WC { - - void m (List a, List b) { - - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/While.jav b/src/test/resources/javFiles/bytecode/While.jav deleted file mode 100644 index cd2139a6..00000000 --- a/src/test/resources/javFiles/bytecode/While.jav +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.Integer; -import java.lang.Long; -import java.lang.Double; - -public class While { - m(x) { - while(x < 2) { - x = x+1; - } - return x; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/Y.jav b/src/test/resources/javFiles/bytecode/Y.jav deleted file mode 100644 index 3c3e204d..00000000 --- a/src/test/resources/javFiles/bytecode/Y.jav +++ /dev/null @@ -1,28 +0,0 @@ -import java.lang.Integer; - -class Y { - y; - //factorial; - - Y() { - y = f -> t -> f.apply(y.apply(f)).apply(t); - //factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); }); - } -} - -/* -ergibt Parse-Error -class fac1 { - factorial; - - fac1() { - var y; - y = new Y<>().y; - factorial = y.apply(f -> n -> { if (n == 0) return 1; else return n * f.apply(n - 1); }); - } - public static void main(String args[]) { - System.out.println(new fac1().factorial.apply(3)); - } - -} -*/ \ No newline at end of file diff --git a/src/test/resources/javFiles/bytecode/applyLambda.jav b/src/test/resources/javFiles/bytecode/applyLambda.jav deleted file mode 100644 index 331bfbfe..00000000 --- a/src/test/resources/javFiles/bytecode/applyLambda.jav +++ /dev/null @@ -1,16 +0,0 @@ -import java.util.Vector; -class Apply { } - -public class applyLambda { - - m () { - var lam1 = (x) -> { - return x; - }; - - return lam1.apply(new Apply()); - //return lam1; - //return new Vector(); - } -} - diff --git a/src/test/resources/javFiles/parser/AntlrTest.jav b/src/test/resources/javFiles/parser/AntlrTest.jav deleted file mode 100644 index 31ab067d..00000000 --- a/src/test/resources/javFiles/parser/AntlrTest.jav +++ /dev/null @@ -1,6 +0,0 @@ -class Test{ -method(){ - if(true)i++; - if(true)i--; - else i++; -}} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/BoundedParameter.jav b/src/test/resources/javFiles/parser/BoundedParameter.jav deleted file mode 100644 index 6d7518a9..00000000 --- a/src/test/resources/javFiles/parser/BoundedParameter.jav +++ /dev/null @@ -1,3 +0,0 @@ -class Matrix{ - String op = "String"; -} diff --git a/src/test/resources/javFiles/parser/CastTest.jav b/src/test/resources/javFiles/parser/CastTest.jav deleted file mode 100644 index 86ca7519..00000000 --- a/src/test/resources/javFiles/parser/CastTest.jav +++ /dev/null @@ -1,8 +0,0 @@ - -class CastTest{ -void methode(){ - Object a; - String b; - a = (Object) b; -} -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/ExtendsTest.jav b/src/test/resources/javFiles/parser/ExtendsTest.jav deleted file mode 100644 index 9103f463..00000000 --- a/src/test/resources/javFiles/parser/ExtendsTest.jav +++ /dev/null @@ -1,4 +0,0 @@ -class C1 extends Object -{ - m(para) { return para; } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/FeatherWeightJava.jav b/src/test/resources/javFiles/parser/FeatherWeightJava.jav deleted file mode 100644 index e607b12a..00000000 --- a/src/test/resources/javFiles/parser/FeatherWeightJava.jav +++ /dev/null @@ -1,11 +0,0 @@ - -class FeatherWeightJava { - mt4(a,b,c) { return a.add(b).sub(c) ; } - - mt1(a) {return a; } - - mt2(a) {return a.f; } - - mt3(a) {return a.add(); } -} - diff --git a/src/test/resources/javFiles/parser/FieldInitializationTest.jav b/src/test/resources/javFiles/parser/FieldInitializationTest.jav deleted file mode 100644 index f7818cc3..00000000 --- a/src/test/resources/javFiles/parser/FieldInitializationTest.jav +++ /dev/null @@ -1,3 +0,0 @@ -class FieldInitializationTest{ - var var = "hallo"; -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/FieldVarTest.jav b/src/test/resources/javFiles/parser/FieldVarTest.jav deleted file mode 100644 index 6e897824..00000000 --- a/src/test/resources/javFiles/parser/FieldVarTest.jav +++ /dev/null @@ -1,5 +0,0 @@ -package test; - -class Test{ -Typ a; -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/GenericFieldVarTest.jav b/src/test/resources/javFiles/parser/GenericFieldVarTest.jav deleted file mode 100644 index a47b41eb..00000000 --- a/src/test/resources/javFiles/parser/GenericFieldVarTest.jav +++ /dev/null @@ -1,3 +0,0 @@ -class Test{ - A var; -} diff --git a/src/test/resources/javFiles/parser/ImportTest.jav b/src/test/resources/javFiles/parser/ImportTest.jav deleted file mode 100644 index 2de55cee..00000000 --- a/src/test/resources/javFiles/parser/ImportTest.jav +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.*; - -class ImportTest{ -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/ImportTest2.jav b/src/test/resources/javFiles/parser/ImportTest2.jav deleted file mode 100644 index 3492e31c..00000000 --- a/src/test/resources/javFiles/parser/ImportTest2.jav +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.ArrayList; - -class ImportTest{ -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/ImportTestGeneric.jav b/src/test/resources/javFiles/parser/ImportTestGeneric.jav deleted file mode 100644 index 094f4c5e..00000000 --- a/src/test/resources/javFiles/parser/ImportTestGeneric.jav +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.List; - -class ImportTest{ - List test; -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/NewTest.jav b/src/test/resources/javFiles/parser/NewTest.jav deleted file mode 100644 index 992a2e8d..00000000 --- a/src/test/resources/javFiles/parser/NewTest.jav +++ /dev/null @@ -1,5 +0,0 @@ - -class NewTest { -main() { return new NewTest<>().mt(new NewTest(1) , new NewTest(2) , new -NewTest(3)); } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/OpratorTest.jav b/src/test/resources/javFiles/parser/OpratorTest.jav deleted file mode 100644 index 2764adf4..00000000 --- a/src/test/resources/javFiles/parser/OpratorTest.jav +++ /dev/null @@ -1,12 +0,0 @@ -import java.lang.Integer; - -class OpratorTest { - m(Integer a, Integer b) { - c = a+b; -// d = a-b; -// e = a*b; -// f = a/b; - - return c; - } -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/PackageNameTest.jav b/src/test/resources/javFiles/parser/PackageNameTest.jav deleted file mode 100644 index 53c889b7..00000000 --- a/src/test/resources/javFiles/parser/PackageNameTest.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.Integer; -import java.lang.Comparable; - -class PackageNameTest{ -java.lang.Integer test(a){return a;} - -Comparable test2(a){return a;} - -} \ No newline at end of file diff --git a/src/test/resources/javFiles/parser/StatementsTest.jav b/src/test/resources/javFiles/parser/StatementsTest.jav deleted file mode 100644 index 891dff12..00000000 --- a/src/test/resources/javFiles/parser/StatementsTest.jav +++ /dev/null @@ -1,8 +0,0 @@ -class Statements{ - -public void methodeTest(){ - methodeTest(); - return null; -} - -} diff --git a/src/test/resources/javFiles/parser/StructuralTypes.jav b/src/test/resources/javFiles/parser/StructuralTypes.jav deleted file mode 100644 index b3c210c8..00000000 --- a/src/test/resources/javFiles/parser/StructuralTypes.jav +++ /dev/null @@ -1,5 +0,0 @@ - -class A { - mt(x, y, z) { return x.sub(y).add(z); } -} - diff --git a/src/test/resources/javFiles/parser/WhileTest.jav b/src/test/resources/javFiles/parser/WhileTest.jav deleted file mode 100644 index 2ce192bd..00000000 --- a/src/test/resources/javFiles/parser/WhileTest.jav +++ /dev/null @@ -1,14 +0,0 @@ -class WhileTest{ - void methode(){ - Boolean test; - do{ - test=test; - }while(test); - - - while(test){ - test = test; - } - return; - } -} \ No newline at end of file diff --git a/src/test/resources/testBytecode/Field.java b/src/test/resources/testBytecode/Field.java deleted file mode 100644 index 50002082..00000000 --- a/src/test/resources/testBytecode/Field.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Field{ - public void m(){ - MethFieldVar mF = new MethFieldVar(); - mF.s1 = "Field S1"; - } -} diff --git a/src/test/resources/testBytecode/Import.java b/src/test/resources/testBytecode/Import.java deleted file mode 100644 index f3519acb..00000000 --- a/src/test/resources/testBytecode/Import.java +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.Vector; - -class Import { - void methode(){ - Vector v = new Vector(); - v.add(v); - } -} diff --git a/src/test/resources/testBytecode/Lam1.java b/src/test/resources/testBytecode/Lam1.java deleted file mode 100644 index 142feed2..00000000 --- a/src/test/resources/testBytecode/Lam1.java +++ /dev/null @@ -1,10 +0,0 @@ -import java.util.function.Function; -public class Lam1{ - public Lam1() { - Function fun = (x) -> x+"1"; - fun.apply("2"); - - Runnable lam = () -> System.out.println("lambda"); - lam.run(); - } -} diff --git a/src/test/resources/testBytecode/LamRun.java b/src/test/resources/testBytecode/LamRun.java deleted file mode 100644 index fdaf0852..00000000 --- a/src/test/resources/testBytecode/LamRun.java +++ /dev/null @@ -1,8 +0,0 @@ -public class LamRun{ - - public void mRun(){ - - Runnable lam = () -> System.out.println("lambda"); - lam.run(); - } -} diff --git a/src/test/resources/testBytecode/MethFieldVar.java b/src/test/resources/testBytecode/MethFieldVar.java deleted file mode 100644 index 74086a01..00000000 --- a/src/test/resources/testBytecode/MethFieldVar.java +++ /dev/null @@ -1,38 +0,0 @@ -public class MethFieldVar{ - String s1;// = ""; - String s2; - -/* public void meth(Integer i, String j, Boolean b){ - //String local = "a"; - //int localL = local.length(); - //int l = s.length(); - String s = null; - //s = ""; - //return s.length();//l+localL; - } -*/ - public void mm(){ -// return "mm"; - } - public void m2(){ - System.out.println(""); - // Math.abs(1); - // String lV = "local"; - // s1 = "1"; - // s1.concat("2"); - s2 = s1; - - mm(); - - Clazz i = new Clazz(); - - Runnable lam = ()->{ - String test = ""; - String b = "b"; - test = b; - System.out.println(test); - }; - } -} - -class Clazz{} diff --git a/src/test/resources/testBytecode/Subclass.java b/src/test/resources/testBytecode/Subclass.java deleted file mode 100644 index 3e8b5853..00000000 --- a/src/test/resources/testBytecode/Subclass.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - } -} diff --git a/src/test/resources/testBytecode/SuperTest.java b/src/test/resources/testBytecode/SuperTest.java deleted file mode 100644 index 1b6ac268..00000000 --- a/src/test/resources/testBytecode/SuperTest.java +++ /dev/null @@ -1,14 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} - -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - - } -} diff --git a/src/test/resources/testBytecode/Superclass.java b/src/test/resources/testBytecode/Superclass.java deleted file mode 100644 index d58089de..00000000 --- a/src/test/resources/testBytecode/Superclass.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} diff --git a/src/test/resources/testBytecode/TestMyTest.java b/src/test/resources/testBytecode/TestMyTest.java deleted file mode 100644 index e1305f76..00000000 --- a/src/test/resources/testBytecode/TestMyTest.java +++ /dev/null @@ -1,11 +0,0 @@ -class TestMyTest{ -public static void main(String[] a){ - //test1 - //new TestClass(); - //test if statement - //new TestIf(new Boolean(true)); - // test lambda - //new TestClass(); - new LamRun(); -} -} diff --git a/src/test/resources/testBytecode/testF.java b/src/test/resources/testBytecode/testF.java deleted file mode 100644 index fa4a50b7..00000000 --- a/src/test/resources/testBytecode/testF.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets(){ - public static void main(String[] args){ - new tetsF(); - } -} diff --git a/src/test/resources/testBytecode/testTets.java b/src/test/resources/testBytecode/testTets.java deleted file mode 100644 index 4f95cbc0..00000000 --- a/src/test/resources/testBytecode/testTets.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets{ - public static void main(String[] args){ - new TetsF(); - } -} diff --git a/src/test/resources/testBytecode/testTetsF.java b/src/test/resources/testBytecode/testTetsF.java deleted file mode 100644 index fa4a50b7..00000000 --- a/src/test/resources/testBytecode/testTetsF.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets(){ - public static void main(String[] args){ - new tetsF(); - } -} 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 12/14] 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 9d93fa63fa7c7ef35f07294b7f62b45e982eaf82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 20 Feb 2019 18:33:27 +0100 Subject: [PATCH 13/14] new file: UnifyResultListener.java new file: model/hashKeyType.java --- .../unify/UnifyResultListener.java | 7 ++++++ .../unify/model/hashKeyType.java | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/model/hashKeyType.java diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java new file mode 100644 index 00000000..f490ccde --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.typeinference.unify; + +public interface UnifyResultListener { + + void onNewTypeResultFound(UnifyResultEvent evt); + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/hashKeyType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/hashKeyType.java new file mode 100644 index 00000000..dedfcd86 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/hashKeyType.java @@ -0,0 +1,25 @@ +package de.dhbwstuttgart.typeinference.unify.model; + +public class hashKeyType { + UnifyType realType; + + hashKeyType(UnifyType realType) { + this.realType= realType; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof hashKeyType) { + return realType.equals(((hashKeyType)obj).realType); + } + else + { + return false; + } + } + + @Override + public int hashCode() { + return realType.hashCode(); + } +} From 6a6e6b343d2597df45496a67d53c68b73f49d559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 21 Feb 2019 12:06:04 +0100 Subject: [PATCH 14/14] modified: ../../core/JavaTXCompiler.java modified: TypeUnifyTask.java NullWriter eingefuegt --- .../java/de/dhbwstuttgart/core/JavaTXCompiler.java | 14 +++++++++++--- .../typeinference/unify/TypeUnifyTask.java | 10 +++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 0be50fb5..6197aa19 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -39,7 +39,7 @@ import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import java.io.File; import java.io.FileOutputStream; -import java.io.FileWriter; +//import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.util.*; @@ -287,7 +287,11 @@ public class JavaTXCompiler { Set> results = new HashSet<>(); UnifyResultModel urm = null; try { - Writer logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + Writer logFile = new Writer() {//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + public void close() {} + public void flush() {} + public void write(char[] cbuf, int off, int len) { } + }; IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); @@ -423,7 +427,11 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); try { - Writer logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + Writer logFile = new Writer() {//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + public void close() {} + public void flush() {} + public void write(char[] cbuf, int off, int len) { } + }; IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1d383c66..f55c742a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -42,7 +42,7 @@ import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import de.dhbwstuttgart.typeinference.unify.model.Pair; import java.io.File; -import java.io.FileWriter; +//import java.io.FileWriter; import java.io.IOException; import java.io.Writer; @@ -160,9 +160,13 @@ public class TypeUnifyTask extends RecursiveTask>> { thNo = totalnoOfThread; writeLog("thNo2 " + thNo); try { - this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo)); + this.logFile = new Writer() {//FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo)); + public void close() {} + public void flush() {} + public void write(char[] cbuf, int off, int len) { } + }; } - catch (IOException e) { + catch (Exception e) { System.err.println("log-File nicht vorhanden"); } rules = new RuleSet(logFile);