2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
25 ** mtMergeClauseList.c
27 ** based on list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "lclintMacros.nf"
34 # include "mtgrammar.h"
37 mtMergeClauseList_new ()
39 return mtMergeClauseList_undefined;
42 static /*@notnull@*/ mtMergeClauseList
43 mtMergeClauseList_newEmpty (void)
45 mtMergeClauseList s = (mtMergeClauseList) dmalloc (sizeof (*s));
48 s->nspace = mtMergeClauseListBASESIZE;
49 s->elements = (mtMergeClause *) dmalloc (sizeof (*s->elements) * mtMergeClauseListBASESIZE);
55 mtMergeClauseList_grow (/*@notnull@*/ mtMergeClauseList s)
58 mtMergeClause *newelements;
60 s->nspace += mtMergeClauseListBASESIZE;
62 newelements = (mtMergeClause *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
64 if (newelements == (mtMergeClause *) 0)
66 llfatalerror (cstring_makeLiteral ("mtMergeClauseList_grow: out of memory!"));
69 for (i = 0; i < s->nelements; i++)
71 newelements[i] = s->elements[i];
75 s->elements = newelements;
78 mtMergeClauseList mtMergeClauseList_single (/*@keep@*/ mtMergeClause el)
80 mtMergeClauseList s = mtMergeClauseList_new ();
81 s = mtMergeClauseList_add (s, el);
85 mtMergeClauseList mtMergeClauseList_add (mtMergeClauseList s, /*@keep@*/ mtMergeClause el)
87 if (!mtMergeClauseList_isDefined (s))
89 s = mtMergeClauseList_newEmpty ();
94 mtMergeClauseList_grow (s);
98 /*@i32@*/ s->elements[s->nelements] = el;
104 mtMergeClauseList mtMergeClauseList_prepend (mtMergeClauseList s, /*@keep@*/ mtMergeClause el)
108 if (!mtMergeClauseList_isDefined (s))
110 /*@i32@*/ return mtMergeClauseList_single (el);
115 mtMergeClauseList_grow (s);
120 for (i = s->nelements; i > 0; i--)
122 s->elements[i] = s->elements [i - 1];
125 /*@i32@*/ s->elements[0] = el;
132 mtMergeClauseList_unparse (mtMergeClauseList s)
134 return mtMergeClauseList_unparseSep (s, cstring_makeLiteralTemp (" "));
138 mtMergeClauseList_unparseSep (mtMergeClauseList s, cstring sep)
140 cstring st = cstring_undefined;
142 if (mtMergeClauseList_isDefined (s))
146 for (i = 0; i < s->nelements; i++)
150 st = mtMergeClause_unparse (s->elements[i]);
153 st = message ("%q%s%q", st, sep, mtMergeClause_unparse (s->elements[i]));
161 mtMergeClauseList_free (mtMergeClauseList s)
163 if (mtMergeClauseList_isDefined (s))
167 for (i = 0; i < s->nelements; i++) {
168 mtMergeClause_free (s->elements[i]);