git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@395 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 2752c2b035
commit e51d2718bb
  1. 130
      jode/jode/expr/ComplexExpression.java
  2. 2
      jode/jode/expr/Expression.java
  3. 5
      jode/jode/expr/Operator.java

@ -36,7 +36,9 @@ public class ComplexExpression extends Expression {
operator.parent = this; operator.parent = this;
subExpressions = sub; subExpressions = sub;
for (int i=0; i< subExpressions.length; i++) { 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(); operandcount += subExpressions[i].getOperandCount();
} }
updateType(); updateType();
@ -46,6 +48,20 @@ public class ComplexExpression extends Expression {
return operandcount; 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() { public Expression negate() {
if (operator.getOperatorIndex() >= operator.COMPARE_OP && if (operator.getOperatorIndex() >= operator.COMPARE_OP &&
operator.getOperatorIndex() < operator.COMPARE_OP+6) { operator.getOperatorIndex() < operator.COMPARE_OP+6) {
@ -55,12 +71,15 @@ public class ComplexExpression extends Expression {
operator.getOperatorIndex() == operator.LOG_OR_OP) { operator.getOperatorIndex() == operator.LOG_OR_OP) {
operator.setOperatorIndex(operator.getOperatorIndex() ^ 1); operator.setOperatorIndex(operator.getOperatorIndex() ^ 1);
for (int i=0; i< subExpressions.length; i++) { for (int i=0; i< subExpressions.length; i++) {
subExpressions[i] = subExpressions[i].negate(); subExpressions[i] = subExpressions[i].negate();
subExpressions[i].parent = this; subExpressions[i].parent = this;
} }
return this; return this;
} else if (operator.operator == operator.LOG_NOT_OP) { } 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 = Operator negop =
@ -148,7 +167,7 @@ public class ComplexExpression extends Expression {
ComplexExpression ce = (ComplexExpression) e; ComplexExpression ce = (ComplexExpression) e;
int i; int i;
for (i=0; i < ce.subExpressions.length-1; 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; break;
} }
if (i == ce.subExpressions.length-1) if (i == ce.subExpressions.length-1)
@ -179,12 +198,12 @@ public class ComplexExpression extends Expression {
return e; return e;
} }
for (int i=0; i < subExpressions.length; i++) { for (int i=0; i < subExpressions.length; i++) {
Expression combined = subExpressions[i].combine(e); Expression combined = subExpressions[i].combine(e);
if (combined != null) { if (combined != null) {
subExpressions[i] = combined; subExpressions[i] = combined;
subExpressions[i].parent = this; subExpressions[i].parent = this;
return this; return this;
} }
} }
return null; return null;
} }
@ -197,15 +216,15 @@ public class ComplexExpression extends Expression {
return subExpressions; return subExpressions;
} }
public void setSubExpressions(int i, Expression expr) { // public void setSubExpressions(int i, Expression expr) {
int diff = expr.getOperandCount() // int diff = expr.getOperandCount()
- subExpressions[i].getOperandCount(); // - subExpressions[i].getOperandCount();
subExpressions[i] = expr; // subExpressions[i] = expr;
for (ComplexExpression ce = this; ce != null; // for (ComplexExpression ce = this; ce != null;
ce = (ComplexExpression) ce.parent) // ce = (ComplexExpression) ce.parent)
ce.operandcount += diff; // ce.operandcount += diff;
updateType(); // updateType();
} // }
void updateSubTypes() { void updateSubTypes() {
boolean changed = false; boolean changed = false;
@ -287,24 +306,24 @@ public class ComplexExpression extends Expression {
public String toString() { public String toString() {
String[] expr = new String[subExpressions.length]; String[] expr = new String[subExpressions.length];
for (int i=0; i<subExpressions.length; i++) { for (int i=0; i<subExpressions.length; i++) {
expr[i] = subExpressions[i]. expr[i] = subExpressions[i].
toString(Decompiler.isTypeDebugging toString(Decompiler.isTypeDebugging
? 700 /* type cast priority */ ? 700 /* type cast priority */
: operator.getOperandPriority(i)); : operator.getOperandPriority(i));
if (Decompiler.isTypeDebugging) { if (Decompiler.isTypeDebugging) {
expr[i] = "("+ expr[i] = "("+
(operator.getOperandType(i) (operator.getOperandType(i)
.equals(subExpressions[i].getType()) .equals(subExpressions[i].getType())
? "" : ""+subExpressions[i].getType()+"->") ? "" : ""+subExpressions[i].getType()+"->")
+ operator.getOperandType(i)+") "+expr[i]; + operator.getOperandType(i)+") "+expr[i];
if (700 < operator.getOperandPriority(i)) if (700 < operator.getOperandPriority(i))
expr[i] = "(" + expr[i] + ")"; expr[i] = "(" + expr[i] + ")";
} }
else if (subExpressions[i].getType() == Type.tError) else if (subExpressions[i].getType() == Type.tError)
expr[i] = "(/*type error */" + expr[i]+")"; expr[i] = "(/*type error */" + expr[i]+")";
} }
if (Decompiler.isTypeDebugging && parent != null) if (Decompiler.isTypeDebugging && parent != null)
return "[("+type+") "+ operator.toString(expr)+"]"; return "[("+type+") "+ operator.toString(expr)+"]";
return operator.toString(expr); return operator.toString(expr);
} }
@ -319,7 +338,7 @@ public class ComplexExpression extends Expression {
return false; return false;
for (int i=0; i<subExpressions.length; i++) { for (int i=0; i<subExpressions.length; i++) {
if (!subExpressions[i].equals(expr.subExpressions[i])) if(!subExpressions[i].equals(expr.subExpressions[i]))
return false; return false;
} }
return true; return true;
@ -339,19 +358,21 @@ public class ComplexExpression extends Expression {
return null; return null;
if (e == EMPTYSTRING if (e == EMPTYSTRING
&& subExpressions[1].getType().isOfType(Type.tString)) && subExpressions[1].getType().isOfType(Type.tString))
return subExpressions[1]; return subExpressions[1];
subExpressions[1] = subExpressions[1].simplifyString();
return new ComplexExpression return new ComplexExpression
(new StringAddOperator(), new Expression[] (new StringAddOperator(), new Expression[]
{ e, subExpressions[1].simplifyString() }); { e, subExpressions[1] });
} }
if (operator instanceof ConstructorOperator if (operator instanceof ConstructorOperator
&& (((ConstructorOperator) operator).getClassType() && (((ConstructorOperator) operator).getClassType()
== Type.tStringBuffer)) { == Type.tStringBuffer)) {
if (subExpressions.length == 1 && if (subExpressions.length == 1
subExpressions[0].getType().isOfType(Type.tString)) && subExpressions[0].getType().isOfType(Type.tString))
return subExpressions[0].simplifyString(); return subExpressions[0].simplifyString();
} }
return null; return null;
@ -396,7 +417,7 @@ public class ComplexExpression extends Expression {
return new ComplexExpression return new ComplexExpression
(new StringAddOperator(), new Expression[] (new StringAddOperator(), new Expression[]
{ left, right }); { left, right });
} }
} }
return this; return this;
@ -405,8 +426,8 @@ public class ComplexExpression extends Expression {
public Expression simplify() { public Expression simplify() {
if (operator instanceof IfThenElseOperator && if (operator instanceof IfThenElseOperator &&
operator.getType().isOfType(Type.tBoolean)) { operator.getType().isOfType(Type.tBoolean)) {
if (subExpressions[1].getOperator() instanceof ConstOperator && if (subExpressions[1].getOperator() instanceof ConstOperator
subExpressions[2].getOperator() instanceof ConstOperator) { && subExpressions[2].getOperator() instanceof ConstOperator) {
ConstOperator c1 = ConstOperator c1 =
(ConstOperator) subExpressions[1].getOperator(); (ConstOperator) subExpressions[1].getOperator();
ConstOperator c2 = ConstOperator c2 =
@ -419,9 +440,9 @@ public class ComplexExpression extends Expression {
return subExpressions[0].negate().simplify(); return subExpressions[0].negate().simplify();
} }
} }
else if (operator instanceof StoreInstruction && else if (operator instanceof StoreInstruction
subExpressions[subExpressions.length-1] && (subExpressions[subExpressions.length-1]
.getOperator() instanceof ConstOperator) { .getOperator() instanceof ConstOperator)) {
StoreInstruction store = (StoreInstruction) operator; StoreInstruction store = (StoreInstruction) operator;
ConstOperator one = (ConstOperator) ConstOperator one = (ConstOperator)
@ -446,8 +467,9 @@ public class ComplexExpression extends Expression {
ppfixop.parent = this; ppfixop.parent = this;
} }
} }
else if (operator instanceof CompareUnaryOperator && else if (operator instanceof CompareUnaryOperator
subExpressions[0].getOperator() instanceof CompareToIntOperator) { && (subExpressions[0].getOperator()
instanceof CompareToIntOperator)) {
CompareBinaryOperator newOp = new CompareBinaryOperator CompareBinaryOperator newOp = new CompareBinaryOperator
(subExpressions[0].getOperator().getOperandType(0), (subExpressions[0].getOperator().getOperandType(0),
@ -464,7 +486,7 @@ public class ComplexExpression extends Expression {
else if (operator instanceof CompareUnaryOperator && else if (operator instanceof CompareUnaryOperator &&
operator.getOperandType(0).isOfType(Type.tBoolean)) { operator.getOperandType(0).isOfType(Type.tBoolean)) {
/* xx == false */ /* xx == false */
if (operator.getOperatorIndex() == operator.EQUALS_OP) if (operator.getOperatorIndex() == operator.EQUALS_OP)
return subExpressions[0].negate().simplify(); return subExpressions[0].negate().simplify();
/* xx != false */ /* xx != false */
if (operator.getOperatorIndex() == operator.NOTEQUALS_OP) if (operator.getOperatorIndex() == operator.NOTEQUALS_OP)
@ -521,8 +543,8 @@ public class ComplexExpression extends Expression {
return stringExpr.simplify(); return stringExpr.simplify();
} }
for (int i=0; i< subExpressions.length; i++) { for (int i=0; i< subExpressions.length; i++) {
subExpressions[i] = subExpressions[i].simplify(); subExpressions[i] = subExpressions[i].simplify();
subExpressions[i].parent = this; subExpressions[i].parent = this;
} }
return this; return this;
} }

@ -52,6 +52,8 @@ public abstract class Expression {
*/ */
public abstract int getOperandCount(); public abstract int getOperandCount();
public abstract Expression addOperand(Expression op);
public Expression negate() { public Expression negate() {
Operator negop = Operator negop =
new UnaryOperator(Type.tBoolean, Operator.LOG_NOT_OP); new UnaryOperator(Type.tBoolean, Operator.LOG_NOT_OP);

@ -54,6 +54,11 @@ public abstract class Operator extends Expression {
throw new jode.AssertError("type == null"); throw new jode.AssertError("type == null");
} }
public Expression addOperand(Expression op) {
return new ComplexExpression
(this, new Expression[getOperandCount()]).addOperand(op);
}
public Operator getOperator() { public Operator getOperator() {
return this; return this;
} }

Loading…
Cancel
Save