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 /*@notnull@*/ /*@only@*/ ltokenList
38 ltokenList s = (ltokenList) dmalloc (sizeof (*s));
41 s->nspace = ltokenListBASESIZE;
42 s->elements = (ltoken *)
43 dmalloc (sizeof (*s->elements) * ltokenListBASESIZE);
49 /*@notnull@*/ /*@only@*/ ltokenList
50 ltokenList_singleton (ltoken l)
52 ltokenList s = (ltokenList) dmalloc (sizeof (*s));
55 s->nspace = ltokenListBASESIZE - 1;
56 s->elements = (ltoken *) dmalloc (sizeof (*s->elements) * ltokenListBASESIZE);
64 ltokenList_grow (/*@notnull@*/ ltokenList s)
69 s->nspace += ltokenListBASESIZE;
71 newelements = (ltoken *) dmalloc (sizeof (*newelements)
72 * (s->nelements + s->nspace));
74 for (i = 0; i < s->nelements; i++)
76 newelements[i] = s->elements[i];
80 s->elements = newelements;
84 ltokenList_push (/*@returned@*/ ltokenList s, ltoken el)
86 ltokenList_addh (s, el);
91 ltokenList_addh (ltokenList s, ltoken el)
93 llassert (ltokenList_isDefined (s));
99 s->elements[s->nelements] = el;
104 ltokenList_reset (ltokenList s)
106 if (ltokenList_isDefined (s))
113 ltokenList_isFinished (ltokenList s)
115 return (ltokenList_isUndefined(s) || (s->current == s->nelements));
119 ltokenList_advance (ltokenList s)
121 if (ltokenList_isDefined (s))
124 llassert (s->current <= s->nelements);
129 ltokenList_head (ltokenList s)
131 llassert (ltokenList_isDefined (s) && s->nelements > 0);
132 return (s->elements[0]);
136 ltokenList_equal (ltokenList s1, ltokenList s2)
138 if (ltokenList_isUndefined (s1))
140 return (ltokenList_isEmpty (s2));
144 if (ltokenList_isUndefined (s2))
146 return ltokenList_isEmpty (s1);
151 int size = s1->nelements;
153 if (s2->nelements != size)
156 for (i = 0; i < size; i++)
158 if (!ltoken_similar (s1->elements[i], s2->elements[i]))
166 /*@only@*/ ltokenList
167 ltokenList_copy (ltokenList s)
169 ltokenList r = ltokenList_new ();
171 ltokenList_elements (s, x)
173 ltokenList_addh (r, ltoken_copy (x));
174 } end_ltokenList_elements;
180 ltokenList_removeCurrent (ltokenList s)
183 llassert (ltokenList_isDefined (s) && s->current >= 0 && s->current < s->nelements);
185 for (i = s->current; i < s->nelements - 1; i++)
187 s->elements[i] = s->elements[i+1];
195 ltokenList_current (ltokenList s)
197 llassert (ltokenList_isDefined (s) && s->current >= 0 && s->current < s->nelements);
198 return (s->elements[s->current]);
202 ltokenList_unparse (ltokenList s)
205 cstring st = cstring_undefined;
207 if (ltokenList_isDefined (s))
209 for (i = 0; i < s->nelements; i++)
213 st = cstring_copy (ltoken_unparse (s->elements[i]));
216 st = message ("%q, %s", st, ltoken_unparse (s->elements[i]));
224 ltokenList_free (ltokenList s)
226 if (ltokenList_isDefined (s))