convertoperator are no correctly removed

Allows assign expressions for locals and static variables


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@312 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent d0b18e2e83
commit 3a2d077de0
  1. 54
      jode/jode/flow/CreateAssignExpression.java

@ -39,7 +39,7 @@ public class CreateAssignExpression {
* *
* (push loadstoreOps) <- not checked * (push loadstoreOps) <- not checked
* sequBlock: * sequBlock:
* dup * dup (may be missing for static / local variables)
* opBlock: * opBlock:
* load(stack) * rightHandSide * load(stack) * rightHandSide
* (optional dup_x) * (optional dup_x)
@ -70,21 +70,25 @@ public class CreateAssignExpression {
return false; return false;
InstructionBlock ib = (InstructionBlock) opBlock.subBlocks[0]; InstructionBlock ib = (InstructionBlock) opBlock.subBlocks[0];
if (!(ib.getInstruction() instanceof ComplexExpression))
return false;
if (!(opBlock.outer instanceof SequentialBlock) ComplexExpression expr = (ComplexExpression) ib.getInstruction();
|| !(opBlock.outer.getSubBlocks()[0] instanceof SpecialBlock) SpecialBlock dup = null;
|| !(ib.getInstruction() instanceof ComplexExpression))
return false;
SequentialBlock sequBlock = (SequentialBlock) opBlock.outer; if (store.getLValueOperandCount() > 0) {
ComplexExpression expr = (ComplexExpression) ib.getInstruction(); if (!(opBlock.outer instanceof SequentialBlock)
SpecialBlock dup = (SpecialBlock) sequBlock.subBlocks[0]; || !(opBlock.outer.getSubBlocks()[0] instanceof SpecialBlock))
return false;
if (dup.type != SpecialBlock.DUP SequentialBlock sequBlock = (SequentialBlock) opBlock.outer;
|| dup.depth != 0 dup = (SpecialBlock) sequBlock.subBlocks[0];
|| dup.count != store.getLValueOperandCount())
return false;
if (dup.type != SpecialBlock.DUP
|| dup.depth != 0
|| dup.count != store.getLValueOperandCount())
return false;
}
int opIndex; int opIndex;
Expression rightHandSide; Expression rightHandSide;
@ -92,18 +96,29 @@ public class CreateAssignExpression {
&& expr.getSubExpressions()[0] instanceof ComplexExpression && expr.getSubExpressions()[0] instanceof ComplexExpression
&& expr.getOperator().getType().isOfType(store.getLValueType())) { && expr.getOperator().getType().isOfType(store.getLValueType())) {
/* This gets tricky. We need to allow something like
* s = (short) (int) ((double) s / 0.1);
*/
expr = (ComplexExpression) expr.getSubExpressions()[0]; expr = (ComplexExpression) expr.getSubExpressions()[0];
while (expr.getOperator() instanceof ConvertOperator
&& expr.getSubExpressions()[0] instanceof ComplexExpression)
expr = (ComplexExpression) expr.getSubExpressions()[0];
} }
if (expr.getOperator() instanceof BinaryOperator) { if (expr.getOperator() instanceof BinaryOperator) {
BinaryOperator binop = (BinaryOperator) expr.getOperator(); BinaryOperator binop = (BinaryOperator) expr.getOperator();
opIndex = binop.getOperatorIndex(); opIndex = binop.getOperatorIndex();
if (opIndex < binop.ADD_OP || opIndex >= binop.ASSIGN_OP)
if (opIndex < binop.ADD_OP || opIndex >= binop.ASSIGN_OP return false;
|| !(expr.getSubExpressions()[0] instanceof Operator)
|| !store.matches((Operator) expr.getSubExpressions()[0])) Expression loadExpr = expr.getSubExpressions()[0];
while (loadExpr instanceof ComplexExpression
&& loadExpr.getOperator() instanceof ConvertOperator)
loadExpr = ((ComplexExpression)loadExpr)
.getSubExpressions()[0];
if (!(loadExpr instanceof Operator)
|| !store.matches((Operator) loadExpr))
return false; return false;
rightHandSide = expr.getSubExpressions()[1]; rightHandSide = expr.getSubExpressions()[1];
} else { } else {
/* For String += the situation is more complex. /* For String += the situation is more complex.
@ -139,10 +154,11 @@ public class CreateAssignExpression {
opIndex = Operator.ADD_OP; opIndex = Operator.ADD_OP;
} }
dup.removeBlock(); if (dup != null)
dup.removeBlock();
ib.setInstruction(rightHandSide); ib.setInstruction(rightHandSide);
store.setOperatorIndex(store.OPASSIGN_OP+opIndex); store.makeOpAssign(store.OPASSIGN_OP+opIndex);
if (isAssignOp) if (isAssignOp)
store.makeNonVoid(); store.makeNonVoid();

Loading…
Cancel
Save