From 4307371dee920ea0051039f68e4ee3a79fc594a8 Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Sun, 13 Nov 2022 13:47:24 +0100 Subject: [PATCH] Box test --- src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java | 3 ++- src/test/java/targetast/TestCodegen.java | 2 +- src/test/java/targetast/TestComplete.java | 1 + src/test/resources/bytecode/javFiles/Box.jav | 4 ---- src/test/resources/bytecode/javFiles/Box.java | 3 +++ 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java index e1744b4dc..bd6e09253 100755 --- a/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/target/bytecode/Codegen.java @@ -873,6 +873,7 @@ public class Codegen { mv.visitLabel(start); if (_for.termination() != null) generate(state, _for.termination()); + else mv.visitInsn(ICONST_1); mv.visitJumpInsn(IFEQ, end); generate(state, _for.body()); if (_for.increment() != null) { @@ -913,7 +914,7 @@ public class Codegen { break; } case TargetReturn ret: { - if (ret.expression() != null) { + if (ret.expression() != null && state.returnType != null) { generate(state, ret.expression()); convertTo(state, ret.expression().type(), state.returnType); boxPrimitive(state, state.returnType); diff --git a/src/test/java/targetast/TestCodegen.java b/src/test/java/targetast/TestCodegen.java index 46c4c834d..4661bc28b 100644 --- a/src/test/java/targetast/TestCodegen.java +++ b/src/test/java/targetast/TestCodegen.java @@ -37,7 +37,7 @@ public class TestCodegen { public static Map> generateClassFiles(String filename, ByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException { var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/", filename).toFile(); - var compiler = new JavaTXCompiler(file); + var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile())); var resultSet = compiler.typeInference(); var sourceFile = compiler.sourceFiles.get(file); var converter = new ASTToTargetAST(resultSet, sourceFile, classLoader); diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index ab42a8b6d..215e5b5aa 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -8,6 +8,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.TypeVariable; +import java.nio.file.Path; import java.util.Arrays; import java.util.Vector; diff --git a/src/test/resources/bytecode/javFiles/Box.jav b/src/test/resources/bytecode/javFiles/Box.jav index e83bde6d3..4859d6119 100644 --- a/src/test/resources/bytecode/javFiles/Box.jav +++ b/src/test/resources/bytecode/javFiles/Box.jav @@ -1,7 +1,3 @@ -class Box { - void m(A a) { } -} - class B { } class Box_Main extends B { m(b) { diff --git a/src/test/resources/bytecode/javFiles/Box.java b/src/test/resources/bytecode/javFiles/Box.java index e69de29bb..581e72560 100644 --- a/src/test/resources/bytecode/javFiles/Box.java +++ b/src/test/resources/bytecode/javFiles/Box.java @@ -0,0 +1,3 @@ +class Box { + void m(A a) { } +} \ No newline at end of file