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
stable
jochen 26 years ago
parent 3c15842b45
commit 00bba38a0c
  1. 31
      jode/jode/expr/ComplexExpression.java

@ -72,17 +72,25 @@ 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. * can be combined into this expression.
* @param e The store expression, must be of type void. * @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 * @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. * conflict was found. You may wish to check for >0.
* @exception ClassCastException, if e.getOperator
* is not a CombineableOperator.
*/ */
public int canCombine(Expression e) { public int canCombine(Expression e) {
if (e instanceof ComplexExpression // Decompiler.err.println("Try to combine "+e+" into "+this);
&& e.getOperator() instanceof StoreInstruction if (e.getOperator() instanceof LocalStoreOperator
&& ((StoreInstruction) e.getOperator()).matches(operator)) { && 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; ComplexExpression ce = (ComplexExpression) e;
for (int i=0; i < ce.subExpressions.length-1; i++) { for (int i=0; i < ce.subExpressions.length-1; i++) {
if (!ce.subExpressions[i].equals(subExpressions[i])) if (!ce.subExpressions[i].equals(subExpressions[i]))
@ -90,15 +98,18 @@ public class ComplexExpression extends Expression {
} }
return 1; return 1;
} }
}
return subExpressions[0].canCombine(e); return subExpressions[0].canCombine(e);
} }
/** /**
* Checks if this expression contains a load, that matches the * Checks if this expression contains a load, that matches the
* given Expression (which should be a * given Expression (which must be a
* StoreInstruction/IIncOperator). * StoreInstruction/IIncOperator).
* @param e The store expression. * @param e The store expression.
* @return if this expression contains a matching load. * @return if this expression contains a matching load.
* @exception ClassCastException, if e.getOperator
* is not a CombineableOperator.
*/ */
public boolean containsMatchingLoad(Expression e) { public boolean containsMatchingLoad(Expression e) {
if (e instanceof ComplexExpression if (e instanceof ComplexExpression
@ -127,13 +138,15 @@ public class ComplexExpression extends Expression {
* canCombine returns the value 1. * canCombine returns the value 1.
* @param e The store expression. * @param e The store expression.
* @return The combined expression. * @return The combined expression.
* @exception ClassCastException, if e.getOperator
* is not a CombineableOperator.
*/ */
public Expression combine(Expression e) { public Expression combine(Expression e) {
StoreInstruction store = (StoreInstruction) e.getOperator(); CombineableOperator op = (CombineableOperator) e.getOperator();
if (store.matches(operator)) { if (op.matches(operator)) {
store.makeNonVoid(); op.makeNonVoid();
e.type = store.getType(); e.type = e.getOperator().getType();
return e; return e;
} }
for (int i=0; i < subExpressions.length; i++) { for (int i=0; i < subExpressions.length; i++) {

Loading…
Cancel
Save