forked from JavaTX/JavaCompilerCore
GenCode: FloatLit implementiert, aufgrund von Typeinferenz-Problemen
nicht testbar.
This commit is contained in:
parent
ea2aa91761
commit
5f6525db19
@ -9,6 +9,7 @@ import java.util.Iterator;
|
|||||||
import org.apache.bcel.generic.ASTORE;
|
import org.apache.bcel.generic.ASTORE;
|
||||||
import org.apache.bcel.generic.ClassGen;
|
import org.apache.bcel.generic.ClassGen;
|
||||||
import org.apache.bcel.generic.DSTORE;
|
import org.apache.bcel.generic.DSTORE;
|
||||||
|
import org.apache.bcel.generic.FSTORE;
|
||||||
import org.apache.bcel.generic.ISTORE;
|
import org.apache.bcel.generic.ISTORE;
|
||||||
import org.apache.bcel.generic.InstructionFactory;
|
import org.apache.bcel.generic.InstructionFactory;
|
||||||
import org.apache.bcel.generic.InstructionList;
|
import org.apache.bcel.generic.InstructionList;
|
||||||
@ -180,12 +181,11 @@ public class Assign extends Expr
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||||
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr
|
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr
|
||||||
counterAssign++;
|
counterAssign++; //macht STORE für meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.)
|
||||||
//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?
|
|
||||||
|
|
||||||
String expr2Type = expr2.getType().get_Name().toString();
|
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":
|
case "java.lang.Integer":
|
||||||
il.append(new ISTORE(counterAssign));
|
il.append(new ISTORE(counterAssign));
|
||||||
break;
|
break;
|
||||||
@ -198,6 +198,9 @@ public class Assign extends Expr
|
|||||||
il.append(new DSTORE(counterAssign));
|
il.append(new DSTORE(counterAssign));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "java.lang.Float":
|
||||||
|
il.append(new FSTORE(counterAssign));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return il;
|
return il;
|
||||||
|
@ -5,6 +5,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import org.apache.bcel.generic.ClassGen;
|
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.typeinference.Menge;
|
||||||
import de.dhbwstuttgart.logger.Logger;
|
import de.dhbwstuttgart.logger.Logger;
|
||||||
@ -128,9 +132,14 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void genByteCode(ClassGen _cg) {
|
public InstructionList genByteCode(ClassGen cg) {
|
||||||
// TODO Auto-generated method stub
|
ConstantPoolGen cp = cg.getConstantPool();
|
||||||
|
InstructionList il = new InstructionList();
|
||||||
|
|
||||||
|
cp.addFloat(get_Float());
|
||||||
|
il.append(new LDC(cp.getSize()-1));
|
||||||
|
return il;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
6
test/bytecode/FloatLiteral.jav
Normal file
6
test/bytecode/FloatLiteral.jav
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class FloatLiteral{
|
||||||
|
|
||||||
|
void method() {f; f = 20.0f;}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
45
test/bytecode/FloatLiteral.java
Normal file
45
test/bytecode/FloatLiteral.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user