]> andersk Git - splint.git/blob - src/constraintList.c
Updteing for cert move
[splint.git] / src / constraintList.c
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
35 constraintList constraintList_makeNew ()
36 {
37   constraintList s = (constraintList) dmalloc (sizeof (*s));
38
39   s->nelements = 0;
40   s->nspace = constraintListBASESIZE;
41   s->elements = (constraint *)
42     dmalloc (sizeof (*s->elements) * constraintListBASESIZE);
43
44   return (s);
45 }
46
47 static void
48 constraintList_grow (constraintList s)
49 {
50   int i;
51   constraint *newelements; 
52
53   s->nspace += constraintListBASESIZE;
54   newelements = (constraint *) dmalloc (sizeof (*newelements)
55                                      * (s->nelements + s->nspace));
56
57   for (i = 0; i < s->nelements; i++)
58     {
59       newelements[i] = s->elements[i]; 
60     }
61
62   sfree (s->elements); 
63   s->elements = newelements;
64 }
65
66
67 constraintList 
68 constraintList_add (constraintList s, constraint el)
69 {
70   /*drl7x */
71   //   el = constraint_simplify (el);
72   if (resolve (el, s) )
73     return s;
74   
75   if (s->nspace <= 0)
76     constraintList_grow (s);
77
78   s->nspace--;
79   s->elements[s->nelements] = el;
80   s->nelements++;
81   return s;
82 }
83
84 constraintList constraintList_addList (constraintList s, constraintList new)
85 {
86   llassert(s);
87   llassert(new);
88
89   if (new == constraintList_undefined)
90     return s;
91   
92   constraintList_elements(new, elem)
93     {
94     s = constraintList_add (s, elem);
95     }
96   end_constraintList_elements
97     return s;
98 }
99
100 cstring
101 constraintList_print (constraintList s) /*@*/
102 {
103   int i;
104   cstring st = cstring_undefined;
105   bool first = TRUE;
106
107   if (s->nelements == 0)
108     st = cstring_makeLiteral("<List Empty>");
109   
110   for (i = 0; i < s->nelements; i++)
111     {
112       cstring type = cstring_undefined;
113       constraint current = s->elements[i];
114
115       if (current != NULL)
116         {
117           cstring temp1;
118             if ( context_getFlag (FLG_ORCONSTRAINT) )
119               temp1 = constraint_printOr(current);
120             else
121               temp1 = constraint_print(current);
122           type = message ("%q %q\n", type, temp1 );
123         }
124
125       if (first)
126         {
127           st = type;
128           first = FALSE;
129         }
130       else
131         {
132           st = message ("%q, %q", st, type);
133         }
134     }
135   return st;
136 }
137
138 void constraintList_printError (constraintList s, fileloc loc)
139 {
140
141   constraintList_elements (s, elem)
142     {
143       if (elem != NULL)
144         {
145           constraint_printError (elem, loc);
146         }
147     }
148   end_constraintList_elements;
149   return;
150 }
151
152 cstring
153 constraintList_printDetailed (constraintList s)
154 {
155   int i;
156   cstring st = cstring_undefined;
157   bool first = TRUE;
158
159   if (s->nelements == 0)
160     st = cstring_makeLiteral("<List Empty>");
161   
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         {
169           cstring temp1 = constraint_printDetailed (current);
170           type = message ("%s %s\n", type, temp1 );
171         }
172
173       if (first)
174         {
175           st = type;
176           first = FALSE;
177         }
178       else
179         {
180           st = message ("%s %s", st, type);
181         }
182     }
183   return st;
184 }
185
186 /*{ x: constraint | (x in l1 -> resolve (x, l2) || (x in l2 -> resolve (x, l1)
187 } */
188
189 constraintList
190 constraintList_logicalOr (constraintList l1, constraintList l2)
191 {
192   constraint temp;
193   constraintList ret;
194   DPRINTF ( (message ("Logical of on %s and %s",
195                       constraintList_print(l1), 
196                       constraintList_print(l2)) ) );
197   
198   ret = constraintList_makeNew();
199   constraintList_elements (l1, el)
200     {
201       temp = substitute (el, l2);
202       
203       if (resolve (el, l2) || resolve(temp,l2) )
204         {   /*avoid redundant constraints*/
205           if (!resolve (el, ret) )
206             ret = constraintList_add (ret, el);
207         }
208     }
209   end_constraintList_elements;
210
211    constraintList_elements (l2, el)
212     {
213       temp = substitute (el, l1);
214       
215       if (resolve (el, l1) || resolve(temp,l1) )
216         {
217           /*avoid redundant constraints*/
218           if (!resolve (el, ret) )
219             ret = constraintList_add (ret, el);
220         }
221     }
222   end_constraintList_elements;
223
224   
225   return ret;
226 }
227
228 void
229 constraintList_free (constraintList s)
230 {
231   int i;
232   for (i = 0; i < s->nelements; i++)
233     {
234       //      constraint_free (s->elements[i]); 
235     }
236
237   sfree (s->elements);
238   sfree (s);
239 }
240
241 constraintList
242 constraintList_copy (constraintList s)
243 {
244   constraintList ret = constraintList_makeNew ();
245
246   constraintList_elements (s, el)
247     {
248       ret = constraintList_add (ret, constraint_copy (el));
249     } end_constraintList_elements;
250
251   return ret;
252 }
253
254 constraintList constraintList_preserveOrig (constraintList c)
255 {
256   constraintList_elements (c, el)
257   {
258     el = constraint_preserveOrig (el);
259   }
260   end_constraintList_elements;
261   return c;
262 }
263
264 constraintList constraintList_addGeneratingExpr (constraintList c, exprNode e)
265 {
266   DPRINTF ((message ("entering constraintList_addGeneratingExpr for %s ", exprNode_unparse(e) ) ));
267   
268   constraintList_elements (c, el)
269   {
270     DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print(el), exprNode_unparse(e) )  ));
271     el = constraint_addGeneratingExpr (el, e);
272   }
273   end_constraintList_elements;
274   return c;
275 }
276
277 constraintList constraintList_doFixResult (constraintList postconditions, exprNode fcnCall)
278 {
279   constraintList ret;
280   ret = constraintList_makeNew();
281   constraintList_elements (postconditions, el)
282     {
283       ret = constraintList_add (ret, constraint_doFixResult (el, fcnCall) );
284     }
285   end_constraintList_elements;
286
287   return ret;
288 }
289
290 constraintList constraintList_doSRefFixConstraintParam (constraintList preconditions, exprNodeList arglist)
291 {
292   constraintList ret;
293   ret = constraintList_makeNew();
294
295   constraintList_elements (preconditions, el)
296     {
297       ret = constraintList_add(ret, constraint_doSRefFixConstraintParam (el, arglist) );
298     }
299   end_constraintList_elements;
300
301   return ret;
302 }
303 constraintList constraintList_doSRefFixBaseParam (constraintList preconditions,
304                                                    exprNodeList arglist)
305 {
306   constraintList ret;
307   ret = constraintList_makeNew();
308
309   constraintList_elements (preconditions, el)
310     {
311       ret = constraintList_add(ret, constraint_doSRefFixBaseParam (el, arglist) );
312     }
313   end_constraintList_elements;
314
315   return ret;
316 }
317
318 constraintList constraintList_togglePost (/*@returned@*/ constraintList c)
319 {
320   constraintList_elements (c, el)
321     {
322       el->post = !el->post;
323     }
324   end_constraintList_elements;
325   return c;
326 }
327
328
This page took 0.060502 seconds and 5 git commands to generate.