001: package net.sf.jdec.jvminstructions.commands;
002:
003: import java.util.ArrayList;
004:
005: import net.sf.jdec.core.DecompilerHelper;
006: import net.sf.jdec.core.GlobalVariableStore;
007: import net.sf.jdec.core.JvmOpCodes;
008: import net.sf.jdec.core.LocalVariable;
009: import net.sf.jdec.core.Operand;
010: import net.sf.jdec.core.OperandStack;
011: import net.sf.jdec.reflection.Behaviour;
012: import net.sf.jdec.util.Util;
013:
014: public class Istore3Command extends AbstractInstructionCommand {
015:
016: public Istore3Command(Behaviour context) {
017: super (context);
018:
019: }
020:
021: public int getSkipBytes() {
022: return 0;
023: }
024:
025: public void execute() {
026: byte[] info = getCode();
027: handleISTORE(getStack(), info, 3, true);
028:
029: }
030:
031: private void handleISTORE(OperandStack stack, byte[] info,
032: int classIndex, boolean b) {
033: Behaviour behavior = getContext();
034: boolean dupnothandled = GlobalVariableStore.isDupnothandled();
035: int currentForIndex = getCurrentInstPosInCode();
036: LocalVariable local = DecompilerHelper.getLocalVariable(
037: classIndex, "store", "int", b, currentForIndex);
038: boolean doNotPop = GlobalVariableStore.isDoNotPop();
039: if (local != null && !doNotPop) {
040: Operand op = null;
041: op = (Operand) stack.pop();
042:
043: if (local.getDataType().equalsIgnoreCase("boolean")) {
044: if (op.getOperandValue().toString().equals("0")) {
045: op.setOperandValue("false");
046: }
047: if (op.getOperandValue().toString().equals("1")) {
048: op.setOperandValue("true");
049: }
050: }
051:
052: boolean push = getGenericFinder().isPrevInstDup(
053: currentForIndex);
054: if (!push) {
055: if (!local.isDeclarationGenerated()) {
056: Object vaf = DecompilerHelper.newVariableAtFront(
057: local.getVarName(), local.getDataType(),
058: "0");
059: GlobalVariableStore.getVariablesatfront().add(vaf);
060: java.lang.String tempString = "#REPLACE_INT_"
061: + classIndex + "#" + local.getVarName()
062: + "=" + "#VALUE" + classIndex + "#"
063: + op.getOperandValue() + ";\n";
064: behavior.appendToBuffer(Util
065: .formatDecompiledStatement(tempString));
066: local.setDeclarationGenerated(true);
067:
068: } else {
069: java.lang.String tempString = local.getVarName()
070: + "=" + op.getOperandValue() + ";\n";
071: behavior.appendToBuffer(Util
072: .formatDecompiledStatement(tempString));// Change
073: // Here
074: // op->k-1
075: // ,top->k
076: }
077: } else {
078: if (getGenericFinder().isThisInstrStart(
079: currentForIndex - 1)
080: && info[currentForIndex - 1] == JvmOpCodes.DUP
081: && !dupnothandled)
082: stack.getTopOfStack();
083: if (getGenericFinder().isThisInstrStart(
084: currentForIndex - 1)
085: && info[currentForIndex - 1] == JvmOpCodes.DUP2
086: && !dupnothandled) {
087: stack.getTopOfStack();
088: stack.getTopOfStack();
089: }
090: if (dupnothandled)
091: dupnothandled = false;
092: if (!DecompilerHelper.isTernaryCondition(
093: currentForIndex, info)) {// BUG
094: // No
095: // Declaration
096: if (!newfound()) {
097: java.lang.String decl = "";
098: if (!local.isDeclarationGenerated()) {
099: Object vaf = DecompilerHelper
100: .newVariableAtFront(local
101: .getVarName(), local
102: .getDataType(), "0");
103: GlobalVariableStore.getVariablesatfront()
104: .add(vaf);
105: decl = "#REPLACE_INT_" + classIndex + "#";// +local.getVarName()+"="+"#VALUE"+classIndex+"#"+op.getOperandValue()+";\n";
106: local.setDeclarationGenerated(true);
107: }
108: behavior
109: .appendToBuffer(Util
110: .formatDecompiledStatement(decl
111: + local.getVarName()
112: + "="
113: + op.getOperandValue()
114: + ";\n"));
115: op = createOperand(local.getVarName());
116: stack.push(op);
117: } else {
118: java.lang.String str = local.getVarName() + "="
119: + op.getOperandValue() + "";
120: op = createOperand(str);
121: stack.push(op);
122: }
123: } else {
124: boolean ternEndfoundForParentIF = false;// isThisTernaryListEndForParentIF(currentForIndex);
125: boolean ternEndfound = false;// isThisTernaryListEnd(currentForIndex);
126:
127: boolean dupStoreForTerIf = false;// isThisDUPSTOREAtEndOFTernaryIF(
128: // currentForIndex,
129: // info, "store");
130: // FIXME : have to add a check here whether or not push op
131: // itself back on stack
132: boolean n = false;// anydupstoreinternarybesidesthis(
133: // currentForIndex, info);
134: if (ternEndfound && n) {
135: stack.push(op);
136: } else {
137: Operand p = stack.getTopOfStack();
138: boolean end = false;// isTernaryEnd(currentForIndex);
139: if (!dupStoreForTerIf) {
140: if (!end)
141: p.setOperandValue(p.getOperandValue()
142: + local.getVarName() + "="
143: + op.getOperandValue());
144: else
145: p.setOperandValue(p.getOperandValue()
146: + local.getVarName() + "="
147: + op.getOperandValue() + ")");
148:
149: }
150: if (dupStoreForTerIf) {
151: if (!end)
152: p.setOperandValue(p.getOperandValue()
153: + op.getOperandValue());
154: else
155: p.setOperandValue(p.getOperandValue()
156: + op.getOperandValue() + ")");
157: }
158: stack.push(p);
159: }
160: /*
161: * } else{ }
162: */
163: if (ternEndfoundForParentIF) {
164: GlobalVariableStore
165: .setTernList(new ArrayList());
166: // adjustBracketCount(opStack);
167: }
168: }
169: }
170: }
171:
172: if (doNotPop == true)
173: doNotPop = false;
174:
175: GlobalVariableStore.setDoNotPop(doNotPop);
176: GlobalVariableStore.setDupnothandled(dupnothandled);
177:
178: }
179:
180: }
|