GenCode: DoubleLiteral implementiert. Aufgrund von Typinferenz-Problemen
kann ein erfolgreicher Test-Run nicht konsisten repliziert werden.
This commit is contained in:
parent
cef7c777b2
commit
ea2aa91761
@ -8,6 +8,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.ISTORE;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
@ -185,11 +186,18 @@ public class Assign extends Expr
|
||||
|
||||
String expr2Type = expr2.getType().get_Name().toString();
|
||||
switch(expr2Type){//welche rückgabewerte entstehen hier??? Integer und String scheinen nicht zu stimmen
|
||||
case "java.lang.Integer": il.append(new ISTORE(counterAssign));
|
||||
break;
|
||||
case "java.lang.Integer":
|
||||
il.append(new ISTORE(counterAssign));
|
||||
break;
|
||||
|
||||
case "java.lang.String": il.append(new ASTORE(counterAssign));
|
||||
break;
|
||||
case "java.lang.String":
|
||||
il.append(new ASTORE(counterAssign));
|
||||
break;
|
||||
|
||||
case "java.lang.Double":
|
||||
il.append(new DSTORE(counterAssign));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return il;
|
||||
|
@ -6,8 +6,11 @@ import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.generic.BIPUSH;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.ConstantPoolGen;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
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;
|
||||
@ -131,12 +134,26 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
//alter Double-Versuch vermutlich inkorrekt
|
||||
/*@Override
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(new BIPUSH(new Double(get_Double()).byteValue()));
|
||||
return il;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
ConstantPoolGen cp = cg.getConstantPool();
|
||||
//InstructionFactory _factory = new InstructionFactory(cg, cp);
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
cp.addDouble(get_Double());
|
||||
il.append(new LDC2_W(cp.getSize()-1));
|
||||
return il;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
6
test/bytecode/DoubleLiteral.jav
Normal file
6
test/bytecode/DoubleLiteral.jav
Normal file
@ -0,0 +1,6 @@
|
||||
class DoubleLiteral{
|
||||
|
||||
void method() {a; a = 20.0d;}
|
||||
|
||||
|
||||
}
|
45
test/bytecode/DoubleLiteral.java
Normal file
45
test/bytecode/DoubleLiteral.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 DoubleLiteral {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "DoubleLiteral.jav";
|
||||
public final static String outputFile = "DoubleLiteral.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