]> andersk Git - splint.git/blame - src/constraintList2.c
Handles ftpd.c in wu-ftp without crashing.
[splint.git] / src / constraintList2.c
CommitLineData
361091cc 1/*
2** LCLint - annotation-assisted static program checker
3** Copyright (C) 1994-2000 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 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
23*/
24/*
25** termNodeList.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 "lclintMacros.nf"
33# include "llbasic.h"
34
35constraintList constraintList_new ()
36{
37 constraintList s = (constraintList) dmalloc (sizeof (*s));
38
39 s->nelements = 0;
40 s->nspacelow = constraintListGROWLOW;
41 s->nspacehigh = constraintListGROWHI;
42 s->elementsroot = (constraint *) dmalloc (sizeof (*s->elements) * (s->nspacelow + s->nspacehigh));
43 s->elements = s->elementsroot + constraintListGROWLOW;
44 s->current = 0;
45
46 return (s);
47}
48
49static void
50constraintList_grow (constraintList s)
51{
52 int i;
53 constraint *newelements = (constraint *) dmalloc (sizeof (*newelements)
54 * (s->nelements + constraintListBASESIZE));
55
56 for (i = 0; i < s->nelements; i++)
57 {
58 newelements[i + constraintListGROWLOW] = s->elements[i];
59 }
60
61 sfree (s->elementsroot);
62
63 s->nspacelow = constraintListGROWLOW;
64 s->nspacehigh = constraintListGROWHI;
65
66 s->elementsroot = newelements;
67 s->elements = s->elementsroot + s->nspacelow;
68}
69
70void
71constraintList_addh (constraintList s, constraint el)
72{
73 llassert (constraintListGROWHI > 0);
74
75 if (s->nspacehigh <= 0)
76 constraintList_grow (s);
77
78 s->nspacehigh--;
79 s->elements[s->nelements] = el;
80 s->nelements++;
81}
82
83constraintList
84constraintList_push (constraintList s, constraint el)
85{
86 constraintList_addh (s, el);
87 return s;
88}
89
90void constraintList_insertList (constraintList
91
92void
93constraintList_addl (constraintList s, constraint el)
94{
95 llassert (constraintListGROWLOW > 0);
96
97 if (s->nspacelow <= 0)
98 constraintList_grow (s);
99
100 s->nspacelow--;
101 s->elements--;
102 s->elements[0] = el;
103 s->current++;
104 s->nelements++;
105}
106
107void
108constraintList_reset (constraintList s)
109{
110 s->current = 0;
111}
112
113void
114constraintList_finish (constraintList s)
115{
116 s->current = s->nelements - 1;
117}
118
119void
120constraintList_advance (constraintList s)
121{
122 s->current++;
123 llassert (s->current < s->nelements);
124}
125
126/*@exposed@*/ constraint
127constraintList_head (constraintList s)
128{
129 llassert (s->nelements > 0);
130 return (s->elements[0]);
131}
132
133/*@only@*/ constraintList
134constraintList_copy (constraintList s)
135{
136 constraintList r = constraintList_new ();
137
138 constraintList_elements (s, x)
139 {
140 constraintList_addh (r, constraint_copySafe (x));
141 } end_constraintList_elements;
142
143 return r;
144}
145
146/*@exposed@*/ constraint
147constraintList_current (constraintList s)
148{
149 llassert (!(s->current >= s->nelements));
150 return (s->elements[s->current]);
151}
152
153constraint
154constraintList_getN (constraintList s, int n)
155{
156 llassert (n >= 0 && n < s->nelements);
157
158 return (s->elements[n]);
159}
160
161/*@only@*/ cstring
162constraintList_unparse (constraintList s)
163{
164 bool first = TRUE;
165 cstring st = cstring_undefined;
166
167 constraintList_elements (s, current)
168 {
169 if (first)
170 {
171 st = constraint_unparse (current);
172 first = FALSE;
173 }
174 else
175 st = message ("%q, %q", st, constraint_unparse (current));
176 } end_constraintList_elements;
177
178 return st;
179}
180
181///* /*@only@*/ cstring */
182/* constraintList_unparseTail (constraintList s) */
183/* { */
184/* bool head = TRUE; */
185/* bool first = TRUE; */
186/* cstring st = cstring_undefined; */
187
188/* constraintList_elements (s, current) */
189/* { */
190/* if (head) */
191/* { */
192/* head = FALSE; */
193/* } */
194/* else */
195/* { */
196/* if (first) */
197/* { */
198/* st = constraint_unparse (current); */
199/* first = FALSE; */
200/* } */
201/* else */
202/* st = message ("%q, %q", st, constraint_unparse (current)); */
203/* } */
204/* } end_constraintList_elements; */
205
206/* return st; */
207/* } */
208
209// /*@only@*/ cstring
210/* constraintList_unparseToCurrent (constraintList s) */
211/* { */
212/* int i; */
213/* cstring st = cstring_undefined; */
214
215/* for (i = 0; i < s->current; i++) */
216/* { */
217/* constraint current = s->elements[i]; */
218
219/* if (i == 0) */
220/* st = constraint_unparse (current); */
221/* else */
222/* st = message ("%q, %q", st, constraint_unparse (current)); */
223/* } */
224
225/* return st; */
226/* } */
227
228///*@only@*/ cstring
229/* constraintList_unparseSecondToCurrent (constraintList s) */
230/* { */
231/* int i; */
232/* cstring st = cstring_undefined; */
233
234/* for (i = 1; i < s->current; i++) */
235/* { */
236/* constraint current = s->elements[i]; */
237
238/* if (i == 1) */
239/* { */
240/* st = constraint_unparse (current); */
241/* } */
242/* else */
243/* { */
244/* st = message ("%q, %q", st, constraint_unparse (current)); */
245/* } */
246/* } */
247
248/* return st; */
249/* } */
250
251void
252constraintList_free (constraintList s)
253{
254 int i;
255 for (i = 0; i < s->nelements; i++)
256 {
257 constraint_free (s->elements[i]);
258 }
259
260 sfree (s->elementsroot);
261 sfree (s);
262}
This page took 1.148594 seconds and 5 git commands to generate.