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

Go to the documentation of this file.
00001 # include "parm.h"
00002 
00003 # include "stree/ststructs.mh"
00004 
00005 # include "stree/Array.h"
00006 
00007 int comp_gden();
00008 
00009 Array * list_to_array();
00010 
00011 
00012 /*
00013  *  gden_order(guarded_list_or_loop)
00014  *
00015  *  Sort the list of guarded commands into some arbitrary but well-defined
00016  * order.  All but one else clause is deleted, and that clause appears at
00017  * the end.
00018  */
00019 
00020 gden_order(gden)
00021 NODE * gden;
00022 {
00023     Array * a;  /* array representation of the list of guarded denotations */
00024     int a_len;  /* number of pointers in a */
00025     register int i,j;
00026     unsigned *p, *q;
00027     NODE * r;
00028 
00029 #   ifdef DEBUG
00030         if (gden->kind != LOOPDENOTATION && gden->kind != GUARDEDLIST) {
00031             dbgmsg("gden_order: Improper argument: %x\n", gden);
00032             abort();
00033         }
00034 #   endif
00035     a = list_to_array(gden -> gl_list);
00036     a_len = a -> a_size;
00037 
00038     /*
00039         printf("#%x,%d,",a,a_len);
00040         for(i = 0; i < a_len; i++) printf("%x,",a->a_body[i]);
00041         printf("\n");
00042     */
00043     /* Sort the array */
00044         qsort(&a->a_body[0], a_len, (sizeof (NODE *)), comp_gden);
00045 
00046     /*
00047        printf("#%x,%d,",a,a_len);
00048        for(i = 0; i < a_len; i++) printf("%x,",a->a_body[i]);
00049        printf("\n");
00050     */
00051     /* Put everything back into the loop or conditional node */
00052         chgfld(&(gden -> gl_list), emptylist());
00053         for (i = 0; i < a_len; i++) {
00054             addright(gden -> gl_list, a->a_body[i]);
00055             /* stop after the first else clause */
00056                 if(a->a_body[i] -> ge_guard -> kind == WORDELSE) break;
00057         }
00058         free_array(a);
00059 }
00060 
00061 /*
00062  * compare two guarded denotation nodes, imposing an arbitrary order on the
00063  * guards, except that anything with a WORDELSE guard is infinitely large.
00064  */
00065 comp_gden(p, q)
00066 NODE **p, **q;
00067 {
00068     register int i;
00069 
00070     i = comp_st((*p) -> ge_guard, (*q) -> ge_guard, 
00071                 NIL, NIL /* may be wrong, but no -1 stt indicees
00072                             are ever generated within conditionals,
00073                             so it doesn't matter */);
00074     if (i == 0) {
00075         i = comp_st((*p) -> ge_element, (*q) -> ge_element, NIL, NIL);
00076     }
00077     return(i);
00078 }

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