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 // a class-wide initialization
19 DefiniteReachState.initBuilders();
21 fn2state = new HashMap<FlatNode, DefiniteReachState>();
25 public void methodEntry( FlatNode fn,
26 Set<TempDescriptor> parameters ) {
27 DefiniteReachState state = get( fn );
28 state.methodEntry( parameters );
29 fn2state.put( fn, state );
32 public void copy( FlatNode fn,
35 DefiniteReachState state = makeIn( fn );
37 fn2state.put( fn, state );
40 public void load( FlatNode fn,
44 DefiniteReachState state = makeIn( fn );
45 state.load( x, y, f );
46 fn2state.put( fn, state );
49 public void store( FlatNode fn,
53 DefiniteReachState state = makeIn( fn );
54 state.store( x, f, y );
55 fn2state.put( fn, state );
58 public void newObject( FlatNode fn,
60 DefiniteReachState state = makeIn( fn );
62 fn2state.put( fn, state );
65 // x is the return value, x = foo(...);
66 public void methodCall( FlatNode fn,
68 DefiniteReachState state = makeIn( fn );
69 state.methodCall( x );
70 fn2state.put( fn, state );
74 public void writeState( FlatNode fn, String outputName ) {
75 DefiniteReachState state = makeIn( fn );
77 BufferedWriter bw = new BufferedWriter( new FileWriter( outputName+".txt" ) );
78 bw.write( state.toString() );
80 } catch( IOException e ) {
81 System.out.println( "ERROR writing definite reachability state:\n "+e );
86 // get the current state for just after the given
88 private DefiniteReachState get( FlatNode fn ) {
89 DefiniteReachState state = fn2state.get( fn );
91 state = new DefiniteReachState();
92 fn2state.put( fn, state );
97 // get the current state for the program point just
98 // before the given program point by merging the out
99 // states of the predecessor statements
100 private DefiniteReachState makeIn( FlatNode fn ) {
101 DefiniteReachState stateIn = new DefiniteReachState();
102 for( int i = 0; i < fn.numPrev(); ++i ) {
103 stateIn.merge( get( fn.getPrev( i ) ) );