001: /*
002: * DstoreCommand.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 java.util.ArrayList;
022:
023: import net.sf.jdec.core.DecompilerHelper;
024: import net.sf.jdec.core.GlobalVariableStore;
025: import net.sf.jdec.core.JvmOpCodes;
026: import net.sf.jdec.core.LocalVariable;
027: import net.sf.jdec.core.Operand;
028: import net.sf.jdec.core.OperandStack;
029: import net.sf.jdec.reflection.Behaviour;
030: import net.sf.jdec.util.Util;
031:
032: public class DstoreCommand extends AbstractInstructionCommand {
033:
034: public DstoreCommand(Behaviour context) {
035: super (context);
036:
037: }
038:
039: public int getSkipBytes() {
040: return 1;
041: }
042:
043: public void execute() {
044: int currentForIndex = getCurrentInstPosInCode();
045: OperandStack opStack = getStack();
046: byte[] info = getCode();
047: int classIndex = info[(currentForIndex + 1)];
048: Behaviour behaviour = getContext();
049: LocalVariable local = DecompilerHelper.getLocalVariable(
050: classIndex, "store", "double", false, currentForIndex);
051:
052: boolean doNotPop = GlobalVariableStore.isDoNotPop();
053: boolean dupnothandled = GlobalVariableStore.isDupnothandled();
054: java.lang.String tempString = "";
055: if (local != null && !doNotPop) {
056: Operand op = (Operand) opStack.pop();
057: boolean push = getGenericFinder().isPrevInstDup(
058: currentForIndex);
059: if (!push) {
060: if (!local.isDeclarationGenerated()) {
061: Object vaf = DecompilerHelper.newVariableAtFront(
062: local.getVarName(), local.getDataType(),
063: "0d");
064: GlobalVariableStore.getVariablesatfront().add(vaf);
065: tempString = local.getVarName() + "="
066: + op.getOperandValue() + ";\n";
067: behaviour.appendToBuffer(Util
068: .formatDecompiledStatement(tempString));
069: local.setDeclarationGenerated(true);
070: } else {
071: tempString = local.getVarName() + "="
072: + op.getOperandValue() + ";\n";
073: behaviour.appendToBuffer(Util
074: .formatDecompiledStatement(tempString));
075: }
076: } else {
077: if (((currentForIndex - 1) >= 0)
078: && info[currentForIndex - 1] == JvmOpCodes.DUP
079: && !dupnothandled)
080: opStack.getTopOfStack();
081: if (((currentForIndex - 1) >= 0)
082: && info[currentForIndex - 1] == JvmOpCodes.DUP2
083: && !dupnothandled) {
084: opStack.getTopOfStack();
085: opStack.getTopOfStack();
086: }
087: if (dupnothandled)
088: dupnothandled = false;
089: if (!DecompilerHelper.isTernaryCondition(
090: currentForIndex, info)) {
091: if (!newfound()) {
092: java.lang.String decl = "";
093: if (!local.isDeclarationGenerated()) {
094: Object vaf = DecompilerHelper
095: .newVariableAtFront(local
096: .getVarName(), local
097: .getDataType(), "0d");
098: GlobalVariableStore.getVariablesatfront()
099: .add(vaf);
100: // decl=local.getDataType()+"\t";//+local.getVarName()+"="+"#VALUE"+classIndex+"#"+op.getOperandValue()+";\n";
101: local.setDeclarationGenerated(true);
102: }
103: behaviour
104: .appendToBuffer(Util
105: .formatDecompiledStatement(decl
106: + local.getVarName()
107: + "="
108: + op.getOperandValue()
109: + ";\n"));
110: Operand op2 = createOperand(local.getVarName());
111: opStack.push(op2);
112: } else {
113: Operand op2 = createOperand(local.getVarName()
114: + "=" + op.getOperandValue());
115: opStack.push(op2);
116: }
117: } else {
118: boolean ternEndfoundForParentIF = false;// isThisTernaryListEndForParentIF(currentForIndex);
119: boolean ternEndfound = false;// isThisTernaryListEnd(currentForIndex);
120:
121: boolean dupStoreForTerIf = false;// isThisDUPSTOREAtEndOFTernaryIF(
122: // currentForIndex,
123: // info, "store");
124: boolean n = false;// anydupstoreinternarybesidesthis(
125: // currentForIndex, info);
126: if (ternEndfound && n) {
127: opStack.push(op);
128: } else {
129: Operand p = opStack.getTopOfStack();
130: boolean end = false;// isTernaryEnd(currentForIndex);
131: if (dupStoreForTerIf) {
132: if (!end)
133: p.setOperandValue(p.getOperandValue()
134: + local.getVarName() + "="
135: + op.getOperandValue());
136: else
137: p.setOperandValue(p.getOperandValue()
138: + local.getVarName() + "="
139: + op.getOperandValue() + ")");
140: }
141: if (!dupStoreForTerIf) {
142: if (!end)
143: p.setOperandValue(p.getOperandValue()
144: + op.getOperandValue());
145: else
146: p.setOperandValue(p.getOperandValue()
147: + op.getOperandValue() + ")");
148: }
149: opStack.push(p);
150: }
151: if (ternEndfoundForParentIF)
152: GlobalVariableStore
153: .setTernList(new ArrayList());
154: }
155: }
156: }
157:
158: if (doNotPop == true)
159: doNotPop = false;
160:
161: GlobalVariableStore.setDoNotPop(doNotPop);
162: GlobalVariableStore.setDupnothandled(dupnothandled);
163:
164: }
165:
166: }
|