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
25 ** metaStateConstraintList.c (from slist_template.c)
28 # include "splintMacros.nf"
30 # include "metaStateConstraintList.h"
33 ** Invariant: If any member of the list is metaStateConstraint_undefined, then
34 ** the 0th member is metaStateConstraint_undefined.
37 metaStateConstraintList
38 metaStateConstraintList_new ()
40 return (metaStateConstraintList_undefined);
43 static /*@notnull@*/ /*@only@*/ metaStateConstraintList
44 metaStateConstraintList_newEmpty (void)
46 metaStateConstraintList s = (metaStateConstraintList) dmalloc (sizeof (*s));
49 s->free = metaStateConstraintListBASESIZE;
50 s->elements = (metaStateConstraint *) dmalloc (sizeof (*s->elements) * metaStateConstraintListBASESIZE);
56 metaStateConstraintList_grow (/*@notnull@*/ metaStateConstraintList s)
59 metaStateConstraint *oldelements = s->elements;
61 s->free += metaStateConstraintListBASESIZE;
62 s->elements = (metaStateConstraint *) dmalloc (sizeof (*s->elements)
63 * (s->nelements + s->free));
65 for (i = 0; i < s->nelements; i++)
67 s->elements[i] = oldelements[i];
73 metaStateConstraintList
74 metaStateConstraintList_append (/*@returned@*/ metaStateConstraintList s, /*@only@*/ metaStateConstraintList t)
76 llassert (NOALIAS (s, t));
78 if (metaStateConstraintList_isUndefined (t) || metaStateConstraintList_isEmpty (t)) return s;
80 if (metaStateConstraintList_isUndefined (s))
82 s = metaStateConstraintList_newEmpty ();
85 metaStateConstraintList_elements (t, fl)
87 /* Okay to use exposed storage here, t is begin eaten. */
89 /*@-exposetrans@*/ /*@-dependenttrans@*/
90 s = metaStateConstraintList_add (s, fl);
91 /*@=exposetrans@*/ /*@=dependenttrans@*/
92 } end_metaStateConstraintList_elements;
100 metaStateConstraintList
101 metaStateConstraintList_add (/*@returned@*/ metaStateConstraintList s, /*@observer@*/ metaStateConstraint el)
103 if (metaStateConstraintList_isUndefined (s))
105 s = metaStateConstraintList_newEmpty ();
110 metaStateConstraintList_grow (s);
114 s->elements[s->nelements] = el;
120 metaStateConstraintList
121 metaStateConstraintList_single (metaStateConstraint el)
123 metaStateConstraintList res = metaStateConstraintList_newEmpty ();
124 return metaStateConstraintList_add (res, el);
128 metaStateConstraintList_getFirst (metaStateConstraintList s)
130 llassert (metaStateConstraintList_isDefined (s)
131 && metaStateConstraintList_size (s) >= 1);
132 return s->elements[0];
136 metaStateConstraintList_unparse (metaStateConstraintList s)
139 cstring st = cstring_makeLiteral ("[");
141 if (metaStateConstraintList_isDefined (s))
143 for (i = 0; i < metaStateConstraintList_size (s); i++)
147 st = message ("%q %q", st, metaStateConstraint_unparse (s->elements[i]));
150 st = message ("%q, %q", st, metaStateConstraint_unparse (s->elements[i]));
154 st = message ("%q ]", st);
159 metaStateConstraintList_free (/*@only@*/ metaStateConstraintList s)
161 if (metaStateConstraintList_isDefined (s))