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 "splintMacros.nf"
33 # include "cgrammar.h"
34 # include "cgrammar_tokens.h"
35 # include "exprChecks.h"
36 # include "exprNodeSList.h"
38 static /*@only@*/ cstring
39 constraint_unparseDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint p_c);
41 static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void)
42 /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/
43 /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/;
46 advanceField (char **s)
48 reader_checkChar (s, '@');
51 bool constraint_same (constraint c1, constraint c2)
53 llassert (c1 != NULL);
54 llassert (c2 != NULL);
61 if (!constraintExpr_similar (c1->lexpr, c2->lexpr))
66 if (!constraintExpr_similar (c1->expr, c2->expr))
74 constraint makeConstraintParse3 (constraintExpr l, lltok relOp, constraintExpr r)
77 ret = constraint_makeNew ();
78 llassert (constraintExpr_isDefined (l));
80 ret->lexpr = constraintExpr_copy (l);
82 if (lltok_getTok (relOp) == GE_OP)
86 else if (lltok_getTok (relOp) == LE_OP)
90 else if (lltok_getTok (relOp) == EQ_OP)
95 llfatalbug ( message ("Unsupported relational operator"));
97 ret->expr = constraintExpr_copy (r);
101 ret->orig = constraint_copy (ret);
103 ret = constraint_simplify (ret);
104 /* ret->orig = ret; */
106 DPRINTF (("GENERATED CONSTRAINT:"));
107 DPRINTF ((message ("%s", constraint_unparse (ret))));
111 constraint constraint_copy (/*@temp@*/ /*@observer@*/ constraint c)
115 llassert (constraint_isDefined (c));
117 ret = constraint_makeNew ();
118 ret->lexpr = constraintExpr_copy (c->lexpr);
120 ret->expr = constraintExpr_copy (c->expr);
123 ret->generatingExpr = c->generatingExpr;
128 ret->orig = constraint_copy (c->orig);
133 ret->or = constraint_copy (c->or);
137 ret->fcnPre = c->fcnPre;
142 /*like copy expect it doesn't allocate memory for the constraint*/
144 void constraint_overWrite (constraint c1, constraint c2)
146 llassert (constraint_isDefined (c1) && constraint_isDefined (c2));
150 DPRINTF ((message ("OverWriteing constraint %q with %q", constraint_unparse (c1),
151 constraint_unparse (c2))));
153 constraintExpr_free (c1->lexpr);
154 constraintExpr_free (c1->expr);
156 c1->lexpr = constraintExpr_copy (c2->lexpr);
158 c1->expr = constraintExpr_copy (c2->expr);
161 if (c1->orig != NULL)
162 constraint_free (c1->orig);
164 if (c2->orig != NULL)
165 c1->orig = constraint_copy (c2->orig);
169 /*@i33 make sure that the or is freed correctly*/
171 constraint_free (c1->or);
174 c1->or = constraint_copy (c2->or);
178 c1->fcnPre = c2->fcnPre;
181 c1->generatingExpr = c2->generatingExpr;
187 static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void)
188 /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/
189 /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/
192 ret = dmalloc (sizeof (*ret));
199 ret->generatingExpr = NULL;
204 /*@access exprNode@*/
206 constraint constraint_addGeneratingExpr (/*@returned@*/ constraint c, /*@exposed@*/ exprNode e)
209 llassert (constraint_isDefined (c) );
211 if (c->generatingExpr == NULL)
213 c->generatingExpr = e;
214 DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_unparse (c), exprNode_unparse (e)) ));
218 DPRINTF ((message ("Not setting generatingExpr for %s to %s", constraint_unparse (c), exprNode_unparse (e)) ));
222 /*@noaccess exprNode@*/
224 constraint constraint_origAddGeneratingExpr (/*@returned@*/ constraint c, exprNode e)
226 llassert (constraint_isDefined (c) );
228 if (c->orig != constraint_undefined)
230 c->orig = constraint_addGeneratingExpr (c->orig, e);
234 DPRINTF ((message ("constraint_origAddGeneratingExpr: Not setting generatingExpr for %s to %s", constraint_unparse (c), exprNode_unparse (e)) ));
239 constraint constraint_setFcnPre (/*@returned@*/ constraint c)
242 llassert (constraint_isDefined (c) );
244 if (c->orig != constraint_undefined)
246 c->orig->fcnPre = TRUE;
251 DPRINTF (( message ("Warning Setting fcnPre directly")));
259 fileloc constraint_getFileloc (constraint c)
262 llassert (constraint_isDefined (c) );
264 if (exprNode_isDefined (c->generatingExpr))
265 return (fileloc_copy (exprNode_getfileloc (c->generatingExpr)));
267 return (constraintExpr_getFileloc (c->lexpr));
272 static bool checkForMaxSet (constraint c)
275 llassert (constraint_isDefined (c) );
277 if (constraintExpr_hasMaxSet (c->lexpr) || constraintExpr_hasMaxSet (c->expr))
283 bool constraint_hasMaxSet (constraint c)
286 llassert (constraint_isDefined (c) );
288 if (checkForMaxSet (c))
293 if (checkForMaxSet (c->orig))
300 constraint constraint_makeReadSafeExprNode (exprNode po, exprNode ind)
302 constraint ret = constraint_makeNew ();
306 ret->lexpr = constraintExpr_makeMaxReadExpr (po);
308 ret->expr = constraintExpr_makeValueExpr (ind);
313 constraint constraint_makeWriteSafeInt ( exprNode po, int ind)
315 constraint ret = constraint_makeNew ();
317 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
319 ret->expr = constraintExpr_makeIntLiteral (ind);
323 constraint constraint_makeSRefSetBufferSize (sRef s, long int size)
325 constraint ret = constraint_makeNew ();
326 ret->lexpr = constraintExpr_makeSRefMaxset (s);
328 ret->expr = constraintExpr_makeIntLiteral ((int)size);
334 constraint constraint_makeSRefWriteSafeInt (sRef s, int ind)
336 constraint ret = constraint_makeNew ();
339 ret->lexpr = constraintExpr_makeSRefMaxset ( s);
341 ret->expr = constraintExpr_makeIntLiteral (ind);
347 /* drl added 01/12/2000
349 makes the constraint: Ensures index <= MaxRead (buffer) */
351 constraint constraint_makeEnsureLteMaxRead (exprNode index, exprNode buffer)
353 constraint ret = constraint_makeNew ();
355 ret->lexpr = constraintExpr_makeValueExpr (index);
357 ret->expr = constraintExpr_makeMaxReadExpr (buffer);
362 constraint constraint_makeWriteSafeExprNode (exprNode po, exprNode ind)
364 constraint ret = constraint_makeNew ();
367 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
369 ret->expr = constraintExpr_makeValueExpr (ind);
374 constraint constraint_makeReadSafeInt ( exprNode t1, int index)
376 constraint ret = constraint_makeNew ();
378 ret->lexpr = constraintExpr_makeMaxReadExpr (t1);
380 ret->expr = constraintExpr_makeIntLiteral (index);
385 constraint constraint_makeSRefReadSafeInt (sRef s, int ind)
387 constraint ret = constraint_makeNew ();
390 ret->lexpr = constraintExpr_makeSRefMaxRead (s);
392 ret->expr = constraintExpr_makeIntLiteral (ind);
397 constraint constraint_makeEnsureMaxReadAtLeast (exprNode t1, exprNode t2, fileloc sequencePoint)
401 ret = constraint_makeReadSafeExprNode (t1, t2);
402 llassert (constraint_isDefined (ret) );
404 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
410 static constraint constraint_makeEnsuresOpConstraintExpr (/*@only@*/ constraintExpr c1, /*@only@*/ constraintExpr c2, fileloc sequencePoint, arithType ar)
415 llassert (constraintExpr_isDefined (c1) && constraintExpr_isDefined (c2));
417 ret = constraint_makeNew ();
423 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
427 static constraint constraint_makeEnsuresOp (/*@dependent@*/ exprNode e1, /*@dependent@*/ exprNode e2, fileloc sequencePoint, arithType ar)
429 constraintExpr c1, c2;
433 if (! (exprNode_isDefined (e1) && exprNode_isDefined (e2)))
435 llcontbug ((message ("null exprNode, Exprnodes are %s and %s",
436 exprNode_unparse (e1), exprNode_unparse (e2))
441 c1 = constraintExpr_makeValueExpr (e);
444 c2 = constraintExpr_makeValueExpr (e);
446 ret = constraint_makeEnsuresOpConstraintExpr (c1, c2, sequencePoint, ar);
452 /* make constraint ensures e1 == e2 */
454 constraint constraint_makeEnsureEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
456 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, EQ));
459 /*make constraint ensures e1 < e2 */
460 constraint constraint_makeEnsureLessThan (exprNode e1, exprNode e2, fileloc sequencePoint)
462 constraintExpr t1, t2;
465 t1 = constraintExpr_makeValueExpr (e1);
466 t2 = constraintExpr_makeValueExpr (e2);
468 /*change this to e1 <= (e2 -1) */
470 t2 = constraintExpr_makeDecConstraintExpr (t2);
472 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, LTE);
474 t3 = constraint_simplify(t3);
478 constraint constraint_makeEnsureLessThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
480 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, LTE));
483 constraint constraint_makeEnsureGreaterThan (exprNode e1, exprNode e2, fileloc sequencePoint)
485 constraintExpr t1, t2;
488 t1 = constraintExpr_makeValueExpr (e1);
489 t2 = constraintExpr_makeValueExpr (e2);
492 /* change this to e1 >= (e2 + 1) */
493 t2 = constraintExpr_makeIncConstraintExpr (t2);
495 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, GTE);
497 t3 = constraint_simplify(t3);
502 constraint constraint_makeEnsureGreaterThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
504 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, GTE));
509 /* Makes the constraint e = e + f */
510 constraint constraint_makeAddAssign (exprNode e, exprNode f, fileloc sequencePoint)
512 constraintExpr x1, x2, y;
515 ret = constraint_makeNew ();
517 x1 = constraintExpr_makeValueExpr (e);
518 x2 = constraintExpr_copy (x1);
519 y = constraintExpr_makeValueExpr (f);
524 ret->expr = constraintExpr_makeAddExpr (x2, y);
526 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
532 /* Makes the constraint e = e - f */
533 constraint constraint_makeSubtractAssign (exprNode e, exprNode f, fileloc sequencePoint)
535 constraintExpr x1, x2, y;
538 ret = constraint_makeNew ();
540 x1 = constraintExpr_makeValueExpr (e);
541 x2 = constraintExpr_copy (x1);
542 y = constraintExpr_makeValueExpr (f);
547 ret->expr = constraintExpr_makeSubtractExpr (x2, y);
549 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
554 constraint constraint_makeMaxSetSideEffectPostDecrement (exprNode e, fileloc sequencePoint)
556 constraint ret = constraint_makeNew ();
558 ret->lexpr = constraintExpr_makeValueExpr (e);
561 ret->expr = constraintExpr_makeValueExpr (e);
562 ret->expr = constraintExpr_makeDecConstraintExpr (ret->expr);
563 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
566 constraint constraint_makeMaxSetSideEffectPostIncrement (exprNode e, fileloc sequencePoint)
568 constraint ret = constraint_makeNew ();
570 ret->lexpr = constraintExpr_makeValueExpr (e);
573 ret->expr = constraintExpr_makeValueExpr (e);
574 ret->expr = constraintExpr_makeIncConstraintExpr (ret->expr);
576 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
581 void constraint_free (/*@only@*/ constraint c)
583 llassert (constraint_isDefined (c));
586 if (constraint_isDefined (c->orig))
587 constraint_free (c->orig);
588 if ( constraint_isDefined (c->or))
589 constraint_free (c->or);
592 constraintExpr_free (c->lexpr);
593 constraintExpr_free (c->expr);
604 cstring arithType_print (arithType ar) /*@*/
606 cstring st = cstring_undefined;
610 st = cstring_makeLiteral ("<");
613 st = cstring_makeLiteral ("<=");
616 st = cstring_makeLiteral (">");
619 st = cstring_makeLiteral (">=");
622 st = cstring_makeLiteral ("==");
625 st = cstring_makeLiteral ("NONNEGATIVE");
628 st = cstring_makeLiteral ("POSITIVE");
637 void constraint_printErrorPostCondition (constraint c, fileloc loc)
640 fileloc errorLoc, temp;
642 string = constraint_unparseDetailedPostCondition (c);
648 temp = constraint_getFileloc (c);
651 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
653 string = cstring_replaceChar(string, '\n', ' ');
656 if (fileloc_isDefined (temp))
659 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
664 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
668 /*drl added 8-11-001*/
669 cstring constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c) /*@*/
674 string = constraint_unparse (c);
676 errorLoc = constraint_getFileloc (c);
678 ret = message ("constraint: %q @ %q", string, fileloc_unparse (errorLoc));
680 fileloc_free (errorLoc);
687 void constraint_printError (constraint c, fileloc loc)
690 fileloc errorLoc, temp;
695 llassert (constraint_isDefined (c) );
697 /*drl 11/26/2001 avoid printing tautological constraints */
698 if (constraint_isAlwaysTrue (c))
704 string = constraint_unparseDetailed (c);
708 temp = constraint_getFileloc (c);
710 if (fileloc_isDefined (temp))
717 DPRINTF (("constraint %s had undefined fileloc %s", constraint_unparse (c), fileloc_unparse (temp)));
719 errorLoc = fileloc_copy (errorLoc);
723 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
725 string = cstring_replaceChar(string, '\n', ' ');
728 /*drl added 12/19/2002 print
729 a different error fro "likely" bounds-errors*/
731 isLikely = constraint_isConstantOnly(c);
737 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
741 if (constraint_hasMaxSet (c))
743 voptgenerror (FLG_LIKELYBOUNDSWRITE, string, errorLoc);
747 voptgenerror (FLG_LIKELYBOUNDSREAD, string, errorLoc);
753 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
757 if (constraint_hasMaxSet (c))
759 voptgenerror (FLG_BOUNDSWRITE, string, errorLoc);
763 voptgenerror (FLG_BOUNDSREAD, string, errorLoc);
767 fileloc_free(errorLoc);
770 static cstring constraint_unparseDeep (constraint c)
775 llassert (constraint_isDefined (c));
776 st = constraint_unparse (c);
778 if (c->orig != constraint_undefined)
780 st = cstring_appendChar (st, '\n');
781 genExpr = exprNode_unparse (c->orig->generatingExpr);
787 st = cstring_concatFree (st, message (" derived from %s precondition: %q",
788 genExpr, constraint_unparseDeep (c->orig)));
792 st = cstring_concatFree (st, message (" needed to satisfy precondition:\n%q",
793 constraint_unparseDeep (c->orig)));
798 st = cstring_concatFree (st, message ("derived from: %q",
799 constraint_unparseDeep (c->orig)));
807 static /*@only@*/ cstring constraint_unparseDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c)
809 cstring st = cstring_undefined;
812 llassert (constraint_isDefined (c) );
814 st = message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q",
815 constraint_unparseDeep (c));
817 genExpr = exprNode_unparse (c->generatingExpr);
819 if (context_getFlag (FLG_CONSTRAINTLOCATION))
823 temp = message ("\nOriginal Generating expression %q: %s\n",
824 fileloc_unparse ( exprNode_getfileloc (c->generatingExpr)),
826 st = cstring_concatFree (st, temp);
828 if (constraint_hasMaxSet (c))
830 temp = message ("Has MaxSet\n");
831 st = cstring_concatFree (st, temp);
837 cstring constraint_unparseDetailed (constraint c)
839 cstring st = cstring_undefined;
840 cstring temp = cstring_undefined;
844 llassert (constraint_isDefined (c) );
848 st = message ("Unable to resolve constraint:\n%q", constraint_unparseDeep (c));
852 st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_unparseDeep (c));
855 isLikely = constraint_isConstantOnly(c);
859 if (constraint_hasMaxSet (c))
861 temp = cstring_makeLiteral ("Likely out-of-bounds store:\n");
865 temp = cstring_makeLiteral ("Likely out-of-bounds read:\n");
871 if (constraint_hasMaxSet (c))
873 temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
877 temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
881 genExpr = exprNode_unparse (c->generatingExpr);
883 if (context_getFlag (FLG_CONSTRAINTLOCATION))
886 temp2 = message ("%s\n", genExpr);
887 temp = cstring_concatFree (temp, temp2);
890 st = cstring_concatFree (temp,st);
895 /*@only@*/ cstring constraint_unparse (constraint c) /*@*/
897 cstring st = cstring_undefined;
898 cstring type = cstring_undefined;
902 if (context_getFlag (FLG_PARENCONSTRAINT))
904 type = cstring_makeLiteral ("ensures: ");
908 type = cstring_makeLiteral ("ensures");
913 if (context_getFlag (FLG_PARENCONSTRAINT))
915 type = cstring_makeLiteral ("requires: ");
919 type = cstring_makeLiteral ("requires");
923 if (context_getFlag (FLG_PARENCONSTRAINT))
925 st = message ("%q: %q %q %q",
927 constraintExpr_print (c->lexpr),
928 arithType_print (c->ar),
929 constraintExpr_print (c->expr));
933 st = message ("%q %q %q %q",
935 constraintExpr_print (c->lexpr),
936 arithType_print (c->ar),
937 constraintExpr_print (c->expr));
942 cstring constraint_unparseOr (constraint c) /*@*/
947 ret = cstring_undefined;
949 llassert (constraint_isDefined (c) );
953 ret = cstring_concatFree (ret, constraint_unparse (temp));
957 while ( constraint_isDefined (temp))
959 ret = cstring_concatFree (ret, cstring_makeLiteral (" OR "));
960 ret = cstring_concatFree (ret, constraint_unparse (temp));
968 /*@only@*/ constraint constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition,
969 exprNodeList arglist)
972 llassert (constraint_isDefined (precondition) );
974 precondition->lexpr = constraintExpr_doSRefFixBaseParam (precondition->lexpr,
976 precondition->expr = constraintExpr_doSRefFixBaseParam (precondition->expr,
983 constraint constraint_doFixResult (constraint postcondition, /*@dependent@*/ exprNode fcnCall)
985 postcondition = constraint_copy (postcondition);
987 llassert (constraint_isDefined (postcondition) );
990 postcondition->lexpr = constraintExpr_doFixResult (postcondition->lexpr, fcnCall);
991 postcondition->expr = constraintExpr_doFixResult (postcondition->expr, fcnCall);
993 return postcondition;
995 /*Commenting out temporally
997 / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct )
1000 invar = constraint_copy (invar);
1001 invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct);
1002 invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct);
1008 /*@only@*/ constraint constraint_doSRefFixConstraintParam (constraint precondition,
1009 exprNodeList arglist)
1012 precondition = constraint_copy (precondition);
1014 llassert (constraint_isDefined (precondition) );
1016 precondition->lexpr = constraintExpr_doSRefFixConstraintParam (precondition->lexpr, arglist);
1017 precondition->expr = constraintExpr_doSRefFixConstraintParam (precondition->expr, arglist);
1019 precondition->fcnPre = FALSE;
1020 return constraint_simplify(precondition);
1023 constraint constraint_preserveOrig (/*@returned@*/ constraint c) /*@modifies c @*/
1025 DPRINTF (("Doing constraint_preserverOrig for %q", constraint_printDetailed (c)));
1026 llassert (constraint_isDefined (c));
1028 if (c->orig == constraint_undefined)
1030 c->orig = constraint_copy (c);
1032 else if (c->orig->fcnPre)
1034 constraint temp = c->orig;
1036 /* avoid infinite loop */
1038 c->orig = constraint_copy (c);
1039 /*drl 03/2/2003 if c != NULL then the copy of c will != null*/
1040 llassert (constraint_isDefined (c->orig) );
1042 if (c->orig->orig == NULL)
1044 c->orig->orig = temp;
1049 llcontbug ((message ("Expected c->orig->orig to be null")));
1050 constraint_free (c->orig->orig);
1051 c->orig->orig = temp;
1057 DPRINTF (("Not changing constraint"));
1060 DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_unparseDetailed (c))));
1064 constraint constraint_togglePost (/*@returned@*/ constraint c)
1066 llassert (constraint_isDefined (c));
1071 constraint constraint_togglePostOrig (/*@returned@*/ constraint c)
1073 llassert (constraint_isDefined (c));
1075 if (c->orig != NULL)
1077 c->orig = constraint_togglePost (c->orig);
1083 bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c)
1085 llassert (constraint_isDefined (c));
1086 return (c->orig != NULL);
1090 constraint constraint_undump (FILE *f)
1095 constraintExpr lexpr, expr;
1098 os = mstring_create (MAX_DUMP_LINE_LENGTH);
1099 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1101 if (!mstring_isDefined (s))
1103 llfatalbug (message ("Library file is corrupted") );
1106 fcnPre = (bool) reader_getInt (&s);
1108 post = (bool) reader_getInt (&s);
1110 ar = (arithType) reader_getInt (&s);
1112 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1114 if (! mstring_isDefined(s) )
1116 llfatalbug(message("Library file is corrupted") );
1119 reader_checkChar (&s, 'l');
1121 lexpr = constraintExpr_undump (f);
1123 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1125 reader_checkChar (&s, 'r');
1127 if (! mstring_isDefined(s) )
1129 llfatalbug(message("Library file is corrupted") );
1132 expr = constraintExpr_undump (f);
1134 c = constraint_makeNew ();
1144 c = constraint_preserveOrig (c);
1149 void constraint_dump (/*@observer@*/ constraint c, FILE *f)
1155 constraintExpr lexpr;
1156 constraintExpr expr;
1158 llassert (constraint_isDefined (c) );
1166 fprintf (f, "%d@%d@%d\n", (int) fcnPre, (int) post, (int) ar);
1168 constraintExpr_dump (lexpr, f);
1170 constraintExpr_dump (expr, f);
1174 int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint * c1, /*@observer@*/ /*@temp@*/ const constraint * c2) /*@*/
1180 llassert (constraint_isDefined (*c1));
1181 llassert (constraint_isDefined (*c2));
1183 if (constraint_isUndefined (*c1))
1185 if (constraint_isUndefined (*c2))
1191 if (constraint_isUndefined (*c2))
1196 loc1 = constraint_getFileloc (*c1);
1197 loc2 = constraint_getFileloc (*c2);
1199 ret = fileloc_compare (loc1, loc2);
1201 fileloc_free (loc1);
1202 fileloc_free (loc2);
1208 bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c)
1210 llassert (constraint_isDefined (c));
1212 if (constraint_isUndefined (c))
1219 static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c)
1223 llassert (constraint_isDefined (c) );
1225 l = constraintExpr_getDepth (c->lexpr);
1226 r = constraintExpr_getDepth (c->expr);
1230 DPRINTF (( message ("constraint depth returning %d for %s", l, constraint_unparse (c))));
1235 DPRINTF (( message ("constraint depth returning %d for %s", r, constraint_unparse (c))));
1241 bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c)
1245 temp = constraint_getDepth (c);
1256 /*drl added 12/19/2002*/
1257 /*whether constraints consist only of
1258 terms which are constants*/
1259 bool constraint_isConstantOnly (constraint c)
1263 llassert (constraint_isDefined (c) );
1265 l = constraintExpr_isConstantOnly(c->lexpr);
1266 r = constraintExpr_isConstantOnly(c->expr);