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