| 1 19 20 package edu.umd.cs.findbugs.ba; 21 22 import java.util.IdentityHashMap ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 26 import org.apache.bcel.generic.InstructionHandle; 27 28 40 public abstract class BasicAbstractDataflowAnalysis<Fact> implements DataflowAnalysis<Fact> { 41 private IdentityHashMap <BasicBlock, Fact> startFactMap; 42 private IdentityHashMap <BasicBlock, Fact> resultFactMap; 43 44 47 public BasicAbstractDataflowAnalysis() { 48 this.startFactMap = new IdentityHashMap <BasicBlock, Fact>(); 49 this.resultFactMap = new IdentityHashMap <BasicBlock, Fact>(); 50 } 51 52 55 public Iterator <Fact> resultFactIterator() { 56 return resultFactMap.values().iterator(); 57 } 58 59 64 public String factToString(Fact fact) { 65 return fact.toString(); 66 } 67 68 public Fact getStartFact(BasicBlock block) { 69 return lookupOrCreateFact(startFactMap, block); 70 } 71 72 public Fact getResultFact(BasicBlock block) { 73 return lookupOrCreateFact(resultFactMap, block); 74 } 75 76 90 public Fact getFactAtLocation(Location location) throws DataflowAnalysisException { 91 return getStartFact(location.getBasicBlock()); 92 } 93 94 108 public Fact getFactAfterLocation(Location location) throws DataflowAnalysisException { 109 if (location.getBasicBlock().isEmpty()) { 110 return getResultFact(location.getBasicBlock()); 111 } 112 113 InstructionHandle logicalLastInstruction = isForwards() 114 ? location.getBasicBlock().getLastInstruction() 115 : location.getBasicBlock().getFirstInstruction(); 116 117 if (location.getHandle() == logicalLastInstruction) { 118 return getResultFact(location.getBasicBlock()); 119 } else { 120 return getStartFact(location.getBasicBlock()); 121 } 122 } 123 124 131 public Fact getFactOnEdge(Edge edge) throws DataflowAnalysisException { 132 BasicBlock block = isForwards() ? edge.getSource() : edge.getTarget(); 133 134 Fact predFact = createFact(); 135 copy(getResultFact(block), predFact); 136 137 edgeTransfer(edge, predFact); 138 139 Fact result = createFact(); 140 makeFactTop(result); 141 meetInto(predFact, edge, result); 142 143 return result; 144 } 145 146 149 public void startIteration() { 150 } 152 153 156 public void finishIteration() { 157 } 159 160 163 public void edgeTransfer(Edge edge, Fact fact) throws DataflowAnalysisException { 164 } 167 168 private Fact lookupOrCreateFact(Map <BasicBlock, Fact> map, BasicBlock block) { 169 Fact fact = map.get(block); 170 if (fact == null) { 171 fact = createFact(); 172 map.put(block, fact); 173 } 174 return fact; 175 } 176 177 public int getLastUpdateTimestamp(Fact fact) { 178 return 0; 179 } 180 public void setLastUpdateTimestamp(Fact fact, int lastUpdateTimestamp) { 181 182 } 183 184 } 185 | Popular Tags |