2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
29 /* #define DEBUGPRINT 1 */
31 # include <ctype.h> /* for isdigit */
32 # include "splintMacros.nf"
34 # include "cgrammar.h"
35 # include "cgrammar_tokens.h"
37 # include "exprChecks.h"
38 # include "exprNodeSList.h"
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! */
47 static /*@only@*/ cstring constraint_printDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint p_c);
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 @*/;
55 advanceField (char **s)
57 reader_checkChar (s, '@');
61 static constraint makeConstraintParse2 (constraintExpr l, lltok relOp, exprNode cconstant)
66 ret = constraint_makeNew ();
67 llassert (constraintExpr_isDefined (l));
69 ret->lexpr = constraintExpr_copy (l);
72 if (relOp.tok == GE_OP)
74 else if (relOp.tok == LE_OP)
76 else if (relOp.tok == EQ_OP)
79 llfatalbug (message ("Unsupported relational operator"));
82 t = cstring_toCharsSafe (exprNode_unparse (cconstant));
84 ret->expr = constraintExpr_makeIntLiteral (c);
87 DPRINTF (("GENERATED CONSTRAINT:"));
88 DPRINTF ((message ("%s", constraint_print (ret))));
93 bool constraint_same (constraint c1, constraint c2)
95 llassert (c1 != NULL);
96 llassert (c2 != NULL);
103 if (!constraintExpr_similar (c1->lexpr, c2->lexpr))
108 if (!constraintExpr_similar (c1->expr, c2->expr))
116 constraint makeConstraintParse3 (constraintExpr l, lltok relOp, constraintExpr r)
119 ret = constraint_makeNew ();
120 llassert (constraintExpr_isDefined (l));
122 ret->lexpr = constraintExpr_copy (l);
124 if (lltok_getTok (relOp) == GE_OP)
128 else if (lltok_getTok (relOp) == LE_OP)
132 else if (lltok_getTok (relOp) == EQ_OP)
137 llfatalbug ( message ("Unsupported relational operator"));
139 ret->expr = constraintExpr_copy (r);
143 ret->orig = constraint_copy (ret);
145 ret = constraint_simplify (ret);
146 /* ret->orig = ret; */
148 DPRINTF (("GENERATED CONSTRAINT:"));
149 DPRINTF ((message ("%s", constraint_print (ret))));
153 constraint constraint_copy (/*@temp@*/ /*@observer@*/ constraint c)
157 llassert (constraint_isDefined (c));
159 ret = constraint_makeNew ();
160 ret->lexpr = constraintExpr_copy (c->lexpr);
162 ret->expr = constraintExpr_copy (c->expr);
165 ret->generatingExpr = c->generatingExpr;
170 ret->orig = constraint_copy (c->orig);
175 ret->or = constraint_copy (c->or);
179 ret->fcnPre = c->fcnPre;
184 /*like copy expect it doesn't allocate memory for the constraint*/
186 void constraint_overWrite (constraint c1, constraint c2)
188 llassert (constraint_isDefined (c1));
192 DPRINTF ((message ("OverWriteing constraint %q with %q", constraint_print (c1),
193 constraint_print (c2))));
195 constraintExpr_free (c1->lexpr);
196 constraintExpr_free (c1->expr);
198 c1->lexpr = constraintExpr_copy (c2->lexpr);
200 c1->expr = constraintExpr_copy (c2->expr);
203 if (c1->orig != NULL)
204 constraint_free (c1->orig);
206 if (c2->orig != NULL)
207 c1->orig = constraint_copy (c2->orig);
211 /*@i33 make sure that the or is freed correctly*/
213 constraint_free (c1->or);
216 c1->or = constraint_copy (c2->or);
220 c1->fcnPre = c2->fcnPre;
223 c1->generatingExpr = c2->generatingExpr;
229 static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void)
230 /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/
231 /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/
234 ret = dmalloc (sizeof (*ret));
241 ret->generatingExpr = NULL;
246 constraint constraint_addGeneratingExpr (/*@returned@*/ constraint c, /*@exposed@*/ exprNode e)
249 if (c->generatingExpr == NULL)
251 c->generatingExpr = e;
252 DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) ));
256 DPRINTF ((message ("Not setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) ));
261 constraint constraint_origAddGeneratingExpr (/*@returned@*/ constraint c, exprNode e)
264 if (c->orig != constraint_undefined)
266 c->orig = constraint_addGeneratingExpr (c->orig, e);
270 DPRINTF ((message ("constraint_origAddGeneratingExpr: Not setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) ));
275 constraint constraint_setFcnPre (/*@returned@*/ constraint c)
278 if (c->orig != constraint_undefined)
280 c->orig->fcnPre = TRUE;
285 DPRINTF (( message ("Warning Setting fcnPre directly")));
293 fileloc constraint_getFileloc (constraint c)
295 if (exprNode_isDefined (c->generatingExpr))
296 return (fileloc_copy (exprNode_getfileloc (c->generatingExpr)));
298 return (constraintExpr_getFileloc (c->lexpr));
303 static bool checkForMaxSet (constraint c)
305 if (constraintExpr_hasMaxSet (c->lexpr) || constraintExpr_hasMaxSet (c->expr))
311 bool constraint_hasMaxSet (constraint c)
313 if (checkForMaxSet (c))
318 if (checkForMaxSet (c->orig))
325 constraint constraint_makeReadSafeExprNode (exprNode po, exprNode ind)
327 constraint ret = constraint_makeNew ();
331 ret->lexpr = constraintExpr_makeMaxReadExpr (po);
333 ret->expr = constraintExpr_makeValueExpr (ind);
338 constraint constraint_makeWriteSafeInt ( exprNode po, int ind)
340 constraint ret = constraint_makeNew ();
343 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
345 ret->expr = constraintExpr_makeIntLiteral (ind);
349 constraint constraint_makeSRefSetBufferSize (sRef s, long int size)
351 constraint ret = constraint_makeNew ();
352 ret->lexpr = constraintExpr_makeSRefMaxset (s);
354 ret->expr = constraintExpr_makeIntLiteral ((int)size);
359 constraint constraint_makeSRefWriteSafeInt (sRef s, int ind)
361 constraint ret = constraint_makeNew ();
364 ret->lexpr = constraintExpr_makeSRefMaxset ( s);
366 ret->expr = constraintExpr_makeIntLiteral (ind);
371 /* drl added 01/12/2000
373 makes the constraint: Ensures index <= MaxRead (buffer) */
375 constraint constraint_makeEnsureLteMaxRead (exprNode index, exprNode buffer)
377 constraint ret = constraint_makeNew ();
379 ret->lexpr = constraintExpr_makeValueExpr (index);
381 ret->expr = constraintExpr_makeMaxReadExpr (buffer);
386 constraint constraint_makeWriteSafeExprNode (exprNode po, exprNode ind)
388 constraint ret = constraint_makeNew ();
391 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
393 ret->expr = constraintExpr_makeValueExpr (ind);
398 constraint constraint_makeReadSafeInt ( exprNode t1, int index)
400 constraint ret = constraint_makeNew ();
402 ret->lexpr = constraintExpr_makeMaxReadExpr (t1);
404 ret->expr = constraintExpr_makeIntLiteral (index);
409 constraint constraint_makeSRefReadSafeInt (sRef s, int ind)
411 constraint ret = constraint_makeNew ();
414 ret->lexpr = constraintExpr_makeSRefMaxRead (s);
416 ret->expr = constraintExpr_makeIntLiteral (ind);
421 constraint constraint_makeEnsureMaxReadAtLeast (exprNode t1, exprNode t2, fileloc sequencePoint)
425 ret = constraint_makeReadSafeExprNode (t1, t2);
426 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
432 static constraint constraint_makeEnsuresOpConstraintExpr (/*@only@*/ constraintExpr c1, /*@only@*/ constraintExpr c2, fileloc sequencePoint, arithType ar)
437 llassert (constraintExpr_isDefined (c1) && constraintExpr_isDefined (c2));
439 ret = constraint_makeNew ();
445 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
449 static constraint constraint_makeEnsuresOp (/*@dependent@*/ exprNode e1, /*@dependent@*/ exprNode e2, fileloc sequencePoint, arithType ar)
451 constraintExpr c1, c2;
455 if (! (exprNode_isDefined (e1) && exprNode_isDefined (e2)))
457 llcontbug ((message ("null exprNode, Exprnodes are %s and %s",
458 exprNode_unparse (e1), exprNode_unparse (e2))
463 c1 = constraintExpr_makeValueExpr (e);
466 c2 = constraintExpr_makeValueExpr (e);
468 ret = constraint_makeEnsuresOpConstraintExpr (c1, c2, sequencePoint, ar);
474 /* make constraint ensures e1 == e2 */
476 constraint constraint_makeEnsureEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
478 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, EQ));
481 /*make constraint ensures e1 < e2 */
482 constraint constraint_makeEnsureLessThan (exprNode e1, exprNode e2, fileloc sequencePoint)
484 constraintExpr t1, t2;
487 t1 = constraintExpr_makeValueExpr (e1);
488 t2 = constraintExpr_makeValueExpr (e2);
490 /*change this to e1 <= (e2 -1) */
492 t2 = constraintExpr_makeDecConstraintExpr (t2);
494 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, LTE);
496 t3 = constraint_simplify(t3);
500 constraint constraint_makeEnsureLessThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
502 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, LTE));
505 constraint constraint_makeEnsureGreaterThan (exprNode e1, exprNode e2, fileloc sequencePoint)
507 constraintExpr t1, t2;
510 t1 = constraintExpr_makeValueExpr (e1);
511 t2 = constraintExpr_makeValueExpr (e2);
514 /* change this to e1 >= (e2 + 1) */
515 t2 = constraintExpr_makeIncConstraintExpr (t2);
517 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, GTE);
519 t3 = constraint_simplify(t3);
524 constraint constraint_makeEnsureGreaterThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
526 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, GTE));
530 exprNode exprNode_copyConstraints (/*@returned@*/ exprNode dst, exprNode src)
532 constraintList_free (dst->ensuresConstraints);
533 constraintList_free (dst->requiresConstraints);
534 constraintList_free (dst->trueEnsuresConstraints);
535 constraintList_free (dst->falseEnsuresConstraints);
537 dst->ensuresConstraints = constraintList_copy (src->ensuresConstraints);
538 dst->requiresConstraints = constraintList_copy (src->requiresConstraints);
539 dst->trueEnsuresConstraints = constraintList_copy (src->trueEnsuresConstraints);
540 dst->falseEnsuresConstraints = constraintList_copy (src->falseEnsuresConstraints);
544 /* Makes the constraint e = e + f */
545 constraint constraint_makeAddAssign (exprNode e, exprNode f, fileloc sequencePoint)
547 constraintExpr x1, x2, y;
550 ret = constraint_makeNew ();
552 x1 = constraintExpr_makeValueExpr (e);
553 x2 = constraintExpr_copy (x1);
554 y = constraintExpr_makeValueExpr (f);
559 ret->expr = constraintExpr_makeAddExpr (x2, y);
561 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
567 /* Makes the constraint e = e - f */
568 constraint constraint_makeSubtractAssign (exprNode e, exprNode f, fileloc sequencePoint)
570 constraintExpr x1, x2, y;
573 ret = constraint_makeNew ();
575 x1 = constraintExpr_makeValueExpr (e);
576 x2 = constraintExpr_copy (x1);
577 y = constraintExpr_makeValueExpr (f);
582 ret->expr = constraintExpr_makeSubtractExpr (x2, y);
584 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
589 constraint constraint_makeMaxSetSideEffectPostDecrement (exprNode e, fileloc sequencePoint)
591 constraint ret = constraint_makeNew ();
593 ret->lexpr = constraintExpr_makeValueExpr (e);
596 ret->expr = constraintExpr_makeValueExpr (e);
597 ret->expr = constraintExpr_makeDecConstraintExpr (ret->expr);
598 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
601 constraint constraint_makeMaxSetSideEffectPostIncrement (exprNode e, fileloc sequencePoint)
603 constraint ret = constraint_makeNew ();
605 ret->lexpr = constraintExpr_makeValueExpr (e);
608 ret->expr = constraintExpr_makeValueExpr (e);
609 ret->expr = constraintExpr_makeIncConstraintExpr (ret->expr);
611 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
616 void constraint_free (/*@only@*/ constraint c)
618 llassert (constraint_isDefined (c));
621 if (constraint_isDefined (c->orig))
622 constraint_free (c->orig);
623 if ( constraint_isDefined (c->or))
624 constraint_free (c->or);
627 constraintExpr_free (c->lexpr);
628 constraintExpr_free (c->expr);
639 cstring arithType_print (arithType ar) /*@*/
641 cstring st = cstring_undefined;
645 st = cstring_makeLiteral ("<");
648 st = cstring_makeLiteral ("<=");
651 st = cstring_makeLiteral (">");
654 st = cstring_makeLiteral (">=");
657 st = cstring_makeLiteral ("==");
660 st = cstring_makeLiteral ("NONNEGATIVE");
663 st = cstring_makeLiteral ("POSITIVE");
672 void constraint_printErrorPostCondition (constraint c, fileloc loc)
675 fileloc errorLoc, temp;
677 string = constraint_printDetailedPostCondition (c);
683 temp = constraint_getFileloc (c);
686 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
688 string = cstring_replaceChar(string, '\n', ' ');
691 if (fileloc_isDefined (temp))
694 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
699 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
703 /*drl added 8-11-001*/
704 cstring constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c) /*@*/
709 string = constraint_print (c);
711 errorLoc = constraint_getFileloc (c);
713 ret = message ("constraint: %q @ %q", string, fileloc_unparse (errorLoc));
715 fileloc_free (errorLoc);
722 void constraint_printError (constraint c, fileloc loc)
725 fileloc errorLoc, temp;
729 /*drl 11/26/2001 avoid printing tautological constraints */
730 if (constraint_isAlwaysTrue (c))
736 string = constraint_printDetailed (c);
740 temp = constraint_getFileloc (c);
742 if (fileloc_isDefined (temp))
749 DPRINTF (("constraint %s had undefined fileloc %s", constraint_print (c), fileloc_unparse (temp)));
751 errorLoc = fileloc_copy (errorLoc);
755 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
757 string = cstring_replaceChar(string, '\n', ' ');
760 /*drl added 12/19/2002 print
761 a different error fro "likely" bounds-errors*/
763 isLikely = constraint_isConstantOnly(c);
769 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
773 if (constraint_hasMaxSet (c))
775 voptgenerror (FLG_LIKELYBOUNDSWRITE, string, errorLoc);
779 voptgenerror (FLG_LIKELYBOUNDSREAD, string, errorLoc);
785 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
789 if (constraint_hasMaxSet (c))
791 voptgenerror (FLG_BOUNDSWRITE, string, errorLoc);
795 voptgenerror (FLG_BOUNDSREAD, string, errorLoc);
799 fileloc_free(errorLoc);
802 static cstring constraint_printDeep (constraint c)
805 cstring st = cstring_undefined;
807 st = constraint_print(c);
809 if (c->orig != constraint_undefined)
811 st = cstring_appendChar (st, '\n');
812 genExpr = exprNode_unparse (c->orig->generatingExpr);
818 st = cstring_concatFree (st, message (" derived from %s precondition: %q",
819 genExpr, constraint_printDeep (c->orig)));
823 st = cstring_concatFree (st, message (" needed to satisfy precondition:\n%q",
824 constraint_printDeep (c->orig)));
829 st = cstring_concatFree (st, message ("derived from: %q",
830 constraint_printDeep (c->orig)));
838 static /*@only@*/ cstring constraint_printDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c)
840 cstring st = cstring_undefined;
843 st = message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q", constraint_printDeep (c));
845 genExpr = exprNode_unparse (c->generatingExpr);
847 if (context_getFlag (FLG_CONSTRAINTLOCATION))
851 temp = message ("\nOriginal Generating expression %q: %s\n",
852 fileloc_unparse ( exprNode_getfileloc (c->generatingExpr)),
854 st = cstring_concatFree (st, temp);
856 if (constraint_hasMaxSet (c))
858 temp = message ("Has MaxSet\n");
859 st = cstring_concatFree (st, temp);
865 cstring constraint_printDetailed (constraint c)
867 cstring st = cstring_undefined;
868 cstring temp = cstring_undefined;
874 st = message ("Unable to resolve constraint:\n%q", constraint_printDeep (c));
878 st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_printDeep (c));
881 isLikely = constraint_isConstantOnly(c);
885 if (constraint_hasMaxSet (c))
887 temp = cstring_makeLiteral ("Likely out-of-bounds store:\n");
891 temp = cstring_makeLiteral ("Likely out-of-bounds read:\n");
897 if (constraint_hasMaxSet (c))
899 temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
903 temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
907 genExpr = exprNode_unparse (c->generatingExpr);
909 if (context_getFlag (FLG_CONSTRAINTLOCATION))
912 temp2 = message ("%s\n", genExpr);
913 temp = cstring_concatFree (temp, temp2);
916 st = cstring_concatFree (temp,st);
921 /*@only@*/ cstring constraint_print (constraint c) /*@*/
923 cstring st = cstring_undefined;
924 cstring type = cstring_undefined;
928 if (context_getFlag (FLG_PARENCONSTRAINT))
930 type = cstring_makeLiteral ("ensures: ");
934 type = cstring_makeLiteral ("ensures");
939 if (context_getFlag (FLG_PARENCONSTRAINT))
941 type = cstring_makeLiteral ("requires: ");
945 type = cstring_makeLiteral ("requires");
949 if (context_getFlag (FLG_PARENCONSTRAINT))
951 st = message ("%q: %q %q %q",
953 constraintExpr_print (c->lexpr),
954 arithType_print (c->ar),
955 constraintExpr_print (c->expr)
960 st = message ("%q %q %q %q",
962 constraintExpr_print (c->lexpr),
963 arithType_print (c->ar),
964 constraintExpr_print (c->expr)
970 cstring constraint_printOr (constraint c) /*@*/
975 ret = cstring_undefined;
978 ret = cstring_concatFree (ret, constraint_print (temp));
982 while ( constraint_isDefined (temp))
984 ret = cstring_concatFree (ret, cstring_makeLiteral (" OR "));
985 ret = cstring_concatFree (ret, constraint_print (temp));
993 /*@only@*/ constraint constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition,
994 exprNodeList arglist)
996 precondition->lexpr = constraintExpr_doSRefFixBaseParam (precondition->lexpr,
998 precondition->expr = constraintExpr_doSRefFixBaseParam (precondition->expr,
1001 return precondition;
1005 constraint constraint_doFixResult (constraint postcondition, /*@dependent@*/ exprNode fcnCall)
1007 postcondition = constraint_copy (postcondition);
1008 postcondition->lexpr = constraintExpr_doFixResult (postcondition->lexpr, fcnCall);
1009 postcondition->expr = constraintExpr_doFixResult (postcondition->expr, fcnCall);
1011 return postcondition;
1013 /*Commenting out temporally
1015 / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct )
1018 invar = constraint_copy (invar);
1019 invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct);
1020 invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct);
1026 /*@only@*/ constraint constraint_doSRefFixConstraintParam (constraint precondition,
1027 exprNodeList arglist)
1030 precondition = constraint_copy (precondition);
1031 precondition->lexpr = constraintExpr_doSRefFixConstraintParam (precondition->lexpr, arglist);
1032 precondition->expr = constraintExpr_doSRefFixConstraintParam (precondition->expr, arglist);
1034 precondition->fcnPre = FALSE;
1035 return constraint_simplify(precondition);
1038 constraint constraint_preserveOrig (/*@returned@*/ constraint c) /*@modifies c @*/
1041 DPRINTF ((message ("Doing constraint_preserverOrig for %q ", constraint_printDetailed (c))));
1043 if (c->orig == constraint_undefined)
1044 c->orig = constraint_copy (c);
1046 else if (c->orig->fcnPre)
1052 /* avoid infinite loop */
1054 c->orig = constraint_copy (c);
1055 if (c->orig->orig == NULL)
1057 c->orig->orig = temp;
1062 llcontbug ((message ("Expected c->orig->orig to be null")));
1063 constraint_free (c->orig->orig);
1064 c->orig->orig = temp;
1070 DPRINTF ((message ("Not changing constraint")));
1073 DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_printDetailed (c))));
1082 constraint constraint_togglePost (/*@returned@*/ constraint c)
1088 constraint constraint_togglePostOrig (/*@returned@*/ constraint c)
1090 if (c->orig != NULL)
1091 c->orig = constraint_togglePost (c->orig);
1095 bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c)
1097 if (c->orig == NULL)
1104 constraint constraint_undump (FILE *f)
1111 constraintExpr lexpr;
1112 constraintExpr expr;
1119 os = mstring_create (MAX_DUMP_LINE_LENGTH);
1121 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1123 /*@i33*/ /*this should probably be wrappered...*/
1125 fcnPre = (bool) reader_getInt (&s);
1127 post = (bool) reader_getInt (&s);
1129 ar = (arithType) reader_getInt (&s);
1131 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1133 reader_checkChar (&s, 'l');
1135 lexpr = constraintExpr_undump (f);
1137 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1139 reader_checkChar (&s, 'r');
1140 expr = constraintExpr_undump (f);
1142 c = constraint_makeNew ();
1152 c = constraint_preserveOrig (c);
1157 void constraint_dump (/*@observer@*/ constraint c, FILE *f)
1163 constraintExpr lexpr;
1164 constraintExpr expr;
1173 fprintf (f, "%d@%d@%d\n", (int) fcnPre, (int) post, (int) ar);
1175 constraintExpr_dump (lexpr, f);
1177 constraintExpr_dump (expr, f);
1181 int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint * c1, /*@observer@*/ /*@temp@*/ const constraint * c2) /*@*/
1187 llassert (constraint_isDefined (*c1));
1188 llassert (constraint_isDefined (*c2));
1190 if (constraint_isUndefined (*c1))
1192 if (constraint_isUndefined (*c2))
1198 if (constraint_isUndefined (*c2))
1203 loc1 = constraint_getFileloc (*c1);
1204 loc2 = constraint_getFileloc (*c2);
1206 ret = fileloc_compare (loc1, loc2);
1208 fileloc_free (loc1);
1209 fileloc_free (loc2);
1215 bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c)
1217 llassert (constraint_isDefined (c));
1219 if (constraint_isUndefined (c))
1226 static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c)
1230 l = constraintExpr_getDepth (c->lexpr);
1231 r = constraintExpr_getDepth (c->expr);
1235 DPRINTF (( message ("constraint depth returning %d for %s", l, constraint_print (c))));
1240 DPRINTF (( message ("constraint depth returning %d for %s", r, constraint_print (c))));
1246 bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c)
1250 temp = constraint_getDepth (c);
1261 /*drl added 12/19/2002*/
1262 /*whether constraints consist only of
1263 terms which are constants*/
1264 bool constraint_isConstantOnly (constraint c)
1268 l = constraintExpr_isConstantOnly(c->lexpr);
1269 r = constraintExpr_isConstantOnly(c->expr);