forked from JavaTX/JavaCompilerCore
DUP Befehl fuer UnaryExpr
This commit is contained in:
parent
dc535ad9b7
commit
f99d4dae5a
@ -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;
|
||||
@ -163,7 +159,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// wird die lokale Var geladen. Sonst wird zuerst die lokale Var geladen.
|
||||
System.out.println(localVar.name);
|
||||
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name));
|
||||
|
||||
|
||||
if (isBinaryExp) {
|
||||
doUnboxing(getResolvedType(localVar.getType()));
|
||||
}
|
||||
@ -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("<")) {
|
||||
@ -229,12 +226,18 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
// this case for while loops
|
||||
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) {
|
||||
|
@ -39,5 +39,12 @@ public class BinaryTest {
|
||||
Integer res = (Integer) m2.invoke(instanceOfClass, 2,3);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -10,4 +10,8 @@ public class BinaryInMeth {
|
||||
m2(a,b){
|
||||
return m(a+b);
|
||||
}
|
||||
|
||||
m3(a) {
|
||||
return m(++a);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user