From c72204428f6317656723f548d1a5ecaee576afad Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 7 Sep 2018 01:41:26 +0200 Subject: [PATCH] =?UTF-8?q?=3D=3D=20Operator=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SyntaxTreeGenerator/StatementGenerator.java | 13 ++++++++++--- .../syntaxtree/statement/BinaryExpr.java | 4 +++- .../typeinference/typeAlgo/TYPEStmt.java | 15 +++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 1c15f678..36cba603 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -583,7 +583,10 @@ public class StatementGenerator { if(expression.equalityExpression() == null){ return convert(expression.relationalExpression()); }else{ - throw new NotImplementedException(); + String operator = expression.getChild(1).getText(); + Expression leftSide = convert(expression.equalityExpression()); + Expression rightSide = convert(expression.relationalExpression()); + return new BinaryExpr(convertBinaryOperator(operator), TypePlaceholder.fresh(expression.getStart()), leftSide, rightSide, expression.getStart()); } } @@ -619,8 +622,12 @@ public class StatementGenerator { return BinaryExpr.Operator.BIGGERTHAN; }else if(operator.equals(">=")) { return BinaryExpr.Operator.BIGGEREQUAL; - } else if(operator.equals("<=")) { - return BinaryExpr.Operator.LESSEQUAL; + } else if(operator.equals("<=")) { + return BinaryExpr.Operator.LESSEQUAL; + } else if(operator.equals("==")) { + return BinaryExpr.Operator.EQUAL; + } else if(operator.equals("!=")) { + return BinaryExpr.Operator.NOTEQUAL; } else { throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java index bb631e04..4fab15cc 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java @@ -23,7 +23,9 @@ public class BinaryExpr extends Expression LESSTHAN, // < BIGGERTHAN, // > LESSEQUAL, // <= - BIGGEREQUAL // >= + BIGGEREQUAL, // >= + EQUAL, // == + NOTEQUAL // != } public final Operator operation; diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 32dc72ef..8e0a98b3 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -223,7 +223,8 @@ public class TYPEStmt implements StatementVisitor{ if(binary.operation.equals(BinaryExpr.Operator.DIV) || binary.operation.equals(BinaryExpr.Operator.MUL)|| binary.operation.equals(BinaryExpr.Operator.MOD)|| - binary.operation.equals(BinaryExpr.Operator.ADD)){ + binary.operation.equals(BinaryExpr.Operator.ADD)|| + binary.operation.equals(BinaryExpr.Operator.SUB)){ Set> numericAdditionOrStringConcatenation = new HashSet<>(); //Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer: @@ -303,7 +304,7 @@ public class TYPEStmt implements StatementVisitor{ }else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) || binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) || binary.operation.equals(BinaryExpr.Operator.BIGGERTHAN) || - binary.operation.equals(BinaryExpr.Operator.LESSTHAN)){ + binary.operation.equals(BinaryExpr.Operator.LESSTHAN)) { /* //eingefuegt PL 2018-05-24 Set> numericRelationConcatenation = new HashSet<>(); Constraint numeric = new Constraint<>(); @@ -340,18 +341,24 @@ 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)); //Rückgabetyp ist Boolean //constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT)); + }else if(binary.operation.equals(BinaryExpr.Operator.EQUAL) || binary.operation.equals(BinaryExpr.Operator.NOTEQUAL)){ + /*Auszug aus https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.21 + The equality operators may be used to compare two operands that are convertible (§5.1.8) to numeric type, or two operands of type boolean or Boolean, or two operands that are each of either reference type or the null type. All other cases result in a compile-time error. + */ + //Der Equals Operator geht mit fast allen Typen, daher werden hier keine Constraints gesetzt + constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.SMALLERDOT)); }else{ throw new NotImplementedException(); }