DUP Befehl fuer UnaryExpr

This commit is contained in:
Fayez Abu Alia 2018-08-06 16:14:09 +02:00
parent dc535ad9b7
commit f99d4dae5a
4 changed files with 33 additions and 21 deletions

View File

@ -69,11 +69,7 @@ public class BytecodeGenMethod implements StatementVisitor {
private SourceFile sf;
private IStatement statement = null;
private boolean returnParentOfUnary = false;
// speichert, ob der Argument RefType ist.
private List<Boolean> argList = new LinkedList<>();
// private int numMethodCalls = 0;
private boolean needDUP = false;
// for tests **
private String fieldName;
@ -199,6 +195,7 @@ public class BytecodeGenMethod implements StatementVisitor {
doBoxing(binaryType);
isBinaryExp = false;
}
System.out.println("ASSIGN TYPE R: " + getResolvedType(assign.rightSide.getType()));
String typeOfRightSide = getResolvedType(assign.rightSide.getType());
if(typeOfRightSide.contains("<")) {
@ -230,11 +227,17 @@ public class BytecodeGenMethod implements StatementVisitor {
if (statement instanceof LoopStmt)
mv.visitLabel(endLabel);
if(binary.lexpr instanceof UnaryExpr)
needDUP = true;
binary.lexpr.accept(this);
if (!lexpType.equals(rexpType) && !lexpType.equals(largerType))
doCast(lexpType, largerType);
if(binary.rexpr instanceof UnaryExpr)
needDUP = true;
binary.rexpr.accept(this);
if (!lexpType.equals(rexpType) && !rexpType.equals(largerType))
@ -713,10 +716,6 @@ public class BytecodeGenMethod implements StatementVisitor {
String mDesc = "";
List<Boolean> argListMethCall = new LinkedList<>();
if(methodRefl == null) {
// Alle Argumente sind nicht Primitiv
for(Expression arg : methodCall.arglist.getArguments()) {
argList.add(true);
}
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
receiverName, genericsAndBoundsMethod, genericsAndBounds);
mDesc = method.accept(new DescriptorToString(resultSet));
@ -832,7 +831,6 @@ public class BytecodeGenMethod implements StatementVisitor {
@Override
public void visit(UnaryExpr unaryExpr) {
unaryExpr.expr.accept(this);
Operation op = unaryExpr.operation;
@ -868,13 +866,14 @@ public class BytecodeGenMethod implements StatementVisitor {
// Für Byte und Short muss noch einen Cast geben i2b, i2s
// das wird später gemacht, da bytecode für cast noch nicht erzeugt wird
if (isIncOrDec && (unaryExpr.expr instanceof LocalVar) && !returnParentOfUnary) {
if (isIncOrDec && (unaryExpr.expr instanceof LocalVar)) {
if(needDUP) {
mv.visitInsn(Opcodes.DUP);
needDUP = false;
}
LocalVar local = (LocalVar) unaryExpr.expr;
mv.visitVarInsn(Opcodes.ASTORE, paramsAndLocals.get(local.name));
}
if(returnParentOfUnary)
returnParentOfUnary = false;
}
private void doVisitNegIns(String typeOfUnary) {
@ -922,7 +921,7 @@ public class BytecodeGenMethod implements StatementVisitor {
isBinaryExp = statement.isExprBinary();
if(aReturn.retexpr instanceof UnaryExpr)
returnParentOfUnary = true;
needDUP = true;
aReturn.retexpr.accept(this);
@ -1184,6 +1183,8 @@ public class BytecodeGenMethod implements StatementVisitor {
for (Expression al : argumentList.getArguments()) {
statement = new ArgumentExpr(al);
isBinaryExp = statement.isExprBinary();
if(al instanceof UnaryExpr)
needDUP = true;
al.accept(this);
//TODO: teste, ob man das für unary braucht
if (isBinaryExp) {

View File

@ -40,4 +40,11 @@ public class BinaryTest {
assertEquals(6, res);
}
@Test
public void testM3() throws Exception {
Method m3 = classToTest.getDeclaredMethod("m3", Integer.class);
Integer res = (Integer) m3.invoke(instanceOfClass, 2);
assertEquals(4, res);
}
}

View File

@ -28,9 +28,9 @@ public class MergeTest {
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/");
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Merge");
// pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
// classToTest = loader.loadClass("Merge");
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
//Method m = classToTest.getDeclaredMethod("m");

View File

@ -10,4 +10,8 @@ public class BinaryInMeth {
m2(a,b){
return m(a+b);
}
m3(a) {
return m(++a);
}
}