Don't try calling lsl when file is missing.
[splint-patched.git] / src / exprNodeSList.c
blobd71625070932166bb3568054c60c72c148ffb3e0
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 ** exprNodeSList.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"
34 # include "exprNodeSList.h"
36 /*@constant int exprNodeSListBASESIZE;@*/
37 # define exprNodeSListBASESIZE SMALLBASESIZE
39 exprNodeSList
40 exprNodeSList_new (void)
42 exprNodeSList s = (exprNodeSList) dmalloc (sizeof (*s));
44 s->nelements = 0;
45 s->nspace = exprNodeSListBASESIZE;
46 s->elements = (exprNode *)
47 dmalloc (sizeof (*s->elements) * exprNodeSListBASESIZE);
49 return (s);
52 static void
53 exprNodeSList_grow (exprNodeSList s)
55 int i;
56 exprNode *newelements;
58 s->nspace += exprNodeSListBASESIZE;
60 newelements = (exprNode *) dmalloc (sizeof (*newelements)
61 * (s->nelements + s->nspace));
63 if (newelements == (exprNode *) 0)
65 llfatalerror (cstring_makeLiteral ("exprNodeSList_grow: out of memory!"));
68 for (i = 0; i < s->nelements; i++)
70 newelements[i] = s->elements[i];
73 sfree (s->elements);
74 s->elements = newelements;
77 static /*@unused@*/ void exprNodeSList_addh (exprNodeSList s, /*@exposed@*/ /*@dependent@*/ exprNode el)
79 llassert (exprNodeSListBASESIZE > 0);
81 if (s->nspace <= 0)
82 exprNodeSList_grow (s);
84 s->nspace--;
85 s->elements[s->nelements] = el;
86 s->nelements++;
90 ** appends s2 to s1
93 exprNodeSList exprNodeSList_append (/*@returned@*/ exprNodeSList s1, /*@only@*/ exprNodeSList s2)
95 exprNodeSList_elements (s2, x)
97 exprNodeSList_addh (s1, x);
98 } end_exprNodeSList_elements;
100 exprNodeSList_free (s2);
101 return s1;
104 /*@only@*/ exprNodeSList exprNodeSList_singleton (/*@exposed@*/ /*@dependent@*/ exprNode e)
106 exprNodeSList s = (exprNodeSList) dmalloc (sizeof (*s));
108 s->nelements = 1;
109 s->nspace = exprNodeSListBASESIZE - 1;
110 s->elements = (exprNode *) dmalloc (sizeof (*s->elements) * exprNodeSListBASESIZE);
111 s->elements[0] = e;
113 return (s);
116 # ifdef DEADCODE
117 /*@only@*/ cstring
118 exprNodeSList_unparse (exprNodeSList s)
120 int i;
121 cstring st = cstring_undefined;
123 for (i = 0; i < s->nelements; i++)
125 if (i == 0)
127 st = cstring_copy (exprNode_unparse (s->elements[i]));
129 else
130 st = message ("%q, %s", st, exprNode_unparse (s->elements[i]));
133 return st;
135 # endif /* DEADCODE */
137 void
138 exprNodeSList_free (exprNodeSList s)
140 sfree (s->elements);
141 sfree (s);