1 19 20 package edu.umd.cs.findbugs.ba; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import org.apache.bcel.classfile.ClassParser; 26 import org.apache.bcel.classfile.JavaClass; 27 import org.apache.bcel.classfile.Method; 28 import org.apache.bcel.generic.CodeExceptionGen; 29 import org.apache.bcel.generic.InstructionHandle; 30 import org.apache.bcel.generic.ObjectType; 31 32 import edu.umd.cs.findbugs.SystemProperties; 33 import edu.umd.cs.findbugs.annotations.CheckForNull; 34 35 42 public class BlockTypeAnalysis extends BasicAbstractDataflowAnalysis<BlockType> { 43 private DepthFirstSearch dfs; 44 45 50 public BlockTypeAnalysis(DepthFirstSearch dfs) { 51 this.dfs = dfs; 52 } 53 54 public BlockType createFact() { 55 return new BlockType(); 56 } 57 58 public void copy(BlockType source, BlockType dest) { 59 dest.copyFrom(source); 60 } 61 62 public void initEntryFact(BlockType result) throws DataflowAnalysisException { 63 result.setNormal(); 64 } 65 66 public void initResultFact(BlockType result) { 67 makeFactTop(result); 68 } 69 70 public void makeFactTop(BlockType fact) { 71 fact.setTop(); 72 } 73 public boolean isTop(BlockType fact) { 74 return fact.isTop(); 75 } 76 public boolean isForwards() { 77 return true; 78 } 79 80 public BlockOrder getBlockOrder(CFG cfg) { 81 return new ReversePostOrder(cfg, dfs); 82 } 83 84 public boolean same(BlockType fact1, BlockType fact2) { 85 return fact1.sameAs(fact2); 86 } 87 88 public void transfer(BasicBlock basicBlock, @CheckForNull InstructionHandle end, BlockType start, BlockType result) 89 throws DataflowAnalysisException { 90 result.copyFrom(start); 91 92 if (start.isValid()) { 93 if (basicBlock.isExceptionHandler()) { 94 CodeExceptionGen exceptionGen = basicBlock.getExceptionGen(); 95 ObjectType catchType = exceptionGen.getCatchType(); 96 if (catchType == null) { 97 result.pushFinally(); 100 } else { 101 result.pushCatch(); 104 } 105 } 106 } 107 } 108 109 public void meetInto(BlockType fact, Edge edge, BlockType result) throws DataflowAnalysisException { 110 result.mergeWith(fact); 111 } 112 113 public static void main(String [] argv) throws Exception { 114 if (argv.length != 1) { 115 System.err.println("Usage: " + BlockTypeAnalysis.class.getName() + " <classfile>"); 116 System.exit(1); 117 } 118 119 DataflowTestDriver<BlockType, BlockTypeAnalysis> driver = new DataflowTestDriver<BlockType, BlockTypeAnalysis>() { 120 123 @Override 124 public Dataflow<BlockType, BlockTypeAnalysis> createDataflow(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException { 125 return classContext.getBlockTypeDataflow(method); 126 } 127 }; 128 129 driver.execute(argv[0]); 130 } 131 } 132 133 | Popular Tags |