1 19 20 package jode.flow; 21 import jode.decompiler.TabbedPrintWriter; 22 import jode.expr.Expression; 23 import jode.expr.LocalVarOperator; 24 25 29 public class ConditionalBlock extends InstructionContainer { 30 33 VariableStack stack; 34 35 EmptyBlock trueBlock; 36 37 public void checkConsistent() { 38 super.checkConsistent(); 39 if (trueBlock.jump == null 40 || !(trueBlock instanceof EmptyBlock)) 41 throw new jode.AssertError("Inconsistency"); 42 } 43 44 47 public ConditionalBlock(Expression cond, Jump condJump, Jump elseJump) { 48 super(cond, elseJump); 49 52 trueBlock = new EmptyBlock(condJump); 53 trueBlock.outer = this; 54 } 55 56 59 public ConditionalBlock(Expression cond) { 60 super(cond); 61 64 trueBlock = new EmptyBlock(); 65 trueBlock.outer = this; 66 } 67 68 71 72 75 public StructuredBlock[] getSubBlocks() { 76 return new StructuredBlock[] { trueBlock }; 77 } 78 79 85 public boolean replaceSubBlock(StructuredBlock oldBlock, 86 StructuredBlock newBlock) { 87 throw new jode.AssertError("replaceSubBlock on ConditionalBlock"); 88 } 89 90 96 public VariableStack mapStackToLocal(VariableStack stack) { 97 VariableStack newStack; 98 int params = instr.getFreeOperandCount(); 99 if (params > 0) { 100 this.stack = stack.peek(params); 101 newStack = stack.pop(params); 102 } else 103 newStack = stack; 104 105 trueBlock.jump.stackMap = newStack; 106 if (jump != null) { 107 jump.stackMap = newStack; 108 return null; 109 } 110 return newStack; 111 } 112 113 public void removePush() { 114 if (stack != null) 115 instr = stack.mergeIntoExpression(instr); 116 trueBlock.removePush(); 117 } 118 119 122 public void dumpInstruction(TabbedPrintWriter writer) 123 throws java.io.IOException 124 { 125 writer.print("IF ("); 126 instr.dumpExpression(writer.EXPL_PAREN, writer); 127 writer.println(")"); 128 writer.tab(); 129 trueBlock.dumpSource(writer); 130 writer.untab(); 131 } 132 133 public boolean doTransformations() { 134 StructuredBlock last = flowBlock.lastModified; 135 return super.doTransformations() 136 || CombineIfGotoExpressions.transform(this, last) 137 || CreateIfThenElseOperator.createFunny(this, last); 138 } 139 } 140 141 | Popular Tags |