]> andersk Git - splint.git/blob - src/fcnNodeList.c
19bb191f03c566a10a01abcb2dc926befec4d4a0
[splint.git] / src / fcnNodeList.c
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.
19 **
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
23 */
24 /*
25 ** fcnNodeList.c
26 **
27 ** based on list_template.c
28 **
29 ** where T has T_equal (or change this) and T_unparse
30 */
31
32 # include "splintMacros.nf"
33 # include "llbasic.h"
34
35 fcnNodeList
36   fcnNodeList_new ()
37 {
38   return fcnNodeList_undefined;
39 }
40
41 static /*@notnull@*/ /*@only@*/ fcnNodeList
42 fcnNodeList_newEmpty (void)
43 {
44   fcnNodeList s = (fcnNodeList) dmalloc (sizeof (*s));
45   
46   s->nelements = 0;
47   s->nspace = fcnNodeListBASESIZE;
48   s->elements = (fcnNode *) dmalloc (sizeof (*s->elements) * fcnNodeListBASESIZE);
49
50   return (s);
51 }
52
53 static void
54 fcnNodeList_grow (/*@notnull@*/ fcnNodeList s)
55 {
56   int i;
57   fcnNode *newelements;
58
59   s->nspace += fcnNodeListBASESIZE;
60   newelements = (fcnNode *) dmalloc (sizeof (*newelements) 
61                                      * (s->nelements + s->nspace));
62
63   if (newelements == (fcnNode *) 0)
64     {
65       llfatalerror (cstring_makeLiteral ("fcnNodeList_grow: out of memory!"));
66     }
67
68   for (i = 0; i < s->nelements; i++)
69     {
70       newelements[i] = s->elements[i];
71     }
72
73   sfree (s->elements);
74   s->elements = newelements;
75 }
76
77 fcnNodeList
78 fcnNodeList_add (fcnNodeList s, fcnNode el)
79 {
80   if (fcnNodeList_isUndefined (s))
81     {
82       s = fcnNodeList_newEmpty ();
83     }
84
85   if (s->nspace <= 0)
86     fcnNodeList_grow (s);
87
88   s->nspace--;
89   s->elements[s->nelements] = el;
90   s->nelements++;
91
92   return s;
93 }
94
95 /*@only@*/ cstring
96 fcnNodeList_unparse (fcnNodeList s)
97 {
98   int i;
99   cstring st = cstring_undefined;
100
101   if (fcnNodeList_isDefined (s))
102     {
103       for (i = 0; i < s->nelements; i++)
104         {
105           st = message ("%q%q\n", st, fcnNode_unparse (s->elements[i]));
106         }
107     }
108
109   return st;
110 }
111
112 void
113 fcnNodeList_free (/*@null@*/ /*@only@*/ fcnNodeList s)
114 {
115   if (s != NULL)
116     {
117       int i;
118       for (i = 0; i < s->nelements; i++)
119         {
120           fcnNode_free (s->elements[i]); 
121         }
122       
123       sfree (s->elements);
124       sfree (s);
125     
126     }
127 }
This page took 0.032597 seconds and 3 git commands to generate.