]> andersk Git - splint.git/blame - src/constraintList.c
Fixed make file so that pristine gets rid of more generated files.
[splint.git] / src / constraintList.c
CommitLineData
616915dd 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** constraintList.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
d46ce6a4 35
36/*@iter constraintList_elements_private (sef constraintList x, yield constraint el); @*/
37# define constraintList_elements_private(x, m_el) \
38 { int m_ind; constraint *m_elements = &((x)->elements[0]); \
39 for (m_ind = 0 ; m_ind < (x)->nelements; m_ind++) \
40 { constraint m_el = *(m_elements++);
41
42# define end_constraintList_elements_private }}
43
44
c3e695ff 45constraintList constraintList_makeNew ()
616915dd 46{
47 constraintList s = (constraintList) dmalloc (sizeof (*s));
48
49 s->nelements = 0;
50 s->nspace = constraintListBASESIZE;
51 s->elements = (constraint *)
52 dmalloc (sizeof (*s->elements) * constraintListBASESIZE);
53
54 return (s);
55}
56
57static void
58constraintList_grow (constraintList s)
59{
60 int i;
61 constraint *newelements;
62
63 s->nspace += constraintListBASESIZE;
64 newelements = (constraint *) dmalloc (sizeof (*newelements)
65 * (s->nelements + s->nspace));
66
67 for (i = 0; i < s->nelements; i++)
68 {
69 newelements[i] = s->elements[i];
70 }
71
72 sfree (s->elements);
73 s->elements = newelements;
74}
75
c3e695ff 76
616915dd 77constraintList
bb25bea6 78constraintList_add (/*@returned@*/ constraintList s, /*@only@*/ constraint el)
616915dd 79{
c3e695ff 80 /*drl7x */
81 // el = constraint_simplify (el);
616915dd 82 if (resolve (el, s) )
d46ce6a4 83 {
84 constraint_free (el);
85 return s;
86 }
616915dd 87
88 if (s->nspace <= 0)
89 constraintList_grow (s);
90
91 s->nspace--;
92 s->elements[s->nelements] = el;
93 s->nelements++;
94 return s;
95}
96
d46ce6a4 97/* frees everything but actual constraints */
98/* This function should only be used if you have
99 other references to unshared constraints
100*/
101static void constraintList_freeShallow (/*@only@*/ constraintList c)
102{
103 if (constraintList_isDefined(c) )
bb25bea6 104 {
105 free (c->elements);
106 c->elements = NULL;
107 c->nelements = -1;
108 c->nspace = -1;
109 }
d46ce6a4 110 free (c);
bb25bea6 111 c = NULL;
112}
113
114/*@only@*/ constraintList constraintList_addList (/*@returned@*/ constraintList s, /*@observer@*/ constraintList new)
115{
116 llassert(constraintList_isDefined(s) );
117 llassert(constraintList_isDefined(new) );
118
119 if (new == constraintList_undefined)
120 return s;
121
122 constraintList_elements (new, elem)
123 {
124 s = constraintList_add (s, constraint_copy(elem) );
125 }
126 end_constraintList_elements;
127
128 return s;
d46ce6a4 129}
130
bb25bea6 131/*@only@*/ constraintList constraintList_addListFree (/*@only@*/ constraintList s, /*@only@*/ constraintList new)
616915dd 132{
84c9ffbf 133 llassert(constraintList_isDefined(s) );
134 llassert(constraintList_isDefined(new) );
616915dd 135
136 if (new == constraintList_undefined)
137 return s;
138
d46ce6a4 139 constraintList_elements_private(new, elem)
616915dd 140 {
141 s = constraintList_add (s, elem);
142 }
d46ce6a4 143 end_constraintList_elements_private
144
145 constraintList_freeShallow(new);
616915dd 146 return s;
147}
148
149cstring
150constraintList_print (constraintList s) /*@*/
151{
152 int i;
153 cstring st = cstring_undefined;
154 bool first = TRUE;
155
156 if (s->nelements == 0)
d46ce6a4 157 {
158 st = cstring_makeLiteral("<List Empty>");
159 return st;
160 }
161
616915dd 162 for (i = 0; i < s->nelements; i++)
163 {
164 cstring type = cstring_undefined;
165 constraint current = s->elements[i];
166
167 if (current != NULL)
168 {
90bc41f7 169 cstring temp1;
170 if ( context_getFlag (FLG_ORCONSTRAINT) )
171 temp1 = constraint_printOr(current);
172 else
173 temp1 = constraint_print(current);
616915dd 174 type = message ("%q %q\n", type, temp1 );
175 }
176
177 if (first)
178 {
179 st = type;
180 first = FALSE;
181 }
182 else
183 {
184 st = message ("%q, %q", st, type);
185 }
d46ce6a4 186 } //end for
187
616915dd 188 return st;
189}
190
8f299805 191void constraintList_printErrorPostConditions (constraintList s, fileloc loc)
192{
193
194 constraintList_elements (s, elem)
195 {
196 if (elem != NULL)
197 {
198 constraint_printErrorPostCondition (elem, loc);
199 }
200 }
201 end_constraintList_elements;
202 return;
203}
204
616915dd 205void constraintList_printError (constraintList s, fileloc loc)
206{
207
bb25bea6 208 constraintList_elements (s, elem)
616915dd 209 {
210 if (elem != NULL)
211 {
212 constraint_printError (elem, loc);
213 }
214 }
bb25bea6 215 end_constraintList_elements;
616915dd 216 return;
217}
218
8f299805 219
616915dd 220cstring
221constraintList_printDetailed (constraintList s)
222{
223 int i;
224 cstring st = cstring_undefined;
225 bool first = TRUE;
226
227 if (s->nelements == 0)
d46ce6a4 228 {
229 st = cstring_makeLiteral("<List Empty>");
230 return st;
231 }
232
616915dd 233 for (i = 0; i < s->nelements; i++)
234 {
235 cstring type = cstring_undefined;
236 constraint current = s->elements[i];
237
238 if (current != NULL)
239 {
240 cstring temp1 = constraint_printDetailed (current);
241 type = message ("%s %s\n", type, temp1 );
d46ce6a4 242 cstring_free(temp1);
616915dd 243 }
244
245 if (first)
246 {
247 st = type;
248 first = FALSE;
249 }
250 else
251 {
252 st = message ("%s %s", st, type);
253 }
254 }
255 return st;
256}
257
258/*{ x: constraint | (x in l1 -> resolve (x, l2) || (x in l2 -> resolve (x, l1)
259} */
260
261constraintList
bb25bea6 262constraintList_logicalOr (/*@observer@*/ constraintList l1, /*@observer@*/ constraintList l2)
616915dd 263{
264 constraint temp;
265 constraintList ret;
bb25bea6 266 DPRINTF ( (message ("Logical or on %s and %s",
616915dd 267 constraintList_print(l1),
268 constraintList_print(l2)) ) );
269
c3e695ff 270 ret = constraintList_makeNew();
bb25bea6 271 constraintList_elements (l1, el)
616915dd 272 {
273 temp = substitute (el, l2);
274
275 if (resolve (el, l2) || resolve(temp,l2) )
276 { /*avoid redundant constraints*/
277 if (!resolve (el, ret) )
bb25bea6 278 {
279 constraint temp2;
280 temp2 = constraint_copy(el);
281 ret = constraintList_add (ret, temp2);
282 }
616915dd 283 }
d46ce6a4 284 constraint_free(temp);
616915dd 285 }
bb25bea6 286 end_constraintList_elements;
616915dd 287
bb25bea6 288 constraintList_elements (l2, el)
616915dd 289 {
290 temp = substitute (el, l1);
291
292 if (resolve (el, l1) || resolve(temp,l1) )
293 {
294 /*avoid redundant constraints*/
295 if (!resolve (el, ret) )
bb25bea6 296 {
297 constraint temp2;
298 temp2 = constraint_copy(el);
299 ret = constraintList_add (ret, temp2);
300 }
616915dd 301 }
d46ce6a4 302 constraint_free(temp);
616915dd 303 }
bb25bea6 304 end_constraintList_elements;
616915dd 305
306
307 return ret;
308}
309
310void
bb25bea6 311constraintList_free (/*@only@*/ constraintList s)
616915dd 312{
313 int i;
bb25bea6 314
315 llassert(constraintList_isDefined(s) );
316
317
616915dd 318 for (i = 0; i < s->nelements; i++)
319 {
bb25bea6 320 constraint_free (s->elements[i]);
616915dd 321 }
322
323 sfree (s->elements);
bb25bea6 324 s->elements = NULL;
325 s->nelements = -1;
326 s->nspace = -1;
616915dd 327 sfree (s);
bb25bea6 328 s = NULL;
616915dd 329}
330
331constraintList
332constraintList_copy (constraintList s)
333{
c3e695ff 334 constraintList ret = constraintList_makeNew ();
616915dd 335
bb25bea6 336 constraintList_elements (s, el)
616915dd 337 {
338 ret = constraintList_add (ret, constraint_copy (el));
bb25bea6 339 } end_constraintList_elements;
616915dd 340
341 return ret;
342}
343
344constraintList constraintList_preserveOrig (constraintList c)
345{
d46ce6a4 346 DPRINTF((message("constraintList_preserveOrig preserving the originial constraints for %s ", constraintList_print (c) ) ));
347
348 constraintList_elements_private (c, el)
616915dd 349 {
350 el = constraint_preserveOrig (el);
351 }
d46ce6a4 352 end_constraintList_elements_private;
616915dd 353 return c;
354}
355
4ab867d6 356constraintList constraintList_preserveCallInfo (/*@returned@*/ constraintList c, exprNode fcn)
357{
358 DPRINTF((message("constraintList_preserveOrig preserving the originial constraints for %s ", constraintList_print (c) ) ));
359
360 constraintList_elements_private (c, el)
361 {
362 // el = constraint_preserveOrig (el);
363 el = constraint_setFcnPre(el);
364 el = constraint_origAddGeneratingExpr (el, fcn);
365 }
366 end_constraintList_elements_private;
367 return c;
368}
369
370
371
9280addf 372constraintList constraintList_addGeneratingExpr (constraintList c, exprNode e)
373{
374 DPRINTF ((message ("entering constraintList_addGeneratingExpr for %s ", exprNode_unparse(e) ) ));
375
d46ce6a4 376 constraintList_elements_private (c, el)
9280addf 377 {
378 DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print(el), exprNode_unparse(e) ) ));
379 el = constraint_addGeneratingExpr (el, e);
380 }
d46ce6a4 381 end_constraintList_elements_private;
9280addf 382 return c;
383}
384
d46ce6a4 385/*@only@*/ constraintList constraintList_doFixResult (/*@only@*/constraintList postconditions, exprNode fcnCall)
616915dd 386{
387 constraintList ret;
c3e695ff 388 ret = constraintList_makeNew();
d46ce6a4 389 constraintList_elements_private (postconditions, el)
616915dd 390 {
391 ret = constraintList_add (ret, constraint_doFixResult (el, fcnCall) );
392 }
d46ce6a4 393 end_constraintList_elements_private;
616915dd 394
d46ce6a4 395 constraintList_free(postconditions);
616915dd 396 return ret;
397}
398
4ab867d6 399/*@only@*/ constraintList constraintList_doSRefFixConstraintParam (constraintList preconditions, exprNodeList arglist)
616915dd 400{
401 constraintList ret;
c3e695ff 402 ret = constraintList_makeNew();
616915dd 403
bb25bea6 404 constraintList_elements (preconditions, el)
616915dd 405 {
406 ret = constraintList_add(ret, constraint_doSRefFixConstraintParam (el, arglist) );
407 }
bb25bea6 408 end_constraintList_elements;
d46ce6a4 409
410 constraintList_free (preconditions);
616915dd 411
412 return ret;
413}
bb25bea6 414constraintList constraintList_doSRefFixBaseParam (/*@observer@*/ constraintList preconditions, /*@observer@*/
616915dd 415 exprNodeList arglist)
416{
417 constraintList ret;
bb25bea6 418 constraint temp;
c3e695ff 419 ret = constraintList_makeNew();
616915dd 420
bb25bea6 421 constraintList_elements (preconditions, el)
616915dd 422 {
bb25bea6 423 temp = constraint_copy(el);
424 ret = constraintList_add(ret, constraint_doSRefFixBaseParam (temp, arglist) );
616915dd 425 }
bb25bea6 426 end_constraintList_elements;
616915dd 427
428 return ret;
429}
430
431constraintList constraintList_togglePost (/*@returned@*/ constraintList c)
432{
d46ce6a4 433 constraintList_elements_private (c, el)
616915dd 434 {
84c9ffbf 435 el = constraint_togglePost(el);
2934b455 436 if (constraint_hasOrig(el) )
4ab867d6 437 {
2934b455 438 el = constraint_togglePostOrig (el);
4ab867d6 439 }
616915dd 440 }
d46ce6a4 441 end_constraintList_elements_private;
616915dd 442 return c;
443}
444
445
This page took 0.142236 seconds and 5 git commands to generate.