01: package net.sf.jdec.jvminstructions.commands;
02:
03: import net.sf.jdec.core.GlobalVariableStore;
04: import net.sf.jdec.core.Operand;
05: import net.sf.jdec.core.OperandStack;
06: import net.sf.jdec.util.Util;
07: import net.sf.jdec.reflection.Behaviour;
08:
09: import java.util.Iterator;
10: import java.util.Map;
11: import java.util.HashMap;
12:
13: /*
14: * AReturnCommand.java Copyright (c) 2006,07 Swaroop Belur
15: *
16: * This program is free software; you can redistribute it and/or
17: * modify it under the terms of the GNU General Public License
18: * as published by the Free Software Foundation; either version 2
19: * of the License, or (at your option) any later version.
20:
21: * This program is distributed in the hope that it will be useful,
22: * but WITHOUT ANY WARRANTY; without even the implied warranty of
23: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24: * GNU General Public License for more details.
25:
26: * You should have received a copy of the GNU General Public License
27: * along with this program; if not, write to the Free Software
28: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29: *
30: */
31:
32: /**
33: * @author swaroop belur
34: * @since 1.2.1
35: */
36: public class AReturnCommand extends AbstractInstructionCommand {
37: public AReturnCommand(Behaviour context) {
38: super (context);
39: }
40:
41: public int getSkipBytes() {
42: return 0;
43: }
44:
45: public void execute() {
46: Behaviour behavior = getContext();
47: boolean oktoadd = true;
48: int i = getCurrentInstPosInCode();
49:
50: HashMap returnsAtI = GlobalVariableStore.getReturnsAtI();
51: OperandStack opStack = getContext().getOpStack();
52: Iterator mapIT = returnsAtI.entrySet().iterator();
53: while (mapIT.hasNext()) {
54: Map.Entry entry = (Map.Entry) mapIT.next();
55: Object key = entry.getKey();
56: Object retStatus = entry.getValue().toString();
57: if (key instanceof Integer) {
58: Integer pos = (Integer) key;
59: int temp = pos.intValue();
60: if (temp == i) {
61: if (retStatus.equals("true")) {
62:
63: oktoadd = false;
64: break;
65: }
66: }
67: }
68:
69: }
70:
71: if (!oktoadd) {
72: returnsAtI.remove(new Integer(i));
73: }
74: Object obj = returnsAtI.get(new Integer(i));
75: java.lang.String tempString = "";
76: if (oktoadd && opStack.size() > 0) {
77: //System.out.println(currentForIndex+"i"+behaviour.getBehaviourName());
78: Operand op = (Operand) opStack.pop();
79:
80: if (op.getOperandValue() != null
81: && !op.getOperandValue().toString().trim()
82: .endsWith(";"))
83: tempString = "return " + op.getOperandValue() + ";\n";
84: else
85: tempString = "return " + op.getOperandValue() + "\n";
86: behavior.appendToBuffer(Util
87: .formatDecompiledStatement(tempString));
88:
89: }
90: GlobalVariableStore.setReturnsAtI(returnsAtI);
91:
92: }
93: }
|