*** empty log message ***

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@42 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 27 years ago
parent 3714549529
commit f7064ccbaa
  1. 2
      jode/jode/expr/CompareBinaryOperator.java
  2. 2
      jode/jode/expr/CompareUnaryOperator.java
  3. 278
      jode/jode/expr/Expression.java
  4. 11
      jode/jode/expr/Operator.java
  5. 4
      jode/jode/flow/CombineIfGotoExpressions.java
  6. 36
      jode/jode/flow/CreateAssignExpression.java
  7. 23
      jode/jode/flow/CreateConstantArray.java
  8. 52
      jode/jode/flow/CreateExpression.java
  9. 13
      jode/jode/flow/CreateIfThenElseOperator.java
  10. 8
      jode/jode/flow/CreateNewConstructor.java
  11. 44
      jode/jode/flow/CreatePostIncExpression.java
  12. 7
      jode/jode/flow/LoopBlock.java

@ -27,7 +27,7 @@ public class CompareBinaryOperator extends SimpleOperator {
} }
public int getPriority() { public int getPriority() {
switch (getOperator()) { switch (getOperatorIndex()) {
case 26: case 26:
case 27: case 27:
return 500; return 500;

@ -30,7 +30,7 @@ public class CompareUnaryOperator extends SimpleOperator {
} }
public int getPriority() { public int getPriority() {
switch (getOperator()) { switch (getOperatorIndex()) {
case 26: case 26:
case 27: case 27:
return 500; return 500;

@ -19,290 +19,40 @@
package jode; package jode;
import sun.tools.java.Type; import sun.tools.java.Type;
import sun.tools.java.Constants;
import sun.tools.java.FieldDefinition;
public class Expression extends Instruction { public abstract class Expression extends Instruction {
Operator operator;
Expression[] subExpressions;
Expression parent = null;
public Expression(Operator op, Expression[] sub) { ComplexExpression parent = null;
super(MyType.tUnknown);
operator = op; public Expression(Type type) {
subExpressions = sub; super (type);
operator.setExpression(this);
if (subExpressions.length != op.getOperandCount())
throw new AssertError ("Operand count mismatch: "+
subExpressions.length + " != " +
op.getOperandCount());
if (subExpressions.length > 0) {
Type types[] = new Type[subExpressions.length];
for (int i=0; i < types.length; i++) {
subExpressions[i].parent = this;
types[i] = subExpressions[i].getType();
}
operator.setOperandType(types);
updateSubTypes();
}
this.type = operator.getType();
} }
public Expression negate() { public Expression negate() {
if (operator.operator >= operator.COMPARE_OP &&
operator.operator < operator.COMPARE_OP+6) {
operator.setOperator(operator.getOperator() ^ 1);
return this;
} else if (operator.operator == operator.LOG_AND_OP ||
operator.operator == operator.LOG_OR_OP) {
operator.setOperator(operator.getOperator() ^ 1);
for (int i=0; i< subExpressions.length; i++) {
subExpressions[i] = subExpressions[i].negate();
}
return this;
} else if (operator.operator == operator.LOG_NOT_OP) {
return subExpressions[0];
}
Operator negop = Operator negop =
new UnaryOperator(Type.tBoolean, Operator.LOG_NOT_OP); new UnaryOperator(Type.tBoolean, Operator.LOG_NOT_OP);
Expression[] e = { this }; Expression[] e = { this };
return new Expression(negop, e); return new ComplexExpression(negop, e);
} }
public Expression tryToCombine(Expression e) { public Expression tryToCombine(Expression e) {
if (e.operator instanceof StoreInstruction) {
StoreInstruction store = (StoreInstruction) e.operator;
if (store.matches(operator)) {
int i;
for (i=0; i < e.subExpressions.length-1; i++) {
if (!e.subExpressions[i].equals
(subExpressions[i]))
break;
}
if (i == e.subExpressions.length-1) {
operator =
new AssignOperator(store.getOperator(), store);
subExpressions = e.subExpressions;
return this;
}
}
for (int i=0; i < subExpressions.length; i++) {
Expression combined = subExpressions[i].tryToCombine(e);
if (combined != null) {
subExpressions[i] = combined;
return this;
}
}
}
return null; return null;
} }
public Operator getOperator() { Expression simplifyStringBuffer() {
return operator; return this;
}
public Expression[] getSubExpressions() {
return subExpressions;
}
public void updateSubTypes() {
for (int i=0; i < subExpressions.length; i++) {
subExpressions[i].setType(operator.getOperandType(i));
}
}
public void setType(Type newType) {
newType = MyType.intersection(type, newType);
if (newType != type) {
type = newType;
operator.setType(type);
}
} }
public boolean isVoid() { public abstract Operator getOperator();
return operator.getType() == Type.tVoid;
}
String toString(int minPriority) { String toString(int minPriority) {
String[] expr = new String[subExpressions.length]; String result = toString();
for (int i=0; i<subExpressions.length; i++) { if (getOperator().getPriority() < minPriority)
expr[i] = subExpressions[i]. return "("+result+")";
toString(operator.getOperandPriority(i));
}
String result = operator.toString(expr);
if (operator.getPriority() < minPriority) {
result = "("+result+")";
}
if (Decompiler.isTypeDebugging)
result = "(("+operator.getType()+")"+result+")";
else if (operator.getType() == MyType.tError)
result = "(/*type error */" + result+")";
return result; return result;
} }
public boolean equals(Object o) { public boolean isVoid() {
if (this == o) return getType() == Type.tVoid;
return true;
if (!(o instanceof Expression))
return false;
Expression expr = (Expression) o;
if (!operator.equals(expr.operator) ||
subExpressions.length != expr.subExpressions.length)
return false;
for (int i=0; i<subExpressions.length; i++) {
if (!subExpressions[i].equals(expr.subExpressions[i]))
return false;
}
return true;
}
public String toString() {
return toString(0);
}
static Expression emptyString =
new Expression(new EmptyStringOperator(), new Expression[0]);
Expression simplifyStringBuffer() {
FieldDefinition field;
if (operator instanceof InvokeOperator &&
(field = ((InvokeOperator)operator).getField())
.getClassDefinition().getName() ==
Constants.idJavaLangStringBuffer &&
!((InvokeOperator)operator).isStatic() &&
field.getName() == Constants.idAppend &&
field.getType().getArgumentTypes().length == 1) {
Expression e = subExpressions[0].simplifyStringBuffer();
if (e == null)
return null;
if (e.operator instanceof EmptyStringOperator &&
MyType.isOfType(subExpressions[1].getType(), Type.tString))
return subExpressions[1];
Expression[] exprs = { e,
(Expression)subExpressions[1].simplify() };
return new Expression(new StringAddOperator(), exprs);
}
if (operator instanceof ConstructorOperator &&
MyType.isOfType(operator.getType(), MyType.tStringBuffer)) {
if (operator.getOperandCount() == 1)
return emptyString;
else if (operator.getOperandCount() == 2 &&
MyType.isOfType(subExpressions[1].getType(),
MyType.tString))
return (Expression) subExpressions[1].simplify();
}
return null;
}
public Instruction simplify() {
if (operator instanceof IfThenElseOperator &&
operator.getType() == Type.tBoolean) {
if (subExpressions[1].operator instanceof ConstOperator &&
subExpressions[2].operator instanceof ConstOperator) {
ConstOperator c1 = (ConstOperator) subExpressions[1].operator;
ConstOperator c2 = (ConstOperator) subExpressions[2].operator;
if (c1.getValue().equals("true") &&
c2.getValue().equals("false"))
return subExpressions[0].simplify();
if (c2.getValue().equals("true") &&
c1.getValue().equals("false"))
return subExpressions[0].negate().simplify();
}
}
// if ((operator instanceof AssignOperator ||
// operator instanceof StoreInstruction) &&
// subExpressions[subExpressions.length-1]
// .operator instanceof ConstOperator) {
// StoreInstruction store;
// if (operator instanceof AssignOperator)
// store = ((AssignOperator)operator).getStore();
// else
// store = (StoreInstruction)operator;
// ConstOperator one = (ConstOperator)
// subExpressions[subExpressions.length-1].operator;
// if ((operator.getOperator() ==
// operator.OPASSIGN_OP+operator.ADD_OP ||
// operator.getOperator() ==
// operator.OPASSIGN_OP+operator.NEG_OP) &&
// (one.getValue().equals("1") ||
// one.getValue().equals("-1"))) {
// int op = ((operator.getOperator() ==
// operator.OPASSIGN_OP+operator.ADD_OP) ==
// one.getValue().equals("1"))?
// operator.INC_OP : operator.DEC_OP;
// return new Expression
// (new PostFixOperator
// (store.getType(), op, store,
// operator instanceof StoreInstruction),
// new Expression[0]).simplify();
// }
// }
if (operator instanceof CompareUnaryOperator &&
subExpressions[0].operator instanceof CompareToIntOperator) {
CompareBinaryOperator newOp = new CompareBinaryOperator
(subExpressions[0].operator.getOperandType(0),
operator.getOperator());
return new Expression(newOp, subExpressions[0].subExpressions).
simplify();
}
if (operator instanceof CompareUnaryOperator &&
operator.getOperandType(0) != Type.tBoolean) {
if (subExpressions[0].operator instanceof ConstOperator) {
ConstOperator c = (ConstOperator) subExpressions[0].operator;
if (c.getValue().equals("0") || c.getValue().equals("1")) {
Type[] newType = {Type.tBoolean};
operator.setOperandType(newType);
}
}
}
if (operator instanceof CompareUnaryOperator &&
operator.getOperandType(0) == Type.tBoolean) {
if (operator.getOperator() == 26) /* xx == false */
return subExpressions[0].negate().simplify();
if (operator.getOperator() == 27) /* xx != false */
return subExpressions[0].simplify();
}
if (operator instanceof InvokeOperator &&
((InvokeOperator)operator).getField().
getName() == Constants.idToString &&
!((InvokeOperator)operator).isStatic() &&
((InvokeOperator)operator).getField().
getClassDefinition().getType() == MyType.tStringBuffer &&
operator.getOperandCount() == 1) {
Instruction simple = subExpressions[0].simplifyStringBuffer();
if (simple != null)
return simple;
}
if (operator instanceof InvokeOperator &&
((InvokeOperator)operator).getField().
getName() == Constants.idValueOf &&
((InvokeOperator)operator).isStatic() &&
((InvokeOperator)operator).getField().
getClassDefinition().getType() == MyType.tString &&
operator.getOperandCount() == 1) {
if (subExpressions[0].getType() == MyType.tString)
return subExpressions[0].simplify();
else {
Expression[] exprs = {
emptyString,
(Expression) subExpressions[0].simplify()
};
return new Expression(new StringAddOperator(), exprs);
}
}
for (int i=0; i< subExpressions.length; i++)
subExpressions[i] = (Expression) subExpressions[i].simplify();
return this;
} }
} }

@ -20,7 +20,7 @@
package jode; package jode;
import sun.tools.java.Type; import sun.tools.java.Type;
public abstract class Operator extends Instruction { public abstract class Operator extends Expression {
public final static int ADD_OP = 1; public final static int ADD_OP = 1;
public final static int NEG_OP = 2; public final static int NEG_OP = 2;
public final static int SHIFT_OP = 6; public final static int SHIFT_OP = 6;
@ -59,10 +59,14 @@ public abstract class Operator extends Instruction {
expression = expr; expression = expr;
} }
public int getOperator() { public Operator getOperator() {
return this;
}
public int getOperatorIndex() {
return operator; return operator;
} }
public void setOperator(int op) { public void setOperatorIndex(int op) {
operator = op; operator = op;
} }
@ -120,3 +124,4 @@ public abstract class Operator extends Instruction {
return toString(operands); return toString(operands);
} }
} }

@ -20,6 +20,7 @@
package jode.flow; package jode.flow;
import java.util.Vector; import java.util.Vector;
import jode.Expression; import jode.Expression;
import jode.ComplexExpression;
import jode.MyType; import jode.MyType;
import jode.BinaryOperator; import jode.BinaryOperator;
@ -66,7 +67,8 @@ public class CombineIfGotoExpressions implements Transformation{
} }
prevJump.prev.removeJump(); prevJump.prev.removeJump();
Expression cond = Expression cond =
new Expression(new BinaryOperator(MyType.tBoolean, operator), e); new ComplexExpression
(new BinaryOperator(MyType.tBoolean, operator), e);
cb.setInstruction(cond); cb.setInstruction(cond);
cb.replace(cb.outer, cb); cb.replace(cb.outer, cb);
return true; return true;

@ -31,38 +31,34 @@ public class CreateAssignExpression implements Transformation{
StoreInstruction store; StoreInstruction store;
BinaryOperator binop; BinaryOperator binop;
InstructionContainer lastBlock; InstructionContainer lastBlock;
SequentialBlock rhsBlock; SequentialBlock opBlock;
SequentialBlock sequBlock; SequentialBlock sequBlock;
try { try {
InstructionBlock ib; InstructionBlock ib;
lastBlock = (InstructionContainer) flow.lastModified; lastBlock = (InstructionContainer) flow.lastModified;
store = (StoreInstruction) lastBlock.getInstruction(); store = (StoreInstruction) lastBlock.getInstruction();
sequBlock = (SequentialBlock) lastBlock.outer; opBlock = (SequentialBlock) lastBlock.outer;
if (sequBlock.subBlocks[1] != lastBlock) if (opBlock.subBlocks[1] != lastBlock)
return false; return false;
ib = (InstructionBlock) sequBlock.subBlocks[0]; ib = (InstructionBlock) opBlock.subBlocks[0];
binop = (BinaryOperator) ib.getInstruction(); ComplexExpression binopExpr =
if (binop.getOperator() < binop.ADD_OP || (ComplexExpression) ib.getInstruction();
binop.getOperator() >= binop.ASSIGN_OP) binop = (BinaryOperator) binopExpr.getOperator();
if (binop.getOperatorIndex() < binop.ADD_OP ||
binop.getOperatorIndex() >= binop.ASSIGN_OP)
return false; return false;
sequBlock = (SequentialBlock) sequBlock.outer; rightHandSide = binopExpr.getSubExpressions()[1];
ib = (InstructionBlock) sequBlock.subBlocks[0];
rightHandSide = (Expression) ib.getInstruction();
if (rightHandSide.isVoid()) if (rightHandSide.isVoid())
return false; /* XXX */ return false; /* XXX */
rhsBlock = (SequentialBlock) sequBlock.outer; Operator load = (Operator) binopExpr.getSubExpressions()[0];
ib = (InstructionBlock) rhsBlock.subBlocks[0];
Operator load = (Operator) ib.getInstruction();
if (!store.matches(load)) if (!store.matches(load))
return false; return false;
sequBlock = (SequentialBlock) rhsBlock.outer; sequBlock = (SequentialBlock) opBlock.outer;
ib = (InstructionBlock) sequBlock.subBlocks[0]; ib = (InstructionBlock) sequBlock.subBlocks[0];
DupOperator dup = (DupOperator) ib.getInstruction(); DupOperator dup = (DupOperator) ib.getInstruction();
@ -74,15 +70,15 @@ public class CreateAssignExpression implements Transformation{
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
return false; return false;
} }
((InstructionBlock)rhsBlock.subBlocks[0]) ((InstructionBlock)opBlock.subBlocks[0])
.setInstruction(rightHandSide); .setInstruction(rightHandSide);
rhsBlock.replace(sequBlock, rhsBlock); opBlock.replace(sequBlock, opBlock);
store.setOperator(store.OPASSIGN_OP+binop.getOperator()); store.setOperatorIndex(store.OPASSIGN_OP+binop.getOperatorIndex());
store.setLValueType(MyType.intersection(binop.getType(), store.setLValueType(MyType.intersection(binop.getType(),
store.getLValueType())); store.getLValueType()));
lastBlock.setInstruction(store); lastBlock.setInstruction(store);
lastBlock.replace(rhsBlock.subBlocks[1], lastBlock); lastBlock.replace(opBlock.subBlocks[1], lastBlock);
return true; return true;
} }

@ -19,6 +19,7 @@
package jode.flow; package jode.flow;
import jode.Expression; import jode.Expression;
import jode.ComplexExpression;
import jode.DupOperator; import jode.DupOperator;
import jode.ArrayStoreOperator; import jode.ArrayStoreOperator;
import jode.NewArrayOperator; import jode.NewArrayOperator;
@ -69,9 +70,8 @@ public class CreateConstantArray implements Transformation {
return false; return false;
else { else {
while (index < lastindex) { while (index < lastindex) {
consts[lastindex--] = new Expression consts[lastindex--] =
(new ConstOperator(MyType.tUnknown, "0"), new ConstOperator(MyType.tUnknown, "0");
new Expression[0]);
} }
} }
consts[lastindex--] = lastconst; consts[lastindex--] = lastconst;
@ -88,11 +88,11 @@ public class CreateConstantArray implements Transformation {
if (count == 0) if (count == 0)
return false; return false;
while (lastindex >= 0) { while (lastindex >= 0) {
consts[lastindex--] = new Expression consts[lastindex--] =
(new ConstOperator(MyType.tUnknown, "0"), new ConstOperator(MyType.tUnknown, "0");
new Expression[0]);
} }
Expression newArrayExpr = (Expression) ib.getInstruction(); ComplexExpression newArrayExpr =
(ComplexExpression) ib.getInstruction();
NewArrayOperator newArrayOp = NewArrayOperator newArrayOp =
(NewArrayOperator) newArrayExpr.getOperator(); (NewArrayOperator) newArrayExpr.getOperator();
type = newArrayOp.getType(); type = newArrayOp.getType();
@ -111,9 +111,7 @@ public class CreateConstantArray implements Transformation {
Expression[] newConsts = new Expression[arraylength]; Expression[] newConsts = new Expression[arraylength];
System.arraycopy(consts, 0, newConsts, 0, consts.length); System.arraycopy(consts, 0, newConsts, 0, consts.length);
for (int i=consts.length; i<arraylength; i++) for (int i=consts.length; i<arraylength; i++)
newConsts[i] = new Expression newConsts[i] = new ConstOperator(MyType.tUnknown, "0");
(new ConstOperator(MyType.tUnknown, "0"),
new Expression[0]);
consts = newConsts; consts = newConsts;
} }
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
@ -125,8 +123,9 @@ public class CreateConstantArray implements Transformation {
System.err.print("a"); System.err.print("a");
lastBlock.setInstruction lastBlock.setInstruction
(new Expression(new ConstantArrayOperator(type, consts.length), (new ComplexExpression
consts)); (new ConstantArrayOperator(type, consts.length),
consts));
lastBlock.replace(sequBlock.subBlocks[0], lastBlock); lastBlock.replace(sequBlock.subBlocks[0], lastBlock);
flow.lastModified.replace(sequBlock.subBlocks[1], flow.lastModified); flow.lastModified.replace(sequBlock.subBlocks[1], flow.lastModified);
return true; return true;

@ -20,6 +20,7 @@
package jode.flow; package jode.flow;
import jode.Operator; import jode.Operator;
import jode.Expression; import jode.Expression;
import jode.ComplexExpression;
/** /**
* This transformation creates expressions. It transforms * This transformation creates expressions. It transforms
@ -42,7 +43,7 @@ public class CreateExpression implements Transformation {
Operator op; Operator op;
Expression exprs[]; Expression exprs[];
int params; int params;
StructuredBlock block; StructuredBlock sequBlock;
// try { // try {
// System.err.println("Transformation on: "+flow.getLabel()); // System.err.println("Transformation on: "+flow.getLabel());
@ -58,23 +59,23 @@ public class CreateExpression implements Transformation {
// } // }
try { try {
SequentialBlock sequBlock; op = (Operator)
block = flow.lastModified; ((InstructionContainer)flow.lastModified).getInstruction();
op = (Operator) ((InstructionContainer)block).getInstruction(); params = op.getOperandCount();
params = op.getOperandCount(); if (params == 0)
return false;
exprs = new Expression[params]; exprs = new Expression[params];
for (int i = params-1; i>=0; i--) {
sequBlock = (SequentialBlock)block.outer;
if (i == params-1 &&
sequBlock.getSubBlocks()[1] != block)
return false;
block = sequBlock.getSubBlocks()[0]; sequBlock = flow.lastModified.outer;
if (sequBlock.getSubBlocks()[1] != flow.lastModified)
return false;
for (int i = params-1; i>=0; i--) {
InstructionBlock block =
(InstructionBlock) sequBlock.getSubBlocks()[0];
if (block.jump != null) if (block.jump != null)
return false; return false;
exprs[i] = exprs[i] =
(Expression) ((InstructionBlock)block).getInstruction(); (Expression) block.getInstruction();
if (exprs[i].isVoid()) { if (exprs[i].isVoid()) {
if (i == params-1) if (i == params-1)
return false; return false;
@ -90,7 +91,8 @@ public class CreateExpression implements Transformation {
setInstruction(e); setInstruction(e);
exprs[i] = e; exprs[i] = e;
} }
block = sequBlock; if (i > 0)
sequBlock = (SequentialBlock)sequBlock.outer;
} }
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
return false; return false;
@ -100,27 +102,9 @@ public class CreateExpression implements Transformation {
if(jode.Decompiler.isVerbose && params > 0) if(jode.Decompiler.isVerbose && params > 0)
System.err.print("x"); System.err.print("x");
// try {
// System.err.println("replacing: ");
// jode.TabbedPrintWriter writer =
// new jode.TabbedPrintWriter(System.err, " ");
// writer.tab();
// block.dumpSource(writer);
// System.err.println("with: ");
// flow.lastModified.dumpSource(writer);
// } catch (java.io.IOException ioex) {
// }
((InstructionContainer) flow.lastModified).setInstruction ((InstructionContainer) flow.lastModified).setInstruction
(new Expression(op, exprs)); (new ComplexExpression(op, exprs));
flow.lastModified.replace(block, flow.lastModified); flow.lastModified.replace(sequBlock, flow.lastModified);
// try {
// System.err.println("result: ");
// jode.TabbedPrintWriter writer =
// new jode.TabbedPrintWriter(System.err, " ");
// writer.tab();
// flow.lastModified.dumpSource(writer);
// } catch (java.io.IOException ioex) {
// }
return true; return true;
} }
} }

@ -19,6 +19,7 @@
package jode.flow; package jode.flow;
import jode.Expression; import jode.Expression;
import jode.ComplexExpression;
import jode.IfThenElseOperator; import jode.IfThenElseOperator;
import jode.MyType; import jode.MyType;
import jode.CompareUnaryOperator; import jode.CompareUnaryOperator;
@ -76,9 +77,9 @@ public class CreateIfThenElseOperator implements Transformation {
(CompareUnaryOperator) conditional.getInstruction(); (CompareUnaryOperator) conditional.getInstruction();
FlowBlock trueDestination; FlowBlock trueDestination;
if (compare.getOperator() == compare.EQUALS_OP) if (compare.getOperatorIndex() == compare.EQUALS_OP)
trueDestination = conditional.jump.destination; trueDestination = conditional.jump.destination;
else if (compare.getOperator() == compare.NOTEQUALS_OP) else if (compare.getOperatorIndex() == compare.NOTEQUALS_OP)
trueDestination = conditional.trueBlock.jump.destination; trueDestination = conditional.trueBlock.jump.destination;
else else
return false; return false;
@ -116,10 +117,8 @@ public class CreateIfThenElseOperator implements Transformation {
InstructionBlock pushBlock = InstructionBlock pushBlock =
(InstructionBlock) sequBlock.subBlocks[1]; (InstructionBlock) sequBlock.subBlocks[1];
Expression zeroExpr =
(Expression) pushBlock.getInstruction();
jode.ConstOperator zero = jode.ConstOperator zero =
(jode.ConstOperator) zeroExpr.getOperator(); (jode.ConstOperator) pushBlock.getInstruction();
if (!zero.getValue().equals("0")) if (!zero.getValue().equals("0"))
return false; return false;
@ -149,7 +148,7 @@ public class CreateIfThenElseOperator implements Transformation {
(MyType.intersection(e[1].getType(),e[2].getType())); (MyType.intersection(e[1].getType(),e[2].getType()));
((InstructionBlock)ifBlock.thenBlock). ((InstructionBlock)ifBlock.thenBlock).
setInstruction(new Expression(iteo, e)); setInstruction(new ComplexExpression(iteo, e));
ifBlock.thenBlock.replace(ifBlock, ifBlock.thenBlock); ifBlock.thenBlock.replace(ifBlock, ifBlock.thenBlock);
return true; return true;
} }
@ -210,7 +209,7 @@ public class CreateIfThenElseOperator implements Transformation {
(MyType.intersection(e[1].getType(),e[2].getType())); (MyType.intersection(e[1].getType(),e[2].getType()));
((InstructionBlock)flow.lastModified). ((InstructionBlock)flow.lastModified).
setInstruction(new Expression(iteo, e)); setInstruction(new ComplexExpression(iteo, e));
flow.lastModified.replace(flow.lastModified.outer, flow.lastModified); flow.lastModified.replace(flow.lastModified.outer, flow.lastModified);
return true; return true;
} }

@ -20,6 +20,7 @@
package jode.flow; package jode.flow;
import jode.InvokeOperator; import jode.InvokeOperator;
import jode.Expression; import jode.Expression;
import jode.ComplexExpression;
import jode.ConstructorOperator; import jode.ConstructorOperator;
import jode.DupOperator; import jode.DupOperator;
import jode.NewOperator; import jode.NewOperator;
@ -85,9 +86,10 @@ public class CreateNewConstructor implements Transformation{
return false; return false;
} }
((InstructionContainer) flow.lastModified).setInstruction ((InstructionContainer) flow.lastModified).setInstruction
(new Expression(new ConstructorOperator(constrCall.getClassType(), (new ComplexExpression
constrCall.getField()), (new ConstructorOperator(constrCall.getClassType(),
exprs)); constrCall.getField()),
exprs));
flow.lastModified.replace(sequBlock, flow.lastModified); flow.lastModified.replace(sequBlock, flow.lastModified);
return true; return true;

@ -35,11 +35,10 @@ public class CreatePostIncExpression implements Transformation {
Type type; Type type;
try { try {
lastBlock = (InstructionContainer) flow.lastModified; lastBlock = (InstructionContainer) flow.lastModified;
Expression iincExpr = (Expression) lastBlock.getInstruction(); iinc = (IIncOperator) lastBlock.getInstruction();
iinc = (IIncOperator) iincExpr.getOperator(); if (iinc.getOperatorIndex() == iinc.ADD_OP + iinc.OPASSIGN_OP)
if (iinc.getOperator() == iinc.ADD_OP + iinc.OPASSIGN_OP)
op = Operator.INC_OP; op = Operator.INC_OP;
else if (iinc.getOperator() == iinc.NEG_OP + iinc.OPASSIGN_OP) else if (iinc.getOperatorIndex() == iinc.NEG_OP + iinc.OPASSIGN_OP)
op = Operator.DEC_OP; op = Operator.DEC_OP;
else else
return false; return false;
@ -54,9 +53,7 @@ public class CreatePostIncExpression implements Transformation {
return false; return false;
InstructionBlock ib = (InstructionBlock) sequBlock.subBlocks[0]; InstructionBlock ib = (InstructionBlock) sequBlock.subBlocks[0];
Expression loadExpr = (Expression) ib.getInstruction(); LocalLoadOperator load = (LocalLoadOperator)ib.getInstruction();
LocalLoadOperator load =
(LocalLoadOperator)loadExpr.getOperator();
if (!iinc.matches(load)) if (!iinc.matches(load))
return false; return false;
@ -80,26 +77,34 @@ public class CreatePostIncExpression implements Transformation {
SequentialBlock sequBlock; SequentialBlock sequBlock;
try { try {
lastBlock = (InstructionBlock) flow.lastModified; lastBlock = (InstructionBlock) flow.lastModified;
store = (StoreInstruction) lastBlock.getInstruction();
Expression storeExpr = (Expression) lastBlock.getInstruction();
store = (StoreInstruction) storeExpr.getOperator();
sequBlock = (SequentialBlock) lastBlock.outer; sequBlock = (SequentialBlock) lastBlock.outer;
if (sequBlock.subBlocks[1] != lastBlock) if (sequBlock.subBlocks[1] != lastBlock)
return false; return false;
InstructionBlock ib = (InstructionBlock) sequBlock.subBlocks[0]; BinaryOperator binOp;
BinaryOperator binOp = (BinaryOperator) ib.getInstruction(); InstructionBlock ib;
if (binOp.getOperator() == store.ADD_OP) if (store.getLValueOperandCount() > 0) {
ib = (InstructionBlock) sequBlock.subBlocks[0];
binOp = (BinaryOperator) ib.getInstruction();
sequBlock = (SequentialBlock) sequBlock.outer;
} else
binOp = (BinaryOperator)
((ComplexExpression) storeExpr).getSubExpressions()[0];
if (binOp.getOperatorIndex() == store.ADD_OP)
op = Operator.INC_OP; op = Operator.INC_OP;
else if (store.getOperator() == store.NEG_OP) else if (store.getOperatorIndex() == store.NEG_OP)
op = Operator.DEC_OP; op = Operator.DEC_OP;
else else
return false; return false;
sequBlock = (SequentialBlock) sequBlock.outer;
ib = (InstructionBlock) sequBlock.subBlocks[0]; ib = (InstructionBlock) sequBlock.subBlocks[0];
Expression expr = (Expression) ib.getInstruction(); ConstOperator constOp = (ConstOperator) ib.getInstruction();
ConstOperator constOp = (ConstOperator) expr.getOperator();
if (!constOp.getValue().equals("1") && if (!constOp.getValue().equals("1") &&
!constOp.getValue().equals("-1")) !constOp.getValue().equals("-1"))
return false; return false;
@ -117,12 +122,7 @@ public class CreatePostIncExpression implements Transformation {
sequBlock = (SequentialBlock) sequBlock.outer; sequBlock = (SequentialBlock) sequBlock.outer;
ib = (InstructionBlock) sequBlock.subBlocks[0]; ib = (InstructionBlock) sequBlock.subBlocks[0];
Instruction instr = ib.getInstruction(); Operator load = (Operator) ib.getInstruction();
if (instr instanceof Expression
&& ((Expression)instr).getSubExpressions().length == 0)
instr = ((Expression)instr).getOperator();
Operator load = (Operator) instr;
if (!store.matches(load)) if (!store.matches(load))
return false; return false;

@ -30,12 +30,9 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock {
public static final int FOR = 2; public static final int FOR = 2;
public static final Instruction TRUE = public static final Instruction TRUE =
new Expression(new ConstOperator(MyType.tBoolean, "1"), new ConstOperator(MyType.tBoolean, "1");
new Expression[0]);
public static final Instruction FALSE = public static final Instruction FALSE =
new Expression(new ConstOperator(MyType.tBoolean, "0"), new ConstOperator(MyType.tBoolean, "0");
new Expression[0]);
/** /**
* The condition. Must be of boolean type. * The condition. Must be of boolean type.

Loading…
Cancel
Save