2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
27 ** based on list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "lclintMacros.nf"
35 constraintList constraintList_new ()
37 constraintList s = (constraintList) dmalloc (sizeof (*s));
40 s->nspacelow = constraintListGROWLOW;
41 s->nspacehigh = constraintListGROWHI;
42 s->elementsroot = (constraint *) dmalloc (sizeof (*s->elements) * (s->nspacelow + s->nspacehigh));
43 s->elements = s->elementsroot + constraintListGROWLOW;
50 constraintList_grow (constraintList s)
53 constraint *newelements = (constraint *) dmalloc (sizeof (*newelements)
54 * (s->nelements + constraintListBASESIZE));
56 for (i = 0; i < s->nelements; i++)
58 newelements[i + constraintListGROWLOW] = s->elements[i];
61 sfree (s->elementsroot);
63 s->nspacelow = constraintListGROWLOW;
64 s->nspacehigh = constraintListGROWHI;
66 s->elementsroot = newelements;
67 s->elements = s->elementsroot + s->nspacelow;
71 constraintList_addh (constraintList s, constraint el)
73 llassert (constraintListGROWHI > 0);
75 if (s->nspacehigh <= 0)
76 constraintList_grow (s);
79 s->elements[s->nelements] = el;
84 constraintList_push (constraintList s, constraint el)
86 constraintList_addh (s, el);
90 void constraintList_insertList (constraintList
93 constraintList_addl (constraintList s, constraint el)
95 llassert (constraintListGROWLOW > 0);
97 if (s->nspacelow <= 0)
98 constraintList_grow (s);
108 constraintList_reset (constraintList s)
114 constraintList_finish (constraintList s)
116 s->current = s->nelements - 1;
120 constraintList_advance (constraintList s)
123 llassert (s->current < s->nelements);
126 /*@exposed@*/ constraint
127 constraintList_head (constraintList s)
129 llassert (s->nelements > 0);
130 return (s->elements[0]);
133 /*@only@*/ constraintList
134 constraintList_copy (constraintList s)
136 constraintList r = constraintList_new ();
138 constraintList_elements (s, x)
140 constraintList_addh (r, constraint_copySafe (x));
141 } end_constraintList_elements;
146 /*@exposed@*/ constraint
147 constraintList_current (constraintList s)
149 llassert (!(s->current >= s->nelements));
150 return (s->elements[s->current]);
154 constraintList_getN (constraintList s, int n)
156 llassert (n >= 0 && n < s->nelements);
158 return (s->elements[n]);
162 constraintList_unparse (constraintList s)
165 cstring st = cstring_undefined;
167 constraintList_elements (s, current)
171 st = constraint_unparse (current);
175 st = message ("%q, %q", st, constraint_unparse (current));
176 } end_constraintList_elements;
181 ///* /*@only@*/ cstring */
182 /* constraintList_unparseTail (constraintList s) */
184 /* bool head = TRUE; */
185 /* bool first = TRUE; */
186 /* cstring st = cstring_undefined; */
188 /* constraintList_elements (s, current) */
198 /* st = constraint_unparse (current); */
202 /* st = message ("%q, %q", st, constraint_unparse (current)); */
204 /* } end_constraintList_elements; */
209 // /*@only@*/ cstring
210 /* constraintList_unparseToCurrent (constraintList s) */
213 /* cstring st = cstring_undefined; */
215 /* for (i = 0; i < s->current; i++) */
217 /* constraint current = s->elements[i]; */
220 /* st = constraint_unparse (current); */
222 /* st = message ("%q, %q", st, constraint_unparse (current)); */
229 /* constraintList_unparseSecondToCurrent (constraintList s) */
232 /* cstring st = cstring_undefined; */
234 /* for (i = 1; i < s->current; i++) */
236 /* constraint current = s->elements[i]; */
240 /* st = constraint_unparse (current); */
244 /* st = message ("%q, %q", st, constraint_unparse (current)); */
252 constraintList_free (constraintList s)
255 for (i = 0; i < s->nelements; i++)
257 constraint_free (s->elements[i]);
260 sfree (s->elementsroot);