]>
Commit | Line | Data |
---|---|---|
616915dd | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
616915dd | 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 | ** | |
1b8ae690 | 20 | ** For information on splint: splint@cs.virginia.edu |
21 | ** To report a bug: splint-bug@cs.virginia.edu | |
11db3170 | 22 | ** For more information: http://www.splint.org |
616915dd | 23 | */ |
65f973be | 24 | |
616915dd | 25 | /* |
26 | ** constraintList.c | |
27 | ** | |
28 | ** based on list_template.c | |
29 | ** | |
30 | ** where T has T_equal (or change this) and T_unparse | |
31 | */ | |
32 | ||
1b8ae690 | 33 | # include "splintMacros.nf" |
616915dd | 34 | # include "llbasic.h" |
35 | ||
d46ce6a4 | 36 | |
28bf4b0b | 37 | /*@iter constraintList_elements_private_only (sef constraintList x, yield only constraint el); @*/ |
38 | # define constraintList_elements_private_only(x, m_el) \ | |
60eced23 | 39 | { if (constraintList_isDefined (x)) { int m_ind; constraint *m_elements = &((x)->elements[0]); \ |
28bf4b0b | 40 | for (m_ind = 0 ; m_ind < (x)->nelements; m_ind++) \ |
41 | { constraint m_el = *(m_elements++); | |
42 | ||
60eced23 | 43 | # define end_constraintList_elements_private_only }}} |
28bf4b0b | 44 | |
45 | ||
60eced23 | 46 | /*@iter constraintList_elements_private (sef constraintList x, yield constraint el); @*/ |
d46ce6a4 | 47 | # define constraintList_elements_private(x, m_el) \ |
60eced23 | 48 | { if (constraintList_isDefined (x)) { int m_ind; constraint *m_elements = &((x)->elements[0]); \ |
d46ce6a4 | 49 | for (m_ind = 0 ; m_ind < (x)->nelements; m_ind++) \ |
50 | { constraint m_el = *(m_elements++); | |
51 | ||
60eced23 | 52 | # define end_constraintList_elements_private }}} |
d46ce6a4 | 53 | |
54 | ||
03d670b6 | 55 | /*@only@*/ constraintList constraintList_makeNew () |
616915dd | 56 | { |
57 | constraintList s = (constraintList) dmalloc (sizeof (*s)); | |
58 | ||
59 | s->nelements = 0; | |
60 | s->nspace = constraintListBASESIZE; | |
61 | s->elements = (constraint *) | |
62 | dmalloc (sizeof (*s->elements) * constraintListBASESIZE); | |
63 | ||
64 | return (s); | |
65 | } | |
66 | ||
67 | static void | |
68 | constraintList_grow (constraintList s) | |
69 | { | |
70 | int i; | |
71 | constraint *newelements; | |
72 | ||
60eced23 | 73 | llassert (constraintList_isDefined (s)); |
74 | ||
616915dd | 75 | s->nspace += constraintListBASESIZE; |
76 | newelements = (constraint *) dmalloc (sizeof (*newelements) | |
77 | * (s->nelements + s->nspace)); | |
78 | ||
79 | for (i = 0; i < s->nelements; i++) | |
80 | { | |
81 | newelements[i] = s->elements[i]; | |
82 | } | |
83 | ||
84 | sfree (s->elements); | |
85 | s->elements = newelements; | |
86 | } | |
87 | ||
c3e695ff | 88 | |
616915dd | 89 | constraintList |
bb25bea6 | 90 | constraintList_add (/*@returned@*/ constraintList s, /*@only@*/ constraint el) |
616915dd | 91 | { |
60eced23 | 92 | llassert (constraintList_isDefined (s)); |
93 | ||
c3e695ff | 94 | /*drl7x */ |
b7b694d6 | 95 | |
28bf4b0b | 96 | if (constraintList_resolve (el, s) ) |
d46ce6a4 | 97 | { |
98 | constraint_free (el); | |
99 | return s; | |
100 | } | |
616915dd | 101 | |
102 | if (s->nspace <= 0) | |
103 | constraintList_grow (s); | |
104 | ||
105 | s->nspace--; | |
106 | s->elements[s->nelements] = el; | |
107 | s->nelements++; | |
108 | return s; | |
109 | } | |
110 | ||
d46ce6a4 | 111 | /* frees everything but actual constraints */ |
112 | /* This function should only be used if you have | |
113 | other references to unshared constraints | |
114 | */ | |
115 | static void constraintList_freeShallow (/*@only@*/ constraintList c) | |
116 | { | |
117 | if (constraintList_isDefined(c) ) | |
bb25bea6 | 118 | { |
119 | free (c->elements); | |
120 | c->elements = NULL; | |
121 | c->nelements = -1; | |
122 | c->nspace = -1; | |
123 | } | |
d46ce6a4 | 124 | free (c); |
bb25bea6 | 125 | c = NULL; |
126 | } | |
127 | ||
28bf4b0b | 128 | /*@only@*/ constraintList constraintList_addList (/*@only@*/ /*@returned@*/ constraintList s, /*@observer@*/ constraintList newList) |
bb25bea6 | 129 | { |
130 | llassert(constraintList_isDefined(s) ); | |
28bf4b0b | 131 | llassert(constraintList_isDefined(newList) ); |
bb25bea6 | 132 | |
28bf4b0b | 133 | if (newList == constraintList_undefined) |
bb25bea6 | 134 | return s; |
135 | ||
28bf4b0b | 136 | constraintList_elements (newList, elem) |
bb25bea6 | 137 | { |
138 | s = constraintList_add (s, constraint_copy(elem) ); | |
139 | } | |
140 | end_constraintList_elements; | |
141 | ||
142 | return s; | |
d46ce6a4 | 143 | } |
144 | ||
28bf4b0b | 145 | constraintList constraintList_addListFree (/*@returned@*/ constraintList s, /*@only@*/ constraintList newList) |
616915dd | 146 | { |
84c9ffbf | 147 | llassert(constraintList_isDefined(s) ); |
28bf4b0b | 148 | llassert(constraintList_isDefined(newList) ); |
616915dd | 149 | |
28bf4b0b | 150 | if (constraintList_isUndefined(newList) ) |
616915dd | 151 | return s; |
152 | ||
28bf4b0b | 153 | constraintList_elements_private_only(newList, elem) |
616915dd | 154 | { |
155 | s = constraintList_add (s, elem); | |
156 | } | |
28bf4b0b | 157 | end_constraintList_elements_private_only |
d46ce6a4 | 158 | |
28bf4b0b | 159 | constraintList_freeShallow(newList); |
616915dd | 160 | return s; |
161 | } | |
162 | ||
920a3797 | 163 | |
7edb30e6 | 164 | constraintList constraintList_removeSurpressed (/*@only@*/ constraintList s) |
165 | { | |
166 | constraintList ret; | |
167 | fileloc loc; | |
168 | llassert(constraintList_isDefined(s) ); | |
169 | ||
170 | ret = constraintList_makeNew(); | |
171 | ||
172 | constraintList_elements_private_only(s, elem) | |
173 | { | |
174 | loc = constraint_getFileloc(elem); | |
175 | ||
bb7c2085 | 176 | if (fileloc_isUndefined(loc)) |
7edb30e6 | 177 | { |
178 | ret = constraintList_add (ret, elem); | |
179 | } | |
180 | ||
bb7c2085 | 181 | else if (context_suppressFlagMsg(FLG_BOUNDSWRITE, loc) ) |
7edb30e6 | 182 | { |
bb7c2085 | 183 | DPRINTF ((message ("constraintList_removeSurpressed getting rid of surpressed constraint %q", |
184 | constraint_print(elem)))); | |
7edb30e6 | 185 | constraint_free(elem); |
186 | } | |
187 | ||
bb7c2085 | 188 | else if (!constraint_hasMaxSet(elem) && context_suppressFlagMsg(FLG_BOUNDSREAD, loc)) |
7edb30e6 | 189 | { |
bb7c2085 | 190 | DPRINTF ((message("constraintList_removeSurpressed getting rid of surpressed constraint %q", |
191 | constraint_print(elem)))); | |
7edb30e6 | 192 | constraint_free(elem); |
193 | } | |
194 | else | |
195 | { | |
196 | ret = constraintList_add (ret, elem); | |
197 | } | |
198 | fileloc_free(loc); | |
199 | } | |
200 | end_constraintList_elements_private_only; | |
201 | ||
202 | constraintList_freeShallow(s); | |
203 | ||
204 | return ret; | |
205 | } | |
206 | ||
207 | ||
920a3797 | 208 | extern /*@only@*/ cstring constraintList_unparse ( /*@observer@*/ constraintList s) /*@*/ |
209 | { | |
210 | return (constraintList_print(s)); | |
920a3797 | 211 | } |
212 | ||
15b3d2b2 | 213 | # if 0 |
f4ec8018 | 214 | static /*@only@*/ cstring |
215 | constraintList_printLocation (/*@temp@*/ constraintList s) /*@*/ | |
216 | { | |
217 | int i; | |
218 | cstring st = cstring_undefined; | |
219 | bool first = TRUE; | |
220 | ||
221 | if (!constraintList_isDefined (s)) | |
222 | { | |
223 | return cstring_makeLiteral ("<undefined>"); | |
224 | } | |
225 | ||
226 | if (s->nelements == 0) | |
227 | { | |
228 | st = cstring_makeLiteral("<List Empty>"); | |
229 | return st; | |
230 | } | |
231 | ||
232 | for (i = 0; i < s->nelements; i++) | |
233 | { | |
234 | cstring type = cstring_undefined; | |
235 | constraint current = s->elements[i]; | |
236 | ||
237 | if (constraint_isDefined(current) ) | |
238 | { | |
239 | cstring temp1; | |
240 | temp1 = constraint_printLocation(current); | |
241 | type = message ("%q %q\n", type, temp1 ); | |
242 | } | |
243 | ||
244 | if (first) | |
245 | { | |
246 | st = type; | |
247 | first = FALSE; | |
248 | } | |
249 | else | |
250 | { | |
251 | st = message ("%q, %q", st, type); | |
252 | } | |
b7b694d6 | 253 | } |
f4ec8018 | 254 | |
255 | return st; | |
256 | } | |
15b3d2b2 | 257 | # endif |
f4ec8018 | 258 | |
920a3797 | 259 | /*@only@*/ cstring |
28bf4b0b | 260 | constraintList_print (/*@temp@*/ constraintList s) /*@*/ |
616915dd | 261 | { |
262 | int i; | |
263 | cstring st = cstring_undefined; | |
264 | bool first = TRUE; | |
60eced23 | 265 | |
266 | if (!constraintList_isDefined (s)) | |
267 | { | |
268 | return cstring_makeLiteral ("<undefined>"); | |
269 | } | |
616915dd | 270 | |
271 | if (s->nelements == 0) | |
d46ce6a4 | 272 | { |
273 | st = cstring_makeLiteral("<List Empty>"); | |
274 | return st; | |
275 | } | |
276 | ||
616915dd | 277 | for (i = 0; i < s->nelements; i++) |
278 | { | |
279 | cstring type = cstring_undefined; | |
280 | constraint current = s->elements[i]; | |
281 | ||
28bf4b0b | 282 | if (constraint_isDefined(current) ) |
616915dd | 283 | { |
90bc41f7 | 284 | cstring temp1; |
285 | if ( context_getFlag (FLG_ORCONSTRAINT) ) | |
286 | temp1 = constraint_printOr(current); | |
287 | else | |
288 | temp1 = constraint_print(current); | |
616915dd | 289 | type = message ("%q %q\n", type, temp1 ); |
290 | } | |
291 | ||
292 | if (first) | |
293 | { | |
294 | st = type; | |
295 | first = FALSE; | |
296 | } | |
297 | else | |
298 | { | |
299 | st = message ("%q, %q", st, type); | |
300 | } | |
b7b694d6 | 301 | } |
d46ce6a4 | 302 | |
616915dd | 303 | return st; |
304 | } | |
305 | ||
8f299805 | 306 | void constraintList_printErrorPostConditions (constraintList s, fileloc loc) |
307 | { | |
308 | ||
309 | constraintList_elements (s, elem) | |
310 | { | |
28bf4b0b | 311 | if (constraint_isDefined(elem)) |
8f299805 | 312 | { |
313 | constraint_printErrorPostCondition (elem, loc); | |
314 | } | |
315 | } | |
316 | end_constraintList_elements; | |
317 | return; | |
318 | } | |
319 | ||
616915dd | 320 | void constraintList_printError (constraintList s, fileloc loc) |
321 | { | |
322 | ||
bb25bea6 | 323 | constraintList_elements (s, elem) |
616915dd | 324 | { |
28bf4b0b | 325 | if (constraint_isDefined(elem) ) |
616915dd | 326 | { |
84380658 | 327 | if (constraint_isPost(elem) ) |
328 | constraint_printErrorPostCondition (elem, loc); | |
329 | else | |
330 | constraint_printError (elem, loc); | |
616915dd | 331 | } |
332 | } | |
bb25bea6 | 333 | end_constraintList_elements; |
616915dd | 334 | return; |
335 | } | |
336 | ||
8f299805 | 337 | |
616915dd | 338 | cstring |
339 | constraintList_printDetailed (constraintList s) | |
340 | { | |
341 | int i; | |
342 | cstring st = cstring_undefined; | |
343 | bool first = TRUE; | |
344 | ||
60eced23 | 345 | if (!constraintList_isDefined (s)) |
346 | { | |
347 | return cstring_makeLiteral ("<undefined>"); | |
348 | } | |
349 | ||
616915dd | 350 | if (s->nelements == 0) |
d46ce6a4 | 351 | { |
352 | st = cstring_makeLiteral("<List Empty>"); | |
353 | return st; | |
354 | } | |
355 | ||
616915dd | 356 | for (i = 0; i < s->nelements; i++) |
357 | { | |
358 | cstring type = cstring_undefined; | |
359 | constraint current = s->elements[i]; | |
360 | ||
28bf4b0b | 361 | if (constraint_isDefined(current ) ) |
616915dd | 362 | { |
363 | cstring temp1 = constraint_printDetailed (current); | |
364 | type = message ("%s %s\n", type, temp1 ); | |
d46ce6a4 | 365 | cstring_free(temp1); |
616915dd | 366 | } |
367 | ||
368 | if (first) | |
369 | { | |
370 | st = type; | |
371 | first = FALSE; | |
920a3797 | 372 | type = NULL; |
616915dd | 373 | } |
374 | else | |
375 | { | |
920a3797 | 376 | st = message ("%q %q", st, type); |
616915dd | 377 | } |
378 | } | |
379 | return st; | |
380 | } | |
381 | ||
382 | /*{ x: constraint | (x in l1 -> resolve (x, l2) || (x in l2 -> resolve (x, l1) | |
383 | } */ | |
384 | ||
385 | constraintList | |
bb25bea6 | 386 | constraintList_logicalOr (/*@observer@*/ constraintList l1, /*@observer@*/ constraintList l2) |
616915dd | 387 | { |
388 | constraint temp; | |
389 | constraintList ret; | |
bb7c2085 | 390 | DPRINTF ((message ("Logical or on %s and %s", |
616915dd | 391 | constraintList_print(l1), |
392 | constraintList_print(l2)) ) ); | |
393 | ||
c3e695ff | 394 | ret = constraintList_makeNew(); |
bb25bea6 | 395 | constraintList_elements (l1, el) |
616915dd | 396 | { |
28bf4b0b | 397 | temp = constraint_substitute (el, l2); |
616915dd | 398 | |
28bf4b0b | 399 | if (constraintList_resolve (el, l2) || constraintList_resolve(temp,l2) ) |
616915dd | 400 | { /*avoid redundant constraints*/ |
28bf4b0b | 401 | if (!constraintList_resolve (el, ret) ) |
bb25bea6 | 402 | { |
403 | constraint temp2; | |
404 | temp2 = constraint_copy(el); | |
405 | ret = constraintList_add (ret, temp2); | |
406 | } | |
616915dd | 407 | } |
d46ce6a4 | 408 | constraint_free(temp); |
616915dd | 409 | } |
bb25bea6 | 410 | end_constraintList_elements; |
616915dd | 411 | |
bb25bea6 | 412 | constraintList_elements (l2, el) |
616915dd | 413 | { |
28bf4b0b | 414 | temp = constraint_substitute (el, l1); |
616915dd | 415 | |
28bf4b0b | 416 | if (constraintList_resolve (el, l1) || constraintList_resolve(temp,l1) ) |
616915dd | 417 | { |
418 | /*avoid redundant constraints*/ | |
28bf4b0b | 419 | if (!constraintList_resolve (el, ret) ) |
bb25bea6 | 420 | { |
421 | constraint temp2; | |
422 | temp2 = constraint_copy(el); | |
423 | ret = constraintList_add (ret, temp2); | |
424 | } | |
616915dd | 425 | } |
d46ce6a4 | 426 | constraint_free(temp); |
616915dd | 427 | } |
bb25bea6 | 428 | end_constraintList_elements; |
616915dd | 429 | |
430 | ||
431 | return ret; | |
432 | } | |
433 | ||
434 | void | |
bb25bea6 | 435 | constraintList_free (/*@only@*/ constraintList s) |
616915dd | 436 | { |
437 | int i; | |
bb25bea6 | 438 | |
439 | llassert(constraintList_isDefined(s) ); | |
440 | ||
441 | ||
616915dd | 442 | for (i = 0; i < s->nelements; i++) |
443 | { | |
bb25bea6 | 444 | constraint_free (s->elements[i]); |
616915dd | 445 | } |
446 | ||
447 | sfree (s->elements); | |
bb25bea6 | 448 | s->elements = NULL; |
449 | s->nelements = -1; | |
450 | s->nspace = -1; | |
616915dd | 451 | sfree (s); |
bb25bea6 | 452 | s = NULL; |
616915dd | 453 | } |
454 | ||
455 | constraintList | |
03d670b6 | 456 | constraintList_copy (/*@observer@*/ /*@temp@*/ constraintList s) |
616915dd | 457 | { |
c3e695ff | 458 | constraintList ret = constraintList_makeNew (); |
616915dd | 459 | |
bb25bea6 | 460 | constraintList_elements (s, el) |
616915dd | 461 | { |
462 | ret = constraintList_add (ret, constraint_copy (el)); | |
bb25bea6 | 463 | } end_constraintList_elements; |
616915dd | 464 | |
465 | return ret; | |
466 | } | |
467 | ||
468 | constraintList constraintList_preserveOrig (constraintList c) | |
469 | { | |
d46ce6a4 | 470 | DPRINTF((message("constraintList_preserveOrig preserving the originial constraints for %s ", constraintList_print (c) ) )); |
471 | ||
472 | constraintList_elements_private (c, el) | |
616915dd | 473 | { |
474 | el = constraint_preserveOrig (el); | |
475 | } | |
d46ce6a4 | 476 | end_constraintList_elements_private; |
616915dd | 477 | return c; |
478 | } | |
479 | ||
03d670b6 | 480 | constraintList constraintList_preserveCallInfo (/*@returned@*/ constraintList c,/*@observer@*/ /*@dependent@*/ /*@observer@*/ exprNode fcn) |
4ab867d6 | 481 | { |
dc7f6a51 | 482 | DPRINTF((message("constraintList_preserveCallInfo %s ", constraintList_print (c) ) )); |
4ab867d6 | 483 | |
484 | constraintList_elements_private (c, el) | |
485 | { | |
4ab867d6 | 486 | el = constraint_setFcnPre(el); |
487 | el = constraint_origAddGeneratingExpr (el, fcn); | |
488 | } | |
489 | end_constraintList_elements_private; | |
490 | return c; | |
491 | } | |
492 | ||
3814599d | 493 | constraintList constraintList_single (constraint c) |
494 | { | |
495 | constraintList res; | |
496 | res = constraintList_makeNew(); | |
497 | res = constraintList_add (res, c); | |
498 | return res; | |
499 | } | |
4ab867d6 | 500 | |
28bf4b0b | 501 | constraintList constraintList_addGeneratingExpr (constraintList c,/*@dependent@*/ exprNode e) |
9280addf | 502 | { |
503 | DPRINTF ((message ("entering constraintList_addGeneratingExpr for %s ", exprNode_unparse(e) ) )); | |
504 | ||
d46ce6a4 | 505 | constraintList_elements_private (c, el) |
9280addf | 506 | { |
507 | DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print(el), exprNode_unparse(e) ) )); | |
508 | el = constraint_addGeneratingExpr (el, e); | |
509 | } | |
d46ce6a4 | 510 | end_constraintList_elements_private; |
9280addf | 511 | return c; |
512 | } | |
513 | ||
d46ce6a4 | 514 | /*@only@*/ constraintList constraintList_doFixResult (/*@only@*/constraintList postconditions, exprNode fcnCall) |
616915dd | 515 | { |
516 | constraintList ret; | |
c3e695ff | 517 | ret = constraintList_makeNew(); |
d46ce6a4 | 518 | constraintList_elements_private (postconditions, el) |
616915dd | 519 | { |
520 | ret = constraintList_add (ret, constraint_doFixResult (el, fcnCall) ); | |
521 | } | |
d46ce6a4 | 522 | end_constraintList_elements_private; |
616915dd | 523 | |
d46ce6a4 | 524 | constraintList_free(postconditions); |
616915dd | 525 | return ret; |
526 | } | |
86d93ed3 | 527 | /* |
528 | Commenting out because function is not yet stable | |
529 | ||
530 | / *@only@* / constraintList constraintList_doSRefFixStructConstraint(constraintList invars, sRef s, ctype ct ) | |
531 | { | |
532 | constraintList ret; | |
533 | ret = constraintList_makeNew(); | |
534 | ||
535 | constraintList_elements (invars, el) | |
536 | { | |
537 | ret = constraintList_add(ret, constraint_doSRefFixInvarConstraint (el, s, ct) ); | |
538 | } | |
539 | end_constraintList_elements; | |
540 | ||
541 | / * constraintList_free (invars);* / | |
542 | ||
543 | return ret; | |
544 | } | |
545 | */ | |
616915dd | 546 | |
28bf4b0b | 547 | /*@only@*/ constraintList constraintList_doSRefFixConstraintParam (constraintList preconditions, /*@temp@*/ /*@observer@*/ exprNodeList arglist) |
616915dd | 548 | { |
549 | constraintList ret; | |
c3e695ff | 550 | ret = constraintList_makeNew(); |
616915dd | 551 | |
bb25bea6 | 552 | constraintList_elements (preconditions, el) |
616915dd | 553 | { |
554 | ret = constraintList_add(ret, constraint_doSRefFixConstraintParam (el, arglist) ); | |
555 | } | |
bb25bea6 | 556 | end_constraintList_elements; |
d46ce6a4 | 557 | |
558 | constraintList_free (preconditions); | |
616915dd | 559 | |
560 | return ret; | |
561 | } | |
28bf4b0b | 562 | constraintList constraintList_doSRefFixBaseParam (constraintList preconditions, /*@observer@*/ |
616915dd | 563 | exprNodeList arglist) |
564 | { | |
565 | constraintList ret; | |
bb25bea6 | 566 | constraint temp; |
c3e695ff | 567 | ret = constraintList_makeNew(); |
616915dd | 568 | |
bb25bea6 | 569 | constraintList_elements (preconditions, el) |
616915dd | 570 | { |
bb25bea6 | 571 | temp = constraint_copy(el); |
572 | ret = constraintList_add(ret, constraint_doSRefFixBaseParam (temp, arglist) ); | |
616915dd | 573 | } |
bb25bea6 | 574 | end_constraintList_elements; |
616915dd | 575 | |
576 | return ret; | |
577 | } | |
578 | ||
579 | constraintList constraintList_togglePost (/*@returned@*/ constraintList c) | |
580 | { | |
d46ce6a4 | 581 | constraintList_elements_private (c, el) |
616915dd | 582 | { |
84c9ffbf | 583 | el = constraint_togglePost(el); |
2934b455 | 584 | if (constraint_hasOrig(el) ) |
4ab867d6 | 585 | { |
2934b455 | 586 | el = constraint_togglePostOrig (el); |
4ab867d6 | 587 | } |
616915dd | 588 | } |
d46ce6a4 | 589 | end_constraintList_elements_private; |
616915dd | 590 | return c; |
591 | } | |
592 | ||
920a3797 | 593 | /*@only@*/ constraintList constraintList_undump (FILE *f) |
594 | { | |
595 | constraintList ret; | |
3be9a165 | 596 | char *s; |
920a3797 | 597 | char *os; |
598 | ||
599 | ret = constraintList_makeNew(); | |
600 | ||
3be9a165 | 601 | os = mstring_create (MAX_DUMP_LINE_LENGTH); |
920a3797 | 602 | s = fgets (os, MAX_DUMP_LINE_LENGTH, f); |
603 | ||
604 | while (s != NULL && *s != ';') | |
605 | { | |
606 | constraint temp; | |
607 | char * c; | |
608 | ||
28bf4b0b | 609 | c = reader_getWord(&s); |
920a3797 | 610 | |
611 | if (strcmp (c, "C") != 0) | |
612 | { | |
613 | llfatalbug(message("Error reading library. File may be corrupted")); | |
614 | } | |
615 | ||
616 | temp = constraint_undump (f); | |
617 | ret = constraintList_add (ret, temp); | |
618 | s = fgets (os, MAX_DUMP_LINE_LENGTH, f); | |
619 | free(c); | |
620 | } | |
621 | free(s); | |
622 | ||
623 | return ret; | |
624 | } | |
625 | ||
626 | ||
627 | void constraintList_dump (/*@observer@*/ constraintList c, FILE *f) | |
628 | { | |
629 | constraintList_elements (c, el) | |
630 | { | |
631 | fprintf(f, "C\n"); | |
632 | constraint_dump (el, f); | |
633 | } | |
634 | end_constraintList_elements; ; | |
635 | } | |
636 | ||
616915dd | 637 | |
02984642 | 638 | constraintList constraintList_sort (/*@returned@*/ constraintList ret) |
639 | { | |
640 | qsort (ret->elements, (size_t) ret->nelements, | |
15b3d2b2 | 641 | (sizeof (*ret->elements)), |
642 | (int (*)(const void *, const void *)) constraint_compare); | |
643 | ||
644 | DPRINTF((message("onstraint_sort returning") )); | |
02984642 | 645 | return ret; |
646 | } | |
f4ec8018 | 647 | |
648 |