used gets now calculated at propagateUsage

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@790 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 25 years ago
parent 97fe374b0f
commit 8ec936c5a9
  1. 14
      jode/jode/flow/CatchBlock.java
  2. 2
      jode/jode/flow/ConditionalBlock.java
  3. 2
      jode/jode/flow/CreateCheckNull.java
  4. 9
      jode/jode/flow/IfThenElseBlock.java
  5. 3
      jode/jode/flow/InstructionBlock.java
  6. 21
      jode/jode/flow/InstructionContainer.java
  7. 8
      jode/jode/flow/RetBlock.java
  8. 2
      jode/jode/flow/ReturnBlock.java
  9. 4
      jode/jode/flow/SequentialBlock.java
  10. 26
      jode/jode/flow/StructuredBlock.java
  11. 13
      jode/jode/flow/SwitchBlock.java
  12. 1
      jode/jode/flow/TransformExceptionHandlers.java
  13. 6
      jode/jode/flow/VariableStack.java

@ -48,8 +48,6 @@ public class CatchBlock extends StructuredBlock {
public CatchBlock(Type type, LocalInfo local) {
exceptionType = type;
exceptionLocal = local;
if (local != null)
used.addElement(exceptionLocal);
}
public Type getExceptionType() {
@ -115,13 +113,19 @@ public class CatchBlock extends StructuredBlock {
}
public void removePush() {
if (pushedLocal != null) {
if (pushedLocal != null)
exceptionLocal = pushedLocal;
used.addElement(pushedLocal);
}
super.removePush();
}
public VariableSet propagateUsage() {
if (used == null)
used = new VariableSet(); /*XXX*/
if (exceptionLocal != null)
used.addElement(exceptionLocal);
return super.propagateUsage();
}
/**
* Print the code for the declaration of a local variable.
* @param writer The tabbed print writer, where we print to.

@ -112,7 +112,7 @@ public class ConditionalBlock extends InstructionContainer {
public void removePush() {
if (stack != null)
instr = stack.mergeIntoExpression(instr, used);
instr = stack.mergeIntoExpression(instr);
trueBlock.removePush();
}

@ -63,7 +63,6 @@ public class CreateCheckNull {
LocalInfo li = new LocalInfo();
ic.setInstruction(new CheckNullOperator(Type.tUObject, li));
ic.used.addElement(li);
last.replace(last.outer);
return true;
}
@ -94,7 +93,6 @@ public class CreateCheckNull {
LocalInfo li = new LocalInfo();
InstructionContainer ic =
new InstructionBlock(new CheckNullOperator(Type.tUObject, li));
ic.used.addElement(li);
ifBlock.flowBlock.removeSuccessor(ifBlock.thenBlock.jump);
ic.moveJump(ifBlock.jump);
if (last == ifBlock) {

@ -125,12 +125,19 @@ public class IfThenElseBlock extends StructuredBlock {
public void removePush() {
if (condStack != null)
cond = condStack.mergeIntoExpression(cond, used);
cond = condStack.mergeIntoExpression(cond);
thenBlock.removePush();
if (elseBlock != null)
elseBlock.removePush();
}
public VariableSet propagateUsage() {
if (used == null)
used = new VariableSet(); /*XXX*/
cond.fillInGenSet(null, used);
return super.propagateUsage();
}
/**
* Print the source code for this structured block. This may be
* called only once, because it remembers which local variables

@ -77,13 +77,12 @@ public class InstructionBlock extends InstructionContainer {
public void removePush() {
if (stack != null)
instr = stack.mergeIntoExpression(instr, used);
instr = stack.mergeIntoExpression(instr);
if (pushedLocal != null) {
Expression store = new StoreInstruction
(new LocalStoreOperator
(pushedLocal.getType(), pushedLocal)).addOperand(instr);
instr = store;
used.addElement(pushedLocal);
}
super.removePush();
}

@ -33,19 +33,16 @@ public abstract class InstructionContainer extends StructuredBlock {
public InstructionContainer(Expression instr) {
this.instr = instr;
if (instr != null)
instr.fillInGenSet(null, used);
}
public InstructionContainer(Expression instr, Jump jump) {
this(instr);
setJump(jump);
}
public void setJump(Jump jump) {
super.setJump(jump);
jump.gen.add(used);
jump.kill.add(used);
if (instr != null) {
VariableSet gen = new VariableSet();
instr.fillInGenSet(null, jump.gen);
instr.fillInGenSet(null, jump.kill);
}
}
/**
@ -72,6 +69,14 @@ public abstract class InstructionContainer extends StructuredBlock {
instr.fillInGenSet(in, gen);
}
public VariableSet propagateUsage() {
if (used == null)
used = new VariableSet(); /*XXX*/
if (instr != null)
instr.fillInGenSet(null, used);
return super.propagateUsage();
}
public boolean doTransformations() {
StructuredBlock last = flowBlock.lastModified;
return CreateNewConstructor.transform(this, last)

@ -35,7 +35,6 @@ public class RetBlock extends StructuredBlock {
public RetBlock(LocalInfo local) {
this.local = local;
used.addElement(local);
}
/**
@ -59,6 +58,13 @@ public class RetBlock extends StructuredBlock {
return null;
}
public VariableSet propagateUsage() {
if (used == null)
used = new VariableSet(); /*XXX*/
used.addElement(local);
return super.propagateUsage();
}
public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
throws java.io.IOException
{

@ -60,7 +60,7 @@ public class ReturnBlock extends InstructionContainer {
public void removePush() {
if (stack != null)
instr = stack.mergeIntoExpression(instr, used);
instr = stack.mergeIntoExpression(instr);
}
/**

@ -168,7 +168,9 @@ public class SequentialBlock extends StructuredBlock {
* block (this is <i>not</i> the used set).
*/
public VariableSet propagateUsage() {
VariableSet allUse = (VariableSet) used.clone();
if (used == null)
used = new VariableSet();/*XXX*/
VariableSet allUse = new VariableSet();
VariableSet childUse0 = subBlocks[0].propagateUsage();
VariableSet childUse1 = subBlocks[1].propagateUsage();
/* All variables used somewhere inside both sub blocks, are

@ -64,9 +64,9 @@ public abstract class StructuredBlock {
/**
* The variable set containing all variables that are used in
* this block.
* this block. You must set this, before calling super.propagateUsage.
*/
VariableSet used = new VariableSet();
VariableSet used;
/**
* The variable set containing all variables we must declare.
@ -210,16 +210,16 @@ public abstract class StructuredBlock {
* will be moved to this block (may be this).
*/
void moveDefinitions(StructuredBlock from, StructuredBlock sub) {
while (from != sub && from != this) {
used.unionExact(from.used);
from.used.removeAllElements();
StructuredBlock[] subs = from.getSubBlocks();
if (subs.length == 0)
return;
for (int i=0; i<subs.length - 1; i++)
moveDefinitions(subs[i], sub);
from = subs[subs.length-1];
}
// while (from != sub && from != this) {
// used.unionExact(from.used);
// from.used.removeAllElements();
// StructuredBlock[] subs = from.getSubBlocks();
// if (subs.length == 0)
// return;
// for (int i=0; i<subs.length - 1; i++)
// moveDefinitions(subs[i], sub);
// from = subs[subs.length-1];
// }
}
/**
@ -349,6 +349,8 @@ public abstract class StructuredBlock {
* block (this is <i>not</i> the used set).
*/
public VariableSet propagateUsage() {
if (used == null)
used = new VariableSet(); /*XXX*/
StructuredBlock[] subs = getSubBlocks();
VariableSet allUse = (VariableSet) used.clone();
for (int i=0; i<subs.length; i++) {

@ -120,7 +120,7 @@ implements BreakableBlock {
public void removePush() {
if (exprStack != null)
instr = exprStack.mergeIntoExpression(instr, used);
instr = exprStack.mergeIntoExpression(instr);
super.removePush();
}
@ -183,6 +183,13 @@ implements BreakableBlock {
return getNextFlowBlock();
}
public VariableSet propagateUsage() {
if (used == null)
used = new VariableSet(); /*XXX*/
instr.fillInGenSet(null, used);
return super.propagateUsage();
}
public void dumpInstruction(TabbedPrintWriter writer)
throws java.io.IOException
{
@ -191,7 +198,9 @@ implements BreakableBlock {
writer.println(label+":");
writer.tab();
}
writer.print("switch ("+instr+")");
writer.print("switch (");
instr.dumpExpression(writer);
writer.print(")");
writer.openBrace();
for (int i=0; i < caseBlocks.length; i++)
caseBlocks[i].dumpSource(writer);

@ -314,7 +314,6 @@ public class TransformExceptionHandlers {
store.getSubExpressions()[1];
ret.setInstruction(expr);
ret.replace(ret.outer);
ret.used.removeElement(local);
}
} catch(ClassCastException ex) {
/* didn't succeed */

@ -98,12 +98,12 @@ public class VariableStack {
return first;
}
public Expression mergeIntoExpression(Expression expr, VariableSet used) {
public Expression mergeIntoExpression(Expression expr) {
/* assert expr.getFreeOperandCount() == stackMap.length */
for (int i = stackMap.length-1; i >= 0; i--) {
if (!used.contains(stackMap[i]))
used.addElement(stackMap[i]);
// if (!used.contains(stackMap[i]))
// used.addElement(stackMap[i]);
expr = expr.addOperand
(new LocalLoadOperator(stackMap[i].getType(), null,
stackMap[i]));

Loading…
Cancel
Save