diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index a992d209..0ba2d11d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -9,6 +9,7 @@ import java.util.Iterator; import org.apache.bcel.generic.ASTORE; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.DSTORE; +import org.apache.bcel.generic.FSTORE; import org.apache.bcel.generic.ISTORE; import org.apache.bcel.generic.InstructionFactory; import org.apache.bcel.generic.InstructionList; @@ -180,12 +181,11 @@ public class Assign extends Expr // TODO Auto-generated method stub InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr - counterAssign++; - //il.append(new ISTORE(counterAssign)); //macht ISTORE für meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.) - //Anpassung für Variablen außerhalb von int = ISTORE nötig? + counterAssign++; //macht STORE für meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.) + String expr2Type = expr2.getType().get_Name().toString(); - switch(expr2Type){//welche rückgabewerte entstehen hier??? Integer und String scheinen nicht zu stimmen + switch(expr2Type){ case "java.lang.Integer": il.append(new ISTORE(counterAssign)); break; @@ -198,6 +198,9 @@ public class Assign extends Expr il.append(new DSTORE(counterAssign)); break; + case "java.lang.Float": + il.append(new FSTORE(counterAssign)); + break; } return il; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java index bcd087b7..bdfd0149 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java @@ -5,6 +5,10 @@ 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.LDC; +import org.apache.bcel.generic.LDC2_W; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -128,9 +132,14 @@ 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(); + InstructionList il = new InstructionList(); + cp.addFloat(get_Float()); + il.append(new LDC(cp.getSize()-1)); + return il; + } } // ino.end diff --git a/test/bytecode/FloatLiteral.jav b/test/bytecode/FloatLiteral.jav new file mode 100644 index 00000000..c0531da4 --- /dev/null +++ b/test/bytecode/FloatLiteral.jav @@ -0,0 +1,6 @@ +class FloatLiteral{ + +void method() {f; f = 20.0f;} + + +} \ No newline at end of file diff --git a/test/bytecode/FloatLiteral.java b/test/bytecode/FloatLiteral.java new file mode 100644 index 00000000..ba789535 --- /dev/null +++ b/test/bytecode/FloatLiteral.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 FloatLiteral { + + public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + public final static String testFile = "FloatLiteral.jav"; + public final static String outputFile = "FloatLiteral.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(); + } + } + +}