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_getFileloc (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 return (constraint_makeEnsuresOp (e1, e2, sequencePoint, EQ));
429 /* make constraint ensures e1 < e2 */
430 constraint constraint_makeEnsureLessThan (exprNode e1, exprNode e2, fileloc sequencePoint)
432 constraintExpr t1, t2;
435 t1 = constraintExpr_makeValueExpr (e1);
436 t2 = constraintExpr_makeValueExpr (e2);
438 /* change this to e1 <= (e2 -1) */
440 t2 = constraintExpr_makeDecConstraintExpr (t2);
441 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, LTE);
442 t3 = constraint_simplify (t3);
446 constraint constraint_makeEnsureLessThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
448 return (constraint_makeEnsuresOp (e1, e2, sequencePoint, LTE));
451 constraint constraint_makeEnsureGreaterThan (exprNode e1, exprNode e2, fileloc sequencePoint)
453 constraintExpr t1, t2;
456 t1 = constraintExpr_makeValueExpr (e1);
457 t2 = constraintExpr_makeValueExpr (e2);
459 /* change this to e1 >= (e2 + 1) */
460 t2 = constraintExpr_makeIncConstraintExpr (t2);
462 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, GTE);
463 t3 = constraint_simplify(t3);
468 constraint constraint_makeEnsureGreaterThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
470 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, GTE));
475 /* Makes the constraint e = e + f */
476 constraint constraint_makeAddAssign (exprNode e, exprNode f, fileloc sequencePoint)
478 constraintExpr x1, x2, y;
481 ret = constraint_makeNew ();
483 x1 = constraintExpr_makeValueExpr (e);
484 x2 = constraintExpr_copy (x1);
485 y = constraintExpr_makeValueExpr (f);
490 ret->expr = constraintExpr_makeAddExpr (x2, y);
492 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
498 /* Makes the constraint e = e - f */
499 constraint constraint_makeSubtractAssign (exprNode e, exprNode f, fileloc sequencePoint)
501 constraintExpr x1, x2, y;
504 ret = constraint_makeNew ();
506 x1 = constraintExpr_makeValueExpr (e);
507 x2 = constraintExpr_copy (x1);
508 y = constraintExpr_makeValueExpr (f);
513 ret->expr = constraintExpr_makeSubtractExpr (x2, y);
515 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
520 constraint constraint_makeMaxSetSideEffectPostDecrement (exprNode e, fileloc sequencePoint)
522 constraint ret = constraint_makeNew ();
524 ret->lexpr = constraintExpr_makeValueExpr (e);
527 ret->expr = constraintExpr_makeValueExpr (e);
528 ret->expr = constraintExpr_makeDecConstraintExpr (ret->expr);
529 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
532 constraint constraint_makeMaxSetSideEffectPostIncrement (exprNode e, fileloc sequencePoint)
534 constraint ret = constraint_makeNew ();
536 ret->lexpr = constraintExpr_makeValueExpr (e);
539 ret->expr = constraintExpr_makeValueExpr (e);
540 ret->expr = constraintExpr_makeIncConstraintExpr (ret->expr);
542 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
547 void constraint_free (/*@only@*/ constraint c)
549 llassert (constraint_isDefined (c));
552 if (constraint_isDefined (c->orig))
553 constraint_free (c->orig);
554 if ( constraint_isDefined (c->or))
555 constraint_free (c->or);
558 constraintExpr_free (c->lexpr);
559 constraintExpr_free (c->expr);
570 cstring arithType_print (arithType ar) /*@*/
572 cstring st = cstring_undefined;
576 st = cstring_makeLiteral ("<");
579 st = cstring_makeLiteral ("<=");
582 st = cstring_makeLiteral (">");
585 st = cstring_makeLiteral (">=");
588 st = cstring_makeLiteral ("==");
591 st = cstring_makeLiteral ("NONNEGATIVE");
594 st = cstring_makeLiteral ("POSITIVE");
603 void constraint_printErrorPostCondition (constraint c, fileloc loc)
606 fileloc errorLoc, temp;
608 string = constraint_unparseDetailedPostCondition (c);
614 temp = constraint_getFileloc (c);
617 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
619 string = cstring_replaceChar(string, '\n', ' ');
622 if (fileloc_isDefined (temp))
625 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
630 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
634 /*drl added 8-11-001*/
635 cstring constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c) /*@*/
640 string = constraint_unparse (c);
642 errorLoc = constraint_getFileloc (c);
644 ret = message ("constraint: %q @ %q", string, fileloc_unparse (errorLoc));
646 fileloc_free (errorLoc);
653 void constraint_printError (constraint c, fileloc loc)
656 fileloc errorLoc, temp;
661 llassert (constraint_isDefined (c) );
663 /*drl 11/26/2001 avoid printing tautological constraints */
664 if (constraint_isAlwaysTrue (c))
670 string = constraint_unparseDetailed (c);
674 temp = constraint_getFileloc (c);
676 if (fileloc_isDefined (temp))
683 DPRINTF (("constraint %s had undefined fileloc %s", constraint_unparse (c), fileloc_unparse (temp)));
685 errorLoc = fileloc_copy (errorLoc);
689 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
691 string = cstring_replaceChar(string, '\n', ' ');
694 /*drl added 12/19/2002 print
695 a different error fro "likely" bounds-errors*/
697 isLikely = constraint_isConstantOnly(c);
703 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
707 if (constraint_hasMaxSet (c))
709 voptgenerror (FLG_LIKELYBOUNDSWRITE, string, errorLoc);
713 voptgenerror (FLG_LIKELYBOUNDSREAD, string, errorLoc);
719 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
723 if (constraint_hasMaxSet (c))
725 voptgenerror (FLG_BOUNDSWRITE, string, errorLoc);
729 voptgenerror (FLG_BOUNDSREAD, string, errorLoc);
733 fileloc_free(errorLoc);
736 static cstring constraint_unparseDeep (constraint c)
741 llassert (constraint_isDefined (c));
742 st = constraint_unparse (c);
744 if (c->orig != constraint_undefined)
746 st = cstring_appendChar (st, '\n');
747 genExpr = exprNode_unparse (c->orig->generatingExpr);
753 st = cstring_concatFree (st, message (" derived from %s precondition: %q",
754 genExpr, constraint_unparseDeep (c->orig)));
758 st = cstring_concatFree (st, message (" needed to satisfy precondition:\n%q",
759 constraint_unparseDeep (c->orig)));
764 st = cstring_concatFree (st, message ("derived from: %q",
765 constraint_unparseDeep (c->orig)));
773 static /*@only@*/ cstring constraint_unparseDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c)
775 cstring st = cstring_undefined;
778 llassert (constraint_isDefined (c) );
780 st = message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q",
781 constraint_unparseDeep (c));
783 genExpr = exprNode_unparse (c->generatingExpr);
785 if (context_getFlag (FLG_CONSTRAINTLOCATION))
789 temp = message ("\nOriginal Generating expression %q: %s\n",
790 fileloc_unparse (exprNode_loc (c->generatingExpr)),
792 st = cstring_concatFree (st, temp);
794 if (constraint_hasMaxSet (c))
796 temp = message ("Has MaxSet\n");
797 st = cstring_concatFree (st, temp);
803 cstring constraint_unparseDetailed (constraint c)
805 cstring st = cstring_undefined;
806 cstring temp = cstring_undefined;
810 llassert (constraint_isDefined (c) );
814 st = message ("Unable to resolve constraint:\n%q", constraint_unparseDeep (c));
818 st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_unparseDeep (c));
821 isLikely = constraint_isConstantOnly(c);
825 if (constraint_hasMaxSet (c))
827 temp = cstring_makeLiteral ("Likely out-of-bounds store:\n");
831 temp = cstring_makeLiteral ("Likely out-of-bounds read:\n");
837 if (constraint_hasMaxSet (c))
839 temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
843 temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
847 genExpr = exprNode_unparse (c->generatingExpr);
849 if (context_getFlag (FLG_CONSTRAINTLOCATION))
852 temp2 = message ("%s\n", genExpr);
853 temp = cstring_concatFree (temp, temp2);
856 st = cstring_concatFree (temp,st);
861 /*@only@*/ cstring constraint_unparse (constraint c) /*@*/
863 cstring st = cstring_undefined;
864 cstring type = cstring_undefined;
868 if (context_getFlag (FLG_PARENCONSTRAINT))
870 type = cstring_makeLiteral ("ensures: ");
874 type = cstring_makeLiteral ("ensures");
879 if (context_getFlag (FLG_PARENCONSTRAINT))
881 type = cstring_makeLiteral ("requires: ");
885 type = cstring_makeLiteral ("requires");
889 if (context_getFlag (FLG_PARENCONSTRAINT))
891 st = message ("%q: %q %q %q",
893 constraintExpr_print (c->lexpr),
894 arithType_print (c->ar),
895 constraintExpr_print (c->expr));
899 st = message ("%q %q %q %q",
901 constraintExpr_print (c->lexpr),
902 arithType_print (c->ar),
903 constraintExpr_print (c->expr));
908 cstring constraint_unparseOr (constraint c) /*@*/
913 ret = cstring_undefined;
915 llassert (constraint_isDefined (c) );
919 ret = cstring_concatFree (ret, constraint_unparse (temp));
923 while ( constraint_isDefined (temp))
925 ret = cstring_concatFree (ret, cstring_makeLiteral (" OR "));
926 ret = cstring_concatFree (ret, constraint_unparse (temp));
934 /*@only@*/ constraint constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition,
935 exprNodeList arglist)
938 llassert (constraint_isDefined (precondition) );
940 precondition->lexpr = constraintExpr_doSRefFixBaseParam (precondition->lexpr,
942 precondition->expr = constraintExpr_doSRefFixBaseParam (precondition->expr,
949 constraint constraint_doFixResult (constraint postcondition, /*@dependent@*/ exprNode fcnCall)
951 postcondition = constraint_copy (postcondition);
953 llassert (constraint_isDefined (postcondition) );
956 postcondition->lexpr = constraintExpr_doFixResult (postcondition->lexpr, fcnCall);
957 postcondition->expr = constraintExpr_doFixResult (postcondition->expr, fcnCall);
959 return postcondition;
961 /*Commenting out temporally
963 / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct )
966 invar = constraint_copy (invar);
967 invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct);
968 invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct);
974 /*@only@*/ constraint constraint_doSRefFixConstraintParam (constraint precondition,
975 exprNodeList arglist)
978 precondition = constraint_copy (precondition);
980 llassert (constraint_isDefined (precondition) );
982 precondition->lexpr = constraintExpr_doSRefFixConstraintParam (precondition->lexpr, arglist);
983 precondition->expr = constraintExpr_doSRefFixConstraintParam (precondition->expr, arglist);
985 precondition->fcnPre = FALSE;
986 return constraint_simplify(precondition);
989 constraint constraint_preserveOrig (/*@returned@*/ constraint c) /*@modifies c @*/
991 DPRINTF (("Doing constraint_preserverOrig for %q", constraint_printDetailed (c)));
992 llassert (constraint_isDefined (c));
994 if (c->orig == constraint_undefined)
996 c->orig = constraint_copy (c);
998 else if (c->orig->fcnPre)
1000 constraint temp = c->orig;
1002 /* avoid infinite loop */
1004 c->orig = constraint_copy (c);
1005 /*drl 03/2/2003 if c != NULL then the copy of c will != null*/
1006 llassert (constraint_isDefined (c->orig) );
1008 if (c->orig->orig == NULL)
1010 c->orig->orig = temp;
1015 llcontbug ((message ("Expected c->orig->orig to be null")));
1016 constraint_free (c->orig->orig);
1017 c->orig->orig = temp;
1023 DPRINTF (("Not changing constraint"));
1026 DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_unparseDetailed (c))));
1030 constraint constraint_togglePost (/*@returned@*/ constraint c)
1032 llassert (constraint_isDefined (c));
1037 constraint constraint_togglePostOrig (/*@returned@*/ constraint c)
1039 llassert (constraint_isDefined (c));
1041 if (c->orig != NULL)
1043 c->orig = constraint_togglePost (c->orig);
1049 bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c)
1051 llassert (constraint_isDefined (c));
1052 return (c->orig != NULL);
1056 constraint constraint_undump (FILE *f)
1061 constraintExpr lexpr, expr;
1064 os = mstring_create (MAX_DUMP_LINE_LENGTH);
1065 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1067 if (!mstring_isDefined (s))
1069 llfatalbug (message ("Library file is corrupted") );
1072 fcnPre = (bool) reader_getInt (&s);
1074 post = (bool) reader_getInt (&s);
1076 ar = (arithType) reader_getInt (&s);
1078 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1080 if (! mstring_isDefined(s) )
1082 llfatalbug(message("Library file is corrupted") );
1085 reader_checkChar (&s, 'l');
1087 lexpr = constraintExpr_undump (f);
1089 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1091 reader_checkChar (&s, 'r');
1093 if (! mstring_isDefined(s) )
1095 llfatalbug(message("Library file is corrupted") );
1098 expr = constraintExpr_undump (f);
1100 c = constraint_makeNew ();
1110 c = constraint_preserveOrig (c);
1115 void constraint_dump (/*@observer@*/ constraint c, FILE *f)
1121 constraintExpr lexpr;
1122 constraintExpr expr;
1124 llassert (constraint_isDefined (c) );
1132 fprintf (f, "%d@%d@%d\n", (int) fcnPre, (int) post, (int) ar);
1134 constraintExpr_dump (lexpr, f);
1136 constraintExpr_dump (expr, f);
1140 int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint * c1, /*@observer@*/ /*@temp@*/ const constraint * c2) /*@*/
1146 llassert (constraint_isDefined (*c1));
1147 llassert (constraint_isDefined (*c2));
1149 if (constraint_isUndefined (*c1))
1151 if (constraint_isUndefined (*c2))
1157 if (constraint_isUndefined (*c2))
1162 loc1 = constraint_getFileloc (*c1);
1163 loc2 = constraint_getFileloc (*c2);
1165 ret = fileloc_compare (loc1, loc2);
1167 fileloc_free (loc1);
1168 fileloc_free (loc2);
1174 bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c)
1176 llassert (constraint_isDefined (c));
1178 if (constraint_isUndefined (c))
1185 static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c)
1189 llassert (constraint_isDefined (c) );
1191 l = constraintExpr_getDepth (c->lexpr);
1192 r = constraintExpr_getDepth (c->expr);
1196 DPRINTF (( message ("constraint depth returning %d for %s", l, constraint_unparse (c))));
1201 DPRINTF (( message ("constraint depth returning %d for %s", r, constraint_unparse (c))));
1207 bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c)
1211 temp = constraint_getDepth (c);
1222 /*drl added 12/19/2002*/
1223 /*whether constraints consist only of
1224 terms which are constants*/
1225 bool constraint_isConstantOnly (constraint c)
1229 llassert (constraint_isDefined (c) );
1231 l = constraintExpr_isConstantOnly(c->lexpr);
1232 r = constraintExpr_isConstantOnly(c->expr);