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 fcnNodeList
00036 fcnNodeList_new ()
00037 {
00038 return fcnNodeList_undefined;
00039 }
00040
00041 static fcnNodeList
00042 fcnNodeList_newEmpty (void)
00043 {
00044 fcnNodeList s = (fcnNodeList) dmalloc (sizeof (*s));
00045
00046 s->nelements = 0;
00047 s->nspace = fcnNodeListBASESIZE;
00048 s->elements = (fcnNode *) dmalloc (sizeof (*s->elements) * fcnNodeListBASESIZE);
00049
00050 return (s);
00051 }
00052
00053 static void
00054 fcnNodeList_grow ( fcnNodeList s)
00055 {
00056 int i;
00057 fcnNode *newelements;
00058
00059 s->nspace += fcnNodeListBASESIZE;
00060 newelements = (fcnNode *) dmalloc (sizeof (*newelements)
00061 * (s->nelements + s->nspace));
00062
00063 if (newelements == (fcnNode *) 0)
00064 {
00065 llfatalerror (cstring_makeLiteral ("fcnNodeList_grow: out of memory!"));
00066 }
00067
00068 for (i = 0; i < s->nelements; i++)
00069 {
00070 newelements[i] = s->elements[i];
00071 }
00072
00073 sfree (s->elements);
00074 s->elements = newelements;
00075 }
00076
00077 fcnNodeList
00078 fcnNodeList_add (fcnNodeList s, fcnNode el)
00079 {
00080 if (fcnNodeList_isUndefined (s))
00081 {
00082 s = fcnNodeList_newEmpty ();
00083 }
00084
00085 if (s->nspace <= 0)
00086 fcnNodeList_grow (s);
00087
00088 s->nspace--;
00089 s->elements[s->nelements] = el;
00090 s->nelements++;
00091
00092 return s;
00093 }
00094
00095 cstring
00096 fcnNodeList_unparse (fcnNodeList s)
00097 {
00098 int i;
00099 cstring st = cstring_undefined;
00100
00101 if (fcnNodeList_isDefined (s))
00102 {
00103 for (i = 0; i < s->nelements; i++)
00104 {
00105 st = message ("%q%q\n", st, fcnNode_unparse (s->elements[i]));
00106 }
00107 }
00108
00109 return st;
00110 }
00111
00112 void
00113 fcnNodeList_free ( fcnNodeList s)
00114 {
00115 if (s != NULL)
00116 {
00117 int i;
00118 for (i = 0; i < s->nelements; i++)
00119 {
00120 fcnNode_free (s->elements[i]);
00121 }
00122
00123 sfree (s->elements);
00124 sfree (s);
00125
00126 }
00127 }