From 34e632b872fb87f50d02e4a6b47b469d67f76528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 24 May 2018 14:11:04 +0200 Subject: [PATCH 1/2] modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java Reduce ausgetauscht bei ArgPara und Returntype modified: ../../src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java isUndefinedPair korrigiert. modified: ../../test/bytecode/LambdaTest.java modified: ../../test/bytecode/javFiles/Plus.jav modified: ../../test/bytecode/javFiles/RelOps.jav --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 5 +++-- src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java | 4 ++-- src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 5 +++++ test/bytecode/LambdaTest.java | 2 +- test/bytecode/javFiles/Plus.jav | 2 +- test/bytecode/javFiles/RelOps.jav | 1 + 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 68bb2585..05edbaa1 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -121,8 +121,9 @@ public class JavaTXCompiler { System.out.println(xConsSet); Set paraTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType() instanceof TypePlaceholder) - .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get()) - .reduce((a,b) -> { a.addAll(b); return a;} ).get(); + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} ); Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 4dad9de6..c15f65fc 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -217,7 +217,7 @@ public class TYPEStmt implements StatementVisitor{ binary.operation.equals(BinaryExpr.Operator.MUL)|| binary.operation.equals(BinaryExpr.Operator.MOD)|| binary.operation.equals(BinaryExpr.Operator.ADD)){ - Set numericAdditionOrStringConcatenation = new HashSet<>(); + Set> numericAdditionOrStringConcatenation = new HashSet<>(); //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 @@ -273,7 +273,7 @@ public class TYPEStmt implements StatementVisitor{ binary.operation.equals(BinaryExpr.Operator.BIGGERTHAN) || binary.operation.equals(BinaryExpr.Operator.LESSTHAN)){ //eingefuegt PL 2018-05-24 - Set numericRelationConcatenation = new HashSet<>(); + Set> numericRelationConcatenation = new HashSet<>(); Constraint numeric = new Constraint<>(); numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 1d5ca564..d3448d49 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -586,8 +586,13 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean isUndefinedPairSet(Set s) { + if (s.size() >= 1 ) { Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y)); return ret; + } + else { + return false; + } } protected boolean isUndefinedPairSetSet(Set> s) { diff --git a/test/bytecode/LambdaTest.java b/test/bytecode/LambdaTest.java index 12e16829..f29690cb 100644 --- a/test/bytecode/LambdaTest.java +++ b/test/bytecode/LambdaTest.java @@ -13,7 +13,7 @@ public class LambdaTest { @Test public void generateBC() throws Exception { - path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Lambda2.jav"; + path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Lambda.jav"; fileToTest = new File(path); compiler = new JavaTXCompiler(fileToTest); compiler.generateBytecode(); diff --git a/test/bytecode/javFiles/Plus.jav b/test/bytecode/javFiles/Plus.jav index 86b4eb36..4d425bf0 100644 --- a/test/bytecode/javFiles/Plus.jav +++ b/test/bytecode/javFiles/Plus.jav @@ -1,4 +1,4 @@ -//import java.lang.Integer; +import java.lang.Integer; public class Plus { diff --git a/test/bytecode/javFiles/RelOps.jav b/test/bytecode/javFiles/RelOps.jav index d75ee2f3..0fdd2cff 100644 --- a/test/bytecode/javFiles/RelOps.jav +++ b/test/bytecode/javFiles/RelOps.jav @@ -1,4 +1,5 @@ import java.lang.Integer; +import java.lang.Boolean; public class RelOps { m(a,b){ From 65531ac12e41e868e747a72303baa1f79367dd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 24 May 2018 16:20:57 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=09modified:=20=20=20../../src/de/dhbwstutt?= =?UTF-8?q?gart/syntaxtree/factory/UnifyTypeFactory.java=20=09modified:=20?= =?UTF-8?q?=20=20../../src/de/dhbwstuttgart/typeinference/constraints/Pair?= =?UTF-8?q?.java=20=09modified:=20=20=20../../src/de/dhbwstuttgart/typeinf?= =?UTF-8?q?erence/typeAlgo/TYPEStmt.java=20=09modified:=20=20=20../../src/?= =?UTF-8?q?de/dhbwstuttgart/typeinference/unify/RuleSet.java=20=09modified?= =?UTF-8?q?:=20=20=20../../src/de/dhbwstuttgart/typeinference/unify/TypeUn?= =?UTF-8?q?ifyTask.java=20=09modified:=20=20=20../../src/de/dhbwstuttgart/?= =?UTF-8?q?typeinference/unify/model/PairOperator.java=20Einf=C3=BChrung?= =?UTF-8?q?=20eines=20neuen=20Operators=20SMALLERNEQDOT=20um=20Ungleichung?= =?UTF-8?q?en=20a=20> numericRelationConcatenation = new HashSet<>(); Constraint numeric = new Constraint<>(); numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT)); @@ -308,7 +308,13 @@ public class TYPEStmt implements StatementVisitor{ //***ACHTUNG: Moeglicherweise oder und und-Contraint falsch constraintsSet.addOderConstraint(numericRelationConcatenation); //***ACHTUNG: Moeglicherweise oder und und-Contraint falsch - + */ + //Testeise eingefuegt PL 2018-05-24 + constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT)); + constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT)); + //Rückgabetyp ist Boolean + constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.SMALLERDOT)); + //auskommentiert PL 2018-05-24 //constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT)); //constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 5631724b..8c1c60ae 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -369,9 +369,13 @@ public class RuleSet implements IRuleSet{ @Override public boolean erase1(UnifyPair pair, IFiniteClosure fc) { - if(pair.getPairOp() != PairOperator.SMALLERDOT) + if((pair.getPairOp() != PairOperator.SMALLERDOT) && (pair.getPairOp() != PairOperator.SMALLERNEQDOT)) return false; + if ((pair.getPairOp() == PairOperator.SMALLERNEQDOT) && (pair.getLhsType().equals(pair.getRhsType()))) { + return false; + } + UnifyType lhsType = pair.getLhsType(); if(!(lhsType instanceof ReferenceType) && !(lhsType instanceof PlaceholderType)) return false; diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d3448d49..bd50d5de 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -794,10 +794,15 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType rhsType = pair.getRhsType(); // Case 1: (a <. Theta') - if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) { + if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); Set> x1 = unifyCase1(pair, fc); + if (pairOp == PairOperator.SMALLERNEQDOT) { + Set remElem = new HashSet<>(); + remElem.add(pair.getRhsType()); + x1.remove(remElem); + } //System.out.println(x1); result.get(0).add(x1); if (x1.isEmpty()) { @@ -853,10 +858,15 @@ public class TypeUnifyTask extends RecursiveTask>> { // result.get(3).add(unifyCase4((PlaceholderType) lhsType, rhsType, fc)); // Case 5: (Theta <. a) - else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType) + else if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && rhsType instanceof PlaceholderType) if (first) { //writeLog(pair.toString()+"\n"); Set> x1 = unifyCase5(pair, fc); result.get(4).add(x1); + if (pairOp == PairOperator.SMALLERNEQDOT) { + Set remElem = new HashSet<>(); + remElem.add(pair.getLhsType()); + x1.remove(remElem); + } if (x1.isEmpty()) { undefined.add(pair); //Theta ist nicht im FC } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java b/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java index fd18f6c0..ea323c79 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java @@ -17,6 +17,12 @@ public enum PairOperator { */ SMALLERDOT, + /** + * The smallernedot operator for arguments (T / ... with the Supertype Number + */ + SMALLERNEQDOT, + /** * The smallerdot operator for arguments (T <.? P) is used to express that * T is an element of smArg(P) (or P is an element of grArg(T)) in a CONSTRAINT @@ -35,6 +41,7 @@ public enum PairOperator { switch (this) { case SMALLER: return "<"; case SMALLERDOT: return "<."; + case SMALLERNEQDOT: return "> { 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))); + //erg = add1(erg, mul1(v1.elementAt(k), + // m.elementAt(k).elementAt(j))); k++; } v2.addElement(new Integer(erg)); j++; }