Nicer handling of hand-generated files by build system
[splint-patched.git] / src / ctypeList.c
blob003742208d2bd51894c93315689be649926ba222
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 ()
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 ctypeList ctypeList_add (ctypeList s, ctype el)
84 llassert (ctypeListBASESIZE > 0);
86 if (ctypeList_isUndefined (s))
88 s = ctypeList_new ();
91 ctypeList_addh (s, el);
92 return s;
95 ctypeList ctypeList_append (ctypeList s1, ctypeList s2)
97 ctypeList res = s1;
99 ctypeList_elements (s2, el)
101 res = ctypeList_add (res, el);
102 } end_ctypeList_elements;
104 return res;
107 /*@only@*/ cstring
108 ctypeList_unparse (ctypeList ct)
110 cstring s = cstring_undefined;
111 int i;
112 bool first = TRUE;
114 if (ctypeList_isUndefined (ct) || ctypeList_size (ct) == 0)
116 return (cstring_makeLiteral ("void"));
119 for (i = 0; i < ct->nelements; i++)
121 if (first)
123 s = cstring_copy (ctype_unparse (ct->elements[i]));
124 first = FALSE;
126 else
128 s = message ("%q, %s", s, ctype_unparse (ct->elements[i]));
132 return s;
135 void
136 ctypeList_free (/*@only@*/ ctypeList s)
138 if (ctypeList_isDefined (s))
140 int i;
141 for (i = 0; i < s->nelements; i++)
143 /* ctype_free (s->elements[i]); */
146 sfree (s->elements); /* not quite!!! */
147 sfree (s);