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 set_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "splintMacros.nf"
36 static bool sigNodeSet_member (sigNodeSet p_s, sigNode p_el);
41 sigNodeSet s = (sigNodeSet) dmalloc (sizeof (*s));
44 s->nspace = sigNodeSetBASESIZE;
45 s->elements = (sigNode *) dmalloc (sizeof (*s->elements) * sigNodeSetBASESIZE);
51 sigNodeSet_singleton (sigNode el)
53 sigNodeSet s = (sigNodeSet) dmalloc (sizeof (*s));
56 s->nspace = sigNodeSetBASESIZE - 1;
57 s->elements = (sigNode *) dmalloc (sizeof (*s->elements) * sigNodeSetBASESIZE);
64 sigNodeSet_grow (/*@notnull@*/ sigNodeSet s)
69 s->nspace = sigNodeSetBASESIZE;
70 newelements = (sigNode *) dmalloc (sizeof (*newelements)
71 * (s->entries + s->nspace));
73 for (i = 0; i < s->entries; i++)
75 newelements[i] = s->elements[i];
79 s->elements = newelements;
83 ** Ensures: if *e \in *s
84 ** then unchanged (*s) & result = false
85 ** else *s' = insert (*s, *e) & result = true
90 sigNodeSet_insert (sigNodeSet s, /*@owned@*/ sigNode el)
92 llassert (sigNodeSet_isDefined (s));
94 if (sigNodeSet_member (s, el))
107 s->elements[s->entries] = el;
114 sigNodeSet_member (sigNodeSet s, sigNode el)
116 if (sigNodeSet_isUndefined (s))
124 for (i = 0; i < s->entries; i++)
126 if (sigNode_equal (el, s->elements[i]))
134 sigNodeSet_unparse (sigNodeSet s)
137 cstring st = cstring_undefined;
139 if (sigNodeSet_isDefined (s))
141 for (i = 0; i < s->entries; i++)
145 st = sigNode_unparse (s->elements[i]);
148 st = message ("%q, %q", st, sigNode_unparse (s->elements[i]));
156 sigNodeSet_unparseSomeSigs (sigNodeSet s)
159 cstring st = cstring_undefined;
161 if (sigNodeSet_isDefined (s))
163 for (i = 0; i < s->entries; i++)
165 cstring t = sigNode_unparseText (s->elements[i]);
169 st = cstring_copy (t);
172 else if (i > 5 && (s->entries > 8))
174 return (message ("%q; %q; ... (%d more signatures)",
175 st, t, (s->entries - i - 1)));
179 st = message ("%q; %q", st, t);
188 sigNodeSet_unparsePossibleAritys (sigNodeSet s)
191 intSet is = intSet_new ();
194 if (sigNodeSet_isDefined (s))
196 for (i = 0; i < s->entries; i++)
198 int arity = ltokenList_size ((s->elements[i])->domain);
199 (void) intSet_insert (is, arity);
203 st = intSet_unparseText (is);
209 sigNodeSet_free (sigNodeSet s)
211 if (sigNodeSet_isDefined (s))
214 for (i = 0; i < s->entries; i++)
216 sigNode_free (s->elements[i]);