001: /*
002: * AthrowCommand.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/itor
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019: package net.sf.jdec.jvminstructions.commands;
020:
021: import net.sf.jdec.blocks.FinallyBlock;
022: import net.sf.jdec.blocks.TryBlock;
023: import net.sf.jdec.core.*;
024: import net.sf.jdec.reflection.Behaviour;
025: import net.sf.jdec.util.Util;
026:
027: import java.util.ArrayList;
028:
029: public class AthrowCommand extends AbstractInstructionCommand {
030:
031: public AthrowCommand(Behaviour context) {
032: super (context);
033:
034: }
035:
036: public int getSkipBytes() {
037: return 0;
038: }
039:
040: public void execute() {
041:
042: boolean add = true;
043: Behaviour behavior = getContext();
044: int currentForIndex = getCurrentInstPosInCode();
045: int i = currentForIndex;
046: boolean aloadPresent = getLoadFinder().isPrevInstructionAload(
047: i, new StringBuffer(""));
048: OperandStack opStack = getContext().getOpStack();
049:
050: // Problem:
051: // Some Defect Here. If Exception thrown as the last stmt in finally in
052: // java code
053: // Then it will not show it...
054: // TODO: Keep Testing This.
055:
056: ArrayList methodTries = getContext().getAllTriesForMethod();
057: if (aloadPresent == true) // Is this enough to make add=false ?
058: {
059: // The following is just to confirm that this is indeed the end of
060: // finally
061: if (methodTries != null) {
062: for (int st = 0; st < methodTries.size(); st++) {
063: TryBlock tryblk = (TryBlock) methodTries.get(st);
064: if (tryblk != null) {
065: FinallyBlock fin = tryblk.getFinallyBlock();
066: if (fin != null) {
067:
068: int finEnd = fin.getEnd();
069: if (finEnd == i) {
070: add = false;
071: break;
072: } else if (finEnd != i) {
073: int finStart = fin.getStart();
074: int fromWhere = i;
075: int tillWhere = finStart;
076: while (fromWhere >= tillWhere) {
077: byte[] info = getContext()
078: .getCode();
079: int inst = info[fromWhere];
080: if (inst == JvmOpCodes.JSR) // TODO : Check
081: // for Jsr_w
082: {
083: add = false;
084: break;
085: }
086: fromWhere--;
087: }
088:
089: } else
090: add = true;
091: }
092: }
093:
094: }
095: }
096: }
097:
098: if (add && DecompilerHelper.addATHROWOutput(currentForIndex)) {
099: Operand op = (Operand) opStack.pop();
100: opStack.push(op);
101: String tempString = "throw " + op.getOperandValue() + ";\n";
102: behavior.appendToBuffer("\n"
103: + Util.formatDecompiledStatement(tempString));
104: GlobalVariableStore.setAthrowseen(true);
105: GlobalVariableStore.setAthrowseenpos(currentForIndex);
106: }
107: }
108:
109: }
|