]>
Commit | Line | Data |
---|---|---|
65f973be | 1 | /* |
11db3170 | 2 | ** Splint - annotation-assisted static program checker |
77d37419 | 3 | ** Copyright (C) 1994-2002 University of Virginia, |
65f973be | 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 | ** | |
155af98d | 20 | ** For information on splint: info@splint.org |
21 | ** To report a bug: splint-bug@splint.org | |
11db3170 | 22 | ** For more information: http://www.splint.org |
65f973be | 23 | */ |
24 | ||
616915dd | 25 | /* |
4ab867d6 | 26 | ** constraint.c |
616915dd | 27 | */ |
28 | ||
b7b694d6 | 29 | /* #define DEBUGPRINT 1 */ |
616915dd | 30 | |
31 | # include <ctype.h> /* for isdigit */ | |
1b8ae690 | 32 | # include "splintMacros.nf" |
616915dd | 33 | # include "basic.h" |
34 | # include "cgrammar.h" | |
35 | # include "cgrammar_tokens.h" | |
f0171cff | 36 | |
616915dd | 37 | # include "exprChecks.h" |
616915dd | 38 | # include "exprNodeSList.h" |
616915dd | 39 | |
40 | /*@i33*/ | |
616915dd | 41 | |
393e573f | 42 | /*@access exprNode@*/ /* !!! NO! Don't do this recklessly! */ |
43 | /*@-nullderef@*/ /* !!! DRL needs to fix this code! */ | |
44 | /*@-nullstate@*/ /* !!! DRL needs to fix this code! */ | |
45 | /*@-temptrans@*/ /* !!! DRL needs to fix this code! */ | |
d46ce6a4 | 46 | |
28bf4b0b | 47 | static /*@only@*/ cstring constraint_printDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint p_c); |
2934b455 | 48 | |
49 | ||
ccf0a4a8 | 50 | static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void) |
51 | /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/ | |
52 | /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/; | |
4ab867d6 | 53 | |
920a3797 | 54 | static void |
55 | advanceField (char **s) | |
56 | { | |
28bf4b0b | 57 | reader_checkChar (s, '@'); |
920a3797 | 58 | } |
59 | ||
15b3d2b2 | 60 | # if 0 |
28bf4b0b | 61 | static constraint makeConstraintParse2 (constraintExpr l, lltok relOp, exprNode cconstant) |
616915dd | 62 | { |
63 | char *t; | |
64 | int c; | |
65 | constraint ret; | |
ccf0a4a8 | 66 | ret = constraint_makeNew (); |
bb7c2085 | 67 | llassert (constraintExpr_isDefined (l)); |
d46ce6a4 | 68 | |
616915dd | 69 | ret->lexpr = constraintExpr_copy (l); |
2934b455 | 70 | |
616915dd | 71 | |
72 | if (relOp.tok == GE_OP) | |
73 | ret->ar = GTE; | |
74 | else if (relOp.tok == LE_OP) | |
75 | ret->ar = LTE; | |
76 | else if (relOp.tok == EQ_OP) | |
77 | ret->ar = EQ; | |
78 | else | |
bb7c2085 | 79 | llfatalbug (message ("Unsupported relational operator")); |
616915dd | 80 | |
81 | ||
bb7c2085 | 82 | t = cstring_toCharsSafe (exprNode_unparse (cconstant)); |
83 | c = atoi ( t); | |
616915dd | 84 | ret->expr = constraintExpr_makeIntLiteral (c); |
85 | ||
86 | ret->post = TRUE; | |
bb7c2085 | 87 | DPRINTF (("GENERATED CONSTRAINT:")); |
88 | DPRINTF ((message ("%s", constraint_print (ret)))); | |
616915dd | 89 | return ret; |
90 | } | |
15b3d2b2 | 91 | # endif |
616915dd | 92 | |
c3e695ff | 93 | bool constraint_same (constraint c1, constraint c2) |
90bc41f7 | 94 | { |
15b3d2b2 | 95 | llassert (c1 != NULL); |
96 | llassert (c2 != NULL); | |
90bc41f7 | 97 | |
15b3d2b2 | 98 | if (c1->ar != c2->ar) |
99 | { | |
100 | return FALSE; | |
101 | } | |
102 | ||
bb7c2085 | 103 | if (!constraintExpr_similar (c1->lexpr, c2->lexpr)) |
15b3d2b2 | 104 | { |
105 | return FALSE; | |
106 | } | |
90bc41f7 | 107 | |
bb7c2085 | 108 | if (!constraintExpr_similar (c1->expr, c2->expr)) |
15b3d2b2 | 109 | { |
110 | return FALSE; | |
111 | } | |
90bc41f7 | 112 | |
113 | return TRUE; | |
114 | } | |
616915dd | 115 | |
116 | constraint makeConstraintParse3 (constraintExpr l, lltok relOp, constraintExpr r) | |
117 | { | |
118 | constraint ret; | |
bb7c2085 | 119 | ret = constraint_makeNew (); |
120 | llassert (constraintExpr_isDefined (l)); | |
616915dd | 121 | |
122 | ret->lexpr = constraintExpr_copy (l); | |
616915dd | 123 | |
80489f0a | 124 | if (lltok_getTok (relOp) == GE_OP) |
125 | { | |
616915dd | 126 | ret->ar = GTE; |
80489f0a | 127 | } |
128 | else if (lltok_getTok (relOp) == LE_OP) | |
129 | { | |
130 | ret->ar = LTE; | |
131 | } | |
132 | else if (lltok_getTok (relOp) == EQ_OP) | |
133 | { | |
134 | ret->ar = EQ; | |
135 | } | |
616915dd | 136 | else |
80489f0a | 137 | llfatalbug ( message ("Unsupported relational operator")); |
616915dd | 138 | |
139 | ret->expr = constraintExpr_copy (r); | |
140 | ||
141 | ret->post = TRUE; | |
90bc41f7 | 142 | |
bb7c2085 | 143 | ret->orig = constraint_copy (ret); |
90bc41f7 | 144 | |
145 | ret = constraint_simplify (ret); | |
b7b694d6 | 146 | /* ret->orig = ret; */ |
147 | ||
bb7c2085 | 148 | DPRINTF (("GENERATED CONSTRAINT:")); |
149 | DPRINTF ((message ("%s", constraint_print (ret)))); | |
616915dd | 150 | return ret; |
151 | } | |
152 | ||
28bf4b0b | 153 | constraint constraint_copy (/*@temp@*/ /*@observer@*/ constraint c) |
616915dd | 154 | { |
155 | constraint ret; | |
90bc41f7 | 156 | |
bb7c2085 | 157 | llassert (constraint_isDefined (c)); |
b7b694d6 | 158 | |
bb7c2085 | 159 | ret = constraint_makeNew (); |
616915dd | 160 | ret->lexpr = constraintExpr_copy (c->lexpr); |
161 | ret->ar = c->ar; | |
162 | ret->expr = constraintExpr_copy (c->expr); | |
163 | ret->post = c->post; | |
795e7f34 | 164 | /*@-assignexpose@*/ |
28bf4b0b | 165 | ret->generatingExpr = c->generatingExpr; |
795e7f34 | 166 | /*@=assignexpose@*/ |
9280addf | 167 | |
616915dd | 168 | /*@i33 fix this*/ |
169 | if (c->orig != NULL) | |
170 | ret->orig = constraint_copy (c->orig); | |
171 | else | |
172 | ret->orig = NULL; | |
90bc41f7 | 173 | |
174 | if (c->or != NULL) | |
175 | ret->or = constraint_copy (c->or); | |
176 | else | |
177 | ret->or = NULL; | |
4ab867d6 | 178 | |
179 | ret->fcnPre = c->fcnPre; | |
90bc41f7 | 180 | |
616915dd | 181 | return ret; |
182 | } | |
183 | ||
184 | /*like copy expect it doesn't allocate memory for the constraint*/ | |
185 | ||
d46ce6a4 | 186 | void constraint_overWrite (constraint c1, constraint c2) |
616915dd | 187 | { |
bb7c2085 | 188 | llassert (constraint_isDefined (c1)); |
d46ce6a4 | 189 | |
190 | llassert (c1 != c2); | |
191 | ||
bb7c2085 | 192 | DPRINTF ((message ("OverWriteing constraint %q with %q", constraint_print (c1), |
193 | constraint_print (c2)))); | |
d46ce6a4 | 194 | |
bb7c2085 | 195 | constraintExpr_free (c1->lexpr); |
196 | constraintExpr_free (c1->expr); | |
d46ce6a4 | 197 | |
616915dd | 198 | c1->lexpr = constraintExpr_copy (c2->lexpr); |
199 | c1->ar = c2->ar; | |
200 | c1->expr = constraintExpr_copy (c2->expr); | |
201 | c1->post = c2->post; | |
d46ce6a4 | 202 | |
203 | if (c1->orig != NULL) | |
204 | constraint_free (c1->orig); | |
205 | ||
616915dd | 206 | if (c2->orig != NULL) |
207 | c1->orig = constraint_copy (c2->orig); | |
208 | else | |
209 | c1->orig = NULL; | |
90bc41f7 | 210 | |
d46ce6a4 | 211 | /*@i33 make sure that the or is freed correctly*/ |
212 | if (c1->or != NULL) | |
213 | constraint_free (c1->or); | |
214 | ||
90bc41f7 | 215 | if (c2->or != NULL) |
216 | c1->or = constraint_copy (c2->or); | |
217 | else | |
218 | c1->or = NULL; | |
4ab867d6 | 219 | |
220 | c1->fcnPre = c2->fcnPre; | |
795e7f34 | 221 | |
222 | /*@-assignexpose@*/ | |
4ab867d6 | 223 | c1->generatingExpr = c2->generatingExpr; |
795e7f34 | 224 | /*@=assignexpose@*/ |
616915dd | 225 | } |
226 | ||
616915dd | 227 | |
228 | ||
d46ce6a4 | 229 | static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void) |
ccf0a4a8 | 230 | /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/ |
231 | /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/ | |
616915dd | 232 | { |
233 | constraint ret; | |
bb7c2085 | 234 | ret = dmalloc (sizeof (*ret)); |
616915dd | 235 | ret->lexpr = NULL; |
236 | ret->expr = NULL; | |
237 | ret->ar = LT; | |
238 | ret->post = FALSE; | |
239 | ret->orig = NULL; | |
90bc41f7 | 240 | ret->or = NULL; |
9280addf | 241 | ret->generatingExpr = NULL; |
4ab867d6 | 242 | ret->fcnPre = NULL; |
dc92450f | 243 | return ret; |
616915dd | 244 | } |
245 | ||
b37cf05e | 246 | constraint constraint_addGeneratingExpr (/*@returned@*/ constraint c, /*@exposed@*/ exprNode e) |
9280addf | 247 | { |
248 | ||
249 | if (c->generatingExpr == NULL) | |
250 | { | |
28bf4b0b | 251 | c->generatingExpr = e; |
bb7c2085 | 252 | DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) )); |
9280addf | 253 | } |
254 | else | |
255 | { | |
bb7c2085 | 256 | DPRINTF ((message ("Not setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) )); |
9280addf | 257 | } |
258 | return c; | |
259 | } | |
260 | ||
4ab867d6 | 261 | constraint constraint_origAddGeneratingExpr (/*@returned@*/ constraint c, exprNode e) |
262 | { | |
263 | ||
264 | if (c->orig != constraint_undefined) | |
265 | { | |
bb7c2085 | 266 | c->orig = constraint_addGeneratingExpr (c->orig, e); |
4ab867d6 | 267 | } |
268 | else | |
269 | { | |
bb7c2085 | 270 | DPRINTF ((message ("constraint_origAddGeneratingExpr: Not setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) )); |
4ab867d6 | 271 | } |
272 | return c; | |
273 | } | |
274 | ||
bb7c2085 | 275 | constraint constraint_setFcnPre (/*@returned@*/ constraint c) |
4ab867d6 | 276 | { |
277 | ||
278 | if (c->orig != constraint_undefined) | |
279 | { | |
280 | c->orig->fcnPre = TRUE; | |
281 | } | |
282 | else | |
283 | { | |
284 | c->fcnPre = TRUE; | |
bb7c2085 | 285 | DPRINTF (( message ("Warning Setting fcnPre directly"))); |
4ab867d6 | 286 | } |
287 | return c; | |
288 | } | |
289 | ||
290 | ||
291 | ||
292 | ||
616915dd | 293 | fileloc constraint_getFileloc (constraint c) |
294 | { | |
bb7c2085 | 295 | if (exprNode_isDefined (c->generatingExpr)) |
296 | return (fileloc_copy (exprNode_getfileloc (c->generatingExpr))); | |
9280addf | 297 | |
bb7c2085 | 298 | return (constraintExpr_getFileloc (c->lexpr)); |
616915dd | 299 | |
300 | ||
301 | } | |
302 | ||
9280addf | 303 | static bool checkForMaxSet (constraint c) |
304 | { | |
bb7c2085 | 305 | if (constraintExpr_hasMaxSet (c->lexpr) || constraintExpr_hasMaxSet (c->expr)) |
9280addf | 306 | return TRUE; |
307 | ||
308 | return FALSE; | |
309 | } | |
310 | ||
bb7c2085 | 311 | bool constraint_hasMaxSet (constraint c) |
9280addf | 312 | { |
bb7c2085 | 313 | if (checkForMaxSet (c)) |
03d670b6 | 314 | return TRUE; |
315 | ||
dc92450f | 316 | if (c->orig != NULL) |
9280addf | 317 | { |
bb7c2085 | 318 | if (checkForMaxSet (c->orig)) |
9280addf | 319 | return TRUE; |
320 | } | |
321 | ||
03d670b6 | 322 | return FALSE; |
9280addf | 323 | } |
324 | ||
abd7f895 | 325 | constraint constraint_makeReadSafeExprNode (exprNode po, exprNode ind) |
616915dd | 326 | { |
bb7c2085 | 327 | constraint ret = constraint_makeNew (); |
b7b694d6 | 328 | |
28bf4b0b | 329 | po = po; |
330 | ind = ind; | |
bb7c2085 | 331 | ret->lexpr = constraintExpr_makeMaxReadExpr (po); |
616915dd | 332 | ret->ar = GTE; |
333 | ret->expr = constraintExpr_makeValueExpr (ind); | |
d46ce6a4 | 334 | ret->post = FALSE; |
616915dd | 335 | return ret; |
336 | } | |
337 | ||
28bf4b0b | 338 | constraint constraint_makeWriteSafeInt ( exprNode po, int ind) |
616915dd | 339 | { |
bb7c2085 | 340 | constraint ret = constraint_makeNew (); |
616915dd | 341 | |
342 | ||
bb7c2085 | 343 | ret->lexpr =constraintExpr_makeMaxSetExpr (po); |
616915dd | 344 | ret->ar = GTE; |
c3e695ff | 345 | ret->expr = constraintExpr_makeIntLiteral (ind); |
616915dd | 346 | /*@i1*/return ret; |
347 | } | |
348 | ||
84c9ffbf | 349 | constraint constraint_makeSRefSetBufferSize (sRef s, long int size) |
616915dd | 350 | { |
bb7c2085 | 351 | constraint ret = constraint_makeNew (); |
4ab867d6 | 352 | ret->lexpr = constraintExpr_makeSRefMaxset (s); |
616915dd | 353 | ret->ar = EQ; |
84c9ffbf | 354 | ret->expr = constraintExpr_makeIntLiteral ((int)size); |
616915dd | 355 | ret->post = TRUE; |
356 | /*@i1*/return ret; | |
357 | } | |
358 | ||
359 | constraint constraint_makeSRefWriteSafeInt (sRef s, int ind) | |
360 | { | |
bb7c2085 | 361 | constraint ret = constraint_makeNew (); |
616915dd | 362 | |
363 | ||
bb7c2085 | 364 | ret->lexpr = constraintExpr_makeSRefMaxset ( s); |
616915dd | 365 | ret->ar = GTE; |
c3e695ff | 366 | ret->expr = constraintExpr_makeIntLiteral (ind); |
616915dd | 367 | ret->post = TRUE; |
368 | /*@i1*/return ret; | |
369 | } | |
370 | ||
371 | /* drl added 01/12/2000 | |
372 | ||
bb7c2085 | 373 | makes the constraint: Ensures index <= MaxRead (buffer) */ |
616915dd | 374 | |
bb7c2085 | 375 | constraint constraint_makeEnsureLteMaxRead (exprNode index, exprNode buffer) |
616915dd | 376 | { |
bb7c2085 | 377 | constraint ret = constraint_makeNew (); |
616915dd | 378 | |
379 | ret->lexpr = constraintExpr_makeValueExpr (index); | |
380 | ret->ar = LTE; | |
bb7c2085 | 381 | ret->expr = constraintExpr_makeMaxReadExpr (buffer); |
616915dd | 382 | ret->post = TRUE; |
383 | return ret; | |
384 | } | |
385 | ||
386 | constraint constraint_makeWriteSafeExprNode (exprNode po, exprNode ind) | |
387 | { | |
bb7c2085 | 388 | constraint ret = constraint_makeNew (); |
616915dd | 389 | |
390 | ||
bb7c2085 | 391 | ret->lexpr =constraintExpr_makeMaxSetExpr (po); |
616915dd | 392 | ret->ar = GTE; |
393 | ret->expr = constraintExpr_makeValueExpr (ind); | |
394 | /*@i1*/return ret; | |
395 | } | |
396 | ||
397 | ||
28bf4b0b | 398 | constraint constraint_makeReadSafeInt ( exprNode t1, int index) |
616915dd | 399 | { |
bb7c2085 | 400 | constraint ret = constraint_makeNew (); |
616915dd | 401 | |
bb7c2085 | 402 | ret->lexpr = constraintExpr_makeMaxReadExpr (t1); |
616915dd | 403 | ret->ar = GTE; |
28bf4b0b | 404 | ret->expr = constraintExpr_makeIntLiteral (index); |
d46ce6a4 | 405 | ret->post = FALSE; |
616915dd | 406 | return ret; |
407 | } | |
408 | ||
470b7798 | 409 | constraint constraint_makeSRefReadSafeInt (sRef s, int ind) |
410 | { | |
bb7c2085 | 411 | constraint ret = constraint_makeNew (); |
470b7798 | 412 | |
413 | ||
bb7c2085 | 414 | ret->lexpr = constraintExpr_makeSRefMaxRead (s); |
470b7798 | 415 | ret->ar = GTE; |
c3e695ff | 416 | ret->expr = constraintExpr_makeIntLiteral (ind); |
470b7798 | 417 | ret->post = TRUE; |
418 | /*@i1*/return ret; | |
419 | } | |
420 | ||
28bf4b0b | 421 | constraint constraint_makeEnsureMaxReadAtLeast (exprNode t1, exprNode t2, fileloc sequencePoint) |
616915dd | 422 | { |
d46ce6a4 | 423 | constraint ret; |
616915dd | 424 | |
bb7c2085 | 425 | ret = constraint_makeReadSafeExprNode (t1, t2); |
b7b694d6 | 426 | ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint); |
616915dd | 427 | ret->post = TRUE; |
428 | ||
616915dd | 429 | return ret; |
430 | } | |
431 | ||
d46ce6a4 | 432 | static constraint constraint_makeEnsuresOpConstraintExpr (/*@only@*/ constraintExpr c1, /*@only@*/ constraintExpr c2, fileloc sequencePoint, arithType ar) |
470b7798 | 433 | { |
434 | ||
435 | constraint ret; | |
436 | ||
bb7c2085 | 437 | llassert (constraintExpr_isDefined (c1) && constraintExpr_isDefined (c2)); |
470b7798 | 438 | |
bb7c2085 | 439 | ret = constraint_makeNew (); |
470b7798 | 440 | |
441 | ret->lexpr = c1; | |
442 | ret->ar = ar; | |
443 | ret->post = TRUE; | |
444 | ret->expr = c2; | |
445 | ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint); | |
446 | return ret; | |
447 | } | |
616915dd | 448 | |
28bf4b0b | 449 | static constraint constraint_makeEnsuresOp (/*@dependent@*/ exprNode e1, /*@dependent@*/ exprNode e2, fileloc sequencePoint, arithType ar) |
616915dd | 450 | { |
470b7798 | 451 | constraintExpr c1, c2; |
452 | constraint ret; | |
616915dd | 453 | exprNode e; |
470b7798 | 454 | |
bb7c2085 | 455 | if (! (exprNode_isDefined (e1) && exprNode_isDefined (e2))) |
616915dd | 456 | { |
bb7c2085 | 457 | llcontbug ((message ("null exprNode, Exprnodes are %s and %s", |
458 | exprNode_unparse (e1), exprNode_unparse (e2)) | |
459 | )); | |
616915dd | 460 | } |
470b7798 | 461 | |
28bf4b0b | 462 | e = e1; |
470b7798 | 463 | c1 = constraintExpr_makeValueExpr (e); |
464 | ||
28bf4b0b | 465 | e = e2; |
470b7798 | 466 | c2 = constraintExpr_makeValueExpr (e); |
467 | ||
468 | ret = constraint_makeEnsuresOpConstraintExpr (c1, c2, sequencePoint, ar); | |
616915dd | 469 | |
616915dd | 470 | return ret; |
471 | } | |
472 | ||
473 | ||
474 | /* make constraint ensures e1 == e2 */ | |
475 | ||
476 | constraint constraint_makeEnsureEqual (exprNode e1, exprNode e2, fileloc sequencePoint) | |
477 | { | |
bb7c2085 | 478 | return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, EQ)); |
616915dd | 479 | } |
480 | ||
481 | /*make constraint ensures e1 < e2 */ | |
482 | constraint constraint_makeEnsureLessThan (exprNode e1, exprNode e2, fileloc sequencePoint) | |
483 | { | |
470b7798 | 484 | constraintExpr t1, t2; |
485 | ||
486 | t1 = constraintExpr_makeValueExpr (e1); | |
487 | t2 = constraintExpr_makeValueExpr (e2); | |
488 | ||
489 | /*change this to e1 <= (e2 -1) */ | |
490 | ||
491 | t2 = constraintExpr_makeDecConstraintExpr (t2); | |
492 | ||
bb7c2085 | 493 | return ( constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, LTE)); |
616915dd | 494 | } |
495 | ||
496 | constraint constraint_makeEnsureLessThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint) | |
497 | { | |
bb7c2085 | 498 | return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, LTE)); |
616915dd | 499 | } |
500 | ||
501 | constraint constraint_makeEnsureGreaterThan (exprNode e1, exprNode e2, fileloc sequencePoint) | |
502 | { | |
470b7798 | 503 | constraintExpr t1, t2; |
504 | ||
505 | t1 = constraintExpr_makeValueExpr (e1); | |
506 | t2 = constraintExpr_makeValueExpr (e2); | |
507 | ||
508 | ||
509 | /* change this to e1 >= (e2 + 1) */ | |
510 | t2 = constraintExpr_makeIncConstraintExpr (t2); | |
511 | ||
512 | ||
bb7c2085 | 513 | return ( constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, GTE)); |
616915dd | 514 | } |
515 | ||
516 | constraint constraint_makeEnsureGreaterThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint) | |
517 | { | |
bb7c2085 | 518 | return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, GTE)); |
616915dd | 519 | } |
520 | ||
521 | ||
522 | exprNode exprNode_copyConstraints (/*@returned@*/ exprNode dst, exprNode src) | |
523 | { | |
bb7c2085 | 524 | constraintList_free (dst->ensuresConstraints); |
525 | constraintList_free (dst->requiresConstraints); | |
526 | constraintList_free (dst->trueEnsuresConstraints); | |
527 | constraintList_free (dst->falseEnsuresConstraints); | |
d46ce6a4 | 528 | |
bb7c2085 | 529 | dst->ensuresConstraints = constraintList_copy (src->ensuresConstraints); |
530 | dst->requiresConstraints = constraintList_copy (src->requiresConstraints); | |
531 | dst->trueEnsuresConstraints = constraintList_copy (src->trueEnsuresConstraints); | |
532 | dst->falseEnsuresConstraints = constraintList_copy (src->falseEnsuresConstraints); | |
616915dd | 533 | return dst; |
534 | } | |
535 | ||
2934b455 | 536 | /* Makes the constraint e = e + f */ |
537 | constraint constraint_makeAddAssign (exprNode e, exprNode f, fileloc sequencePoint) | |
538 | { | |
539 | constraintExpr x1, x2, y; | |
540 | constraint ret; | |
541 | ||
bb7c2085 | 542 | ret = constraint_makeNew (); |
2934b455 | 543 | |
544 | x1 = constraintExpr_makeValueExpr (e); | |
bb7c2085 | 545 | x2 = constraintExpr_copy (x1); |
2934b455 | 546 | y = constraintExpr_makeValueExpr (f); |
547 | ||
548 | ret->lexpr = x1; | |
549 | ret->ar = EQ; | |
550 | ret->post = TRUE; | |
551 | ret->expr = constraintExpr_makeAddExpr (x2, y); | |
552 | ||
553 | ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint); | |
554 | ||
555 | return ret; | |
556 | } | |
557 | ||
558 | ||
559 | /* Makes the constraint e = e - f */ | |
560 | constraint constraint_makeSubtractAssign (exprNode e, exprNode f, fileloc sequencePoint) | |
561 | { | |
562 | constraintExpr x1, x2, y; | |
563 | constraint ret; | |
564 | ||
bb7c2085 | 565 | ret = constraint_makeNew (); |
2934b455 | 566 | |
567 | x1 = constraintExpr_makeValueExpr (e); | |
bb7c2085 | 568 | x2 = constraintExpr_copy (x1); |
2934b455 | 569 | y = constraintExpr_makeValueExpr (f); |
570 | ||
571 | ret->lexpr = x1; | |
572 | ret->ar = EQ; | |
573 | ret->post = TRUE; | |
574 | ret->expr = constraintExpr_makeSubtractExpr (x2, y); | |
575 | ||
576 | ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint); | |
577 | ||
578 | return ret; | |
579 | } | |
580 | ||
616915dd | 581 | constraint constraint_makeMaxSetSideEffectPostDecrement (exprNode e, fileloc sequencePoint) |
582 | { | |
bb7c2085 | 583 | constraint ret = constraint_makeNew (); |
616915dd | 584 | |
616915dd | 585 | ret->lexpr = constraintExpr_makeValueExpr (e); |
586 | ret->ar = EQ; | |
587 | ret->post = TRUE; | |
588 | ret->expr = constraintExpr_makeValueExpr (e); | |
589 | ret->expr = constraintExpr_makeDecConstraintExpr (ret->expr); | |
616915dd | 590 | ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint); |
616915dd | 591 | return ret; |
592 | } | |
593 | constraint constraint_makeMaxSetSideEffectPostIncrement (exprNode e, fileloc sequencePoint) | |
594 | { | |
bb7c2085 | 595 | constraint ret = constraint_makeNew (); |
616915dd | 596 | |
616915dd | 597 | ret->lexpr = constraintExpr_makeValueExpr (e); |
598 | ret->ar = EQ; | |
599 | ret->post = TRUE; | |
600 | ret->expr = constraintExpr_makeValueExpr (e); | |
601 | ret->expr = constraintExpr_makeIncConstraintExpr (ret->expr); | |
602 | ||
603 | ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint); | |
616915dd | 604 | return ret; |
605 | } | |
606 | ||
607 | ||
920a3797 | 608 | void constraint_free (/*@only@*/ constraint c) |
d46ce6a4 | 609 | { |
bb7c2085 | 610 | llassert (constraint_isDefined (c)); |
d46ce6a4 | 611 | |
612 | ||
bb7c2085 | 613 | if (constraint_isDefined (c->orig)) |
d46ce6a4 | 614 | constraint_free (c->orig); |
bb7c2085 | 615 | if ( constraint_isDefined (c->or)) |
d46ce6a4 | 616 | constraint_free (c->or); |
617 | ||
bb25bea6 | 618 | |
bb7c2085 | 619 | constraintExpr_free (c->lexpr); |
620 | constraintExpr_free (c->expr); | |
bb25bea6 | 621 | |
622 | c->orig = NULL; | |
623 | c->or = NULL; | |
624 | c->lexpr = NULL; | |
625 | c->expr = NULL; | |
626 | ||
d46ce6a4 | 627 | free (c); |
628 | ||
629 | } | |
630 | ||
dc92450f | 631 | cstring arithType_print (arithType ar) /*@*/ |
616915dd | 632 | { |
633 | cstring st = cstring_undefined; | |
634 | switch (ar) | |
635 | { | |
636 | case LT: | |
a779b61e | 637 | st = cstring_makeLiteral ("<"); |
616915dd | 638 | break; |
639 | case LTE: | |
a779b61e | 640 | st = cstring_makeLiteral ("<="); |
616915dd | 641 | break; |
642 | case GT: | |
a779b61e | 643 | st = cstring_makeLiteral (">"); |
616915dd | 644 | break; |
645 | case GTE: | |
a779b61e | 646 | st = cstring_makeLiteral (">="); |
616915dd | 647 | break; |
648 | case EQ: | |
a779b61e | 649 | st = cstring_makeLiteral ("=="); |
616915dd | 650 | break; |
651 | case NONNEGATIVE: | |
a779b61e | 652 | st = cstring_makeLiteral ("NONNEGATIVE"); |
616915dd | 653 | break; |
654 | case POSITIVE: | |
a779b61e | 655 | st = cstring_makeLiteral ("POSITIVE"); |
616915dd | 656 | break; |
657 | default: | |
bb7c2085 | 658 | llassert (FALSE); |
616915dd | 659 | break; |
660 | } | |
661 | return st; | |
662 | } | |
663 | ||
8f299805 | 664 | void constraint_printErrorPostCondition (constraint c, fileloc loc) |
665 | { | |
666 | cstring string; | |
667 | fileloc errorLoc, temp; | |
668 | ||
669 | string = constraint_printDetailedPostCondition (c); | |
670 | ||
671 | errorLoc = loc; | |
672 | ||
673 | loc = NULL; | |
674 | ||
bb7c2085 | 675 | temp = constraint_getFileloc (c); |
8f299805 | 676 | |
9276a168 | 677 | |
678 | if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) ) | |
679 | { | |
680 | string = cstring_replaceChar(string, '\n', ' '); | |
681 | } | |
682 | ||
bb7c2085 | 683 | if (fileloc_isDefined (temp)) |
8f299805 | 684 | { |
685 | errorLoc = temp; | |
686 | voptgenerror ( FLG_CHECKPOST, string, errorLoc); | |
bb7c2085 | 687 | fileloc_free (temp); |
8f299805 | 688 | } |
689 | else | |
690 | { | |
691 | voptgenerror ( FLG_CHECKPOST, string, errorLoc); | |
692 | } | |
693 | } | |
694 | ||
f4ec8018 | 695 | /*drl added 8-11-001*/ |
696 | cstring constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c) /*@*/ | |
697 | { | |
698 | cstring string, ret; | |
699 | fileloc errorLoc; | |
700 | ||
bb7c2085 | 701 | string = constraint_print (c); |
f4ec8018 | 702 | |
bb7c2085 | 703 | errorLoc = constraint_getFileloc (c); |
f4ec8018 | 704 | |
bb7c2085 | 705 | ret = message ("constraint: %q @ %q", string, fileloc_unparse (errorLoc)); |
f4ec8018 | 706 | |
bb7c2085 | 707 | fileloc_free (errorLoc); |
f4ec8018 | 708 | return ret; |
709 | ||
710 | } | |
8f299805 | 711 | |
712 | ||
713 | ||
616915dd | 714 | void constraint_printError (constraint c, fileloc loc) |
715 | { | |
716 | cstring string; | |
4ab867d6 | 717 | fileloc errorLoc, temp; |
e5f31c00 | 718 | |
719 | ||
720 | /*drl 11/26/2001 avoid printing tautological constraints */ | |
bb7c2085 | 721 | if (constraint_isAlwaysTrue (c)) |
e5f31c00 | 722 | { |
723 | return; | |
724 | } | |
725 | ||
726 | ||
616915dd | 727 | string = constraint_printDetailed (c); |
9280addf | 728 | |
729 | errorLoc = loc; | |
730 | ||
bb7c2085 | 731 | temp = constraint_getFileloc (c); |
4ab867d6 | 732 | |
bb7c2085 | 733 | if (fileloc_isDefined (temp)) |
616915dd | 734 | { |
4ab867d6 | 735 | errorLoc = temp; |
84380658 | 736 | } |
737 | else | |
738 | { | |
bb7c2085 | 739 | llassert (FALSE); |
740 | DPRINTF (("constraint %s had undefined fileloc %s", constraint_print (c), fileloc_unparse (temp))); | |
741 | fileloc_free (temp); | |
742 | errorLoc = fileloc_copy (errorLoc); | |
84380658 | 743 | } |
9276a168 | 744 | |
745 | ||
746 | if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) ) | |
747 | { | |
748 | string = cstring_replaceChar(string, '\n', ' '); | |
749 | } | |
750 | ||
751 | ||
84380658 | 752 | if (c->post) |
753 | { | |
754 | voptgenerror (FLG_FUNCTIONPOST, string, errorLoc); | |
616915dd | 755 | } |
756 | else | |
757 | { | |
bb7c2085 | 758 | if (constraint_hasMaxSet (c)) |
759 | { | |
760 | voptgenerror (FLG_BOUNDSWRITE, string, errorLoc); | |
761 | } | |
4ab867d6 | 762 | else |
bb7c2085 | 763 | { |
764 | voptgenerror (FLG_BOUNDSREAD, string, errorLoc); | |
765 | } | |
616915dd | 766 | } |
84380658 | 767 | |
86d93ed3 | 768 | fileloc_free(errorLoc); |
616915dd | 769 | } |
770 | ||
28bf4b0b | 771 | static cstring constraint_printDeep (constraint c) |
616915dd | 772 | { |
28bf4b0b | 773 | cstring genExpr; |
616915dd | 774 | cstring st = cstring_undefined; |
775 | ||
86d93ed3 | 776 | st = constraint_print(c); |
28bf4b0b | 777 | |
4ab867d6 | 778 | if (c->orig != constraint_undefined) |
779 | { | |
bb7c2085 | 780 | st = cstring_appendChar (st, '\n'); |
781 | genExpr = exprNode_unparse (c->orig->generatingExpr); | |
782 | ||
4ab867d6 | 783 | if (!c->post) |
784 | { | |
785 | if (c->orig->fcnPre) | |
bb7c2085 | 786 | { |
787 | st = cstring_concatFree (st, message (" derived from %s precondition: %q", | |
788 | genExpr, constraint_printDeep (c->orig))); | |
789 | } | |
4ab867d6 | 790 | else |
bb7c2085 | 791 | { |
792 | st = cstring_concatFree (st, message (" needed to satisfy precondition:\n%q", | |
793 | constraint_printDeep (c->orig))); | |
794 | } | |
4ab867d6 | 795 | } |
796 | else | |
797 | { | |
bb7c2085 | 798 | st = cstring_concatFree (st, message ("derived from: %q", |
799 | constraint_printDeep (c->orig))); | |
4ab867d6 | 800 | } |
801 | } | |
802 | ||
803 | return st; | |
4ab867d6 | 804 | } |
805 | ||
2934b455 | 806 | |
807 | static /*@only@*/ cstring constraint_printDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c) | |
8f299805 | 808 | { |
809 | cstring st = cstring_undefined; | |
28bf4b0b | 810 | cstring genExpr; |
811 | ||
bb7c2085 | 812 | st = message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q", constraint_printDeep (c)); |
28bf4b0b | 813 | |
814 | genExpr = exprNode_unparse (c->generatingExpr); | |
815 | ||
bb7c2085 | 816 | if (context_getFlag (FLG_CONSTRAINTLOCATION)) |
8f299805 | 817 | { |
818 | cstring temp; | |
b7b694d6 | 819 | |
820 | temp = message ("\nOriginal Generating expression %q: %s\n", | |
bb7c2085 | 821 | fileloc_unparse ( exprNode_getfileloc (c->generatingExpr)), |
822 | genExpr); | |
8f299805 | 823 | st = cstring_concatFree (st, temp); |
824 | ||
bb7c2085 | 825 | if (constraint_hasMaxSet (c)) |
8f299805 | 826 | { |
827 | temp = message ("Has MaxSet\n"); | |
828 | st = cstring_concatFree (st, temp); | |
829 | } | |
830 | } | |
831 | return st; | |
832 | } | |
833 | ||
4ab867d6 | 834 | cstring constraint_printDetailed (constraint c) |
835 | { | |
836 | cstring st = cstring_undefined; | |
03d670b6 | 837 | cstring temp = cstring_undefined; |
9276a168 | 838 | cstring genExpr; |
28bf4b0b | 839 | |
616915dd | 840 | if (!c->post) |
841 | { | |
bb7c2085 | 842 | st = message ("Unable to resolve constraint:\n%q", constraint_printDeep (c)); |
616915dd | 843 | } |
844 | else | |
845 | { | |
bb7c2085 | 846 | st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_printDeep (c)); |
616915dd | 847 | } |
9280addf | 848 | |
bb7c2085 | 849 | if (constraint_hasMaxSet (c)) |
03d670b6 | 850 | { |
bb7c2085 | 851 | temp = cstring_makeLiteral ("Possible out-of-bounds store:\n"); |
03d670b6 | 852 | } |
853 | else | |
854 | { | |
bb7c2085 | 855 | temp = cstring_makeLiteral ("Possible out-of-bounds read:\n"); |
03d670b6 | 856 | } |
03d670b6 | 857 | |
28bf4b0b | 858 | genExpr = exprNode_unparse (c->generatingExpr); |
7bf96067 | 859 | |
bb7c2085 | 860 | if (context_getFlag (FLG_CONSTRAINTLOCATION)) |
9280addf | 861 | { |
7bf96067 | 862 | cstring temp2; |
bb7c2085 | 863 | temp2 = message ("%s\n", genExpr); |
7bf96067 | 864 | temp = cstring_concatFree (temp, temp2); |
9280addf | 865 | } |
7bf96067 | 866 | |
bb7c2085 | 867 | st = cstring_concatFree (temp,st); |
7bf96067 | 868 | |
616915dd | 869 | return st; |
870 | } | |
871 | ||
d46ce6a4 | 872 | /*@only@*/ cstring constraint_print (constraint c) /*@*/ |
616915dd | 873 | { |
874 | cstring st = cstring_undefined; | |
875 | cstring type = cstring_undefined; | |
dc92450f | 876 | llassert (c !=NULL); |
616915dd | 877 | if (c->post) |
878 | { | |
bb7c2085 | 879 | if (context_getFlag (FLG_PARENCONSTRAINT)) |
a779b61e | 880 | { |
881 | type = cstring_makeLiteral ("ensures: "); | |
882 | } | |
883 | else | |
884 | { | |
885 | type = cstring_makeLiteral ("ensures"); | |
886 | } | |
616915dd | 887 | } |
888 | else | |
889 | { | |
bb7c2085 | 890 | if (context_getFlag (FLG_PARENCONSTRAINT)) |
a779b61e | 891 | { |
892 | type = cstring_makeLiteral ("requires: "); | |
893 | } | |
894 | else | |
895 | { | |
896 | type = cstring_makeLiteral ("requires"); | |
897 | } | |
898 | ||
616915dd | 899 | } |
bb7c2085 | 900 | if (context_getFlag (FLG_PARENCONSTRAINT)) |
a779b61e | 901 | { |
902 | st = message ("%q: %q %q %q", | |
903 | type, | |
904 | constraintExpr_print (c->lexpr), | |
bb7c2085 | 905 | arithType_print (c->ar), |
906 | constraintExpr_print (c->expr) | |
a779b61e | 907 | ); |
908 | } | |
909 | else | |
910 | { | |
911 | st = message ("%q %q %q %q", | |
912 | type, | |
913 | constraintExpr_print (c->lexpr), | |
bb7c2085 | 914 | arithType_print (c->ar), |
915 | constraintExpr_print (c->expr) | |
616915dd | 916 | ); |
a779b61e | 917 | } |
616915dd | 918 | return st; |
919 | } | |
920 | ||
90bc41f7 | 921 | cstring constraint_printOr (constraint c) /*@*/ |
922 | { | |
923 | cstring ret; | |
924 | constraint temp; | |
925 | ||
926 | ret = cstring_undefined; | |
927 | temp = c; | |
928 | ||
bb7c2085 | 929 | ret = cstring_concatFree (ret, constraint_print (temp)); |
90bc41f7 | 930 | |
931 | temp = temp->or; | |
932 | ||
bb7c2085 | 933 | while ( constraint_isDefined (temp)) |
90bc41f7 | 934 | { |
bb7c2085 | 935 | ret = cstring_concatFree (ret, cstring_makeLiteral (" OR ")); |
936 | ret = cstring_concatFree (ret, constraint_print (temp)); | |
90bc41f7 | 937 | temp = temp->or; |
938 | } | |
939 | ||
940 | return ret; | |
941 | ||
942 | } | |
943 | ||
dc92450f | 944 | /*@only@*/ constraint constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition, |
616915dd | 945 | exprNodeList arglist) |
946 | { | |
947 | precondition->lexpr = constraintExpr_doSRefFixBaseParam (precondition->lexpr, | |
948 | arglist); | |
949 | precondition->expr = constraintExpr_doSRefFixBaseParam (precondition->expr, | |
950 | arglist); | |
951 | ||
952 | return precondition; | |
953 | } | |
954 | ||
955 | ||
28bf4b0b | 956 | constraint constraint_doFixResult (constraint postcondition, /*@dependent@*/ exprNode fcnCall) |
616915dd | 957 | { |
958 | postcondition = constraint_copy (postcondition); | |
959 | postcondition->lexpr = constraintExpr_doFixResult (postcondition->lexpr, fcnCall); | |
960 | postcondition->expr = constraintExpr_doFixResult (postcondition->expr, fcnCall); | |
961 | ||
962 | return postcondition; | |
963 | } | |
86d93ed3 | 964 | /*Commenting out temporally |
965 | ||
966 | / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct ) | |
967 | { | |
968 | ||
969 | invar = constraint_copy (invar); | |
970 | invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct); | |
971 | invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct); | |
972 | ||
973 | return invar; | |
974 | } | |
975 | */ | |
616915dd | 976 | |
d46ce6a4 | 977 | /*@only@*/ constraint constraint_doSRefFixConstraintParam (constraint precondition, |
616915dd | 978 | exprNodeList arglist) |
979 | { | |
980 | ||
981 | precondition = constraint_copy (precondition); | |
982 | precondition->lexpr = constraintExpr_doSRefFixConstraintParam (precondition->lexpr, arglist); | |
983 | precondition->expr = constraintExpr_doSRefFixConstraintParam (precondition->expr, arglist); | |
984 | ||
4ab867d6 | 985 | precondition->fcnPre = FALSE; |
616915dd | 986 | return precondition; |
987 | } | |
988 | ||
d46ce6a4 | 989 | constraint constraint_preserveOrig (/*@returned@*/ constraint c) /*@modifies c @*/ |
616915dd | 990 | { |
4ab867d6 | 991 | |
bb7c2085 | 992 | DPRINTF ((message ("Doing constraint_preserverOrig for %q ", constraint_printDetailed (c)))); |
4ab867d6 | 993 | |
d46ce6a4 | 994 | if (c->orig == constraint_undefined) |
995 | c->orig = constraint_copy (c); | |
4ab867d6 | 996 | |
997 | else if (c->orig->fcnPre) | |
998 | { | |
999 | constraint temp; | |
1000 | ||
1001 | temp = c->orig; | |
1002 | ||
1003 | /* avoid infinite loop */ | |
1004 | c->orig = NULL; | |
1005 | c->orig = constraint_copy (c); | |
1006 | if (c->orig->orig == NULL) | |
920a3797 | 1007 | { |
1008 | c->orig->orig = temp; | |
1009 | temp = NULL; | |
1010 | } | |
4ab867d6 | 1011 | else |
920a3797 | 1012 | { |
bb7c2085 | 1013 | llcontbug ((message ("Expected c->orig->orig to be null"))); |
1014 | constraint_free (c->orig->orig); | |
920a3797 | 1015 | c->orig->orig = temp; |
1016 | temp = NULL; | |
1017 | } | |
4ab867d6 | 1018 | } |
1019 | else | |
1020 | { | |
bb7c2085 | 1021 | DPRINTF ((message ("Not changing constraint"))); |
4ab867d6 | 1022 | } |
d46ce6a4 | 1023 | |
bb7c2085 | 1024 | DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_printDetailed (c)))); |
4ab867d6 | 1025 | |
616915dd | 1026 | return c; |
1027 | } | |
1028 | /*@=fcnuse*/ | |
1029 | /*@=assignexpose*/ | |
1030 | /*@=czechfcns@*/ | |
84c9ffbf | 1031 | |
2934b455 | 1032 | |
84c9ffbf | 1033 | constraint constraint_togglePost (/*@returned@*/ constraint c) |
1034 | { | |
1035 | c->post = !c->post; | |
1036 | return c; | |
1037 | } | |
2934b455 | 1038 | |
1039 | constraint constraint_togglePostOrig (/*@returned@*/ constraint c) | |
1040 | { | |
1041 | if (c->orig != NULL) | |
bb7c2085 | 1042 | c->orig = constraint_togglePost (c->orig); |
2934b455 | 1043 | return c; |
1044 | } | |
1045 | ||
bb7c2085 | 1046 | bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c) |
2934b455 | 1047 | { |
1048 | if (c->orig == NULL) | |
1049 | return FALSE; | |
1050 | else | |
1051 | return TRUE; | |
1052 | } | |
920a3797 | 1053 | |
1054 | ||
1055 | constraint constraint_undump (FILE *f) | |
1056 | { | |
1057 | constraint c; | |
1058 | bool fcnPre; | |
1059 | bool post; | |
1060 | arithType ar; | |
1061 | ||
1062 | constraintExpr lexpr; | |
1063 | constraintExpr expr; | |
28bf4b0b | 1064 | |
920a3797 | 1065 | |
1066 | char * s; | |
1067 | ||
1068 | char *os; | |
1069 | ||
3be9a165 | 1070 | os = mstring_create (MAX_DUMP_LINE_LENGTH); |
920a3797 | 1071 | |
bb7c2085 | 1072 | s = fgets (os, MAX_DUMP_LINE_LENGTH, f); |
920a3797 | 1073 | |
1074 | /*@i33*/ /*this should probably be wrappered...*/ | |
1075 | ||
28bf4b0b | 1076 | fcnPre = (bool) reader_getInt (&s); |
bb7c2085 | 1077 | advanceField (&s); |
28bf4b0b | 1078 | post = (bool) reader_getInt (&s); |
bb7c2085 | 1079 | advanceField (&s); |
28bf4b0b | 1080 | ar = (arithType) reader_getInt (&s); |
920a3797 | 1081 | |
bb7c2085 | 1082 | s = fgets (os, MAX_DUMP_LINE_LENGTH, f); |
920a3797 | 1083 | |
28bf4b0b | 1084 | reader_checkChar (&s, 'l'); |
920a3797 | 1085 | |
1086 | lexpr = constraintExpr_undump (f); | |
1087 | ||
bb7c2085 | 1088 | s = fgets (os, MAX_DUMP_LINE_LENGTH, f); |
920a3797 | 1089 | |
28bf4b0b | 1090 | reader_checkChar (&s, 'r'); |
920a3797 | 1091 | expr = constraintExpr_undump (f); |
1092 | ||
bb7c2085 | 1093 | c = constraint_makeNew (); |
920a3797 | 1094 | |
1095 | c->fcnPre = fcnPre; | |
1096 | c->post = post; | |
1097 | c->ar = ar; | |
1098 | ||
1099 | c->lexpr = lexpr; | |
1100 | c->expr = expr; | |
1101 | ||
bb7c2085 | 1102 | free (os); |
1103 | c = constraint_preserveOrig (c); | |
920a3797 | 1104 | return c; |
1105 | } | |
1106 | ||
1107 | ||
1108 | void constraint_dump (/*@observer@*/ constraint c, FILE *f) | |
1109 | { | |
1110 | bool fcnPre; | |
1111 | bool post; | |
1112 | arithType ar; | |
1113 | ||
1114 | constraintExpr lexpr; | |
1115 | constraintExpr expr; | |
28bf4b0b | 1116 | |
920a3797 | 1117 | |
1118 | fcnPre = c->fcnPre; | |
1119 | post = c->post; | |
1120 | ar = c->ar; | |
1121 | lexpr = c->lexpr; | |
1122 | expr = c->expr; | |
1123 | ||
bb7c2085 | 1124 | fprintf (f, "%d@%d@%d\n", (int) fcnPre, (int) post, (int) ar); |
1125 | fprintf (f,"l\n"); | |
920a3797 | 1126 | constraintExpr_dump (lexpr, f); |
bb7c2085 | 1127 | fprintf (f,"r\n"); |
920a3797 | 1128 | constraintExpr_dump (expr, f); |
1129 | } | |
1130 | ||
1131 | ||
f4ec8018 | 1132 | int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint * c1, /*@observer@*/ /*@temp@*/ const constraint * c2) /*@*/ |
02984642 | 1133 | { |
1134 | fileloc loc1, loc2; | |
1135 | ||
1136 | int ret; | |
1137 | ||
bb7c2085 | 1138 | llassert (constraint_isDefined (*c1)); |
1139 | llassert (constraint_isDefined (*c2)); | |
02984642 | 1140 | |
bb7c2085 | 1141 | if (constraint_isUndefined (*c1)) |
02984642 | 1142 | { |
bb7c2085 | 1143 | if (constraint_isUndefined (*c2)) |
02984642 | 1144 | return 0; |
1145 | else | |
1146 | return 1; | |
1147 | } | |
1148 | ||
bb7c2085 | 1149 | if (constraint_isUndefined (*c2)) |
02984642 | 1150 | { |
1151 | return -1; | |
1152 | } | |
1153 | ||
bb7c2085 | 1154 | loc1 = constraint_getFileloc (*c1); |
1155 | loc2 = constraint_getFileloc (*c2); | |
02984642 | 1156 | |
bb7c2085 | 1157 | ret = fileloc_compare (loc1, loc2); |
02984642 | 1158 | |
bb7c2085 | 1159 | fileloc_free (loc1); |
1160 | fileloc_free (loc2); | |
02984642 | 1161 | |
1162 | return ret; | |
1163 | } | |
1164 | ||
1165 | ||
84380658 | 1166 | bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c) |
1167 | { | |
bb7c2085 | 1168 | llassert (constraint_isDefined (c)); |
84380658 | 1169 | |
bb7c2085 | 1170 | if (constraint_isUndefined (c)) |
84380658 | 1171 | return FALSE; |
1172 | ||
1173 | return (c->post); | |
1174 | } | |
a779b61e | 1175 | |
1176 | ||
bb7c2085 | 1177 | static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c) |
a779b61e | 1178 | { |
1179 | int l , r; | |
1180 | ||
bb7c2085 | 1181 | l = constraintExpr_getDepth (c->lexpr); |
1182 | r = constraintExpr_getDepth (c->expr); | |
a779b61e | 1183 | |
1184 | if (l > r) | |
1185 | { | |
bb7c2085 | 1186 | DPRINTF (( message ("constraint depth returning %d for %s", l, constraint_print (c)))); |
a779b61e | 1187 | return l; |
1188 | } | |
1189 | else | |
1190 | { | |
bb7c2085 | 1191 | DPRINTF (( message ("constraint depth returning %d for %s", r, constraint_print (c)))); |
a779b61e | 1192 | return r; |
1193 | } | |
1194 | } | |
1195 | ||
1196 | ||
1197 | bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c) | |
1198 | { | |
1199 | int temp; | |
1200 | ||
bb7c2085 | 1201 | temp = constraint_getDepth (c); |
a779b61e | 1202 | |
bb7c2085 | 1203 | if (temp >= 20) |
a779b61e | 1204 | { |
1205 | return TRUE; | |
1206 | } | |
1207 | ||
1208 | return FALSE; | |
1209 | ||
1210 | } |