]>
Commit | Line | Data |
---|---|---|
616915dd | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
c59f5181 | 3 | ** Copyright (C) 1994-2003 University of Virginia, |
616915dd | 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 | ** | |
155af98d | 20 | ** For information on splint: info@splint.org |
21 | ** To report a bug: splint-bug@splint.org | |
11db3170 | 22 | ** For more information: http://www.splint.org |
616915dd | 23 | */ |
24 | /* | |
25 | ** paramNodeList.c | |
26 | ** | |
27 | ** based on list_template.c | |
28 | ** | |
29 | ** where T has T_equal (or change this) and T_unparse | |
30 | */ | |
31 | ||
1b8ae690 | 32 | # include "splintMacros.nf" |
b73d1009 | 33 | # include "basic.h" |
616915dd | 34 | |
35 | /*@only@*/ paramNodeList | |
36 | paramNodeList_new () | |
37 | { | |
38 | paramNodeList s = (paramNodeList) dmalloc (sizeof (*s)); | |
39 | ||
40 | s->nelements = 0; | |
41 | s->nspace = paramNodeListBASESIZE; | |
42 | s->elements = (paramNode *) | |
43 | dmalloc (sizeof (*s->elements) * paramNodeListBASESIZE); | |
44 | ||
45 | return (s); | |
46 | } | |
47 | ||
48 | /*@only@*/ paramNodeList | |
49 | paramNodeList_single (/*@keep@*/ paramNode p) | |
50 | { | |
51 | paramNodeList s = (paramNodeList) dmalloc (sizeof (*s)); | |
52 | ||
53 | s->nelements = 1; | |
54 | s->nspace = paramNodeListBASESIZE - 1; | |
55 | s->elements = (paramNode *) dmalloc (sizeof (*s->elements) * paramNodeListBASESIZE); | |
56 | s->elements[0] = p; | |
57 | ||
58 | return (s); | |
59 | } | |
60 | ||
61 | static void | |
62 | paramNodeList_grow (/*@notnull@*/ paramNodeList s) | |
63 | { | |
64 | int i; | |
65 | paramNode *newelements; | |
66 | ||
67 | s->nspace += paramNodeListBASESIZE; | |
68 | ||
69 | newelements = (paramNode *) dmalloc (sizeof (*newelements) | |
70 | * (s->nelements + s->nspace)); | |
71 | ||
72 | for (i = 0; i < s->nelements; i++) | |
73 | { | |
74 | newelements[i] = s->elements[i]; | |
75 | } | |
76 | ||
77 | sfree (s->elements); | |
78 | s->elements = newelements; | |
79 | } | |
80 | ||
81 | paramNodeList | |
82 | paramNodeList_add (paramNodeList s, paramNode el) | |
83 | { | |
84 | llassert (paramNodeList_isDefined (s)); | |
85 | ||
86 | if (s->nspace <= 0) | |
87 | paramNodeList_grow (s); | |
88 | ||
89 | s->nspace--; | |
90 | s->elements[s->nelements] = el; | |
91 | ||
92 | s->nelements++; | |
93 | return s; | |
94 | } | |
95 | ||
96 | /*@only@*/ paramNodeList | |
97 | paramNodeList_copy (paramNodeList s) | |
98 | { | |
99 | paramNodeList r = paramNodeList_new (); | |
100 | ||
101 | paramNodeList_elements (s, x) | |
102 | { | |
103 | r = paramNodeList_add (r, paramNode_copy (x)); | |
104 | } end_paramNodeList_elements; | |
105 | ||
106 | return r; | |
107 | } | |
108 | ||
109 | /*@only@*/ cstring | |
110 | paramNodeList_unparse (paramNodeList s) | |
111 | { | |
112 | bool first = TRUE; | |
113 | cstring st = cstring_undefined; | |
114 | ||
115 | paramNodeList_elements (s, current) | |
116 | { | |
117 | if (first) | |
118 | { | |
119 | st = paramNode_unparse (current); | |
120 | first = FALSE; | |
121 | } | |
122 | else | |
123 | { | |
124 | st = message ("%q, %q", st, paramNode_unparse (current)); | |
125 | } | |
126 | } end_paramNodeList_elements; | |
127 | ||
128 | return st; | |
129 | } | |
130 | ||
131 | /*@only@*/ cstring | |
132 | paramNodeList_unparseComments (paramNodeList s) | |
133 | { | |
134 | bool first = TRUE; | |
135 | cstring st = cstring_undefined; | |
136 | ||
137 | paramNodeList_elements (s, current) | |
138 | { | |
139 | if (first) | |
140 | { | |
141 | st = paramNode_unparseComments (current); | |
142 | first = FALSE; | |
143 | } | |
144 | else | |
145 | { | |
146 | st = message ("%q, %q", st, paramNode_unparseComments (current)); | |
147 | } | |
148 | } end_paramNodeList_elements; | |
149 | ||
150 | return st; | |
151 | } | |
152 | ||
153 | void | |
154 | paramNodeList_free (/*@only@*/ paramNodeList s) | |
155 | { | |
156 | if (paramNodeList_isDefined (s)) | |
157 | { | |
158 | int i; | |
159 | for (i = 0; i < s->nelements; i++) | |
160 | { | |
161 | paramNode_free (s->elements[i]); | |
162 | } | |
163 | ||
164 | sfree (s->elements); | |
165 | sfree (s); | |
166 | } | |
167 | } |