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 Set<EdgeKey> edgeKeysRemoved ) {
54 DefiniteReachState state = makeIn( fn );
55 state.store( x, f, y, edgeKeysRemoved );
56 fn2state.put( fn, state );
59 public void newObject( FlatNode fn,
61 DefiniteReachState state = makeIn( fn );
63 fn2state.put( fn, state );
66 public void methodCall( FlatNode fn,
67 TempDescriptor retVal ) {
68 DefiniteReachState state = makeIn( fn );
69 state.methodCall( retVal );
70 fn2state.put( fn, state );
76 public void writeState( FlatNode fn, String outputName ) {
77 DefiniteReachState state = makeIn( fn );
79 BufferedWriter bw = new BufferedWriter( new FileWriter( outputName+".txt" ) );
80 bw.write( state.toString() );
82 } catch( IOException e ) {
83 System.out.println( "ERROR writing definite reachability state:\n "+e );
88 // get the current state for just after the given
90 private DefiniteReachState get( FlatNode fn ) {
91 DefiniteReachState state = fn2state.get( fn );
93 state = new DefiniteReachState();
94 fn2state.put( fn, state );
99 // get the current state for the program point just
100 // before the given program point by merging the out
101 // states of the predecessor statements
102 private DefiniteReachState makeIn( FlatNode fn ) {
103 DefiniteReachState stateIn = new DefiniteReachState();
104 for( int i = 0; i < fn.numPrev(); ++i ) {
105 stateIn.merge( get( fn.getPrev( i ) ) );