diff --git a/jode/jode/expr/ComplexExpression.java b/jode/jode/expr/ComplexExpression.java index 62ff819..ec6f0cc 100644 --- a/jode/jode/expr/ComplexExpression.java +++ b/jode/jode/expr/ComplexExpression.java @@ -78,24 +78,45 @@ public class ComplexExpression extends Expression { */ public int canCombine(Expression e) { if (e instanceof ComplexExpression - && e.getOperator() instanceof StoreInstruction) { + && e.getOperator() instanceof StoreInstruction + && ((StoreInstruction) e.getOperator()).matches(operator)) { + + ComplexExpression ce = (ComplexExpression) e; + for (int i=0; i < ce.subExpressions.length-1; i++) { + if (!ce.subExpressions[i].equals(subExpressions[i])) + return -1; + } + return 1; + } + return subExpressions[0].canCombine(e); + } + + /** + * Checks if this expression contains a load, that matches the + * given Expression (which should be a + * StoreInstruction/IIncOperator). + * @param e The store expression. + * @return if this expression contains a matching load. + */ + public boolean containsMatchingLoad(Expression e) { + if (e instanceof ComplexExpression + && e.getOperator() instanceof StoreInstruction + && ((StoreInstruction) e.getOperator()).matches(operator)) { + ComplexExpression ce = (ComplexExpression) e; - StoreInstruction store = (StoreInstruction) e.getOperator(); - if (store.matches(operator)) { - for (int i=0; i < ce.subExpressions.length-1; i++) { - if (!ce.subExpressions[i].equals(subExpressions[i])) - return -1; - } - return 1; - } - return subExpressions[0].canCombine(e); -// for (int i=0; i < subExpressions.length; i++) { -// int can = subExpressions[i].canCombine(e); -// if (can != 0) -// return can; -// } - } - return 0; + int i; + for (i=0; i < ce.subExpressions.length-1; i++) { + if (!ce.subExpressions[i].equals(subExpressions[i])) + break; + } + if (i == ce.subExpressions.length-1) + return true; + } + for (int i=0; i < subExpressions.length; i++) { + if (subExpressions[i].containsMatchingLoad(e)) + return true; + } + return false; } /** diff --git a/jode/jode/expr/Expression.java b/jode/jode/expr/Expression.java index d152b12..b3596b4 100644 --- a/jode/jode/expr/Expression.java +++ b/jode/jode/expr/Expression.java @@ -65,17 +65,26 @@ public abstract class Expression { * conflict was found. You may wish to check for >0. */ public int canCombine(Expression e) { - if (!e.isVoid()) - return 0; + return containsMatchingLoad(e)? 1 : 0; + } + + /** + * Checks if this expression contains a load, that matches the + * given Expression (which should be a + * StoreInstruction/IIncOperator). + * @param e The store expression. + * @return if this expression contains a matching load. + */ + public boolean containsMatchingLoad(Expression e) { if (e instanceof IIncOperator && ((IIncOperator)e.getOperator()).matches(getOperator())) - return 1; + return true; else if (e instanceof ComplexExpression && e.getOperator() instanceof StoreInstruction && ((StoreInstruction) e.getOperator()) .matches(getOperator())) - return 1; - return 0; + return true; + return false; } /**