diff --git a/jode/jode/flow/CatchBlock.java b/jode/jode/flow/CatchBlock.java index 7f4ebcc..69cbc7b 100644 --- a/jode/jode/flow/CatchBlock.java +++ b/jode/jode/flow/CatchBlock.java @@ -24,6 +24,7 @@ import jode.expr.Expression; import jode.expr.LocalLoadOperator; import jode.expr.LocalStoreOperator; import jode.expr.StoreInstruction; +import jode.util.SimpleSet; /** * @@ -120,10 +121,10 @@ public class CatchBlock extends StructuredBlock { super.removePush(); } - public VariableSet getUsed() { - used = new VariableSet(); + public SimpleSet getDeclarables() { + SimpleSet used = new SimpleSet(); if (exceptionLocal != null) - used.addElement(exceptionLocal); + used.add(exceptionLocal); return used; } @@ -133,7 +134,7 @@ public class CatchBlock extends StructuredBlock { * is marked as used, but not done. * @param done The set of the already declare variables. */ - public void makeDeclaration(VariableSet done) { + public void makeDeclaration(SimpleSet done) { super.makeDeclaration(done); /* Normally we have to declare our exceptionLocal. This * is automatically done in dumpSource. @@ -142,7 +143,7 @@ public class CatchBlock extends StructuredBlock { * this block. In that case we do a transformation. */ if (declare.contains(exceptionLocal)) - declare.removeElement(exceptionLocal); + declare.remove(exceptionLocal); else { LocalInfo dummyLocal = new LocalInfo(); Expression store = new StoreInstruction diff --git a/jode/jode/flow/FlowBlock.java b/jode/jode/flow/FlowBlock.java index 304e856..298ebc4 100644 --- a/jode/jode/flow/FlowBlock.java +++ b/jode/jode/flow/FlowBlock.java @@ -27,6 +27,7 @@ import jode.decompiler.LocalInfo; import jode.expr.Expression; import jode.expr.CombineableOperator; import jode.util.SimpleDictionary; +import jode.util.SimpleSet; /** * A flow block is the structure of which the flow graph consists. A @@ -1489,14 +1490,19 @@ public class FlowBlock { nextByAddr.removeOnetimeLocals(); } - public void makeDeclaration(VariableSet param) { - in.merge(param); - in.subtract(param); + public void mergeParams(LocalInfo[] param) { + VariableSet paramSet = new VariableSet(param); + in.merge(paramSet); + in.subtract(paramSet); + } + + public void makeDeclaration(LocalInfo[] param) { block.propagateUsage(); - Enumeration enum = param.elements(); - while (enum.hasMoreElements()) - ((LocalInfo) enum.nextElement()).guessName(); - block.makeDeclaration(param); + SimpleSet declared = new SimpleSet(); + for (int i=0; i < param.length; i++) { + declared.add(param[i]); + } + block.makeDeclaration(declared); } public void simplify() { diff --git a/jode/jode/flow/IfThenElseBlock.java b/jode/jode/flow/IfThenElseBlock.java index fd26542..0e8c07d 100644 --- a/jode/jode/flow/IfThenElseBlock.java +++ b/jode/jode/flow/IfThenElseBlock.java @@ -22,6 +22,7 @@ import jode.decompiler.LocalInfo; import jode.decompiler.TabbedPrintWriter; import jode.expr.Expression; import jode.type.Type; +import jode.util.SimpleSet; /** * An IfThenElseBlock is the structured block representing an if @@ -131,9 +132,9 @@ public class IfThenElseBlock extends StructuredBlock { elseBlock.removePush(); } - public VariableSet getUsed() { - used = new VariableSet(); - cond.fillInGenSet(null, used); + public SimpleSet getDeclarables() { + SimpleSet used = new SimpleSet(); + cond.fillDeclarables(used); return used; } diff --git a/jode/jode/flow/InstructionBlock.java b/jode/jode/flow/InstructionBlock.java index 0455a5b..60953d2 100644 --- a/jode/jode/flow/InstructionBlock.java +++ b/jode/jode/flow/InstructionBlock.java @@ -24,6 +24,7 @@ import jode.decompiler.LocalInfo; import jode.expr.Expression; import jode.expr.StoreInstruction; import jode.expr.LocalStoreOperator; +import jode.util.SimpleSet; /** * This is the structured block for atomic instructions. @@ -100,7 +101,7 @@ public class InstructionBlock extends InstructionContainer { * variable. In that case mark this as declaration and return the * variable. */ - public void checkDeclaration(VariableSet declareSet) { + public void checkDeclaration(SimpleSet declareSet) { if (instr instanceof StoreInstruction && (((StoreInstruction)instr).getLValue() instanceof LocalStoreOperator)) { @@ -114,7 +115,7 @@ public class InstructionBlock extends InstructionContainer { */ isDeclaration = true; storeOp.getSubExpressions()[1].makeInitializer(); - declareSet.removeElement(local); + declareSet.remove(local); } } } @@ -125,7 +126,7 @@ public class InstructionBlock extends InstructionContainer { * is marked as used, but not done. * @param done The set of the already declare variables. */ - public void makeDeclaration(VariableSet done) { + public void makeDeclaration(SimpleSet done) { super.makeDeclaration(done); checkDeclaration(declare); } @@ -133,16 +134,18 @@ public class InstructionBlock extends InstructionContainer { public void dumpInstruction(TabbedPrintWriter writer) throws java.io.IOException { - if (instr.getType() != Type.tVoid) - writer.print("PUSH "); - else if (isDeclaration) { + if (isDeclaration) { + StoreInstruction store = (StoreInstruction) instr; LocalInfo local = - ((LocalStoreOperator) ((StoreInstruction) instr).getLValue()) - .getLocalInfo(); - writer.printType(local.getType().getHint()); - writer.print(" "); + ((LocalStoreOperator) store.getLValue()).getLocalInfo(); + local.dumpDeclaration(writer); + writer.print(" = "); + store.getSubExpressions()[1].dumpExpression(writer); + } else { + if (instr.getType() != Type.tVoid) + writer.print("PUSH "); + instr.dumpExpression(writer); } - instr.dumpExpression(writer); writer.println(";"); } } diff --git a/jode/jode/flow/InstructionContainer.java b/jode/jode/flow/InstructionContainer.java index be3b1c5..355b5a0 100644 --- a/jode/jode/flow/InstructionContainer.java +++ b/jode/jode/flow/InstructionContainer.java @@ -21,6 +21,7 @@ package jode.flow; import jode.decompiler.LocalInfo; import jode.expr.Expression; import jode.expr.LocalVarOperator; +import jode.util.SimpleSet; /** * This is a method for block containing a single instruction. @@ -69,10 +70,10 @@ public abstract class InstructionContainer extends StructuredBlock { instr.fillInGenSet(in, gen); } - public VariableSet getUsed() { - used = new VariableSet(); + public SimpleSet getDeclarables() { + SimpleSet used = new SimpleSet(); if (instr != null) - instr.fillInGenSet(null, used); + instr.fillDeclarables(used); return used; } diff --git a/jode/jode/flow/LoopBlock.java b/jode/jode/flow/LoopBlock.java index f4b3d09..84910ba 100644 --- a/jode/jode/flow/LoopBlock.java +++ b/jode/jode/flow/LoopBlock.java @@ -26,6 +26,7 @@ import jode.expr.ConstOperator; import jode.expr.StoreInstruction; import jode.expr.LocalStoreOperator; import jode.expr.CombineableOperator; +import jode.util.SimpleSet; /** * This is the structured block for an Loop block. @@ -200,25 +201,25 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { * Remove all variables from set, that we can declare inside the * loop-block. This is the initializer for for-blocks. */ - public void removeLocallyDeclareable(VariableSet set) { + public void removeLocallyDeclareable(SimpleSet set) { if (type == FOR && initInstr instanceof StoreInstruction) { StoreInstruction storeOp = (StoreInstruction) initInstr; if (storeOp.getLValue() instanceof LocalStoreOperator) { LocalInfo local = ((LocalStoreOperator) storeOp.getLValue()).getLocalInfo(); - set.removeElement(local); + set.remove(local); } } } - public VariableSet getUsed() { - used = new VariableSet(); + public SimpleSet getDeclarables() { + SimpleSet used = new SimpleSet(); if (type == FOR) { - incrInstr.fillInGenSet(null, used); + incrInstr.fillDeclarables(used); if (initInstr != null) - initInstr.fillInGenSet(null, used); + initInstr.fillDeclarables(used); } - cond.fillInGenSet(null, used); + cond.fillDeclarables(used); return used; } @@ -249,7 +250,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { * variable. In that case mark this as declaration and return the * variable. */ - public void checkDeclaration(VariableSet declareSet) { + public void checkDeclaration(SimpleSet declareSet) { if (initInstr instanceof StoreInstruction && (((StoreInstruction)initInstr).getLValue() instanceof LocalStoreOperator)) { @@ -263,7 +264,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { */ isDeclaration = true; storeOp.getSubExpressions()[1].makeInitializer(); - declareSet.removeElement(local); + declareSet.remove(local); } } } @@ -274,7 +275,7 @@ public class LoopBlock extends StructuredBlock implements BreakableBlock { * is marked as used, but not done. * @param done The set of the already declare variables. */ - public void makeDeclaration(VariableSet done) { + public void makeDeclaration(SimpleSet done) { super.makeDeclaration(done); if (type == FOR && initInstr != null) checkDeclaration(declare); diff --git a/jode/jode/flow/RetBlock.java b/jode/jode/flow/RetBlock.java index 8bb6ba1..f90e97b 100644 --- a/jode/jode/flow/RetBlock.java +++ b/jode/jode/flow/RetBlock.java @@ -19,6 +19,7 @@ package jode.flow; import jode.decompiler.LocalInfo; +import jode.util.SimpleSet; /** * This block represents a ret instruction. A ret instruction is @@ -58,9 +59,9 @@ public class RetBlock extends StructuredBlock { return null; } - public VariableSet getUsed() { - used = new VariableSet(); - used.addElement(local); + public SimpleSet getDeclarables() { + SimpleSet used = new SimpleSet(); + used.add(local); return used; } diff --git a/jode/jode/flow/SequentialBlock.java b/jode/jode/flow/SequentialBlock.java index 5a9b47d..f898973 100644 --- a/jode/jode/flow/SequentialBlock.java +++ b/jode/jode/flow/SequentialBlock.java @@ -22,6 +22,7 @@ import jode.decompiler.TabbedPrintWriter; import jode.decompiler.LocalInfo; import jode.expr.LocalStoreOperator; import jode.expr.StoreInstruction; +import jode.util.SimpleSet; /** * A sequential block combines exactly two structured blocks to a new @@ -167,22 +168,23 @@ public class SequentialBlock extends StructuredBlock { * @return all locals that are used in this block or in some sub * block (this is not the used set). */ - public VariableSet propagateUsage() { - used = new VariableSet(); - VariableSet allUse = new VariableSet(); - VariableSet childUse0 = subBlocks[0].propagateUsage(); - VariableSet childUse1 = subBlocks[1].propagateUsage(); + public SimpleSet propagateUsage() { + used = getDeclarables(); + SimpleSet allUse = new SimpleSet(); + SimpleSet childUse0 = subBlocks[0].propagateUsage(); + SimpleSet childUse1 = subBlocks[1].propagateUsage(); /* All variables used somewhere inside both sub blocks, are * used in this block, too. * Also the variables used in first block are used in this * block, except when it can be declared locally. (Note that * subBlocks[0].used != childUse0) */ - used.unionExact(subBlocks[0].used); + used.addAll(subBlocks[0].used); if (subBlocks[0] instanceof LoopBlock) ((LoopBlock) subBlocks[0]).removeLocallyDeclareable(used); - used.unionExact(childUse0.intersectExact(childUse1)); - allUse.unionExact(childUse0); - allUse.unionExact(childUse1); + allUse.addAll(childUse0); + allUse.addAll(childUse1); + childUse0.retainAll(childUse1); + used.addAll(childUse0); return allUse; } @@ -192,7 +194,7 @@ public class SequentialBlock extends StructuredBlock { * is marked as used, but not done. * @param done The set of the already declare variables. */ - public void makeDeclaration(VariableSet done) { + public void makeDeclaration(SimpleSet done) { super.makeDeclaration(done); if (subBlocks[0] instanceof InstructionBlock) /* An instruction block may declare a variable for us. diff --git a/jode/jode/flow/StructuredBlock.java b/jode/jode/flow/StructuredBlock.java index 87e582d..b847753 100644 --- a/jode/jode/flow/StructuredBlock.java +++ b/jode/jode/flow/StructuredBlock.java @@ -22,6 +22,10 @@ import jode.AssertError; import jode.GlobalOptions; import jode.decompiler.TabbedPrintWriter; import jode.decompiler.LocalInfo; +import jode.decompiler.Declarable; +import jode.util.SimpleSet; + +import java.util.Enumeration; /** * A structured block is the building block of the source programm. @@ -63,17 +67,17 @@ public abstract class StructuredBlock { */ /** - * The variable set containing all variables that are used in - * this block. You must set this, before calling super.propagateUsage. + * The SimpleSet containing all Declarables that are used in this + * block. */ - VariableSet used; + SimpleSet used; /** - * The variable set containing all variables we must declare. + * The SimpleSet containing all Declarables we must declare. * The analyzation is done in makeDeclaration */ - VariableSet declare; - VariableSet done; + SimpleSet declare; + SimpleSet done; /** * The surrounding structured block. If this is the outermost @@ -339,8 +343,8 @@ public abstract class StructuredBlock { return false; } - public VariableSet getUsed() { - return new VariableSet(); + public SimpleSet getDeclarables() { + return new SimpleSet(); } /** @@ -351,17 +355,21 @@ public abstract class StructuredBlock { * * @return all locals that are used in this block or in some sub * block (this is not the used set). */ - public VariableSet propagateUsage() { - used = getUsed(); + public SimpleSet propagateUsage() { + used = getDeclarables(); StructuredBlock[] subs = getSubBlocks(); - VariableSet allUse = (VariableSet) used.clone(); + SimpleSet allUse = (SimpleSet) used.clone(); for (int i=0; i