From f7064ccbaa79ec356c893838d1353b6e367056c7 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 29 Sep 1998 11:28:19 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@42 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/expr/CompareBinaryOperator.java | 2 +- jode/jode/expr/CompareUnaryOperator.java | 2 +- jode/jode/expr/Expression.java | 278 +------------------ jode/jode/expr/Operator.java | 11 +- jode/jode/flow/CombineIfGotoExpressions.java | 4 +- jode/jode/flow/CreateAssignExpression.java | 36 ++- jode/jode/flow/CreateConstantArray.java | 23 +- jode/jode/flow/CreateExpression.java | 52 ++-- jode/jode/flow/CreateIfThenElseOperator.java | 13 +- jode/jode/flow/CreateNewConstructor.java | 8 +- jode/jode/flow/CreatePostIncExpression.java | 44 +-- jode/jode/flow/LoopBlock.java | 7 +- 12 files changed, 107 insertions(+), 373 deletions(-) diff --git a/jode/jode/expr/CompareBinaryOperator.java b/jode/jode/expr/CompareBinaryOperator.java index 94556d9..71928f5 100644 --- a/jode/jode/expr/CompareBinaryOperator.java +++ b/jode/jode/expr/CompareBinaryOperator.java @@ -27,7 +27,7 @@ public class CompareBinaryOperator extends SimpleOperator { } public int getPriority() { - switch (getOperator()) { + switch (getOperatorIndex()) { case 26: case 27: return 500; diff --git a/jode/jode/expr/CompareUnaryOperator.java b/jode/jode/expr/CompareUnaryOperator.java index c2425b2..73181a5 100644 --- a/jode/jode/expr/CompareUnaryOperator.java +++ b/jode/jode/expr/CompareUnaryOperator.java @@ -30,7 +30,7 @@ public class CompareUnaryOperator extends SimpleOperator { } public int getPriority() { - switch (getOperator()) { + switch (getOperatorIndex()) { case 26: case 27: return 500; diff --git a/jode/jode/expr/Expression.java b/jode/jode/expr/Expression.java index fded40d..0031d68 100644 --- a/jode/jode/expr/Expression.java +++ b/jode/jode/expr/Expression.java @@ -19,290 +19,40 @@ package jode; import sun.tools.java.Type; -import sun.tools.java.Constants; -import sun.tools.java.FieldDefinition; -public class Expression extends Instruction { - Operator operator; - Expression[] subExpressions; - Expression parent = null; +public abstract class Expression extends Instruction { - public Expression(Operator op, Expression[] sub) { - super(MyType.tUnknown); - operator = op; - subExpressions = sub; - 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(); + ComplexExpression parent = null; + + public Expression(Type type) { + super (type); } 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 = new UnaryOperator(Type.tBoolean, Operator.LOG_NOT_OP); Expression[] e = { this }; - return new Expression(negop, e); + return new ComplexExpression(negop, 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; } - public Operator getOperator() { - return operator; - } - - 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); - } + Expression simplifyStringBuffer() { + return this; } - public boolean isVoid() { - return operator.getType() == Type.tVoid; - } + public abstract Operator getOperator(); String toString(int minPriority) { - String[] expr = new String[subExpressions.length]; - for (int i=0; i= binop.ASSIGN_OP) + ComplexExpression binopExpr = + (ComplexExpression) ib.getInstruction(); + binop = (BinaryOperator) binopExpr.getOperator(); + if (binop.getOperatorIndex() < binop.ADD_OP || + binop.getOperatorIndex() >= binop.ASSIGN_OP) return false; - sequBlock = (SequentialBlock) sequBlock.outer; - ib = (InstructionBlock) sequBlock.subBlocks[0]; - - rightHandSide = (Expression) ib.getInstruction(); + rightHandSide = binopExpr.getSubExpressions()[1]; if (rightHandSide.isVoid()) return false; /* XXX */ - rhsBlock = (SequentialBlock) sequBlock.outer; - ib = (InstructionBlock) rhsBlock.subBlocks[0]; - - Operator load = (Operator) ib.getInstruction(); + Operator load = (Operator) binopExpr.getSubExpressions()[0]; if (!store.matches(load)) return false; - sequBlock = (SequentialBlock) rhsBlock.outer; + sequBlock = (SequentialBlock) opBlock.outer; ib = (InstructionBlock) sequBlock.subBlocks[0]; DupOperator dup = (DupOperator) ib.getInstruction(); @@ -74,15 +70,15 @@ public class CreateAssignExpression implements Transformation{ } catch (NullPointerException ex) { return false; } - ((InstructionBlock)rhsBlock.subBlocks[0]) + ((InstructionBlock)opBlock.subBlocks[0]) .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.getLValueType())); lastBlock.setInstruction(store); - lastBlock.replace(rhsBlock.subBlocks[1], lastBlock); + lastBlock.replace(opBlock.subBlocks[1], lastBlock); return true; } diff --git a/jode/jode/flow/CreateConstantArray.java b/jode/jode/flow/CreateConstantArray.java index c8a01d2..8dfd989 100644 --- a/jode/jode/flow/CreateConstantArray.java +++ b/jode/jode/flow/CreateConstantArray.java @@ -19,6 +19,7 @@ package jode.flow; import jode.Expression; +import jode.ComplexExpression; import jode.DupOperator; import jode.ArrayStoreOperator; import jode.NewArrayOperator; @@ -69,9 +70,8 @@ public class CreateConstantArray implements Transformation { return false; else { while (index < lastindex) { - consts[lastindex--] = new Expression - (new ConstOperator(MyType.tUnknown, "0"), - new Expression[0]); + consts[lastindex--] = + new ConstOperator(MyType.tUnknown, "0"); } } consts[lastindex--] = lastconst; @@ -88,11 +88,11 @@ public class CreateConstantArray implements Transformation { if (count == 0) return false; while (lastindex >= 0) { - consts[lastindex--] = new Expression - (new ConstOperator(MyType.tUnknown, "0"), - new Expression[0]); + consts[lastindex--] = + new ConstOperator(MyType.tUnknown, "0"); } - Expression newArrayExpr = (Expression) ib.getInstruction(); + ComplexExpression newArrayExpr = + (ComplexExpression) ib.getInstruction(); NewArrayOperator newArrayOp = (NewArrayOperator) newArrayExpr.getOperator(); type = newArrayOp.getType(); @@ -111,9 +111,7 @@ public class CreateConstantArray implements Transformation { Expression[] newConsts = new Expression[arraylength]; System.arraycopy(consts, 0, newConsts, 0, consts.length); for (int i=consts.length; 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) return false; exprs[i] = - (Expression) ((InstructionBlock)block).getInstruction(); + (Expression) block.getInstruction(); if (exprs[i].isVoid()) { if (i == params-1) return false; @@ -90,7 +91,8 @@ public class CreateExpression implements Transformation { setInstruction(e); exprs[i] = e; } - block = sequBlock; + if (i > 0) + sequBlock = (SequentialBlock)sequBlock.outer; } } catch (NullPointerException ex) { return false; @@ -100,27 +102,9 @@ public class CreateExpression implements Transformation { if(jode.Decompiler.isVerbose && params > 0) 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 - (new Expression(op, exprs)); - flow.lastModified.replace(block, 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) { -// } + (new ComplexExpression(op, exprs)); + flow.lastModified.replace(sequBlock, flow.lastModified); return true; } } diff --git a/jode/jode/flow/CreateIfThenElseOperator.java b/jode/jode/flow/CreateIfThenElseOperator.java index 114758f..82a2e41 100644 --- a/jode/jode/flow/CreateIfThenElseOperator.java +++ b/jode/jode/flow/CreateIfThenElseOperator.java @@ -19,6 +19,7 @@ package jode.flow; import jode.Expression; +import jode.ComplexExpression; import jode.IfThenElseOperator; import jode.MyType; import jode.CompareUnaryOperator; @@ -76,9 +77,9 @@ public class CreateIfThenElseOperator implements Transformation { (CompareUnaryOperator) conditional.getInstruction(); FlowBlock trueDestination; - if (compare.getOperator() == compare.EQUALS_OP) + if (compare.getOperatorIndex() == compare.EQUALS_OP) trueDestination = conditional.jump.destination; - else if (compare.getOperator() == compare.NOTEQUALS_OP) + else if (compare.getOperatorIndex() == compare.NOTEQUALS_OP) trueDestination = conditional.trueBlock.jump.destination; else return false; @@ -116,10 +117,8 @@ public class CreateIfThenElseOperator implements Transformation { InstructionBlock pushBlock = (InstructionBlock) sequBlock.subBlocks[1]; - Expression zeroExpr = - (Expression) pushBlock.getInstruction(); jode.ConstOperator zero = - (jode.ConstOperator) zeroExpr.getOperator(); + (jode.ConstOperator) pushBlock.getInstruction(); if (!zero.getValue().equals("0")) return false; @@ -149,7 +148,7 @@ public class CreateIfThenElseOperator implements Transformation { (MyType.intersection(e[1].getType(),e[2].getType())); ((InstructionBlock)ifBlock.thenBlock). - setInstruction(new Expression(iteo, e)); + setInstruction(new ComplexExpression(iteo, e)); ifBlock.thenBlock.replace(ifBlock, ifBlock.thenBlock); return true; } @@ -210,7 +209,7 @@ public class CreateIfThenElseOperator implements Transformation { (MyType.intersection(e[1].getType(),e[2].getType())); ((InstructionBlock)flow.lastModified). - setInstruction(new Expression(iteo, e)); + setInstruction(new ComplexExpression(iteo, e)); flow.lastModified.replace(flow.lastModified.outer, flow.lastModified); return true; } diff --git a/jode/jode/flow/CreateNewConstructor.java b/jode/jode/flow/CreateNewConstructor.java index 784a47b..eef172b 100644 --- a/jode/jode/flow/CreateNewConstructor.java +++ b/jode/jode/flow/CreateNewConstructor.java @@ -20,6 +20,7 @@ package jode.flow; import jode.InvokeOperator; import jode.Expression; +import jode.ComplexExpression; import jode.ConstructorOperator; import jode.DupOperator; import jode.NewOperator; @@ -85,9 +86,10 @@ public class CreateNewConstructor implements Transformation{ return false; } ((InstructionContainer) flow.lastModified).setInstruction - (new Expression(new ConstructorOperator(constrCall.getClassType(), - constrCall.getField()), - exprs)); + (new ComplexExpression + (new ConstructorOperator(constrCall.getClassType(), + constrCall.getField()), + exprs)); flow.lastModified.replace(sequBlock, flow.lastModified); return true; diff --git a/jode/jode/flow/CreatePostIncExpression.java b/jode/jode/flow/CreatePostIncExpression.java index cc5ce6e..ab003ab 100644 --- a/jode/jode/flow/CreatePostIncExpression.java +++ b/jode/jode/flow/CreatePostIncExpression.java @@ -35,11 +35,10 @@ public class CreatePostIncExpression implements Transformation { Type type; try { lastBlock = (InstructionContainer) flow.lastModified; - Expression iincExpr = (Expression) lastBlock.getInstruction(); - iinc = (IIncOperator) iincExpr.getOperator(); - if (iinc.getOperator() == iinc.ADD_OP + iinc.OPASSIGN_OP) + iinc = (IIncOperator) lastBlock.getInstruction(); + if (iinc.getOperatorIndex() == iinc.ADD_OP + iinc.OPASSIGN_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; else return false; @@ -54,9 +53,7 @@ public class CreatePostIncExpression implements Transformation { return false; InstructionBlock ib = (InstructionBlock) sequBlock.subBlocks[0]; - Expression loadExpr = (Expression) ib.getInstruction(); - LocalLoadOperator load = - (LocalLoadOperator)loadExpr.getOperator(); + LocalLoadOperator load = (LocalLoadOperator)ib.getInstruction(); if (!iinc.matches(load)) return false; @@ -80,26 +77,34 @@ public class CreatePostIncExpression implements Transformation { SequentialBlock sequBlock; try { lastBlock = (InstructionBlock) flow.lastModified; - store = (StoreInstruction) lastBlock.getInstruction(); + + Expression storeExpr = (Expression) lastBlock.getInstruction(); + store = (StoreInstruction) storeExpr.getOperator(); sequBlock = (SequentialBlock) lastBlock.outer; if (sequBlock.subBlocks[1] != lastBlock) return false; - InstructionBlock ib = (InstructionBlock) sequBlock.subBlocks[0]; - BinaryOperator binOp = (BinaryOperator) ib.getInstruction(); - if (binOp.getOperator() == store.ADD_OP) + BinaryOperator binOp; + InstructionBlock ib; + 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; - else if (store.getOperator() == store.NEG_OP) + else if (store.getOperatorIndex() == store.NEG_OP) op = Operator.DEC_OP; else return false; - - sequBlock = (SequentialBlock) sequBlock.outer; + ib = (InstructionBlock) sequBlock.subBlocks[0]; - Expression expr = (Expression) ib.getInstruction(); - ConstOperator constOp = (ConstOperator) expr.getOperator(); + ConstOperator constOp = (ConstOperator) ib.getInstruction(); if (!constOp.getValue().equals("1") && !constOp.getValue().equals("-1")) return false; @@ -117,12 +122,7 @@ public class CreatePostIncExpression implements Transformation { sequBlock = (SequentialBlock) sequBlock.outer; ib = (InstructionBlock) sequBlock.subBlocks[0]; - Instruction instr = ib.getInstruction(); - if (instr instanceof Expression - && ((Expression)instr).getSubExpressions().length == 0) - instr = ((Expression)instr).getOperator(); - - Operator load = (Operator) instr; + Operator load = (Operator) ib.getInstruction(); if (!store.matches(load)) return false; diff --git a/jode/jode/flow/LoopBlock.java b/jode/jode/flow/LoopBlock.java index 7527de0..9b96bdf 100644 --- a/jode/jode/flow/LoopBlock.java +++ b/jode/jode/flow/LoopBlock.java @@ -30,12 +30,9 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { public static final int FOR = 2; public static final Instruction TRUE = - new Expression(new ConstOperator(MyType.tBoolean, "1"), - new Expression[0]); - + new ConstOperator(MyType.tBoolean, "1"); public static final Instruction FALSE = - new Expression(new ConstOperator(MyType.tBoolean, "0"), - new Expression[0]); + new ConstOperator(MyType.tBoolean, "0"); /** * The condition. Must be of boolean type.