From 8bc2867eb7f08ff6ba2b7eaa01c89c7bf6453270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=BCtterling=2C=20Franziska=20=28WWI2012D=29?= Date: Tue, 23 Jun 2015 20:28:36 +0200 Subject: [PATCH] =?UTF-8?q?GenCode=20f=C3=BCr=20CharLiteral,=20momentan=20?= =?UTF-8?q?aufgrund=20einer=20Parser-NPE=20nicht=20lauff=C3=A4hig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/statement/CharLiteral.java | 18 ++++++-- test/bytecode/CharLitTest.jav | 7 +++ test/bytecode/CharLitTest.java | 45 +++++++++++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 test/bytecode/CharLitTest.jav create mode 100644 test/bytecode/CharLitTest.java diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java index a47853f2..33871d6f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java @@ -4,7 +4,10 @@ package de.dhbwstuttgart.syntaxtree.statement; // ino.module.CharLiteral.8628.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; @@ -111,10 +114,19 @@ public class CharLiteral extends Literal } + //Char-Getter fuer genByteCode + public char get_Char() + // ino.end + // ino.method.get_Int.25463.body + { + return Char; + } @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((byte) get_Char())); + return il; } } // ino.end diff --git a/test/bytecode/CharLitTest.jav b/test/bytecode/CharLitTest.jav new file mode 100644 index 00000000..1cf78415 --- /dev/null +++ b/test/bytecode/CharLitTest.jav @@ -0,0 +1,7 @@ +class CharLitTest{ + + +void method() { c; c = 'A'; } + + +} \ No newline at end of file diff --git a/test/bytecode/CharLitTest.java b/test/bytecode/CharLitTest.java new file mode 100644 index 00000000..add8b515 --- /dev/null +++ b/test/bytecode/CharLitTest.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 CharLitTest { + + public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + public final static String testFile = "CharLitTest.jav"; + public final static String outputFile = "CharLitTest.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(); + } + } + +}