Various minor fixes for compiler/linter (other then splint itself) warnings.
[splint-patched.git] / src / ctypeList.c
blob1987c0ff498abcf0c4a312ea0bedd2bb3440ba9e
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
5 **
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.
10 **
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.
15 **
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
25 ** ctypeList.c
27 ** based on list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "splintMacros.nf"
33 # include "basic.h"
35 /*@only@*/ ctypeList
36 ctypeList_new (void)
38 ctypeList s = (ctypeList) dmalloc (sizeof (*s));
40 s->nelements = 0;
41 s->nspace = ctypeListBASESIZE;
42 s->elements = (ctype *) dmalloc (sizeof (*s->elements) * ctypeListBASESIZE);
44 return (s);
47 static void
48 ctypeList_grow (/*@notnull@*/ ctypeList s)
50 int i;
51 ctype *newelements;
53 s->nspace += ctypeListBASESIZE;
54 newelements = (ctype *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
56 if (newelements == (ctype *) 0)
58 llfatalerror (cstring_makeLiteral ("ctypeList_grow: out of memory!"));
61 for (i = 0; i < s->nelements; i++)
63 newelements[i] = s->elements[i];
66 sfree (s->elements);
67 s->elements = newelements;
70 void ctypeList_addh (ctypeList s, ctype el)
72 llassert (ctypeList_isDefined (s));
73 llassert (ctypeListBASESIZE > 0);
75 if (s->nspace <= 0) ctypeList_grow (s);
77 s->nspace--;
78 s->elements[s->nelements] = el;
79 s->nelements++;
82 # ifdef DEADCODE
83 ctypeList ctypeList_add (ctypeList s, ctype el)
85 llassert (ctypeListBASESIZE > 0);
87 if (ctypeList_isUndefined (s))
89 s = ctypeList_new ();
92 ctypeList_addh (s, el);
93 return s;
96 ctypeList ctypeList_append (ctypeList s1, ctypeList s2)
98 ctypeList res = s1;
100 ctypeList_elements (s2, el)
102 res = ctypeList_add (res, el);
103 } end_ctypeList_elements;
105 return res;
108 /*@only@*/ cstring
109 ctypeList_unparse (ctypeList ct)
111 cstring s = cstring_undefined;
112 int i;
113 bool first = TRUE;
115 if (ctypeList_isUndefined (ct) || ctypeList_size (ct) == 0)
117 return (cstring_makeLiteral ("void"));
120 for (i = 0; i < ct->nelements; i++)
122 if (first)
124 s = cstring_copy (ctype_unparse (ct->elements[i]));
125 first = FALSE;
127 else
129 s = message ("%q, %s", s, ctype_unparse (ct->elements[i]));
133 return s;
135 # endif /* DEADCODE */
137 void
138 ctypeList_free (/*@only@*/ ctypeList s)
140 if (ctypeList_isDefined (s))
142 int i;
143 for (i = 0; i < s->nelements; i++)
145 /* ctype_free (s->elements[i]); */
148 sfree (s->elements); /* not quite!!! */
149 sfree (s);