1 package Analysis.Disjoint;
11 public class DefiniteReachAnalysis {
13 // keep a state of definite reachability analysis for
14 // every program point
15 private Map<FlatNode, DefiniteReachState> fn2state;
17 public DefiniteReachAnalysis() {
18 fn2state = new HashMap<FlatNode, DefiniteReachState>();
22 public void methodEntry( FlatNode fn,
23 Set<TempDescriptor> parameters ) {
24 DefiniteReachState state = get( fn );
25 state.methodEntry( parameters );
26 fn2state.put( fn, state );
29 public void copy( FlatNode fn,
32 DefiniteReachState state = makeIn( fn );
34 fn2state.put( fn, state );
37 public void load( FlatNode fn,
41 DefiniteReachState state = makeIn( fn );
42 state.load( x, y, f );
43 fn2state.put( fn, state );
46 public void store( FlatNode fn,
50 DefiniteReachState state = makeIn( fn );
51 state.store( x, f, y );
52 fn2state.put( fn, state );
55 public void newObject( FlatNode fn,
57 DefiniteReachState state = makeIn( fn );
59 fn2state.put( fn, state );
62 // x is the return value, x = foo(...);
63 public void methodCall( FlatNode fn,
65 DefiniteReachState state = makeIn( fn );
66 state.methodCall( x );
67 fn2state.put( fn, state );
71 public void writeState( FlatNode fn, String outputName ) {
72 DefiniteReachState state = makeIn( fn );
74 BufferedWriter bw = new BufferedWriter( new FileWriter( outputName+".txt" ) );
75 bw.write( state.toString() );
77 } catch( IOException e ) {
78 System.out.println( "ERROR writing definite reachability state:\n "+e );
83 // get the current state for just after the given
85 private DefiniteReachState get( FlatNode fn ) {
86 DefiniteReachState state = fn2state.get( fn );
88 state = new DefiniteReachState();
89 fn2state.put( fn, state );
94 // get the current state for the program point just
95 // before the given program point by merging the out
96 // states of the predecessor statements
97 private DefiniteReachState makeIn( FlatNode fn ) {
98 DefiniteReachState stateIn = new DefiniteReachState();
99 for( int i = 0; i < fn.numPrev(); ++i ) {
100 stateIn.merge( get( fn.getPrev( i ) ) );