From a23f77c33715cc438dc01229fd0cd7601c3f2bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Thu, 14 Apr 2016 14:36:18 +0200 Subject: [PATCH] =?UTF-8?q?-Test=20f=C3=BCr=20Variablen=20erstellt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bytecode/DHBWInstructionFactory.java | 7 ++-- src/de/dhbwstuttgart/syntaxtree/Method.java | 5 +++ test/bytecode/Variable.jav | 8 +++++ test/bytecode/VariableTest.java | 35 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 test/bytecode/Variable.jav create mode 100644 test/bytecode/VariableTest.java diff --git a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java index 5cb13991..bc5a3806 100644 --- a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java +++ b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java @@ -144,8 +144,9 @@ public class DHBWInstructionFactory extends InstructionFactory{ } public Integer getStoreIndex(String variableName) { - if(!storeIndexes.containsKey(variableName)){ - storeIndexes.put(variableName, storeIndexes.size()+1); + if(storeIndexes.get(variableName) == null){ + Integer index = storeIndexes.size()+1; + storeIndexes.put(variableName, index); } return storeIndexes.get(variableName); @@ -160,6 +161,6 @@ public class DHBWInstructionFactory extends InstructionFactory{ } public void resetStoreIndexes() { - storeIndexes.clear(); + //storeIndexes.clear(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index ebed1381..9a59788a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -610,6 +610,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable public void genByteCode(ClassGenerator cg, Class classObj) { List typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg); + DHBWInstructionFactory _factory = cg.getInstructionFactory(); for(TypeinferenceResultSet t: typeInterferenceResults){ DHBWConstantPoolGen _cp = cg.getConstantPool(); @@ -626,6 +627,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable for(FormalParameter parameter : this.parameterlist){ argumentTypes[i] = parameter.getType().getBytecodeType(cg, t); argumentNames[i] = parameter.getIdentifier(); + + + _factory.getStoreIndex(parameter.getIdentifier()); + i++; } } diff --git a/test/bytecode/Variable.jav b/test/bytecode/Variable.jav new file mode 100644 index 00000000..ef9de331 --- /dev/null +++ b/test/bytecode/Variable.jav @@ -0,0 +1,8 @@ +class Variable{ + public Integer method(Integer parameter){ + Integer lokaleVariable; + lokaleVariable = 2; + + return parameter+lokaleVariable; + } +} \ No newline at end of file diff --git a/test/bytecode/VariableTest.java b/test/bytecode/VariableTest.java new file mode 100644 index 00000000..de387566 --- /dev/null +++ b/test/bytecode/VariableTest.java @@ -0,0 +1,35 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Test; + +import org.junit.Ignore; + +import bytecode.SourceFileBytecodeTest; + + +public class VariableTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Variable"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +}