From 2fac549cf590793d69bfb53d47828f6cde5788c7 Mon Sep 17 00:00:00 2001 From: "Fikus, Evelyn (WWI2012D)" Date: Tue, 16 Jun 2015 13:08:11 +0200 Subject: [PATCH] =?UTF-8?q?Zus=C3=A4tzliche=20Kommentare=20und=20geringf?= =?UTF-8?q?=C3=BCgige=20=C3=84nderungen=20in=20der=20=C3=9Cberlegung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/syntaxtree/Constructor.java | 11 +++++------ src/de/dhbwstuttgart/syntaxtree/Method.java | 15 ++++++++++----- .../dhbwstuttgart/syntaxtree/statement/Block.java | 12 ++++++------ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index f09ccd30..253788bd 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -53,19 +53,18 @@ public class Constructor extends Method { @Override public void genByteCode(ClassGen cg) { - ConstantPoolGen _cp = cg.getConstantPool(); - InstructionFactory _factory = new InstructionFactory(cg, _cp); - InstructionList il = new InstructionList(); + //ConstantPoolGen _cp = cg.getConstantPool(); + //InstructionFactory _factory = new InstructionFactory(cg, _cp); + //InstructionList il = new InstructionList(); Class parentClass = this.getParentClass(); //TODO: Hier return type und Argument-Typen dynamisch generieren. return type mittels method.getReturnType() ermitteln //Hier müsste drin stehen: Kreiere einen Block, welcher ein Statement enthält, welches ein Super Statement ist. - - // MethodGen method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(methode.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "", parentClass.name, il, _cp); + MethodGen method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(methode.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "", parentClass.name, il, _cp); - il.dispose(); + //il.dispose(); } // super statement muss drin sein // stmt genByteCode + im block genByteCode implementieren & dann Hierarchie ausprobieren diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 8d7a8e90..4b2f159a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -721,20 +721,25 @@ 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(); + //ConstantPoolGen _cp = cg.getConstantPool(); + //InstructionFactory _factory = new InstructionFactory(cg, _cp); + //InstructionList il = new InstructionList(); Class parentClass = this.getParentClass(); //TODO: Hier return type und Argument-Typen dynamisch generieren. return type mittels method.getReturnType() ermitteln - MethodGen method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(methode.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "", parentClass.name, il, _cp); + //Über Statements iterieren um den Block abzurufen + for(Statement statements : ){ + statements.genByteCode(cg); + } + + MethodGen method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(Constructor.createEmptyMethod(getTypeInformation(), parent).getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "", parentClass.name, il, _cp); //GenByteCode Constructor method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); - il.dispose(); + // il.dispose(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index 4ab83011..47f5a709 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -258,17 +258,17 @@ public class Block extends Statement @Override public void genByteCode(ClassGen cg) { - - ConstantPoolGen _cp = cg.getConstantPool(); + //ConstantPoolGen _cp = cg.getConstantPool(); InstructionFactory _factory = new InstructionFactory(cg, _cp); InstructionList il = new InstructionList(); - Class parentClass = this.getParentClass(); //Instructionhandle dynamisch //Frage: Wenn Block von Statements erbt, und Block selbst keinen BCEL Code besitzt, ist das hier dann nicht eine Sackgasse? - for(Statement statements : this.statements){ - statements.genByteCode(_cg); - } + InstructionHandle ih_0 = il.append(_factory.createLoad(org.apache.bcel.generic.Type.OBJECT, 0)); //creates Constructor + il.append(_factory.createInvoke(this.getParentClass().superclassid.toString(), "", org.apache.bcel.generic.Type.VOID, org.apache.bcel.generic.Type.NO_ARGS, Constants.INVOKESPECIAL)); + InstructionHandle ih_4 = il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); //creates Constructor + + il.dispose(); } }