From 00bba38a0c4c7d4d336b5260dc3b6ecd4fa90411 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 5 Feb 1999 12:48:38 +0000 Subject: [PATCH] reworked canCombine, combine. this is currently *NOT* correct, because it doesn't handle side effects. but it is really unlikely that real world code can invoke this wrong behaviour git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@178 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/expr/ComplexExpression.java | 45 +++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/jode/jode/expr/ComplexExpression.java b/jode/jode/expr/ComplexExpression.java index c9d187d..d2db47f 100644 --- a/jode/jode/expr/ComplexExpression.java +++ b/jode/jode/expr/ComplexExpression.java @@ -72,33 +72,44 @@ public class ComplexExpression extends Expression { } /** - * Checks if the given Expression (which should be a StoreInstruction) + * Checks if the given Expression (which must be a CombineableOperator) * can be combined into this expression. * @param e The store expression, must be of type void. * @return 1, if it can, 0, if no match was found and -1, if a * conflict was found. You may wish to check for >0. + * @exception ClassCastException, if e.getOperator + * is not a CombineableOperator. */ public int canCombine(Expression e) { - if (e instanceof ComplexExpression - && 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; +// Decompiler.err.println("Try to combine "+e+" into "+this); + if (e.getOperator() instanceof LocalStoreOperator + && e.getOperandCount() == 0) { + // Special case for locals created on inlining methods, which may + // combine everywhere + return containsMatchingLoad(e) ? 1 : 0; + } + + if (e instanceof ComplexExpression) { + if (((CombineableOperator) 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 + * given Expression (which must be a * StoreInstruction/IIncOperator). * @param e The store expression. * @return if this expression contains a matching load. + * @exception ClassCastException, if e.getOperator + * is not a CombineableOperator. */ public boolean containsMatchingLoad(Expression e) { if (e instanceof ComplexExpression @@ -127,13 +138,15 @@ public class ComplexExpression extends Expression { * canCombine returns the value 1. * @param e The store expression. * @return The combined expression. + * @exception ClassCastException, if e.getOperator + * is not a CombineableOperator. */ public Expression combine(Expression e) { - StoreInstruction store = (StoreInstruction) e.getOperator(); - if (store.matches(operator)) { - store.makeNonVoid(); - e.type = store.getType(); + CombineableOperator op = (CombineableOperator) e.getOperator(); + if (op.matches(operator)) { + op.makeNonVoid(); + e.type = e.getOperator().getType(); return e; } for (int i=0; i < subExpressions.length; i++) {