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