C:/Users/Dennis/src/lang/russell.orig/src/pass3/number.c

Go to the documentation of this file.
00001 /* assign pre- and post-order numbers to each node in the syntax tree */
00002 
00003 # include "parm.h"
00004 
00005 # include "stree/ststructs.mh"
00006 
00007 # include "stree/stplinks.mh"
00008 
00009 int next_pre; next_post;   /* next pre- and post-order numbers to be */
00010                                   /* assigned.                              */
00011 
00012 /* Number the subtree headed by p */
00013 number(p)
00014 NODE * p;
00015 {
00016     register int * q;   /* pointer to next field of p to be recursively     */
00017                         /* examined.                                        */
00018     register int v;     /* bit vector specifying primary link fields of *p  */
00019                         /* shifted so that the most significant bit         */
00020                         /* corresponds to q.                                */
00021     if ( p == NIL ) return;
00022     p -> pre_num = next_pre++;
00023     /* recursively examine subtrees */
00024         if (is_list(p)) {
00025             maplist(e, p, {
00026                 number(e);
00027             });
00028         } else {
00029             v = stplinks[p -> kind];
00030             q = (int *) p;
00031             while ( v != 0 ) {
00032                 if ( v < 0 /* msb is set */) {
00033                     number(*q);
00034                 }
00035                 q++;
00036                 v <<= 1;
00037             }
00038         }
00039     p -> post_num = next_post++;
00040 }
00041 

Generated on Fri Jan 25 10:39:46 2008 for russell by  doxygen 1.5.4