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);
370 constraint constraint_makeSRefWriteSafeInt (sRef s, int ind)
372 constraint ret = constraint_makeNew ();
375 ret->lexpr = constraintExpr_makeSRefMaxset ( s);
377 ret->expr = constraintExpr_makeIntLiteral (ind);
382 /* drl added 01/12/2000
384 makes the constraint: Ensures index <= MaxRead (buffer) */
386 constraint constraint_makeEnsureLteMaxRead (exprNode index, exprNode buffer)
388 constraint ret = constraint_makeNew ();
390 ret->lexpr = constraintExpr_makeValueExpr (index);
392 ret->expr = constraintExpr_makeMaxReadExpr (buffer);
397 constraint constraint_makeWriteSafeExprNode (exprNode po, exprNode ind)
399 constraint ret = constraint_makeNew ();
402 ret->lexpr =constraintExpr_makeMaxSetExpr (po);
404 ret->expr = constraintExpr_makeValueExpr (ind);
409 constraint constraint_makeReadSafeInt ( exprNode t1, int index)
411 constraint ret = constraint_makeNew ();
413 ret->lexpr = constraintExpr_makeMaxReadExpr (t1);
415 ret->expr = constraintExpr_makeIntLiteral (index);
420 constraint constraint_makeSRefReadSafeInt (sRef s, int ind)
422 constraint ret = constraint_makeNew ();
425 ret->lexpr = constraintExpr_makeSRefMaxRead (s);
427 ret->expr = constraintExpr_makeIntLiteral (ind);
432 constraint constraint_makeEnsureMaxReadAtLeast (exprNode t1, exprNode t2, fileloc sequencePoint)
436 ret = constraint_makeReadSafeExprNode (t1, t2);
437 llassert (constraint_isDefined (ret) );
439 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
445 static constraint constraint_makeEnsuresOpConstraintExpr (/*@only@*/ constraintExpr c1, /*@only@*/ constraintExpr c2, fileloc sequencePoint, arithType ar)
450 llassert (constraintExpr_isDefined (c1) && constraintExpr_isDefined (c2));
452 ret = constraint_makeNew ();
458 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
462 static constraint constraint_makeEnsuresOp (/*@dependent@*/ exprNode e1, /*@dependent@*/ exprNode e2, fileloc sequencePoint, arithType ar)
464 constraintExpr c1, c2;
468 if (! (exprNode_isDefined (e1) && exprNode_isDefined (e2)))
470 llcontbug ((message ("null exprNode, Exprnodes are %s and %s",
471 exprNode_unparse (e1), exprNode_unparse (e2))
476 c1 = constraintExpr_makeValueExpr (e);
479 c2 = constraintExpr_makeValueExpr (e);
481 ret = constraint_makeEnsuresOpConstraintExpr (c1, c2, sequencePoint, ar);
487 /* make constraint ensures e1 == e2 */
489 constraint constraint_makeEnsureEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
491 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, EQ));
494 /*make constraint ensures e1 < e2 */
495 constraint constraint_makeEnsureLessThan (exprNode e1, exprNode e2, fileloc sequencePoint)
497 constraintExpr t1, t2;
500 t1 = constraintExpr_makeValueExpr (e1);
501 t2 = constraintExpr_makeValueExpr (e2);
503 /*change this to e1 <= (e2 -1) */
505 t2 = constraintExpr_makeDecConstraintExpr (t2);
507 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, LTE);
509 t3 = constraint_simplify(t3);
513 constraint constraint_makeEnsureLessThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
515 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, LTE));
518 constraint constraint_makeEnsureGreaterThan (exprNode e1, exprNode e2, fileloc sequencePoint)
520 constraintExpr t1, t2;
523 t1 = constraintExpr_makeValueExpr (e1);
524 t2 = constraintExpr_makeValueExpr (e2);
527 /* change this to e1 >= (e2 + 1) */
528 t2 = constraintExpr_makeIncConstraintExpr (t2);
530 t3 = constraint_makeEnsuresOpConstraintExpr (t1, t2, sequencePoint, GTE);
532 t3 = constraint_simplify(t3);
537 constraint constraint_makeEnsureGreaterThanEqual (exprNode e1, exprNode e2, fileloc sequencePoint)
539 return ( constraint_makeEnsuresOp (e1, e2, sequencePoint, GTE));
544 /* Makes the constraint e = e + f */
545 constraint constraint_makeAddAssign (exprNode e, exprNode f, fileloc sequencePoint)
547 constraintExpr x1, x2, y;
550 ret = constraint_makeNew ();
552 x1 = constraintExpr_makeValueExpr (e);
553 x2 = constraintExpr_copy (x1);
554 y = constraintExpr_makeValueExpr (f);
559 ret->expr = constraintExpr_makeAddExpr (x2, y);
561 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
567 /* Makes the constraint e = e - f */
568 constraint constraint_makeSubtractAssign (exprNode e, exprNode f, fileloc sequencePoint)
570 constraintExpr x1, x2, y;
573 ret = constraint_makeNew ();
575 x1 = constraintExpr_makeValueExpr (e);
576 x2 = constraintExpr_copy (x1);
577 y = constraintExpr_makeValueExpr (f);
582 ret->expr = constraintExpr_makeSubtractExpr (x2, y);
584 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
589 constraint constraint_makeMaxSetSideEffectPostDecrement (exprNode e, fileloc sequencePoint)
591 constraint ret = constraint_makeNew ();
593 ret->lexpr = constraintExpr_makeValueExpr (e);
596 ret->expr = constraintExpr_makeValueExpr (e);
597 ret->expr = constraintExpr_makeDecConstraintExpr (ret->expr);
598 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
601 constraint constraint_makeMaxSetSideEffectPostIncrement (exprNode e, fileloc sequencePoint)
603 constraint ret = constraint_makeNew ();
605 ret->lexpr = constraintExpr_makeValueExpr (e);
608 ret->expr = constraintExpr_makeValueExpr (e);
609 ret->expr = constraintExpr_makeIncConstraintExpr (ret->expr);
611 ret->lexpr = constraintExpr_setFileloc (ret->lexpr, sequencePoint);
616 void constraint_free (/*@only@*/ constraint c)
618 llassert (constraint_isDefined (c));
621 if (constraint_isDefined (c->orig))
622 constraint_free (c->orig);
623 if ( constraint_isDefined (c->or))
624 constraint_free (c->or);
627 constraintExpr_free (c->lexpr);
628 constraintExpr_free (c->expr);
639 cstring arithType_print (arithType ar) /*@*/
641 cstring st = cstring_undefined;
645 st = cstring_makeLiteral ("<");
648 st = cstring_makeLiteral ("<=");
651 st = cstring_makeLiteral (">");
654 st = cstring_makeLiteral (">=");
657 st = cstring_makeLiteral ("==");
660 st = cstring_makeLiteral ("NONNEGATIVE");
663 st = cstring_makeLiteral ("POSITIVE");
672 void constraint_printErrorPostCondition (constraint c, fileloc loc)
675 fileloc errorLoc, temp;
677 string = constraint_printDetailedPostCondition (c);
683 temp = constraint_getFileloc (c);
686 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
688 string = cstring_replaceChar(string, '\n', ' ');
691 if (fileloc_isDefined (temp))
694 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
699 voptgenerror ( FLG_CHECKPOST, string, errorLoc);
703 /*drl added 8-11-001*/
704 cstring constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c) /*@*/
709 string = constraint_print (c);
711 errorLoc = constraint_getFileloc (c);
713 ret = message ("constraint: %q @ %q", string, fileloc_unparse (errorLoc));
715 fileloc_free (errorLoc);
722 void constraint_printError (constraint c, fileloc loc)
725 fileloc errorLoc, temp;
730 llassert (constraint_isDefined (c) );
732 /*drl 11/26/2001 avoid printing tautological constraints */
733 if (constraint_isAlwaysTrue (c))
739 string = constraint_printDetailed (c);
743 temp = constraint_getFileloc (c);
745 if (fileloc_isDefined (temp))
752 DPRINTF (("constraint %s had undefined fileloc %s", constraint_print (c), fileloc_unparse (temp)));
754 errorLoc = fileloc_copy (errorLoc);
758 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES ) )
760 string = cstring_replaceChar(string, '\n', ' ');
763 /*drl added 12/19/2002 print
764 a different error fro "likely" bounds-errors*/
766 isLikely = constraint_isConstantOnly(c);
772 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
776 if (constraint_hasMaxSet (c))
778 voptgenerror (FLG_LIKELYBOUNDSWRITE, string, errorLoc);
782 voptgenerror (FLG_LIKELYBOUNDSREAD, string, errorLoc);
788 voptgenerror (FLG_FUNCTIONPOST, string, errorLoc);
792 if (constraint_hasMaxSet (c))
794 voptgenerror (FLG_BOUNDSWRITE, string, errorLoc);
798 voptgenerror (FLG_BOUNDSREAD, string, errorLoc);
802 fileloc_free(errorLoc);
805 static cstring constraint_printDeep (constraint c)
808 cstring st = cstring_undefined;
811 llassert (constraint_isDefined (c) );
814 st = constraint_print(c);
816 if (c->orig != constraint_undefined)
818 st = cstring_appendChar (st, '\n');
819 genExpr = exprNode_unparse (c->orig->generatingExpr);
825 st = cstring_concatFree (st, message (" derived from %s precondition: %q",
826 genExpr, constraint_printDeep (c->orig)));
830 st = cstring_concatFree (st, message (" needed to satisfy precondition:\n%q",
831 constraint_printDeep (c->orig)));
836 st = cstring_concatFree (st, message ("derived from: %q",
837 constraint_printDeep (c->orig)));
845 static /*@only@*/ cstring constraint_printDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c)
847 cstring st = cstring_undefined;
851 llassert (constraint_isDefined (c) );
853 st = message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q", constraint_printDeep (c));
855 genExpr = exprNode_unparse (c->generatingExpr);
857 if (context_getFlag (FLG_CONSTRAINTLOCATION))
861 temp = message ("\nOriginal Generating expression %q: %s\n",
862 fileloc_unparse ( exprNode_getfileloc (c->generatingExpr)),
864 st = cstring_concatFree (st, temp);
866 if (constraint_hasMaxSet (c))
868 temp = message ("Has MaxSet\n");
869 st = cstring_concatFree (st, temp);
875 cstring constraint_printDetailed (constraint c)
877 cstring st = cstring_undefined;
878 cstring temp = cstring_undefined;
882 llassert (constraint_isDefined (c) );
886 st = message ("Unable to resolve constraint:\n%q", constraint_printDeep (c));
890 st = message ("Block Post condition:\nThis function block has the post condition %q", constraint_printDeep (c));
893 isLikely = constraint_isConstantOnly(c);
897 if (constraint_hasMaxSet (c))
899 temp = cstring_makeLiteral ("Likely out-of-bounds store:\n");
903 temp = cstring_makeLiteral ("Likely out-of-bounds read:\n");
909 if (constraint_hasMaxSet (c))
911 temp = cstring_makeLiteral ("Possible out-of-bounds store:\n");
915 temp = cstring_makeLiteral ("Possible out-of-bounds read:\n");
919 genExpr = exprNode_unparse (c->generatingExpr);
921 if (context_getFlag (FLG_CONSTRAINTLOCATION))
924 temp2 = message ("%s\n", genExpr);
925 temp = cstring_concatFree (temp, temp2);
928 st = cstring_concatFree (temp,st);
933 /*@only@*/ cstring constraint_print (constraint c) /*@*/
935 cstring st = cstring_undefined;
936 cstring type = cstring_undefined;
940 if (context_getFlag (FLG_PARENCONSTRAINT))
942 type = cstring_makeLiteral ("ensures: ");
946 type = cstring_makeLiteral ("ensures");
951 if (context_getFlag (FLG_PARENCONSTRAINT))
953 type = cstring_makeLiteral ("requires: ");
957 type = cstring_makeLiteral ("requires");
961 if (context_getFlag (FLG_PARENCONSTRAINT))
963 st = message ("%q: %q %q %q",
965 constraintExpr_print (c->lexpr),
966 arithType_print (c->ar),
967 constraintExpr_print (c->expr)
972 st = message ("%q %q %q %q",
974 constraintExpr_print (c->lexpr),
975 arithType_print (c->ar),
976 constraintExpr_print (c->expr)
982 cstring constraint_printOr (constraint c) /*@*/
987 ret = cstring_undefined;
989 llassert (constraint_isDefined (c) );
993 ret = cstring_concatFree (ret, constraint_print (temp));
997 while ( constraint_isDefined (temp))
999 ret = cstring_concatFree (ret, cstring_makeLiteral (" OR "));
1000 ret = cstring_concatFree (ret, constraint_print (temp));
1008 /*@only@*/ constraint constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition,
1009 exprNodeList arglist)
1012 llassert (constraint_isDefined (precondition) );
1014 precondition->lexpr = constraintExpr_doSRefFixBaseParam (precondition->lexpr,
1016 precondition->expr = constraintExpr_doSRefFixBaseParam (precondition->expr,
1019 return precondition;
1023 constraint constraint_doFixResult (constraint postcondition, /*@dependent@*/ exprNode fcnCall)
1025 postcondition = constraint_copy (postcondition);
1027 llassert (constraint_isDefined (postcondition) );
1030 postcondition->lexpr = constraintExpr_doFixResult (postcondition->lexpr, fcnCall);
1031 postcondition->expr = constraintExpr_doFixResult (postcondition->expr, fcnCall);
1033 return postcondition;
1035 /*Commenting out temporally
1037 / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct )
1040 invar = constraint_copy (invar);
1041 invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct);
1042 invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct);
1048 /*@only@*/ constraint constraint_doSRefFixConstraintParam (constraint precondition,
1049 exprNodeList arglist)
1052 precondition = constraint_copy (precondition);
1054 llassert (constraint_isDefined (precondition) );
1056 precondition->lexpr = constraintExpr_doSRefFixConstraintParam (precondition->lexpr, arglist);
1057 precondition->expr = constraintExpr_doSRefFixConstraintParam (precondition->expr, arglist);
1059 precondition->fcnPre = FALSE;
1060 return constraint_simplify(precondition);
1063 constraint constraint_preserveOrig (/*@returned@*/ constraint c) /*@modifies c @*/
1066 DPRINTF ((message ("Doing constraint_preserverOrig for %q ", constraint_printDetailed (c))));
1068 llassert (constraint_isDefined (c) );
1070 if (c->orig == constraint_undefined)
1071 c->orig = constraint_copy (c);
1073 else if (c->orig->fcnPre)
1079 /* avoid infinite loop */
1081 c->orig = constraint_copy (c);
1082 /*drl 03/2/2003 if c != NULL then the copy of c will != null*/
1083 llassert (constraint_isDefined (c->orig) );
1085 if (c->orig->orig == NULL)
1087 c->orig->orig = temp;
1092 llcontbug ((message ("Expected c->orig->orig to be null")));
1093 constraint_free (c->orig->orig);
1094 c->orig->orig = temp;
1100 DPRINTF ((message ("Not changing constraint")));
1103 DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_printDetailed (c))));
1112 constraint constraint_togglePost (/*@returned@*/ constraint c)
1114 llassert (constraint_isDefined (c) );
1120 constraint constraint_togglePostOrig (/*@returned@*/ constraint c)
1122 llassert (constraint_isDefined (c) );
1124 if (c->orig != NULL)
1125 c->orig = constraint_togglePost (c->orig);
1129 bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c)
1132 llassert (constraint_isDefined (c) );
1134 if (c->orig == NULL)
1141 constraint constraint_undump (FILE *f)
1148 constraintExpr lexpr;
1149 constraintExpr expr;
1156 os = mstring_create (MAX_DUMP_LINE_LENGTH);
1158 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1160 if (! mstring_isDefined(s) )
1162 llfatalbug(message("Library file is corrupted") );
1165 fcnPre = (bool) reader_getInt (&s);
1167 post = (bool) reader_getInt (&s);
1169 ar = (arithType) reader_getInt (&s);
1171 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1173 if (! mstring_isDefined(s) )
1175 llfatalbug(message("Library file is corrupted") );
1178 reader_checkChar (&s, 'l');
1180 lexpr = constraintExpr_undump (f);
1182 s = fgets (os, MAX_DUMP_LINE_LENGTH, f);
1184 reader_checkChar (&s, 'r');
1186 if (! mstring_isDefined(s) )
1188 llfatalbug(message("Library file is corrupted") );
1191 expr = constraintExpr_undump (f);
1193 c = constraint_makeNew ();
1203 c = constraint_preserveOrig (c);
1208 void constraint_dump (/*@observer@*/ constraint c, FILE *f)
1214 constraintExpr lexpr;
1215 constraintExpr expr;
1217 llassert (constraint_isDefined (c) );
1225 fprintf (f, "%d@%d@%d\n", (int) fcnPre, (int) post, (int) ar);
1227 constraintExpr_dump (lexpr, f);
1229 constraintExpr_dump (expr, f);
1233 int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint * c1, /*@observer@*/ /*@temp@*/ const constraint * c2) /*@*/
1239 llassert (constraint_isDefined (*c1));
1240 llassert (constraint_isDefined (*c2));
1242 if (constraint_isUndefined (*c1))
1244 if (constraint_isUndefined (*c2))
1250 if (constraint_isUndefined (*c2))
1255 loc1 = constraint_getFileloc (*c1);
1256 loc2 = constraint_getFileloc (*c2);
1258 ret = fileloc_compare (loc1, loc2);
1260 fileloc_free (loc1);
1261 fileloc_free (loc2);
1267 bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c)
1269 llassert (constraint_isDefined (c));
1271 if (constraint_isUndefined (c))
1278 static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c)
1282 llassert (constraint_isDefined (c) );
1284 l = constraintExpr_getDepth (c->lexpr);
1285 r = constraintExpr_getDepth (c->expr);
1289 DPRINTF (( message ("constraint depth returning %d for %s", l, constraint_print (c))));
1294 DPRINTF (( message ("constraint depth returning %d for %s", r, constraint_print (c))));
1300 bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c)
1304 temp = constraint_getDepth (c);
1315 /*drl added 12/19/2002*/
1316 /*whether constraints consist only of
1317 terms which are constants*/
1318 bool constraint_isConstantOnly (constraint c)
1322 llassert (constraint_isDefined (c) );
1324 l = constraintExpr_isConstantOnly(c->lexpr);
1325 r = constraintExpr_isConstantOnly(c->expr);