01: /*
02: * DupCommand.java Copyright (c) 2006,07 Swaroop Belur
03: *
04: * This program is free software; you can redistribute it and/itor
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08:
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13:
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17: *
18: */
19: package net.sf.jdec.jvminstructions.commands;
20:
21: import net.sf.jdec.core.DecompilerHelper;
22: import net.sf.jdec.core.GlobalVariableStore;
23: import net.sf.jdec.core.JvmOpCodes;
24: import net.sf.jdec.core.Operand;
25: import net.sf.jdec.core.OperandStack;
26: import net.sf.jdec.reflection.Behaviour;
27:
28: public class DupCommand extends AbstractInstructionCommand {
29:
30: public DupCommand(Behaviour context) {
31: super (context);
32:
33: }
34:
35: public int getSkipBytes() {
36: return 0;
37: }
38:
39: public void execute() {
40:
41: byte[] info = getCode();
42: OperandStack opStack = getStack();
43: boolean dupnothandled = GlobalVariableStore.isDupnothandled();
44: int currentForIndex = getCurrentInstPosInCode();
45: if ((getGenericFinder().isThisInstrStart((currentForIndex - 3)) && info[(currentForIndex - 3)] == JvmOpCodes.ANEWARRAY)
46: && newfound()) {
47: dupnothandled = true;
48: } else if (newfound()
49: && (DecompilerHelper.checkForSizeOfArrayTimesStack()
50: || DecompilerHelper.prevNewPresent() || GlobalVariableStore
51: .getTernList().size() > 0)) {
52: dupnothandled = true;
53: }
54: // else if(dupStoreForTerIf){}
55: else {
56: if (!GlobalVariableStore.isEmbeddedANEWARRAY()
57: && !GlobalVariableStore.isEmbeddedNEWARRAY()
58: && (opStack.size() > 0)) {
59: Operand op1 = (Operand) opStack.pop();
60: opStack.push(op1);
61: opStack.push(op1);
62: } else {
63: if (GlobalVariableStore.isEmbeddedANEWARRAY())
64: GlobalVariableStore.setEmbeddedANEWARRAY(false);
65: if (GlobalVariableStore.isEmbeddedNEWARRAY())
66: GlobalVariableStore.setEmbeddedNEWARRAY(false);
67:
68: }
69: dupnothandled = false;
70: // Test This
71: if (GlobalVariableStore.isDoNotPop()) {
72: GlobalVariableStore.setDoNotPop(false);
73: }
74: }
75:
76: GlobalVariableStore.setDupnothandled(dupnothandled);
77:
78: }
79:
80: }
|