2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 ** based on list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "splintMacros.nf"
35 termNodeList termNodeList_new ()
37 termNodeList s = (termNodeList) dmalloc (sizeof (*s));
40 s->nspacelow = termNodeListGROWLOW;
41 s->nspacehigh = termNodeListGROWHI;
42 s->elementsroot = (termNode *) dmalloc (sizeof (*s->elements) * (s->nspacelow + s->nspacehigh));
43 s->elements = s->elementsroot + termNodeListGROWLOW;
50 termNodeList_grow (termNodeList s)
53 termNode *newelements = (termNode *) dmalloc (sizeof (*newelements)
54 * (s->nelements + termNodeListBASESIZE));
56 for (i = 0; i < s->nelements; i++)
58 newelements[i + termNodeListGROWLOW] = s->elements[i];
61 sfree (s->elementsroot);
63 s->nspacelow = termNodeListGROWLOW;
64 s->nspacehigh = termNodeListGROWHI;
66 s->elementsroot = newelements;
67 s->elements = s->elementsroot + s->nspacelow;
71 termNodeList_addh (termNodeList s, termNode el)
73 llassert (termNodeListGROWHI > 0);
75 if (s->nspacehigh <= 0)
76 termNodeList_grow (s);
79 s->elements[s->nelements] = el;
84 termNodeList_push (termNodeList s, termNode el)
86 termNodeList_addh (s, el);
91 termNodeList_addl (termNodeList s, termNode el)
93 llassert (termNodeListGROWLOW > 0);
95 if (s->nspacelow <= 0)
96 termNodeList_grow (s);
106 termNodeList_reset (termNodeList s)
112 termNodeList_finish (termNodeList s)
114 s->current = s->nelements - 1;
118 termNodeList_advance (termNodeList s)
121 llassert (s->current < s->nelements);
124 /*@exposed@*/ termNode
125 termNodeList_head (termNodeList s)
127 llassert (s->nelements > 0);
128 return (s->elements[0]);
131 /*@only@*/ termNodeList
132 termNodeList_copy (termNodeList s)
134 termNodeList r = termNodeList_new ();
136 termNodeList_elements (s, x)
138 termNodeList_addh (r, termNode_copySafe (x));
139 } end_termNodeList_elements;
144 /*@exposed@*/ termNode
145 termNodeList_current (termNodeList s)
147 llassert (!(s->current >= s->nelements));
148 return (s->elements[s->current]);
152 termNodeList_getN (termNodeList s, int n)
154 llassert (n >= 0 && n < s->nelements);
156 return (s->elements[n]);
160 termNodeList_unparse (termNodeList s)
163 cstring st = cstring_undefined;
165 termNodeList_elements (s, current)
169 st = termNode_unparse (current);
173 st = message ("%q, %q", st, termNode_unparse (current));
174 } end_termNodeList_elements;
180 termNodeList_unparseTail (termNodeList s)
184 cstring st = cstring_undefined;
186 termNodeList_elements (s, current)
196 st = termNode_unparse (current);
200 st = message ("%q, %q", st, termNode_unparse (current));
202 } end_termNodeList_elements;
208 termNodeList_unparseToCurrent (termNodeList s)
211 cstring st = cstring_undefined;
213 for (i = 0; i < s->current; i++)
215 termNode current = s->elements[i];
218 st = termNode_unparse (current);
220 st = message ("%q, %q", st, termNode_unparse (current));
227 termNodeList_unparseSecondToCurrent (termNodeList s)
230 cstring st = cstring_undefined;
232 for (i = 1; i < s->current; i++)
234 termNode current = s->elements[i];
238 st = termNode_unparse (current);
242 st = message ("%q, %q", st, termNode_unparse (current));
250 termNodeList_free (termNodeList s)
253 for (i = 0; i < s->nelements; i++)
255 termNode_free (s->elements[i]);
258 sfree (s->elementsroot);