]> andersk Git - splint.git/blame - src/constraintResolve.c
Added additional tests for buffer overflow detection fixes to the test suite.
[splint.git] / src / constraintResolve.c
CommitLineData
65f973be 1/*
2** LCLint - annotation-assisted static program checker
3** Copyright (C) 1994-2001 University of Virginia,
4** Massachusetts Institute of Technology
5**
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.
10**
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.
15**
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.
19**
20** For information on lclint: lclint-request@cs.virginia.edu
21** To report a bug: lclint-bug@cs.virginia.edu
22** For more information: http://lclint.cs.virginia.edu
23*/
24
616915dd 25/*
26*
27** constraintResolve.c
28*/
29
b7b694d6 30/* #define DEBUGPRINT 1 */
616915dd 31
32# include <ctype.h> /* for isdigit */
33# include "lclintMacros.nf"
34# include "basic.h"
35# include "cgrammar.h"
36# include "cgrammar_tokens.h"
37
38# include "exprChecks.h"
616915dd 39# include "exprNodeSList.h"
616915dd 40
616915dd 41
84c9ffbf 42/*@access constraint, exprNode @*/
616915dd 43
44
28bf4b0b 45static constraint inequalitySubstitute (/*@returned@*/ constraint p_c, constraintList p_p);
616915dd 46
616915dd 47
28bf4b0b 48static bool rangeCheck (arithType p_ar1, /*@observer@*/ constraintExpr p_expr1, arithType p_ar2, /*@observer@*/ constraintExpr p_expr2);
616915dd 49
28bf4b0b 50static constraint inequalitySubstituteUnsound (/*@returned@*/ constraint p_c, constraintList p_p);
616915dd 51
dc7f6a51 52static constraint inequalitySubstituteStrong (/*@returned@*/ constraint p_c, constraintList p_p);
53
28bf4b0b 54static constraint constraint_searchandreplace (/*@returned@*/ constraint p_c, constraintExpr p_old, constraintExpr p_newExpr);
bb25bea6 55
28bf4b0b 56
57static constraint constraint_addOr (/*@returned@*/ constraint p_orig, /*@observer@*/ constraint p_orConstr);
58
59static bool resolveOr (/*@temp@*/constraint p_c, /*@observer@*/ /*@temp@*/ constraintList p_list);
60
61static /*@only@*/ constraintList reflectChangesEnsuresFree1 (/*@only@*/ constraintList p_pre2, constraintList p_post1);
616915dd 62
63/*********************************************/
64
bb25bea6 65
66
67
68/*@only@*/ constraintList constraintList_mergeEnsuresFreeFirst (constraintList list1, constraintList list2)
69{
70 constraintList ret;
71
72 ret = constraintList_mergeEnsures (list1, list2);
73
74 constraintList_free(list1);
75 return ret;
76}
616915dd 77
d46ce6a4 78/*@only@*/ constraintList constraintList_mergeEnsures (constraintList list1, constraintList list2)
616915dd 79{
80 constraintList ret;
81 constraintList temp;
470b7798 82
84c9ffbf 83 llassert(constraintList_isDefined(list1) );
d46ce6a4 84 llassert(constraintList_isDefined(list2) );
90bc41f7 85
86 DPRINTF(( message ("constraintList_mergeEnsures: list1 %s list2 %s",
87 constraintList_print(list1), constraintList_print(list2)
88 )));
616915dd 89
90bc41f7 90 ret = constraintList_fixConflicts (list1, list2);
bb25bea6 91 ret = reflectChangesEnsuresFree1 (ret, list2);
d46ce6a4 92 temp = constraintList_subsumeEnsures (ret, list2);
93 constraintList_free(ret);
94 ret = temp;
95
96 temp = constraintList_subsumeEnsures (list2, ret);
616915dd 97
98 temp = constraintList_addList (temp, ret);
4ab867d6 99 constraintList_free(ret);
100
90bc41f7 101 DPRINTF(( message ("constraintList_mergeEnsures: returning %s ",
102 constraintList_print(temp) )
103 ));
104
105
616915dd 106 return temp;
616915dd 107}
108
bb25bea6 109
110/*@only@*/ constraintList constraintList_mergeRequiresFreeFirst (/*@only@*/ constraintList list1, constraintList list2)
111{
112 constraintList ret;
113
114 ret = constraintList_mergeRequires(list1, list2);
115
116 constraintList_free(list1);
117
118 return ret;
119}
120
d46ce6a4 121/*@only@*/ constraintList constraintList_mergeRequires (constraintList list1, constraintList list2)
470b7798 122{
123 constraintList ret;
124 constraintList temp;
125
126 DPRINTF((message ("constraintList_mergeRequires: merging %s and %s ", constraintList_print (list1), constraintList_print(list2) ) ) );
127
128 /* get constraints in list1 not satified by list2 */
28bf4b0b 129 temp = constraintList_reflectChanges(list1, list2);
470b7798 130 DPRINTF((message ("constraintList_mergeRequires: temp = %s", constraintList_print(temp) ) ) );
131
132/*get constraints in list2 not satified by temp*/
28bf4b0b 133 ret = constraintList_reflectChanges(list2, temp);
470b7798 134
135 DPRINTF((message ("constraintList_mergeRequires: ret = %s", constraintList_print(ret) ) ) );
136
4ab867d6 137 ret = constraintList_addListFree (ret, temp);
470b7798 138
139 DPRINTF((message ("constraintList_mergeRequires: returning %s", constraintList_print(ret) ) ) );
140
141 return ret;
142}
616915dd 143
28bf4b0b 144/* old name mergeResolve renamed for czech naming convention */
145void exprNode_mergeResolve (exprNode parent, exprNode child1, exprNode child2)
616915dd 146{
d46ce6a4 147 constraintList temp, temp2;
616915dd 148
d46ce6a4 149 DPRINTF( (message ("magically merging constraint into parent:%s for", exprNode_unparse (parent) )) );
616915dd 150
151 DPRINTF( (message (" children: %s and %s", exprNode_unparse (child1), exprNode_unparse(child2) ) ) );
152
153 if (exprNode_isError (child1) || exprNode_isError(child2) )
d46ce6a4 154 {
155 if (exprNode_isError (child1) && !exprNode_isError(child2) )
616915dd 156 {
d46ce6a4 157 constraintList_free(parent->requiresConstraints);
158
616915dd 159 parent->requiresConstraints = constraintList_copy (child2->requiresConstraints);
d46ce6a4 160 constraintList_free(parent->ensuresConstraints);
161
616915dd 162 parent->ensuresConstraints = constraintList_copy (child2->ensuresConstraints);
163 DPRINTF((message ("Copied child constraints: pre: %s and post: %s",
164 constraintList_print( child2->requiresConstraints),
165 constraintList_print (child2->ensuresConstraints)
166 )
167 ));
168 return;
169 }
170 else
171 {
172 llassert(exprNode_isError(child2) );
616915dd 173 return;
174 }
175 }
176
177 llassert(!exprNode_isError (child1) && ! exprNode_isError(child2) );
178
9280addf 179 DPRINTF( (message ("Child constraints are %s %s and %s %s",
616915dd 180 constraintList_print (child1->requiresConstraints),
181 constraintList_print (child1->ensuresConstraints),
182 constraintList_print (child2->requiresConstraints),
183 constraintList_print (child2->ensuresConstraints)
184 ) ) );
185
d46ce6a4 186
187 constraintList_free(parent->requiresConstraints);
616915dd 188
189 parent->requiresConstraints = constraintList_copy (child1->requiresConstraints);
470b7798 190
90bc41f7 191 if ( context_getFlag (FLG_ORCONSTRAINT) )
28bf4b0b 192 temp = constraintList_reflectChangesOr (child2->requiresConstraints, child1->ensuresConstraints);
90bc41f7 193 else
28bf4b0b 194 temp = constraintList_reflectChanges(child2->requiresConstraints, child1->ensuresConstraints);
d46ce6a4 195
196 temp2 = constraintList_mergeRequires (parent->requiresConstraints, temp);
197 constraintList_free(parent->requiresConstraints);
198 constraintList_free(temp);
90bc41f7 199
d46ce6a4 200 parent->requiresConstraints = temp2;
201
202 DPRINTF( (message ("Parent requires constraints are %s ",
203 constraintList_print (parent->requiresConstraints)
204 ) ) );
205
206 constraintList_free(parent->ensuresConstraints);
616915dd 207
208 parent->ensuresConstraints = constraintList_mergeEnsures(child1->ensuresConstraints,
209 child2->ensuresConstraints);
d46ce6a4 210
616915dd 211
212 DPRINTF( (message ("Parent constraints are %s and %s ",
213 constraintList_print (parent->requiresConstraints),
214 constraintList_print (parent->ensuresConstraints)
215 ) ) );
216
217}
218
219
220
221
d46ce6a4 222/*@only@*/ constraintList constraintList_subsumeEnsures (constraintList list1, constraintList list2)
616915dd 223{
224 constraintList ret;
c3e695ff 225 ret = constraintList_makeNew();
616915dd 226 constraintList_elements (list1, el)
227 {
228
229 DPRINTF ((message ("Examining %s", constraint_print (el) ) ) );
28bf4b0b 230 if (!constraintList_resolve (el, list2) )
616915dd 231 {
d46ce6a4 232 constraint temp;
233 temp = constraint_copy(el);
234 ret = constraintList_add (ret, temp);
616915dd 235 }
236 else
237 {
238 DPRINTF ( (message ("Subsuming %s", constraint_print (el) ) ) );
239 }
240 } end_constraintList_elements;
241
242 return ret;
243}
244
90bc41f7 245
bb25bea6 246
28bf4b0b 247/*used to be reflectChangesFreePre renamed for Czech naming conventino*/
bb25bea6 248/* tries to resolve constraints in list pre2 using post1 */
28bf4b0b 249/*@only@*/ constraintList constraintList_reflectChangesFreePre (/*@only@*/ constraintList pre2, /*@observer@*/ constraintList post1)
bb25bea6 250{
251 constraintList ret;
252
28bf4b0b 253 ret = constraintList_reflectChanges(pre2, post1);
bb25bea6 254
255 constraintList_free (pre2);
256
257 return ret;
258}
259
260
dc7f6a51 261
90bc41f7 262/* tries to resolve constraints in list pre2 using post1 */
dc7f6a51 263
264static /*@only@*/ constraintList reflectChangesNoOr (/*@observer@*/ /*@temp@*/ constraintList pre2, /*@observer@*/ /*@temp@*/ constraintList post1)
616915dd 265{
266
267 constraintList ret;
268 constraint temp;
bb25bea6 269 constraint temp2;
270
dc7f6a51 271 llassert (! context_getFlag (FLG_ORCONSTRAINT) );
272
c3e695ff 273 ret = constraintList_makeNew();
616915dd 274 DPRINTF((message ("reflectChanges: lists %s and %s", constraintList_print(pre2), constraintList_print(post1) )));
275
276 constraintList_elements (pre2, el)
277 {
28bf4b0b 278 if (!constraintList_resolve (el, post1) )
616915dd 279 {
28bf4b0b 280 temp = constraint_substitute (el, post1);
281 if (!constraintList_resolve (temp, post1) )
616915dd 282 {
b7b694d6 283 /* try inequality substitution
284 the inequality substitution may cause us to lose information
285 so we don't want to store the result but we do it anyway
286 */
616915dd 287 temp2 = constraint_copy (temp);
920a3797 288 temp2 = inequalitySubstitute (temp2, post1);
28bf4b0b 289 if (!constraintList_resolve (temp2, post1) )
920a3797 290 {
291 temp2 = inequalitySubstituteUnsound (temp2, post1);
28bf4b0b 292 if (!constraintList_resolve (temp2, post1) )
920a3797 293 ret = constraintList_add (ret, temp2);
294 else
295 constraint_free(temp2);
296 }
297 else
298 {
299 constraint_free(temp2);
300 }
616915dd 301 }
bb25bea6 302 constraint_free(temp);
616915dd 303 }
304 } end_constraintList_elements;
305
306 DPRINTF((message ("reflectChanges: returning %s", constraintList_print(ret) ) ) );
307 return ret;
308}
309
dc7f6a51 310/* tries to resolve constraints in list pre2 using post1 */
311/*@only@*/ constraintList constraintList_reflectChanges(/*@observer@*/ constraintList pre2, /*@observer@*/ constraintList post1)
312{
313 constraintList temp;
314
315 if ( context_getFlag (FLG_ORCONSTRAINT) )
316
317 temp = constraintList_reflectChangesOr (pre2, post1);
318 else
319 temp = reflectChangesNoOr(pre2, post1);
320
321 return temp;
322}
616915dd 323
28bf4b0b 324static constraint constraint_addOr (/*@returned@*/ constraint orig, /*@observer@*/ constraint orConstr)
90bc41f7 325{
326 constraint c;
327 c = orig;
328
28bf4b0b 329 DPRINTF((message("constraint_addor: oring %s onto %s", constraint_printOr(orConstr), constraint_printOr(orig) ) ));
90bc41f7 330
331 while (c->or != NULL)
332 {
333 c = c->or;
334 }
a779b61e 335
28bf4b0b 336 c->or = constraint_copy(orConstr);
90bc41f7 337
338 DPRINTF((message("constraint_addor: returning %s",constraint_printOr(orig) ) ));
339
340 return orig;
341}
342
343
28bf4b0b 344static bool resolveOr ( /*@temp@*/ constraint c, /*@observer@*/ /*@temp@*/ constraintList list)
90bc41f7 345{
346 constraint temp;
347
a779b61e 348 int numberOr;
349
350 numberOr = 0;
90bc41f7 351 DPRINTF(( message("resolveOr: constraint %s and list %s", constraint_printOr(c), constraintList_print(list) ) ));
352 temp = c;
353
354 do
355 {
28bf4b0b 356 if (constraintList_resolve (temp, list) )
90bc41f7 357 return TRUE;
358 temp = temp->or;
a779b61e 359 numberOr++;
360 llassert(numberOr <= 10);
90bc41f7 361 }
84c9ffbf 362 while (constraint_isDefined(temp));
90bc41f7 363
364 return FALSE;
365}
366
bb25bea6 367/*This is a "helper" function for doResolveOr */
90bc41f7 368
bb25bea6 369static /*@only@*/ constraint doResolve (/*@only@*/ constraint c, constraintList post1, bool * resolved)
90bc41f7 370{
371 constraint temp;
a779b61e 372
373 llassert(constraint_isUndefined (c->or ) );
90bc41f7 374
a779b61e 375 if (!resolveOr (c, post1) )
376 {
377
378 temp = constraint_substitute (c, post1);
379
380 if (!resolveOr (temp, post1) )
90bc41f7 381 {
b7b694d6 382 /* try inequality substitution */
a779b61e 383 constraint temp2;
bb25bea6 384
b7b694d6 385 /* the inequality substitution may cause us to lose information
386 so we don't want to store the result but we do anyway
387 */
388 temp2 = constraint_copy (c);
389 temp2 = inequalitySubstitute (temp2, post1);
390
391 if (!resolveOr (temp2, post1) )
392 {
393 constraint temp3;
394 temp3 = constraint_copy(temp2);
395
396 temp3 = inequalitySubstituteStrong (temp3, post1);
397 if (!resolveOr (temp3, post1) )
bb25bea6 398 {
b7b694d6 399 temp2 = inequalitySubstituteUnsound (temp2, post1);
400 if (!resolveOr (temp2, post1) )
dc7f6a51 401 {
b7b694d6 402 if (!constraint_same (temp, temp2) )
403 temp = constraint_addOr (temp, temp2);
404
405 if (!constraint_same (temp, temp3) && !constraint_same (temp3, temp2) )
406 temp = constraint_addOr (temp, temp3);
407
408 *resolved = FALSE;
409
dc7f6a51 410 constraint_free(temp2);
411 constraint_free(temp3);
b7b694d6 412 constraint_free(c);
413
414 return temp;
bb25bea6 415 }
b7b694d6 416 constraint_free(temp2);
417 constraint_free(temp3);
bb25bea6 418 }
dc7f6a51 419 else
420 {
421 constraint_free(temp2);
b7b694d6 422 constraint_free(temp3);
423 }
90bc41f7 424 }
b7b694d6 425 else
426 {
427 constraint_free(temp2);
428 }
429
90bc41f7 430 }
b7b694d6 431 constraint_free(temp);
432 }
433 constraint_free(c);
434
435 *resolved = TRUE;
436 return NULL;
90bc41f7 437}
438
a779b61e 439static /*@only@*/ constraint doResolveOr (/*@observer@*/ /*@temp@*/ constraint c, constraintList post1, /*@out@*/bool * resolved)
90bc41f7 440{
441 constraint ret;
442 constraint next;
443 constraint curr;
a779b61e 444
445
446 DPRINTF(( message("doResolveOr: constraint %s and list %s", constraint_printOr(c), constraintList_print(post1) ) ));
447
448
90bc41f7 449
450 *resolved = FALSE;
a779b61e 451
452
90bc41f7 453 ret = constraint_copy(c);
a779b61e 454
455 if (constraintList_isEmpty(post1) )
456 {
457 return ret;
458 }
459
90bc41f7 460 next = ret->or;
461 ret->or = NULL;
462
463 ret = doResolve (ret, post1, resolved);
bb25bea6 464
465 if (*resolved)
466 {
2934b455 467 if (next != NULL)
4ab867d6 468 constraint_free(next);
a779b61e 469
920a3797 470 /*we don't need to free ret when resolved is false because ret is null*/
471 llassert(ret == NULL);
472
a779b61e 473 return NULL;
bb25bea6 474 }
a779b61e 475
84c9ffbf 476 while (next != NULL)
90bc41f7 477 {
478 curr = next;
479 next = curr->or;
480 curr->or = NULL;
481
482 curr = doResolve (curr, post1, resolved);
a779b61e 483
90bc41f7 484 if (*resolved)
bb25bea6 485 {
4ab867d6 486 /* curr is null so we don't try to free it*/
920a3797 487 llassert(curr == NULL);
4ab867d6 488
2934b455 489 if (next != NULL)
4ab867d6 490 constraint_free(next);
920a3797 491
bb25bea6 492 constraint_free(ret);
920a3797 493 return NULL;
bb25bea6 494 }
90bc41f7 495 ret = constraint_addOr (ret, curr);
4ab867d6 496 constraint_free(curr);
90bc41f7 497 }
90bc41f7 498 return ret;
499}
500
90bc41f7 501/* tries to resolve constraints in list pr2 using post1 */
28bf4b0b 502/*@only@*/ constraintList constraintList_reflectChangesOr (constraintList pre2, constraintList post1)
90bc41f7 503{
504 bool resolved;
505 constraintList ret;
506 constraint temp;
c3e695ff 507 ret = constraintList_makeNew();
28bf4b0b 508 DPRINTF((message ("constraintList_reflectChangesOr: lists %s and %s", constraintList_print(pre2), constraintList_print(post1) )));
90bc41f7 509
510 constraintList_elements (pre2, el)
511 {
512 temp = doResolveOr (el, post1, &resolved);
513
514 if (!resolved)
515 {
516 ret = constraintList_add(ret, temp);
517 }
920a3797 518 else
519 {
a779b61e 520 /* we don't need to free temp when
521 resolved is false because temp is null */
920a3797 522 llassert(temp == NULL);
523 }
524
90bc41f7 525 } end_constraintList_elements;
526
a779b61e 527 DPRINTF((message ("constraintList_reflectChangesOr: returning %s", constraintList_print(ret) ) ) );
90bc41f7 528 return ret;
529}
a779b61e 530
bb25bea6 531static /*@only@*/ constraintList reflectChangesEnsures (/*@observer@*/ constraintList pre2, constraintList post1)
616915dd 532{
533 constraintList ret;
534 constraint temp;
c3e695ff 535 ret = constraintList_makeNew();
616915dd 536 constraintList_elements (pre2, el)
537 {
28bf4b0b 538 if (!constraintList_resolve (el, post1) )
616915dd 539 {
28bf4b0b 540 temp = constraint_substitute (el, post1);
616915dd 541 llassert (temp != NULL);
542
28bf4b0b 543 if (!constraintList_resolve (temp, post1) )
616915dd 544 ret = constraintList_add (ret, temp);
920a3797 545 else
546 constraint_free(temp);
616915dd 547 }
548 else
549 {
550 DPRINTF ( (message ("Resolved away %s ", constraint_print(el) ) ) );
551 }
552 } end_constraintList_elements;
553
554 return ret;
555}
556
557
bb25bea6 558static /*@only@*/ constraintList reflectChangesEnsuresFree1 (/*@only@*/ constraintList pre2, constraintList post1)
559{
560 constraintList ret;
561
562 ret = reflectChangesEnsures (pre2, post1);
563
564 constraintList_free(pre2);
565
566 return ret;
567}
568
569
570static bool constraint_conflict (constraint c1, constraint c2)
616915dd 571{
572
573 if (constraintExpr_similar(c1->lexpr, c2->lexpr) )
574 {
575 if (c1->ar == EQ)
576 if (c1->ar == c2->ar)
577 {
578 DPRINTF ( (message ("%s conflicts with %s ", constraint_print (c1), constraint_print(c2) ) ) );
579 return TRUE;
580 }
581 }
582
b7b694d6 583 /* This is a slight kludg to prevent circular constraints like
584 strlen(str) == maxRead(s) + strlen(str);
585 */
a779b61e 586
b7b694d6 587 /*@i324234*/ /* clean this up */
a779b61e 588
589 if (c1->ar == EQ)
590 if (c1->ar == c2->ar)
591 {
592 if (constraintExpr_search (c1->lexpr, c2->expr) )
593 if (constraintExpr_isTerm(c1->lexpr) )
594 {
595 constraintTerm term;
596
597 term = constraintExpr_getTerm(c1->lexpr);
598
599 if (constraintTerm_isExprNode(term) )
600 {
601 DPRINTF ( (message ("%s conflicts with %s ", constraint_print (c1), constraint_print(c2) ) ) );
602 return TRUE;
603 }
604 }
605 }
606
607 if (constraint_tooDeep(c1) || constraint_tooDeep(c2) )
608 {
609 DPRINTF ( (message ("%s conflicts with %s (constraint is too deep", constraint_print (c1), constraint_print(c2) ) ) );
610 return TRUE;
611 }
612
616915dd 613 DPRINTF ( (message ("%s doesn't conflict with %s ", constraint_print (c1), constraint_print(c2) ) ) );
614
615 return FALSE;
616
617}
618
28bf4b0b 619static void constraint_fixConflict (/*@temp@*/ constraint good, /*@temp@*/ /*@observer@*/ constraint conflicting) /*@modifies good@*/
616915dd 620{
616915dd 621 if (conflicting->ar ==EQ )
622 {
623 good->expr = constraintExpr_searchandreplace (good->expr, conflicting->lexpr, conflicting->expr);
d46ce6a4 624 good = constraint_simplify (good);
616915dd 625 }
626
627
628}
629
bb25bea6 630static bool conflict (constraint c, constraintList list)
616915dd 631{
90bc41f7 632
633 constraintList_elements (list, el)
616915dd 634 {
635 if ( constraint_conflict(el, c) )
636 {
637 constraint_fixConflict (el, c);
638 return TRUE;
639 }
640 } end_constraintList_elements;
641
642 return FALSE;
616915dd 643
644}
645
b7b694d6 646/*
647 check if constraint in list1 conflicts with constraints in List2. If so we
648 remove form list1 and change list2.
649*/
650
84c9ffbf 651constraintList constraintList_fixConflicts (constraintList list1, constraintList list2)
616915dd 652{
653 constraintList ret;
c3e695ff 654 ret = constraintList_makeNew();
84c9ffbf 655 llassert(constraintList_isDefined(list1) );
616915dd 656 constraintList_elements (list1, el)
657 {
658 if (! conflict (el, list2) )
659 {
d46ce6a4 660 constraint temp;
661 temp = constraint_copy(el);
662 ret = constraintList_add (ret, temp);
616915dd 663 }
664 } end_constraintList_elements;
665
666 return ret;
616915dd 667}
668
90bc41f7 669/*returns true if constraint post satifies cosntriant pre */
bb25bea6 670static bool satifies (constraint pre, constraint post)
616915dd 671{
672 if (constraint_isAlwaysTrue (pre) )
673 return TRUE;
674
675 if (!constraintExpr_similar (pre->lexpr, post->lexpr) )
676 {
677 return FALSE;
678 }
28bf4b0b 679 if (constraintExpr_isUndefined(post->expr))
616915dd 680 {
681 llassert(FALSE);
682 return FALSE;
683 }
684
685 return rangeCheck (pre->ar, pre->expr, post->ar, post->expr);
686}
687
bb25bea6 688
28bf4b0b 689bool constraintList_resolve (/*@temp@*/ /*@observer@*/ constraint c, /*@temp@*/ /*@observer@*/ constraintList p)
bb25bea6 690{
691 constraintList_elements (p, el)
692 {
693 if ( satifies (c, el) )
694 {
695 DPRINTF ( (message ("\n%s Satifies %s\n ", constraint_print(el), constraint_print(c) ) ) );
696 return TRUE;
697 }
698 DPRINTF ( (message ("\n%s does not satify %s\n ", constraint_print(el), constraint_print(c) ) ) );
699 }
700 end_constraintList_elements;
701 DPRINTF ( (message ("no constraints satify %s", constraint_print(c) ) ));
702 return FALSE;
703}
704
705static bool arithType_canResolve (arithType ar1, arithType ar2)
616915dd 706{
707 switch (ar1)
708 {
709 case GTE:
710 case GT:
711 if ( (ar2 == GT) || (ar2 == GTE) || (ar2 == EQ) )
712 {
713 return TRUE;
714 }
715 break;
716
717 case EQ:
718 if (ar2 == EQ)
719 return TRUE;
720 break;
721
722 case LT:
723 case LTE:
616915dd 724 if ( (ar2 == LT) || (ar2 == LTE) || (ar2 == EQ) )
725 return TRUE;
84c9ffbf 726 break;
616915dd 727 default:
728 return FALSE;
729 }
730 return FALSE;
731}
732
e5f31c00 733/*checks for the case expr2 == sizeof buf1 and buf1 is a fixed array*/
734static bool sizeofBufComp(constraintExpr buf1, constraintExpr expr2)
735{
736 constraintTerm ct;
737 exprNode e, t;
738 sRef s1, s2;
739 /*@access constraintExpr@*/
740
741 if ( (expr2->kind != term) && (buf1->kind != term) )
742 return FALSE;
743
744
745 ct = constraintExprData_termGetTerm(expr2->data);
746
747 if (!constraintTerm_isExprNode(ct) )
748 return FALSE;
749
750 e = constraintTerm_getExprNode(ct);
751
752 if (e->kind != XPR_SIZEOF)
753 return FALSE;
754
755 t = exprData_getSingle (e->edata);
756 s1 = exprNode_getSref (t);
757
758 s2 = constraintTerm_getsRef(constraintExprData_termGetTerm(buf1->data) );
759
760 /*@i223@*/ /*this may be the wronge thing to test for */
761 if (sRef_similarRelaxed(s1, s2) || sRef_sameName (s1, s2) )
762 {
763 if (ctype_isFixedArray (sRef_getType (s2) ) )
764 return TRUE;
765 }
766 return FALSE;
767}
768
769/* look for the special case of
770 maxSet(buf) >= sizeof(buf) - 1
771*/
772
773/*@i223@*/ /*need to add some type checking */
774static bool sizeOfMaxSet( /*@observer@*/ /*@temp@*/ constraint c)
775{
776 constraintExpr l, r, buf1, buf2, con;
777
778 DPRINTF(( message("sizeOfMaxSet: checking %s ", constraint_print(c) )
779 ));
780
781 l = c->lexpr;
782 r = c->expr;
783
784 if (!( (c->ar == EQ) || (c->ar == GTE) || (c->ar == LTE) ) )
785 return FALSE;
786
787 /*check if the constraintExpr is MaxSet(buf) */
788 if (l->kind == unaryExpr)
789 {
790 if (constraintExprData_unaryExprGetOp(l->data) == MAXSET)
791 {
792 buf1 = constraintExprData_unaryExprGetExpr(l->data);
793 }
794 else
795 return FALSE;
796 }
797 else
798 return FALSE;
799
800
801 if (r->kind != binaryexpr)
802 return FALSE;
803
804 buf2 = constraintExprData_binaryExprGetExpr1(r->data);
805 con = constraintExprData_binaryExprGetExpr2(r->data);
806
807 if (constraintExprData_binaryExprGetOp(r->data) == BINARYOP_MINUS)
808 {
809 if (constraintExpr_canGetValue(con) )
810 {
811 long i;
812
813 i = constraintExpr_getValue(con);
814 if (i != 1)
815 {
816 return FALSE;
817 }
818 }
819 else
820 return FALSE;
821 }
822
823 if (constraintExprData_binaryExprGetOp(r->data) == BINARYOP_PLUS)
824 {
825 if (constraintExpr_canGetValue(con) )
826 {
827 long i;
828
829 i = constraintExpr_getValue(con);
830 if (i != -1)
831 {
832 return FALSE;
833 }
834 }
835 else
836 return FALSE;
837 }
838
839 if (sizeofBufComp(buf1, buf2))
840 {
841 return TRUE;
842 }
843 else
844 {
845 return FALSE;
846 }
847
848
849}
850/*@noaccess constraintExpr@*/
851
90bc41f7 852/* We look for constraint which are tautologies */
853
28bf4b0b 854bool constraint_isAlwaysTrue (/*@observer@*/ /*@temp@*/ constraint c)
616915dd 855{
856 constraintExpr l, r;
15b3d2b2 857 bool rHasConstant;
858 int rConstant;
9280addf 859
616915dd 860 l = c->lexpr;
861 r = c->expr;
90bc41f7 862
863 DPRINTF(( message("constraint_IsAlwaysTrue:examining %s", constraint_print(c) ) ));
e5f31c00 864
865 if (sizeOfMaxSet(c) )
866 return TRUE;
867
616915dd 868 if (constraintExpr_canGetValue(l) && constraintExpr_canGetValue(r) )
869 {
870 int cmp;
871 cmp = constraintExpr_compare (l, r);
872 switch (c->ar)
873 {
874 case EQ:
875 return (cmp == 0);
876 case GT:
877 return (cmp > 0);
878 case GTE:
879 return (cmp >= 0);
880 case LTE:
881 return (cmp <= 0);
882 case LT:
883 return (cmp < 0);
884
885 default:
9280addf 886 BADEXIT;
84c9ffbf 887 /*@notreached@*/
9280addf 888 break;
889 }
890 }
891
892 if (constraintExpr_similar (l,r) )
893 {
894 switch (c->ar)
895 {
896 case EQ:
897 case GTE:
898 case LTE:
899 return TRUE;
900
901 case GT:
902 case LT:
903 break;
904 default:
905 BADEXIT;
84c9ffbf 906 /*@notreached@*/
616915dd 907 break;
908 }
909 }
9280addf 910
911 l = constraintExpr_copy (c->lexpr);
912 r = constraintExpr_copy (c->expr);
913
9280addf 914 r = constraintExpr_propagateConstants (r, &rHasConstant, &rConstant);
915
90bc41f7 916 if (constraintExpr_similar (l,r) && (rHasConstant ) )
9280addf 917 {
918 DPRINTF(( message("constraint_IsAlwaysTrue: after removing constants %s and %s are similar", constraintExpr_unparse(l), constraintExpr_unparse(r) ) ));
90bc41f7 919 DPRINTF(( message("constraint_IsAlwaysTrue: rconstant is %d", rConstant ) ));
bb25bea6 920
921 constraintExpr_free(l);
922 constraintExpr_free(r);
923
90bc41f7 924 switch (c->ar)
9280addf 925 {
90bc41f7 926 case EQ:
927 return (rConstant == 0);
928 case LT:
929 return (rConstant > 0);
930 case LTE:
931 return (rConstant >= 0);
932 case GTE:
933 return (rConstant <= 0);
934 case GT:
935 return (rConstant < 0);
936
937 default:
938 BADEXIT;
84c9ffbf 939 /*@notreached@*/
90bc41f7 940 break;
9280addf 941 }
9280addf 942 }
90bc41f7 943 else
944 {
bb25bea6 945 constraintExpr_free(l);
946 constraintExpr_free(r);
90bc41f7 947 DPRINTF(( message("Constraint %s is not always true", constraint_print(c) ) ));
948 return FALSE;
949 }
9280addf 950
951 BADEXIT;
616915dd 952}
953
bb25bea6 954static bool rangeCheck (arithType ar1, /*@observer@*/ constraintExpr expr1, arithType ar2, /*@observer@*/ constraintExpr expr2)
616915dd 955
956{
bb25bea6 957 DPRINTF ((message ("Doing Range CHECK %s and %s", constraintExpr_unparse(expr1), constraintExpr_unparse(expr2) ) ));
616915dd 958
959 if (! arithType_canResolve (ar1, ar2) )
960 return FALSE;
961
962 switch (ar1)
963 {
964 case GTE:
2681ee39 965 if (constraintExpr_similar (expr1, expr2) )
966 return TRUE;
967 /*@fallthrough@*/
968 case GT:
616915dd 969 if (! (constraintExpr_canGetValue (expr1) &&
2681ee39 970 constraintExpr_canGetValue (expr2) ) )
971 {
972 constraintExpr e1, e2;
973 bool p1, p2;
974 int const1, const2;
975
976 e1 = constraintExpr_copy(expr1);
977 e2 = constraintExpr_copy(expr2);
978
979 e1 = constraintExpr_propagateConstants (e1, &p1, &const1);
980
981 e2 = constraintExpr_propagateConstants (e2, &p2, &const2);
982
983 if (p1 || p2)
984 {
985 if (!p1)
986 const1 = 0;
987
988 if (!p2)
989 const2 = 0;
990
991 if (const1 <= const2)
992 if (constraintExpr_similar (e1, e2) )
993 {
994 constraintExpr_free(e1);
995 constraintExpr_free(e2);
996 return TRUE;
997 }
998 }
999 DPRINTF( ("Can't Get value"));
1000
1001 constraintExpr_free(e1);
1002 constraintExpr_free(e2);
1003 return FALSE;
1004 }
1005
1006 if (constraintExpr_compare (expr2, expr1) >= 0)
1007 return TRUE;
616915dd 1008
1009 return FALSE;
2681ee39 1010 case EQ:
1011 if (constraintExpr_similar (expr1, expr2) )
1012 return TRUE;
1013
1014 return FALSE;
1015 case LTE:
1016 if (constraintExpr_similar (expr1, expr2) )
1017 return TRUE;
1018 /*@fallthrough@*/
1019 case LT:
1020 if (! (constraintExpr_canGetValue (expr1) &&
1021 constraintExpr_canGetValue (expr2) ) )
1022 {
1023 constraintExpr e1, e2;
1024 bool p1, p2;
1025 int const1, const2;
1026
1027 e1 = constraintExpr_copy(expr1);
1028 e2 = constraintExpr_copy(expr2);
1029
1030 e1 = constraintExpr_propagateConstants (e1, &p1, &const1);
1031
1032 e2 = constraintExpr_propagateConstants (e2, &p2, &const2);
1033
1034 if (p1 || p2)
1035 {
1036 if (!p1)
1037 const1 = 0;
1038
1039 if (!p2)
1040 const2 = 0;
1041
1042 if (const1 >= const2)
1043 if (constraintExpr_similar (e1, e2) )
1044 {
1045 constraintExpr_free(e1);
1046 constraintExpr_free(e2);
1047 return TRUE;
1048 }
1049 }
1050 constraintExpr_free(e1);
1051 constraintExpr_free(e2);
1052
1053 DPRINTF( ("Can't Get value"));
1054 return FALSE;
1055 }
1056
1057 if (constraintExpr_compare (expr2, expr1) <= 0)
1058 return TRUE;
1059
1060 return FALSE;
1061
1062 default:
1063 llcontbug((message("Unhandled case in switch: %q", arithType_print(ar1) ) ) );
1064 }
616915dd 1065 BADEXIT;
616915dd 1066}
1067
28bf4b0b 1068static constraint constraint_searchandreplace (/*@returned@*/ constraint c, constraintExpr old, constraintExpr newExpr)
616915dd 1069{
1070 DPRINTF (("Doing replace for lexpr") );
28bf4b0b 1071 c->lexpr = constraintExpr_searchandreplace (c->lexpr, old, newExpr);
616915dd 1072 DPRINTF (("Doing replace for expr") );
28bf4b0b 1073 c->expr = constraintExpr_searchandreplace (c->expr, old, newExpr);
616915dd 1074 return c;
1075}
1076
84c9ffbf 1077bool constraint_search (constraint c, constraintExpr old) /*@*/
616915dd 1078{
1079 bool ret;
1080 ret = FALSE;
1081
1082 ret = constraintExpr_search (c->lexpr, old);
1083 ret = ret || constraintExpr_search (c->expr, old);
1084 return ret;
1085}
1086
b7b694d6 1087/* adjust file locs and stuff */
bb25bea6 1088static constraint constraint_adjust (/*@returned@*/ constraint substitute, /*@observer@*/ constraint old)
616915dd 1089{
1090 fileloc loc1, loc2, loc3;
1091
1092 DPRINTF ( (message("Start adjust on %s and %s", constraint_print(substitute),
1093 constraint_print(old))
1094 ));
1095
1096 loc1 = constraint_getFileloc (old);
616915dd 1097 loc2 = constraintExpr_getFileloc (substitute->lexpr);
616915dd 1098 loc3 = constraintExpr_getFileloc (substitute->expr);
616915dd 1099
b7b694d6 1100 /* special case of an equality that "contains itself" */
616915dd 1101 if (constraintExpr_search (substitute->expr, substitute->lexpr) )
1102 if (fileloc_closer (loc1, loc3, loc2))
1103 {
1104 constraintExpr temp;
1105 DPRINTF ( (message("Doing adjust on %s", constraint_print(substitute) )
1106 ));
1107 temp = substitute->lexpr;
1108 substitute->lexpr = substitute->expr;
1109 substitute->expr = temp;
1110 substitute = constraint_simplify(substitute);
1111 }
1112
bb25bea6 1113 fileloc_free (loc1);
1114 fileloc_free (loc2);
1115 fileloc_free (loc3);
1116
616915dd 1117 return substitute;
1118
1119}
1120
90bc41f7 1121/* If function preforms substitutes based on inequality
1122
1123 It uses the rule x >= y && b < y ===> x >= b + 1
1124
1125 Warning this is sound but throws out information
1126 */
dc7f6a51 1127
bb25bea6 1128constraint inequalitySubstitute (/*@returned@*/ constraint c, constraintList p)
616915dd 1129{
1130 if (c->ar != GTE)
1131 return c;
1132
1133 constraintList_elements (p, el)
1134 {
dc7f6a51 1135 if ( (el->ar == LT ) )
b7b694d6 1136 /* if (!constraint_conflict (c, el) ) */ /*@i523 explain this! */
616915dd 1137 {
90bc41f7 1138 constraintExpr temp2;
1139
bb25bea6 1140 /*@i22*/
1141
90bc41f7 1142 if (constraintExpr_same (el->expr, c->expr) )
616915dd 1143 {
dc7f6a51 1144 DPRINTF((message ("inequalitySubstitute Replacing %q in %q with %q",
616915dd 1145 constraintExpr_print (c->expr),
1146 constraint_print (c),
1147 constraintExpr_print (el->expr) )
1148 ));
90bc41f7 1149 temp2 = constraintExpr_copy (el->lexpr);
bb25bea6 1150 constraintExpr_free(c->expr);
90bc41f7 1151 c->expr = constraintExpr_makeIncConstraintExpr (temp2);
dc7f6a51 1152
616915dd 1153 }
1154
1155 }
1156 }
1157 end_constraintList_elements;
1158
1159 c = constraint_simplify(c);
1160 return c;
1161}
1162
dc7f6a51 1163
1164/* drl7x 7/26/001
1165
1166 THis function is like inequalitySubstitute but it adds the rule
1167 added the rules x >= y && y <= b ===> x >= b
1168 x >= y && y < b ===> x >= b + 1
1169
1170 This is sound but sonce it throws out additional information it should only one used
1171 if we're oring constraints.
1172 */
1173
1174static constraint inequalitySubstituteStrong (/*@returned@*/ constraint c, constraintList p)
1175{
1176 DPRINTF (( message ("inequalitySubstituteStrong examining substituting for %q", constraint_print(c) ) ));
1177
1178 if (c->ar != GTE)
1179 return c;
1180
1181 DPRINTF (( message ("inequalitySubstituteStrong examining substituting for %q with %q",
1182 constraint_print(c), constraintList_print(p) ) ));
1183 constraintList_elements (p, el)
1184 {
1185 DPRINTF (( message ("inequalitySubstituteStrong examining substituting %s on %s", constraint_print(el), constraint_print(c) ) ));
1186
1187 if ( (el->ar == LT ) || (el->ar == LTE ) )
b7b694d6 1188 /* if (!constraint_conflict (c, el) ) */ /*@i523@*/
dc7f6a51 1189 {
dc7f6a51 1190 constraintExpr temp2;
1191
1192 /*@i22*/
1193
dc7f6a51 1194 if (constraintExpr_same (el->lexpr, c->expr) )
1195 {
1196 DPRINTF((message ("inequalitySubstitute Replacing %s in %s with %s",
1197 constraintExpr_print (c->expr),
1198 constraint_print (c),
1199 constraintExpr_print (el->expr) )
1200 ));
1201 temp2 = constraintExpr_copy (el->expr);
1202 constraintExpr_free(c->expr);
1203 if ( (el->ar == LTE ) )
1204 {
1205 c->expr = temp2;
1206 }
1207 else
1208 {
1209 c->expr = constraintExpr_makeIncConstraintExpr (temp2);
1210 }
1211 }
1212
1213 }
1214 }
1215 end_constraintList_elements;
1216
1217 c = constraint_simplify(c);
1218 return c;
1219}
1220
1221
90bc41f7 1222/* This function performs substitutions based on the rule:
1223 for a constraint of the form expr1 >= expr2; a < b =>
1224 a = b -1 for all a in expr1. This will work in most cases.
1225
1226 Like inequalitySubstitute we're throwing away some information
1227*/
1228
bb25bea6 1229static constraint inequalitySubstituteUnsound (/*@returned@*/ constraint c, constraintList p)
90bc41f7 1230{
1231 DPRINTF (( message ("Doing inequalitySubstituteUnsound " ) ));
1232
1233 if (c->ar != GTE)
1234 return c;
1235
1236 constraintList_elements (p, el)
1237 {
1238 DPRINTF (( message ("inequalitySubstituteUnsound examining substituting %s on %s", constraint_print(el), constraint_print(c) ) ));
1239 if ( ( el->ar == LTE) || (el->ar == LT) )
b7b694d6 1240 /* if (!constraint_conflict (c, el) ) */ /*@i532@*/
90bc41f7 1241 {
90bc41f7 1242 constraintExpr temp2;
b7b694d6 1243
90bc41f7 1244 temp2 = constraintExpr_copy (el->expr);
1245
1246 if (el->ar == LT)
1247 temp2 = constraintExpr_makeDecConstraintExpr (temp2);
1248
1249 DPRINTF((message ("Replacing %s in %s with %s",
1250 constraintExpr_print (el->lexpr),
1251 constraintExpr_print (c->lexpr),
1252 constraintExpr_print (temp2) ) ));
1253
1254 c->lexpr = constraintExpr_searchandreplace (c->lexpr, el->lexpr, temp2);
bb25bea6 1255 constraintExpr_free(temp2);
90bc41f7 1256 }
1257 }
1258 end_constraintList_elements;
1259
1260 c = constraint_simplify(c);
1261 return c;
1262}
1263
28bf4b0b 1264/*@only@*/ constraint constraint_substitute (/*@observer@*/ /*@temp@*/ constraint c, constraintList p)
616915dd 1265{
90bc41f7 1266 constraint ret;
1267
1268 ret = constraint_copy(c);
616915dd 1269 constraintList_elements (p, el)
1270 {
1271 if ( el->ar == EQ)
90bc41f7 1272 if (!constraint_conflict (ret, el) )
616915dd 1273
1274 {
1275 constraint temp;
bb25bea6 1276
616915dd 1277 temp = constraint_copy(el);
1278
90bc41f7 1279 temp = constraint_adjust(temp, ret);
616915dd 1280
470b7798 1281 DPRINTF((message ("Substituting %s in the constraint %s",
90bc41f7 1282 constraint_print (temp), constraint_print (ret)
616915dd 1283 ) ) );
1284
1285
90bc41f7 1286 ret = constraint_searchandreplace (ret, temp->lexpr, temp->expr);
1287 DPRINTF(( message ("The new constraint is %s", constraint_print (ret) ) ));
bb25bea6 1288 constraint_free(temp);
616915dd 1289 }
1290 }
1291 end_constraintList_elements;
bb25bea6 1292 DPRINTF(( message ("The finial new constraint is %s", constraint_print (ret) ) ));
616915dd 1293
90bc41f7 1294 ret = constraint_simplify(ret);
1295 return ret;
616915dd 1296}
1297
bb25bea6 1298
1299/*@only@*/ constraintList constraintList_substituteFreeTarget (/*@only@*/ constraintList target, /*@observer@*/ constraintList subList)
1300{
1301constraintList ret;
1302
1303ret = constraintList_substitute (target, subList);
1304
1305constraintList_free(target);
1306
1307return ret;
1308}
1309
c3e695ff 1310/* we try to do substitutions on each constraint in target using the constraint in sublist*/
1311
bb25bea6 1312/*@only@*/ constraintList constraintList_substitute (constraintList target,/*2observer@*/ constraintList subList)
c3e695ff 1313{
1314
1315 constraintList ret;
1316
1317 ret = constraintList_makeNew();
1318
1319 constraintList_elements(target, el)
1320 {
d46ce6a4 1321 constraint temp;
b7b694d6 1322 /* drl possible problem : warning make sure that a side effect is not expected */
bb25bea6 1323
28bf4b0b 1324 temp = constraint_substitute(el, subList);
d46ce6a4 1325 ret = constraintList_add (ret, temp);
c3e695ff 1326 }
1327 end_constraintList_elements;
84c9ffbf 1328
bb25bea6 1329 return ret;
c3e695ff 1330}
616915dd 1331
28bf4b0b 1332static constraint constraint_solve (/*@returned@*/ constraint c)
616915dd 1333{
1334 DPRINTF( (message ("Solving %s\n", constraint_print(c) ) ) );
1335 c->expr = constraintExpr_solveBinaryExpr (c->lexpr, c->expr);
1336 DPRINTF( (message ("Solved and got %s\n", constraint_print(c) ) ) );
1337
1338 return c;
1339}
1340
1341static arithType flipAr (arithType ar)
1342{
1343 switch (ar)
1344 {
1345 case LT:
1346 return GT;
1347 case LTE:
1348 return GTE;
1349 case EQ:
1350 return EQ;
1351 case GT:
1352 return LT;
1353 case GTE:
1354 return LTE;
1355 default:
84c9ffbf 1356 llcontbug (message("unexpected value: case not handled"));
616915dd 1357 }
1358 BADEXIT;
1359}
1360
d46ce6a4 1361static constraint constraint_swapLeftRight (/*@returned@*/ constraint c)
616915dd 1362{
1363 constraintExpr temp;
1364 c->ar = flipAr (c->ar);
1365 temp = c->lexpr;
1366 c->lexpr = c->expr;
1367 c->expr = temp;
1368 DPRINTF(("Swaped left and right sides of constraint"));
1369 return c;
1370}
1371
c3e695ff 1372
1373
d46ce6a4 1374constraint constraint_simplify ( /*@returned@*/ constraint c)
616915dd 1375{
a779b61e 1376
1377 DPRINTF(( message("constraint_simplify on %q ", constraint_print(c) ) ));
1378
1379 if (constraint_tooDeep(c))
1380 {
1381 DPRINTF(( message("constraint_simplify: constraint to complex aborting %q ", constraint_print(c) ) ));
1382 return c;
1383
1384 }
1385
616915dd 1386 c->lexpr = constraintExpr_simplify (c->lexpr);
1387 c->expr = constraintExpr_simplify (c->expr);
616915dd 1388
bb25bea6 1389 if (constraintExpr_isBinaryExpr (c->lexpr) )
c3e695ff 1390 {
1391 c = constraint_solve (c);
1392
1393 c->lexpr = constraintExpr_simplify (c->lexpr);
1394 c->expr = constraintExpr_simplify (c->expr);
1395 }
1396
616915dd 1397 if (constraintExpr_isLit(c->lexpr) && (!constraintExpr_isLit(c->expr) ) )
1398 {
1399 c = constraint_swapLeftRight(c);
1400 /*I don't think this will be an infinate loop*/
84c9ffbf 1401 c = constraint_simplify(c);
616915dd 1402 }
a779b61e 1403
1404 DPRINTF(( message("constraint_simplify returning %q ", constraint_print(c) ) ));
1405
616915dd 1406 return c;
1407}
1408
1409
1410
1411
1412/* returns true if fileloc for term1 is closer to file for term2 than term3*/
1413
1414bool fileloc_closer (fileloc loc1, fileloc loc2, fileloc loc3)
1415{
c3e695ff 1416
1417 if (!fileloc_isDefined (loc1) )
1418 return FALSE;
1419
1420 if (!fileloc_isDefined (loc2) )
1421 return FALSE;
1422
1423 if (!fileloc_isDefined (loc3) )
1424 return TRUE;
1425
1426
1427
1428
1429 if (fileloc_equal (loc2, loc3) )
1430 return FALSE;
1431
1432 if (fileloc_equal (loc1, loc2) )
1433 return TRUE;
1434
1435 if (fileloc_equal (loc1, loc3) )
1436 return FALSE;
1437
616915dd 1438 if ( fileloc_lessthan (loc1, loc2) )
1439 {
1440 if (fileloc_lessthan (loc2, loc3) )
1441 {
1442 llassert (fileloc_lessthan (loc1, loc3) );
1443 return TRUE;
1444 }
1445 else
1446 {
1447 return FALSE;
1448 }
1449 }
1450
1451 if ( !fileloc_lessthan (loc1, loc2) )
1452 {
1453 if (!fileloc_lessthan (loc2, loc3) )
1454 {
1455 llassert (!fileloc_lessthan (loc1, loc3) );
1456 return TRUE;
1457 }
1458 else
1459 {
1460 return FALSE;
1461 }
1462 }
1463
1464 llassert(FALSE);
1465 return FALSE;
1466}
1467
1468
This page took 0.315093 seconds and 5 git commands to generate.