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. 60
      jode/jode/expr/ComplexExpression.java
  2. 2
      jode/jode/expr/Expression.java
  3. 5
      jode/jode/expr/Operator.java

@ -36,6 +36,8 @@ 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++) {
if (subExpressions[i] == null)
subExpressions[i] = new NopOperator(Type.tUnknown);
subExpressions[i].parent = this; subExpressions[i].parent = this;
operandcount += subExpressions[i].getOperandCount(); operandcount += subExpressions[i].getOperandCount();
} }
@ -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) {
@ -60,7 +76,10 @@ public class ComplexExpression extends Expression {
} }
return this; return this;
} else if (operator.operator == operator.LOG_NOT_OP) { } else if (operator.operator == operator.LOG_NOT_OP) {
if (subExpressions[0] != null)
return subExpressions[0]; return subExpressions[0];
else
return new NopOperator(Type.tBoolean);
} }
Operator negop = Operator negop =
@ -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;
@ -342,16 +361,18 @@ public class ComplexExpression extends Expression {
&& 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;
@ -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),

@ -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