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 DownSafetyAnalysis extends BackwardFlowAnalysis { 43 private SideEffectTester sideEffect = null; 44 45 private Map unitToGenerateMap; 46 47 private BoundedFlowSet set; 48 49 52 public DownSafetyAnalysis(DirectedGraph dg) { 53 54 super(dg); 55 throw new RuntimeException ("Don't use this Constructor!"); 56 } 57 58 67 public DownSafetyAnalysis(DirectedGraph dg, Map unitToGen, SideEffectTester 68 sideEffect) { 69 this(dg, unitToGen, sideEffect, new 70 ArrayPackedSet(new CollectionFlowUniverse(unitToGen.values()))); 71 } 72 73 85 public DownSafetyAnalysis(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 { 109 Unit u = (Unit)unit; 110 111 Iterator outIt = ((FlowSet)out).iterator(); 112 while (outIt.hasNext()) { 114 EquivalentValue equiVal = (EquivalentValue)outIt.next(); 115 Value avail = equiVal.getValue(); 116 if (avail instanceof FieldRef) { 117 if (sideEffect.unitCanWriteTo(u, avail)) 118 outIt.remove(); 119 } else { 120 Iterator usesIt = avail.getUseBoxes().iterator(); 121 122 while (usesIt.hasNext()) { 124 Value use = ((ValueBox)usesIt.next()).getValue(); 125 if (sideEffect.unitCanWriteTo(u, use)) { 126 outIt.remove(); 127 break; 128 } 129 } 130 } 131 } 132 } 133 134 Value add = (Value)unitToGenerateMap.get(unit); 136 if (add != null) 137 out.add(add, out); 138 } 139 140 protected void merge(Object in1, Object in2, Object out) { 141 FlowSet inSet1 = (FlowSet) in1; 142 FlowSet inSet2 = (FlowSet) in2; 143 144 FlowSet outSet = (FlowSet) out; 145 146 inSet1.intersection(inSet2, outSet); 147 } 148 149 protected void copy(Object source, Object dest) { 150 FlowSet sourceSet = (FlowSet) source; 151 FlowSet destSet = (FlowSet) dest; 152 153 sourceSet.copy(destSet); 154 } 155 } 156 157 | Popular Tags |