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 "exprChecks.h"
35 # include "exprNodeSList.h"
37 static /*@only@*/ cstring
38 constraint_unparseDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint p_c
);
40 static /*@notnull@*/ /*@special@*/ constraint
constraint_makeNew (void)
41 /*@post:isnull result->or, result->orig, result->generatingExpr, result->fcnPre @*/
42 /*@defines result->or, result->generatingExpr, result->orig, result->fcnPre @*/;
45 advanceField (char **s
)
47 reader_checkChar (s
, '@');
50 bool constraint_same (constraint c1
, constraint c2
)
52 llassert (c1
!= NULL
);
53 llassert (c2
!= NULL
);
60 if (!constraintExpr_similar (c1
->lexpr
, c2
->lexpr
))
65 if (!constraintExpr_similar (c1
->expr
, c2
->expr
))
73 constraint
makeConstraintParse3 (constraintExpr l
, lltok relOp
, constraintExpr r
)
76 ret
= constraint_makeNew ();
77 llassert (constraintExpr_isDefined (l
));
79 ret
->lexpr
= constraintExpr_copy (l
);
81 if (lltok_getTok (relOp
) == GE_OP
)
85 else if (lltok_getTok (relOp
) == LE_OP
)
89 else if (lltok_getTok (relOp
) == EQ_OP
)
94 llfatalbug ( message ("Unsupported relational operator"));
96 ret
->expr
= constraintExpr_copy (r
);
100 ret
->orig
= constraint_copy (ret
);
102 ret
= constraint_simplify (ret
);
103 /* ret->orig = ret; */
105 DPRINTF (("GENERATED CONSTRAINT:"));
106 DPRINTF ((message ("%s", constraint_unparse (ret
))));
110 constraint
constraint_copy (/*@temp@*/ /*@observer@*/ constraint c
)
112 if (!constraint_isDefined (c
))
114 return constraint_undefined
;
118 constraint ret
= constraint_makeNew ();
119 ret
->lexpr
= constraintExpr_copy (c
->lexpr
);
121 ret
->expr
= constraintExpr_copy (c
->expr
);
124 ret
->generatingExpr
= c
->generatingExpr
;
128 ret
->orig
= constraint_copy (c
->orig
);
133 ret
->or = constraint_copy (c
->or);
137 ret
->fcnPre
= c
->fcnPre
;
143 /*like copy except it doesn't allocate memory for the constraint*/
145 void constraint_overWrite (constraint c1
, constraint c2
)
147 llassert (constraint_isDefined (c1
) && constraint_isDefined (c2
));
151 DPRINTF ((message ("OverWriteing constraint %q with %q", constraint_unparse (c1
),
152 constraint_unparse (c2
))));
154 constraintExpr_free (c1
->lexpr
);
155 constraintExpr_free (c1
->expr
);
157 c1
->lexpr
= constraintExpr_copy (c2
->lexpr
);
159 c1
->expr
= constraintExpr_copy (c2
->expr
);
162 if (c1
->orig
!= NULL
)
163 constraint_free (c1
->orig
);
165 if (c2
->orig
!= NULL
)
166 c1
->orig
= constraint_copy (c2
->orig
);
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
)
208 if (!constraint_isDefined (c
))
213 if (c
->generatingExpr
== NULL
)
215 c
->generatingExpr
= e
;
216 DPRINTF ((message ("setting generatingExpr for %s to %s", constraint_unparse (c
), exprNode_unparse (e
)) ));
220 DPRINTF ((message ("Not setting generatingExpr for %s to %s", constraint_unparse (c
), exprNode_unparse (e
)) ));
224 /*@noaccess exprNode@*/
226 constraint
constraint_origAddGeneratingExpr (/*@returned@*/ constraint c
, exprNode e
)
228 llassert (constraint_isDefined (c
) );
230 if (c
->orig
!= constraint_undefined
)
232 c
->orig
= constraint_addGeneratingExpr (c
->orig
, e
);
236 DPRINTF ((message ("constraint_origAddGeneratingExpr: Not setting generatingExpr for %s to %s", constraint_unparse (c
), exprNode_unparse (e
)) ));
241 constraint
constraint_setFcnPre (/*@returned@*/ constraint c
)
244 llassert (constraint_isDefined (c
) );
246 if (c
->orig
!= constraint_undefined
)
248 c
->orig
->fcnPre
= TRUE
;
253 DPRINTF (( message ("Warning Setting fcnPre directly")));
261 fileloc
constraint_getFileloc (constraint c
)
263 llassert (constraint_isDefined (c
) );
265 if (exprNode_isDefined (c
->generatingExpr
))
266 return (fileloc_copy (exprNode_loc (c
->generatingExpr
)));
268 return (constraintExpr_loc (c
->lexpr
));
271 static bool checkForMaxSet (constraint c
)
273 llassert (constraint_isDefined (c
));
274 return (constraintExpr_hasMaxSet (c
->lexpr
) || constraintExpr_hasMaxSet (c
->expr
));
277 bool constraint_hasMaxSet (constraint c
)
279 llassert (constraint_isDefined (c
) );
281 if (checkForMaxSet (c
))
286 if (checkForMaxSet (c
->orig
))
293 constraint
constraint_makeReadSafeExprNode (exprNode po
, exprNode ind
)
295 constraint ret
= constraint_makeNew ();
299 ret
->lexpr
= constraintExpr_makeMaxReadExpr (po
);
301 ret
->expr
= constraintExpr_makeValueExpr (ind
);
306 constraint
constraint_makeWriteSafeInt (exprNode po
, int ind
)
308 constraint ret
= constraint_makeNew ();
309 ret
->lexpr
=constraintExpr_makeMaxSetExpr (po
);
311 ret
->expr
= constraintExpr_makeIntLiteral (ind
);
315 constraint
constraint_makeSRefSetBufferSize (sRef s
, long int size
)
317 constraint ret
= constraint_makeNew ();
318 ret
->lexpr
= constraintExpr_makeSRefMaxset (s
);
320 ret
->expr
= constraintExpr_makeIntLiteral ((int)size
);
325 constraint
constraint_makeSRefWriteSafeInt (sRef s
, int ind
)
327 constraint ret
= constraint_makeNew ();
328 ret
->lexpr
= constraintExpr_makeSRefMaxset ( s
);
330 ret
->expr
= constraintExpr_makeIntLiteral (ind
);
335 /* drl added 01/12/2000
336 ** makes the constraint: Ensures index <= MaxRead (buffer)
339 constraint
constraint_makeEnsureLteMaxRead (exprNode index
, exprNode buffer
)
341 constraint ret
= constraint_makeNew ();
343 ret
->lexpr
= constraintExpr_makeValueExpr (index
);
345 ret
->expr
= constraintExpr_makeMaxReadExpr (buffer
);
350 constraint
constraint_makeWriteSafeExprNode (exprNode po
, exprNode ind
)
352 constraint ret
= constraint_makeNew ();
354 ret
->lexpr
=constraintExpr_makeMaxSetExpr (po
);
356 ret
->expr
= constraintExpr_makeValueExpr (ind
);
361 constraint
constraint_makeReadSafeInt (exprNode t1
, int index
)
363 constraint ret
= constraint_makeNew ();
365 ret
->lexpr
= constraintExpr_makeMaxReadExpr (t1
);
367 ret
->expr
= constraintExpr_makeIntLiteral (index
);
372 constraint
constraint_makeSRefReadSafeInt (sRef s
, int ind
)
374 constraint ret
= constraint_makeNew ();
376 ret
->lexpr
= constraintExpr_makeSRefMaxRead (s
);
378 ret
->expr
= constraintExpr_makeIntLiteral (ind
);
383 constraint
constraint_makeEnsureMaxReadAtLeast (exprNode t1
, exprNode t2
, fileloc sequencePoint
)
385 constraint ret
= constraint_makeReadSafeExprNode (t1
, t2
);
386 llassert (constraint_isDefined (ret
));
388 ret
->lexpr
= constraintExpr_setFileloc (ret
->lexpr
, sequencePoint
);
395 constraint_makeEnsuresOpConstraintExpr (/*@only@*/ constraintExpr c1
, /*@only@*/ constraintExpr c2
,
396 fileloc sequencePoint
, arithType ar
)
398 if (constraintExpr_isDefined (c1
) && constraintExpr_isDefined (c2
))
400 constraint ret
= constraint_makeNew ();
405 ret
->lexpr
= constraintExpr_setFileloc (ret
->lexpr
, sequencePoint
);
410 return constraint_undefined
;
415 constraint_makeEnsuresOp (/*@dependent@*/ exprNode e1
, /*@dependent@*/ exprNode e2
,
416 fileloc sequencePoint
, arithType ar
)
418 constraintExpr c1
, c2
;
420 if (!(exprNode_isDefined (e1
) && exprNode_isDefined (e2
)))
422 llcontbug (message ("Invalid exprNode, Exprnodes are %s and %s",
423 exprNode_unparse (e1
), exprNode_unparse (e2
)));
426 c1
= constraintExpr_makeValueExpr (e1
);
427 c2
= constraintExpr_makeValueExpr (e2
);
429 return constraint_makeEnsuresOpConstraintExpr (c1
, c2
, sequencePoint
, ar
);
432 /* make constraint ensures e1 == e2 */
434 constraint
constraint_makeEnsureEqual (exprNode e1
, exprNode e2
, fileloc sequencePoint
)
436 return (constraint_makeEnsuresOp (e1
, e2
, sequencePoint
, EQ
));
439 /* make constraint ensures e1 < e2 */
440 constraint
constraint_makeEnsureLessThan (exprNode e1
, exprNode e2
, fileloc sequencePoint
)
442 constraintExpr t1
, t2
;
445 t1
= constraintExpr_makeValueExpr (e1
);
446 t2
= constraintExpr_makeValueExpr (e2
);
448 /* change this to e1 <= (e2 -1) */
450 t2
= constraintExpr_makeDecConstraintExpr (t2
);
451 t3
= constraint_makeEnsuresOpConstraintExpr (t1
, t2
, sequencePoint
, LTE
);
452 t3
= constraint_simplify (t3
);
456 constraint
constraint_makeEnsureLessThanEqual (exprNode e1
, exprNode e2
, fileloc sequencePoint
)
458 return (constraint_makeEnsuresOp (e1
, e2
, sequencePoint
, LTE
));
461 constraint
constraint_makeEnsureGreaterThan (exprNode e1
, exprNode e2
, fileloc sequencePoint
)
463 constraintExpr t1
, t2
;
466 t1
= constraintExpr_makeValueExpr (e1
);
467 t2
= constraintExpr_makeValueExpr (e2
);
469 /* change this to e1 >= (e2 + 1) */
470 t2
= constraintExpr_makeIncConstraintExpr (t2
);
472 t3
= constraint_makeEnsuresOpConstraintExpr (t1
, t2
, sequencePoint
, GTE
);
473 t3
= constraint_simplify(t3
);
478 constraint
constraint_makeEnsureGreaterThanEqual (exprNode e1
, exprNode e2
, fileloc sequencePoint
)
480 return ( constraint_makeEnsuresOp (e1
, e2
, sequencePoint
, GTE
));
485 /* Makes the constraint e = e + f */
486 constraint
constraint_makeAddAssign (exprNode e
, exprNode f
, fileloc sequencePoint
)
488 constraintExpr x1
, x2
, y
;
491 ret
= constraint_makeNew ();
493 x1
= constraintExpr_makeValueExpr (e
);
494 x2
= constraintExpr_copy (x1
);
495 y
= constraintExpr_makeValueExpr (f
);
500 ret
->expr
= constraintExpr_makeAddExpr (x2
, y
);
502 ret
->lexpr
= constraintExpr_setFileloc (ret
->lexpr
, sequencePoint
);
508 /* Makes the constraint e = e - f */
509 constraint
constraint_makeSubtractAssign (exprNode e
, exprNode f
, fileloc sequencePoint
)
511 constraintExpr x1
, x2
, y
;
514 ret
= constraint_makeNew ();
516 x1
= constraintExpr_makeValueExpr (e
);
517 x2
= constraintExpr_copy (x1
);
518 y
= constraintExpr_makeValueExpr (f
);
523 ret
->expr
= constraintExpr_makeSubtractExpr (x2
, y
);
525 ret
->lexpr
= constraintExpr_setFileloc (ret
->lexpr
, sequencePoint
);
530 constraint
constraint_makeMaxSetSideEffectPostDecrement (exprNode e
, fileloc sequencePoint
)
532 constraint ret
= constraint_makeNew ();
534 ret
->lexpr
= constraintExpr_makeValueExpr (e
);
537 ret
->expr
= constraintExpr_makeValueExpr (e
);
538 ret
->expr
= constraintExpr_makeDecConstraintExpr (ret
->expr
);
539 ret
->lexpr
= constraintExpr_setFileloc (ret
->lexpr
, sequencePoint
);
542 constraint
constraint_makeMaxSetSideEffectPostIncrement (exprNode e
, fileloc sequencePoint
)
544 constraint ret
= constraint_makeNew ();
546 ret
->lexpr
= constraintExpr_makeValueExpr (e
);
549 ret
->expr
= constraintExpr_makeValueExpr (e
);
550 ret
->expr
= constraintExpr_makeIncConstraintExpr (ret
->expr
);
552 ret
->lexpr
= constraintExpr_setFileloc (ret
->lexpr
, sequencePoint
);
557 void constraint_free (/*@only@*/ constraint c
)
559 if (constraint_isDefined (c
))
561 constraint_free (c
->orig
);
564 constraint_free (c
->or);
567 constraintExpr_free (c
->lexpr
);
570 constraintExpr_free (c
->expr
);
577 cstring
arithType_print (arithType ar
) /*@*/
579 cstring st
= cstring_undefined
;
583 st
= cstring_makeLiteral ("<");
586 st
= cstring_makeLiteral ("<=");
589 st
= cstring_makeLiteral (">");
592 st
= cstring_makeLiteral (">=");
595 st
= cstring_makeLiteral ("==");
598 st
= cstring_makeLiteral ("NONNEGATIVE");
601 st
= cstring_makeLiteral ("POSITIVE");
610 void constraint_printErrorPostCondition (constraint c
, fileloc loc
)
613 fileloc errorLoc
, temp
;
615 string
= constraint_unparseDetailedPostCondition (c
);
619 temp
= constraint_getFileloc (c
);
621 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES
))
623 string
= cstring_replaceChar (string
, '\n', ' ');
626 if (fileloc_isDefined (temp
))
629 voptgenerror (FLG_CHECKPOST
, string
, errorLoc
);
634 voptgenerror (FLG_CHECKPOST
, string
, errorLoc
);
638 /*drl added 8-11-001*/
639 cstring
constraint_printLocation (/*@observer@*/ /*@temp@*/ constraint c
) /*@*/
644 string
= constraint_unparse (c
);
646 errorLoc
= constraint_getFileloc (c
);
648 ret
= message ("constraint: %q @ %q", string
, fileloc_unparse (errorLoc
));
649 fileloc_free (errorLoc
);
656 void constraint_printError (constraint c
, fileloc loc
)
659 fileloc errorLoc
, temp
;
663 llassert (constraint_isDefined (c
) );
665 /*drl 11/26/2001 avoid printing tautological constraints */
666 if (constraint_isAlwaysTrue (c
))
672 string
= constraint_unparseDetailed (c
);
676 temp
= constraint_getFileloc (c
);
678 if (fileloc_isDefined (temp
))
685 DPRINTF (("constraint %s had undefined fileloc %s",
686 constraint_unparse (c
), fileloc_unparse (temp
)));
688 errorLoc
= fileloc_copy (errorLoc
);
692 if (context_getFlag (FLG_BOUNDSCOMPACTERRORMESSAGES
))
694 string
= cstring_replaceChar(string
, '\n', ' ');
697 /*drl added 12/19/2002 print
698 a different error fro "likely" bounds-errors*/
700 isLikely
= constraint_isConstantOnly (c
);
706 voptgenerror (FLG_FUNCTIONPOST
, string
, errorLoc
);
710 if (constraint_hasMaxSet (c
))
712 voptgenerror (FLG_LIKELYBOUNDSWRITE
, string
, errorLoc
);
716 voptgenerror (FLG_LIKELYBOUNDSREAD
, string
, errorLoc
);
722 voptgenerror (FLG_FUNCTIONPOST
, string
, errorLoc
);
726 if (constraint_hasMaxSet (c
))
728 voptgenerror (FLG_BOUNDSWRITE
, string
, errorLoc
);
732 voptgenerror (FLG_BOUNDSREAD
, string
, errorLoc
);
736 fileloc_free(errorLoc
);
739 static cstring
constraint_unparseDeep (constraint c
)
744 llassert (constraint_isDefined (c
));
745 st
= constraint_unparse (c
);
747 if (c
->orig
!= constraint_undefined
)
749 st
= cstring_appendChar (st
, '\n');
750 genExpr
= exprNode_unparse (c
->orig
->generatingExpr
);
756 st
= cstring_concatFree (st
, message (" derived from %s precondition: %q",
757 genExpr
, constraint_unparseDeep (c
->orig
)));
761 st
= cstring_concatFree (st
, message (" needed to satisfy precondition:\n%q",
762 constraint_unparseDeep (c
->orig
)));
767 st
= cstring_concatFree (st
, message ("derived from: %q",
768 constraint_unparseDeep (c
->orig
)));
776 static /*@only@*/ cstring
constraint_unparseDetailedPostCondition (/*@observer@*/ /*@temp@*/ constraint c
)
778 cstring st
= cstring_undefined
;
781 llassert (constraint_isDefined (c
) );
783 st
= message ("Unsatisfied ensures constraint condition:\nSplint is unable to verify the constraint %q",
784 constraint_unparseDeep (c
));
786 genExpr
= exprNode_unparse (c
->generatingExpr
);
788 if (context_getFlag (FLG_CONSTRAINTLOCATION
))
792 temp
= message ("\nOriginal Generating expression %q: %s\n",
793 fileloc_unparse (exprNode_loc (c
->generatingExpr
)),
795 st
= cstring_concatFree (st
, temp
);
797 if (constraint_hasMaxSet (c
))
799 temp
= message ("Has MaxSet\n");
800 st
= cstring_concatFree (st
, temp
);
806 cstring
constraint_unparseDetailed (constraint c
)
808 cstring st
= cstring_undefined
;
809 cstring temp
= cstring_undefined
;
813 llassert (constraint_isDefined (c
));
817 st
= message ("Unable to resolve constraint:\n%q", constraint_unparseDeep (c
));
821 st
= message ("Block Post condition:\nThis function block has the post condition %q", constraint_unparseDeep (c
));
824 isLikely
= constraint_isConstantOnly (c
);
828 if (constraint_hasMaxSet (c
))
830 temp
= cstring_makeLiteral ("Likely out-of-bounds store: ");
834 temp
= cstring_makeLiteral ("Likely out-of-bounds read: ");
840 if (constraint_hasMaxSet (c
))
842 temp
= cstring_makeLiteral ("Possible out-of-bounds store: ");
846 temp
= cstring_makeLiteral ("Possible out-of-bounds read: ");
850 genExpr
= exprNode_unparse (c
->generatingExpr
);
852 if (context_getFlag (FLG_CONSTRAINTLOCATION
))
855 temp2
= message ("%s\n", genExpr
);
856 temp
= cstring_concatFree (temp
, temp2
);
859 st
= cstring_concatFree (temp
,st
);
864 /*@only@*/ cstring
constraint_unparse (constraint c
) /*@*/
866 cstring st
= cstring_undefined
;
867 cstring type
= cstring_undefined
;
871 if (context_getFlag (FLG_PARENCONSTRAINT
))
873 type
= cstring_makeLiteral ("ensures: ");
877 type
= cstring_makeLiteral ("ensures");
882 if (context_getFlag (FLG_PARENCONSTRAINT
))
884 type
= cstring_makeLiteral ("requires: ");
888 type
= cstring_makeLiteral ("requires");
892 if (context_getFlag (FLG_PARENCONSTRAINT
))
894 st
= message ("%q: %q %q %q",
896 constraintExpr_print (c
->lexpr
),
897 arithType_print (c
->ar
),
898 constraintExpr_print (c
->expr
));
902 st
= message ("%q %q %q %q",
904 constraintExpr_print (c
->lexpr
),
905 arithType_print (c
->ar
),
906 constraintExpr_print (c
->expr
));
911 cstring
constraint_unparseOr (constraint c
) /*@*/
916 ret
= cstring_undefined
;
918 llassert (constraint_isDefined (c
) );
922 ret
= cstring_concatFree (ret
, constraint_unparse (temp
));
926 while ( constraint_isDefined (temp
))
928 ret
= cstring_concatFree (ret
, cstring_makeLiteral (" OR "));
929 ret
= cstring_concatFree (ret
, constraint_unparse (temp
));
937 /*@only@*/ constraint
constraint_doSRefFixBaseParam (/*@returned@*/ /*@only@*/ constraint precondition
,
938 exprNodeList arglist
)
941 llassert (constraint_isDefined (precondition
) );
943 precondition
->lexpr
= constraintExpr_doSRefFixBaseParam (precondition
->lexpr
,
945 precondition
->expr
= constraintExpr_doSRefFixBaseParam (precondition
->expr
,
952 constraint
constraint_doFixResult (constraint postcondition
, /*@dependent@*/ exprNode fcnCall
)
954 postcondition
= constraint_copy (postcondition
);
956 llassert (constraint_isDefined (postcondition
) );
959 postcondition
->lexpr
= constraintExpr_doFixResult (postcondition
->lexpr
, fcnCall
);
960 postcondition
->expr
= constraintExpr_doFixResult (postcondition
->expr
, fcnCall
);
962 return postcondition
;
964 /*Commenting out temporally
966 / *@only@* /constraint constraint_doSRefFixInvarConstraint(constraint invar, sRef s, ctype ct )
969 invar = constraint_copy (invar);
970 invar->lexpr = constraintExpr_doSRefFixInvarConstraint (invar->lexpr, s, ct);
971 invar->expr = constraintExpr_doSRefFixInvarConstraint (invar->expr, s, ct);
977 /*@only@*/ constraint
constraint_doSRefFixConstraintParam (constraint precondition
,
978 exprNodeList arglist
)
981 precondition
= constraint_copy (precondition
);
983 llassert (constraint_isDefined (precondition
) );
985 precondition
->lexpr
= constraintExpr_doSRefFixConstraintParam (precondition
->lexpr
, arglist
);
986 precondition
->expr
= constraintExpr_doSRefFixConstraintParam (precondition
->expr
, arglist
);
988 precondition
->fcnPre
= FALSE
;
989 return constraint_simplify(precondition
);
992 constraint
constraint_preserveOrig (/*@returned@*/ constraint c
) /*@modifies c @*/
994 if (constraint_isDefined (c
))
996 DPRINTF (("Doing constraint_preserverOrig for %q", constraint_unparseDetailed (c
)));
998 if (c
->orig
== constraint_undefined
)
1000 c
->orig
= constraint_copy (c
);
1002 else if (c
->orig
->fcnPre
)
1004 constraint temp
= c
->orig
;
1006 /* avoid infinite loop */
1008 c
->orig
= constraint_copy (c
);
1009 /*drl 03/2/2003 if c != NULL then the copy of c will != null*/
1010 llassert (constraint_isDefined (c
->orig
) );
1012 if (c
->orig
->orig
== NULL
)
1014 c
->orig
->orig
= temp
;
1019 llcontbug ((message ("Expected c->orig->orig to be null")));
1020 constraint_free (c
->orig
->orig
);
1021 c
->orig
->orig
= temp
;
1027 DPRINTF (("Not changing constraint"));
1031 DPRINTF ((message ("After Doing constraint_preserverOrig for %q ", constraint_unparseDetailed (c
))));
1035 constraint
constraint_togglePost (/*@returned@*/ constraint c
)
1037 llassert (constraint_isDefined (c
));
1042 constraint
constraint_togglePostOrig (/*@returned@*/ constraint c
)
1044 llassert (constraint_isDefined (c
));
1046 if (c
->orig
!= NULL
)
1048 c
->orig
= constraint_togglePost (c
->orig
);
1054 bool constraint_hasOrig ( /*@observer@*/ /*@temp@*/ constraint c
)
1056 llassert (constraint_isDefined (c
));
1057 return (c
->orig
!= NULL
);
1061 constraint
constraint_undump (FILE *f
)
1066 constraintExpr lexpr
, expr
;
1069 os
= mstring_create (MAX_DUMP_LINE_LENGTH
);
1070 s
= fgets (os
, MAX_DUMP_LINE_LENGTH
, f
);
1072 if (!mstring_isDefined (s
))
1074 llfatalbug (message ("Library file is corrupted") );
1077 fcnPre
= (bool) reader_getInt (&s
);
1079 post
= (bool) reader_getInt (&s
);
1081 ar
= (arithType
) reader_getInt (&s
);
1083 s
= fgets (os
, MAX_DUMP_LINE_LENGTH
, f
);
1085 if (! mstring_isDefined(s
) )
1087 llfatalbug(message("Library file is corrupted") );
1090 reader_checkChar (&s
, 'l');
1092 lexpr
= constraintExpr_undump (f
);
1094 s
= fgets (os
, MAX_DUMP_LINE_LENGTH
, f
);
1096 reader_checkChar (&s
, 'r');
1098 if (! mstring_isDefined(s
) )
1100 llfatalbug(message("Library file is corrupted") );
1103 expr
= constraintExpr_undump (f
);
1105 c
= constraint_makeNew ();
1115 c
= constraint_preserveOrig (c
);
1120 void constraint_dump (/*@observer@*/ constraint c
, FILE *f
)
1126 constraintExpr lexpr
;
1127 constraintExpr expr
;
1129 llassert (constraint_isDefined (c
) );
1137 fprintf (f
, "%d@%d@%d\n", (int) fcnPre
, (int) post
, (int) ar
);
1139 constraintExpr_dump (lexpr
, f
);
1141 constraintExpr_dump (expr
, f
);
1145 int constraint_compare (/*@observer@*/ /*@temp@*/ const constraint
* c1
, /*@observer@*/ /*@temp@*/ const constraint
* c2
) /*@*/
1151 llassert (constraint_isDefined (*c1
));
1152 llassert (constraint_isDefined (*c2
));
1154 if (constraint_isUndefined (*c1
))
1156 if (constraint_isUndefined (*c2
))
1162 if (constraint_isUndefined (*c2
))
1167 loc1
= constraint_getFileloc (*c1
);
1168 loc2
= constraint_getFileloc (*c2
);
1170 ret
= fileloc_compare (loc1
, loc2
);
1172 fileloc_free (loc1
);
1173 fileloc_free (loc2
);
1179 bool constraint_isPost (/*@observer@*/ /*@temp@*/ constraint c
)
1181 llassert (constraint_isDefined (c
));
1183 if (constraint_isUndefined (c
))
1190 static int constraint_getDepth (/*@observer@*/ /*@temp@*/ constraint c
)
1194 llassert (constraint_isDefined (c
) );
1196 l
= constraintExpr_getDepth (c
->lexpr
);
1197 r
= constraintExpr_getDepth (c
->expr
);
1201 DPRINTF (( message ("constraint depth returning %d for %s", l
, constraint_unparse (c
))));
1206 DPRINTF (( message ("constraint depth returning %d for %s", r
, constraint_unparse (c
))));
1212 bool constraint_tooDeep (/*@observer@*/ /*@temp@*/ constraint c
)
1216 temp
= constraint_getDepth (c
);
1227 /*drl added 12/19/2002*/
1228 /*whether constraints consist only of
1229 terms which are constants*/
1230 bool constraint_isConstantOnly (constraint c
)
1234 llassert (constraint_isDefined (c
) );
1236 l
= constraintExpr_isConstantOnly(c
->lexpr
);
1237 r
= constraintExpr_isConstantOnly(c
->expr
);