From b707a0f03eedd41d4a34cfb61fdc8e0830ccef7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Thu, 7 Apr 2016 15:44:29 +0200 Subject: [PATCH 1/2] Bugfix: Methodenparameter --- src/de/dhbwstuttgart/bytecode/ClassGenerator.java | 2 +- src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java | 4 ++++ src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index ef556c50..393d2e6e 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -53,7 +53,7 @@ public class ClassGenerator extends ClassGen{ } public DHBWInstructionFactory getInstructionFactory() { - return factory ; + return factory; } /** diff --git a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java index fb555342..853ddae1 100644 --- a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java +++ b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java @@ -158,4 +158,8 @@ public class DHBWInstructionFactory extends InstructionFactory{ public Attribute createSignatureAttribute(String signature) { return new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(signature),cp.getConstantPool()); } + + public void resetStoreIndexes() { + storeIndexes = new HashMap<>(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 051fafff..7b7b82bb 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -12,6 +12,7 @@ import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.Method; @@ -324,7 +325,8 @@ public class MethodCall extends Expr @Override public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { InstructionList il = new InstructionList(); - InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); + DHBWInstructionFactory _factory = cg.getInstructionFactory(); + _factory.resetStoreIndexes(); il.append(receiver.get_Expr().genByteCode(cg, rs)); @@ -343,6 +345,8 @@ public class MethodCall extends Expr argumentTypen = new org.apache.commons.bcel6.generic.Type[this.getArgumentList().size()]; int i = 0; for(Expr argument : this.arglist.expr){ + _factory.getStoreIndex(argument.get_Name()); + argumentTypen[i] = argument.getType().getBytecodeType(cg, rs); //Das Argument auf den Stack legen: il.append(argument.genByteCode(cg, rs)); From 736375860362b818f9cfe177635f055b42d8c576 Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Tue, 12 Apr 2016 11:37:00 +0200 Subject: [PATCH 2/2] new file: OL.jav new file: OLTest.java modified: Overloading.jav main Methode angefuegt --- test/bytecode/types/OL.jav | 16 ++++++ test/bytecode/types/OLTest.java | 75 +++++++++++++++++++++++++++++ test/bytecode/types/Overloading.jav | 7 +-- 3 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 test/bytecode/types/OL.jav create mode 100644 test/bytecode/types/OLTest.java diff --git a/test/bytecode/types/OL.jav b/test/bytecode/types/OL.jav new file mode 100644 index 00000000..66e95aeb --- /dev/null +++ b/test/bytecode/types/OL.jav @@ -0,0 +1,16 @@ +class OL { + + Integer m(Integer x) { return x + x; } + + Boolean m(Boolean x) {return x || x; } +} + +class Main { + + main(x) { + ol; + ol = new OL(); + return ol.m(x); + } + +} diff --git a/test/bytecode/types/OLTest.java b/test/bytecode/types/OLTest.java new file mode 100644 index 00000000..4b369283 --- /dev/null +++ b/test/bytecode/types/OLTest.java @@ -0,0 +1,75 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class OLTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "OL"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; + } + + + @Test + public void testInteger() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + Class stringVector = classLoader.loadClass("Integer"); + + Class[] params = new Class[1]; + params[0] = stringVector; + + Method method = cls.getDeclaredMethod("m", params); + method.invoke(obj, stringVector.newInstance()); + assertTrue(true); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testBoolen() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + Class stringVector = classLoader.loadClass("Boolean"); + + Class[] params = new Class[1]; + params[0] = stringVector; + + Method method = cls.getDeclaredMethod("m", params); + method.invoke(obj, stringVector.newInstance()); + assertTrue(true); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + +} diff --git a/test/bytecode/types/Overloading.jav b/test/bytecode/types/Overloading.jav index 57206bdd..0c0fdb2b 100644 --- a/test/bytecode/types/Overloading.jav +++ b/test/bytecode/types/Overloading.jav @@ -11,12 +11,7 @@ class Overloading{ } main(String[] args) { - ol; - ol = new Overloading(); - v; - v = new Vector (); - ol.method(v); - + new Overloading().method(new Vector ()); } } \ No newline at end of file