1 19 20 package jode.flow; 21 import jode.expr.ConstOperator; 22 import jode.type.Type; 23 24 30 public class CaseBlock extends StructuredBlock { 31 35 StructuredBlock subBlock; 36 37 40 int value; 41 42 45 boolean isDefault = false; 46 47 50 boolean isFallThrough = false; 51 52 55 boolean isLastBlock = false; 56 57 public CaseBlock(int value) { 58 this.value = value; 59 subBlock = null; 60 } 61 62 public CaseBlock(int value, Jump dest) { 63 this.value = value; 64 subBlock = new EmptyBlock(dest); 65 subBlock.outer = this; 66 } 67 68 public void checkConsistent() { 69 if (!(outer instanceof SwitchBlock)) 70 throw new jode.AssertError("Inconsistency"); 71 super.checkConsistent(); 72 } 73 74 80 public boolean replaceSubBlock(StructuredBlock oldBlock, 81 StructuredBlock newBlock) { 82 if (subBlock == oldBlock) 83 subBlock = newBlock; 84 else 85 return false; 86 return true; 87 } 88 89 94 protected boolean wantBraces() { 95 StructuredBlock block = subBlock; 96 if (block == null) 97 return false; 98 for (;;) { 99 if (block.declare != null && !block.declare.isEmpty()) { 100 101 return true; 102 } 103 104 if (!(block instanceof SequentialBlock)) { 105 108 if (block instanceof InstructionBlock 109 && ((InstructionBlock)block).isDeclaration) 110 return true; 111 112 113 115 return false; 116 } 117 118 StructuredBlock[] subBlocks = block.getSubBlocks(); 119 if (subBlocks[0] instanceof InstructionBlock 120 && ((InstructionBlock)subBlocks[0]).isDeclaration) { 121 124 return true; 125 } 126 127 128 block = subBlocks[1]; 129 } 130 } 131 132 135 public StructuredBlock[] getSubBlocks() { 136 return (subBlock != null) 137 ? new StructuredBlock[] { subBlock } 138 : new StructuredBlock[0]; 139 } 140 141 public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer) 142 throws java.io.IOException 143 { 144 if (isDefault) { 145 150 if (isLastBlock 151 && subBlock instanceof EmptyBlock 152 && subBlock.jump == null) 153 return; 154 if (subBlock instanceof BreakBlock 155 && ((BreakBlock) subBlock).breaksBlock == this) { 156 157 if (isFallThrough) { 158 writer.tab(); 159 subBlock.dumpSource(writer); 160 writer.untab(); 161 } 162 return; 163 } 164 if (isFallThrough) { 165 writer.tab(); 166 writer.println("/* fall through */"); 167 writer.untab(); 168 } 169 writer.print("default:"); 170 } else { 171 if (isFallThrough) { 172 writer.tab(); 173 writer.println("/* fall through */"); 174 writer.untab(); 175 } 176 ConstOperator constOp = new ConstOperator(new Integer (value)); 177 Type type = ((SwitchBlock)outer).getInstruction().getType(); 178 constOp.setType(type); 179 constOp.makeInitializer(type); 180 writer.print("case " + constOp.toString() + ":"); 181 } 182 if (subBlock != null) { 183 boolean needBraces = wantBraces(); 184 if (needBraces) 185 writer.openBrace(); 186 else 187 writer.println(); 188 if (subBlock != null) { 189 writer.tab(); 190 subBlock.dumpSource(writer); 191 writer.untab(); 192 } 193 if (needBraces) 194 writer.closeBrace(); 195 } else 196 writer.println(); 197 } 198 199 204 public boolean jumpMayBeChanged() { 205 return subBlock.jump != null || subBlock.jumpMayBeChanged(); 206 } 207 } 208 | Popular Tags |