diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index d4e6b5518..a3430577b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -319,13 +319,20 @@ 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; - else if(lhsType instanceof WildcardType) { + rhsSType = (ReferenceType) rhsType; + } + else if ((lhsType instanceof WildcardType) && (rhsType instanceof WildcardType)) { 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(); } @@ -334,7 +341,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; @@ -349,6 +357,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/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ab672f5e1..8b2c7c3ce 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -61,7 +61,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ private static int noOfThread = 0; private static int totalnoOfThread = 0; - private int thNo; + int thNo; protected boolean one = false; Integer MaxNoOfThreads = 4; @@ -709,12 +709,12 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 6 b) Build the union over everything. */ /* - * PL 2019-01-20: muss uebrprueft werden - */ + * PL 2019-01-22: geloescht + if(parallel) for(TypeUnifyTask fork : forks) eqPrimePrimeSet.addAll(fork.join()); - + */ /* * Step 7: Filter empty sets; */ @@ -881,9 +881,13 @@ public class TypeUnifyTask extends RecursiveTask>> { 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); - forks.add(forkOrig); + //forks.add(forkOrig); forkOrig.fork(); + FORK ENDE */ + synchronized (this) { writeLog("a in " + variance + " "+ a); writeLog("nextSetasListRest: " + nextSetasListRest.toString()); @@ -901,8 +905,18 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - //res = unify2(elems, eq, fc, parallel); - res = forkOrig.join(); + res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG + synchronized (this) { + res = forkOrig.join(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + noOfThread--; + //add_res.add(fork_res); + }; + FORK ENDE */ + for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -918,9 +932,13 @@ public class TypeUnifyTask extends RecursiveTask>> { 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); - forks.add(forkOrig); + //forks.add(forkOrig); forkOrig.fork(); + FORK ENDE */ + synchronized (this) { writeLog("a in " + variance + " "+ a); writeLog("nextSetasListRest: " + nextSetasListRest.toString()); @@ -938,8 +956,18 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - //res = unify2(elems, eq, fc, parallel); - res = forkOrig.join(); + res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG + synchronized (this) { + res = forkOrig.join(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + noOfThread--; + //add_res.add(fork_res); + }; + FORK ENDE */ + for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -949,17 +977,20 @@ public class TypeUnifyTask extends RecursiveTask>> { }; } } else { - if(parallel && (variance == 2) //&& noOfThread <= MaxNoOfThreads - ) { + if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { writeLog("var2einstieg"); 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); - forks.add(forkOrig); + //forks.add(forkOrig); forkOrig.fork(); + FORK ENDE */ + synchronized (this) { writeLog("a in " + variance + " "+ a); writeLog("nextSetasListRest: " + nextSetasListRest.toString()); @@ -975,8 +1006,18 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - //res = unify2(elems, eq, fc, parallel); - res = forkOrig.join(); + res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG + synchronized (this) { + res = forkOrig.join(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + noOfThread--; + //add_res.add(fork_res); //vermutlich falsch + }; + FORK ENDE */ + for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -1089,6 +1130,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)) { @@ -1096,6 +1158,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { + /* vorgezogen vor das if if (parallel) { for (Set> par_res : add_res) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { @@ -1116,7 +1179,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } } //break; - } + */ + /* nextSetasList = nextSetasListRest; */ /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet */ @@ -1137,6 +1201,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { if (variance == -1) { + /* vorgezogen vor das if if (parallel) { for (Set> par_res : add_res) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { @@ -1156,8 +1221,12 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } - //break; + //break; } + + } + */ + System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { @@ -1177,6 +1246,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); break; } else { if (variance == 2) { + /* vorgezogen vor das if if (parallel) { for (Set> par_res : add_res) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { @@ -1198,6 +1268,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } //break; } + */ }}} writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); }