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. 62
      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;
subExpressions = sub;
for (int i=0; i< subExpressions.length; i++) {
if (subExpressions[i] == null)
subExpressions[i] = new NopOperator(Type.tUnknown);
subExpressions[i].parent = this;
operandcount += subExpressions[i].getOperandCount();
}
@ -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) {
@ -60,7 +76,10 @@ public class ComplexExpression extends Expression {
}
return this;
} else if (operator.operator == operator.LOG_NOT_OP) {
if (subExpressions[0] != null)
return subExpressions[0];
else
return new NopOperator(Type.tBoolean);
}
Operator negop =
@ -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;
@ -319,7 +338,7 @@ public class ComplexExpression extends Expression {
return false;
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 true;
@ -342,16 +361,18 @@ public class ComplexExpression extends Expression {
&& subExpressions[1].getType().isOfType(Type.tString))
return subExpressions[1];
subExpressions[1] = subExpressions[1].simplifyString();
return new ComplexExpression
(new StringAddOperator(), new Expression[]
{ e, subExpressions[1].simplifyString() });
{ e, subExpressions[1] });
}
if (operator instanceof ConstructorOperator
&& (((ConstructorOperator) operator).getClassType()
== Type.tStringBuffer)) {
if (subExpressions.length == 1 &&
subExpressions[0].getType().isOfType(Type.tString))
if (subExpressions.length == 1
&& subExpressions[0].getType().isOfType(Type.tString))
return subExpressions[0].simplifyString();
}
return null;
@ -405,8 +426,8 @@ public class ComplexExpression extends Expression {
public Expression simplify() {
if (operator instanceof IfThenElseOperator &&
operator.getType().isOfType(Type.tBoolean)) {
if (subExpressions[1].getOperator() instanceof ConstOperator &&
subExpressions[2].getOperator() instanceof ConstOperator) {
if (subExpressions[1].getOperator() instanceof ConstOperator
&& subExpressions[2].getOperator() instanceof ConstOperator) {
ConstOperator c1 =
(ConstOperator) subExpressions[1].getOperator();
ConstOperator c2 =
@ -419,9 +440,9 @@ public class ComplexExpression extends Expression {
return subExpressions[0].negate().simplify();
}
}
else if (operator instanceof StoreInstruction &&
subExpressions[subExpressions.length-1]
.getOperator() instanceof ConstOperator) {
else if (operator instanceof StoreInstruction
&& (subExpressions[subExpressions.length-1]
.getOperator() instanceof ConstOperator)) {
StoreInstruction store = (StoreInstruction) operator;
ConstOperator one = (ConstOperator)
@ -446,8 +467,9 @@ public class ComplexExpression extends Expression {
ppfixop.parent = this;
}
}
else if (operator instanceof CompareUnaryOperator &&
subExpressions[0].getOperator() instanceof CompareToIntOperator) {
else if (operator instanceof CompareUnaryOperator
&& (subExpressions[0].getOperator()
instanceof CompareToIntOperator)) {
CompareBinaryOperator newOp = new CompareBinaryOperator
(subExpressions[0].getOperator().getOperandType(0),

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

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

Loading…
Cancel
Save