1 19 20 package jode.flow; 21 import jode.type.Type; 22 import jode.decompiler.TabbedPrintWriter; 23 import jode.decompiler.LocalInfo; 24 import jode.expr.Expression; 25 import jode.expr.StoreInstruction; 26 import jode.expr.LocalStoreOperator; 27 import jode.util.SimpleSet; 28 29 import java.util.Set ; 30 31 34 public class InstructionBlock extends InstructionContainer { 35 38 VariableStack stack; 39 42 LocalInfo pushedLocal = null; 43 44 48 boolean isDeclaration = false; 49 50 public InstructionBlock(Expression instr) { 51 super(instr); 52 } 53 54 public InstructionBlock(Expression instr, Jump jump) { 55 super(instr, jump); 56 } 57 58 64 public VariableStack mapStackToLocal(VariableStack stack) { 65 VariableStack newStack; 66 int params = instr.getFreeOperandCount(); 67 if (params > 0) 68 this.stack = stack.peek(params); 69 70 if (instr.getType() != Type.tVoid) { 71 pushedLocal = new LocalInfo(); 72 pushedLocal.setType(instr.getType()); 73 newStack = stack.poppush(params, pushedLocal); 74 } else if (params > 0) { 75 newStack = stack.pop(params); 76 } else 77 newStack = stack; 78 return super.mapStackToLocal(newStack); 79 } 80 81 public void removePush() { 82 if (stack != null) 83 instr = stack.mergeIntoExpression(instr); 84 if (pushedLocal != null) { 85 Expression store = new StoreInstruction 86 (new LocalStoreOperator 87 (pushedLocal.getType(), pushedLocal)).addOperand(instr); 88 instr = store; 89 } 90 super.removePush(); 91 } 92 93 97 public boolean needsBraces() { 98 return isDeclaration || (declare != null && !declare.isEmpty()); 99 } 100 101 106 public void checkDeclaration(Set declareSet) { 107 if (instr instanceof StoreInstruction 108 && (((StoreInstruction)instr).getLValue() 109 instanceof LocalStoreOperator)) { 110 StoreInstruction storeOp = (StoreInstruction) instr; 111 LocalInfo local = 112 ((LocalStoreOperator) storeOp.getLValue()).getLocalInfo(); 113 if (declareSet.contains(local)) { 114 118 isDeclaration = true; 119 declareSet.remove(local); 120 } 121 } 122 } 123 124 130 public void makeDeclaration(Set done) { 131 super.makeDeclaration(done); 132 checkDeclaration(declare); 133 } 134 135 public void dumpInstruction(TabbedPrintWriter writer) 136 throws java.io.IOException 137 { 138 if (isDeclaration) { 139 StoreInstruction store = (StoreInstruction) instr; 140 LocalInfo local = 141 ((LocalStoreOperator) store.getLValue()).getLocalInfo(); 142 writer.startOp(writer.NO_PAREN, 0); 143 local.dumpDeclaration(writer); 144 writer.breakOp(); 145 writer.print(" = "); 146 store.getSubExpressions()[1].makeInitializer(local.getType()); 147 store.getSubExpressions()[1].dumpExpression(writer.IMPL_PAREN, 148 writer); 149 writer.endOp(); 150 } else { 151 try { 152 153 if (instr.getType() != Type.tVoid) { 154 writer.print("PUSH "); 155 instr.dumpExpression(writer.IMPL_PAREN, writer); 156 } else 157 instr.dumpExpression(writer.NO_PAREN, writer); 158 } catch (RuntimeException ex) { 159 writer.print("(RUNTIME ERROR IN EXPRESSION)"); 160 } 161 } 162 writer.println(";"); 163 } 164 } 165 | Popular Tags |