001: package org.hansel.stack;
002:
003: public class ComplexAnd {
004: /*private InstructionList il;
005: private InstructionHandle handle;
006: private BranchInstruction bi;
007: private Hashtable stackMap;
008: private SymbolicStack stack;
009: private boolean branchTaken;
010:
011: public ComplexAnd(InstructionList il,
012: BranchInstruction bi,
013: Hashtable stackMap,
014: boolean branchTaken) {
015: this.il = il;
016: this.bi = bi;
017: this.stackMap = stackMap;
018: this.handle = findHandle();
019: this.stack = (SymbolicStack) stackMap.get(handle);
020: this.branchTaken = branchTaken;
021: }
022:
023: private StackEntry error() {
024: return new StackEntry("<error decompiling and>",
025: Type.VOID);
026: }
027:
028: public StackEntry getStackEntry() {
029: if ((stack == null) || (stack.depth() == 0)) {
030: return error();
031: }
032:
033:
034: StackEntry result = translateBranch();
035:
036: StackEntry parent = findParent();
037:
038: if (parent != null) {
039: result = new AndAndOp(parent, result);
040: }
041:
042: return result;
043: }
044:
045: private InstructionHandle findHandle() {
046: InstructionHandle ih = il.getStart();
047: while (ih != null) {
048: if (ih.getInstruction() == bi) {
049: return ih;
050: }
051:
052: ih = ih.getNext();
053: }
054:
055: return null;
056: }
057:
058: private StackEntry findParent() {
059: int depth = stack.depth() - bi.consumeStack(null);
060:
061: InstructionHandle current = handle.getPrev();
062: SymbolicStack currentStack = (SymbolicStack) stackMap.get(current);
063:
064: while ((current != null) && (currentStack.depth() > depth)) {
065: current = current.getPrev();
066: currentStack = (SymbolicStack) stackMap.get(current);
067: }
068:
069: InstructionHandle expressionStart = current;
070: InstructionHandle previous = null;
071:
072: if (current != null) {
073: previous = current.getPrev();
074: }
075:
076: if ((previous != null)
077: && (previous.getInstruction() instanceof BranchInstruction)
078: && !(previous.getInstruction() instanceof GotoInstruction)) {
079: return new ComplexOr(expressionStart, stackMap, il).getStackEntry();
080: }
081:
082: return null;
083:
084: }
085:
086:
087: private StackEntry translateBranch() {
088: StackEntry result = null;
089:
090: if (bi instanceof IFEQ) {
091: result = stack.getTopEntry();
092: } else if (bi instanceof IFNE) {
093: result = new NotOp(stack.getTopEntry());
094: } else if ((bi instanceof IF_ACMPEQ)
095: || (bi instanceof IF_ICMPEQ)) {
096: result = new NeOp(stack.get(1), stack.get(0));
097: } else if ((bi instanceof IF_ACMPNE)
098: || (bi instanceof IF_ICMPNE)) {
099: result = new EqOp(stack.get(1), stack.get(0));
100: } else if (bi instanceof IF_ICMPLE) {
101: result = new GtOp(stack.get(1), stack.get(0));
102: } else if (bi instanceof IF_ICMPLT) {
103: result = new GeOp(stack.get(1), stack.get(0));
104: } else if (bi instanceof IF_ICMPGT) {
105: result = new LeOp(stack.get(1), stack.get(0));
106: } else if (bi instanceof IF_ICMPGE) {
107: result = new LtOp(stack.get(1), stack.get(0));
108: } else if (bi instanceof IFNULL) {
109: result = new EqOp(stack.get(0), new StackEntry("null", Type.NULL));
110: } else if (bi instanceof IFNONNULL) {
111: result = new NeOp(stack.get(0), new StackEntry("null", Type.NULL));
112: } else {
113: throw new UnsupportedOperationException("Instruction: " + bi + " unknown");
114: }
115:
116: if (branchTaken) {
117: result = result.invert();
118: }
119:
120: return result;
121: }*/
122: }
|