You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.6 KiB
112 lines
3.6 KiB
/* CatchFinallyBlock Copyright (C) 1997-1998 Jochen Hoenicke.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
* any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; see the file COPYING. If not, write to
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*
|
|
* $Id$
|
|
*/
|
|
package jode.flow;
|
|
|
|
/**
|
|
*
|
|
* @author Jochen Hoenicke
|
|
*/
|
|
public class CatchFinallyBlock extends CatchBlock {
|
|
|
|
StructuredBlock finallyBlock;
|
|
|
|
public CatchFinallyBlock() {
|
|
super(null);
|
|
}
|
|
|
|
public void setFinallyBlock(StructuredBlock fin) {
|
|
finallyBlock = fin;
|
|
fin.outer = this;
|
|
fin.setFlowBlock(flowBlock);
|
|
}
|
|
|
|
// /**
|
|
// * Returns the block where the control will normally flow to, when
|
|
// * the given sub block is finished (<em>not</em> ignoring the jump
|
|
// * after this block). FinallyBlock have a special behaviour, since
|
|
// * the try block has the finallyblock as successor and the
|
|
// * finallyblock has no default successor at all!!
|
|
// *
|
|
// * @return null, if the control flows to another FlowBlock.
|
|
// */
|
|
// public StructuredBlock getNextBlock(StructuredBlock subBlock) {
|
|
// return subBlock == tryBlock ? finallyBlock : null;
|
|
// }
|
|
|
|
// public FlowBlock getNextFlowBlock(StructuredBlock subBlock) {
|
|
// return null;
|
|
// }
|
|
|
|
/**
|
|
* Replaces the given sub block with a new block.
|
|
* @param oldBlock the old sub block.
|
|
* @param newBlock the new sub block.
|
|
* @return false, if oldBlock wasn't a direct sub block.
|
|
*/
|
|
public boolean replaceSubBlock(StructuredBlock oldBlock,
|
|
StructuredBlock newBlock) {
|
|
if (tryBlock == oldBlock)
|
|
tryBlock = newBlock;
|
|
else if (finallyBlock == oldBlock)
|
|
finallyBlock = newBlock;
|
|
else
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Returns all sub block of this structured block.
|
|
*/
|
|
public StructuredBlock[] getSubBlocks() {
|
|
return new StructuredBlock[] { tryBlock, finallyBlock };
|
|
}
|
|
|
|
/**
|
|
* Determines if there is a sub block, that flows through to the end
|
|
* of this block. If this returns true, you know that jump is null.
|
|
* @return true, if the jump may be safely changed.
|
|
*/
|
|
public boolean jumpMayBeChanged() {
|
|
return ( tryBlock.jump != null || tryBlock.jumpMayBeChanged())
|
|
&& (finallyBlock.jump != null || finallyBlock.jumpMayBeChanged());
|
|
}
|
|
|
|
public void dumpInstruction(jode.TabbedPrintWriter writer)
|
|
throws java.io.IOException {
|
|
/* avoid ugly nested tries */
|
|
if (!(outer instanceof CatchBlock
|
|
/* XXX || outer instanceof FinallyBlock*/)) {
|
|
writer.println("try {");
|
|
writer.tab();
|
|
}
|
|
tryBlock.dumpSource(writer);
|
|
writer.untab();
|
|
writer.println("} finally {");
|
|
writer.tab();
|
|
finallyBlock.dumpSource(writer);
|
|
if (!(outer instanceof CatchBlock
|
|
/* XXX || outer instanceof FinallyBlock*/)) {
|
|
writer.untab();
|
|
writer.println("}");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|