diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index 0ba2d11d..2b38bc8b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -13,6 +13,7 @@ import org.apache.bcel.generic.FSTORE; import org.apache.bcel.generic.ISTORE; import org.apache.bcel.generic.InstructionFactory; import org.apache.bcel.generic.InstructionList; +import org.apache.bcel.generic.LSTORE; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -201,6 +202,10 @@ public class Assign extends Expr case "java.lang.Float": il.append(new FSTORE(counterAssign)); break; + + case "java.lang.Long": + il.append(new LSTORE(counterAssign)); + break; } return il; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java index 818f5b0e..e41d494f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java @@ -5,6 +5,9 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import org.apache.bcel.generic.ClassGen; +import org.apache.bcel.generic.ConstantPoolGen; +import org.apache.bcel.generic.InstructionList; +import org.apache.bcel.generic.LDC2_W; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -125,9 +128,15 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public void genByteCode(ClassGen _cg) { - // TODO Auto-generated method stub + public InstructionList genByteCode(ClassGen cg) { + ConstantPoolGen cp = cg.getConstantPool(); + //InstructionFactory _factory = new InstructionFactory(cg, cp); + InstructionList il = new InstructionList(); + cp.addLong(get_Long()); + il.append(new LDC2_W(cp.getSize()-1)); + return il; + } } // ino.end diff --git a/test/bytecode/LongLiteral.jav b/test/bytecode/LongLiteral.jav new file mode 100644 index 00000000..70d57aa7 --- /dev/null +++ b/test/bytecode/LongLiteral.jav @@ -0,0 +1,6 @@ +class LongLiteral{ + +void method() {l; l = 20L;} + + +} \ No newline at end of file diff --git a/test/bytecode/LongLiteral.java b/test/bytecode/LongLiteral.java new file mode 100644 index 00000000..5e6ca9cb --- /dev/null +++ b/test/bytecode/LongLiteral.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 LongLiteral { + + public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + public final static String testFile = "LongLiteral.jav"; + public final static String outputFile = "LongLiteral.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(); + } + } + +}