2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 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 /*@only@*/ exprNodeList
38 exprNodeList s = (exprNodeList) dmalloc (sizeof (*s));
41 s->nspace = exprNodeListBASESIZE;
42 s->elements = (exprNode *)
43 dmalloc (sizeof (*s->elements) * exprNodeListBASESIZE);
50 exprNodeList_grow (exprNodeList s)
53 exprNode *newelements;
56 if (s->nelements < exprNodeListBASESIZE)
58 numnew = exprNodeListBASESIZE;
62 numnew = s->nelements;
65 s->nspace = numnew + s->nspace;
67 newelements = (exprNode *) dmalloc (sizeof (*newelements) * (s->nelements + numnew));
69 if (newelements == (exprNode *) 0)
71 llfatalerror (cstring_makeLiteral ("exprNodeList_grow: out of memory!"));
74 for (i = 0; i < s->nelements; i++)
76 newelements[i] = s->elements[i];
80 s->elements = newelements;
83 void exprNodeList_addh (exprNodeList s, /*@only@*/ exprNode el)
85 llassert (exprNodeListBASESIZE > 0);
88 exprNodeList_grow (s);
91 s->elements[s->nelements] = el;
95 void exprNodeList_reset (exprNodeList s)
100 void exprNodeList_advance (exprNodeList s)
103 llassert (s->current <= s->nelements);
106 /*@observer@*/ exprNode exprNodeList_head (exprNodeList s)
108 llassert (s->nelements > 0);
109 return (s->elements[0]);
112 /*@observer@*/ exprNode exprNodeList_current (exprNodeList s)
114 llassert (s->current >= 0 && s->current < s->nelements);
115 return (s->elements[s->current]);
118 exprNode exprNodeList_getN (exprNodeList s, int n)
120 llassert (n >= 0 && n < s->nelements);
121 return (s->elements[n]);
124 /*@only@*/ exprNodeList exprNodeList_singleton (/*@only@*/ exprNode e)
126 exprNodeList s = (exprNodeList) dmalloc (sizeof (*s));
129 s->nspace = exprNodeListBASESIZE - 1;
130 s->elements = (exprNode *) dmalloc (sizeof (*s->elements) * exprNodeListBASESIZE);
134 DPRINTF (("List: %s", exprNode_unparse (e)));
138 exprNodeList exprNodeList_push (/*@returned@*/ exprNodeList args, /*@only@*/ exprNode e)
140 exprNodeList_addh (args, e);
144 /*@exposed@*/ exprNode
145 exprNodeList_nth (exprNodeList args, int n)
147 if (n >= exprNodeList_size (args) || n < 0)
149 llcontbug (message ("exprNodeList_nth: out of range: %q arg %d\n",
150 exprNodeList_unparse (args), n));
151 return exprNode_undefined;
154 return args->elements[n];
158 exprNodeList_unparse (exprNodeList s)
161 cstring st = cstring_undefined;
163 for (i = 0; i < s->nelements; i++)
167 st = cstring_copy (exprNode_unparse (s->elements[i]));
170 st = message ("%q, %s", st, exprNode_unparse (s->elements[i]));
177 exprNodeList_free (exprNodeList s)
181 for (i = 0; i < s->nelements; i++)
183 exprNode_free (s->elements[i]);
191 exprNodeList_freeShallow (/*@only@*/ exprNodeList s)
195 for (i = 0; i < s->nelements; i++)
197 exprNode_freeShallow (s->elements[i]);