]> andersk Git - splint.git/blob - src/constraintList.c
Prewinter break editing commit.
[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_new ()
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 void constraintList_exprNodemerge()
67 {
68 }
69 constraintList 
70 constraintList_add (constraintList s, constraint el)
71 {
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 = constraint_print(current);
118           type = message ("%q %q\n", type, temp1 );
119         }
120
121       if (first)
122         {
123           st = type;
124           first = FALSE;
125         }
126       else
127         {
128           st = message ("%q, %q", st, type);
129         }
130     }
131   return st;
132 }
133
134 void constraintList_printError (constraintList s, fileloc loc)
135 {
136
137   int i;
138   cstring st = cstring_undefined;
139   bool first = TRUE;
140
141   if (s->nelements == 0)
142     {
143       return;
144     }
145   
146   for (i = 0; i < s->nelements; i++)
147     {
148       constraint current = s->elements[i];
149
150       if (current != NULL)
151         {
152           constraint_printError (current,loc);
153         }
154     }
155   return;
156 }
157
158 cstring
159 constraintList_printDetailed (constraintList s)
160 {
161   int i;
162   cstring st = cstring_undefined;
163   bool first = TRUE;
164
165   if (s->nelements == 0)
166     st = cstring_makeLiteral("<List Empty>");
167   
168   for (i = 0; i < s->nelements; i++)
169     {
170       cstring type = cstring_undefined;
171       constraint current = s->elements[i];
172
173       if (current != NULL)
174         {
175           cstring temp1 = constraint_printDetailed (current);
176           type = message ("%s %s\n", type, temp1 );
177         }
178
179       if (first)
180         {
181           st = type;
182           first = FALSE;
183         }
184       else
185         {
186           st = message ("%s %s", st, type);
187         }
188     }
189   return st;
190 }
191
192 /*{ x: constraint | (x in l1 -> resolve (x, l2) || (x in l2 -> resolve (x, l1)
193 } */
194
195 constraintList
196 constraintList_logicalOr (constraintList l1, constraintList l2)
197 {
198   constraint temp;
199   constraintList ret;
200   DPRINTF ( (message ("Logical of on %s and %s",
201                       constraintList_print(l1), 
202                       constraintList_print(l2)) ) );
203   
204   ret = constraintList_new();
205   constraintList_elements (l1, el)
206     {
207       temp = substitute (el, l2);
208       
209       if (resolve (el, l2) || resolve(temp,l2) )
210         {   /*avoid redundant constraints*/
211           if (!resolve (el, ret) )
212             ret = constraintList_add (ret, el);
213         }
214     }
215   end_constraintList_elements;
216
217    constraintList_elements (l2, el)
218     {
219       temp = substitute (el, l1);
220       
221       if (resolve (el, l1) || resolve(temp,l1) )
222         {
223           /*avoid redundant constraints*/
224           if (!resolve (el, ret) )
225             ret = constraintList_add (ret, el);
226         }
227     }
228   end_constraintList_elements;
229
230   
231   return ret;
232 }
233
234 void
235 constraintList_free (constraintList s)
236 {
237   int i;
238   for (i = 0; i < s->nelements; i++)
239     {
240       //      constraint_free (s->elements[i]); 
241     }
242
243   sfree (s->elements);
244   sfree (s);
245 }
246
247 constraintList
248 constraintList_copy (constraintList s)
249 {
250   constraintList ret = constraintList_new ();
251
252   constraintList_elements (s, el)
253     {
254       ret = constraintList_add (ret, constraint_copy (el));
255     } end_constraintList_elements;
256
257   return ret;
258 }
259
260 constraintList constraintList_preserveOrig (constraintList c)
261 {
262   constraintList_elements (c, el)
263   {
264     el = constraint_preserveOrig (el);
265   }
266   end_constraintList_elements;
267   return c;
268 }
269
270
271 constraintList constraintList_doSRefFixBaseParam (constraintList preconditions,
272                                                    exprNodeList arglist)
273 {
274   constraintList ret;
275   ret = constraintList_new();
276
277   constraintList_elements (preconditions, el)
278     {
279       ret = constraintList_add(ret, constraint_doSRefFixBaseParam (el, arglist) );
280     }
281   end_constraintList_elements;
282
283   return ret;
284 }
285
286
287
This page took 0.088043 seconds and 5 git commands to generate.