|
|
@ -23,6 +23,7 @@ import jode.type.Type; |
|
|
|
import jode.decompiler.LocalInfo; |
|
|
|
import jode.decompiler.LocalInfo; |
|
|
|
import jode.expr.Expression; |
|
|
|
import jode.expr.Expression; |
|
|
|
import jode.expr.ConstOperator; |
|
|
|
import jode.expr.ConstOperator; |
|
|
|
|
|
|
|
import jode.expr.StoreInstruction; |
|
|
|
import jode.expr.LocalStoreOperator; |
|
|
|
import jode.expr.LocalStoreOperator; |
|
|
|
import jode.expr.CombineableOperator; |
|
|
|
import jode.expr.CombineableOperator; |
|
|
|
|
|
|
|
|
|
|
@ -83,18 +84,18 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
VariableStack continueStack; |
|
|
|
VariableStack continueStack; |
|
|
|
|
|
|
|
|
|
|
|
/*{ invariant { type != POSSFOR || |
|
|
|
/*{ invariant { type == POSSFOR || type == FOR || incr == null |
|
|
|
(incr != null |
|
|
|
:: "(while/do while) with incr"; |
|
|
|
&& incr.getInstruction().getOperator() |
|
|
|
type == FOR || init == null |
|
|
|
instanceof CombineableOperator) |
|
|
|
:: "(while/do while/poss for) with init"; |
|
|
|
:: "(possible) for with invalid init/incr"; |
|
|
|
(type != FOR && type != POSSFOR) || incr != null |
|
|
|
|
|
|
|
:: "(possible) for without incr"; |
|
|
|
|
|
|
|
type != POSSFOR || |
|
|
|
|
|
|
|
(incr.getInstruction() instanceof CombineableOperator) |
|
|
|
|
|
|
|
:: "possible for with invalid incr"; |
|
|
|
init == null || |
|
|
|
init == null || |
|
|
|
(init.getInstruction().getOperator() |
|
|
|
(init.getInstruction() instanceof CombinableOperator) |
|
|
|
instanceof CombinableOperator) |
|
|
|
|
|
|
|
:: "Initializer is not combinableOperator"; |
|
|
|
:: "Initializer is not combinableOperator"; |
|
|
|
type == POSSFOR || type == FOR || |
|
|
|
|
|
|
|
(init == null && incr == null) |
|
|
|
|
|
|
|
:: "(while/do while) with init or incr"; |
|
|
|
|
|
|
|
cond != null && cond.getType() == Type.tBoolean |
|
|
|
cond != null && cond.getType() == Type.tBoolean |
|
|
|
:: "invalid condition type"; |
|
|
|
:: "invalid condition type"; |
|
|
|
type != POSSFOR || bodyBlock.contains(incr) |
|
|
|
type != POSSFOR || bodyBlock.contains(incr) |
|
|
@ -133,9 +134,8 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { |
|
|
|
init.removeBlock(); |
|
|
|
init.removeBlock(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean conditionMatches(InstructionBlock instr) { |
|
|
|
public boolean conditionMatches(CombineableOperator combinable) { |
|
|
|
return (type == POSSFOR || |
|
|
|
return (type == POSSFOR || cond.containsMatchingLoad(combinable)); |
|
|
|
cond.containsMatchingLoad(instr.getInstruction())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -148,11 +148,13 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { |
|
|
|
if (type == POSSFOR) { |
|
|
|
if (type == POSSFOR) { |
|
|
|
/* We can now say, if this is a for block or not. |
|
|
|
/* We can now say, if this is a for block or not. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (cond.containsMatchingLoad(incr.getInstruction())) { |
|
|
|
if (cond.containsMatchingLoad((CombineableOperator) |
|
|
|
|
|
|
|
incr.getInstruction())) { |
|
|
|
type = FOR; |
|
|
|
type = FOR; |
|
|
|
incr.removeBlock(); |
|
|
|
incr.removeBlock(); |
|
|
|
if (init != null) { |
|
|
|
if (init != null) { |
|
|
|
if (cond.containsMatchingLoad(init.getInstruction())) |
|
|
|
if (cond.containsMatchingLoad((CombineableOperator) |
|
|
|
|
|
|
|
init.getInstruction())) |
|
|
|
init.removeBlock(); |
|
|
|
init.removeBlock(); |
|
|
|
else |
|
|
|
else |
|
|
|
init = null; |
|
|
|
init = null; |
|
|
@ -176,11 +178,30 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { |
|
|
|
this.type = type; |
|
|
|
this.type = type; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Remove all variables from set, that we can declare inside the |
|
|
|
|
|
|
|
* loop-block. This is the initializer for for-blocks. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void removeLocallyDeclareable(VariableSet set) { |
|
|
|
|
|
|
|
if (type == FOR && init != null |
|
|
|
|
|
|
|
&& init.getInstruction() instanceof StoreInstruction) { |
|
|
|
|
|
|
|
StoreInstruction storeOp = |
|
|
|
|
|
|
|
(StoreInstruction) init.getInstruction(); |
|
|
|
|
|
|
|
if (storeOp.getLValue() instanceof LocalStoreOperator) { |
|
|
|
|
|
|
|
LocalInfo local = |
|
|
|
|
|
|
|
((LocalStoreOperator) storeOp.getLValue()).getLocalInfo(); |
|
|
|
|
|
|
|
set.removeElement(local); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public VariableSet propagateUsage() { |
|
|
|
public VariableSet propagateUsage() { |
|
|
|
if (type == FOR && init != null) |
|
|
|
if (type == FOR) { |
|
|
|
|
|
|
|
if (init != null) |
|
|
|
used.unionExact(init.used); |
|
|
|
used.unionExact(init.used); |
|
|
|
if (type == FOR && incr != null) |
|
|
|
if (incr != null) |
|
|
|
used.unionExact(incr.used); |
|
|
|
used.unionExact(incr.used); |
|
|
|
|
|
|
|
} |
|
|
|
VariableSet allUse = (VariableSet) used.clone(); |
|
|
|
VariableSet allUse = (VariableSet) used.clone(); |
|
|
|
allUse.unionExact(bodyBlock.propagateUsage()); |
|
|
|
allUse.unionExact(bodyBlock.propagateUsage()); |
|
|
|
return allUse; |
|
|
|
return allUse; |
|
|
@ -256,7 +277,8 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { |
|
|
|
if (init != null) { |
|
|
|
if (init != null) { |
|
|
|
if (init.isDeclaration) { |
|
|
|
if (init.isDeclaration) { |
|
|
|
writer.printType(((LocalStoreOperator) |
|
|
|
writer.printType(((LocalStoreOperator) |
|
|
|
init.getInstruction().getOperator()) |
|
|
|
((CombineableOperator) |
|
|
|
|
|
|
|
init.getInstruction()).getLValue()) |
|
|
|
.getLocalInfo().getType().getHint()); |
|
|
|
.getLocalInfo().getType().getHint()); |
|
|
|
writer.print(" "); |
|
|
|
writer.print(" "); |
|
|
|
} |
|
|
|
} |
|
|
@ -333,7 +355,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { |
|
|
|
|
|
|
|
|
|
|
|
if (continueStack != null) { |
|
|
|
if (continueStack != null) { |
|
|
|
VariableStack newStack; |
|
|
|
VariableStack newStack; |
|
|
|
int params = cond.getOperandCount(); |
|
|
|
int params = cond.getFreeOperandCount(); |
|
|
|
if (params > 0) { |
|
|
|
if (params > 0) { |
|
|
|
condStack = continueStack.peek(params); |
|
|
|
condStack = continueStack.peek(params); |
|
|
|
newStack = continueStack.pop(params); |
|
|
|
newStack = continueStack.pop(params); |
|
|
@ -348,7 +370,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
continueStack = stack; |
|
|
|
continueStack = stack; |
|
|
|
VariableStack newStack; |
|
|
|
VariableStack newStack; |
|
|
|
int params = cond.getOperandCount(); |
|
|
|
int params = cond.getFreeOperandCount(); |
|
|
|
if (params > 0) { |
|
|
|
if (params > 0) { |
|
|
|
condStack = stack.peek(params); |
|
|
|
condStack = stack.peek(params); |
|
|
|
newStack = stack.pop(params); |
|
|
|
newStack = stack.pop(params); |
|
|
|