1 19 20 package edu.umd.cs.findbugs.ba; 21 22 import java.util.BitSet ; 23 import java.util.IdentityHashMap ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 27 import org.apache.bcel.generic.InstructionHandle; 28 29 import edu.umd.cs.findbugs.annotations.CheckForNull; 30 31 50 public abstract class AbstractDominatorsAnalysis extends BasicAbstractDataflowAnalysis<BitSet > { 51 private final CFG cfg; 52 private EdgeChooser edgeChooser; 53 54 60 public AbstractDominatorsAnalysis(CFG cfg, final boolean ignoreExceptionEdges) { 61 this(cfg, new EdgeChooser() { 62 public boolean choose(Edge edge) { 63 if (ignoreExceptionEdges && edge.isExceptionEdge()) 64 return false; 65 else 66 return true; 67 } 68 }); 69 } 70 71 77 public AbstractDominatorsAnalysis(CFG cfg, EdgeChooser edgeChooser) { 78 this.cfg = cfg; 79 this.edgeChooser = edgeChooser; 80 } 81 82 public BitSet createFact() { 83 return new BitSet (); 84 } 85 86 public void copy(BitSet source, BitSet dest) { 87 dest.clear(); 88 dest.or(source); 89 } 90 91 public void initEntryFact(BitSet result) { 92 result.clear(); 94 } 95 96 public void initResultFact(BitSet result) { 97 makeFactTop(result); 98 } 99 100 public boolean isTop(BitSet fact) { 101 return fact.get(cfg.getNumBasicBlocks()); 103 } 104 105 public void makeFactTop(BitSet fact) { 106 fact.set(cfg.getNumBasicBlocks()); 108 } 109 110 public boolean same(BitSet fact1, BitSet fact2) { 111 return fact1.equals(fact2); 112 } 113 114 public void transfer(BasicBlock basicBlock, @CheckForNull InstructionHandle end, BitSet start, BitSet result) throws DataflowAnalysisException { 115 copy(start, result); 117 118 if (!isTop(result)) { 119 result.set(basicBlock.getId()); 121 } 122 } 123 124 public void meetInto(BitSet fact, Edge edge, BitSet result) throws DataflowAnalysisException { 125 if (!edgeChooser.choose(edge)) 126 return; 127 128 if (isTop(fact)) 129 return; 130 else if (isTop(result)) 131 copy(fact, result); 132 else 133 result.and(fact); 135 } 136 137 145 public BitSet getAllDominatorsOf(BasicBlock block) { 146 return getResultFact(block); 147 } 148 149 158 public BitSet getAllDominatedBy(BasicBlock dominator) { 159 BitSet allDominated = new BitSet (); 160 for (Iterator <BasicBlock> i = cfg.blockIterator(); i.hasNext();) { 161 BasicBlock block = i.next(); 162 BitSet dominators = getResultFact(block); 163 if (dominators.get(dominator.getId())) 164 allDominated.set(block.getId()); 165 } 166 return allDominated; 167 } 168 169 } 170 171 | Popular Tags |