handle cases, where exceptionLocal is unknown

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@766 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 82af4162ab
commit 8c0bf3909a
  1. 33
      jode/jode/flow/CatchBlock.java

@ -38,7 +38,7 @@ public class CatchBlock extends StructuredBlock {
Type exceptionType;
/**
* The local containing the exception.
* The local containing the exception. May be null.
*/
LocalInfo exceptionLocal;
@ -48,6 +48,7 @@ public class CatchBlock extends StructuredBlock {
public CatchBlock(Type type, LocalInfo local) {
exceptionType = type;
exceptionLocal = local;
if (local != null)
used.addElement(exceptionLocal);
}
@ -94,6 +95,33 @@ public class CatchBlock extends StructuredBlock {
return new StructuredBlock[] { catchBlock };
}
LocalInfo pushedLocal;
/**
* A catch block pushes the exception on the stack, iff a local
* doesn't exists.
* @param stack the stack before the instruction is called
* @return stack the stack afterwards.
*/
public VariableStack mapStackToLocal(VariableStack stack) {
VariableStack newStack;
if (exceptionLocal == null) {
pushedLocal = new LocalInfo();
pushedLocal.setType(exceptionType);
newStack = stack.push(pushedLocal);
} else
newStack = stack;
return super.mapStackToLocal(newStack);
}
public void removePush() {
if (pushedLocal != null) {
exceptionLocal = pushedLocal;
used.addElement(pushedLocal);
}
super.removePush();
}
/**
* Print the code for the declaration of a local variable.
* @param writer The tabbed print writer, where we print to.
@ -115,7 +143,8 @@ public class CatchBlock extends StructuredBlock {
writer.closeBraceContinue();
writer.print("catch (");
writer.printType(exceptionType);
writer.print(" " + exceptionLocal.getName() + ")");
writer.print(" " + (exceptionLocal != null
? exceptionLocal.getName() : "PUSH") + ")");
writer.openBrace();
writer.tab();
catchBlock.dumpSource(writer);

Loading…
Cancel
Save