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. 35
      jode/jode/flow/CatchBlock.java

@ -38,7 +38,7 @@ public class CatchBlock extends StructuredBlock {
Type exceptionType; Type exceptionType;
/** /**
* The local containing the exception. * The local containing the exception. May be null.
*/ */
LocalInfo exceptionLocal; LocalInfo exceptionLocal;
@ -48,7 +48,8 @@ public class CatchBlock extends StructuredBlock {
public CatchBlock(Type type, LocalInfo local) { public CatchBlock(Type type, LocalInfo local) {
exceptionType = type; exceptionType = type;
exceptionLocal = local; exceptionLocal = local;
used.addElement(exceptionLocal); if (local != null)
used.addElement(exceptionLocal);
} }
public Type getExceptionType() { public Type getExceptionType() {
@ -94,6 +95,33 @@ public class CatchBlock extends StructuredBlock {
return new StructuredBlock[] { catchBlock }; 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. * Print the code for the declaration of a local variable.
* @param writer The tabbed print writer, where we print to. * @param writer The tabbed print writer, where we print to.
@ -115,7 +143,8 @@ public class CatchBlock extends StructuredBlock {
writer.closeBraceContinue(); writer.closeBraceContinue();
writer.print("catch ("); writer.print("catch (");
writer.printType(exceptionType); writer.printType(exceptionType);
writer.print(" " + exceptionLocal.getName() + ")"); writer.print(" " + (exceptionLocal != null
? exceptionLocal.getName() : "PUSH") + ")");
writer.openBrace(); writer.openBrace();
writer.tab(); writer.tab();
catchBlock.dumpSource(writer); catchBlock.dumpSource(writer);

Loading…
Cancel
Save