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
34 # include "splintMacros.nf"
40 enumNameList s = (enumNameList) dmalloc (sizeof (*s));
43 s->nspace = enumNameListBASESIZE;
44 s->elements = (enumName *)
45 dmalloc (sizeof (*s->elements) * enumNameListBASESIZE);
50 /*@only@*/ enumNameList
51 enumNameList_single (/*@keep@*/ enumName t)
53 enumNameList s = (enumNameList) dmalloc (sizeof (*s));
56 s->nspace = enumNameListBASESIZE - 1;
57 s->elements = (enumName *) dmalloc (sizeof (*s->elements) * enumNameListBASESIZE);
64 enumNameList_match (enumNameList e1, enumNameList e2)
68 if (e1->nelements != e2->nelements) return FALSE;
70 for (i = 0; i < e1->nelements; i++)
72 if (!cstring_equal (e1->elements[i], e2->elements[i]))
79 enumNameList_grow (enumNameList s)
82 enumName *newelements;
84 s->nspace += enumNameListBASESIZE;
85 newelements = (enumName *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
87 if (newelements == (enumName *) 0)
89 llfatalerror (cstring_makeLiteral ("enumNameList_grow: out of memory!"));
92 for (i = 0; i < s->nelements; i++)
94 newelements[i] = s->elements[i];
98 s->elements = newelements;
102 enumNameList_addh (enumNameList s, /*@keep@*/ enumName el)
105 enumNameList_grow (s);
108 s->elements[s->nelements] = el;
113 enumNameList_push (/*@returned@*/ enumNameList s, /*@only@*/ enumName el)
115 enumNameList_addh (s, el);
119 /*@only@*/ enumNameList
120 enumNameList_copy (enumNameList s)
122 enumNameList r = enumNameList_new ();
124 enumNameList_elements (s, x)
126 enumNameList_addh (r, cstring_copy (x));
127 } end_enumNameList_elements;
133 enumNameList_member (enumNameList s, cstring m)
135 enumNameList_elements (s, x)
137 if (cstring_equal (m, x)) return TRUE;
138 } end_enumNameList_elements;
143 /*@only@*/ enumNameList
144 enumNameList_subtract (enumNameList source, enumNameList del)
146 enumNameList ret = enumNameList_new ();
148 enumNameList_elements (source, el)
150 if (!enumNameList_member (del, el))
152 enumNameList_addh (ret, cstring_copy (el));
154 } end_enumNameList_elements;
160 enumNameList_unparse (enumNameList s)
163 cstring st = cstring_undefined;
165 for (i = 0; i < s->nelements; i++)
169 st = cstring_copy (s->elements[i]);
173 st = message ("%q, %s", st, s->elements[i]);
180 cstring enumNameList_unparseBrief (enumNameList s)
183 cstring st = cstring_undefined;
185 for (i = 0; i < s->nelements; i++)
189 st = cstring_copy (s->elements[i]);
191 else if (i == 3 && s->nelements > 5)
193 st = message ("%q, ...", st);
194 i = s->nelements - 2;
198 st = message ("%q, %s", st, s->elements[i]);
206 enumNameList_dump (enumNameList s)
209 cstring st = cstring_undefined;
211 for (i = 0; i < s->nelements; i++)
215 st = cstring_copy (s->elements[i]);
218 st = message ("%q,%s", st, s->elements[i]);
223 /*@only@*/ enumNameList
224 enumNameList_undump (d_char *s)
226 enumNameList e = enumNameList_new ();
234 char *t = strchr (*s, ',');
239 t = strchr (*s, '}');
243 llcontbug (message ("enumNameList_undump: bad line: %s", cstring_fromChars (*s)));
251 enumNameList_addh (e, cstring_fromChars (mstring_copy (*s)));
261 enumNameList_free (enumNameList s)
266 for (i = 0; i < s->nelements; i++)
268 cstring_free (s->elements[i]);