From 521a1cbf3b611fd57e832d8d40c8c380c4739491 Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Tue, 8 May 2018 17:42:58 +0200 Subject: [PATCH] Bug 77 gefixt --- src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java | 12 ++++++++++++ test/bytecode/OpTest.java | 2 +- test/bytecode/javFiles/Op.jav | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 7cfd8e7dd..ce5d3deff 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -772,7 +772,19 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(Return aReturn) { + if(aReturn.retexpr instanceof BinaryExpr) + isBinaryExp = true; + aReturn.retexpr.accept(this); + + if (isBinaryExp) { + BinaryExpr binary = (BinaryExpr) aReturn.retexpr; + String lexpType = getResolvedType(binary.lexpr.getType()); + String rexpType = getResolvedType(binary.rexpr.getType()); + getValueOfIns(getLargerType(lexpType, rexpType)); + isBinaryExp = false; + } + mv.visitInsn(Opcodes.ARETURN); } diff --git a/test/bytecode/OpTest.java b/test/bytecode/OpTest.java index 39bde2b37..1d213a781 100644 --- a/test/bytecode/OpTest.java +++ b/test/bytecode/OpTest.java @@ -29,7 +29,7 @@ public class OpTest { fileToTest = new File(path); compiler = new JavaTXCompiler(fileToTest); compiler.generateBytecode(); - pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/examples/"; + pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("Op"); instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); diff --git a/test/bytecode/javFiles/Op.jav b/test/bytecode/javFiles/Op.jav index 8092d18fd..c01e7e6e9 100644 --- a/test/bytecode/javFiles/Op.jav +++ b/test/bytecode/javFiles/Op.jav @@ -9,8 +9,8 @@ import java.lang.Byte; public class Op { - m(a,b) { - var c = a+b; - return c; + Integer m(Integer a, Integer b) { + //var c = a+b; + return a+b; } } \ No newline at end of file