2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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"
41 static /*@only@*/ cstring constraint_printDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint p_c);
44 static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void)
45 /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/
46 /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/;
49 advanceField (char **s)
51 reader_checkChar (s, '@');
55 static constraint makeConstraintParse2 (constraintExpr l, lltok relOp, exprNode cconstant)
60 ret = constraint_makeNew ();
61 llassert (constraintExpr_isDefined (l));
63 ret->lexpr = constraintExpr_copy (l);
66 if (relOp.tok == GE_OP)
68 else if (relOp.tok == LE_OP)
70 else if (relOp.tok == EQ_OP)
73 llfatalbug (message ("Unsupported relational operator"));
76 t = cstring_toCharsSafe (exprNode_unparse (cconstant));
78 ret->expr = constraintExpr_makeIntLiteral (c);
81 DPRINTF (("GENERATED CONSTRAINT:"));
82 DPRINTF ((message ("%s", constraint_print (ret))));
87 bool constraint_same (constraint c1, constraint c2)
89 llassert (c1 != NULL);
90 llassert (c2 != NULL);
97 if (!constraintExpr_similar (c1->lexpr, c2->lexpr))
102 if (!constraintExpr_similar (c1->expr, c2->expr))
110 constraint makeConstraintParse3 (constraintExpr l, lltok relOp, constraintExpr r)
113 ret = constraint_makeNew ();
114 llassert (constraintExpr_isDefined (l));
116 ret->lexpr = constraintExpr_copy (l);
118 if (lltok_getTok (relOp) == GE_OP)
122 else if (lltok_getTok (relOp) == LE_OP)
126 else if (lltok_getTok (relOp) == EQ_OP)
131 llfatalbug ( message ("Unsupported relational operator"));
133 ret->expr = constraintExpr_copy (r);
137 ret->orig = constraint_copy (ret);
139 ret = constraint_simplify (ret);
140 /* ret->orig = ret; */
142 DPRINTF (("GENERATED CONSTRAINT:"));
143 DPRINTF ((message ("%s", constraint_print (ret))));
147 constraint constraint_copy (/*@temp@*/ /*@observer@*/ constraint c)
151 llassert (constraint_isDefined (c));
153 ret = constraint_makeNew ();
154 ret->lexpr = constraintExpr_copy (c->lexpr);
156 ret->expr = constraintExpr_copy (c->expr);
159 ret->generatingExpr = c->generatingExpr;
164 ret->orig = constraint_copy (c->orig);
169 ret->or = constraint_copy (c->or);
173 ret->fcnPre = c->fcnPre;
178 /*like copy expect it doesn't allocate memory for the constraint*/
180 void constraint_overWrite (constraint c1, constraint c2)
182 llassert (constraint_isDefined (c1) && constraint_isDefined (c2));
186 DPRINTF ((message ("OverWriteing constraint %q with %q", constraint_print (c1),
187 constraint_print (c2))));
189 constraintExpr_free (c1->lexpr);
190 constraintExpr_free (c1->expr);
192 c1->lexpr = constraintExpr_copy (c2->lexpr);
194 c1->expr = constraintExpr_copy (c2->expr);
197 if (c1->orig != NULL)
198 constraint_free (c1->orig);
200 if (c2->orig != NULL)
201 c1->orig = constraint_copy (c2->orig);
205 /*@i33 make sure that the or is freed correctly*/
207 constraint_free (c1->or);
210 c1->or = constraint_copy (c2->or);
214 c1->fcnPre = c2->fcnPre;
217 c1->generatingExpr = c2->generatingExpr;
223 static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void)
224 /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/
225 /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/
228 ret = dmalloc (sizeof (*ret));
235 ret->generatingExpr = NULL;
240 /*@access exprNode@*/
242 constraint constraint_addGeneratingExpr (/*@returned@*/ constraint c, /*@exposed@*/ exprNode e)
245 llassert (constraint_isDefined (c) );
247 if (c->generatingExpr == NULL)
249 c->generatingExpr = e;
250 DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) ));
254 DPRINTF ((message ("Not setting generatingExpr for %s to %s", constraint_print (c), exprNode_unparse (e)) ));
258 /*@noaccess exprNode@*/
260 constraint constraint_origAddGeneratingExpr (/*@returned@*/ constraint c, exprNode e)
262 llassert (constraint_isDefined (c) );
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 llassert (constraint_isDefined (c) );
280 if (c->orig != constraint_undefined)
282 c->orig->fcnPre = TRUE;
287 DPRINTF (( message ("Warning Setting fcnPre directly")));
295 fileloc constraint_getFileloc (constraint c)
298 llassert (constraint_isDefined (c) );
300 if (exprNode_isDefined (c->generatingExpr))
301 return (fileloc_copy (exprNode_getfileloc (c->generatingExpr)));
303 return (constraintExpr_getFileloc (c->lexpr));
308 static bool checkForMaxSet (constraint c)
311 llassert (constraint_isDefined (c) );
313 if (constraintExpr_hasMaxSet (c->lexpr) || constraintExpr_hasMaxSet (c->expr))
319 bool constraint_hasMaxSet (constraint c)
322 llassert (constraint_isDefined (c) );
324 if (checkForMaxSet (c))
329 if (checkForMaxSet (c->orig))
336 constraint constraint_makeReadSafeExprNode (exprNode po, exprNode ind)
338 constraint ret = constraint_makeNew ();
342 ret->lexpr = constraintExpr_makeMaxReadExpr (po);
344 ret->expr = constraintExpr_makeValueExpr (ind);
349 constraint constraint_makeWriteSafeInt ( exprNode po, int ind)
351 constraint ret = constraint_makeNew ();
354 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
356 ret->expr = constraintExpr_makeIntLiteral (ind);
360 constraint constraint_makeSRefSetBufferSize (sRef s, long int size)
362 constraint ret = constraint_makeNew ();
363 ret->lexpr = constraintExpr_makeSRefMaxset (s);
365 ret->expr = constraintExpr_makeIntLiteral ((int)size);
371 constraint constraint_makeSRefWriteSafeInt (sRef s, int ind)
373 constraint ret = constraint_makeNew ();
376 ret->lexpr = constraintExpr_makeSRefMaxset ( s);
378 ret->expr = constraintExpr_makeIntLiteral (ind);
384 /* drl added 01/12/2000
386 makes the constraint: Ensures index <= MaxRead (buffer) */
388 constraint constraint_makeEnsureLteMaxRead (exprNode index, exprNode buffer)
390 constraint ret = constraint_makeNew ();
392 ret->lexpr = constraintExpr_makeValueExpr (index);
394 ret->expr = constraintExpr_makeMaxReadExpr (buffer);
399 constraint constraint_makeWriteSafeExprNode (exprNode po, exprNode ind)
401 constraint ret = constraint_makeNew ();
404 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
406 ret->expr = constraintExpr_makeValueExpr (ind);
411 constraint constraint_makeReadSafeInt ( exprNode t1, int index)
413 constraint ret = constraint_makeNew ();
415 ret->lexpr = constraintExpr_makeMaxReadExpr (t1);
417 ret->expr = constraintExpr_makeIntLiteral (index);
422 constraint constraint_makeSRefReadSafeInt (sRef s, int ind)
424 constraint ret = constraint_makeNew ();
427 ret->lexpr = constraintExpr_makeSRefMaxRead (s);
429 ret->expr = constraintExpr_makeIntLiteral (ind);
434 constraint constraint_makeEnsureMaxReadAtLeast (exprNode t1, exprNode t2, fileloc sequencePoint)
438 ret = constraint_makeReadSafeExprNode (t1, t2);
439 llassert (constraint_isDefined (ret) );
441 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
447 static constraint constraint_makeEnsuresOpConstraintExpr (/*@only@*/ constraintExpr c1, /*@only@*/ constraintExpr c2, fileloc sequencePoint, arithType ar)
452 llassert (constraintExpr_isDefined (c1) && constraintExpr_isDefined (c2));
454 ret = constraint_makeNew ();
460 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
464 static constraint constraint_makeEnsuresOp (/*@dependent@*/ exprNode e1, /*@dependent@*/ exprNode e2, fileloc sequencePoint, arithType ar)
466 constraintExpr c1, c2;
470 if (! (exprNode_isDefined (e1) && exprNode_isDefined (e2)))
472 llcontbug ((message ("null exprNode, Exprnodes are %s and %s",
473 exprNode_unparse (e1), exprNode_unparse (e2))
478 c1 = constraintExpr_makeValueExpr (e);
481 c2 = constraintExpr_makeValueExpr (e);
483 ret = constraint_makeEnsuresOpConstraintExpr (c1, c2, sequencePoint, ar);
489 /* make constraint ensures e1 == e2 */
491 constraint constraint_makeEnsureEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
493 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, EQ));
496 /*make constraint ensures e1 < e2 */
497 constraint constraint_makeEnsureLessThan (exprNode e1, exprNode e2, fileloc sequencePoint)
499 constraintExpr t1, t2;
502 t1 = constraintExpr_makeValueExpr (e1);
503 t2 = constraintExpr_makeValueExpr (e2);
505 /*change this to e1 <= (e2 -1) */
507 t2 = constraintExpr_makeDecConstraintExpr (t2);
509 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, LTE);
511 t3 = constraint_simplify(t3);
515 constraint constraint_makeEnsureLessThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
517 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, LTE));
520 constraint constraint_makeEnsureGreaterThan (exprNode e1, exprNode e2, fileloc sequencePoint)
522 constraintExpr t1, t2;
525 t1 = constraintExpr_makeValueExpr (e1);
526 t2 = constraintExpr_makeValueExpr (e2);
529 /* change this to e1 >= (e2 + 1) */
530 t2 = constraintExpr_makeIncConstraintExpr (t2);
532 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, GTE);
534 t3 = constraint_simplify(t3);
539 constraint constraint_makeEnsureGreaterThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
541 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, GTE));
546 /* Makes the constraint e = e + f */
547 constraint constraint_makeAddAssign (exprNode e, exprNode f, fileloc sequencePoint)
549 constraintExpr x1, x2, y;
552 ret = constraint_makeNew ();
554 x1 = constraintExpr_makeValueExpr (e);
555 x2 = constraintExpr_copy (x1);
556 y = constraintExpr_makeValueExpr (f);
561 ret->expr = constraintExpr_makeAddExpr (x2, y);
563 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
569 /* Makes the constraint e = e - f */
570 constraint constraint_makeSubtractAssign (exprNode e, exprNode f, fileloc sequencePoint)
572 constraintExpr x1, x2, y;
575 ret = constraint_makeNew ();
577 x1 = constraintExpr_makeValueExpr (e);
578 x2 = constraintExpr_copy (x1);
579 y = constraintExpr_makeValueExpr (f);
584 ret->expr = constraintExpr_makeSubtractExpr (x2, y);
586 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
591 constraint constraint_makeMaxSetSideEffectPostDecrement (exprNode e, fileloc sequencePoint)
593 constraint ret = constraint_makeNew ();
595 ret->lexpr = constraintExpr_makeValueExpr (e);
598 ret->expr = constraintExpr_makeValueExpr (e);
599 ret->expr = constraintExpr_makeDecConstraintExpr (ret->expr);
600 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
603 constraint constraint_makeMaxSetSideEffectPostIncrement (exprNode e, fileloc sequencePoint)
605 constraint ret = constraint_makeNew ();
607 ret->lexpr = constraintExpr_makeValueExpr (e);
610 ret->expr = constraintExpr_makeValueExpr (e);
611 ret->expr = constraintExpr_makeIncConstraintExpr (ret->expr);
613 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
618 void constraint_free (/*@only@*/ constraint c)
620 llassert (constraint_isDefined (c));
623 if (constraint_isDefined (c->orig))
624 constraint_free (c->orig);
625 if ( constraint_isDefined (c->or))
626 constraint_free (c->or);
629 constraintExpr_free (c->lexpr);
630 constraintExpr_free (c->expr);
641 cstring arithType_print (arithType ar) /*@*/
643 cstring st = cstring_undefined;
647 st = cstring_makeLiteral ("<");
650 st = cstring_makeLiteral ("<=");
653 st = cstring_makeLiteral (">");
656 st = cstring_makeLiteral (">=");
659 st = cstring_makeLiteral ("==");
662 st = cstring_makeLiteral ("NONNEGATIVE");
665 st = cstring_makeLiteral ("POSITIVE");
674 void constraint_printErrorPostCondition (constraint c, fileloc loc)
677 fileloc errorLoc, temp;
679 string = constraint_printDetailedPostCondition (c);
685 temp = constraint_getFileloc (c);
688 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
690 string = cstring_replaceChar(string, '\n', ' ');
693 if (fileloc_isDefined (temp))
696 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
701 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
705 /*drl added 8-11-001*/
706 cstring constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c) /*@*/
711 string = constraint_print (c);
713 errorLoc = constraint_getFileloc (c);
715 ret = message ("constraint: %q @ %q", string, fileloc_unparse (errorLoc));
717 fileloc_free (errorLoc);
724 void constraint_printError (constraint c, fileloc loc)
727 fileloc errorLoc, temp;
732 llassert (constraint_isDefined (c) );
734 /*drl 11/26/2001 avoid printing tautological constraints */
735 if (constraint_isAlwaysTrue (c))
741 string = constraint_printDetailed (c);
745 temp = constraint_getFileloc (c);
747 if (fileloc_isDefined (temp))
754 DPRINTF (("constraint %s had undefined fileloc %s", constraint_print (c), fileloc_unparse (temp)));
756 errorLoc = fileloc_copy (errorLoc);
760 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
762 string = cstring_replaceChar(string, '\n', ' ');
765 /*drl added 12/19/2002 print
766 a different error fro "likely" bounds-errors*/
768 isLikely = constraint_isConstantOnly(c);
774 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
778 if (constraint_hasMaxSet (c))
780 voptgenerror (FLG_LIKELYBOUNDSWRITE, string, errorLoc);
784 voptgenerror (FLG_LIKELYBOUNDSREAD, string, errorLoc);
790 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
794 if (constraint_hasMaxSet (c))
796 voptgenerror (FLG_BOUNDSWRITE, string, errorLoc);
800 voptgenerror (FLG_BOUNDSREAD, string, errorLoc);
804 fileloc_free(errorLoc);
807 static cstring constraint_printDeep (constraint c)
810 cstring st = cstring_undefined;
813 llassert (constraint_isDefined (c) );
816 st = constraint_print(c);
818 if (c->orig != constraint_undefined)
820 st = cstring_appendChar (st, '\n');
821 genExpr = exprNode_unparse (c->orig->generatingExpr);
827 st = cstring_concatFree (st, message (" derived from %s precondition: %q",
828 genExpr, constraint_printDeep (c->orig)));
832 st = cstring_concatFree (st, message (" needed to satisfy precondition:\n%q",
833 constraint_printDeep (c->orig)));
838 st = cstring_concatFree (st, message ("derived from: %q",
839 constraint_printDeep (c->orig)));
847 static /*@only@*/ cstring constraint_printDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c)
849 cstring st = cstring_undefined;
853 llassert (constraint_isDefined (c) );
855 st = message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q", constraint_printDeep (c));
857 genExpr = exprNode_unparse (c->generatingExpr);
859 if (context_getFlag (FLG_CONSTRAINTLOCATION))
863 temp = message ("\nOriginal Generating expression %q: %s\n",
864 fileloc_unparse ( exprNode_getfileloc (c->generatingExpr)),
866 st = cstring_concatFree (st, temp);
868 if (constraint_hasMaxSet (c))
870 temp = message ("Has MaxSet\n");
871 st = cstring_concatFree (st, temp);
877 cstring constraint_printDetailed (constraint c)
879 cstring st = cstring_undefined;
880 cstring temp = cstring_undefined;
884 llassert (constraint_isDefined (c) );
888 st = message ("Unable to resolve constraint:\n%q", constraint_printDeep (c));
892 st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_printDeep (c));
895 isLikely = constraint_isConstantOnly(c);
899 if (constraint_hasMaxSet (c))
901 temp = cstring_makeLiteral ("Likely out-of-bounds store:\n");
905 temp = cstring_makeLiteral ("Likely out-of-bounds read:\n");
911 if (constraint_hasMaxSet (c))
913 temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
917 temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
921 genExpr = exprNode_unparse (c->generatingExpr);
923 if (context_getFlag (FLG_CONSTRAINTLOCATION))
926 temp2 = message ("%s\n", genExpr);
927 temp = cstring_concatFree (temp, temp2);
930 st = cstring_concatFree (temp,st);
935 /*@only@*/ cstring constraint_print (constraint c) /*@*/
937 cstring st = cstring_undefined;
938 cstring type = cstring_undefined;
942 if (context_getFlag (FLG_PARENCONSTRAINT))
944 type = cstring_makeLiteral ("ensures: ");
948 type = cstring_makeLiteral ("ensures");
953 if (context_getFlag (FLG_PARENCONSTRAINT))
955 type = cstring_makeLiteral ("requires: ");
959 type = cstring_makeLiteral ("requires");
963 if (context_getFlag (FLG_PARENCONSTRAINT))
965 st = message ("%q: %q %q %q",
967 constraintExpr_print (c->lexpr),
968 arithType_print (c->ar),
969 constraintExpr_print (c->expr)
974 st = message ("%q %q %q %q",
976 constraintExpr_print (c->lexpr),
977 arithType_print (c->ar),
978 constraintExpr_print (c->expr)
984 cstring constraint_printOr (constraint c) /*@*/
989 ret = cstring_undefined;
991 llassert (constraint_isDefined (c) );
995 ret = cstring_concatFree (ret, constraint_print (temp));
999 while ( constraint_isDefined (temp))
1001 ret = cstring_concatFree (ret, cstring_makeLiteral (" OR "));
1002 ret = cstring_concatFree (ret, constraint_print (temp));
1010 /*@only@*/ constraint constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition,
1011 exprNodeList arglist)
1014 llassert (constraint_isDefined (precondition) );
1016 precondition->lexpr = constraintExpr_doSRefFixBaseParam (precondition->lexpr,
1018 precondition->expr = constraintExpr_doSRefFixBaseParam (precondition->expr,
1021 return precondition;
1025 constraint constraint_doFixResult (constraint postcondition, /*@dependent@*/ exprNode fcnCall)
1027 postcondition = constraint_copy (postcondition);
1029 llassert (constraint_isDefined (postcondition) );
1032 postcondition->lexpr = constraintExpr_doFixResult (postcondition->lexpr, fcnCall);
1033 postcondition->expr = constraintExpr_doFixResult (postcondition->expr, fcnCall);
1035 return postcondition;
1037 /*Commenting out temporally
1039 / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct )
1042 invar = constraint_copy (invar);
1043 invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct);
1044 invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct);
1050 /*@only@*/ constraint constraint_doSRefFixConstraintParam (constraint precondition,
1051 exprNodeList arglist)
1054 precondition = constraint_copy (precondition);
1056 llassert (constraint_isDefined (precondition) );
1058 precondition->lexpr = constraintExpr_doSRefFixConstraintParam (precondition->lexpr, arglist);
1059 precondition->expr = constraintExpr_doSRefFixConstraintParam (precondition->expr, arglist);
1061 precondition->fcnPre = FALSE;
1062 return constraint_simplify(precondition);
1065 constraint constraint_preserveOrig (/*@returned@*/ constraint c) /*@modifies c @*/
1068 DPRINTF ((message ("Doing constraint_preserverOrig for %q ", constraint_printDetailed (c))));
1070 llassert (constraint_isDefined (c) );
1072 if (c->orig == constraint_undefined)
1073 c->orig = constraint_copy (c);
1075 else if (c->orig->fcnPre)
1081 /* avoid infinite loop */
1083 c->orig = constraint_copy (c);
1084 /*drl 03/2/2003 if c != NULL then the copy of c will != null*/
1085 llassert (constraint_isDefined (c->orig) );
1087 if (c->orig->orig == NULL)
1089 c->orig->orig = temp;
1094 llcontbug ((message ("Expected c->orig->orig to be null")));
1095 constraint_free (c->orig->orig);
1096 c->orig->orig = temp;
1102 DPRINTF ((message ("Not changing constraint")));
1105 DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_printDetailed (c))));
1114 constraint constraint_togglePost (/*@returned@*/ constraint c)
1116 llassert (constraint_isDefined (c) );
1122 constraint constraint_togglePostOrig (/*@returned@*/ constraint c)
1124 llassert (constraint_isDefined (c) );
1126 if (c->orig != NULL)
1127 c->orig = constraint_togglePost (c->orig);
1131 bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c)
1134 llassert (constraint_isDefined (c) );
1136 if (c->orig == NULL)
1143 constraint constraint_undump (FILE *f)
1150 constraintExpr lexpr;
1151 constraintExpr expr;
1158 os = mstring_create (MAX_DUMP_LINE_LENGTH);
1160 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1162 if (! mstring_isDefined(s) )
1164 llfatalbug(message("Library file is corrupted") );
1167 fcnPre = (bool) reader_getInt (&s);
1169 post = (bool) reader_getInt (&s);
1171 ar = (arithType) reader_getInt (&s);
1173 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1175 if (! mstring_isDefined(s) )
1177 llfatalbug(message("Library file is corrupted") );
1180 reader_checkChar (&s, 'l');
1182 lexpr = constraintExpr_undump (f);
1184 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1186 reader_checkChar (&s, 'r');
1188 if (! mstring_isDefined(s) )
1190 llfatalbug(message("Library file is corrupted") );
1193 expr = constraintExpr_undump (f);
1195 c = constraint_makeNew ();
1205 c = constraint_preserveOrig (c);
1210 void constraint_dump (/*@observer@*/ constraint c, FILE *f)
1216 constraintExpr lexpr;
1217 constraintExpr expr;
1219 llassert (constraint_isDefined (c) );
1227 fprintf (f, "%d@%d@%d\n", (int) fcnPre, (int) post, (int) ar);
1229 constraintExpr_dump (lexpr, f);
1231 constraintExpr_dump (expr, f);
1235 int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint * c1, /*@observer@*/ /*@temp@*/ const constraint * c2) /*@*/
1241 llassert (constraint_isDefined (*c1));
1242 llassert (constraint_isDefined (*c2));
1244 if (constraint_isUndefined (*c1))
1246 if (constraint_isUndefined (*c2))
1252 if (constraint_isUndefined (*c2))
1257 loc1 = constraint_getFileloc (*c1);
1258 loc2 = constraint_getFileloc (*c2);
1260 ret = fileloc_compare (loc1, loc2);
1262 fileloc_free (loc1);
1263 fileloc_free (loc2);
1269 bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c)
1271 llassert (constraint_isDefined (c));
1273 if (constraint_isUndefined (c))
1280 static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c)
1284 llassert (constraint_isDefined (c) );
1286 l = constraintExpr_getDepth (c->lexpr);
1287 r = constraintExpr_getDepth (c->expr);
1291 DPRINTF (( message ("constraint depth returning %d for %s", l, constraint_print (c))));
1296 DPRINTF (( message ("constraint depth returning %d for %s", r, constraint_print (c))));
1302 bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c)
1306 temp = constraint_getDepth (c);
1317 /*drl added 12/19/2002*/
1318 /*whether constraints consist only of
1319 terms which are constants*/
1320 bool constraint_isConstantOnly (constraint c)
1324 llassert (constraint_isDefined (c) );
1326 l = constraintExpr_isConstantOnly(c->lexpr);
1327 r = constraintExpr_isConstantOnly(c->expr);