1 19 20 48 49 50 package soot.jimple.toolkits.annotation.nullcheck; 51 52 import soot.*; 53 import soot.toolkits.graph.*; 54 import soot.toolkits.scalar.*; 55 import java.util.*; 56 57 public class LocalRefVarsAnalysisWrapper 58 { 59 private static final boolean computeChecks = true; 61 private static final boolean discardKTop = true; 62 63 Map unitToVarsBefore; 64 Map unitToVarsAfterFall; 65 Map unitToListsOfVarsAfterBranches; 66 Map unitToVarsNeedCheck; 67 Map unitToVarsDontNeedCheck; 68 69 BranchedRefVarsAnalysis analysis; 70 71 private final List buildList(FlowSet set) 74 { 75 List lst = new ArrayList(); 76 Iterator it = analysis.refTypeValues.iterator(); 77 while (it.hasNext()) { 78 EquivalentValue r = (EquivalentValue) it.next(); 79 int refInfo = analysis.refInfo(r, set); 80 if (!(discardKTop && (refInfo == analysis.kTop))) 81 lst.add(analysis.getKRefIntPair(r, refInfo)); 82 } 84 return lst; 85 } 87 88 public LocalRefVarsAnalysisWrapper(ExceptionalUnitGraph graph) 90 { 91 analysis = new BranchedRefVarsAnalysis(graph); 92 93 unitToVarsBefore = new HashMap(graph.size() * 2 + 1, 0.7f); 94 unitToVarsAfterFall = new HashMap(graph.size() * 2 + 1, 0.7f); 95 unitToListsOfVarsAfterBranches = new HashMap(graph.size() * 2 + 1, 0.7f); 96 unitToVarsNeedCheck = new HashMap(graph.size() * 2 + 1, 0.7f); 97 unitToVarsDontNeedCheck = new HashMap(graph.size() * 2 + 1, 0.7f); 98 99 Iterator unitIt = graph.iterator(); 100 101 while(unitIt.hasNext()) { 102 103 FlowSet set; 104 Unit s = (Unit) unitIt.next(); 105 106 set = (FlowSet) analysis.getFallFlowAfter(s); 107 unitToVarsAfterFall.put(s, Collections.unmodifiableList(buildList(set))); 108 109 { 111 List branchesFlowsets = analysis.getBranchFlowAfter(s); 112 List lst = new ArrayList(branchesFlowsets.size()); 113 114 Iterator it = branchesFlowsets.iterator(); 115 while (it.hasNext()) { 116 set = (FlowSet) it.next(); 117 lst.add(Collections.unmodifiableList(buildList(set))); 118 } 119 unitToListsOfVarsAfterBranches.put(s, lst); 120 } 122 set = (FlowSet) analysis.getFlowBefore(s); 123 unitToVarsBefore.put(s, Collections.unmodifiableList(buildList(set))); 124 126 if (computeChecks) { 127 128 ArrayList dontNeedCheckVars = new ArrayList(); 129 ArrayList needCheckVars = new ArrayList(); 130 131 HashSet allChecksSet = new HashSet(5, 0.7f); 132 allChecksSet.addAll((HashSet) analysis.unitToArrayRefChecksSet.get(s)); 133 allChecksSet.addAll((HashSet) analysis.unitToInstanceFieldRefChecksSet.get(s)); 134 allChecksSet.addAll((HashSet) analysis.unitToInstanceInvokeExprChecksSet.get(s)); 135 allChecksSet.addAll((HashSet) analysis.unitToLengthExprChecksSet.get(s)); 136 138 Iterator it = allChecksSet.iterator(); 139 140 while (it.hasNext()) { 141 142 Value v = (Value) it.next(); 143 int vInfo = analysis.anyRefInfo(v, set); 144 145 if (vInfo == analysis.kTop) { 146 needCheckVars.add(v); 148 } else if (vInfo == analysis.kBottom) { 149 needCheckVars.add(analysis.getKRefIntPair(new EquivalentValue(v), vInfo)); 152 } else { 153 dontNeedCheckVars.add(analysis.getKRefIntPair(new EquivalentValue(v), vInfo)); 155 } 156 } 157 158 unitToVarsNeedCheck.put(s, Collections.unmodifiableList(needCheckVars)); 159 unitToVarsDontNeedCheck.put(s, Collections.unmodifiableList(dontNeedCheckVars)); 160 } 162 } 164 } 166 167 175 176 177 public List getVarsBefore(Unit s) 178 { 179 return (List) unitToVarsBefore.get(s); 180 } 182 183 public List getVarsAfterFall(Unit s) 184 { 185 return (List) unitToVarsAfterFall.get(s); 186 } 188 189 public List getListsOfVarsAfterBranch(Unit s) 190 { 191 return (List) unitToListsOfVarsAfterBranches.get(s); 192 } 194 public List getVarsNeedCheck(Unit s) 195 { 196 if (computeChecks) 197 return (List) unitToVarsNeedCheck.get(s); 198 else 199 return new ArrayList(); 200 } 202 public List getVarsDontNeedCheck(Unit s) 203 { 204 if (computeChecks) 205 return (List) unitToVarsDontNeedCheck.get(s); 206 else 207 return new ArrayList(); 208 } 210 211 } | Popular Tags |