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 set_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "splintMacros.nf"
35 /*@constant int lsymbolSetBASESIZE;@*/
36 # define lsymbolSetBASESIZE MIDBASESIZE
38 lsymbolSet
lsymbolSet_new (void)
40 lsymbolSet s
= (lsymbolSet
) dmalloc (sizeof (*s
));
43 s
->nspace
= lsymbolSetBASESIZE
;
44 s
->elements
= (lsymbol
*) dmalloc (sizeof (*s
->elements
) * lsymbolSetBASESIZE
);
50 lsymbolSet_grow (lsymbolSet s
)
55 llassert (lsymbolSet_isDefined (s
));
57 s
->nspace
= lsymbolSetBASESIZE
;
58 newelements
= (lsymbol
*) dmalloc (sizeof (*newelements
)
59 * (s
->entries
+ s
->nspace
));
61 if (newelements
== (lsymbol
*) 0)
63 llfatalerror (cstring_makeLiteral ("lsymbolSet_grow: out of memory!"));
66 for (i
= 0; i
< s
->entries
; i
++)
68 newelements
[i
] = s
->elements
[i
];
72 s
->elements
= newelements
;
76 ** Ensures: if *e \in *s
77 ** then unchanged (*s) & result = false
78 ** else *s' = insert (*s, *e) & result = true
83 lsymbolSet_insert (lsymbolSet s
, lsymbol el
)
85 llassert (lsymbolSet_isDefined (s
));
87 if (lsymbolSet_member (s
, el
))
96 s
->elements
[s
->entries
] = el
;
103 lsymbolSet_member (lsymbolSet s
, lsymbol el
)
105 if (lsymbolSet_isDefined (s
))
109 for (i
= 0; i
< s
->entries
; i
++)
111 /* was: &el == &s->elements[i] ! */
113 if (lsymbol_equal (el
, s
->elements
[i
]))
125 lsymbolSet_unparse (lsymbolSet s
)
127 if (lsymbolSet_isDefined (s
))
130 cstring st
= cstring_makeLiteral ("{");
132 for (i
= 0; i
< s
->entries
; i
++)
136 st
= message ("%q %s", st
,
137 cstring_fromChars (lsymbol_toChars (s
->elements
[i
])));
140 st
= message ("%q, %s", st
,
141 cstring_fromChars (lsymbol_toChars (s
->elements
[i
])));
144 st
= message ("%q }", st
);
149 return (cstring_makeLiteral ("{ }"));
152 # endif /* DEADCODE */
155 lsymbolSet_free (/*@null@*/ lsymbolSet s
)
157 if (lsymbolSet_isDefined (s
))