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