From 20abd181b6de312e160863197fc611db936a3544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 28 Dec 2018 19:37:45 +0100 Subject: [PATCH] modified: ../../pom.xml modified: ../../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Abfrage, ob OderConstraints empty sind, bei der Unify-Abbruchbedingungen eingefuegt modified: ../../src/test/java/bytecode/BinaryTest.java modified: ../../src/test/java/bytecode/MatrixTest.java modified: ../../src/test/java/bytecode/applyLambdaTest.java Pfadanpassungen --- pom.xml | 4 +-- .../typeinference/unify/TypeUnifyTask.java | 31 +++++++++++++------ src/test/java/bytecode/BinaryTest.java | 4 +-- src/test/java/bytecode/MatrixTest.java | 4 +-- src/test/java/bytecode/applyLambdaTest.java | 4 +-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 3c15eec5..d69740e0 100644 --- a/pom.xml +++ b/pom.xml @@ -140,7 +140,7 @@ - + org.apache.maven.plugins maven-compiler-plugin diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 306552b3..a28f45df 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -520,12 +520,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); - List>> oderConstraintsOutput = new ArrayList<>(oderConstraints); + 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. @@ -616,7 +617,8 @@ public class TypeUnifyTask extends RecursiveTask>> { * 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. @@ -636,17 +638,20 @@ public class TypeUnifyTask extends RecursiveTask>> { } 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)) { - logFile.write(eqPrime.toString()+"\n"); + logFile.write("eqPrime:" + eqPrime.toString()+"\n"); logFile.flush(); } } - catch (IOException e) { } + catch (IOException e) { + System.err.println("log-File nicht vorhanden"); + } eqPrimePrimeSet.add(eqPrime); } else if(eqPrimePrime.isPresent()) { @@ -808,14 +813,19 @@ public class TypeUnifyTask extends RecursiveTask>> { { //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 + 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)); 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)); + 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)); //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));; @@ -1254,6 +1264,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * (as in case 1 where sigma is added to the innermost set). */ protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { + oderConstraintsOutput.addAll(oderConstraintsInput); List>>> result = new ArrayList<>(9); // Init all 8 cases + 9. Case: oderConstraints @@ -1298,6 +1309,8 @@ public class TypeUnifyTask extends RecursiveTask>> { 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))); diff --git a/src/test/java/bytecode/BinaryTest.java b/src/test/java/bytecode/BinaryTest.java index 84f102b7..aad81def 100644 --- a/src/test/java/bytecode/BinaryTest.java +++ b/src/test/java/bytecode/BinaryTest.java @@ -23,10 +23,10 @@ public class BinaryTest { @BeforeClass public static void setUpBeforeClass() throws Exception { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/BinaryInMeth.jav"; + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BinaryInMeth.jav"; fileToTest = new File(path); compiler = new JavaTXCompiler(fileToTest); - pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; compiler.generateBytecode(pathToClassFile); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("BinaryInMeth"); diff --git a/src/test/java/bytecode/MatrixTest.java b/src/test/java/bytecode/MatrixTest.java index cd0a20b7..c5dae3df 100644 --- a/src/test/java/bytecode/MatrixTest.java +++ b/src/test/java/bytecode/MatrixTest.java @@ -28,10 +28,10 @@ public class MatrixTest { @Test public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav"; + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Matrix.jav"; fileToTest = new File(path); compiler = new JavaTXCompiler(fileToTest); - pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; compiler.generateBytecode(pathToClassFile); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("Matrix"); diff --git a/src/test/java/bytecode/applyLambdaTest.java b/src/test/java/bytecode/applyLambdaTest.java index c7b5d7ad..3c7ea452 100644 --- a/src/test/java/bytecode/applyLambdaTest.java +++ b/src/test/java/bytecode/applyLambdaTest.java @@ -25,8 +25,8 @@ public class applyLambdaTest { path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/applyLambda.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("applyLambda"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance();