8 # include <ctype.h> /* for isdigit */
9 # include "lclintMacros.nf"
11 # include "cgrammar.h"
12 # include "cgrammar_tokens.h"
14 # include "exprChecks.h"
15 # include "exprNodeSList.h"
18 /*@access constraint, exprNode @*/
21 static constraint inequalitySubstitute (/*@returned@*/ constraint p_c, constraintList p_p);
24 static bool rangeCheck (arithType p_ar1, /*@observer@*/ constraintExpr p_expr1, arithType p_ar2, /*@observer@*/ constraintExpr p_expr2);
26 static constraint inequalitySubstituteUnsound (/*@returned@*/ constraint p_c, constraintList p_p);
28 static constraint inequalitySubstituteStrong (/*@returned@*/ constraint p_c, constraintList p_p);
30 static constraint constraint_searchandreplace (/*@returned@*/ constraint p_c, constraintExpr p_old, constraintExpr p_newExpr);
33 static constraint constraint_addOr (/*@returned@*/ constraint p_orig, /*@observer@*/ constraint p_orConstr);
35 static bool resolveOr (/*@temp@*/constraint p_c, /*@observer@*/ /*@temp@*/ constraintList p_list);
37 static /*@only@*/ constraintList reflectChangesEnsuresFree1 (/*@only@*/ constraintList p_pre2, constraintList p_post1);
39 /*********************************************/
44 /*@only@*/ constraintList constraintList_mergeEnsuresFreeFirst (constraintList list1, constraintList list2)
48 ret = constraintList_mergeEnsures (list1, list2);
50 constraintList_free(list1);
54 /*@only@*/ constraintList constraintList_mergeEnsures (constraintList list1, constraintList list2)
59 //ret = constraintList_makeNew();
61 llassert(constraintList_isDefined(list1) );
62 llassert(constraintList_isDefined(list2) );
64 DPRINTF(( message ("constraintList_mergeEnsures: list1 %s list2 %s",
65 constraintList_print(list1), constraintList_print(list2)
68 ret = constraintList_fixConflicts (list1, list2);
69 ret = reflectChangesEnsuresFree1 (ret, list2);
70 temp = constraintList_subsumeEnsures (ret, list2);
71 constraintList_free(ret);
74 temp = constraintList_subsumeEnsures (list2, ret);
76 temp = constraintList_addList (temp, ret);
77 constraintList_free(ret);
79 DPRINTF(( message ("constraintList_mergeEnsures: returning %s ",
80 constraintList_print(temp) )
85 //ret = constraintList_addList (ret, list2);
90 /*@only@*/ constraintList constraintList_mergeRequiresFreeFirst (/*@only@*/ constraintList list1, constraintList list2)
94 ret = constraintList_mergeRequires(list1, list2);
96 constraintList_free(list1);
101 /*@only@*/ constraintList constraintList_mergeRequires (constraintList list1, constraintList list2)
106 DPRINTF((message ("constraintList_mergeRequires: merging %s and %s ", constraintList_print (list1), constraintList_print(list2) ) ) );
108 /* get constraints in list1 not satified by list2 */
109 temp = constraintList_reflectChanges(list1, list2);
110 DPRINTF((message ("constraintList_mergeRequires: temp = %s", constraintList_print(temp) ) ) );
112 /*get constraints in list2 not satified by temp*/
113 ret = constraintList_reflectChanges(list2, temp);
115 DPRINTF((message ("constraintList_mergeRequires: ret = %s", constraintList_print(ret) ) ) );
117 ret = constraintList_addListFree (ret, temp);
119 DPRINTF((message ("constraintList_mergeRequires: returning %s", constraintList_print(ret) ) ) );
124 /* old name mergeResolve renamed for czech naming convention */
125 void exprNode_mergeResolve (exprNode parent, exprNode child1, exprNode child2)
127 constraintList temp, temp2;
129 DPRINTF( (message ("magically merging constraint into parent:%s for", exprNode_unparse (parent) )) );
131 DPRINTF( (message (" children: %s and %s", exprNode_unparse (child1), exprNode_unparse(child2) ) ) );
133 if (exprNode_isError (child1) || exprNode_isError(child2) )
135 if (exprNode_isError (child1) && !exprNode_isError(child2) )
137 constraintList_free(parent->requiresConstraints);
139 parent->requiresConstraints = constraintList_copy (child2->requiresConstraints);
140 constraintList_free(parent->ensuresConstraints);
142 parent->ensuresConstraints = constraintList_copy (child2->ensuresConstraints);
143 DPRINTF((message ("Copied child constraints: pre: %s and post: %s",
144 constraintList_print( child2->requiresConstraints),
145 constraintList_print (child2->ensuresConstraints)
152 llassert(exprNode_isError(child2) );
153 //parent->requiresConstraints = constraintList_makeNew();
154 //parent->ensuresConstraints = constraintList_makeNew();
159 llassert(!exprNode_isError (child1) && ! exprNode_isError(child2) );
161 DPRINTF( (message ("Child constraints are %s %s and %s %s",
162 constraintList_print (child1->requiresConstraints),
163 constraintList_print (child1->ensuresConstraints),
164 constraintList_print (child2->requiresConstraints),
165 constraintList_print (child2->ensuresConstraints)
169 constraintList_free(parent->requiresConstraints);
171 parent->requiresConstraints = constraintList_copy (child1->requiresConstraints);
173 if ( context_getFlag (FLG_ORCONSTRAINT) )
174 temp = constraintList_reflectChangesOr (child2->requiresConstraints, child1->ensuresConstraints);
176 temp = constraintList_reflectChanges(child2->requiresConstraints, child1->ensuresConstraints);
178 temp2 = constraintList_mergeRequires (parent->requiresConstraints, temp);
179 constraintList_free(parent->requiresConstraints);
180 constraintList_free(temp);
182 parent->requiresConstraints = temp2;
184 DPRINTF( (message ("Parent requires constraints are %s ",
185 constraintList_print (parent->requiresConstraints)
188 constraintList_free(parent->ensuresConstraints);
190 parent->ensuresConstraints = constraintList_mergeEnsures(child1->ensuresConstraints,
191 child2->ensuresConstraints);
194 DPRINTF( (message ("Parent constraints are %s and %s ",
195 constraintList_print (parent->requiresConstraints),
196 constraintList_print (parent->ensuresConstraints)
204 /*@only@*/ constraintList constraintList_subsumeEnsures (constraintList list1, constraintList list2)
207 ret = constraintList_makeNew();
208 constraintList_elements (list1, el)
211 DPRINTF ((message ("Examining %s", constraint_print (el) ) ) );
212 if (!constraintList_resolve (el, list2) )
215 temp = constraint_copy(el);
216 ret = constraintList_add (ret, temp);
220 DPRINTF ( (message ("Subsuming %s", constraint_print (el) ) ) );
222 } end_constraintList_elements;
229 /*used to be reflectChangesFreePre renamed for Czech naming conventino*/
230 /* tries to resolve constraints in list pre2 using post1 */
231 /*@only@*/ constraintList constraintList_reflectChangesFreePre (/*@only@*/ constraintList pre2, /*@observer@*/ constraintList post1)
235 ret = constraintList_reflectChanges(pre2, post1);
237 constraintList_free (pre2);
244 /* tries to resolve constraints in list pre2 using post1 */
246 static /*@only@*/ constraintList reflectChangesNoOr (/*@observer@*/ /*@temp@*/ constraintList pre2, /*@observer@*/ /*@temp@*/ constraintList post1)
253 llassert (! context_getFlag (FLG_ORCONSTRAINT) );
255 ret = constraintList_makeNew();
256 DPRINTF((message ("reflectChanges: lists %s and %s", constraintList_print(pre2), constraintList_print(post1) )));
258 constraintList_elements (pre2, el)
260 if (!constraintList_resolve (el, post1) )
262 temp = constraint_substitute (el, post1);
263 if (!constraintList_resolve (temp, post1) )
265 // try inequality substitution
268 // the inequality substitution may cause us to lose information
269 //so we don't want to store the result but we do it anyway
270 temp2 = constraint_copy (temp);
271 // if (context_getFlag (FLG_ORCONSTRAINT) )
272 temp2 = inequalitySubstitute (temp2, post1);
273 if (!constraintList_resolve (temp2, post1) )
275 temp2 = inequalitySubstituteUnsound (temp2, post1);
276 if (!constraintList_resolve (temp2, post1) )
277 ret = constraintList_add (ret, temp2);
279 constraint_free(temp2);
283 constraint_free(temp2);
286 constraint_free(temp);
288 } end_constraintList_elements;
290 DPRINTF((message ("reflectChanges: returning %s", constraintList_print(ret) ) ) );
294 /* tries to resolve constraints in list pre2 using post1 */
295 /*@only@*/ constraintList constraintList_reflectChanges(/*@observer@*/ constraintList pre2, /*@observer@*/ constraintList post1)
299 if ( context_getFlag (FLG_ORCONSTRAINT) )
301 temp = constraintList_reflectChangesOr (pre2, post1);
303 temp = reflectChangesNoOr(pre2, post1);
308 static constraint constraint_addOr (/*@returned@*/ constraint orig, /*@observer@*/ constraint orConstr)
313 DPRINTF((message("constraint_addor: oring %s onto %s", constraint_printOr(orConstr), constraint_printOr(orig) ) ));
315 while (c->or != NULL)
320 c->or = constraint_copy(orConstr);
322 DPRINTF((message("constraint_addor: returning %s",constraint_printOr(orig) ) ));
328 static bool resolveOr ( /*@temp@*/ constraint c, /*@observer@*/ /*@temp@*/ constraintList list)
335 DPRINTF(( message("resolveOr: constraint %s and list %s", constraint_printOr(c), constraintList_print(list) ) ));
340 if (constraintList_resolve (temp, list) )
344 llassert(numberOr <= 10);
346 while (constraint_isDefined(temp));
351 /*This is a "helper" function for doResolveOr */
353 static /*@only@*/ constraint doResolve (/*@only@*/ constraint c, constraintList post1, bool * resolved)
357 llassert(constraint_isUndefined (c->or ) );
359 if (!resolveOr (c, post1) )
362 temp = constraint_substitute (c, post1);
364 if (!resolveOr (temp, post1) )
366 // try inequality substitution
369 // the inequality substitution may cause us to lose information
370 //so we don't want to store the result but we do anyway
371 temp2 = constraint_copy (c);
372 // if (context_getFlag (FLG_ORCONSTRAINT) )
373 temp2 = inequalitySubstitute (temp2, post1);
374 if (!resolveOr (temp2, post1) )
377 temp3 = constraint_copy(temp2);
379 temp3 = inequalitySubstituteStrong (temp3, post1);
380 if (!resolveOr (temp3, post1) )
382 temp2 = inequalitySubstituteUnsound (temp2, post1);
383 if (!resolveOr (temp2, post1) )
385 if (!constraint_same (temp, temp2) )
386 temp = constraint_addOr (temp, temp2);
388 if (!constraint_same (temp, temp3) && !constraint_same (temp3, temp2) )
389 temp = constraint_addOr (temp, temp3);
393 constraint_free(temp2);
394 constraint_free(temp3);
399 constraint_free(temp2);
400 constraint_free(temp3);
404 constraint_free(temp2);
405 constraint_free(temp3);
410 constraint_free(temp2);
414 constraint_free(temp);
423 static /*@only@*/ constraint doResolveOr (/*@observer@*/ /*@temp@*/ constraint c, constraintList post1, /*@out@*/bool * resolved)
430 DPRINTF(( message("doResolveOr: constraint %s and list %s", constraint_printOr(c), constraintList_print(post1) ) ));
437 ret = constraint_copy(c);
439 if (constraintList_isEmpty(post1) )
447 ret = doResolve (ret, post1, resolved);
452 constraint_free(next);
454 /*we don't need to free ret when resolved is false because ret is null*/
455 llassert(ret == NULL);
466 curr = doResolve (curr, post1, resolved);
470 /* curr is null so we don't try to free it*/
471 llassert(curr == NULL);
474 constraint_free(next);
476 constraint_free(ret);
479 ret = constraint_addOr (ret, curr);
480 constraint_free(curr);
485 /* tries to resolve constraints in list pr2 using post1 */
486 /*@only@*/ constraintList constraintList_reflectChangesOr (constraintList pre2, constraintList post1)
491 ret = constraintList_makeNew();
492 DPRINTF((message ("constraintList_reflectChangesOr: lists %s and %s", constraintList_print(pre2), constraintList_print(post1) )));
494 constraintList_elements (pre2, el)
496 temp = doResolveOr (el, post1, &resolved);
500 ret = constraintList_add(ret, temp);
504 /* we don't need to free temp when
505 resolved is false because temp is null */
506 llassert(temp == NULL);
509 } end_constraintList_elements;
511 DPRINTF((message ("constraintList_reflectChangesOr: returning %s", constraintList_print(ret) ) ) );
515 static /*@only@*/ constraintList reflectChangesEnsures (/*@observer@*/ constraintList pre2, constraintList post1)
519 ret = constraintList_makeNew();
520 constraintList_elements (pre2, el)
522 if (!constraintList_resolve (el, post1) )
524 temp = constraint_substitute (el, post1);
525 llassert (temp != NULL);
527 if (!constraintList_resolve (temp, post1) )
528 ret = constraintList_add (ret, temp);
530 constraint_free(temp);
534 DPRINTF ( (message ("Resolved away %s ", constraint_print(el) ) ) );
536 } end_constraintList_elements;
542 static /*@only@*/ constraintList reflectChangesEnsuresFree1 (/*@only@*/ constraintList pre2, constraintList post1)
546 ret = reflectChangesEnsures (pre2, post1);
548 constraintList_free(pre2);
554 static bool constraint_conflict (constraint c1, constraint c2)
557 if (constraintExpr_similar(c1->lexpr, c2->lexpr) )
560 if (c1->ar == c2->ar)
562 DPRINTF ( (message ("%s conflicts with %s ", constraint_print (c1), constraint_print(c2) ) ) );
567 // This is a slight kludg to prevent circular constraints like
568 // strlen(str) == maxRead(s) + strlen(str);
570 /*@i324234*/ //clean this up
573 if (c1->ar == c2->ar)
575 if (constraintExpr_search (c1->lexpr, c2->expr) )
576 if (constraintExpr_isTerm(c1->lexpr) )
580 term = constraintExpr_getTerm(c1->lexpr);
582 if (constraintTerm_isExprNode(term) )
584 DPRINTF ( (message ("%s conflicts with %s ", constraint_print (c1), constraint_print(c2) ) ) );
590 if (constraint_tooDeep(c1) || constraint_tooDeep(c2) )
592 DPRINTF ( (message ("%s conflicts with %s (constraint is too deep", constraint_print (c1), constraint_print(c2) ) ) );
596 DPRINTF ( (message ("%s doesn't conflict with %s ", constraint_print (c1), constraint_print(c2) ) ) );
602 static void constraint_fixConflict (/*@temp@*/ constraint good, /*@temp@*/ /*@observer@*/ constraint conflicting) /*@modifies good@*/
604 if (conflicting->ar ==EQ )
606 good->expr = constraintExpr_searchandreplace (good->expr, conflicting->lexpr, conflicting->expr);
607 good = constraint_simplify (good);
613 static bool conflict (constraint c, constraintList list)
616 constraintList_elements (list, el)
618 if ( constraint_conflict(el, c) )
620 constraint_fixConflict (el, c);
623 } end_constraintList_elements;
629 //check if constraint in list1 conflicts with constraints in List2. If so we
630 //remove form list1 and change list2.
631 constraintList constraintList_fixConflicts (constraintList list1, constraintList list2)
634 ret = constraintList_makeNew();
635 llassert(constraintList_isDefined(list1) );
636 constraintList_elements (list1, el)
638 if (! conflict (el, list2) )
641 temp = constraint_copy(el);
642 ret = constraintList_add (ret, temp);
644 } end_constraintList_elements;
649 /*returns true if constraint post satifies cosntriant pre */
650 static bool satifies (constraint pre, constraint post)
652 if (constraint_isAlwaysTrue (pre) )
655 if (!constraintExpr_similar (pre->lexpr, post->lexpr) )
659 if (constraintExpr_isUndefined(post->expr))
665 return rangeCheck (pre->ar, pre->expr, post->ar, post->expr);
669 bool constraintList_resolve (/*@temp@*/ /*@observer@*/ constraint c, /*@temp@*/ /*@observer@*/ constraintList p)
671 constraintList_elements (p, el)
673 if ( satifies (c, el) )
675 DPRINTF ( (message ("\n%s Satifies %s\n ", constraint_print(el), constraint_print(c) ) ) );
678 DPRINTF ( (message ("\n%s does not satify %s\n ", constraint_print(el), constraint_print(c) ) ) );
680 end_constraintList_elements;
681 DPRINTF ( (message ("no constraints satify %s", constraint_print(c) ) ));
685 static bool arithType_canResolve (arithType ar1, arithType ar2)
691 if ( (ar2 == GT) || (ar2 == GTE) || (ar2 == EQ) )
705 if ( (ar2 == LT) || (ar2 == LTE) || (ar2 == EQ) )
714 /* We look for constraint which are tautologies */
716 bool constraint_isAlwaysTrue (/*@observer@*/ /*@temp@*/ constraint c)
725 DPRINTF(( message("constraint_IsAlwaysTrue:examining %s", constraint_print(c) ) ));
727 if (constraintExpr_canGetValue(l) && constraintExpr_canGetValue(r) )
730 cmp = constraintExpr_compare (l, r);
751 if (constraintExpr_similar (l,r) )
770 l = constraintExpr_copy (c->lexpr);
771 r = constraintExpr_copy (c->expr);
773 // l = constraintExpr_propagateConstants (l, &lHasConstant, &lConstant);
774 r = constraintExpr_propagateConstants (r, &rHasConstant, &rConstant);
776 if (constraintExpr_similar (l,r) && (rHasConstant ) )
778 DPRINTF(( message("constraint_IsAlwaysTrue: after removing constants %s and %s are similar", constraintExpr_unparse(l), constraintExpr_unparse(r) ) ));
779 DPRINTF(( message("constraint_IsAlwaysTrue: rconstant is %d", rConstant ) ));
781 constraintExpr_free(l);
782 constraintExpr_free(r);
787 return (rConstant == 0);
789 return (rConstant > 0);
791 return (rConstant >= 0);
793 return (rConstant <= 0);
795 return (rConstant < 0);
805 constraintExpr_free(l);
806 constraintExpr_free(r);
807 DPRINTF(( message("Constraint %s is not always true", constraint_print(c) ) ));
814 static bool rangeCheck (arithType ar1, /*@observer@*/ constraintExpr expr1, arithType ar2, /*@observer@*/ constraintExpr expr2)
817 DPRINTF ((message ("Doing Range CHECK %s and %s", constraintExpr_unparse(expr1), constraintExpr_unparse(expr2) ) ));
819 if (! arithType_canResolve (ar1, ar2) )
825 if (constraintExpr_similar (expr1, expr2) )
829 if (! (constraintExpr_canGetValue (expr1) &&
830 constraintExpr_canGetValue (expr2) ) )
832 constraintExpr e1, e2;
836 e1 = constraintExpr_copy(expr1);
837 e2 = constraintExpr_copy(expr2);
839 e1 = constraintExpr_propagateConstants (e1, &p1, &const1);
841 e2 = constraintExpr_propagateConstants (e2, &p2, &const2);
851 if (const1 <= const2)
852 if (constraintExpr_similar (e1, e2) )
854 constraintExpr_free(e1);
855 constraintExpr_free(e2);
859 DPRINTF( ("Can't Get value"));
861 constraintExpr_free(e1);
862 constraintExpr_free(e2);
866 if (constraintExpr_compare (expr2, expr1) >= 0)
871 if (constraintExpr_similar (expr1, expr2) )
876 if (constraintExpr_similar (expr1, expr2) )
880 if (! (constraintExpr_canGetValue (expr1) &&
881 constraintExpr_canGetValue (expr2) ) )
883 constraintExpr e1, e2;
887 e1 = constraintExpr_copy(expr1);
888 e2 = constraintExpr_copy(expr2);
890 e1 = constraintExpr_propagateConstants (e1, &p1, &const1);
892 e2 = constraintExpr_propagateConstants (e2, &p2, &const2);
902 if (const1 >= const2)
903 if (constraintExpr_similar (e1, e2) )
905 constraintExpr_free(e1);
906 constraintExpr_free(e2);
910 constraintExpr_free(e1);
911 constraintExpr_free(e2);
913 DPRINTF( ("Can't Get value"));
917 if (constraintExpr_compare (expr2, expr1) <= 0)
923 llcontbug((message("Unhandled case in switch: %q", arithType_print(ar1) ) ) );
928 static constraint constraint_searchandreplace (/*@returned@*/ constraint c, constraintExpr old, constraintExpr newExpr)
930 DPRINTF (("Doing replace for lexpr") );
931 c->lexpr = constraintExpr_searchandreplace (c->lexpr, old, newExpr);
932 DPRINTF (("Doing replace for expr") );
933 c->expr = constraintExpr_searchandreplace (c->expr, old, newExpr);
937 bool constraint_search (constraint c, constraintExpr old) /*@*/
942 ret = constraintExpr_search (c->lexpr, old);
943 ret = ret || constraintExpr_search (c->expr, old);
947 //adjust file locs and stuff
948 static constraint constraint_adjust (/*@returned@*/ constraint substitute, /*@observer@*/ constraint old)
950 fileloc loc1, loc2, loc3;
952 DPRINTF ( (message("Start adjust on %s and %s", constraint_print(substitute),
953 constraint_print(old))
956 loc1 = constraint_getFileloc (old);
958 loc2 = constraintExpr_getFileloc (substitute->lexpr);
960 loc3 = constraintExpr_getFileloc (substitute->expr);
963 // special case of an equality that "contains itself"
964 if (constraintExpr_search (substitute->expr, substitute->lexpr) )
965 if (fileloc_closer (loc1, loc3, loc2))
968 DPRINTF ( (message("Doing adjust on %s", constraint_print(substitute) )
970 temp = substitute->lexpr;
971 substitute->lexpr = substitute->expr;
972 substitute->expr = temp;
973 substitute = constraint_simplify(substitute);
984 /* If function preforms substitutes based on inequality
986 It uses the rule x >= y && b < y ===> x >= b + 1
988 Warning this is sound but throws out information
991 constraint inequalitySubstitute (/*@returned@*/ constraint c, constraintList p)
996 constraintList_elements (p, el)
998 if ( (el->ar == LT ) )
999 // if (!constraint_conflict (c, el) )
1002 constraintExpr temp2;
1006 //temp = constraint_copy(el);
1008 // temp = constraint_adjust(temp, c);
1010 if (constraintExpr_same (el->expr, c->expr) )
1012 DPRINTF((message ("inequalitySubstitute Replacing %q in %q with %q",
1013 constraintExpr_print (c->expr),
1014 constraint_print (c),
1015 constraintExpr_print (el->expr) )
1017 temp2 = constraintExpr_copy (el->lexpr);
1018 constraintExpr_free(c->expr);
1019 c->expr = constraintExpr_makeIncConstraintExpr (temp2);
1025 end_constraintList_elements;
1027 c = constraint_simplify(c);
1034 THis function is like inequalitySubstitute but it adds the rule
1035 added the rules x >= y && y <= b ===> x >= b
1036 x >= y && y < b ===> x >= b + 1
1038 This is sound but sonce it throws out additional information it should only one used
1039 if we're oring constraints.
1042 static constraint inequalitySubstituteStrong (/*@returned@*/ constraint c, constraintList p)
1044 DPRINTF (( message ("inequalitySubstituteStrong examining substituting for %q", constraint_print(c) ) ));
1049 DPRINTF (( message ("inequalitySubstituteStrong examining substituting for %q with %q",
1050 constraint_print(c), constraintList_print(p) ) ));
1051 constraintList_elements (p, el)
1053 DPRINTF (( message ("inequalitySubstituteStrong examining substituting %s on %s", constraint_print(el), constraint_print(c) ) ));
1055 if ( (el->ar == LT ) || (el->ar == LTE ) )
1056 // if (!constraint_conflict (c, el) )
1059 constraintExpr temp2;
1063 //temp = constraint_copy(el);
1065 // temp = constraint_adjust(temp, c);
1067 if (constraintExpr_same (el->lexpr, c->expr) )
1069 DPRINTF((message ("inequalitySubstitute Replacing %s in %s with %s",
1070 constraintExpr_print (c->expr),
1071 constraint_print (c),
1072 constraintExpr_print (el->expr) )
1074 temp2 = constraintExpr_copy (el->expr);
1075 constraintExpr_free(c->expr);
1076 if ( (el->ar == LTE ) )
1082 c->expr = constraintExpr_makeIncConstraintExpr (temp2);
1088 end_constraintList_elements;
1090 c = constraint_simplify(c);
1095 /* This function performs substitutions based on the rule:
1096 for a constraint of the form expr1 >= expr2; a < b =>
1097 a = b -1 for all a in expr1. This will work in most cases.
1099 Like inequalitySubstitute we're throwing away some information
1102 static constraint inequalitySubstituteUnsound (/*@returned@*/ constraint c, constraintList p)
1104 DPRINTF (( message ("Doing inequalitySubstituteUnsound " ) ));
1109 constraintList_elements (p, el)
1111 DPRINTF (( message ("inequalitySubstituteUnsound examining substituting %s on %s", constraint_print(el), constraint_print(c) ) ));
1112 if ( ( el->ar == LTE) || (el->ar == LT) )
1113 // if (!constraint_conflict (c, el) )
1116 constraintExpr temp2;
1118 //temp = constraint_copy(el);
1120 // temp = constraint_adjust(temp, c);
1121 temp2 = constraintExpr_copy (el->expr);
1124 temp2 = constraintExpr_makeDecConstraintExpr (temp2);
1126 DPRINTF((message ("Replacing %s in %s with %s",
1127 constraintExpr_print (el->lexpr),
1128 constraintExpr_print (c->lexpr),
1129 constraintExpr_print (temp2) ) ));
1131 c->lexpr = constraintExpr_searchandreplace (c->lexpr, el->lexpr, temp2);
1132 constraintExpr_free(temp2);
1135 end_constraintList_elements;
1137 c = constraint_simplify(c);
1141 /*@only@*/ constraint constraint_substitute (/*@observer@*/ /*@temp@*/ constraint c, constraintList p)
1145 ret = constraint_copy(c);
1146 constraintList_elements (p, el)
1149 if (!constraint_conflict (ret, el) )
1154 temp = constraint_copy(el);
1156 temp = constraint_adjust(temp, ret);
1158 DPRINTF((message ("Substituting %s in the constraint %s",
1159 constraint_print (temp), constraint_print (ret)
1163 ret = constraint_searchandreplace (ret, temp->lexpr, temp->expr);
1164 DPRINTF(( message ("The new constraint is %s", constraint_print (ret) ) ));
1165 constraint_free(temp);
1168 end_constraintList_elements;
1169 DPRINTF(( message ("The finial new constraint is %s", constraint_print (ret) ) ));
1171 ret = constraint_simplify(ret);
1176 /*@only@*/ constraintList constraintList_substituteFreeTarget (/*@only@*/ constraintList target, /*@observer@*/ constraintList subList)
1180 ret = constraintList_substitute (target, subList);
1182 constraintList_free(target);
1187 /* we try to do substitutions on each constraint in target using the constraint in sublist*/
1189 /*@only@*/ constraintList constraintList_substitute (constraintList target,/*2observer@*/ constraintList subList)
1194 ret = constraintList_makeNew();
1196 constraintList_elements(target, el)
1199 //drl possible problem : warning make sure that a side effect is not expected
1201 temp = constraint_substitute(el, subList);
1202 ret = constraintList_add (ret, temp);
1204 end_constraintList_elements;
1209 static constraint constraint_solve (/*@returned@*/ constraint c)
1211 DPRINTF( (message ("Solving %s\n", constraint_print(c) ) ) );
1212 c->expr = constraintExpr_solveBinaryExpr (c->lexpr, c->expr);
1213 DPRINTF( (message ("Solved and got %s\n", constraint_print(c) ) ) );
1218 static arithType flipAr (arithType ar)
1233 llcontbug (message("unexpected value: case not handled"));
1238 static constraint constraint_swapLeftRight (/*@returned@*/ constraint c)
1240 constraintExpr temp;
1241 c->ar = flipAr (c->ar);
1245 DPRINTF(("Swaped left and right sides of constraint"));
1251 constraint constraint_simplify ( /*@returned@*/ constraint c)
1254 DPRINTF(( message("constraint_simplify on %q ", constraint_print(c) ) ));
1256 if (constraint_tooDeep(c))
1258 DPRINTF(( message("constraint_simplify: constraint to complex aborting %q ", constraint_print(c) ) ));
1263 c->lexpr = constraintExpr_simplify (c->lexpr);
1264 c->expr = constraintExpr_simplify (c->expr);
1266 if (constraintExpr_isBinaryExpr (c->lexpr) )
1268 c = constraint_solve (c);
1270 c->lexpr = constraintExpr_simplify (c->lexpr);
1271 c->expr = constraintExpr_simplify (c->expr);
1274 if (constraintExpr_isLit(c->lexpr) && (!constraintExpr_isLit(c->expr) ) )
1276 c = constraint_swapLeftRight(c);
1277 /*I don't think this will be an infinate loop*/
1278 c = constraint_simplify(c);
1281 DPRINTF(( message("constraint_simplify returning %q ", constraint_print(c) ) ));
1289 /* returns true if fileloc for term1 is closer to file for term2 than term3*/
1291 bool fileloc_closer (fileloc loc1, fileloc loc2, fileloc loc3)
1294 if (!fileloc_isDefined (loc1) )
1297 if (!fileloc_isDefined (loc2) )
1300 if (!fileloc_isDefined (loc3) )
1306 if (fileloc_equal (loc2, loc3) )
1309 if (fileloc_equal (loc1, loc2) )
1312 if (fileloc_equal (loc1, loc3) )
1315 if ( fileloc_lessthan (loc1, loc2) )
1317 if (fileloc_lessthan (loc2, loc3) )
1319 llassert (fileloc_lessthan (loc1, loc3) );
1328 if ( !fileloc_lessthan (loc1, loc2) )
1330 if (!fileloc_lessthan (loc2, loc3) )
1332 llassert (!fileloc_lessthan (loc1, loc3) );