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

Go to the documentation of this file.
00001 /* Reorder type signatures, conditionals, and loops.  Reordering of   */
00002 /* type signatures is essential since subsequent passes assume a      */
00003 /* normal form.  Reordering of conditionals and loops generalizes     */
00004 /* signature matching and makes sure the programmer doesn't rely      */
00005 /* on sequential evaluation of guarded commands.  It also makes life  */
00006 /* easier for the code generator, since else guards will be permuted  */
00007 /* to the end.                                                        */
00008 
00009 # include "parm.h"
00010 
00011 # include "stree/ststructs.mh"
00012 
00013 extern int stplinks[];
00014 
00015 
00016 
00017 /* Fix up the subtree headed by p */
00018 reorder(p)
00019 NODE * p;
00020 {
00021     register int * q;   /* pointer to next field of p to be recursively     */
00022                         /* examined.                                        */
00023     register int v;     /* bit vector specifying primary link fields of *p  */
00024                         /* shifted so that the most significant bit         */
00025                         /* corresponds to q.                                */
00026 
00027     if (p == NIL) return;
00028     /* recursively examine subtrees */
00029         if (is_list(p)) {
00030             maplist(e, p, {
00031                 reorder(e);
00032             });
00033         } else {
00034             v = stplinks[p -> kind];
00035             q = (int *) p;
00036             while ( v != 0 ) {
00037                 if ( v < 0 /* msb is set */) {
00038                     reorder(*q);
00039                 }
00040                 q++;
00041                 v <<= 1;
00042             }
00043         }
00044     /* Now massage the subtree in question */
00045         switch( p -> kind ) {
00046             case GUARDEDLIST:
00047             case LOOPDENOTATION:
00048                 /* reorder list of guarded denotations */
00049                     gden_order(p);
00050                 break;
00051             case TYPESIGNATURE:
00052                 /* reorder type signature */
00053                     tsig_order(p);
00054                 break;
00055         }
00056 }
00057 

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