code aufräumen
This commit is contained in:
parent
9575afd0b4
commit
dcc36f082f
30
src/de/dhbwstuttgart/bytecode/AStatement.java
Normal file
30
src/de/dhbwstuttgart/bytecode/AStatement.java
Normal file
@ -0,0 +1,30 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
|
||||
public abstract class AStatement implements IStatement {
|
||||
protected Expression expr;
|
||||
|
||||
public AStatement(Expression expr) {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExprBinary() {
|
||||
return (expr instanceof BinaryExpr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
|
||||
mv.visitInsn(Opcodes.ICONST_1);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
mv.visitLabel(branchLabel);
|
||||
mv.visitInsn(Opcodes.ICONST_0);
|
||||
mv.visitLabel(endLabel);
|
||||
}
|
||||
}
|
11
src/de/dhbwstuttgart/bytecode/ArgumentExpr.java
Normal file
11
src/de/dhbwstuttgart/bytecode/ArgumentExpr.java
Normal file
@ -0,0 +1,11 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
|
||||
public class ArgumentExpr extends AStatement {
|
||||
|
||||
public ArgumentExpr(Expression expr) {
|
||||
super(expr);
|
||||
}
|
||||
|
||||
}
|
11
src/de/dhbwstuttgart/bytecode/AssignStmt.java
Normal file
11
src/de/dhbwstuttgart/bytecode/AssignStmt.java
Normal file
@ -0,0 +1,11 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
|
||||
public class AssignStmt extends AStatement {
|
||||
|
||||
public AssignStmt(Expression rightSide) {
|
||||
super(rightSide);
|
||||
}
|
||||
|
||||
}
|
@ -55,6 +55,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
HashMap<String, String> genericsAndBoundsMethod;
|
||||
private HashMap<String, String> genericsAndBounds;
|
||||
private boolean isBinaryExp = false;
|
||||
|
||||
private IStatement statement;
|
||||
|
||||
// for tests **
|
||||
private String fieldName;
|
||||
@ -148,6 +150,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
statement = new AssignStmt(assign.rightSide);
|
||||
isAssignStmt = true;
|
||||
|
||||
// if the right side is a lambda => the left side must be a functional interface
|
||||
@ -157,8 +160,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
isRightSideALambda = false;
|
||||
}
|
||||
|
||||
if (assign.rightSide instanceof BinaryExpr)
|
||||
isBinaryExp = true;
|
||||
isBinaryExp = statement.isExprBinary();
|
||||
|
||||
|
||||
if (assign.lefSide instanceof AssignToField) {
|
||||
@ -198,7 +200,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
Label endLabel = new Label();
|
||||
// this case for while loops
|
||||
if(!isAssignStmt)
|
||||
if(statement instanceof LoopStmt)
|
||||
mv.visitLabel(endLabel);
|
||||
|
||||
binary.lexpr.accept(this);
|
||||
@ -341,18 +343,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(isAssignStmt) {
|
||||
mv.visitInsn(Opcodes.ICONST_1);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
mv.visitLabel(branchLabel);
|
||||
mv.visitInsn(Opcodes.ICONST_0);
|
||||
mv.visitLabel(endLabel);
|
||||
} else {
|
||||
loopBlock.accept(this);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
|
||||
mv.visitLabel(branchLabel);
|
||||
}
|
||||
|
||||
statement.genBCForRelOp(mv, branchLabel, endLabel,this);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -375,18 +368,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(isAssignStmt) {
|
||||
mv.visitInsn(Opcodes.ICONST_1);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
mv.visitLabel(branchLabel);
|
||||
mv.visitInsn(Opcodes.ICONST_0);
|
||||
mv.visitLabel(endLabel);
|
||||
} else {
|
||||
loopBlock.accept(this);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
|
||||
mv.visitLabel(branchLabel);
|
||||
}
|
||||
statement.genBCForRelOp(mv, branchLabel, endLabel, this);
|
||||
|
||||
}
|
||||
|
||||
@ -644,6 +626,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(MethodCall methodCall) {
|
||||
|
||||
methodCall.receiver.accept(this);
|
||||
methodCall.arglist.accept(this);
|
||||
|
||||
@ -667,7 +650,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(NewClass methodCall) {
|
||||
|
||||
|
||||
mv.visitTypeInsn(Opcodes.NEW, methodCall.name.replace(".", "/"));
|
||||
mv.visitInsn(Opcodes.DUP);
|
||||
// creates Descriptor
|
||||
@ -776,8 +759,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
if(aReturn.retexpr instanceof BinaryExpr)
|
||||
isBinaryExp = true;
|
||||
|
||||
statement = new ReturnStmt(aReturn.retexpr);
|
||||
|
||||
isBinaryExp = statement.isExprBinary();
|
||||
|
||||
aReturn.retexpr.accept(this);
|
||||
|
||||
@ -818,10 +803,12 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
|
||||
statement = new LoopStmt(whileStmt.expr, whileStmt.loopBlock);
|
||||
this.loopBlock = whileStmt.loopBlock;
|
||||
|
||||
if(whileStmt.expr instanceof BinaryExpr)
|
||||
isBinaryExp = true;
|
||||
|
||||
isBinaryExp = statement.isExprBinary();
|
||||
|
||||
whileStmt.expr.accept(this);
|
||||
|
||||
@ -1030,6 +1017,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
@Override
|
||||
public void visit(ArgumentList argumentList) {
|
||||
for (Expression al : argumentList.getArguments()) {
|
||||
statement = new ArgumentExpr(al);
|
||||
al.accept(this);
|
||||
}
|
||||
}
|
||||
|
9
src/de/dhbwstuttgart/bytecode/IStatement.java
Normal file
9
src/de/dhbwstuttgart/bytecode/IStatement.java
Normal file
@ -0,0 +1,9 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
public interface IStatement {
|
||||
public boolean isExprBinary();
|
||||
public void genBCForRelOp(MethodVisitor mv, Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod);
|
||||
}
|
25
src/de/dhbwstuttgart/bytecode/LoopStmt.java
Normal file
25
src/de/dhbwstuttgart/bytecode/LoopStmt.java
Normal file
@ -0,0 +1,25 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
|
||||
public class LoopStmt extends AStatement {
|
||||
|
||||
private Statement loopBlock;
|
||||
|
||||
public LoopStmt(Expression expr, Statement loopBlock) {
|
||||
super(expr);
|
||||
this.loopBlock = loopBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) {
|
||||
this.loopBlock.accept(bytecodeGenMethod);
|
||||
mv.visitJumpInsn(Opcodes.GOTO, endLabel);
|
||||
mv.visitLabel(branchLabel);
|
||||
}
|
||||
}
|
14
src/de/dhbwstuttgart/bytecode/ReturnStmt.java
Normal file
14
src/de/dhbwstuttgart/bytecode/ReturnStmt.java
Normal file
@ -0,0 +1,14 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
|
||||
public class ReturnStmt extends AStatement {
|
||||
|
||||
public ReturnStmt(Expression retexpr) {
|
||||
super(retexpr);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user