00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 # include "lclintMacros.nf"
00033 # include "llbasic.h"
00034
00035 sortList
00036 sortList_new ()
00037 {
00038 sortList s = (sortList) dmalloc (sizeof (*s));
00039
00040 s->nelements = 0;
00041 s->nspace = sortListBASESIZE;
00042 s->elements = (sort *) dmalloc (sizeof (*s->elements) * sortListBASESIZE);
00043 s->current = 0;
00044
00045 return (s);
00046 }
00047
00048 static void
00049 sortList_grow (sortList s)
00050 {
00051 int i;
00052 sort *newelements;
00053
00054 s->nspace += sortListBASESIZE;
00055
00056 newelements = (sort *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
00057
00058 if (newelements == (sort *) 0)
00059 {
00060 llfatalerror (cstring_makeLiteral ("sortList_grow: out of memory!"));
00061 }
00062
00063 for (i = 0; i < s->nelements; i++)
00064 {
00065 newelements[i] = s->elements[i];
00066 }
00067
00068 sfree (s->elements);
00069 s->elements = newelements;
00070 }
00071
00072 void
00073 sortList_addh (sortList s, sort el)
00074 {
00075 if (s->nspace <= 0)
00076 sortList_grow (s);
00077
00078 s->nspace--;
00079 s->elements[s->nelements] = el;
00080 s->nelements++;
00081 }
00082
00083 void
00084 sortList_reset (sortList s)
00085 {
00086 s->current = 0;
00087 }
00088
00089 void
00090 sortList_advance (sortList s)
00091 {
00092 s->current++;
00093 llassert (s->current < s->nelements);
00094 }
00095
00096 sort
00097 sortList_current (sortList s)
00098 {
00099 if (s->current < 0 || s->current >= s->nelements)
00100 {
00101 llbug (message ("sortList_current: current out of range: %d (size: %d)",
00102 s->current, s->nelements));
00103 }
00104 return (s->elements[s->current]);
00105 }
00106
00107 cstring
00108 sortList_unparse (sortList s)
00109 {
00110 int i;
00111 cstring st = cstring_undefined;
00112
00113 for (i = 0; i < s->nelements; i++)
00114 {
00115 if (i == 0)
00116 {
00117 st = cstring_copy (sort_unparseName (s->elements[i]));
00118 }
00119 else
00120 {
00121 st = message ("%q, %s", st, sort_unparseName (s->elements[i]));
00122 }
00123 }
00124
00125 return st;
00126 }
00127
00128 void
00129 sortList_free (sortList s)
00130 {
00131 int i;
00132 for (i = 0; i < s->nelements; i++)
00133 {
00134
00135 }
00136
00137 sfree (s->elements);
00138 sfree (s);
00139 }