void cleanup ( ) { State s ; State nexts ; int n ; /* clear out unreachable or dead-end states */ /* use pre to mark reachable, then post to mark can-reach-post */ markreachable ( pre , null , pre ) ; markcanreach ( post , pre , post ) ; for ( s = states ; s != null ; s = nexts ) { nexts = s . next ; if ( s . tmp != post && 0 == s . flag ) { dropstate ( s ) ; } } assert post . nins == 0 || post . tmp == post ; cleartraverse ( pre ) ; assert post . nins == 0 || post . tmp == null ; /* the nins==0 (final unreachable) case will be caught later */ /* renumber surviving states */ n = 0 ; for ( s = states ; s != null ; s = s . next ) { s . no = n ++ ; } nstates = n ; }
cleanup - clean up NFA after optimizations