diff --git a/resources/bytecode/javFiles/Op1.jav b/resources/bytecode/javFiles/Op1.jav index 426569dc..9f62c5a5 100644 --- a/resources/bytecode/javFiles/Op1.jav +++ b/resources/bytecode/javFiles/Op1.jav @@ -1,9 +1,28 @@ import java.lang.Boolean; +import java.lang.Integer; public class Op1 { - public m() { + public not() { var b = false; var c = !b; return c; } + + public or() { + var a = 10; + var b = 20; + return a | b; + } + + public and() { + var a = 10; + var b = 20; + return a & b; + } + + public xor() { + var a = 10; + var b = 20; + return a ^ b; + } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 7bdb0489..f96df097 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -885,15 +885,15 @@ public class StatementGenerator { } private Expression convert(Java17Parser.BitwiseorexpressionContext expression) { - throw new NotImplementedException(); + return new BinaryExpr(BinaryExpr.Operator.OR, TypePlaceholder.fresh(expression.getStart()), convert(expression.expression(0)), convert(expression.expression(1)), expression.getStart()); } private Expression convert(Java17Parser.BitwisexorexpressionContext expression) { - throw new NotImplementedException(); + return new BinaryExpr(BinaryExpr.Operator.XOR, TypePlaceholder.fresh(expression.getStart()), convert(expression.expression(0)), convert(expression.expression(1)), expression.getStart()); } private Expression convert(Java17Parser.BitwiseandexpressionContext expression) { - throw new NotImplementedException(); + return new BinaryExpr(BinaryExpr.Operator.AND, TypePlaceholder.fresh(expression.getStart()), convert(expression.expression(0)), convert(expression.expression(1)), expression.getStart()); } private Expression convert(Java17Parser.EqualityexpressionContext expression) { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java index 9902f481..1aa8cd99 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java @@ -17,6 +17,7 @@ public class BinaryExpr extends Expression { MOD, // Modulo Operator % AND, // & OR, // | + XOR, // ^ DIV, // / LESSTHAN, // < BIGGERTHAN, // > diff --git a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java index c719c2c2..2efe35c3 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java @@ -103,8 +103,9 @@ public class StatementToTargetExpression implements ASTVisitor { case SUB -> new TargetBinaryOp.Sub(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); case MUL -> new TargetBinaryOp.Mul(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); case MOD -> new TargetBinaryOp.Rem(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); - case AND -> new TargetBinaryOp.And(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); - case OR -> new TargetBinaryOp.Or(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); + case AND -> new TargetBinaryOp.BAnd(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); + case OR -> new TargetBinaryOp.BOr(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); + case XOR -> new TargetBinaryOp.XOr(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); case DIV -> new TargetBinaryOp.Div(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); case LESSTHAN -> new TargetBinaryOp.Less(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); case BIGGERTHAN -> new TargetBinaryOp.Greater(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr)); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 4cf55ce9..8d2052af 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -259,7 +259,15 @@ public class TYPEStmt implements StatementVisitor { public void visit(BinaryExpr binary) { binary.lexpr.accept(this); binary.rexpr.accept(this); - 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.SUB)) { + 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.SUB) + || binary.operation.equals(BinaryExpr.Operator.OR) + || binary.operation.equals(BinaryExpr.Operator.AND) + || binary.operation.equals(BinaryExpr.Operator.XOR)) { + Set> numericAdditionOrStringConcatenation = new HashSet<>(); // TODO PL 2018-11-06 diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index 671e9529..ebc973cf 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -842,7 +842,10 @@ public class TestComplete { var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Op1.jav"); var clazz = classFiles.get("Op1"); var instance = clazz.getDeclaredConstructor().newInstance(); - assertEquals(clazz.getDeclaredMethod("m").invoke(instance), true); + assertEquals(clazz.getDeclaredMethod("not").invoke(instance), true); + assertEquals(clazz.getDeclaredMethod("or").invoke(instance), 10 | 20); + assertEquals(clazz.getDeclaredMethod("and").invoke(instance), 10 & 20); + assertEquals(clazz.getDeclaredMethod("xor").invoke(instance), 10 ^ 20); } @Ignore("Not implemented")