1 19 20 25 26 27 28 29 30 package soot.jimple.toolkits.base; 31 32 import soot.*; 33 import soot.jimple.*; 34 import soot.util.*; 35 import java.util.*; 36 37 public class Zonation 38 { 39 private int zoneCount; 40 private Map unitToZone; 41 42 public Zonation(StmtBody body) 43 { 44 Chain units = body.getUnits(); 45 Map unitToTrapBoundaries = new HashMap(); 46 47 { 49 Iterator unitIt = units.iterator(); 50 51 while(unitIt.hasNext()) 52 { 53 Unit u = (Unit) unitIt.next(); 54 55 unitToTrapBoundaries.put(u, new ArrayList()); 56 } 57 } 58 59 { 61 Iterator trapIt = body.getTraps().iterator(); 62 63 while(trapIt.hasNext()) 64 { 65 Trap t = (Trap) trapIt.next(); 66 67 List boundary = (List) unitToTrapBoundaries.get(t.getBeginUnit()); 68 boundary.add(t); 69 70 boundary = (List) unitToTrapBoundaries.get(t.getEndUnit()); 71 boundary.add(t); 72 } 73 } 74 75 { 77 Map trapListToZone = new HashMap(10, 0.7f); 78 List currentTraps = new ArrayList(); 79 Zone currentZone; 80 81 zoneCount = 0; 82 unitToZone = new HashMap(units.size() * 2 + 1, 0.7f); 83 84 currentZone = new Zone("0"); 86 trapListToZone.put(new ArrayList(), currentZone); 87 88 Iterator unitIt = units.iterator(); 89 90 while(unitIt.hasNext()) 91 { 92 Unit u = (Unit) unitIt.next(); 93 94 { 96 List trapBoundaries = (List) unitToTrapBoundaries.get(u); 97 98 if(trapBoundaries.size() != 0) 99 { 100 Iterator trapIt = trapBoundaries.iterator(); 101 102 while(trapIt.hasNext()) 103 { 104 Trap trap = (Trap) trapIt.next(); 105 106 if(currentTraps.contains(trap)) 107 currentTraps.remove(trap); 108 else 109 currentTraps.add(trap); 110 } 111 112 if(trapListToZone.containsKey(currentTraps)) 113 currentZone = (Zone) trapListToZone.get(currentTraps); 114 else 115 { 116 118 zoneCount++; 119 currentZone = new Zone(new Integer (zoneCount).toString()); 120 121 trapListToZone.put(currentTraps, currentZone); 122 } 123 124 } 125 } 126 127 unitToZone.put(u, currentZone); 128 } 129 } 130 131 } 132 133 public Zone getZoneOf(Unit u) 134 { 135 Zone z = (Zone) unitToZone.get(u); 136 137 if(z == null) 138 throw new RuntimeException ("null zone!"); 139 140 return z; 141 } 142 143 public int getZoneCount() 144 { 145 return zoneCount; 146 } 147 } 148 | Popular Tags |