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 list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "splintMacros.nf"
38 ctypeList s
= (ctypeList
) dmalloc (sizeof (*s
));
41 s
->nspace
= ctypeListBASESIZE
;
42 s
->elements
= (ctype
*) dmalloc (sizeof (*s
->elements
) * ctypeListBASESIZE
);
48 ctypeList_grow (/*@notnull@*/ ctypeList s
)
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
];
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
);
78 s
->elements
[s
->nelements
] = el
;
82 ctypeList
ctypeList_add (ctypeList s
, ctype el
)
84 llassert (ctypeListBASESIZE
> 0);
86 if (ctypeList_isUndefined (s
))
91 ctypeList_addh (s
, el
);
95 ctypeList
ctypeList_append (ctypeList s1
, ctypeList s2
)
99 ctypeList_elements (s2
, el
)
101 res
= ctypeList_add (res
, el
);
102 } end_ctypeList_elements
;
108 ctypeList_unparse (ctypeList ct
)
110 cstring s
= cstring_undefined
;
114 if (ctypeList_isUndefined (ct
) || ctypeList_size (ct
) == 0)
116 return (cstring_makeLiteral ("void"));
119 for (i
= 0; i
< ct
->nelements
; i
++)
123 s
= cstring_copy (ctype_unparse (ct
->elements
[i
]));
128 s
= message ("%q, %s", s
, ctype_unparse (ct
->elements
[i
]));
136 ctypeList_free (/*@only@*/ ctypeList s
)
138 if (ctypeList_isDefined (s
))
141 for (i
= 0; i
< s
->nelements
; i
++)
143 /* ctype_free (s->elements[i]); */
146 sfree (s
->elements
); /* not quite!!! */