diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 0be50fb5..03567487 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -52,7 +52,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; - Boolean resultmodel = true; + Boolean resultmodel = false; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -551,8 +551,8 @@ public class JavaTXCompiler { } /* UnifyResultModel End */ else { - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + //Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure)); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index bcc6ba80..804d497e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -115,7 +115,7 @@ public class TypeUnifyTask extends RecursiveTask>> { static int noBacktracking; - Integer noShortendElements = 0; + static Integer noShortendElements = 0; public TypeUnifyTask() { rules = new RuleSet(); @@ -615,25 +615,27 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair()); /* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */ - Optional optOrigPair = nextSetElem.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && (x.getPairOp().equals(PairOperator.EQUALSDOT)) - /* (x.getBasePair().getLhsType() instanceof PlaceholderType + Set sameEqSet = null; + if (variance != 2) { + Optional optOrigPair = nextSetElem.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && //(x.getPairOp().equals(PairOperator.EQUALSDOT)) + (x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()))) - */ + && x.getLhsType().equals(x.getBasePair().getRhsType())) )).findFirst(); - Set sameEqSet = null; - if (optOrigPair.isPresent()) { - UnifyPair origPair = optOrigPair.get(); - UnifyType tyVar; - if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { - tyVar = origPair.getRhsType(); - } - UnifyType tyVarEF = tyVar; - sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) - .filter(x -> ((x.getLhsType().equals(tyVarEF) || x.getRhsType().equals(tyVarEF)))) + if (optOrigPair.isPresent()) { + UnifyPair origPair = optOrigPair.get(); + UnifyType tyVar; + if (!((tyVar = origPair.getLhsType()) instanceof PlaceholderType)) { + tyVar = origPair.getRhsType(); + } + UnifyType tyVarEF = tyVar; + sameEqSet = fstElems.stream().map(xx -> xx.iterator().next()) + .filter(x -> (((x.getLhsType().equals(tyVarEF) && !(x.getRhsType() instanceof PlaceholderType)) + || (x.getRhsType().equals(tyVarEF) && !(x.getLhsType() instanceof PlaceholderType))))) .collect(Collectors.toCollection(HashSet::new)); + } } /* sameEqSet-Bestimmung Ende */ @@ -746,24 +748,24 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> aParDef = new HashSet<>(); /* PL 2019-03-11 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - Optional optAPair = a.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) - && (x.getPairOp().equals(PairOperator.EQUALSDOT)) - /* + if (variance != 2) { + Optional optAPair = a.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + && //(x.getPairOp().equals(PairOperator.EQUALSDOT)) (x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType - && x.getLhsType().equals(x.getBasePair().getRhsType()))) - */ + && x.getLhsType().equals(x.getBasePair().getRhsType())) )).findFirst(); - if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a - UnifyPair aPair = optAPair.get(); - //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); - writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { - a = null; - noShortendElements++; - continue; + if (optAPair.isPresent()) {//basepair ist entweder a <. Ty oder ty <. a + UnifyPair aPair = optAPair.get(); + //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); + writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); + if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + a = null; + noShortendElements++; + continue; + } } } /* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ @@ -792,7 +794,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + Optional optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && ((x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType @@ -877,7 +879,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* PL 2019-03-13 Anfang eingefuegt Vergleich mit anderen Paaren ggf. loeschen */ - optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) + Optional optAPair = nSaL.stream().filter(x -> (x.getBasePair() != null && x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) && ((x.getBasePair().getLhsType() instanceof PlaceholderType && x.getLhsType().equals(x.getBasePair().getLhsType())) || (x.getBasePair().getRhsType() instanceof PlaceholderType @@ -888,7 +890,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyPair aPair = optAPair.get(); //writeLog("optOrigPair: " + optOrigPair + " " + "aPair: " + aPair+ " " + "aPair.basePair(): " + aPair.getBasePair()); writeLog("variance: " + new Integer(variance).toString() + "sameEqSet:" + sameEqSet); - if (variance != 2 && !sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { + if (!sameEqSet.isEmpty() && !checkA(aPair, sameEqSet, elems, result)) { nSaL = null; noShortendElements++; continue; @@ -1335,18 +1337,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } protected Boolean checkA (UnifyPair aPair, Set sameEqSet, Set> elems, Set> result) { - //if (aPair.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT)) - //{ - writeLog("checkA: " + aPair); - //Set sameEqSet = elems.stream().map(xx -> xx.iterator().next()) - // .filter(x -> ((x.getLhsType().equals(aPair.getLhsType()) || x.getRhsType().equals(aPair.getLhsType())))) - // .collect(Collectors.toCollection(HashSet::new)); - //consideredElements.addAll(sameEqSet); - Boolean wrong = false; + writeLog("checkA: " + aPair + "sameEqSet: " + sameEqSet); for (UnifyPair sameEq : sameEqSet) { - //writeLog("x1 Original:\n" + x1.toString()); if (sameEq.getLhsType() instanceof PlaceholderType) { - //UnifyPair type = a.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); Set unitedSubst = new HashSet<>(aPair.getSubstitution()); unitedSubst.addAll(sameEq.getSubstitution()); @@ -1356,11 +1349,11 @@ public class TypeUnifyTask extends RecursiveTask>> { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); } + //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); return false; } } else { - //UnifyPair type = y.stream().filter(z -> z.getLhsType().equals(lhsType)).findFirst().get(); Set localEq = new HashSet<>(); Set unitedSubst = new HashSet<>(aPair.getSubstitution()); unitedSubst.addAll(sameEq.getSubstitution()); @@ -1370,12 +1363,12 @@ public class TypeUnifyTask extends RecursiveTask>> { if (result.isEmpty() || isUndefinedPairSetSet(result)) { result.addAll(localRes); } + //writeLog("FALSE: " + aPair + "sameEqSet: " + sameEqSet); return false; } } - //writeLog("x1 nach Loeschung von " + sameEq.toString()+" :\n" + x1.toString()); } - //} + //writeLog("TRUE: " + aPair + "sameEqSet: " + sameEqSet); return true; } diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 29505161..0f45a91b 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -4,7 +4,7 @@ import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; -public class Matrix extends Vector> { +public class Matrix extends Vector> { Matrix () { } @@ -16,7 +16,7 @@ public class Matrix extends Vector> { // Boolean a = this.add(vv.elementAt(i)); this.add(vv.elementAt(i)); i=i+1; - } + } } mul(m) {