diff --git a/jode/jode/expr/ComplexExpression.java b/jode/jode/expr/ComplexExpression.java index ebd47d2..4481432 100644 --- a/jode/jode/expr/ComplexExpression.java +++ b/jode/jode/expr/ComplexExpression.java @@ -36,7 +36,9 @@ public class ComplexExpression extends Expression { operator.parent = this; subExpressions = sub; for (int i=0; i< subExpressions.length; i++) { - subExpressions[i].parent = this; + if (subExpressions[i] == null) + subExpressions[i] = new NopOperator(Type.tUnknown); + subExpressions[i].parent = this; operandcount += subExpressions[i].getOperandCount(); } updateType(); @@ -46,6 +48,20 @@ public class ComplexExpression extends Expression { return operandcount; } + public Expression addOperand(Expression op) { + for (int i= subExpressions.length-1; i >= 0; i--) { + int opcount = subExpressions[i].getOperandCount(); + if (opcount > 0) { + subExpressions[i] = subExpressions[i].addOperand(op); + subExpressions[i].parent = this; + operandcount += subExpressions[i].getOperandCount() - opcount; + updateType(); + return this; + } + } + throw new jode.AssertError("addOperand called, but no operand needed"); + } + public Expression negate() { if (operator.getOperatorIndex() >= operator.COMPARE_OP && operator.getOperatorIndex() < operator.COMPARE_OP+6) { @@ -55,12 +71,15 @@ public class ComplexExpression extends Expression { operator.getOperatorIndex() == operator.LOG_OR_OP) { operator.setOperatorIndex(operator.getOperatorIndex() ^ 1); for (int i=0; i< subExpressions.length; i++) { - subExpressions[i] = subExpressions[i].negate(); + subExpressions[i] = subExpressions[i].negate(); subExpressions[i].parent = this; } return this; } else if (operator.operator == operator.LOG_NOT_OP) { - return subExpressions[0]; + if (subExpressions[0] != null) + return subExpressions[0]; + else + return new NopOperator(Type.tBoolean); } Operator negop = @@ -148,7 +167,7 @@ public class ComplexExpression extends Expression { ComplexExpression ce = (ComplexExpression) e; int i; for (i=0; i < ce.subExpressions.length-1; i++) { - if (!ce.subExpressions[i].equals(subExpressions[i])) + if (!ce.subExpressions[i].equals(subExpressions[i])) break; } if (i == ce.subExpressions.length-1) @@ -179,12 +198,12 @@ public class ComplexExpression extends Expression { return e; } for (int i=0; i < subExpressions.length; i++) { - Expression combined = subExpressions[i].combine(e); - if (combined != null) { - subExpressions[i] = combined; - subExpressions[i].parent = this; - return this; - } + Expression combined = subExpressions[i].combine(e); + if (combined != null) { + subExpressions[i] = combined; + subExpressions[i].parent = this; + return this; + } } return null; } @@ -197,15 +216,15 @@ public class ComplexExpression extends Expression { return subExpressions; } - public void setSubExpressions(int i, Expression expr) { - int diff = expr.getOperandCount() - - subExpressions[i].getOperandCount(); - subExpressions[i] = expr; - for (ComplexExpression ce = this; ce != null; - ce = (ComplexExpression) ce.parent) - ce.operandcount += diff; - updateType(); - } +// public void setSubExpressions(int i, Expression expr) { +// int diff = expr.getOperandCount() +// - subExpressions[i].getOperandCount(); +// subExpressions[i] = expr; +// for (ComplexExpression ce = this; ce != null; +// ce = (ComplexExpression) ce.parent) +// ce.operandcount += diff; +// updateType(); +// } void updateSubTypes() { boolean changed = false; @@ -287,24 +306,24 @@ public class ComplexExpression extends Expression { public String toString() { String[] expr = new String[subExpressions.length]; for (int i=0; i") - + operator.getOperandType(i)+") "+expr[i]; - if (700 < operator.getOperandPriority(i)) - expr[i] = "(" + expr[i] + ")"; - } - else if (subExpressions[i].getType() == Type.tError) - expr[i] = "(/*type error */" + expr[i]+")"; - } - if (Decompiler.isTypeDebugging && parent != null) - return "[("+type+") "+ operator.toString(expr)+"]"; + expr[i] = subExpressions[i]. + toString(Decompiler.isTypeDebugging + ? 700 /* type cast priority */ + : operator.getOperandPriority(i)); + if (Decompiler.isTypeDebugging) { + expr[i] = "("+ + (operator.getOperandType(i) + .equals(subExpressions[i].getType()) + ? "" : ""+subExpressions[i].getType()+"->") + + operator.getOperandType(i)+") "+expr[i]; + if (700 < operator.getOperandPriority(i)) + expr[i] = "(" + expr[i] + ")"; + } + else if (subExpressions[i].getType() == Type.tError) + expr[i] = "(/*type error */" + expr[i]+")"; + } + if (Decompiler.isTypeDebugging && parent != null) + return "[("+type+") "+ operator.toString(expr)+"]"; return operator.toString(expr); } @@ -319,7 +338,7 @@ public class ComplexExpression extends Expression { return false; for (int i=0; i