1 19 20 package soot.toolkits.scalar; 21 22 import java.util.*; 23 import soot.*; 24 import soot.jimple.*; 25 import soot.util.*; 26 import soot.toolkits.graph.*; 27 28 32 public class InitAnalysis extends ForwardFlowAnalysis { 33 FlowSet allLocals; 34 35 public InitAnalysis(UnitGraph g) { 36 super(g); 37 Chain locs=g.getBody().getLocals(); 38 allLocals=new ArraySparseSet(); 39 Iterator it=locs.iterator(); 40 while(it.hasNext()) { 41 Local loc=(Local) it.next(); 42 allLocals.add(loc); 43 } 44 45 doAnalysis(); 46 } 47 48 protected Object entryInitialFlow() { 49 return new ArraySparseSet(); 50 } 51 protected Object newInitialFlow() { 52 FlowSet ret=new ArraySparseSet(); 53 allLocals.copy(ret); 54 return ret; 55 } 56 57 protected void flowThrough(Object in,Object unit,Object out) { 58 FlowSet inSet=(FlowSet) in; 59 FlowSet outSet=(FlowSet) out; 60 Stmt s=(Stmt) unit; 61 62 inSet.copy(outSet); 63 64 if(s instanceof DefinitionStmt) { 65 DefinitionStmt ds=(DefinitionStmt) s; 66 if(ds.getLeftOp() instanceof Local) { 67 Local l=(Local) ds.getLeftOp(); 68 outSet.add(l); 69 } 70 } 71 } 72 73 protected void merge(Object in1,Object in2,Object out) { 74 FlowSet outSet=(FlowSet) out; 75 FlowSet inSet1=(FlowSet) in1; 76 FlowSet inSet2=(FlowSet) in2; 77 inSet1.intersection(inSet2,outSet); 78 } 79 80 protected void copy(Object source,Object dest) { 81 FlowSet sourceSet=(FlowSet) source; 82 FlowSet destSet=(FlowSet) dest; 83 sourceSet.copy(destSet); 84 } 85 86 87 } 88 | Popular Tags |