]>
Commit | Line | Data |
---|---|---|
d0e5b01f | 1 | /* |
4cccc6ad | 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 | /* | |
d0e5b01f | 25 | ** constraintList.c |
4cccc6ad | 26 | ** |
27 | ** based on list_template.c | |
28 | ** | |
29 | ** where T has T_equal (or change this) and T_unparse | |
d0e5b01f | 30 | */ |
31 | ||
d0e5b01f | 32 | # include "lclintMacros.nf" |
4cccc6ad | 33 | # include "llbasic.h" |
d0e5b01f | 34 | |
4cccc6ad | 35 | constraintList constraintList_new () |
36 | { | |
37 | constraintList s = (constraintList) dmalloc (sizeof (*s)); | |
d0e5b01f | 38 | |
4cccc6ad | 39 | s->nelements = 0; |
40 | s->nspace = constraintListBASESIZE; | |
41 | s->elements = (constraint *) | |
42 | dmalloc (sizeof (*s->elements) * constraintListBASESIZE); | |
d0e5b01f | 43 | |
4cccc6ad | 44 | return (s); |
d0e5b01f | 45 | } |
46 | ||
4cccc6ad | 47 | static void |
48 | constraintList_grow (constraintList s) | |
d0e5b01f | 49 | { |
d0e5b01f | 50 | int i; |
4cccc6ad | 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++) | |
d0e5b01f | 58 | { |
4cccc6ad | 59 | newelements[i] = s->elements[i]; |
d0e5b01f | 60 | } |
d0e5b01f | 61 | |
4cccc6ad | 62 | sfree (s->elements); |
63 | s->elements = newelements; | |
d0e5b01f | 64 | } |
65 | ||
361091cc | 66 | void constraintList_exprNodemerge() |
d0e5b01f | 67 | { |
d0e5b01f | 68 | } |
4cccc6ad | 69 | constraintList |
70 | constraintList_add (constraintList s, constraint el) | |
d0e5b01f | 71 | { |
754746a0 | 72 | if (resolve (el, s) ) |
73 | return s; | |
74 | ||
4cccc6ad | 75 | if (s->nspace <= 0) |
76 | constraintList_grow (s); | |
d0e5b01f | 77 | |
4cccc6ad | 78 | s->nspace--; |
79 | s->elements[s->nelements] = el; | |
80 | s->nelements++; | |
81 | return s; | |
82 | } | |
d0e5b01f | 83 | |
361091cc | 84 | constraintList constraintList_addList (constraintList s, constraintList new) |
85 | { | |
86 | constraintList_elements(new, elem) | |
87 | s = constraintList_add (s, elem); | |
88 | end_constraintList_elements | |
89 | return s; | |
90 | } | |
91 | ||
92 | cstring | |
93 | constraintList_print (constraintList s) | |
94 | { | |
95 | int i; | |
96 | cstring st = cstring_undefined; | |
97 | bool first = TRUE; | |
98 | ||
99 | if (s->nelements == 0) | |
100 | st = cstring_makeLiteral("<List Empty>"); | |
101 | ||
102 | for (i = 0; i < s->nelements; i++) | |
103 | { | |
104 | cstring type = cstring_undefined; | |
105 | constraint current = s->elements[i]; | |
106 | ||
107 | if (current != NULL) | |
108 | { | |
109 | cstring temp1 = constraint_print(current); | |
110 | type = message ("%q %q\n", type, temp1 ); | |
111 | } | |
112 | ||
113 | if (first) | |
114 | { | |
115 | st = type; | |
116 | first = FALSE; | |
117 | } | |
118 | else | |
119 | { | |
120 | st = message ("%q, %q", st, type); | |
121 | } | |
122 | } | |
123 | return st; | |
124 | } | |
4cccc6ad | 125 | |
bf92e32c | 126 | |
127 | cstring | |
128 | constraintList_printDetailed (constraintList s) | |
129 | { | |
130 | int i; | |
131 | cstring st = cstring_undefined; | |
132 | bool first = TRUE; | |
133 | ||
134 | if (s->nelements == 0) | |
135 | st = cstring_makeLiteral("<List Empty>"); | |
136 | ||
137 | for (i = 0; i < s->nelements; i++) | |
138 | { | |
139 | cstring type = cstring_undefined; | |
140 | constraint current = s->elements[i]; | |
141 | ||
142 | if (current != NULL) | |
143 | { | |
144 | cstring temp1 = constraint_printDetailed (current); | |
145 | type = message ("%s %s\n", type, temp1 ); | |
146 | } | |
147 | ||
148 | if (first) | |
149 | { | |
150 | st = type; | |
151 | first = FALSE; | |
152 | } | |
153 | else | |
154 | { | |
155 | st = message ("%s %s", st, type); | |
156 | } | |
157 | } | |
158 | return st; | |
159 | } | |
160 | ||
754746a0 | 161 | /*{ x: constraint | (x in l1 -> resolve (x, l2) || (x in l2 -> resolve (x, l1) |
162 | } */ | |
163 | ||
164 | constraintList | |
165 | constraintList_logicalOr (constraintList l1, constraintList l2) | |
166 | { | |
167 | constraint temp; | |
168 | constraintList ret; | |
169 | TPRINTF ( (message ("Logical of on %s and %s", | |
170 | constraintList_print(l1), | |
171 | constraintList_print(l2)) ) ); | |
172 | ||
173 | ret = constraintList_new(); | |
174 | constraintList_elements (l1, el) | |
175 | { | |
176 | temp = substitute (el, l2); | |
177 | ||
178 | if (resolve (el, l2) || resolve(temp,l2) ) | |
179 | { /*avoid redundant constraints*/ | |
180 | if (!resolve (el, ret) ) | |
181 | ret = constraintList_add (ret, el); | |
182 | } | |
183 | } | |
184 | end_constraintList_elements; | |
185 | ||
186 | constraintList_elements (l2, el) | |
187 | { | |
188 | temp = substitute (el, l1); | |
189 | ||
190 | if (resolve (el, l1) || resolve(temp,l1) ) | |
191 | { | |
192 | /*avoid redundant constraints*/ | |
193 | if (!resolve (el, ret) ) | |
194 | ret = constraintList_add (ret, el); | |
195 | } | |
196 | } | |
197 | end_constraintList_elements; | |
198 | ||
199 | ||
200 | return ret; | |
201 | } | |
202 | ||
4cccc6ad | 203 | void |
204 | constraintList_free (constraintList s) | |
d0e5b01f | 205 | { |
d0e5b01f | 206 | int i; |
4cccc6ad | 207 | for (i = 0; i < s->nelements; i++) |
d0e5b01f | 208 | { |
4cccc6ad | 209 | // constraint_free (s->elements[i]); |
d0e5b01f | 210 | } |
d0e5b01f | 211 | |
4cccc6ad | 212 | sfree (s->elements); |
213 | sfree (s); | |
d0e5b01f | 214 | } |
215 | ||
4cccc6ad | 216 | constraintList |
217 | constraintList_copy (constraintList s) | |
d0e5b01f | 218 | { |
4cccc6ad | 219 | constraintList ret = constraintList_new (); |
d0e5b01f | 220 | |
4cccc6ad | 221 | constraintList_elements (s, el) |
d0e5b01f | 222 | { |
4cccc6ad | 223 | ret = constraintList_add (ret, constraint_copy (el)); |
224 | } end_constraintList_elements; | |
d0e5b01f | 225 | |
4cccc6ad | 226 | return ret; |
d0e5b01f | 227 | } |
361091cc | 228 | |
bf92e32c | 229 | constraintList constraintList_preserveOrig (constraintList c) |
230 | { | |
231 | constraintList_elements (c, el); | |
232 | { | |
233 | el = constraint_preserveOrig (el); | |
234 | } | |
235 | end_constraintList_elements; | |
236 | return c; | |
237 | } |