1 19 20 package soot.shimple.toolkits.scalar; 21 22 import soot.*; 23 import soot.util.*; 24 import soot.shimple.*; 25 import soot.toolkits.scalar.*; 26 import java.util.*; 27 28 47 public class ShimpleLocalDefs implements LocalDefs 48 { 49 protected Map localToDefs; 50 51 56 public ShimpleLocalDefs(ShimpleBody sb) 57 { 58 if(!sb.isSSA()) 61 throw new RuntimeException ("ShimpleBody is not in proper SSA form as required by ShimpleLocalDefs. You may need to rebuild it or use SimpleLocalDefs instead."); 62 63 { 67 Chain unitsChain = sb.getUnits(); 68 Iterator unitsIt = unitsChain.iterator(); 69 localToDefs = new HashMap(unitsChain.size() * 2 + 1, 0.7f); 70 71 while(unitsIt.hasNext()){ 72 Unit unit = (Unit) unitsIt.next(); 73 Iterator defBoxesIt = unit.getDefBoxes().iterator(); 74 while(defBoxesIt.hasNext()){ 75 Value value = ((ValueBox)defBoxesIt.next()).getValue(); 76 77 if(!(value instanceof Local)) 79 continue; 80 81 localToDefs.put(value, new SingletonList(unit)); 82 } 83 } 84 } 85 } 86 87 94 public List getDefsOf(Local l) 95 { 96 List defs = (List) localToDefs.get(l); 97 98 if(defs == null) 99 throw new RuntimeException ("Local not found in Body."); 100 101 return defs; 102 } 103 104 113 public List getDefsOfAt(Local l, Unit s) 114 { 115 { 120 Iterator boxIt = s.getUseBoxes().iterator(); 121 boolean defined = false; 122 123 while(boxIt.hasNext()){ 124 Value value = ((ValueBox) boxIt.next()).getValue(); 125 if(value.equals(l)){ 126 defined = true; 127 break; 128 } 129 } 130 131 if(!defined) 132 throw new RuntimeException ("Illegal LocalDefs query; local " + l + " is not being used at " + s); 133 } 134 135 return getDefsOf(l); 136 } 137 } 138 | Popular Tags |