From 7fb4824f8d66bc6ce6ccb25575846923d1fe58f0 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Fri, 12 Apr 2024 15:40:22 +0200 Subject: [PATCH] Add modulo, fix #319 --- resources/bytecode/javFiles/Op1.jav | 6 ++++++ .../parser/SyntaxTreeGenerator/StatementGenerator.java | 2 ++ src/test/java/TestComplete.java | 1 + 3 files changed, 9 insertions(+) diff --git a/resources/bytecode/javFiles/Op1.jav b/resources/bytecode/javFiles/Op1.jav index 9f62c5a5..48af9df1 100644 --- a/resources/bytecode/javFiles/Op1.jav +++ b/resources/bytecode/javFiles/Op1.jav @@ -25,4 +25,10 @@ public class Op1 { var b = 20; return a ^ b; } + + public mod() { + var a = 10; + var b = 2; + 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 f96df097..02cad496 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -958,6 +958,8 @@ public class StatementGenerator { return BinaryExpr.Operator.EQUAL; } else if (operator.equals("!=")) { return BinaryExpr.Operator.NOTEQUAL; + } else if (operator.equals("%")) { + return BinaryExpr.Operator.MOD; } else { throw new NotImplementedException(); } diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index 3269aa22..6e743108 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -848,6 +848,7 @@ public class TestComplete { assertEquals(clazz.getDeclaredMethod("or").invoke(instance), 10 | 20); assertEquals(clazz.getDeclaredMethod("and").invoke(instance), 10 & 20); assertEquals(clazz.getDeclaredMethod("xor").invoke(instance), 10 ^ 20); + assertEquals(clazz.getDeclaredMethod("mod").invoke(instance), 10 % 2); } @Ignore("Not implemented")