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
28 ** based on set_template.c
30 ** where T has T_equal (or change this) and T_unparse
33 # include "splintMacros.nf"
35 # include "checking.h" /* for lslOp_equal */
37 static bool lslOpSet_member (lslOpSet p_s, lslOp p_el);
39 lslOpSet lslOpSet_new ()
41 lslOpSet s = (lslOpSet) dmalloc (sizeof (*s));
44 s->nspace = lslOpSetBASESIZE;
45 s->elements = (lslOp *)
46 dmalloc (sizeof (*s->elements) * lslOpSetBASESIZE);
51 static /*@only@*/ lslOpSet
52 lslOpSet_predict (int size)
54 lslOpSet s = (lslOpSet) dmalloc (sizeof (*s));
61 s->elements = (lslOp *) dmalloc (sizeof (*s->elements) * size);
73 lslOpSet_grow (/*@notnull@*/ lslOpSet s)
78 s->nspace = lslOpSetBASESIZE;
79 newelements = (lslOp *) dmalloc (sizeof (*newelements)
80 * (s->entries + s->nspace));
82 if (newelements == (lslOp *) 0)
84 llfatalerror (cstring_makeLiteral ("lslOpSet_grow: out of memory!"));
87 for (i = 0; i < s->entries; i++)
89 newelements[i] = s->elements[i];
93 s->elements = newelements;
97 ** Ensures: if *e \in *s
98 ** then unchanged (*s) & result = false
99 ** else *s' = insert (*s, *e) & result = true
104 lslOpSet_insert (lslOpSet s, /*@only@*/ lslOp el)
106 llassert (lslOpSet_isDefined (s));
108 if (lslOpSet_member (s, el))
118 s->elements[s->entries] = el;
125 lslOpSet_member (lslOpSet s, lslOp el)
127 if (lslOpSet_isDefined (s))
131 for (i = 0; i < lslOpSet_size (s); i++)
133 if (lslOp_equal (el, s->elements[i]))
142 lslOpSet_unparse (lslOpSet s)
144 if (lslOpSet_isDefined (s))
147 cstring st = cstring_makeLiteral ("{");
149 for (i = 0; i < lslOpSet_size (s); i++)
151 st = message ("%q %q", st, lslOp_unparse (s->elements[i]));
154 st = message ("%q}", st);
159 return (cstring_makeLiteral ("{ }"));
164 lslOpSet_copy (lslOpSet s)
166 if (lslOpSet_isDefined (s))
168 lslOpSet t = lslOpSet_predict (lslOpSet_size (s));
171 for (i = 0; i < lslOpSet_size (s); i++)
173 (void) lslOpSet_insert (t, lslOp_copy (s->elements[i]));
180 return lslOpSet_undefined;
185 lslOpSet_free (lslOpSet s)
187 if (lslOpSet_isDefined (s))
190 for (i = 0; i < s->entries; i++)
192 lslOp_free (s->elements[i]);