From 93f4257cdc4fd17d53c7b2ad59e49a8888480008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=BCtterling=2C=20Franziska=20=28WWI2012D=29?= Date: Mon, 22 Jun 2015 23:53:29 +0200 Subject: [PATCH] =?UTF-8?q?Assign=20und=20LiteralInt=20enthalten=20eine=20?= =?UTF-8?q?funktionierende=20GenCode-Methode,=20Anpassungen=20f=C3=BCr=20m?= =?UTF-8?q?ehrere=20Variablen=20evtl.=20n=C3=B6tig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/statement/Assign.java | 3 +- .../syntaxtree/statement/IntLiteral.java | 11 +++-- .../syntaxtree/statement/LocalVarDecl.java | 5 ++- test/bytecode/Assign.jav | 7 +++ test/bytecode/Assign.java | 45 +++++++++++++++++++ 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 test/bytecode/Assign.jav create mode 100644 test/bytecode/Assign.java diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index a71592ed..fc209ed6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -180,8 +180,9 @@ public class Assign extends Expr // istore_1 InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr - il.append(_factory.createConstant(expr2)); + //il.append(_factory.createConstant(expr2)); il.append(_factory.ISTORE_1); + return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java index b56d253f..9c37c19a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java @@ -4,7 +4,10 @@ package de.dhbwstuttgart.syntaxtree.statement; // ino.module.IntLiteral.8635.import import java.util.Hashtable; +import org.apache.bcel.generic.BIPUSH; import org.apache.bcel.generic.ClassGen; +import org.apache.bcel.generic.InstructionFactory; +import org.apache.bcel.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -131,9 +134,11 @@ public class IntLiteral extends Literal } @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(new BIPUSH(new Integer(get_Int()).byteValue())); + return il; } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 494bffd5..eddc29cf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -6,6 +6,7 @@ import java.util.Enumeration; import java.util.Hashtable; import org.apache.bcel.generic.ClassGen; +import org.apache.bcel.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -427,9 +428,9 @@ public class LocalVarDecl extends Statement implements TypeInsertable } @Override - public void genByteCode(ClassGen _cg) { + public InstructionList genByteCode(ClassGen _cg) { // TODO Auto-generated method stub - + return new InstructionList(); } } // ino.end diff --git a/test/bytecode/Assign.jav b/test/bytecode/Assign.jav new file mode 100644 index 00000000..ba88c14c --- /dev/null +++ b/test/bytecode/Assign.jav @@ -0,0 +1,7 @@ +class Assign{ + + +void method() {i; i = 20;} + + +} \ No newline at end of file diff --git a/test/bytecode/Assign.java b/test/bytecode/Assign.java new file mode 100644 index 00000000..c027e25b --- /dev/null +++ b/test/bytecode/Assign.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 Assign { + + public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + public final static String testFile = "Assign.jav"; + public final static String outputFile = "Assign.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(); + } + } + +}