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