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 private static PointerMethod pm;
18 public static void setPointerMethod( PointerMethod pm ) {
19 DefiniteReachAnalysis.pm = pm;
23 public DefiniteReachAnalysis() {
24 // a class-wide initialization
25 DefiniteReachState.initBuilders();
27 fn2state = new HashMap<FlatNode, DefiniteReachState>();
31 public void methodEntry( FlatNode fn,
32 Set<TempDescriptor> parameters ) {
33 DefiniteReachState state = makeIn( fn );
34 state.methodEntry( parameters );
35 fn2state.put( fn, state );
38 public void copy( FlatNode fn,
41 DefiniteReachState state = makeIn( fn );
43 fn2state.put( fn, state );
46 public void load( FlatNode fn,
50 Set<EdgeKey> edgeKeysForLoad ) {
52 DefiniteReachState state = makeIn( fn );
53 state.load( x, y, f, edgeKeysForLoad );
54 fn2state.put( fn, state );
57 public void store( FlatNode fn,
61 Set<EdgeKey> edgeKeysRemoved,
62 Set<EdgeKey> edgeKeysAdded ) {
64 DefiniteReachState state = makeIn( fn );
65 state.store( x, f, y, edgeKeysRemoved, edgeKeysAdded );
66 fn2state.put( fn, state );
69 public void newObject( FlatNode fn,
71 DefiniteReachState state = makeIn( fn );
73 fn2state.put( fn, state );
76 public void methodCall( FlatNode fn,
77 TempDescriptor retVal ) {
78 DefiniteReachState state = makeIn( fn );
79 if( retVal != null ) {
80 state.methodCall( retVal );
82 fn2state.put( fn, state );
85 public void otherStatement( FlatNode fn ) {
86 fn2state.put( fn, makeIn( fn ) );
90 public void writeState( FlatNode fn, String outputName ) {
91 makeIn( fn ).writeState( outputName );
95 // get the current state for just after the given
97 public DefiniteReachState get( FlatNode fn ) {
98 DefiniteReachState state = fn2state.get( fn );
100 state = new DefiniteReachState();
101 fn2state.put( fn, state );
106 // get the current state for the program point just
107 // before the given program point by merging the out
108 // states of the predecessor statements
109 public DefiniteReachState makeIn( FlatNode fn ) {
110 if( pm.numPrev( fn ) == 0 ) {
111 return new DefiniteReachState();
114 DefiniteReachState stateIn = null;
116 for( int i = 0; i < pm.numPrev( fn ); ++i ) {
118 if( fn2state.containsKey( pm.getPrev( fn, i ) ) ) {
119 if( stateIn == null ) {
120 // duplicate the first partial result we find
121 stateIn = new DefiniteReachState( get( pm.getPrev( fn, i ) ) );
123 // merge other partial results into the rest
124 stateIn.merge( get( pm.getPrev( fn, i ) ) );
129 // at least one predecessor was analyzed before this
130 assert( stateIn != null );