diff --git a/bin/log4j.xml b/bin/log4j.xml
index f36fb342..64e7c5db 100755
--- a/bin/log4j.xml
+++ b/bin/log4j.xml
@@ -1,35 +1,35 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/bin/log4jTesting.xml b/bin/log4jTesting.xml
index ef849218..dc30c245 100755
--- a/bin/log4jTesting.xml
+++ b/bin/log4jTesting.xml
@@ -1,24 +1,24 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java
index 566f4135..e8f651b8 100644
--- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java
+++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java
@@ -65,8 +65,8 @@ public class Constructor extends Method {
this.method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "", parentClass.name, il, _cp);
//Iteration �ber Block starten
- Block instructions = this.get_Block();
- InstructionList blockInstructions = instructions.genByteCode(cg);
+ Block block = this.get_Block();
+ InstructionList blockInstructions = block.genByteCode(cg);
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java
index dd27c698..c5547f23 100755
--- a/src/de/dhbwstuttgart/syntaxtree/Method.java
+++ b/src/de/dhbwstuttgart/syntaxtree/Method.java
@@ -741,19 +741,27 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
@Override
public void genByteCode(ClassGen cg) {
- /*ConstantPoolGen _cp = cg.getConstantPool();
- * InstructionFactory _factory = new InstructionFactory(cg, _cp);
- * InstructionList il = new InstructionList();
- * Class parentClass = this.getParentClass();
- */
+ ConstantPoolGen _cp = cg.getConstantPool();
+ InstructionFactory _factory = new InstructionFactory(cg, _cp);
+ InstructionList il = new InstructionList();
+ Class parentClass = this.getParentClass();
+
+ MethodGen method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, this.get_Method_Name(), parentClass.name, il, _cp);
- //oben steht MethodGen method als Variable (Z. 71)
+ Block block = this.get_Block();
+ InstructionList blockInstructions = block.genByteCode(cg);
- // �ber Statements iterieren um Block abzurufen
- for (Statement statements : block.get_Statement()) {
- statements.genByteCode(cg);
+ il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
+
+ if (block.get_Statement().size() == 0) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
+ else {
+ if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
}
+ method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
+
+ cg.addMethod(method.getMethod());
+
}
}
diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java
index 2246614a..0e513996 100755
--- a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java
+++ b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java
@@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.Return.8651.import
import java.util.Hashtable;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionFactory;
+import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
@@ -130,9 +133,13 @@ public class Return extends Statement
}
@Override
- public void genByteCode(ClassGen _cg) {
- // TODO Auto-generated method stub
+ public InstructionList genByteCode(ClassGen cg) {
+ InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
+ InstructionList il = new InstructionList();
+ il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID));
+ //TO BE DONE
+ return il;
}
}
// ino.end
diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java
index a4ce2738..c0875303 100755
--- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java
+++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java
@@ -810,6 +810,10 @@ public class RefType extends ObjectType implements IMatchable
param.parserPostProcessing(this);
}
}
+
+ public org.apache.bcel.generic.Type getBytecodeType() {
+ return new org.apache.bcel.generic.ObjectType(this.getTypeName());
+ }
}
// ino.end
diff --git a/test/bytecode/EmptyClass.jav b/test/bytecode/EmptyClass.jav
index 44dfecf2..381162fa 100644
--- a/test/bytecode/EmptyClass.jav
+++ b/test/bytecode/EmptyClass.jav
@@ -1,7 +1,7 @@
class EmptyClass{
-public EmptyClass(){}
-public void leckMichAmArsch(){}
+
+
}
\ No newline at end of file
diff --git a/test/bytecode/MethodEmpty.jav b/test/bytecode/MethodEmpty.jav
new file mode 100644
index 00000000..e2c5d97a
--- /dev/null
+++ b/test/bytecode/MethodEmpty.jav
@@ -0,0 +1,7 @@
+class MethodEmpty{
+
+
+void method() { }
+
+
+}
\ No newline at end of file
diff --git a/test/bytecode/MethodEmpty.java b/test/bytecode/MethodEmpty.java
new file mode 100644
index 00000000..dbeea0a5
--- /dev/null
+++ b/test/bytecode/MethodEmpty.java
@@ -0,0 +1,45 @@
+package bytecode;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import plugindevelopment.TypeInsertTester;
+import de.dhbwstuttgart.core.MyCompiler;
+import de.dhbwstuttgart.core.MyCompilerAPI;
+import de.dhbwstuttgart.logger.LoggerConfiguration;
+import de.dhbwstuttgart.logger.Section;
+import de.dhbwstuttgart.parser.JavaParser.yyException;
+import de.dhbwstuttgart.typeinference.ByteCodeResult;
+import de.dhbwstuttgart.typeinference.Menge;
+import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
+import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
+
+public class MethodEmpty {
+
+ public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
+ public final static String testFile = "MethodEmpty.jav";
+ public final static String outputFile = "MethodEmpty.class";
+
+ @Test
+ public void test() {
+ LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
+ MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
+ try {
+ compiler.parse(new File(rootDirectory + testFile));
+ compiler.typeReconstruction();
+ ByteCodeResult bytecode = compiler.generateBytecode();
+ System.out.println(bytecode);
+ bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
+ } catch (IOException | yyException e) {
+ e.printStackTrace();
+ TestCase.fail();
+ }
+ }
+
+}
diff --git a/test/bytecode/MethodEmptyRetType.jav b/test/bytecode/MethodEmptyRetType.jav
new file mode 100644
index 00000000..84dbc709
--- /dev/null
+++ b/test/bytecode/MethodEmptyRetType.jav
@@ -0,0 +1,7 @@
+class MethodEmptyRetType{
+
+
+Object method() { return null; }
+
+
+}
\ No newline at end of file
diff --git a/test/bytecode/MethodEmptyRetType.java b/test/bytecode/MethodEmptyRetType.java
new file mode 100644
index 00000000..7eecbe0e
--- /dev/null
+++ b/test/bytecode/MethodEmptyRetType.java
@@ -0,0 +1,45 @@
+package bytecode;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import plugindevelopment.TypeInsertTester;
+import de.dhbwstuttgart.core.MyCompiler;
+import de.dhbwstuttgart.core.MyCompilerAPI;
+import de.dhbwstuttgart.logger.LoggerConfiguration;
+import de.dhbwstuttgart.logger.Section;
+import de.dhbwstuttgart.parser.JavaParser.yyException;
+import de.dhbwstuttgart.typeinference.ByteCodeResult;
+import de.dhbwstuttgart.typeinference.Menge;
+import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
+import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
+
+public class MethodEmptyRetType {
+
+ public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
+ public final static String testFile = "MethodEmptyRetType.jav";
+ public final static String outputFile = "MethodEmptyRetType.class";
+
+ @Test
+ public void test() {
+ LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
+ MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
+ try {
+ compiler.parse(new File(rootDirectory + testFile));
+ compiler.typeReconstruction();
+ ByteCodeResult bytecode = compiler.generateBytecode();
+ System.out.println(bytecode);
+ bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
+ } catch (IOException | yyException e) {
+ e.printStackTrace();
+ TestCase.fail();
+ }
+ }
+
+}