1 19 20 25 26 package soot.baf.internal; 27 import soot.jimple.Constant; 28 import soot.util.*; 29 import java.util.*; 30 import soot.*; 31 import soot.baf.*; 32 33 public class BLookupSwitchInst extends AbstractInst implements LookupSwitchInst 34 { 35 UnitBox defaultTargetBox; 36 List lookupValues; 37 UnitBox[] targetBoxes; 38 List unitBoxes; 39 40 public BLookupSwitchInst(Unit defaultTarget, 41 List lookupValues, List targets) 42 { 43 this.defaultTargetBox = Baf.v().newInstBox(defaultTarget); 44 45 this.targetBoxes = new UnitBox[targets.size()]; 46 47 for(int i = 0; i < targetBoxes.length; i++) 48 this.targetBoxes[i] = Baf.v().newInstBox((Unit) targets.get(i)); 49 50 this.lookupValues = new ArrayList(); 51 this.lookupValues.addAll(lookupValues); 52 53 { 55 unitBoxes = new ArrayList(); 56 57 for(int i = 0; i < targetBoxes.length; i++) 58 unitBoxes.add(targetBoxes[i]); 59 60 unitBoxes.add(defaultTargetBox); 61 unitBoxes = Collections.unmodifiableList(unitBoxes); 62 } 63 } 64 65 public Object clone() 66 { 67 List list = new ArrayList(); 68 for(int i =0; i< targetBoxes.length; i++) { 69 70 list.add(targetBoxes[i].getUnit()); 71 } 72 73 74 return new BLookupSwitchInst(defaultTargetBox.getUnit(), lookupValues, list); 75 } 76 77 78 public int getInCount() 79 { 80 return 1; 81 } 82 83 public int getInMachineCount() 84 { 85 return 1; 86 } 87 88 public int getOutCount() 89 { 90 return 0; 91 } 92 93 public int getOutMachineCount() 94 { 95 return 0; 96 } 97 98 public Unit getDefaultTarget() 99 { 100 return defaultTargetBox.getUnit(); 101 } 102 103 public void setDefaultTarget(Unit defaultTarget) 104 { 105 defaultTargetBox.setUnit(defaultTarget); 106 } 107 108 public UnitBox getDefaultTargetBox() 109 { 110 return defaultTargetBox; 111 } 112 113 public void setLookupValues(List lookupValues) 114 { 115 this.lookupValues = new ArrayList(); 116 this.lookupValues.addAll(lookupValues); 117 } 118 119 public void setLookupValue(int index, int value) 120 { 121 this.lookupValues.set(index, new Integer (value)); 122 } 123 124 public int getLookupValue(int index) 125 { 126 return ((Integer ) lookupValues.get(index)).intValue(); 127 } 128 129 public List getLookupValues() 130 { 131 return Collections.unmodifiableList(lookupValues); 132 } 133 134 public int getTargetCount() { return targetBoxes.length; } 135 136 public Unit getTarget(int index) 137 { 138 return targetBoxes[index].getUnit(); 139 } 140 141 public void setTarget(int index, Unit target) 142 { 143 targetBoxes[index].setUnit(target); 144 } 145 146 public void setTargets(List targets) 147 { 148 for(int i = 0; i < targets.size(); i++) 149 targetBoxes[i].setUnit((Unit) targets.get(i)); 150 } 151 152 public UnitBox getTargetBox(int index) 153 { 154 return targetBoxes[index]; 155 } 156 157 public List getTargets() 158 { 159 List targets = new ArrayList(); 160 161 for(int i = 0; i < targetBoxes.length; i++) 162 targets.add(targetBoxes[i].getUnit()); 163 164 return targets; 165 } 166 167 public String getName() { return "lookupswitch"; } 168 169 public String toString() 170 { 171 StringBuffer buffer = new StringBuffer (); 172 String endOfLine = " "; 173 174 buffer.append("lookupswitch" + endOfLine); 175 176 buffer.append("{" + endOfLine); 177 178 for(int i = 0; i < lookupValues.size(); i++) 179 { 180 buffer.append(" case " + lookupValues.get(i) + ": goto " + 181 getTarget(i) + ";" + endOfLine); 182 } 183 184 buffer.append(" default: goto " + getDefaultTarget() + ";" + endOfLine); 185 buffer.append("}"); 186 187 return buffer.toString(); 188 } 189 190 public void toString(UnitPrinter up) { 191 up.literal( "lookupswitch" ); 192 up.newline(); 193 up.literal("{"); 194 up.newline(); 195 196 for(int i = 0; i < lookupValues.size(); i++) 197 { 198 up.literal(" case "); 199 up.constant( (Constant) lookupValues.get(i) ); 200 up.literal(": goto "); 201 targetBoxes[i].toString(up); 202 up.literal(";"); 203 up.newline(); 204 } 205 206 up.literal(" default: goto "); 207 defaultTargetBox.toString(up); 208 up.literal(";"); 209 up.newline(); 210 up.literal("}"); 211 } 212 213 public List getUnitBoxes() 214 { 215 return unitBoxes; 216 } 217 218 public void apply(Switch sw) 219 { 220 ((InstSwitch) sw).caseLookupSwitchInst(this); 221 } 222 223 public boolean fallsThrough() 224 { 225 return false; 226 } 227 public boolean branches() 228 { 229 return true; 230 } 231 232 233 } 234 | Popular Tags |