001: package net.sf.jdec.jvminstructions.commands;
002:
003: import net.sf.jdec.blockhelpers.BranchHelper;
004: import net.sf.jdec.blockhelpers.IFHelper;
005: import net.sf.jdec.blockhelpers.LoopHelper;
006: import net.sf.jdec.blocks.IFBlock;
007: import net.sf.jdec.blocks.Loop;
008: import net.sf.jdec.core.GlobalVariableStore;
009: import net.sf.jdec.core.JvmOpCodes;
010: import net.sf.jdec.core.Operand;
011: import net.sf.jdec.core.OperandStack;
012: import net.sf.jdec.reflection.Behaviour;
013: import net.sf.jdec.util.Util;
014:
015: import java.util.ArrayList;
016: import java.util.Iterator;
017:
018: public class IFACMPNECommand extends AbstractInstructionCommand {
019:
020: public IFACMPNECommand(Behaviour context) {
021: super (context);
022:
023: }
024:
025: public int getSkipBytes() {
026: return 2;
027: }
028:
029: public void execute() {
030: int currentForIndex = getCurrentInstPosInCode();
031: OperandStack opStack = getStack();
032: int i = currentForIndex;
033: Loop this Loop;
034: boolean encounteredAndOrComp = GlobalVariableStore
035: .isEncounteredAndOrComp();
036: boolean isIfInScope = GlobalVariableStore.isIfInScope();
037: Operand op = (Operand) opStack.pop();
038: Operand op1 = (Operand) opStack.pop();
039: byte[] info = getContext().getCode();
040: int classIndex = getGenericFinder().getJumpAddress(i);
041: i++;
042: i++;
043:
044: ArrayList list = getContext().getBehaviourLoops();
045: IFBlock ifst = new IFBlock();
046: ifst.setIfStart(currentForIndex);
047: ifst.setHasIfBeenGenerated(true);
048: getContext().getMethodIfs().add(ifst);
049: Behaviour behavior = getContext();
050:
051: BranchHelper.addBranchLabel(classIndex, i, ifst,
052: currentForIndex, info);
053: boolean addBreak = LoopHelper.checkForParentLoopForIF(ifst);
054: boolean isEndOfLoop = LoopHelper.isIndexEndOfLoop(list, ifst
055: .getIfCloseLineNumber());
056: int loopstart = -1;
057: boolean correctIf = false;
058: String tempString = "";
059: boolean beyondLoop = LoopHelper.isBeyondLoop(ifst
060: .getIfCloseLineNumber(), list, info);
061: this Loop = GlobalVariableStore.getThisLoop();
062: boolean processIF = true;// checkForTernaryIf(ifst, info,
063: // op1.getOperandValue() + "==" +
064: // op.getOperandValue());
065: if (processIF) {
066:
067: if (ifst.getDonotclose() == false
068: && ifst.getIfCloseLineNumber() == -1) {
069: int if_end = IFHelper.checkIFEndIfUnset(ifst, info,
070: currentForIndex);
071: ifst.setIfCloseLineNumber(if_end);
072: }
073: if (isEndOfLoop) {
074: loopstart = LoopHelper.getLoopStartForEnd(ifst
075: .getIfCloseLineNumber(), list);
076: if (currentForIndex > loopstart) {
077: boolean ifinstcodepresent = IFHelper.getIfinst(
078: loopstart, info, currentForIndex);
079: if (ifinstcodepresent) {
080: correctIf = false;
081: } else
082: correctIf = true;
083: }
084: }
085: if ((ifst.getIfCloseLineNumber() > 0 && ifst
086: .getIfCloseLineNumber() < info.length)
087: && info[ifst.getIfCloseLineNumber()] == JvmOpCodes.GOTO
088: && isEndOfLoop && correctIf)
089:
090: {
091: int t = ifst.getIfCloseLineNumber();
092: int gotoIndex = getGenericFinder().getJumpAddress(t);// (info[t+1]
093: // << 8)
094: // |
095: // info[t+2]) +
096: // (ifst.getIfCloseLineNumber());
097: if (gotoIndex < (t + 3)) {
098: boolean isInfiniteLoop = false;
099: Iterator infLoop = getContext().getBehaviourLoops()
100: .iterator();
101: while (infLoop.hasNext()) {
102: Loop iloop = (Loop) infLoop.next();
103: if (iloop.getStartIndex() == gotoIndex
104: && iloop.isInfinite()) {
105: isInfiniteLoop = true;
106: /*
107: * ifLevel++; ifst = new IFBlock();
108: * ifst.setIfStart(currentForIndex);
109: * ifst.setHasIfBeenGenerated(true); //
110: * ifst.setIfCloseLineNumber(classIndex-3);
111: */
112: ifst.setElseCloseLineNumber(gotoIndex);
113: /*
114: * ifHashTable.put(""+(ifLevel),ifst);
115: *
116: * addBranchLabel(classIndex,i,ifst,currentForIndex,info);
117: */
118: boolean bb = LoopHelper.isBeyondLoop(
119: getGenericFinder().getJumpAddress(
120: currentForIndex),
121: getContext().getBehaviourLoops(),
122: info);
123: isIfInScope = true;
124: this Loop = GlobalVariableStore
125: .getThisLoop();
126: boolean print = true;
127: boolean addifbreak = false;
128:
129: if (bb && this Loop != null
130: && this Loop.isInfinite()
131: && !encounteredAndOrComp
132: && addBreak) {
133: Loop dowl = LoopHelper.isIfInADoWhile(
134: currentForIndex, ifst,
135: getContext()
136: .getBehaviourLoops());
137: if (dowl != null) {
138: tempString = "";
139: } else {
140: tempString = "\nif(!"
141: + op1.getOperandValue()
142: + "=="
143: + op.getOperandValue()
144: + ")\n{\nbreak;\n}\n";
145: // odeStatements
146: // +=Util.formatDecompiledStatement(tempString);
147: addifbreak = true;
148: }
149: print = false;
150: }
151: boolean last = IFHelper
152: .lastIFinShortCutChain(info, ifst,
153: currentForIndex);
154: boolean c = IFHelper
155: .addCodeStatementWRTShortcutOR(
156: ifst,
157: op1.getOperandValue()
158: + " != "
159: + op
160: .getOperandValue(),
161: print,
162: "if",
163: last,
164: op1.getOperandValue()
165: + " == "
166: + op
167: .getOperandValue());
168: if (c) {
169: if (addifbreak) {
170: behavior
171: .appendToBuffer(Util
172: .formatDecompiledStatement(tempString));
173: }
174:
175: tempString = "\nif("
176: + op1.getOperandValue() + "=="
177: + op.getOperandValue()
178: + "))\n{\n";
179: behavior
180: .appendToBuffer(Util
181: .formatDecompiledStatement(tempString));
182: } else {
183: boolean firstIfForLoop = LoopHelper
184: .isIfFirstIfInLoopCondition(
185: info, currentForIndex);
186: if (firstIfForLoop) {
187: IFHelper
188: .registerElseBreakForIfChain(currentForIndex);
189: }
190: }
191:
192: break;
193: }
194: }
195: if (isInfiniteLoop) {
196: GlobalVariableStore
197: .setEncounteredAndOrComp(encounteredAndOrComp);
198: GlobalVariableStore.setIfInScope(isIfInScope);
199: GlobalVariableStore.setThisLoop(this Loop);
200:
201: return;
202: }
203: boolean last = IFHelper.lastIFinShortCutChain(info,
204: ifst, currentForIndex);
205: boolean c = IFHelper.addCodeStatementWRTShortcutOR(
206: ifst, op1.getOperandValue() + " != "
207: + op.getOperandValue(), true,
208: "while", last, op1.getOperandValue()
209: + " == " + op.getOperandValue());
210: if (c) {
211: tempString = "\nwhile(" + op1.getOperandValue()
212: + "==" + op.getOperandValue()
213: + "))\n{\n";
214: behavior.appendToBuffer(Util
215: .formatDecompiledStatement(tempString));
216: }
217:
218: }
219: // int x = 0;
220: else {
221:
222: /*
223: * ifLevel++; ifst = new IFBlock();
224: * ifst.setIfStart(currentForIndex);
225: * ifst.setHasIfBeenGenerated(true);
226: * //ifst.setIfCloseLineNumber(classIndex-3);
227: * isIfInScope=true;
228: */
229: ifst.setElseCloseLineNumber(gotoIndex);
230: /*
231: * ifHashTable.put(""+(ifLevel),ifst);
232: * addBranchLabel(classIndex,i,ifst,currentForIndex,info);
233: */
234: boolean bb = LoopHelper.isBeyondLoop(
235: getGenericFinder().getJumpAddress(
236: currentForIndex), getContext()
237: .getBehaviourLoops(), info);
238: isIfInScope = true;
239: this Loop = GlobalVariableStore.getThisLoop();
240: boolean print = true;
241: boolean addifbreak = false;
242: if (bb && this Loop != null && this Loop.isInfinite()
243: && !encounteredAndOrComp && addBreak) {
244: Loop dowl = LoopHelper.isIfInADoWhile(
245: currentForIndex, ifst, getContext()
246: .getBehaviourLoops());
247: if (dowl != null) {
248: tempString = "";
249: } else {
250: tempString = "\nif(!"
251: + op1.getOperandValue() + "=="
252: + op.getOperandValue()
253: + ")\n{\nbreak;\n}\n";
254: // codeStatements
255: // +=Util.formatDecompiledStatement(tempString);
256: addifbreak = true;
257: }
258: print = false;
259: // ifst.setIfHasBeenClosed(true);
260: }
261: boolean last = IFHelper.lastIFinShortCutChain(info,
262: ifst, currentForIndex);
263: boolean c = IFHelper.addCodeStatementWRTShortcutOR(
264: ifst, op1.getOperandValue() + " != "
265: + op.getOperandValue(), print,
266: "if", last, op1.getOperandValue() + " == "
267: + op.getOperandValue());
268: if (c) {
269: if (addifbreak) {
270: behavior
271: .appendToBuffer(Util
272: .formatDecompiledStatement(tempString));
273: }
274:
275: tempString = "\nif(" + op1.getOperandValue()
276: + "==(" + op.getOperandValue()
277: + "))\n{\n";
278: behavior.appendToBuffer(Util
279: .formatDecompiledStatement(tempString));
280: } else {
281: boolean firstIfForLoop = LoopHelper
282: .isIfFirstIfInLoopCondition(info,
283: currentForIndex);
284: if (firstIfForLoop) {
285: IFHelper
286: .registerElseBreakForIfChain(currentForIndex);
287: }
288: }
289:
290: // SerializationTester cc;
291: }
292: } else {
293: /*
294: * ifLevel++; ifst = new IFBlock();
295: * ifst.setIfStart(currentForIndex);
296: * ifst.setHasIfBeenGenerated(true);
297: * ifHashTable.put(""+(ifLevel),ifst); isIfInScope=true;
298: * addBranchLabel(classIndex,i,ifst,currentForIndex,info);
299: */
300: // GradientPaintContext
301: boolean bb = LoopHelper.isBeyondLoop(getGenericFinder()
302: .getJumpAddress(currentForIndex), getContext()
303: .getBehaviourLoops(), info);
304: isIfInScope = true;
305: this Loop = GlobalVariableStore.getThisLoop();
306: boolean print = true;
307: boolean addifbreak = false;
308: if (bb && this Loop != null && this Loop.isInfinite()
309: && !encounteredAndOrComp && addBreak) {
310: Loop dowl = LoopHelper.isIfInADoWhile(
311: currentForIndex, ifst, getContext()
312: .getBehaviourLoops());
313: if (dowl != null) {
314: tempString = "";
315: } else {
316: tempString = "\nif(!" + op1.getOperandValue()
317: + "==" + op.getOperandValue()
318: + ")\n{\nbreak;\n}\n";
319: // codeStatements
320: // +=Util.formatDecompiledStatement(tempString);
321: addifbreak = true;
322: }
323: print = false;
324: // ifst.setIfHasBeenClosed(true);
325: }
326: boolean last = IFHelper.lastIFinShortCutChain(info,
327: ifst, currentForIndex);
328: boolean c = IFHelper.addCodeStatementWRTShortcutOR(
329: ifst, op1.getOperandValue() + " != "
330: + op.getOperandValue(), print, "if",
331: last, op1.getOperandValue() + " == "
332: + op.getOperandValue());
333: if (c) {
334: if (addifbreak) {
335: behavior.appendToBuffer(Util
336: .formatDecompiledStatement(tempString));
337: }
338:
339: tempString = "\nif(" + op1.getOperandValue() + "=="
340: + op.getOperandValue() + "))\n{\n";
341: behavior.appendToBuffer(Util
342: .formatDecompiledStatement(tempString));
343: } else {
344: boolean firstIfForLoop = LoopHelper
345: .isIfFirstIfInLoopCondition(info,
346: currentForIndex);
347: if (firstIfForLoop) {
348: IFHelper
349: .registerElseBreakForIfChain(currentForIndex);
350: }
351: }
352:
353: }
354: }
355: GlobalVariableStore
356: .setEncounteredAndOrComp(encounteredAndOrComp);
357: GlobalVariableStore.setIfInScope(isIfInScope);
358: GlobalVariableStore.setThisLoop(thisLoop);
359:
360: }
361:
362: }
|