| 1 20 21 26 27 28 package soot.jimple.toolkits.scalar.pre; 29 import soot.*; 30 import soot.toolkits.scalar.*; 31 import soot.toolkits.graph.*; 32 import soot.jimple.toolkits.scalar.*; 33 import soot.jimple.*; 34 import java.util.*; 35 import soot.util.*; 36 37 42 public class UpSafetyAnalysis extends ForwardFlowAnalysis { 43 private SideEffectTester sideEffect; 44 45 private Map unitToGenerateMap; 46 47 private BoundedFlowSet set; 48 49 52 public UpSafetyAnalysis(DirectedGraph dg) { 53 54 super(dg); 55 throw new RuntimeException ("Don't use this Constructor!"); 56 } 57 58 67 public UpSafetyAnalysis(DirectedGraph dg, Map unitToGen, SideEffectTester 68 sideEffect) { 69 this(dg, unitToGen, sideEffect, new 70 ArrayPackedSet(new CollectionFlowUniverse(unitToGen.values()))); 71 } 72 73 85 public UpSafetyAnalysis(DirectedGraph dg, Map unitToGen, SideEffectTester 86 sideEffect, BoundedFlowSet set) { 87 super(dg); 88 this.sideEffect = sideEffect; 89 UnitGraph g = (UnitGraph)dg; 90 this.set = set; 91 unitToGenerateMap = unitToGen; 92 doAnalysis(); 93 } 94 95 protected Object newInitialFlow() { 96 return set.topSet(); 97 } 98 99 protected Object entryInitialFlow() { 100 return set.emptySet(); 101 } 102 103 protected void flowThrough(Object inValue, Object unit, Object outValue) { 104 FlowSet in = (FlowSet) inValue, out = (FlowSet) outValue; 105 106 in.copy(out); 107 108 Value add = (Value)unitToGenerateMap.get(unit); 110 if (add != null) 111 out.add(add, out); 112 113 { 114 Unit u = (Unit)unit; 115 116 Iterator outIt = ((FlowSet)out).iterator(); 117 118 while (outIt.hasNext()) { 120 EquivalentValue equiVal = (EquivalentValue)outIt.next(); 121 Value avail = equiVal.getValue(); 122 if (avail instanceof FieldRef) { 123 if (sideEffect.unitCanWriteTo(u, avail)) 124 outIt.remove(); 125 } else { 126 Iterator usesIt = avail.getUseBoxes().iterator(); 127 128 while (usesIt.hasNext()) { 130 Value use = ((ValueBox)usesIt.next()).getValue(); 131 if (sideEffect.unitCanWriteTo(u, use)) { 132 outIt.remove(); 133 break; 134 } 135 } 136 } 137 } 138 } 139 } 140 141 protected void merge(Object in1, Object in2, Object out) { 142 FlowSet inSet1 = (FlowSet) in1; 143 FlowSet inSet2 = (FlowSet) in2; 144 145 FlowSet outSet = (FlowSet) out; 146 147 inSet1.intersection(inSet2, outSet); 148 } 149 150 protected void copy(Object source, Object dest) { 151 FlowSet sourceSet = (FlowSet) source; 152 FlowSet destSet = (FlowSet) dest; 153 154 sourceSet.copy(destSet); 155 } 156 } 157 158 | Popular Tags |