]> andersk Git - splint.git/blob - src/constraintList.c
If checking mostly works. Boolean expression are handled.
[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     s = constraintList_add (s, elem);
94   end_constraintList_elements
95     return s;
96 }
97
98 cstring
99 constraintList_print (constraintList s)
100 {
101   int i;
102   cstring st = cstring_undefined;
103   bool first = TRUE;
104
105   if (s->nelements == 0)
106     st = cstring_makeLiteral("<List Empty>");
107   
108   for (i = 0; i < s->nelements; i++)
109     {
110       cstring type = cstring_undefined;
111       constraint current = s->elements[i];
112
113       if (current != NULL)
114         {
115           cstring temp1 = constraint_print(current);
116           type = message ("%q %q\n", type, temp1 );
117         }
118
119       if (first)
120         {
121           st = type;
122           first = FALSE;
123         }
124       else
125         {
126           st = message ("%q, %q", st, type);
127         }
128     }
129   return st;
130 }
131
132
133 cstring
134 constraintList_printDetailed (constraintList s)
135 {
136   int i;
137   cstring st = cstring_undefined;
138   bool first = TRUE;
139
140   if (s->nelements == 0)
141     st = cstring_makeLiteral("<List Empty>");
142   
143   for (i = 0; i < s->nelements; i++)
144     {
145       cstring type = cstring_undefined;
146       constraint current = s->elements[i];
147
148       if (current != NULL)
149         {
150           cstring temp1 = constraint_printDetailed (current);
151           type = message ("%s %s\n", type, temp1 );
152         }
153
154       if (first)
155         {
156           st = type;
157           first = FALSE;
158         }
159       else
160         {
161           st = message ("%s %s", st, type);
162         }
163     }
164   return st;
165 }
166
167 /*{ x: constraint | (x in l1 -> resolve (x, l2) || (x in l2 -> resolve (x, l1)
168 } */
169
170 constraintList
171 constraintList_logicalOr (constraintList l1, constraintList l2)
172 {
173   constraint temp;
174   constraintList ret;
175   DPRINTF ( (message ("Logical of on %s and %s",
176                       constraintList_print(l1), 
177                       constraintList_print(l2)) ) );
178   
179   ret = constraintList_new();
180   constraintList_elements (l1, el)
181     {
182       temp = substitute (el, l2);
183       
184       if (resolve (el, l2) || resolve(temp,l2) )
185         {   /*avoid redundant constraints*/
186           if (!resolve (el, ret) )
187             ret = constraintList_add (ret, el);
188         }
189     }
190   end_constraintList_elements;
191
192    constraintList_elements (l2, el)
193     {
194       temp = substitute (el, l1);
195       
196       if (resolve (el, l1) || resolve(temp,l1) )
197         {
198           /*avoid redundant constraints*/
199           if (!resolve (el, ret) )
200             ret = constraintList_add (ret, el);
201         }
202     }
203   end_constraintList_elements;
204
205   
206   return ret;
207 }
208
209 void
210 constraintList_free (constraintList s)
211 {
212   int i;
213   for (i = 0; i < s->nelements; i++)
214     {
215       //      constraint_free (s->elements[i]); 
216     }
217
218   sfree (s->elements);
219   sfree (s);
220 }
221
222 constraintList
223 constraintList_copy (constraintList s)
224 {
225   constraintList ret = constraintList_new ();
226
227   constraintList_elements (s, el)
228     {
229       ret = constraintList_add (ret, constraint_copy (el));
230     } end_constraintList_elements;
231
232   return ret;
233 }
234
235 constraintList constraintList_preserveOrig (constraintList c)
236 {
237   constraintList_elements (c, el);
238   {
239     el = constraint_preserveOrig (el);
240   }
241   end_constraintList_elements;
242   return c;
243 }
244
245
246 constraintList constraintList_doSRefFixBaseParam (constraintList preconditions,
247                                                    exprNodeList arglist)
248 {
249   constraintList ret;
250   ret = constraintList_new();
251
252   constraintList_elements (preconditions, el)
253     {
254       ret = constraintList_add(ret, constraint_doSRefFixBaseParam (el, arglist) );
255     }
256   end_constraintList_elements;
257
258   return ret;
259 }
260
261
262
This page took 0.065131 seconds and 5 git commands to generate.