KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hansel > stack > ComplexAnd


1 package org.hansel.stack;
2
3
4 public class ComplexAnd {
5     /*private InstructionList il;
6     private InstructionHandle handle;
7     private BranchInstruction bi;
8     private Hashtable stackMap;
9     private SymbolicStack stack;
10     private boolean branchTaken;
11
12     public ComplexAnd(InstructionList il,
13                       BranchInstruction bi,
14                       Hashtable stackMap,
15                       boolean branchTaken) {
16         this.il = il;
17         this.bi = bi;
18         this.stackMap = stackMap;
19         this.handle = findHandle();
20         this.stack = (SymbolicStack) stackMap.get(handle);
21         this.branchTaken = branchTaken;
22     }
23
24     private StackEntry error() {
25         return new StackEntry("<error decompiling and>",
26                               Type.VOID);
27     }
28
29     public StackEntry getStackEntry() {
30         if ((stack == null) || (stack.depth() == 0)) {
31             return error();
32         }
33
34        
35         StackEntry result = translateBranch();
36
37         StackEntry parent = findParent();
38  
39         if (parent != null) {
40             result = new AndAndOp(parent, result);
41         }
42    
43         return result;
44     }
45
46     private InstructionHandle findHandle() {
47         InstructionHandle ih = il.getStart();
48         while (ih != null) {
49             if (ih.getInstruction() == bi) {
50                 return ih;
51             }
52             
53             ih = ih.getNext();
54         }
55
56         return null;
57     }
58
59     private StackEntry findParent() {
60         int depth = stack.depth() - bi.consumeStack(null);
61         
62         InstructionHandle current = handle.getPrev();
63         SymbolicStack currentStack = (SymbolicStack) stackMap.get(current);
64
65         while ((current != null) && (currentStack.depth() > depth)) {
66             current = current.getPrev();
67             currentStack = (SymbolicStack) stackMap.get(current);
68         }
69
70         InstructionHandle expressionStart = current;
71         InstructionHandle previous = null;
72
73         if (current != null) {
74             previous = current.getPrev();
75         }
76
77         if ((previous != null)
78             && (previous.getInstruction() instanceof BranchInstruction)
79             && !(previous.getInstruction() instanceof GotoInstruction)) {
80             return new ComplexOr(expressionStart, stackMap, il).getStackEntry();
81         }
82
83         return null;
84         
85     }
86
87
88     private StackEntry translateBranch() {
89         StackEntry result = null;
90
91         if (bi instanceof IFEQ) {
92             result = stack.getTopEntry();
93         } else if (bi instanceof IFNE) {
94             result = new NotOp(stack.getTopEntry());
95         } else if ((bi instanceof IF_ACMPEQ)
96                    || (bi instanceof IF_ICMPEQ)) {
97             result = new NeOp(stack.get(1), stack.get(0));
98         } else if ((bi instanceof IF_ACMPNE)
99                    || (bi instanceof IF_ICMPNE)) {
100             result = new EqOp(stack.get(1), stack.get(0));
101         } else if (bi instanceof IF_ICMPLE) {
102             result = new GtOp(stack.get(1), stack.get(0));
103         } else if (bi instanceof IF_ICMPLT) {
104             result = new GeOp(stack.get(1), stack.get(0));
105         } else if (bi instanceof IF_ICMPGT) {
106             result = new LeOp(stack.get(1), stack.get(0));
107         } else if (bi instanceof IF_ICMPGE) {
108             result = new LtOp(stack.get(1), stack.get(0));
109         } else if (bi instanceof IFNULL) {
110             result = new EqOp(stack.get(0), new StackEntry("null", Type.NULL));
111         } else if (bi instanceof IFNONNULL) {
112             result = new NeOp(stack.get(0), new StackEntry("null", Type.NULL));
113         } else {
114             throw new UnsupportedOperationException("Instruction: " + bi + " unknown");
115         }
116
117         if (branchTaken) {
118             result = result.invert();
119         }
120
121         return result;
122     }*/

123 }
124
Popular Tags