2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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 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
27 ** based on list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "lclintMacros.nf"
35 constraintList constraintList_new ()
37 constraintList s = (constraintList) dmalloc (sizeof (*s));
40 s->nspace = constraintListBASESIZE;
41 s->elements = (constraint *)
42 dmalloc (sizeof (*s->elements) * constraintListBASESIZE);
48 constraintList_grow (constraintList s)
51 constraint *newelements;
53 s->nspace += constraintListBASESIZE;
54 newelements = (constraint *) dmalloc (sizeof (*newelements)
55 * (s->nelements + s->nspace));
57 for (i = 0; i < s->nelements; i++)
59 newelements[i] = s->elements[i];
63 s->elements = newelements;
66 /* void constraintList_exprNodemerge(void) */
70 constraintList_add (constraintList s, constraint el)
72 el = constraint_simplify (el);
77 constraintList_grow (s);
80 s->elements[s->nelements] = el;
85 constraintList constraintList_addList (constraintList s, constraintList new)
90 if (new == constraintList_undefined)
93 constraintList_elements(new, elem)
95 s = constraintList_add (s, elem);
97 end_constraintList_elements
102 constraintList_print (constraintList s) /*@*/
105 cstring st = cstring_undefined;
108 if (s->nelements == 0)
109 st = cstring_makeLiteral("<List Empty>");
111 for (i = 0; i < s->nelements; i++)
113 cstring type = cstring_undefined;
114 constraint current = s->elements[i];
119 if ( context_getFlag (FLG_ORCONSTRAINT) )
120 temp1 = constraint_printOr(current);
122 temp1 = constraint_print(current);
123 type = message ("%q %q\n", type, temp1 );
133 st = message ("%q, %q", st, type);
139 void constraintList_printError (constraintList s, fileloc loc)
142 constraintList_elements (s, elem)
146 constraint_printError (elem, loc);
149 end_constraintList_elements;
154 constraintList_printDetailed (constraintList s)
157 cstring st = cstring_undefined;
160 if (s->nelements == 0)
161 st = cstring_makeLiteral("<List Empty>");
163 for (i = 0; i < s->nelements; i++)
165 cstring type = cstring_undefined;
166 constraint current = s->elements[i];
170 cstring temp1 = constraint_printDetailed (current);
171 type = message ("%s %s\n", type, temp1 );
181 st = message ("%s %s", st, type);
187 /*{ x: constraint | (x in l1 -> resolve (x, l2) || (x in l2 -> resolve (x, l1)
191 constraintList_logicalOr (constraintList l1, constraintList l2)
195 DPRINTF ( (message ("Logical of on %s and %s",
196 constraintList_print(l1),
197 constraintList_print(l2)) ) );
199 ret = constraintList_new();
200 constraintList_elements (l1, el)
202 temp = substitute (el, l2);
204 if (resolve (el, l2) || resolve(temp,l2) )
205 { /*avoid redundant constraints*/
206 if (!resolve (el, ret) )
207 ret = constraintList_add (ret, el);
210 end_constraintList_elements;
212 constraintList_elements (l2, el)
214 temp = substitute (el, l1);
216 if (resolve (el, l1) || resolve(temp,l1) )
218 /*avoid redundant constraints*/
219 if (!resolve (el, ret) )
220 ret = constraintList_add (ret, el);
223 end_constraintList_elements;
230 constraintList_free (constraintList s)
233 for (i = 0; i < s->nelements; i++)
235 // constraint_free (s->elements[i]);
243 constraintList_copy (constraintList s)
245 constraintList ret = constraintList_new ();
247 constraintList_elements (s, el)
249 ret = constraintList_add (ret, constraint_copy (el));
250 } end_constraintList_elements;
255 constraintList constraintList_preserveOrig (constraintList c)
257 constraintList_elements (c, el)
259 el = constraint_preserveOrig (el);
261 end_constraintList_elements;
265 constraintList constraintList_addGeneratingExpr (constraintList c, exprNode e)
267 DPRINTF ((message ("entering constraintList_addGeneratingExpr for %s ", exprNode_unparse(e) ) ));
269 constraintList_elements (c, el)
271 DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print(el), exprNode_unparse(e) ) ));
272 el = constraint_addGeneratingExpr (el, e);
274 end_constraintList_elements;
278 constraintList constraintList_doFixResult (constraintList postconditions, exprNode fcnCall)
281 ret = constraintList_new();
282 constraintList_elements (postconditions, el)
284 ret = constraintList_add (ret, constraint_doFixResult (el, fcnCall) );
286 end_constraintList_elements;
291 constraintList constraintList_doSRefFixConstraintParam (constraintList preconditions, exprNodeList arglist)
294 ret = constraintList_new();
296 constraintList_elements (preconditions, el)
298 ret = constraintList_add(ret, constraint_doSRefFixConstraintParam (el, arglist) );
300 end_constraintList_elements;
304 constraintList constraintList_doSRefFixBaseParam (constraintList preconditions,
305 exprNodeList arglist)
308 ret = constraintList_new();
310 constraintList_elements (preconditions, el)
312 ret = constraintList_add(ret, constraint_doSRefFixBaseParam (el, arglist) );
314 end_constraintList_elements;
319 constraintList constraintList_togglePost (/*@returned@*/ constraintList c)
321 constraintList_elements (c, el)
323 el->post = !el->post;
325 end_constraintList_elements;