1 package Analysis.Disjoint;
10 public class DefiniteReachAnalysis {
12 // keep a state of definite reachability analysis for
13 // every program point
14 private Map<FlatNode, DefiniteReachState> fn2state;
16 public DefiniteReachAnalysis() {
17 fn2state = new HashMap<FlatNode, DefiniteReachState>();
21 public void methodEntry( FlatNode fn,
22 Set<TempDescriptor> parameters ) {
23 DefiniteReachState state = get( fn );
24 state.methodEntry( parameters );
25 fn2state.put( fn, state );
28 public void copy( FlatNode fn,
31 DefiniteReachState state = makeIn( fn );
33 fn2state.put( fn, state );
36 public void load( FlatNode fn,
40 DefiniteReachState state = makeIn( fn );
41 state.load( x, y, f );
42 fn2state.put( fn, state );
45 public void store( FlatNode fn,
49 DefiniteReachState state = makeIn( fn );
50 state.store( x, f, y );
51 fn2state.put( fn, state );
54 public void newObject( FlatNode fn,
56 DefiniteReachState state = makeIn( fn );
58 fn2state.put( fn, state );
61 // x is the return value, x = foo(...);
62 public void methodCall( FlatNode fn,
64 DefiniteReachState state = makeIn( fn );
65 state.methodCall( x );
66 fn2state.put( fn, state );
70 // get the current state for just after the given
72 private DefiniteReachState get( FlatNode fn ) {
73 DefiniteReachState state = fn2state.get( fn );
75 state = new DefiniteReachState();
76 fn2state.put( fn, state );
81 // get the current state for the program point just
82 // before the given program point by merging the out
83 // states of the predecessor statements
84 private DefiniteReachState makeIn( FlatNode fn ) {
85 DefiniteReachState stateIn = new DefiniteReachState();
86 for( int i = 0; i < fn.numPrev(); ++i ) {
87 stateIn.merge( get( fn.getPrev( i ) ) );