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;
127 ret->orig = constraint_copy (c->orig);
132 ret->or = constraint_copy (c->or);
136 ret->fcnPre = c->fcnPre;
141 /*like copy except it doesn't allocate memory for the constraint*/
143 void constraint_overWrite (constraint c1, constraint c2)
145 llassert (constraint_isDefined (c1) && constraint_isDefined (c2));
149 DPRINTF ((message ("OverWriteing constraint %q with %q", constraint_unparse (c1),
150 constraint_unparse (c2))));
152 constraintExpr_free (c1->lexpr);
153 constraintExpr_free (c1->expr);
155 c1->lexpr = constraintExpr_copy (c2->lexpr);
157 c1->expr = constraintExpr_copy (c2->expr);
160 if (c1->orig != NULL)
161 constraint_free (c1->orig);
163 if (c2->orig != NULL)
164 c1->orig = constraint_copy (c2->orig);
169 constraint_free (c1->or);
172 c1->or = constraint_copy (c2->or);
176 c1->fcnPre = c2->fcnPre;
179 c1->generatingExpr = c2->generatingExpr;
185 static /*@notnull@*/ /*@special@*/ constraint constraint_makeNew (void)
186 /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/
187 /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/
190 ret = dmalloc (sizeof (*ret));
197 ret->generatingExpr = NULL;
202 /*@access exprNode@*/
204 constraint constraint_addGeneratingExpr (/*@returned@*/ constraint c, /*@exposed@*/ exprNode e)
207 llassert (constraint_isDefined (c) );
209 if (c->generatingExpr == NULL)
211 c->generatingExpr = e;
212 DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_unparse (c), exprNode_unparse (e)) ));
216 DPRINTF ((message ("Not setting generatingExpr for %s to %s", constraint_unparse (c), exprNode_unparse (e)) ));
220 /*@noaccess exprNode@*/
222 constraint constraint_origAddGeneratingExpr (/*@returned@*/ constraint c, exprNode e)
224 llassert (constraint_isDefined (c) );
226 if (c->orig != constraint_undefined)
228 c->orig = constraint_addGeneratingExpr (c->orig, e);
232 DPRINTF ((message ("constraint_origAddGeneratingExpr: Not setting generatingExpr for %s to %s", constraint_unparse (c), exprNode_unparse (e)) ));
237 constraint constraint_setFcnPre (/*@returned@*/ constraint c)
240 llassert (constraint_isDefined (c) );
242 if (c->orig != constraint_undefined)
244 c->orig->fcnPre = TRUE;
249 DPRINTF (( message ("Warning Setting fcnPre directly")));
257 fileloc constraint_getFileloc (constraint c)
259 llassert (constraint_isDefined (c) );
261 if (exprNode_isDefined (c->generatingExpr))
262 return (fileloc_copy (exprNode_loc (c->generatingExpr)));
264 return (constraintExpr_loc (c->lexpr));
267 static bool checkForMaxSet (constraint c)
269 llassert (constraint_isDefined (c));
270 return (constraintExpr_hasMaxSet (c->lexpr) || constraintExpr_hasMaxSet (c->expr));
273 bool constraint_hasMaxSet (constraint c)
275 llassert (constraint_isDefined (c) );
277 if (checkForMaxSet (c))
282 if (checkForMaxSet (c->orig))
289 constraint constraint_makeReadSafeExprNode (exprNode po, exprNode ind)
291 constraint ret = constraint_makeNew ();
295 ret->lexpr = constraintExpr_makeMaxReadExpr (po);
297 ret->expr = constraintExpr_makeValueExpr (ind);
302 constraint constraint_makeWriteSafeInt (exprNode po, int ind)
304 constraint ret = constraint_makeNew ();
305 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
307 ret->expr = constraintExpr_makeIntLiteral (ind);
311 constraint constraint_makeSRefSetBufferSize (sRef s, long int size)
313 constraint ret = constraint_makeNew ();
314 ret->lexpr = constraintExpr_makeSRefMaxset (s);
316 ret->expr = constraintExpr_makeIntLiteral ((int)size);
321 constraint constraint_makeSRefWriteSafeInt (sRef s, int ind)
323 constraint ret = constraint_makeNew ();
324 ret->lexpr = constraintExpr_makeSRefMaxset ( s);
326 ret->expr = constraintExpr_makeIntLiteral (ind);
331 /* drl added 01/12/2000
332 ** makes the constraint: Ensures index <= MaxRead (buffer)
335 constraint constraint_makeEnsureLteMaxRead (exprNode index, exprNode buffer)
337 constraint ret = constraint_makeNew ();
339 ret->lexpr = constraintExpr_makeValueExpr (index);
341 ret->expr = constraintExpr_makeMaxReadExpr (buffer);
346 constraint constraint_makeWriteSafeExprNode (exprNode po, exprNode ind)
348 constraint ret = constraint_makeNew ();
350 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
352 ret->expr = constraintExpr_makeValueExpr (ind);
357 constraint constraint_makeReadSafeInt (exprNode t1, int index)
359 constraint ret = constraint_makeNew ();
361 ret->lexpr = constraintExpr_makeMaxReadExpr (t1);
363 ret->expr = constraintExpr_makeIntLiteral (index);
368 constraint constraint_makeSRefReadSafeInt (sRef s, int ind)
370 constraint ret = constraint_makeNew ();
372 ret->lexpr = constraintExpr_makeSRefMaxRead (s);
374 ret->expr = constraintExpr_makeIntLiteral (ind);
379 constraint constraint_makeEnsureMaxReadAtLeast (exprNode t1, exprNode t2, fileloc sequencePoint)
381 constraint ret = constraint_makeReadSafeExprNode (t1, t2);
382 llassert (constraint_isDefined (ret));
384 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
391 constraint_makeEnsuresOpConstraintExpr (/*@only@*/ constraintExpr c1, /*@only@*/ constraintExpr c2,
392 fileloc sequencePoint, arithType ar)
394 constraint ret = constraint_makeNew ();
395 llassert (constraintExpr_isDefined (c1) && constraintExpr_isDefined (c2));
400 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
405 constraint_makeEnsuresOp (/*@dependent@*/ exprNode e1, /*@dependent@*/ exprNode e2,
406 fileloc sequencePoint, arithType ar)
408 constraintExpr c1, c2;
410 if (!(exprNode_isDefined (e1) && exprNode_isDefined (e2)))
412 llcontbug (message ("Invalid exprNode, Exprnodes are %s and %s",
413 exprNode_unparse (e1), exprNode_unparse (e2)));
416 c1 = constraintExpr_makeValueExpr (e1);
417 c2 = constraintExpr_makeValueExpr (e2);
419 return constraint_makeEnsuresOpConstraintExpr (c1, c2, sequencePoint, ar);
422 /* make constraint ensures e1 == e2 */
424 constraint constraint_makeEnsureEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
426 if (FALSE) /* (!ctype_almostEqual (exprNode_getType (e1), exprNode_getType (e2))) */
428 /* If the types are not identical, need to be careful the element sizes may be different. */
429 //! return (constraint_makeEnsuresOp (e1, e2, sequencePoint, CASTEQ));
434 return (constraint_makeEnsuresOp (e1, e2, sequencePoint, EQ));
438 /* make constraint ensures e1 < e2 */
439 constraint constraint_makeEnsureLessThan (exprNode e1, exprNode e2, fileloc sequencePoint)
441 constraintExpr t1, t2;
444 t1 = constraintExpr_makeValueExpr (e1);
445 t2 = constraintExpr_makeValueExpr (e2);
447 /* change this to e1 <= (e2 -1) */
449 t2 = constraintExpr_makeDecConstraintExpr (t2);
450 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, LTE);
451 t3 = constraint_simplify (t3);
455 constraint constraint_makeEnsureLessThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
457 return (constraint_makeEnsuresOp (e1, e2, sequencePoint, LTE));
460 constraint constraint_makeEnsureGreaterThan (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) */
469 t2 = constraintExpr_makeIncConstraintExpr (t2);
471 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, GTE);
472 t3 = constraint_simplify(t3);
477 constraint constraint_makeEnsureGreaterThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
479 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, GTE));
484 /* Makes the constraint e = e + f */
485 constraint constraint_makeAddAssign (exprNode e, exprNode f, fileloc sequencePoint)
487 constraintExpr x1, x2, y;
490 ret = constraint_makeNew ();
492 x1 = constraintExpr_makeValueExpr (e);
493 x2 = constraintExpr_copy (x1);
494 y = constraintExpr_makeValueExpr (f);
499 ret->expr = constraintExpr_makeAddExpr (x2, y);
501 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
507 /* Makes the constraint e = e - f */
508 constraint constraint_makeSubtractAssign (exprNode e, exprNode f, fileloc sequencePoint)
510 constraintExpr x1, x2, y;
513 ret = constraint_makeNew ();
515 x1 = constraintExpr_makeValueExpr (e);
516 x2 = constraintExpr_copy (x1);
517 y = constraintExpr_makeValueExpr (f);
522 ret->expr = constraintExpr_makeSubtractExpr (x2, y);
524 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
529 constraint constraint_makeMaxSetSideEffectPostDecrement (exprNode e, fileloc sequencePoint)
531 constraint ret = constraint_makeNew ();
533 ret->lexpr = constraintExpr_makeValueExpr (e);
536 ret->expr = constraintExpr_makeValueExpr (e);
537 ret->expr = constraintExpr_makeDecConstraintExpr (ret->expr);
538 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
541 constraint constraint_makeMaxSetSideEffectPostIncrement (exprNode e, fileloc sequencePoint)
543 constraint ret = constraint_makeNew ();
545 ret->lexpr = constraintExpr_makeValueExpr (e);
548 ret->expr = constraintExpr_makeValueExpr (e);
549 ret->expr = constraintExpr_makeIncConstraintExpr (ret->expr);
551 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
556 void constraint_free (/*@only@*/ constraint c)
558 llassert (constraint_isDefined (c));
561 if (constraint_isDefined (c->orig))
562 constraint_free (c->orig);
563 if ( constraint_isDefined (c->or))
564 constraint_free (c->or);
567 constraintExpr_free (c->lexpr);
568 constraintExpr_free (c->expr);
579 cstring arithType_print (arithType ar) /*@*/
581 cstring st = cstring_undefined;
585 st = cstring_makeLiteral ("<");
588 st = cstring_makeLiteral ("<=");
591 st = cstring_makeLiteral (">");
594 st = cstring_makeLiteral (">=");
597 st = cstring_makeLiteral ("==");
600 st = cstring_makeLiteral ("(!)==");
603 st = cstring_makeLiteral ("NONNEGATIVE");
606 st = cstring_makeLiteral ("POSITIVE");
615 void constraint_printErrorPostCondition (constraint c, fileloc loc)
618 fileloc errorLoc, temp;
620 string = constraint_unparseDetailedPostCondition (c);
624 temp = constraint_getFileloc (c);
626 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES))
628 string = cstring_replaceChar (string, '\n', ' ');
631 if (fileloc_isDefined (temp))
634 voptgenerror (FLG_CHECKPOST, string, errorLoc);
639 voptgenerror (FLG_CHECKPOST, string, errorLoc);
643 /*drl added 8-11-001*/
644 cstring constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c) /*@*/
649 string = constraint_unparse (c);
651 errorLoc = constraint_getFileloc (c);
653 ret = message ("constraint: %q @ %q", string, fileloc_unparse (errorLoc));
654 fileloc_free (errorLoc);
661 void constraint_printError (constraint c, fileloc loc)
664 fileloc errorLoc, temp;
668 llassert (constraint_isDefined (c) );
670 /*drl 11/26/2001 avoid printing tautological constraints */
671 if (constraint_isAlwaysTrue (c))
677 string = constraint_unparseDetailed (c);
681 temp = constraint_getFileloc (c);
683 if (fileloc_isDefined (temp))
690 DPRINTF (("constraint %s had undefined fileloc %s",
691 constraint_unparse (c), fileloc_unparse (temp)));
693 errorLoc = fileloc_copy (errorLoc);
697 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES))
699 string = cstring_replaceChar(string, '\n', ' ');
702 /*drl added 12/19/2002 print
703 a different error fro "likely" bounds-errors*/
705 isLikely = constraint_isConstantOnly (c);
711 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
715 if (constraint_hasMaxSet (c))
717 voptgenerror (FLG_LIKELYBOUNDSWRITE, string, errorLoc);
721 voptgenerror (FLG_LIKELYBOUNDSREAD, string, errorLoc);
727 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
731 if (constraint_hasMaxSet (c))
733 voptgenerror (FLG_BOUNDSWRITE, string, errorLoc);
737 voptgenerror (FLG_BOUNDSREAD, string, errorLoc);
741 fileloc_free(errorLoc);
744 static cstring constraint_unparseDeep (constraint c)
749 llassert (constraint_isDefined (c));
750 st = constraint_unparse (c);
752 if (c->orig != constraint_undefined)
754 st = cstring_appendChar (st, '\n');
755 genExpr = exprNode_unparse (c->orig->generatingExpr);
761 st = cstring_concatFree (st, message (" derived from %s precondition: %q",
762 genExpr, constraint_unparseDeep (c->orig)));
766 st = cstring_concatFree (st, message (" needed to satisfy precondition:\n%q",
767 constraint_unparseDeep (c->orig)));
772 st = cstring_concatFree (st, message ("derived from: %q",
773 constraint_unparseDeep (c->orig)));
781 static /*@only@*/ cstring constraint_unparseDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c)
783 cstring st = cstring_undefined;
786 llassert (constraint_isDefined (c) );
788 st = message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q",
789 constraint_unparseDeep (c));
791 genExpr = exprNode_unparse (c->generatingExpr);
793 if (context_getFlag (FLG_CONSTRAINTLOCATION))
797 temp = message ("\nOriginal Generating expression %q: %s\n",
798 fileloc_unparse (exprNode_loc (c->generatingExpr)),
800 st = cstring_concatFree (st, temp);
802 if (constraint_hasMaxSet (c))
804 temp = message ("Has MaxSet\n");
805 st = cstring_concatFree (st, temp);
811 cstring constraint_unparseDetailed (constraint c)
813 cstring st = cstring_undefined;
814 cstring temp = cstring_undefined;
818 llassert (constraint_isDefined (c) );
822 st = message ("Unable to resolve constraint:\n%q", constraint_unparseDeep (c));
826 st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_unparseDeep (c));
829 isLikely = constraint_isConstantOnly(c);
833 if (constraint_hasMaxSet (c))
835 temp = cstring_makeLiteral ("Likely out-of-bounds store:\n");
839 temp = cstring_makeLiteral ("Likely out-of-bounds read:\n");
845 if (constraint_hasMaxSet (c))
847 temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
851 temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
855 genExpr = exprNode_unparse (c->generatingExpr);
857 if (context_getFlag (FLG_CONSTRAINTLOCATION))
860 temp2 = message ("%s\n", genExpr);
861 temp = cstring_concatFree (temp, temp2);
864 st = cstring_concatFree (temp,st);
869 /*@only@*/ cstring constraint_unparse (constraint c) /*@*/
871 cstring st = cstring_undefined;
872 cstring type = cstring_undefined;
876 if (context_getFlag (FLG_PARENCONSTRAINT))
878 type = cstring_makeLiteral ("ensures: ");
882 type = cstring_makeLiteral ("ensures");
887 if (context_getFlag (FLG_PARENCONSTRAINT))
889 type = cstring_makeLiteral ("requires: ");
893 type = cstring_makeLiteral ("requires");
897 if (context_getFlag (FLG_PARENCONSTRAINT))
899 st = message ("%q: %q %q %q",
901 constraintExpr_print (c->lexpr),
902 arithType_print (c->ar),
903 constraintExpr_print (c->expr));
907 st = message ("%q %q %q %q",
909 constraintExpr_print (c->lexpr),
910 arithType_print (c->ar),
911 constraintExpr_print (c->expr));
916 cstring constraint_unparseOr (constraint c) /*@*/
921 ret = cstring_undefined;
923 llassert (constraint_isDefined (c) );
927 ret = cstring_concatFree (ret, constraint_unparse (temp));
931 while ( constraint_isDefined (temp))
933 ret = cstring_concatFree (ret, cstring_makeLiteral (" OR "));
934 ret = cstring_concatFree (ret, constraint_unparse (temp));
942 /*@only@*/ constraint constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition,
943 exprNodeList arglist)
946 llassert (constraint_isDefined (precondition) );
948 precondition->lexpr = constraintExpr_doSRefFixBaseParam (precondition->lexpr,
950 precondition->expr = constraintExpr_doSRefFixBaseParam (precondition->expr,
957 constraint constraint_doFixResult (constraint postcondition, /*@dependent@*/ exprNode fcnCall)
959 postcondition = constraint_copy (postcondition);
961 llassert (constraint_isDefined (postcondition) );
964 postcondition->lexpr = constraintExpr_doFixResult (postcondition->lexpr, fcnCall);
965 postcondition->expr = constraintExpr_doFixResult (postcondition->expr, fcnCall);
967 return postcondition;
969 /*Commenting out temporally
971 / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct )
974 invar = constraint_copy (invar);
975 invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct);
976 invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct);
982 /*@only@*/ constraint constraint_doSRefFixConstraintParam (constraint precondition,
983 exprNodeList arglist)
986 precondition = constraint_copy (precondition);
988 llassert (constraint_isDefined (precondition) );
990 precondition->lexpr = constraintExpr_doSRefFixConstraintParam (precondition->lexpr, arglist);
991 precondition->expr = constraintExpr_doSRefFixConstraintParam (precondition->expr, arglist);
993 precondition->fcnPre = FALSE;
994 return constraint_simplify(precondition);
997 constraint constraint_preserveOrig (/*@returned@*/ constraint c) /*@modifies c @*/
999 DPRINTF (("Doing constraint_preserverOrig for %q", constraint_printDetailed (c)));
1000 llassert (constraint_isDefined (c));
1002 if (c->orig == constraint_undefined)
1004 c->orig = constraint_copy (c);
1006 else if (c->orig->fcnPre)
1008 constraint temp = c->orig;
1010 /* avoid infinite loop */
1012 c->orig = constraint_copy (c);
1013 /*drl 03/2/2003 if c != NULL then the copy of c will != null*/
1014 llassert (constraint_isDefined (c->orig) );
1016 if (c->orig->orig == NULL)
1018 c->orig->orig = temp;
1023 llcontbug ((message ("Expected c->orig->orig to be null")));
1024 constraint_free (c->orig->orig);
1025 c->orig->orig = temp;
1031 DPRINTF (("Not changing constraint"));
1034 DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_unparseDetailed (c))));
1038 constraint constraint_togglePost (/*@returned@*/ constraint c)
1040 llassert (constraint_isDefined (c));
1045 constraint constraint_togglePostOrig (/*@returned@*/ constraint c)
1047 llassert (constraint_isDefined (c));
1049 if (c->orig != NULL)
1051 c->orig = constraint_togglePost (c->orig);
1057 bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c)
1059 llassert (constraint_isDefined (c));
1060 return (c->orig != NULL);
1064 constraint constraint_undump (FILE *f)
1069 constraintExpr lexpr, expr;
1072 os = mstring_create (MAX_DUMP_LINE_LENGTH);
1073 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1075 if (!mstring_isDefined (s))
1077 llfatalbug (message ("Library file is corrupted") );
1080 fcnPre = (bool) reader_getInt (&s);
1082 post = (bool) reader_getInt (&s);
1084 ar = (arithType) reader_getInt (&s);
1086 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1088 if (! mstring_isDefined(s) )
1090 llfatalbug(message("Library file is corrupted") );
1093 reader_checkChar (&s, 'l');
1095 lexpr = constraintExpr_undump (f);
1097 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1099 reader_checkChar (&s, 'r');
1101 if (! mstring_isDefined(s) )
1103 llfatalbug(message("Library file is corrupted") );
1106 expr = constraintExpr_undump (f);
1108 c = constraint_makeNew ();
1118 c = constraint_preserveOrig (c);
1123 void constraint_dump (/*@observer@*/ constraint c, FILE *f)
1129 constraintExpr lexpr;
1130 constraintExpr expr;
1132 llassert (constraint_isDefined (c) );
1140 fprintf (f, "%d@%d@%d\n", (int) fcnPre, (int) post, (int) ar);
1142 constraintExpr_dump (lexpr, f);
1144 constraintExpr_dump (expr, f);
1148 int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint * c1, /*@observer@*/ /*@temp@*/ const constraint * c2) /*@*/
1154 llassert (constraint_isDefined (*c1));
1155 llassert (constraint_isDefined (*c2));
1157 if (constraint_isUndefined (*c1))
1159 if (constraint_isUndefined (*c2))
1165 if (constraint_isUndefined (*c2))
1170 loc1 = constraint_getFileloc (*c1);
1171 loc2 = constraint_getFileloc (*c2);
1173 ret = fileloc_compare (loc1, loc2);
1175 fileloc_free (loc1);
1176 fileloc_free (loc2);
1182 bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c)
1184 llassert (constraint_isDefined (c));
1186 if (constraint_isUndefined (c))
1193 static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c)
1197 llassert (constraint_isDefined (c) );
1199 l = constraintExpr_getDepth (c->lexpr);
1200 r = constraintExpr_getDepth (c->expr);
1204 DPRINTF (( message ("constraint depth returning %d for %s", l, constraint_unparse (c))));
1209 DPRINTF (( message ("constraint depth returning %d for %s", r, constraint_unparse (c))));
1215 bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c)
1219 temp = constraint_getDepth (c);
1230 /*drl added 12/19/2002*/
1231 /*whether constraints consist only of
1232 terms which are constants*/
1233 bool constraint_isConstantOnly (constraint c)
1237 llassert (constraint_isDefined (c) );
1239 l = constraintExpr_isConstantOnly(c->lexpr);
1240 r = constraintExpr_isConstantOnly(c->expr);