]>
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 | */ |
616915dd | 24 | |
25 | /* | |
26 | ** constraintGeneration.c | |
27 | */ | |
28 | ||
b7b694d6 | 29 | /* #define DEBUGPRINT 1 */ |
616915dd | 30 | |
31 | # include <ctype.h> /* for isdigit */ | |
1b8ae690 | 32 | # include "splintMacros.nf" |
616915dd | 33 | # include "basic.h" |
920a3797 | 34 | |
616915dd | 35 | # include "cgrammar_tokens.h" |
36 | ||
37 | # include "exprChecks.h" | |
616915dd | 38 | # include "exprNodeSList.h" |
39 | ||
965143f0 | 40 | /*drl We need to access the internal representation of exprNode |
41 | because these functions walk down the parse tree and need a richer | |
42 | information than is accessible through the exprNode interface.*/ | |
43 | ||
44 | /*@access exprNode@*/ | |
470b7798 | 45 | |
965143f0 | 46 | static /*@nullwhentrue@*/ bool exprNode_handleError (/*@temp@*/ exprNode p_e); |
616915dd | 47 | |
abd7f895 | 48 | static void exprNode_stmt (/*@temp@*/ /*@temp@*/ exprNode p_e); |
49 | static void exprNode_multiStatement (/*@temp@*/ exprNode p_e); | |
24633cea | 50 | |
ae133592 | 51 | static constraintList exprNode_traverseTrueEnsuresConstraints (/*@temp@*/ exprNode p_e); |
52 | static constraintList exprNode_traverseFalseEnsuresConstraints (/*@temp@*/ exprNode p_e); | |
616915dd | 53 | |
28bf4b0b | 54 | static void checkArgumentList (/*@out@*/ exprNode p_temp, exprNodeList p_arglist, fileloc p_sequencePoint) /*@modifies p_temp @*/; |
55 | ||
6317f163 | 56 | static constraintList checkCall (/*@temp@*/ exprNode p_fcn, exprNodeList p_arglist); |
4ab867d6 | 57 | |
abd7f895 | 58 | static bool exprNode_isUnhandled (/*@temp@*/ /*@observer@*/ exprNode e) |
616915dd | 59 | { |
abd7f895 | 60 | llassert(exprNode_isDefined(e)); |
616915dd | 61 | switch (e->kind) |
62 | { | |
63 | case XPR_INITBLOCK: | |
64 | case XPR_EMPTY: | |
65 | case XPR_LABEL: | |
66 | case XPR_CONST: | |
67 | case XPR_VAR: | |
68 | case XPR_BODY: | |
69 | case XPR_OFFSETOF: | |
70 | case XPR_ALIGNOFT: | |
71 | case XPR_ALIGNOF: | |
72 | case XPR_VAARG: | |
73 | case XPR_ITERCALL: | |
74 | case XPR_ITER: | |
616915dd | 75 | case XPR_GOTO: |
76 | case XPR_CONTINUE: | |
77 | case XPR_BREAK: | |
78 | case XPR_COMMA: | |
79 | case XPR_COND: | |
80 | case XPR_TOK: | |
81 | case XPR_FTDEFAULT: | |
82 | case XPR_DEFAULT: | |
616915dd | 83 | case XPR_FTCASE: |
84 | case XPR_CASE: | |
616915dd | 85 | case XPR_NODE: |
abd7f895 | 86 | DPRINTF((message ("Warning current constraint generation does not handle expression %s", exprNode_unparse(e)))); |
616915dd | 87 | return TRUE; |
88 | /*@notreached@*/ | |
89 | break; | |
90 | default: | |
91 | return FALSE; | |
92 | ||
93 | } | |
94 | /*not reached*/ | |
95 | return FALSE; | |
96 | } | |
97 | ||
965143f0 | 98 | /*@nullwhentrue@*/ bool exprNode_handleError (exprNode e) |
616915dd | 99 | { |
abd7f895 | 100 | if (exprNode_isError (e) || exprNode_isUnhandled (e)) |
616915dd | 101 | { |
abd7f895 | 102 | return TRUE; |
616915dd | 103 | } |
abd7f895 | 104 | |
616915dd | 105 | return FALSE; |
106 | } | |
107 | ||
abd7f895 | 108 | /* evans 2002-03-2 - parameter was dependent */ |
109 | bool /*@alt void@*/ exprNode_generateConstraints (/*@temp@*/ exprNode e) | |
616915dd | 110 | { |
abd7f895 | 111 | if (exprNode_isError (e)) |
616915dd | 112 | return FALSE; |
9280addf | 113 | |
abd7f895 | 114 | if (exprNode_isUnhandled (e)) |
616915dd | 115 | { |
abd7f895 | 116 | DPRINTF((message("Warning ignoring %s", exprNode_unparse (e)))); |
24633cea | 117 | return FALSE; |
616915dd | 118 | } |
119 | ||
ae133592 | 120 | DPRINTF ((message ("exprNode_generateConstraints Analyzing %s at %s", exprNode_unparse(e), |
121 | fileloc_unparse(exprNode_loc (e))))); | |
122 | ||
abd7f895 | 123 | if (exprNode_isMultiStatement (e)) |
616915dd | 124 | { |
125 | exprNode_multiStatement(e); | |
126 | } | |
127 | else | |
128 | { | |
ae133592 | 129 | /* fileloc loc; */ |
9280addf | 130 | |
ae133592 | 131 | /* loc = exprNode_getNextSequencePoint(e); */ |
132 | /* exprNode_exprTraverse(e, FALSE, FALSE, loc); */ | |
133 | ||
134 | /* fileloc_free(loc); */ | |
9280addf | 135 | |
24633cea | 136 | exprNode_stmt(e); |
616915dd | 137 | return FALSE; |
24633cea | 138 | |
616915dd | 139 | } |
140 | ||
141 | { | |
142 | constraintList c; | |
ae133592 | 143 | |
616915dd | 144 | c = constraintList_makeFixedArrayConstraints (e->uses); |
28bf4b0b | 145 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, c); |
bb25bea6 | 146 | constraintList_free(c); |
616915dd | 147 | } |
ae133592 | 148 | |
149 | DPRINTF ((message ("e->requiresConstraints %s", | |
150 | constraintList_unparseDetailed (e->requiresConstraints)))); | |
616915dd | 151 | return FALSE; |
616915dd | 152 | } |
153 | ||
abd7f895 | 154 | static void exprNode_stmt (/*@temp@*/ exprNode e) |
616915dd | 155 | { |
156 | exprNode snode; | |
157 | fileloc loc; | |
9280addf | 158 | |
ae133592 | 159 | DPRINTF (("Generating constraint for: %s", exprNode_unparse (e))); |
160 | ||
abd7f895 | 161 | if (exprNode_isError(e)) |
616915dd | 162 | { |
b7b694d6 | 163 | return; |
616915dd | 164 | } |
b7b694d6 | 165 | |
bb25bea6 | 166 | /*e->requiresConstraints = constraintList_makeNew(); |
167 | e->ensuresConstraints = constraintList_makeNew(); */ | |
ae133592 | 168 | |
169 | /*!! s = exprNode_unparse (e); */ | |
9280addf | 170 | |
616915dd | 171 | if (e->kind == XPR_INIT) |
172 | { | |
bb25bea6 | 173 | constraintList tempList; |
ae133592 | 174 | DPRINTF (("Init: %s ", exprNode_unparse (e))); |
175 | loc = exprNode_getNextSequencePoint (e); /* reduces to an expression */ | |
176 | DPRINTF (("Location: %s", fileloc_unparse (loc))); | |
177 | DPRINTF (("Ensures before: %s", constraintList_unparse (e->ensuresConstraints))); | |
84c9ffbf | 178 | exprNode_exprTraverse (e, FALSE, FALSE, loc); |
ae133592 | 179 | DPRINTF (("Ensures after: %s", constraintList_unparse (e->ensuresConstraints))); |
180 | DPRINTF (("After traversing...")); | |
bb25bea6 | 181 | fileloc_free(loc); |
ae133592 | 182 | |
bb25bea6 | 183 | tempList = e->requiresConstraints; |
ae133592 | 184 | DPRINTF (("Requires before: %s", constraintList_unparse (e->requiresConstraints))); |
185 | e->requiresConstraints = exprNode_traverseRequiresConstraints (e); | |
186 | DPRINTF (("Requires after: %s", constraintList_unparse (e->requiresConstraints))); | |
bb25bea6 | 187 | constraintList_free(tempList); |
188 | ||
189 | tempList = e->ensuresConstraints; | |
ae133592 | 190 | DPRINTF (("Ensures before: %s", constraintList_unparse (e->ensuresConstraints))); |
191 | e->ensuresConstraints = exprNode_traverseEnsuresConstraints(e); | |
192 | DPRINTF (("Ensures before: %s", constraintList_unparse (e->ensuresConstraints))); | |
bb25bea6 | 193 | constraintList_free(tempList); |
b7b694d6 | 194 | return; |
616915dd | 195 | } |
24633cea | 196 | |
197 | /*drl 2/13/002 patched bug so return statement will be checked*/ | |
198 | /*return is a stmt not not expression ...*/ | |
199 | if (e->kind == XPR_RETURN) | |
200 | { | |
201 | constraintList tempList; | |
202 | ||
203 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ | |
204 | ||
205 | exprNode_exprTraverse (exprData_getSingle (e->edata), FALSE, TRUE, loc); | |
206 | fileloc_free(loc); | |
207 | ||
208 | tempList = e->requiresConstraints; | |
ae133592 | 209 | e->requiresConstraints = exprNode_traverseRequiresConstraints(e); |
24633cea | 210 | constraintList_free(tempList); |
211 | } | |
616915dd | 212 | |
213 | if (e->kind != XPR_STMT) | |
214 | { | |
abd7f895 | 215 | DPRINTF (("Not Stmt")); |
216 | DPRINTF ((message ("%s ", exprNode_unparse (e)))); | |
b7e84605 | 217 | |
218 | if (exprNode_isMultiStatement (e)) | |
616915dd | 219 | { |
b7e84605 | 220 | exprNode_multiStatement (e); /* evans 2001-08-21: spurious return removed */ |
616915dd | 221 | } |
24633cea | 222 | else |
223 | { | |
224 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ | |
225 | ||
226 | exprNode_exprTraverse (e, FALSE, TRUE, loc); | |
227 | fileloc_free(loc); | |
228 | ||
229 | } | |
230 | return; | |
616915dd | 231 | } |
232 | ||
abd7f895 | 233 | DPRINTF (("Stmt")); |
234 | DPRINTF ((message ("%s ", exprNode_unparse (e)))); | |
616915dd | 235 | |
236 | snode = exprData_getUopNode (e->edata); | |
237 | ||
238 | /* could be stmt involving multiple statements: | |
239 | i.e. if, while for ect. | |
240 | */ | |
241 | ||
242 | if (exprNode_isMultiStatement (snode)) | |
243 | { | |
b7e84605 | 244 | exprNode_multiStatement (snode); |
84c9ffbf | 245 | (void) exprNode_copyConstraints (e, snode); |
246 | return; | |
616915dd | 247 | } |
248 | ||
249 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ | |
84c9ffbf | 250 | exprNode_exprTraverse (snode, FALSE, FALSE, loc); |
bb25bea6 | 251 | |
252 | fileloc_free(loc); | |
253 | ||
254 | constraintList_free (e->requiresConstraints); | |
ae133592 | 255 | e->requiresConstraints = exprNode_traverseRequiresConstraints(snode); |
bb25bea6 | 256 | |
257 | constraintList_free (e->ensuresConstraints); | |
ae133592 | 258 | e->ensuresConstraints = exprNode_traverseEnsuresConstraints(snode); |
259 | ||
bb7c2085 | 260 | DPRINTF ((message ("smtlist constraints are: pre: %s \n and \t post %s\n", |
9a48d98c | 261 | constraintList_unparse(e->requiresConstraints), |
262 | constraintList_unparse(e->ensuresConstraints)))); | |
bb25bea6 | 263 | |
b7b694d6 | 264 | return; |
616915dd | 265 | } |
266 | ||
28bf4b0b | 267 | static void exprNode_stmtList (/*@dependent@*/ exprNode e) |
616915dd | 268 | { |
269 | exprNode stmt1, stmt2; | |
abd7f895 | 270 | if (exprNode_isError (e)) |
616915dd | 271 | { |
b7b694d6 | 272 | return; |
616915dd | 273 | } |
274 | ||
bb25bea6 | 275 | /* |
b7b694d6 | 276 | Handle case of stmtList with only one statement: |
277 | The parse tree stores this as stmt instead of stmtList | |
bb25bea6 | 278 | */ |
b7b694d6 | 279 | |
616915dd | 280 | if (e->kind != XPR_STMTLIST) |
281 | { | |
84c9ffbf | 282 | exprNode_stmt(e); |
283 | return; | |
616915dd | 284 | } |
285 | llassert (e->kind == XPR_STMTLIST); | |
abd7f895 | 286 | DPRINTF(("exprNode_stmtList STMTLIST:")); |
287 | DPRINTF ((cstring_toCharsSafe (exprNode_unparse(e)))); | |
616915dd | 288 | stmt1 = exprData_getPairA (e->edata); |
289 | stmt2 = exprData_getPairB (e->edata); | |
290 | ||
291 | ||
abd7f895 | 292 | DPRINTF(("exprNode_stmtlist ")); |
293 | DPRINTF ((message("XW%s | %s", exprNode_unparse(stmt1), exprNode_unparse(stmt2)))); | |
616915dd | 294 | |
295 | exprNode_stmt (stmt1); | |
abd7f895 | 296 | DPRINTF(("\nstmt after stmtList call ")); |
616915dd | 297 | |
298 | exprNode_stmt (stmt2); | |
abd7f895 | 299 | exprNode_mergeResolve (e, stmt1, stmt2); |
616915dd | 300 | |
bb7c2085 | 301 | DPRINTF ((message ("smtlist constraints are: pre: %s \n and \t post %s\n", |
9a48d98c | 302 | constraintList_unparse(e->requiresConstraints), |
303 | constraintList_unparse(e->ensuresConstraints)))); | |
b7b694d6 | 304 | return; |
a8e557d3 | 305 | } |
306 | ||
28bf4b0b | 307 | static exprNode doIf (/*@returned@*/ exprNode e, /*@dependent@*/ exprNode test, /*@dependent@*/ exprNode body) |
616915dd | 308 | { |
bb25bea6 | 309 | constraintList temp; |
310 | ||
abd7f895 | 311 | DPRINTF ((message ("doIf: %s ", exprNode_unparse(e)))); |
470b7798 | 312 | |
ae133592 | 313 | llassert (exprNode_isDefined(test)); |
abd7f895 | 314 | llassert (exprNode_isDefined (e)); |
315 | llassert (exprNode_isDefined (body)); | |
bb25bea6 | 316 | |
ae133592 | 317 | DPRINTF((message ("ensures constraints for %s are %s", exprNode_unparse(e), constraintList_unparseDetailed(e->ensuresConstraints)))); |
bb25bea6 | 318 | |
9a48d98c | 319 | DPRINTF((message ("Requires constraints for %s are %s", exprNode_unparse(e), constraintList_unparseDetailed(e->ensuresConstraints)))); |
bb25bea6 | 320 | |
9a48d98c | 321 | DPRINTF((message ("trueEnsures constraints for %s are %s", exprNode_unparse(e), constraintList_unparseDetailed(e->trueEnsuresConstraints)))); |
bb25bea6 | 322 | |
9a48d98c | 323 | DPRINTF((message ("falseEnsures constraints for %s are %s", exprNode_unparse(e), constraintList_unparseDetailed(e->falseEnsuresConstraints)))); |
bb25bea6 | 324 | |
325 | ||
326 | ||
9a48d98c | 327 | DPRINTF((message ("ensures constraints for %s are %s", exprNode_unparse(test), constraintList_unparseDetailed(test->ensuresConstraints)))); |
bb25bea6 | 328 | |
9a48d98c | 329 | DPRINTF((message ("Requires constraints for %s are %s", exprNode_unparse(test), constraintList_unparseDetailed(test->ensuresConstraints)))); |
bb25bea6 | 330 | |
9a48d98c | 331 | DPRINTF((message ("trueEnsures constraints for %s are %s", exprNode_unparse(test), constraintList_unparseDetailed(test->trueEnsuresConstraints)))); |
bb25bea6 | 332 | |
9a48d98c | 333 | DPRINTF((message ("falseEnsures constraints for %s are %s", exprNode_unparse(test), constraintList_unparseDetailed(test->falseEnsuresConstraints)))); |
bb25bea6 | 334 | |
335 | ||
336 | ||
337 | temp = test->trueEnsuresConstraints; | |
ae133592 | 338 | test->trueEnsuresConstraints = exprNode_traverseTrueEnsuresConstraints(test); |
bb25bea6 | 339 | constraintList_free(temp); |
340 | ||
341 | temp = test->ensuresConstraints; | |
ae133592 | 342 | test->ensuresConstraints = exprNode_traverseEnsuresConstraints (test); |
bb25bea6 | 343 | constraintList_free(temp); |
344 | ||
345 | temp = test->requiresConstraints; | |
ae133592 | 346 | test->requiresConstraints = exprNode_traverseRequiresConstraints (test); |
bb25bea6 | 347 | constraintList_free(temp); |
616915dd | 348 | |
bb25bea6 | 349 | |
350 | test->trueEnsuresConstraints = constraintList_substituteFreeTarget(test->trueEnsuresConstraints, test->ensuresConstraints); | |
c3e695ff | 351 | |
9a48d98c | 352 | DPRINTF ((message ("doIf: test ensures %s ", constraintList_unparse(test->ensuresConstraints)))); |
c3e695ff | 353 | |
9a48d98c | 354 | DPRINTF ((message ("doIf: test true ensures %s ", constraintList_unparse(test->trueEnsuresConstraints)))); |
bb25bea6 | 355 | |
356 | constraintList_free(e->requiresConstraints); | |
dc7f6a51 | 357 | |
358 | ||
28bf4b0b | 359 | e->requiresConstraints = constraintList_reflectChanges(body->requiresConstraints, test->trueEnsuresConstraints); |
bb25bea6 | 360 | |
28bf4b0b | 361 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, |
616915dd | 362 | test->ensuresConstraints); |
bb25bea6 | 363 | temp = e->requiresConstraints; |
470b7798 | 364 | e->requiresConstraints = constraintList_mergeRequires (e->requiresConstraints, test->requiresConstraints); |
bb25bea6 | 365 | constraintList_free(temp); |
366 | ||
367 | ||
b7b694d6 | 368 | /* drl possible problem : warning bad */ |
bb25bea6 | 369 | constraintList_free(e->ensuresConstraints); |
616915dd | 370 | e->ensuresConstraints = constraintList_copy (test->ensuresConstraints); |
90bc41f7 | 371 | |
abd7f895 | 372 | if (exprNode_mayEscape (body)) |
90bc41f7 | 373 | { |
abd7f895 | 374 | DPRINTF ((message("doIf: the if statement body %s returns or exits", exprNode_unparse(body)))); |
bb25bea6 | 375 | e->ensuresConstraints = constraintList_mergeEnsuresFreeFirst (e->ensuresConstraints, |
470b7798 | 376 | test->falseEnsuresConstraints); |
90bc41f7 | 377 | } |
378 | ||
9a48d98c | 379 | DPRINTF ((message ("doIf: if requiers %s ", constraintList_unparse(e->requiresConstraints)))); |
9280addf | 380 | |
616915dd | 381 | return e; |
382 | } | |
383 | ||
470b7798 | 384 | /*drl added 3/4/2001 |
385 | Also used for condition i.e. ?: operation | |
386 | ||
387 | Precondition | |
388 | This function assumes that p, trueBranch, falseBranch have have all been traversed | |
ae133592 | 389 | for constraints i.e. we assume that exprNode_traverseEnsuresConstraints, |
390 | exprNode_traverseRequiresConstraints, exprNode_traverseTrueEnsuresConstraints, | |
391 | exprNode_traverseFalseEnsuresConstraints have all been run | |
470b7798 | 392 | */ |
393 | ||
28bf4b0b | 394 | static exprNode doIfElse (/*@returned@*/ exprNode e, /*@dependent@*/ exprNode p, /*@dependent@*/ exprNode trueBranch, /*@dependent@*/ exprNode falseBranch) |
470b7798 | 395 | { |
b7b694d6 | 396 | constraintList c1, cons, t, t2, f, f2; |
470b7798 | 397 | |
abd7f895 | 398 | llassert (exprNode_isDefined (e)); |
399 | llassert (exprNode_isDefined (p)); | |
400 | llassert (exprNode_isDefined (trueBranch)); | |
401 | llassert (exprNode_isDefined (falseBranch)); | |
402 | DPRINTF ((message ("doIfElse: %s ", exprNode_unparse(e)))); | |
b7b694d6 | 403 | |
404 | /* do requires clauses */ | |
405 | c1 = constraintList_copy (p->ensuresConstraints); | |
406 | ||
407 | t = constraintList_reflectChanges(trueBranch->requiresConstraints, p->trueEnsuresConstraints); | |
408 | t = constraintList_reflectChangesFreePre (t, p->ensuresConstraints); | |
409 | ||
410 | cons = constraintList_reflectChanges(falseBranch->requiresConstraints, p->falseEnsuresConstraints); | |
411 | cons = constraintList_reflectChangesFreePre (cons, c1); | |
412 | ||
abd7f895 | 413 | constraintList_free (e->requiresConstraints); |
b7b694d6 | 414 | e->requiresConstraints = constraintList_mergeRequiresFreeFirst (t, cons); |
415 | e->requiresConstraints = constraintList_mergeRequiresFreeFirst (e->requiresConstraints, p->requiresConstraints); | |
416 | ||
417 | /* do ensures clauses | |
418 | find the the ensures lists for each subbranch | |
419 | */ | |
bb25bea6 | 420 | |
b7b694d6 | 421 | t = constraintList_mergeEnsures (p->trueEnsuresConstraints, trueBranch->ensuresConstraints); |
422 | t2 = t; | |
423 | t = constraintList_mergeEnsures (p->ensuresConstraints, t); | |
424 | constraintList_free(t2); | |
425 | ||
426 | f = constraintList_mergeEnsures (p->falseEnsuresConstraints, falseBranch->ensuresConstraints); | |
427 | f2 = f; | |
428 | f = constraintList_mergeEnsures (p->ensuresConstraints, f); | |
429 | constraintList_free(f2); | |
430 | ||
431 | /* find ensures for whole if/else statement */ | |
432 | ||
433 | constraintList_free(e->ensuresConstraints); | |
434 | ||
435 | e->ensuresConstraints = constraintList_logicalOr (t, f); | |
436 | ||
437 | constraintList_free(t); | |
438 | constraintList_free(f); | |
439 | constraintList_free(cons); | |
440 | constraintList_free(c1); | |
441 | ||
9a48d98c | 442 | DPRINTF ((message ("doIfElse: if requires %q ", constraintList_unparse(e->requiresConstraints)))); |
443 | DPRINTF ((message ("doIfElse: if ensures %q ", constraintList_unparse(e->ensuresConstraints)))); | |
b7b694d6 | 444 | |
445 | return e; | |
470b7798 | 446 | } |
9280addf | 447 | |
28bf4b0b | 448 | static exprNode doWhile (/*@returned@*/ exprNode e, /*@dependent@*/ exprNode test, /*@dependent@*/ exprNode body) |
9280addf | 449 | { |
abd7f895 | 450 | DPRINTF ((message ("doWhile: %s ", exprNode_unparse(e)))); |
9280addf | 451 | return doIf (e, test, body); |
452 | } | |
453 | ||
920a3797 | 454 | /*@only@*/ constraintList constraintList_makeFixedArrayConstraints (/*@observer@*/ sRefSet s) |
616915dd | 455 | { |
456 | constraintList ret; | |
470b7798 | 457 | constraint con; |
c3e695ff | 458 | ret = constraintList_makeNew(); |
616915dd | 459 | |
460 | sRefSet_elements (s, el) | |
461 | { | |
abd7f895 | 462 | if (sRef_isFixedArray(el)) |
b7b694d6 | 463 | { |
37ae0b5e | 464 | size_t size; |
bb7c2085 | 465 | DPRINTF((message("%s is a fixed array", |
abd7f895 | 466 | sRef_unparse(el)))); |
b7b694d6 | 467 | size = sRef_getArraySize(el); |
bb7c2085 | 468 | DPRINTF((message("%s is a fixed array with size %d", |
abd7f895 | 469 | sRef_unparse(el), (int)size))); |
e5081f8c | 470 | con = constraint_makeSRefSetBufferSize (el, size_toLong (size - 1)); |
b7b694d6 | 471 | ret = constraintList_add(ret, con); |
472 | } | |
473 | else | |
474 | { | |
bb7c2085 | 475 | DPRINTF((message("%s is not a fixed array", |
abd7f895 | 476 | sRef_unparse(el)))); |
b7b694d6 | 477 | |
478 | ||
abd7f895 | 479 | if (sRef_isExternallyVisible (el)) |
b7b694d6 | 480 | { |
481 | /* | |
bb7c2085 | 482 | DPRINTF((message("%s is externally visible", |
abd7f895 | 483 | sRef_unparse(el)))); |
b7b694d6 | 484 | con = constraint_makeSRefWriteSafeInt(el, 0); |
485 | ret = constraintList_add(ret, con); | |
486 | ||
487 | con = constraint_makeSRefReadSafeInt(el, 0); | |
488 | ||
489 | ret = constraintList_add(ret, con); | |
490 | */ | |
491 | } | |
492 | } | |
616915dd | 493 | } |
b7b694d6 | 494 | end_sRefSet_elements ; |
495 | ||
abd7f895 | 496 | DPRINTF((message("constraintList_makeFixedArrayConstraints returning %s", |
9a48d98c | 497 | constraintList_unparse(ret)))); |
b7b694d6 | 498 | return ret; |
616915dd | 499 | } |
500 | ||
b7b694d6 | 501 | # if 0 |
4ab867d6 | 502 | exprNode makeDataTypeConstraints (/*@returned@*/ exprNode e) |
616915dd | 503 | { |
504 | constraintList c; | |
505 | DPRINTF(("makeDataTypeConstraints")); | |
506 | ||
507 | c = constraintList_makeFixedArrayConstraints (e->uses); | |
508 | ||
4ab867d6 | 509 | e->ensuresConstraints = constraintList_addListFree (e->ensuresConstraints, c); |
616915dd | 510 | |
511 | return e; | |
512 | } | |
b7b694d6 | 513 | # endif |
616915dd | 514 | |
28bf4b0b | 515 | static void doFor (/*@dependent@*/ exprNode e, /*@dependent@*/ exprNode forPred, /*@dependent@*/ exprNode forBody) |
616915dd | 516 | { |
517 | exprNode init, test, inc; | |
b7b694d6 | 518 | /* merge the constraints: modle as if statement */ |
519 | ||
abd7f895 | 520 | /* init |
521 | if (test) | |
522 | for body | |
523 | inc */ | |
b7b694d6 | 524 | |
abd7f895 | 525 | llassert (exprNode_isDefined (e)); |
526 | llassert (exprNode_isDefined (forPred)); | |
527 | llassert (exprNode_isDefined (forBody)); | |
528 | ||
529 | init = exprData_getTripleInit (forPred->edata); | |
530 | test = exprData_getTripleTest (forPred->edata); | |
531 | inc = exprData_getTripleInc (forPred->edata); | |
532 | ||
533 | if (((exprNode_isError (test) /*|| (exprNode_isError(init))*/) || (exprNode_isError (inc)))) | |
b7b694d6 | 534 | { |
abd7f895 | 535 | DPRINTF ((message ("strange for statement:%s, ignoring it", exprNode_unparse(e)))); |
b7b694d6 | 536 | return; |
537 | } | |
538 | ||
539 | exprNode_forLoopHeuristics(e, forPred, forBody); | |
540 | ||
541 | constraintList_free(e->requiresConstraints); | |
542 | e->requiresConstraints = constraintList_reflectChanges(forBody->requiresConstraints, test->ensuresConstraints); | |
543 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, test->trueEnsuresConstraints); | |
544 | e->requiresConstraints = constraintList_reflectChangesFreePre (e->requiresConstraints, forPred->ensuresConstraints); | |
545 | ||
546 | if (!forBody->canBreak) | |
547 | { | |
abd7f895 | 548 | e->ensuresConstraints = constraintList_addListFree(e->ensuresConstraints, constraintList_copy(forPred->ensuresConstraints)); |
549 | e->ensuresConstraints = constraintList_addListFree(e->ensuresConstraints,constraintList_copy(test->falseEnsuresConstraints)); | |
b7b694d6 | 550 | } |
551 | else | |
552 | { | |
abd7f895 | 553 | DPRINTF(("Can break")); |
b7b694d6 | 554 | } |
616915dd | 555 | } |
556 | ||
03d670b6 | 557 | static /*@dependent@*/ exprNode exprNode_makeDependent(/*@returned@*/ exprNode e) |
558 | { | |
393e573f | 559 | /* !!! DRL - this is ridiculous! Read the manual on memory annotations please! */ |
03d670b6 | 560 | return e; |
03d670b6 | 561 | } |
562 | ||
3e3ec469 | 563 | static void |
564 | exprNode_doGenerateConstraintSwitch | |
565 | (/*@dependent@*/ exprNode switchExpr, | |
566 | /*@dependent@*/ exprNode body, | |
567 | /*@special@*/ constraintList *currentRequires, | |
568 | /*@special@*/ constraintList *currentEnsures, | |
569 | /*@special@*/ constraintList *savedRequires, | |
570 | /*@special@*/ constraintList *savedEnsures) | |
571 | /*@post:only *currentRequires, *currentEnsures, *savedRequires, *savedEnsures @*/ | |
572 | /*@sets *currentRequires, *currentEnsures, *savedRequires, *savedEnsures @*/ | |
7c9c4a67 | 573 | { |
574 | exprNode stmt, stmtList; | |
575 | ||
abd7f895 | 576 | DPRINTF((message("exprNode_doGenerateConstraintSwitch: (switch %s) %s", |
7c9c4a67 | 577 | exprNode_unparse(switchExpr), exprNode_unparse(body) |
abd7f895 | 578 | ))); |
7c9c4a67 | 579 | |
abd7f895 | 580 | if (exprNode_isError(body)) |
7c9c4a67 | 581 | { |
3e3ec469 | 582 | *currentRequires = constraintList_makeNew (); |
583 | *currentEnsures = constraintList_makeNew (); | |
03d670b6 | 584 | |
3e3ec469 | 585 | *savedRequires = constraintList_makeNew (); |
586 | *savedEnsures = constraintList_makeNew (); | |
03d670b6 | 587 | /*@-onlytrans@*/ |
7c9c4a67 | 588 | return; |
03d670b6 | 589 | /*@=onlytrans@*/ |
7c9c4a67 | 590 | } |
591 | ||
abd7f895 | 592 | if (body->kind != XPR_STMTLIST) |
7c9c4a67 | 593 | { |
dc7f6a51 | 594 | DPRINTF((message("exprNode_doGenerateConstraintSwitch: non stmtlist: %s", |
abd7f895 | 595 | exprNode_unparse(body)))); |
7c9c4a67 | 596 | stmt = body; |
597 | stmtList = exprNode_undefined; | |
03d670b6 | 598 | stmt = exprNode_makeDependent(stmt); |
599 | stmtList = exprNode_makeDependent(stmtList); | |
600 | } | |
601 | else | |
602 | { | |
603 | stmt = exprData_getPairB(body->edata); | |
604 | stmtList = exprData_getPairA(body->edata); | |
605 | stmt = exprNode_makeDependent(stmt); | |
606 | stmtList = exprNode_makeDependent(stmtList); | |
7c9c4a67 | 607 | } |
7c9c4a67 | 608 | |
dc7f6a51 | 609 | DPRINTF((message("exprNode_doGenerateConstraintSwitch: stmtlist: %s stmt: %s", |
abd7f895 | 610 | exprNode_unparse(stmtList), exprNode_unparse(stmt)) |
611 | )); | |
7c9c4a67 | 612 | |
613 | ||
614 | exprNode_doGenerateConstraintSwitch (switchExpr, stmtList, currentRequires, currentEnsures, | |
abd7f895 | 615 | savedRequires, savedEnsures); |
7c9c4a67 | 616 | |
abd7f895 | 617 | if (exprNode_isError(stmt)) |
03d670b6 | 618 | /*@-onlytrans@*/ |
7c9c4a67 | 619 | return; |
03d670b6 | 620 | /*@=onlytrans@*/ |
7c9c4a67 | 621 | |
622 | exprNode_stmt(stmt); | |
03d670b6 | 623 | |
624 | switchExpr = exprNode_makeDependent (switchExpr); | |
625 | ||
abd7f895 | 626 | if (! exprNode_isCaseMarker(stmt)) |
7c9c4a67 | 627 | { |
628 | ||
629 | constraintList temp; | |
630 | ||
abd7f895 | 631 | DPRINTF ((message("Got normal statement %s (requires %s ensures %s)", exprNode_unparse(stmt), |
632 | constraintList_unparse(stmt->requiresConstraints), constraintList_unparse(stmt->ensuresConstraints)))); | |
7c9c4a67 | 633 | |
634 | temp = constraintList_reflectChanges (stmt->requiresConstraints, | |
635 | *currentEnsures); | |
636 | ||
03d670b6 | 637 | *currentRequires = constraintList_mergeRequiresFreeFirst( |
638 | *currentRequires, | |
639 | temp); | |
7c9c4a67 | 640 | |
641 | constraintList_free(temp); | |
642 | ||
643 | *currentEnsures = constraintList_mergeEnsuresFreeFirst | |
644 | (*currentEnsures, | |
645 | stmt->ensuresConstraints); | |
abd7f895 | 646 | DPRINTF((message("returning from exprNode_doGenerateConstraintSwitch: (switch %s) %s currentRequires:" |
7c9c4a67 | 647 | "%s currentEnsures:%s", |
648 | exprNode_unparse(switchExpr), exprNode_unparse(body), | |
9a48d98c | 649 | constraintList_unparse(*currentRequires), constraintList_unparse(*currentEnsures) |
abd7f895 | 650 | ))); |
03d670b6 | 651 | /*@-onlytrans@*/ |
7c9c4a67 | 652 | return; |
03d670b6 | 653 | /*@=onlytrans@*/ |
654 | ||
7c9c4a67 | 655 | } |
656 | ||
abd7f895 | 657 | if (exprNode_isCaseMarker(stmt) && exprNode_mustEscape(stmtList)) |
7c9c4a67 | 658 | { |
b7b694d6 | 659 | /* |
660 | ** merge current and saved constraint with Logical Or... | |
661 | ** make a constraint for ensures | |
662 | */ | |
7c9c4a67 | 663 | |
664 | constraintList temp; | |
665 | constraint con; | |
666 | ||
abd7f895 | 667 | DPRINTF ((message("Got case marker"))); |
7c9c4a67 | 668 | |
669 | if (constraintList_isUndefined(*savedEnsures) && | |
abd7f895 | 670 | constraintList_isUndefined(*savedRequires)) |
7c9c4a67 | 671 | { |
abd7f895 | 672 | llassert(constraintList_isUndefined(*savedEnsures)); |
673 | llassert(constraintList_isUndefined(*savedRequires)); | |
7c9c4a67 | 674 | *savedEnsures = constraintList_copy(*currentEnsures); |
675 | *savedRequires = constraintList_copy(*currentRequires); | |
676 | } | |
03d670b6 | 677 | else |
678 | { | |
abd7f895 | 679 | DPRINTF ((message("Doing logical or"))); |
03d670b6 | 680 | temp = constraintList_logicalOr (*savedEnsures, *currentEnsures); |
681 | constraintList_free (*savedEnsures); | |
682 | *savedEnsures = temp; | |
683 | ||
684 | *savedRequires = constraintList_mergeRequiresFreeFirst (*savedRequires, *currentRequires); | |
685 | } | |
686 | ||
517a2db3 | 687 | con = constraint_makeEnsureEqual (switchExpr, exprData_getSingle (stmt->edata), exprNode_loc (stmt)); |
7c9c4a67 | 688 | |
517a2db3 | 689 | constraintList_free (*currentEnsures); |
7c9c4a67 | 690 | *currentEnsures = constraintList_makeNew(); |
691 | *currentEnsures = constraintList_add(*currentEnsures, con); | |
692 | ||
693 | constraintList_free(*currentRequires); | |
694 | *currentRequires = constraintList_makeNew(); | |
517a2db3 | 695 | DPRINTF (("exprNode_doGenerateConstraintSwitch: (switch %s) %s savedRequires:" |
696 | "%s savedEnsures:%s", | |
697 | exprNode_unparse(switchExpr), exprNode_unparse(body), | |
698 | constraintList_unparse(*savedRequires), constraintList_unparse(*savedEnsures) | |
699 | )); | |
7c9c4a67 | 700 | } |
517a2db3 | 701 | else if (exprNode_isCaseMarker(stmt)) /* prior case has no break. */ |
7c9c4a67 | 702 | { |
b7b694d6 | 703 | /* |
704 | We don't do anything to the sved constraints because the case hasn't ended | |
705 | The new ensures constraints for the case will be: | |
706 | the constraint for the case statement (CASE_LABEL == SWITCH_EXPR) logicalOr currentEnsures | |
707 | */ | |
708 | ||
7c9c4a67 | 709 | constraintList temp; |
710 | constraint con; | |
7c9c4a67 | 711 | constraintList ensuresTemp; |
712 | ||
517a2db3 | 713 | con = constraint_makeEnsureEqual (switchExpr, exprData_getSingle (stmt->edata), exprNode_loc (stmt)); |
714 | ||
715 | ensuresTemp = constraintList_makeNew (); | |
7c9c4a67 | 716 | ensuresTemp = constraintList_add (ensuresTemp, con); |
717 | ||
517a2db3 | 718 | if (exprNode_isError (stmtList)) |
7c9c4a67 | 719 | { |
517a2db3 | 720 | constraintList_free (*currentEnsures); |
721 | *currentEnsures = constraintList_copy (ensuresTemp); | |
722 | constraintList_free (ensuresTemp); | |
03d670b6 | 723 | } |
724 | else | |
725 | { | |
03d670b6 | 726 | temp = constraintList_logicalOr (*currentEnsures, ensuresTemp); |
517a2db3 | 727 | constraintList_free (*currentEnsures); |
728 | constraintList_free (ensuresTemp); | |
03d670b6 | 729 | *currentEnsures = temp; |
730 | } | |
517a2db3 | 731 | |
732 | constraintList_free (*currentRequires); | |
7c9c4a67 | 733 | *currentRequires = constraintList_makeNew(); |
734 | } | |
03d670b6 | 735 | else |
736 | { | |
b7b694d6 | 737 | /* |
738 | we handle the case of ! exprNode_isCaseMarker above | |
739 | the else if clause should always be true. | |
740 | */ | |
03d670b6 | 741 | BADEXIT; |
742 | } | |
7c9c4a67 | 743 | |
517a2db3 | 744 | DPRINTF (("returning from exprNode_doGenerateConstraintSwitch: (switch %s) %s currentRequires:" |
745 | "%s currentEnsures:%s", | |
746 | exprNode_unparse(switchExpr), exprNode_unparse(body), | |
747 | constraintList_unparse(*currentRequires), constraintList_unparse(*currentEnsures) | |
748 | )); | |
749 | ||
03d670b6 | 750 | /*@-onlytrans@*/ |
7c9c4a67 | 751 | return; |
03d670b6 | 752 | /*@=onlytrans@*/ |
7c9c4a67 | 753 | } |
754 | ||
755 | ||
abd7f895 | 756 | static void exprNode_generateConstraintSwitch (/*@notnull@*/ exprNode switchStmt) |
7c9c4a67 | 757 | { |
758 | constraintList constraintsRequires; | |
759 | constraintList constraintsEnsures; | |
760 | constraintList lastRequires; | |
761 | constraintList lastEnsures; | |
762 | ||
763 | exprNode body; | |
764 | exprNode switchExpr; | |
765 | ||
abd7f895 | 766 | switchExpr = exprData_getPairA (switchStmt->edata); |
767 | body = exprData_getPairB (switchStmt->edata); | |
768 | ||
769 | if (!exprNode_isDefined (body)) | |
770 | { | |
771 | return; | |
772 | } | |
7c9c4a67 | 773 | |
abd7f895 | 774 | DPRINTF((message(""))); |
a779b61e | 775 | |
abd7f895 | 776 | if (body->kind == XPR_BLOCK) |
7c9c4a67 | 777 | body = exprData_getSingle(body->edata); |
778 | ||
b941db6b | 779 | |
7c9c4a67 | 780 | constraintsRequires = constraintList_undefined; |
781 | constraintsEnsures = constraintList_undefined; | |
782 | ||
783 | lastRequires = constraintList_makeNew(); | |
784 | lastEnsures = constraintList_makeNew(); | |
b941db6b | 785 | |
7c9c4a67 | 786 | |
3e3ec469 | 787 | /*@-mustfree@*/ |
b73d1009 | 788 | /* evans 2002-01-01: spurious warnings for these becuase of stack allocated storage */ |
3e3ec469 | 789 | exprNode_doGenerateConstraintSwitch (switchExpr, body, &lastRequires, |
790 | &lastEnsures, &constraintsRequires, &constraintsEnsures); | |
791 | /*@=mustfree@*/ | |
7c9c4a67 | 792 | |
b7b694d6 | 793 | /* |
794 | merge current and saved constraint with Logical Or... | |
795 | make a constraint for ensures | |
796 | */ | |
7c9c4a67 | 797 | |
798 | constraintList_free(switchStmt->requiresConstraints); | |
799 | constraintList_free(switchStmt->ensuresConstraints); | |
800 | ||
abd7f895 | 801 | if (constraintList_isDefined(constraintsEnsures) && constraintList_isDefined(constraintsRequires)) |
7c9c4a67 | 802 | { |
803 | switchStmt->ensuresConstraints = constraintList_logicalOr(constraintsEnsures, lastEnsures); | |
804 | switchStmt->requiresConstraints = constraintList_mergeRequires(constraintsRequires, lastRequires); | |
805 | constraintList_free (constraintsRequires); | |
806 | constraintList_free (constraintsEnsures); | |
807 | } | |
03d670b6 | 808 | else |
809 | { | |
810 | switchStmt->ensuresConstraints = constraintList_copy(lastEnsures); | |
811 | switchStmt->requiresConstraints = constraintList_copy(lastRequires); | |
812 | } | |
7c9c4a67 | 813 | |
814 | constraintList_free (lastRequires); | |
815 | constraintList_free (lastEnsures); | |
816 | ||
bb7c2085 | 817 | DPRINTF(((message(" exprNode_generateConstraintSwitch returning requires: %s and ensures %s", |
9a48d98c | 818 | constraintList_unparse(switchStmt->requiresConstraints), |
819 | constraintList_unparse(switchStmt->ensuresConstraints) | |
abd7f895 | 820 | ) |
821 | ))); | |
7c9c4a67 | 822 | } |
823 | ||
abd7f895 | 824 | static exprNode doSwitch (/*@returned@*/ /*@notnull@*/ exprNode e) |
470b7798 | 825 | { |
826 | exprNode body; | |
827 | exprData data; | |
828 | ||
829 | data = e->edata; | |
abd7f895 | 830 | DPRINTF ((message ("doSwitch for: switch (%s) %s", |
2681ee39 | 831 | exprNode_unparse (exprData_getPairA (data)), |
abd7f895 | 832 | exprNode_unparse (exprData_getPairB (data))))); |
7c9c4a67 | 833 | |
470b7798 | 834 | body = exprData_getPairB (data); |
7c9c4a67 | 835 | exprNode_generateConstraintSwitch (e); |
470b7798 | 836 | return e; |
837 | } | |
9280addf | 838 | |
28bf4b0b | 839 | void exprNode_multiStatement (/*@dependent@*/ exprNode e) |
616915dd | 840 | { |
841 | ||
842 | bool ret; | |
843 | exprData data; | |
844 | exprNode e1, e2; | |
845 | exprNode p, trueBranch, falseBranch; | |
846 | exprNode forPred, forBody; | |
470b7798 | 847 | exprNode test; |
bb25bea6 | 848 | |
849 | constraintList temp; | |
850 | ||
abd7f895 | 851 | DPRINTF((message ("exprNode_multistatement Analysising %s %s at", exprNode_unparse(e), |
852 | fileloc_unparse(exprNode_getfileloc(e))))); | |
616915dd | 853 | |
854 | if (exprNode_handleError (e)) | |
855 | { | |
b7b694d6 | 856 | return; |
616915dd | 857 | } |
858 | ||
859 | data = e->edata; | |
860 | ||
861 | ret = TRUE; | |
862 | ||
863 | switch (e->kind) | |
864 | { | |
865 | ||
866 | case XPR_FOR: | |
616915dd | 867 | forPred = exprData_getPairA (data); |
868 | forBody = exprData_getPairB (data); | |
869 | ||
b7b694d6 | 870 | /* First generate the constraints */ |
616915dd | 871 | exprNode_generateConstraints (forPred); |
872 | exprNode_generateConstraints (forBody); | |
873 | ||
874 | ||
875 | doFor (e, forPred, forBody); | |
876 | ||
877 | break; | |
878 | ||
879 | case XPR_FORPRED: | |
abd7f895 | 880 | exprNode_generateConstraints (exprData_getTripleInit (data)); |
616915dd | 881 | test = exprData_getTripleTest (data); |
882 | exprNode_exprTraverse (test,FALSE, FALSE, exprNode_loc(e)); | |
abd7f895 | 883 | exprNode_generateConstraints (exprData_getTripleInc (data)); |
9280addf | 884 | |
abd7f895 | 885 | if (!exprNode_isError(test)) |
bb25bea6 | 886 | { |
887 | constraintList temp2; | |
888 | temp2 = test->trueEnsuresConstraints; | |
ae133592 | 889 | test->trueEnsuresConstraints = exprNode_traverseTrueEnsuresConstraints(test); |
bb25bea6 | 890 | constraintList_free(temp2); |
891 | } | |
892 | ||
616915dd | 893 | exprNode_generateConstraints (exprData_getTripleInc (data)); |
894 | break; | |
9280addf | 895 | |
896 | case XPR_WHILE: | |
897 | e1 = exprData_getPairA (data); | |
898 | e2 = exprData_getPairB (data); | |
899 | ||
900 | exprNode_exprTraverse (e1, | |
901 | FALSE, FALSE, exprNode_loc(e1)); | |
902 | ||
903 | exprNode_generateConstraints (e2); | |
904 | ||
905 | e = doWhile (e, e1, e2); | |
906 | ||
907 | break; | |
908 | ||
616915dd | 909 | case XPR_IF: |
abd7f895 | 910 | DPRINTF(("IF:")); |
911 | DPRINTF ((exprNode_unparse(e))); | |
616915dd | 912 | e1 = exprData_getPairA (data); |
913 | e2 = exprData_getPairB (data); | |
914 | ||
b7b694d6 | 915 | exprNode_exprTraverse (e1, FALSE, FALSE, exprNode_loc(e1)); |
616915dd | 916 | |
917 | exprNode_generateConstraints (e2); | |
616915dd | 918 | e = doIf (e, e1, e2); |
616915dd | 919 | break; |
9280addf | 920 | |
616915dd | 921 | case XPR_IFELSE: |
922 | DPRINTF(("Starting IFELSE")); | |
616915dd | 923 | p = exprData_getTriplePred (data); |
abd7f895 | 924 | |
616915dd | 925 | trueBranch = exprData_getTripleTrue (data); |
926 | falseBranch = exprData_getTripleFalse (data); | |
927 | ||
928 | exprNode_exprTraverse (p, | |
929 | FALSE, FALSE, exprNode_loc(p)); | |
930 | exprNode_generateConstraints (trueBranch); | |
931 | exprNode_generateConstraints (falseBranch); | |
932 | ||
abd7f895 | 933 | llassert (exprNode_isDefined (p)); |
bb25bea6 | 934 | temp = p->ensuresConstraints; |
ae133592 | 935 | p->ensuresConstraints = exprNode_traverseEnsuresConstraints (p); |
bb25bea6 | 936 | constraintList_free(temp); |
937 | ||
938 | temp = p->requiresConstraints; | |
ae133592 | 939 | p->requiresConstraints = exprNode_traverseRequiresConstraints (p); |
bb25bea6 | 940 | constraintList_free(temp); |
941 | ||
942 | temp = p->trueEnsuresConstraints; | |
ae133592 | 943 | p->trueEnsuresConstraints = exprNode_traverseTrueEnsuresConstraints(p); |
bb25bea6 | 944 | constraintList_free(temp); |
945 | ||
cf38ca4d | 946 | |
947 | ||
9a48d98c | 948 | DPRINTF((message("p->trueEnsuresConstraints before substitue %s", constraintList_unparse(p->trueEnsuresConstraints) ) |
cf38ca4d | 949 | )); |
950 | ||
951 | /*drl 10/10/2002 this is a bit of a hack but the reason why we do this is so that any function post conditions or similar things get applied correctly to each branch. e.g. in strlen(s) < 5 we want the trueEnsures to be maxRead(s) < 5*/ | |
952 | ||
953 | p->trueEnsuresConstraints = constraintList_substituteFreeTarget (p->trueEnsuresConstraints, | |
954 | p->ensuresConstraints); | |
955 | ||
9a48d98c | 956 | DPRINTF(( message ("p->trueEnsuresConstraints after substitue %s", constraintList_unparse(p->trueEnsuresConstraints) ) |
cf38ca4d | 957 | )); |
958 | ||
bb25bea6 | 959 | temp = p->falseEnsuresConstraints; |
ae133592 | 960 | p->falseEnsuresConstraints = exprNode_traverseFalseEnsuresConstraints(p); |
bb25bea6 | 961 | constraintList_free(temp); |
616915dd | 962 | |
cf38ca4d | 963 | /*See comment on trueEnsures*/ |
964 | p->falseEnsuresConstraints = constraintList_substituteFreeTarget (p->falseEnsuresConstraints, | |
965 | p->ensuresConstraints); | |
966 | ||
abd7f895 | 967 | e = doIfElse (e, p, trueBranch, falseBranch); |
968 | DPRINTF(("Done IFELSE")); | |
616915dd | 969 | break; |
cf38ca4d | 970 | |
616915dd | 971 | case XPR_DOWHILE: |
470b7798 | 972 | |
973 | e2 = (exprData_getPairB (data)); | |
974 | e1 = (exprData_getPairA (data)); | |
975 | ||
abd7f895 | 976 | DPRINTF((message ("do { %s } while (%s)", exprNode_unparse(e2), exprNode_unparse(e1)))); |
470b7798 | 977 | exprNode_generateConstraints (e2); |
978 | exprNode_generateConstraints (e1); | |
979 | e = exprNode_copyConstraints (e, e2); | |
9a48d98c | 980 | DPRINTF ((message ("e = %s ", constraintList_unparse(e->requiresConstraints)))); |
470b7798 | 981 | |
616915dd | 982 | break; |
983 | ||
984 | case XPR_BLOCK: | |
965143f0 | 985 | { |
986 | exprNode tempExpr; | |
987 | ||
988 | tempExpr = exprData_getSingle (data); | |
989 | ||
990 | exprNode_generateConstraints (tempExpr); | |
991 | ||
992 | if (exprNode_isDefined(tempExpr) ) | |
993 | { | |
994 | constraintList_free(e->requiresConstraints); | |
995 | e->requiresConstraints = constraintList_copy (tempExpr->requiresConstraints); | |
996 | constraintList_free(e->ensuresConstraints); | |
997 | e->ensuresConstraints = constraintList_copy (tempExpr->ensuresConstraints); | |
998 | } | |
999 | else | |
1000 | { | |
1001 | llassert(FALSE); | |
1002 | } | |
1003 | } | |
616915dd | 1004 | break; |
1005 | ||
470b7798 | 1006 | case XPR_SWITCH: |
1007 | e = doSwitch (e); | |
1008 | break; | |
616915dd | 1009 | case XPR_STMT: |
1010 | case XPR_STMTLIST: | |
84c9ffbf | 1011 | exprNode_stmtList (e); |
1012 | return ; | |
616915dd | 1013 | /*@notreached@*/ |
1014 | break; | |
1015 | default: | |
1016 | ret=FALSE; | |
1017 | } | |
b7b694d6 | 1018 | return; |
616915dd | 1019 | } |
1020 | ||
bb25bea6 | 1021 | static bool lltok_isBoolean_Op (lltok tok) |
616915dd | 1022 | { |
1023 | /*this should really be a switch statement but | |
1024 | I don't want to violate the abstraction | |
1025 | maybe this should go in lltok.c */ | |
1026 | ||
16c024b5 | 1027 | if (lltok_isEqOp (tok)) |
616915dd | 1028 | { |
1029 | return TRUE; | |
1030 | } | |
16c024b5 | 1031 | if (lltok_isAndOp (tok)) |
616915dd | 1032 | |
1033 | { | |
1034 | ||
1035 | return TRUE; | |
1036 | } | |
16c024b5 | 1037 | if (lltok_isOrOp (tok)) |
616915dd | 1038 | { |
1039 | return TRUE; | |
1040 | } | |
1041 | ||
abd7f895 | 1042 | if (lltok_isGt_Op (tok)) |
616915dd | 1043 | { |
1044 | return TRUE; | |
1045 | } | |
abd7f895 | 1046 | if (lltok_isLt_Op (tok)) |
616915dd | 1047 | { |
1048 | return TRUE; | |
1049 | } | |
1050 | ||
abd7f895 | 1051 | if (lltok_isLe_Op (tok)) |
616915dd | 1052 | { |
1053 | return TRUE; | |
1054 | } | |
1055 | ||
abd7f895 | 1056 | if (lltok_isGe_Op (tok)) |
616915dd | 1057 | { |
1058 | return TRUE; | |
1059 | } | |
1060 | ||
1061 | return FALSE; | |
1062 | ||
1063 | } | |
1064 | ||
1065 | ||
28bf4b0b | 1066 | static void exprNode_booleanTraverse (/*@dependent@*/ exprNode e, /*@unused@*/ bool definatelv, /*@unused@*/ bool definaterv, fileloc sequencePoint) |
616915dd | 1067 | { |
b7b694d6 | 1068 | constraint cons; |
1069 | exprNode t1, t2; | |
1070 | exprData data; | |
1071 | lltok tok; | |
1072 | constraintList tempList, temp; | |
965143f0 | 1073 | |
1074 | if (exprNode_isUndefined(e) ) | |
1075 | { | |
1076 | llassert (exprNode_isDefined(e) ); | |
1077 | return; | |
1078 | } | |
1079 | ||
b7b694d6 | 1080 | data = e->edata; |
616915dd | 1081 | |
b7b694d6 | 1082 | tok = exprData_getOpTok (data); |
1083 | t1 = exprData_getOpA (data); | |
1084 | t2 = exprData_getOpB (data); | |
965143f0 | 1085 | |
1086 | /* drl 3/2/2003 we know this because of the type of expression*/ | |
1087 | llassert( exprNode_isDefined(t1) && exprNode_isDefined(t2) ); | |
1088 | ||
616915dd | 1089 | |
b7b694d6 | 1090 | tempList = constraintList_undefined; |
616915dd | 1091 | |
b7b694d6 | 1092 | /* arithmetic tests */ |
616915dd | 1093 | |
16c024b5 | 1094 | if (lltok_isEqOp (tok)) |
b7b694d6 | 1095 | { |
1096 | cons = constraint_makeEnsureEqual (t1, t2, sequencePoint); | |
1097 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1098 | } | |
616915dd | 1099 | |
b7b694d6 | 1100 | |
abd7f895 | 1101 | if (lltok_isLt_Op (tok)) |
b7b694d6 | 1102 | { |
1103 | cons = constraint_makeEnsureLessThan (t1, t2, sequencePoint); | |
1104 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1105 | cons = constraint_makeEnsureGreaterThanEqual (t1, t2, sequencePoint); | |
1106 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1107 | } | |
616915dd | 1108 | |
abd7f895 | 1109 | if (lltok_isGe_Op (tok)) |
b7b694d6 | 1110 | { |
1111 | cons = constraint_makeEnsureGreaterThanEqual (t1, t2, sequencePoint); | |
1112 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1113 | ||
1114 | cons = constraint_makeEnsureLessThan (t1, t2, sequencePoint); | |
1115 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1116 | } | |
1117 | ||
abd7f895 | 1118 | if (lltok_isGt_Op (tok)) |
b7b694d6 | 1119 | { |
1120 | cons = constraint_makeEnsureGreaterThan (t1, t2, sequencePoint); | |
1121 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1122 | cons = constraint_makeEnsureLessThanEqual (t1, t2, sequencePoint); | |
1123 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1124 | } | |
1125 | ||
abd7f895 | 1126 | if (lltok_isLe_Op (tok)) |
b7b694d6 | 1127 | { |
1128 | cons = constraint_makeEnsureLessThanEqual (t1, t2, sequencePoint); | |
1129 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); | |
1130 | ||
1131 | cons = constraint_makeEnsureGreaterThan (t1, t2, sequencePoint); | |
1132 | e->falseEnsuresConstraints = constraintList_add(e->falseEnsuresConstraints, cons); | |
1133 | } | |
1134 | ||
1135 | /* Logical operations */ | |
1136 | ||
16c024b5 | 1137 | if (lltok_isAndOp (tok)) |
b7b694d6 | 1138 | { |
1139 | /* true ensures */ | |
1140 | tempList = constraintList_copy (t1->trueEnsuresConstraints); | |
1141 | tempList = constraintList_addList (tempList, t2->trueEnsuresConstraints); | |
1142 | e->trueEnsuresConstraints = constraintList_addListFree(e->trueEnsuresConstraints, tempList); | |
1143 | ||
1144 | /* false ensures: fens t1 or tens t1 and fens t2 */ | |
1145 | tempList = constraintList_copy (t1->trueEnsuresConstraints); | |
1146 | tempList = constraintList_addList (tempList, t2->falseEnsuresConstraints); | |
1147 | temp = tempList; | |
1148 | tempList = constraintList_logicalOr (tempList, t1->falseEnsuresConstraints); | |
1149 | constraintList_free (temp); | |
1150 | ||
1b8ae690 | 1151 | /* evans - was constraintList_addList - memory leak detected by splint */ |
b7b694d6 | 1152 | e->falseEnsuresConstraints = constraintList_addListFree (e->falseEnsuresConstraints, tempList); |
1153 | } | |
16c024b5 | 1154 | else if (lltok_isOrOp (tok)) |
b7b694d6 | 1155 | { |
1156 | /* false ensures */ | |
616915dd | 1157 | tempList = constraintList_copy (t1->falseEnsuresConstraints); |
1158 | tempList = constraintList_addList (tempList, t2->falseEnsuresConstraints); | |
4ab867d6 | 1159 | e->falseEnsuresConstraints = constraintList_addListFree(e->falseEnsuresConstraints, tempList); |
616915dd | 1160 | |
b7b694d6 | 1161 | /* true ensures: tens t1 or fens t1 and tens t2 */ |
616915dd | 1162 | tempList = constraintList_copy (t1->falseEnsuresConstraints); |
1163 | tempList = constraintList_addList (tempList, t2->trueEnsuresConstraints); | |
bb25bea6 | 1164 | |
1165 | temp = tempList; | |
616915dd | 1166 | tempList = constraintList_logicalOr (tempList, t1->trueEnsuresConstraints); |
bb25bea6 | 1167 | constraintList_free(temp); |
1168 | ||
60eced23 | 1169 | e->trueEnsuresConstraints = constraintList_addListFree(e->trueEnsuresConstraints, tempList); |
920a3797 | 1170 | tempList = constraintList_undefined; |
616915dd | 1171 | } |
b7b694d6 | 1172 | else |
84c9ffbf | 1173 | { |
abd7f895 | 1174 | DPRINTF((message("%s is not a boolean operation", lltok_unparse(tok)))); |
60eced23 | 1175 | } |
616915dd | 1176 | } |
1177 | ||
ae133592 | 1178 | void exprNode_exprTraverse (/*@dependent@*/ exprNode e, |
1179 | bool definatelv, bool definaterv, | |
1180 | /*@observer@*/ /*@temp@*/ fileloc sequencePoint) | |
616915dd | 1181 | { |
9280addf | 1182 | exprNode t1, t2, fcn; |
616915dd | 1183 | lltok tok; |
616915dd | 1184 | exprData data; |
1185 | constraint cons; | |
bb25bea6 | 1186 | constraintList temp; |
1187 | ||
abd7f895 | 1188 | if (exprNode_isError(e)) |
470b7798 | 1189 | { |
b7b694d6 | 1190 | return; |
470b7798 | 1191 | } |
1192 | ||
ae133592 | 1193 | DPRINTF (("exprNode_exprTraverse analyzing %s at %s", |
1194 | exprNode_unparse (e), | |
1195 | fileloc_unparse (exprNode_loc (e)))); | |
470b7798 | 1196 | |
abd7f895 | 1197 | if (exprNode_isUnhandled (e)) |
ae133592 | 1198 | { |
1199 | return; | |
1200 | } | |
b7b694d6 | 1201 | |
616915dd | 1202 | data = e->edata; |
1203 | ||
1204 | switch (e->kind) | |
1205 | { | |
616915dd | 1206 | case XPR_WHILEPRED: |
1207 | t1 = exprData_getSingle (data); | |
1208 | exprNode_exprTraverse (t1, definatelv, definaterv, sequencePoint); | |
1209 | e = exprNode_copyConstraints (e, t1); | |
1210 | break; | |
1211 | ||
1212 | case XPR_FETCH: | |
1213 | ||
abd7f895 | 1214 | if (definatelv) |
616915dd | 1215 | { |
abd7f895 | 1216 | t1 = (exprData_getPairA (data)); |
1217 | t2 = (exprData_getPairB (data)); | |
616915dd | 1218 | cons = constraint_makeWriteSafeExprNode (t1, t2); |
1219 | } | |
1220 | else | |
1221 | { | |
abd7f895 | 1222 | t1 = (exprData_getPairA (data)); |
1223 | t2 = (exprData_getPairB (data)); | |
1224 | cons = constraint_makeReadSafeExprNode (t1, t2); | |
616915dd | 1225 | } |
1226 | ||
1227 | e->requiresConstraints = constraintList_add(e->requiresConstraints, cons); | |
1228 | cons = constraint_makeEnsureMaxReadAtLeast (t1, t2, sequencePoint); | |
1229 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); | |
1230 | ||
9280addf | 1231 | cons = constraint_makeEnsureLteMaxRead (t2, t1); |
616915dd | 1232 | e->trueEnsuresConstraints = constraintList_add(e->trueEnsuresConstraints, cons); |
1233 | ||
616915dd | 1234 | exprNode_exprTraverse (exprData_getPairA (data), FALSE, TRUE, sequencePoint); |
1235 | exprNode_exprTraverse (exprData_getPairB (data), FALSE, TRUE, sequencePoint); | |
1236 | ||
616915dd | 1237 | break; |
1238 | ||
1239 | case XPR_PARENS: | |
1240 | exprNode_exprTraverse (exprData_getUopNode (e->edata), definatelv, definaterv, sequencePoint); | |
616915dd | 1241 | break; |
1242 | case XPR_INIT: | |
920a3797 | 1243 | { |
920a3797 | 1244 | t2 = exprData_getInitNode (data); |
ae133592 | 1245 | |
1246 | DPRINTF (("initialization ==> %s",exprNode_unparse (t2))); | |
920a3797 | 1247 | |
abd7f895 | 1248 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); |
920a3797 | 1249 | |
ae133592 | 1250 | /* This test is nessecary because some expressions generate a null expression node. |
1251 | function pointer do that -- drl */ | |
1252 | ||
1253 | if (!exprNode_isError (e) && !exprNode_isError (t2)) | |
920a3797 | 1254 | { |
1255 | cons = constraint_makeEnsureEqual (e, t2, sequencePoint); | |
1256 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); | |
1257 | } | |
1258 | } | |
616915dd | 1259 | |
1260 | break; | |
1261 | case XPR_ASSIGN: | |
1262 | t1 = exprData_getOpA (data); | |
1263 | t2 = exprData_getOpB (data); | |
ae133592 | 1264 | DPRINTF (("Assignment constraints t1: %s", constraintList_unparse (t1->ensuresConstraints))); |
1265 | DPRINTF (("Assignment constraints t2: %s", constraintList_unparse (t2->ensuresConstraints))); | |
abd7f895 | 1266 | exprNode_exprTraverse (t1, TRUE, definaterv, sequencePoint); |
ae133592 | 1267 | DPRINTF (("Assignment constraints t1: %s", constraintList_unparse (t1->ensuresConstraints))); |
1268 | DPRINTF (("Assignment constraints t2: %s", constraintList_unparse (t2->ensuresConstraints))); | |
abd7f895 | 1269 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); |
ae133592 | 1270 | DPRINTF (("Assignment constraints t1: %s", constraintList_unparse (t1->ensuresConstraints))); |
1271 | DPRINTF (("Assignment constraints t2: %s", constraintList_unparse (t2->ensuresConstraints))); | |
616915dd | 1272 | |
ae133592 | 1273 | /* this test is nessecary because some expressions generate a null expression node. |
1274 | function pointer do that -- drl */ | |
1275 | ||
1276 | if ((!exprNode_isError (t1)) && (!exprNode_isError(t2))) | |
616915dd | 1277 | { |
ae133592 | 1278 | cons = constraint_makeEnsureEqual (t1, t2, sequencePoint); |
1279 | DPRINTF (("Ensure equal constraint: %s", constraint_unparse (cons))); | |
1280 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); | |
1281 | DPRINTF (("Assignment constraints: %s", constraintList_unparse (e->ensuresConstraints))); | |
616915dd | 1282 | } |
1283 | break; | |
1284 | case XPR_OP: | |
1285 | t1 = exprData_getOpA (data); | |
1286 | t2 = exprData_getOpB (data); | |
abd7f895 | 1287 | tok = exprData_getOpTok (data); |
920a3797 | 1288 | |
80489f0a | 1289 | if (lltok_getTok (tok) == ADD_ASSIGN) |
2934b455 | 1290 | { |
abd7f895 | 1291 | exprNode_exprTraverse (t1, TRUE, definaterv, sequencePoint); |
1292 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); | |
920a3797 | 1293 | |
abd7f895 | 1294 | cons = constraint_makeAddAssign (t1, t2, sequencePoint); |
2934b455 | 1295 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); |
1296 | } | |
80489f0a | 1297 | else if (lltok_getTok (tok) == SUB_ASSIGN) |
2934b455 | 1298 | { |
abd7f895 | 1299 | exprNode_exprTraverse (t1, TRUE, definaterv, sequencePoint); |
1300 | exprNode_exprTraverse (t2, definatelv, TRUE, sequencePoint); | |
920a3797 | 1301 | |
abd7f895 | 1302 | cons = constraint_makeSubtractAssign (t1, t2, sequencePoint); |
2934b455 | 1303 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); |
1304 | } | |
920a3797 | 1305 | else |
1306 | { | |
abd7f895 | 1307 | exprNode_exprTraverse (t1, definatelv, definaterv, sequencePoint); |
1308 | exprNode_exprTraverse (t2, definatelv, definaterv, sequencePoint); | |
920a3797 | 1309 | } |
2934b455 | 1310 | |
abd7f895 | 1311 | if (lltok_isBoolean_Op (tok)) |
616915dd | 1312 | exprNode_booleanTraverse (e, definatelv, definaterv, sequencePoint); |
1313 | ||
616915dd | 1314 | break; |
1315 | case XPR_SIZEOFT: | |
b941db6b | 1316 | /*drl 4-11-03 I think this is the same as the next case...*/ |
616915dd | 1317 | |
1318 | break; | |
1319 | ||
b4085262 | 1320 | case XPR_SIZEOF: |
1321 | /* drl 7-16-01 | |
1322 | C standard says operand to sizeof isn't evaluated unless | |
1323 | its a variable length array. So we don't generate constraints. | |
1324 | */ | |
1325 | ||
616915dd | 1326 | break; |
1327 | ||
1328 | case XPR_CALL: | |
9280addf | 1329 | fcn = exprData_getFcn(data); |
1330 | ||
abd7f895 | 1331 | exprNode_exprTraverse (fcn, definatelv, definaterv, sequencePoint); |
ae133592 | 1332 | DPRINTF (("Got call that %s (%s)", |
1333 | exprNode_unparse(fcn), exprNodeList_unparse (exprData_getArgs (data)))); | |
616915dd | 1334 | |
965143f0 | 1335 | llassert( exprNode_isDefined(fcn) ); |
ae133592 | 1336 | |
1337 | fcn->requiresConstraints = | |
1338 | constraintList_addListFree (fcn->requiresConstraints, | |
6317f163 | 1339 | checkCall (fcn, exprData_getArgs (data))); |
ae133592 | 1340 | |
1341 | fcn->ensuresConstraints = | |
1342 | constraintList_addListFree (fcn->ensuresConstraints, | |
1343 | exprNode_getPostConditions(fcn, exprData_getArgs (data),e )); | |
1344 | ||
abd7f895 | 1345 | t1 = exprNode_createNew (exprNode_getType (e)); |
9280addf | 1346 | checkArgumentList (t1, exprData_getArgs(data), sequencePoint); |
28bf4b0b | 1347 | exprNode_mergeResolve (e, t1, fcn); |
920a3797 | 1348 | exprNode_free(t1); |
616915dd | 1349 | break; |
1350 | ||
1351 | case XPR_RETURN: | |
abd7f895 | 1352 | exprNode_exprTraverse (exprData_getSingle (data), definatelv, definaterv, sequencePoint); |
616915dd | 1353 | break; |
1354 | ||
1355 | case XPR_NULLRETURN: | |
84c9ffbf | 1356 | |
616915dd | 1357 | break; |
1358 | ||
1359 | ||
1360 | case XPR_FACCESS: | |
abd7f895 | 1361 | exprNode_exprTraverse (exprData_getFieldNode (data), definatelv, definaterv, sequencePoint); |
616915dd | 1362 | break; |
1363 | ||
1364 | case XPR_ARROW: | |
abd7f895 | 1365 | exprNode_exprTraverse (exprData_getFieldNode (data), definatelv, definaterv, sequencePoint); |
616915dd | 1366 | break; |
1367 | ||
1368 | case XPR_STRINGLITERAL: | |
84c9ffbf | 1369 | |
616915dd | 1370 | break; |
1371 | ||
1372 | case XPR_NUMLIT: | |
84c9ffbf | 1373 | |
616915dd | 1374 | break; |
1375 | ||
1376 | case XPR_PREOP: | |
1377 | t1 = exprData_getUopNode(data); | |
965143f0 | 1378 | |
1379 | ||
1380 | /* drl 3/2/2003 we know this because of the type of expression*/ | |
1381 | llassert( exprNode_isDefined(t1) ); | |
1382 | ||
1383 | ||
616915dd | 1384 | tok = (exprData_getUopTok (data)); |
abd7f895 | 1385 | exprNode_exprTraverse (t1, definatelv, definaterv, sequencePoint); |
616915dd | 1386 | /*handle * pointer access */ |
16c024b5 | 1387 | if (lltok_isIncOp (tok)) |
616915dd | 1388 | { |
1389 | DPRINTF(("doing ++(var)")); | |
1390 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1391 | cons = constraint_makeMaxSetSideEffectPostIncrement (t1, sequencePoint); |
616915dd | 1392 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1393 | } | |
16c024b5 | 1394 | else if (lltok_isDecOp (tok)) |
616915dd | 1395 | { |
1396 | DPRINTF(("doing --(var)")); | |
1397 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1398 | cons = constraint_makeMaxSetSideEffectPostDecrement (t1, sequencePoint); |
616915dd | 1399 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1400 | } | |
abd7f895 | 1401 | else if (lltok_isMult(tok )) |
616915dd | 1402 | { |
1403 | if (definatelv) | |
1404 | { | |
1405 | cons = constraint_makeWriteSafeInt (t1, 0); | |
1406 | } | |
1407 | else | |
1408 | { | |
1409 | cons = constraint_makeReadSafeInt (t1, 0); | |
1410 | } | |
1411 | e->requiresConstraints = constraintList_add(e->requiresConstraints, cons); | |
1412 | } | |
16c024b5 | 1413 | else if (lltok_isNotOp (tok)) |
84c9ffbf | 1414 | /* ! expr */ |
616915dd | 1415 | { |
bb25bea6 | 1416 | constraintList_free(e->trueEnsuresConstraints); |
1417 | ||
616915dd | 1418 | e->trueEnsuresConstraints = constraintList_copy (t1->falseEnsuresConstraints); |
bb25bea6 | 1419 | constraintList_free(e->falseEnsuresConstraints); |
616915dd | 1420 | e->falseEnsuresConstraints = constraintList_copy (t1->trueEnsuresConstraints); |
1421 | } | |
bb25bea6 | 1422 | |
abd7f895 | 1423 | else if (lltok_isAmpersand_Op (tok)) |
84c9ffbf | 1424 | { |
1425 | break; | |
1426 | } | |
abd7f895 | 1427 | else if (lltok_isMinus_Op (tok)) |
bb25bea6 | 1428 | { |
1429 | break; | |
1430 | } | |
abd7f895 | 1431 | else if (lltok_isExcl_Op (tok)) |
4ab867d6 | 1432 | { |
1433 | break; | |
1434 | } | |
abd7f895 | 1435 | else if (lltok_isTilde_Op (tok)) |
4ab867d6 | 1436 | { |
1437 | break; | |
1438 | } | |
84c9ffbf | 1439 | else |
1440 | { | |
abd7f895 | 1441 | llcontbug (message("Unsupported preop in %s", exprNode_unparse(e))); |
84c9ffbf | 1442 | BADEXIT; |
1443 | } | |
616915dd | 1444 | break; |
1445 | ||
1446 | case XPR_POSTOP: | |
abd7f895 | 1447 | exprNode_exprTraverse (exprData_getUopNode (data), TRUE, |
1448 | definaterv, sequencePoint); | |
616915dd | 1449 | |
16c024b5 | 1450 | if (lltok_isIncOp (exprData_getUopTok (data))) |
616915dd | 1451 | { |
1452 | DPRINTF(("doing ++")); | |
1453 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1454 | cons = constraint_makeMaxSetSideEffectPostIncrement (t1, sequencePoint); |
616915dd | 1455 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1456 | } | |
16c024b5 | 1457 | if (lltok_isDecOp (exprData_getUopTok (data))) |
616915dd | 1458 | { |
1459 | DPRINTF(("doing --")); | |
1460 | t1 = exprData_getUopNode (data); | |
abd7f895 | 1461 | cons = constraint_makeMaxSetSideEffectPostDecrement (t1, sequencePoint); |
616915dd | 1462 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); |
1463 | } | |
1464 | break; | |
470b7798 | 1465 | case XPR_CAST: |
920a3797 | 1466 | { |
1467 | t2 = exprData_getCastNode (data); | |
abd7f895 | 1468 | DPRINTF ((message ("Examining cast (%q)%s", |
920a3797 | 1469 | qtype_unparse (exprData_getCastType (data)), |
abd7f895 | 1470 | exprNode_unparse (t2)) |
1471 | )); | |
1472 | exprNode_exprTraverse (t2, definatelv, definaterv, sequencePoint); | |
920a3797 | 1473 | } |
470b7798 | 1474 | break; |
920a3797 | 1475 | |
470b7798 | 1476 | case XPR_COND: |
1477 | { | |
28bf4b0b | 1478 | exprNode pred, trueBranch, falseBranch; |
abd7f895 | 1479 | llassert(FALSE); |
1480 | pred = exprData_getTriplePred (data); | |
1481 | trueBranch = exprData_getTripleTrue (data); | |
1482 | falseBranch = exprData_getTripleFalse (data); | |
1483 | ||
1484 | llassert (exprNode_isDefined (pred)); | |
1485 | llassert (exprNode_isDefined (trueBranch)); | |
1486 | llassert (exprNode_isDefined (falseBranch)); | |
470b7798 | 1487 | |
abd7f895 | 1488 | exprNode_exprTraverse (pred, FALSE, TRUE, sequencePoint); |
1489 | ||
1490 | temp = pred->ensuresConstraints; | |
ae133592 | 1491 | pred->ensuresConstraints = exprNode_traverseEnsuresConstraints(pred); |
abd7f895 | 1492 | constraintList_free(temp); |
1493 | ||
1494 | temp = pred->requiresConstraints; | |
ae133592 | 1495 | pred->requiresConstraints = exprNode_traverseRequiresConstraints(pred); |
abd7f895 | 1496 | constraintList_free(temp); |
1497 | ||
1498 | temp = pred->trueEnsuresConstraints; | |
ae133592 | 1499 | pred->trueEnsuresConstraints = exprNode_traverseTrueEnsuresConstraints(pred); |
abd7f895 | 1500 | constraintList_free(temp); |
1501 | ||
1502 | temp = pred->falseEnsuresConstraints; | |
ae133592 | 1503 | pred->falseEnsuresConstraints = exprNode_traverseFalseEnsuresConstraints(pred); |
abd7f895 | 1504 | constraintList_free(temp); |
1505 | ||
1506 | exprNode_exprTraverse (trueBranch, FALSE, TRUE, sequencePoint); | |
1507 | ||
1508 | temp = trueBranch->ensuresConstraints; | |
ae133592 | 1509 | trueBranch->ensuresConstraints = exprNode_traverseEnsuresConstraints(trueBranch); |
abd7f895 | 1510 | constraintList_free(temp); |
1511 | ||
1512 | temp = trueBranch->requiresConstraints; | |
ae133592 | 1513 | trueBranch->requiresConstraints = exprNode_traverseRequiresConstraints(trueBranch); |
abd7f895 | 1514 | constraintList_free(temp); |
1515 | ||
ae133592 | 1516 | temp = trueBranch->trueEnsuresConstraints; |
1517 | trueBranch->trueEnsuresConstraints = exprNode_traverseTrueEnsuresConstraints(trueBranch); | |
abd7f895 | 1518 | constraintList_free(temp); |
1519 | ||
ae133592 | 1520 | temp = trueBranch->falseEnsuresConstraints; |
1521 | trueBranch->falseEnsuresConstraints = exprNode_traverseFalseEnsuresConstraints(trueBranch); | |
abd7f895 | 1522 | constraintList_free(temp); |
1523 | ||
1524 | exprNode_exprTraverse (falseBranch, FALSE, TRUE, sequencePoint); | |
1525 | ||
1526 | temp = falseBranch->ensuresConstraints; | |
ae133592 | 1527 | falseBranch->ensuresConstraints = exprNode_traverseEnsuresConstraints(falseBranch); |
abd7f895 | 1528 | constraintList_free(temp); |
1529 | ||
1530 | ||
1531 | temp = falseBranch->requiresConstraints; | |
ae133592 | 1532 | falseBranch->requiresConstraints = exprNode_traverseRequiresConstraints(falseBranch); |
abd7f895 | 1533 | constraintList_free(temp); |
1534 | ||
1535 | temp = falseBranch->trueEnsuresConstraints; | |
ae133592 | 1536 | falseBranch->trueEnsuresConstraints = exprNode_traverseTrueEnsuresConstraints(falseBranch); |
abd7f895 | 1537 | constraintList_free(temp); |
1538 | ||
1539 | temp = falseBranch->falseEnsuresConstraints; | |
ae133592 | 1540 | falseBranch->falseEnsuresConstraints = exprNode_traverseFalseEnsuresConstraints(falseBranch); |
abd7f895 | 1541 | constraintList_free(temp); |
1542 | ||
1543 | /* if pred is true e equals true otherwise pred equals false */ | |
1544 | ||
1545 | cons = constraint_makeEnsureEqual (e, trueBranch, sequencePoint); | |
1546 | trueBranch->ensuresConstraints = constraintList_add(trueBranch->ensuresConstraints, cons); | |
1547 | ||
1548 | cons = constraint_makeEnsureEqual (e, trueBranch, sequencePoint); | |
1549 | falseBranch->ensuresConstraints = constraintList_add(falseBranch->ensuresConstraints, cons); | |
1550 | ||
1551 | e = doIfElse (e, pred, trueBranch, falseBranch); | |
470b7798 | 1552 | } |
1553 | break; | |
1554 | case XPR_COMMA: | |
1555 | llassert(FALSE); | |
1556 | t1 = exprData_getPairA (data); | |
1557 | t2 = exprData_getPairB (data); | |
ae133592 | 1558 | /* we essiantially treat this like expr1; expr2 |
1559 | of course sequencePoint isn't adjusted so this isn't completely accurate | |
1560 | problems... | |
1561 | */ | |
abd7f895 | 1562 | exprNode_exprTraverse (t1, FALSE, FALSE, sequencePoint); |
1563 | exprNode_exprTraverse (t2, definatelv, definaterv, sequencePoint); | |
28bf4b0b | 1564 | exprNode_mergeResolve (e, t1, t2); |
470b7798 | 1565 | break; |
920a3797 | 1566 | |
616915dd | 1567 | default: |
ae133592 | 1568 | break; |
616915dd | 1569 | } |
1570 | ||
ae133592 | 1571 | e->requiresConstraints = constraintList_preserveOrig (e->requiresConstraints); |
1572 | e->ensuresConstraints = constraintList_preserveOrig (e->ensuresConstraints); | |
abd7f895 | 1573 | e->requiresConstraints = constraintList_addGeneratingExpr (e->requiresConstraints, e); |
ae133592 | 1574 | e->ensuresConstraints = constraintList_addGeneratingExpr (e->ensuresConstraints, e); |
1575 | e->requiresConstraints = constraintList_removeSurpressed (e->requiresConstraints); | |
7edb30e6 | 1576 | |
ae133592 | 1577 | DPRINTF (("ensures constraints for %s are %s", |
1578 | exprNode_unparse(e), constraintList_unparseDetailed (e->ensuresConstraints))); | |
616915dd | 1579 | |
ae133592 | 1580 | DPRINTF (("Requires constraints for %s are %s", exprNode_unparse(e), |
1581 | constraintList_unparseDetailed(e->ensuresConstraints))); | |
bb25bea6 | 1582 | |
ae133592 | 1583 | DPRINTF (("trueEnsures constraints for %s are %s", exprNode_unparse(e), |
1584 | constraintList_unparseDetailed(e->trueEnsuresConstraints))); | |
1585 | ||
1586 | DPRINTF (("falseEnsures constraints for %s are %s", exprNode_unparse(e), | |
1587 | constraintList_unparseDetailed(e->falseEnsuresConstraints))); | |
b7b694d6 | 1588 | return; |
616915dd | 1589 | } |
1590 | ||
1591 | ||
ae133592 | 1592 | constraintList exprNode_traverseTrueEnsuresConstraints (exprNode e) |
616915dd | 1593 | { |
470b7798 | 1594 | exprNode t1; |
616915dd | 1595 | |
1596 | bool handledExprNode; | |
616915dd | 1597 | exprData data; |
1598 | constraintList ret; | |
1599 | ||
2681ee39 | 1600 | if (exprNode_handleError (e)) |
1601 | { | |
1602 | ret = constraintList_makeNew(); | |
1603 | return ret; | |
1604 | } | |
abd7f895 | 1605 | |
1606 | ret = constraintList_copy (e->trueEnsuresConstraints); | |
616915dd | 1607 | |
2681ee39 | 1608 | handledExprNode = TRUE; |
616915dd | 1609 | |
1610 | data = e->edata; | |
1611 | ||
1612 | switch (e->kind) | |
1613 | { | |
9280addf | 1614 | case XPR_WHILEPRED: |
1615 | t1 = exprData_getSingle (data); | |
ae133592 | 1616 | ret = constraintList_addListFree (ret, exprNode_traverseTrueEnsuresConstraints (t1)); |
9280addf | 1617 | break; |
616915dd | 1618 | |
1619 | case XPR_FETCH: | |
1620 | ||
4ab867d6 | 1621 | ret = constraintList_addListFree (ret, |
ae133592 | 1622 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1623 | (exprData_getPairA (data))); |
616915dd | 1624 | |
4ab867d6 | 1625 | ret = constraintList_addListFree (ret, |
ae133592 | 1626 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1627 | (exprData_getPairB (data))); |
616915dd | 1628 | break; |
1629 | case XPR_PREOP: | |
1630 | ||
4ab867d6 | 1631 | ret = constraintList_addListFree (ret, |
ae133592 | 1632 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1633 | (exprData_getUopNode (data))); |
616915dd | 1634 | break; |
1635 | ||
1636 | case XPR_PARENS: | |
ae133592 | 1637 | ret = constraintList_addListFree (ret, exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1638 | (exprData_getUopNode (data))); |
616915dd | 1639 | break; |
2681ee39 | 1640 | |
1641 | case XPR_INIT: | |
1642 | ret = constraintList_addListFree (ret, | |
ae133592 | 1643 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1644 | (exprData_getInitNode (data))); |
2681ee39 | 1645 | break; |
1646 | ||
1647 | ||
616915dd | 1648 | case XPR_ASSIGN: |
4ab867d6 | 1649 | ret = constraintList_addListFree (ret, |
ae133592 | 1650 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1651 | (exprData_getOpA (data))); |
616915dd | 1652 | |
4ab867d6 | 1653 | ret = constraintList_addListFree (ret, |
ae133592 | 1654 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1655 | (exprData_getOpB (data))); |
616915dd | 1656 | break; |
1657 | case XPR_OP: | |
4ab867d6 | 1658 | ret = constraintList_addListFree (ret, |
ae133592 | 1659 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1660 | (exprData_getOpA (data))); |
616915dd | 1661 | |
4ab867d6 | 1662 | ret = constraintList_addListFree (ret, |
ae133592 | 1663 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1664 | (exprData_getOpB (data))); |
616915dd | 1665 | break; |
1666 | case XPR_SIZEOFT: | |
616915dd | 1667 | break; |
1668 | ||
1669 | case XPR_SIZEOF: | |
1670 | ||
4ab867d6 | 1671 | ret = constraintList_addListFree (ret, |
ae133592 | 1672 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1673 | (exprData_getSingle (data))); |
616915dd | 1674 | break; |
1675 | ||
1676 | case XPR_CALL: | |
4ab867d6 | 1677 | ret = constraintList_addListFree (ret, |
ae133592 | 1678 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1679 | (exprData_getFcn (data))); |
b7b694d6 | 1680 | break; |
616915dd | 1681 | |
1682 | case XPR_RETURN: | |
4ab867d6 | 1683 | ret = constraintList_addListFree (ret, |
ae133592 | 1684 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1685 | (exprData_getSingle (data))); |
616915dd | 1686 | break; |
1687 | ||
1688 | case XPR_NULLRETURN: | |
616915dd | 1689 | break; |
1690 | ||
1691 | case XPR_FACCESS: | |
b7b694d6 | 1692 | ret = constraintList_addListFree (ret, |
ae133592 | 1693 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1694 | (exprData_getFieldNode (data))); |
616915dd | 1695 | break; |
1696 | ||
1697 | case XPR_ARROW: | |
b7b694d6 | 1698 | ret = constraintList_addListFree (ret, |
ae133592 | 1699 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1700 | (exprData_getFieldNode (data))); |
616915dd | 1701 | break; |
1702 | ||
1703 | case XPR_STRINGLITERAL: | |
616915dd | 1704 | break; |
1705 | ||
1706 | case XPR_NUMLIT: | |
616915dd | 1707 | break; |
1708 | case XPR_POSTOP: | |
1709 | ||
4ab867d6 | 1710 | ret = constraintList_addListFree (ret, |
ae133592 | 1711 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1712 | (exprData_getUopNode (data))); |
616915dd | 1713 | break; |
470b7798 | 1714 | |
1715 | case XPR_CAST: | |
1716 | ||
4ab867d6 | 1717 | ret = constraintList_addListFree (ret, |
ae133592 | 1718 | exprNode_traverseTrueEnsuresConstraints |
abd7f895 | 1719 | (exprData_getCastNode (data))); |
470b7798 | 1720 | break; |
84c9ffbf | 1721 | |
616915dd | 1722 | default: |
1723 | break; | |
1724 | } | |
1725 | ||
1726 | return ret; | |
1727 | } | |
1728 | ||
ae133592 | 1729 | constraintList exprNode_traverseFalseEnsuresConstraints (exprNode e) |
9280addf | 1730 | { |
b7b694d6 | 1731 | exprNode t1; |
9280addf | 1732 | bool handledExprNode; |
9280addf | 1733 | exprData data; |
1734 | constraintList ret; | |
abd7f895 | 1735 | |
1736 | if (exprNode_handleError (e)) | |
1737 | { | |
1738 | ret = constraintList_makeNew(); | |
1739 | return ret; | |
1740 | } | |
1741 | ||
1742 | ret = constraintList_copy (e->falseEnsuresConstraints); | |
1743 | handledExprNode = TRUE; | |
9280addf | 1744 | data = e->edata; |
1745 | ||
1746 | switch (e->kind) | |
1747 | { | |
1748 | case XPR_WHILEPRED: | |
1749 | t1 = exprData_getSingle (data); | |
ae133592 | 1750 | ret = constraintList_addListFree (ret,exprNode_traverseFalseEnsuresConstraints (t1)); |
9280addf | 1751 | break; |
1752 | ||
1753 | case XPR_FETCH: | |
1754 | ||
4ab867d6 | 1755 | ret = constraintList_addListFree (ret, |
ae133592 | 1756 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1757 | (exprData_getPairA (data))); |
9280addf | 1758 | |
4ab867d6 | 1759 | ret = constraintList_addListFree (ret, |
ae133592 | 1760 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1761 | (exprData_getPairB (data))); |
9280addf | 1762 | break; |
1763 | case XPR_PREOP: | |
1764 | ||
4ab867d6 | 1765 | ret = constraintList_addListFree (ret, |
ae133592 | 1766 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1767 | (exprData_getUopNode (data))); |
9280addf | 1768 | break; |
1769 | ||
1770 | case XPR_PARENS: | |
ae133592 | 1771 | ret = constraintList_addListFree (ret, exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1772 | (exprData_getUopNode (data))); |
9280addf | 1773 | break; |
2681ee39 | 1774 | case XPR_INIT: |
1775 | ret = constraintList_addListFree (ret, | |
ae133592 | 1776 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1777 | ( exprData_getInitNode (data))); |
2681ee39 | 1778 | break; |
1779 | ||
9280addf | 1780 | case XPR_ASSIGN: |
4ab867d6 | 1781 | ret = constraintList_addListFree (ret, |
ae133592 | 1782 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1783 | (exprData_getOpA (data))); |
9280addf | 1784 | |
4ab867d6 | 1785 | ret = constraintList_addListFree (ret, |
ae133592 | 1786 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1787 | (exprData_getOpB (data))); |
9280addf | 1788 | break; |
1789 | case XPR_OP: | |
4ab867d6 | 1790 | ret = constraintList_addListFree (ret, |
ae133592 | 1791 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1792 | (exprData_getOpA (data))); |
9280addf | 1793 | |
4ab867d6 | 1794 | ret = constraintList_addListFree (ret, |
ae133592 | 1795 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1796 | (exprData_getOpB (data))); |
9280addf | 1797 | break; |
1798 | case XPR_SIZEOFT: | |
9280addf | 1799 | break; |
1800 | ||
1801 | case XPR_SIZEOF: | |
1802 | ||
4ab867d6 | 1803 | ret = constraintList_addListFree (ret, |
ae133592 | 1804 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1805 | (exprData_getSingle (data))); |
9280addf | 1806 | break; |
1807 | ||
1808 | case XPR_CALL: | |
4ab867d6 | 1809 | ret = constraintList_addListFree (ret, |
ae133592 | 1810 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1811 | (exprData_getFcn (data))); |
b7b694d6 | 1812 | break; |
9280addf | 1813 | |
1814 | case XPR_RETURN: | |
4ab867d6 | 1815 | ret = constraintList_addListFree (ret, |
ae133592 | 1816 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1817 | (exprData_getSingle (data))); |
9280addf | 1818 | break; |
1819 | ||
1820 | case XPR_NULLRETURN: | |
9280addf | 1821 | break; |
1822 | ||
1823 | case XPR_FACCESS: | |
b7b694d6 | 1824 | ret = constraintList_addListFree (ret, |
ae133592 | 1825 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1826 | (exprData_getFieldNode (data))); |
9280addf | 1827 | break; |
b7b694d6 | 1828 | |
9280addf | 1829 | case XPR_ARROW: |
b7b694d6 | 1830 | ret = constraintList_addListFree (ret, |
ae133592 | 1831 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1832 | (exprData_getFieldNode (data))); |
9280addf | 1833 | break; |
1834 | ||
1835 | case XPR_STRINGLITERAL: | |
9280addf | 1836 | break; |
1837 | ||
1838 | case XPR_NUMLIT: | |
9280addf | 1839 | break; |
1840 | case XPR_POSTOP: | |
1841 | ||
4ab867d6 | 1842 | ret = constraintList_addListFree (ret, |
ae133592 | 1843 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1844 | (exprData_getUopNode (data))); |
9280addf | 1845 | break; |
470b7798 | 1846 | |
1847 | case XPR_CAST: | |
1848 | ||
4ab867d6 | 1849 | ret = constraintList_addListFree (ret, |
ae133592 | 1850 | exprNode_traverseFalseEnsuresConstraints |
abd7f895 | 1851 | (exprData_getCastNode (data))); |
470b7798 | 1852 | break; |
1853 | ||
9280addf | 1854 | default: |
1855 | break; | |
1856 | } | |
1857 | ||
1858 | return ret; | |
1859 | } | |
1860 | ||
616915dd | 1861 | |
1862 | /* walk down the tree and get all requires Constraints in each subexpression*/ | |
ae133592 | 1863 | /*@only@*/ constraintList exprNode_traverseRequiresConstraints (exprNode e) |
616915dd | 1864 | { |
470b7798 | 1865 | exprNode t1; |
616915dd | 1866 | |
1867 | bool handledExprNode; | |
616915dd | 1868 | exprData data; |
1869 | constraintList ret; | |
1870 | ||
1871 | if (exprNode_handleError (e)) | |
1872 | { | |
c3e695ff | 1873 | ret = constraintList_makeNew(); |
616915dd | 1874 | return ret; |
1875 | } | |
abd7f895 | 1876 | |
1877 | ret = constraintList_copy (e->requiresConstraints); | |
1878 | handledExprNode = TRUE; | |
616915dd | 1879 | data = e->edata; |
1880 | ||
1881 | switch (e->kind) | |
1882 | { | |
9280addf | 1883 | case XPR_WHILEPRED: |
1884 | t1 = exprData_getSingle (data); | |
ae133592 | 1885 | ret = constraintList_addListFree (ret, exprNode_traverseRequiresConstraints (t1)); |
9280addf | 1886 | break; |
616915dd | 1887 | |
1888 | case XPR_FETCH: | |
1889 | ||
4ab867d6 | 1890 | ret = constraintList_addListFree (ret, |
ae133592 | 1891 | exprNode_traverseRequiresConstraints |
abd7f895 | 1892 | (exprData_getPairA (data))); |
616915dd | 1893 | |
4ab867d6 | 1894 | ret = constraintList_addListFree (ret, |
ae133592 | 1895 | exprNode_traverseRequiresConstraints |
abd7f895 | 1896 | (exprData_getPairB (data))); |
616915dd | 1897 | break; |
1898 | case XPR_PREOP: | |
1899 | ||
4ab867d6 | 1900 | ret = constraintList_addListFree (ret, |
ae133592 | 1901 | exprNode_traverseRequiresConstraints |
abd7f895 | 1902 | (exprData_getUopNode (data))); |
616915dd | 1903 | break; |
1904 | ||
1905 | case XPR_PARENS: | |
ae133592 | 1906 | ret = constraintList_addListFree (ret, exprNode_traverseRequiresConstraints |
abd7f895 | 1907 | (exprData_getUopNode (data))); |
616915dd | 1908 | break; |
2681ee39 | 1909 | case XPR_INIT: |
1910 | ret = constraintList_addListFree (ret, | |
ae133592 | 1911 | exprNode_traverseRequiresConstraints |
abd7f895 | 1912 | (exprData_getInitNode (data))); |
2681ee39 | 1913 | break; |
1914 | ||
616915dd | 1915 | case XPR_ASSIGN: |
4ab867d6 | 1916 | ret = constraintList_addListFree (ret, |
ae133592 | 1917 | exprNode_traverseRequiresConstraints |
abd7f895 | 1918 | (exprData_getOpA (data))); |
616915dd | 1919 | |
4ab867d6 | 1920 | ret = constraintList_addListFree (ret, |
ae133592 | 1921 | exprNode_traverseRequiresConstraints |
abd7f895 | 1922 | (exprData_getOpB (data))); |
616915dd | 1923 | break; |
1924 | case XPR_OP: | |
4ab867d6 | 1925 | ret = constraintList_addListFree (ret, |
ae133592 | 1926 | exprNode_traverseRequiresConstraints |
abd7f895 | 1927 | (exprData_getOpA (data))); |
616915dd | 1928 | |
4ab867d6 | 1929 | ret = constraintList_addListFree (ret, |
ae133592 | 1930 | exprNode_traverseRequiresConstraints |
abd7f895 | 1931 | (exprData_getOpB (data))); |
616915dd | 1932 | break; |
1933 | case XPR_SIZEOFT: | |
616915dd | 1934 | break; |
1935 | ||
1936 | case XPR_SIZEOF: | |
1937 | ||
4ab867d6 | 1938 | ret = constraintList_addListFree (ret, |
ae133592 | 1939 | exprNode_traverseRequiresConstraints |
abd7f895 | 1940 | (exprData_getSingle (data))); |
616915dd | 1941 | break; |
1942 | ||
1943 | case XPR_CALL: | |
4ab867d6 | 1944 | ret = constraintList_addListFree (ret, |
ae133592 | 1945 | exprNode_traverseRequiresConstraints |
abd7f895 | 1946 | (exprData_getFcn (data))); |
b7b694d6 | 1947 | break; |
616915dd | 1948 | |
1949 | case XPR_RETURN: | |
4ab867d6 | 1950 | ret = constraintList_addListFree (ret, |
ae133592 | 1951 | exprNode_traverseRequiresConstraints |
abd7f895 | 1952 | (exprData_getSingle (data))); |
616915dd | 1953 | break; |
1954 | ||
1955 | case XPR_NULLRETURN: | |
616915dd | 1956 | break; |
1957 | ||
1958 | case XPR_FACCESS: | |
b7b694d6 | 1959 | ret = constraintList_addListFree (ret, |
ae133592 | 1960 | exprNode_traverseRequiresConstraints |
abd7f895 | 1961 | (exprData_getFieldNode (data))); |
616915dd | 1962 | break; |
b7b694d6 | 1963 | |
616915dd | 1964 | case XPR_ARROW: |
b7b694d6 | 1965 | ret = constraintList_addListFree (ret, |
ae133592 | 1966 | exprNode_traverseRequiresConstraints |
abd7f895 | 1967 | (exprData_getFieldNode (data))); |
616915dd | 1968 | break; |
1969 | ||
1970 | case XPR_STRINGLITERAL: | |
616915dd | 1971 | break; |
1972 | ||
1973 | case XPR_NUMLIT: | |
616915dd | 1974 | break; |
1975 | case XPR_POSTOP: | |
1976 | ||
4ab867d6 | 1977 | ret = constraintList_addListFree (ret, |
ae133592 | 1978 | exprNode_traverseRequiresConstraints |
abd7f895 | 1979 | (exprData_getUopNode (data))); |
616915dd | 1980 | break; |
470b7798 | 1981 | |
1982 | case XPR_CAST: | |
1983 | ||
4ab867d6 | 1984 | ret = constraintList_addListFree (ret, |
ae133592 | 1985 | exprNode_traverseRequiresConstraints |
abd7f895 | 1986 | (exprData_getCastNode (data))); |
470b7798 | 1987 | break; |
1988 | ||
616915dd | 1989 | default: |
1990 | break; | |
1991 | } | |
1992 | ||
1993 | return ret; | |
1994 | } | |
1995 | ||
1996 | ||
1997 | /* walk down the tree and get all Ensures Constraints in each subexpression*/ | |
ae133592 | 1998 | /*@only@*/ constraintList exprNode_traverseEnsuresConstraints (exprNode e) |
616915dd | 1999 | { |
470b7798 | 2000 | exprNode t1; |
616915dd | 2001 | |
2002 | bool handledExprNode; | |
616915dd | 2003 | exprData data; |
616915dd | 2004 | constraintList ret; |
2005 | ||
abd7f895 | 2006 | if (exprNode_handleError (e)) |
2007 | { | |
2008 | ret = constraintList_makeNew(); | |
2009 | return ret; | |
2010 | } | |
2011 | ||
2012 | ret = constraintList_copy (e->ensuresConstraints); | |
2013 | handledExprNode = TRUE; | |
2014 | ||
616915dd | 2015 | data = e->edata; |
abd7f895 | 2016 | |
2017 | DPRINTF ((message ("exprnode_traversEnsuresConstraints call for %s with " | |
2018 | "constraintList of %s", | |
616915dd | 2019 | exprNode_unparse (e), |
9a48d98c | 2020 | constraintList_unparse(e->ensuresConstraints) |
616915dd | 2021 | ) |
2022 | )); | |
2023 | ||
2024 | ||
2025 | switch (e->kind) | |
2026 | { | |
abd7f895 | 2027 | case XPR_WHILEPRED: |
9280addf | 2028 | t1 = exprData_getSingle (data); |
ae133592 | 2029 | ret = constraintList_addListFree (ret,exprNode_traverseEnsuresConstraints (t1)); |
9280addf | 2030 | break; |
616915dd | 2031 | |
2032 | case XPR_FETCH: | |
4ab867d6 | 2033 | ret = constraintList_addListFree (ret, |
ae133592 | 2034 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2035 | (exprData_getPairA (data))); |
2036 | ||
4ab867d6 | 2037 | ret = constraintList_addListFree (ret, |
ae133592 | 2038 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2039 | (exprData_getPairB (data))); |
616915dd | 2040 | break; |
2041 | case XPR_PREOP: | |
4ab867d6 | 2042 | ret = constraintList_addListFree (ret, |
ae133592 | 2043 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2044 | (exprData_getUopNode (data))); |
616915dd | 2045 | break; |
2046 | ||
2047 | case XPR_PARENS: | |
ae133592 | 2048 | ret = constraintList_addListFree (ret, exprNode_traverseEnsuresConstraints |
abd7f895 | 2049 | (exprData_getUopNode (data))); |
616915dd | 2050 | break; |
2681ee39 | 2051 | |
2052 | case XPR_INIT: | |
2053 | ret = constraintList_addListFree (ret, | |
ae133592 | 2054 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2055 | (exprData_getInitNode (data))); |
2056 | break; | |
2057 | ||
2058 | ||
616915dd | 2059 | case XPR_ASSIGN: |
abd7f895 | 2060 | ret = constraintList_addListFree (ret, |
ae133592 | 2061 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2062 | (exprData_getOpA (data))); |
2063 | ||
2064 | ret = constraintList_addListFree (ret, | |
ae133592 | 2065 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2066 | (exprData_getOpB (data))); |
2067 | break; | |
616915dd | 2068 | case XPR_OP: |
abd7f895 | 2069 | ret = constraintList_addListFree (ret, |
ae133592 | 2070 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2071 | (exprData_getOpA (data))); |
2072 | ||
2073 | ret = constraintList_addListFree (ret, | |
ae133592 | 2074 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2075 | (exprData_getOpB (data))); |
2076 | break; | |
616915dd | 2077 | case XPR_SIZEOFT: |
616915dd | 2078 | break; |
2079 | ||
2080 | case XPR_SIZEOF: | |
abd7f895 | 2081 | ret = constraintList_addListFree (ret, |
ae133592 | 2082 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2083 | (exprData_getSingle (data))); |
2084 | break; | |
616915dd | 2085 | case XPR_CALL: |
4ab867d6 | 2086 | ret = constraintList_addListFree (ret, |
ae133592 | 2087 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2088 | (exprData_getFcn (data))); |
b7b694d6 | 2089 | break; |
616915dd | 2090 | case XPR_RETURN: |
4ab867d6 | 2091 | ret = constraintList_addListFree (ret, |
ae133592 | 2092 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2093 | (exprData_getSingle (data))); |
616915dd | 2094 | break; |
616915dd | 2095 | case XPR_NULLRETURN: |
616915dd | 2096 | break; |
616915dd | 2097 | case XPR_FACCESS: |
b7b694d6 | 2098 | ret = constraintList_addListFree (ret, |
ae133592 | 2099 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2100 | (exprData_getFieldNode (data))); |
616915dd | 2101 | break; |
616915dd | 2102 | case XPR_ARROW: |
b7b694d6 | 2103 | ret = constraintList_addListFree (ret, |
ae133592 | 2104 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2105 | (exprData_getFieldNode (data))); |
616915dd | 2106 | break; |
616915dd | 2107 | case XPR_STRINGLITERAL: |
616915dd | 2108 | break; |
616915dd | 2109 | case XPR_NUMLIT: |
616915dd | 2110 | break; |
2111 | case XPR_POSTOP: | |
abd7f895 | 2112 | ret = constraintList_addListFree (ret, |
ae133592 | 2113 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2114 | (exprData_getUopNode (data))); |
2115 | break; | |
470b7798 | 2116 | case XPR_CAST: |
4ab867d6 | 2117 | ret = constraintList_addListFree (ret, |
ae133592 | 2118 | exprNode_traverseEnsuresConstraints |
abd7f895 | 2119 | (exprData_getCastNode (data))); |
470b7798 | 2120 | break; |
616915dd | 2121 | default: |
2122 | break; | |
2123 | } | |
abd7f895 | 2124 | |
2125 | DPRINTF((message ("exprnode_traversEnsuresConstraints call for %s with " | |
2126 | "constraintList of is returning %s", | |
2127 | exprNode_unparse (e), | |
9a48d98c | 2128 | constraintList_unparse(ret)))); |
616915dd | 2129 | |
616915dd | 2130 | return ret; |
2131 | } | |
2132 | ||
28bf4b0b | 2133 | /*drl moved out of constraintResolve.c 07-02-001 */ |
abd7f895 | 2134 | void checkArgumentList (/*@out@*/ exprNode temp, exprNodeList arglist, |
2135 | fileloc sequencePoint) | |
28bf4b0b | 2136 | { |
965143f0 | 2137 | |
2138 | llassert(temp != NULL ); | |
2139 | ||
28bf4b0b | 2140 | temp->requiresConstraints = constraintList_makeNew(); |
2141 | temp->ensuresConstraints = constraintList_makeNew(); | |
2142 | temp->trueEnsuresConstraints = constraintList_makeNew(); | |
2143 | temp->falseEnsuresConstraints = constraintList_makeNew(); | |
2144 | ||
2145 | exprNodeList_elements (arglist, el) | |
2146 | { | |
2147 | constraintList temp2; | |
965143f0 | 2148 | |
2149 | llassert(exprNode_isDefined(el) ); | |
2150 | ||
28bf4b0b | 2151 | exprNode_exprTraverse (el, FALSE, FALSE, sequencePoint); |
2152 | temp2 = el->requiresConstraints; | |
ae133592 | 2153 | el->requiresConstraints = exprNode_traverseRequiresConstraints(el); |
28bf4b0b | 2154 | constraintList_free(temp2); |
2155 | ||
2156 | temp2 = el->ensuresConstraints; | |
ae133592 | 2157 | el->ensuresConstraints = exprNode_traverseEnsuresConstraints(el); |
28bf4b0b | 2158 | constraintList_free(temp2); |
2159 | ||
2160 | temp->requiresConstraints = constraintList_addList(temp->requiresConstraints, | |
2161 | el->requiresConstraints); | |
2162 | ||
2163 | temp->ensuresConstraints = constraintList_addList(temp->ensuresConstraints, | |
2164 | el->ensuresConstraints); | |
2165 | } | |
2166 | end_exprNodeList_elements; | |
2167 | ||
2168 | } | |
2169 | ||
2170 | /*drl moved out of constraintResolve.c 07-03-001 */ | |
2171 | constraintList exprNode_getPostConditions (exprNode fcn, exprNodeList arglist, exprNode fcnCall) | |
2172 | { | |
2173 | constraintList postconditions; | |
2174 | uentry temp; | |
abd7f895 | 2175 | DPRINTF((message ("Got call that %s (%s) ", exprNode_unparse(fcn), exprNodeList_unparse (arglist)))); |
28bf4b0b | 2176 | |
2177 | temp = exprNode_getUentry (fcn); | |
2178 | ||
2179 | postconditions = uentry_getFcnPostconditions (temp); | |
2180 | ||
ccf0a4a8 | 2181 | if (constraintList_isDefined (postconditions)) |
28bf4b0b | 2182 | { |
2183 | postconditions = constraintList_doSRefFixConstraintParam (postconditions, arglist); | |
2184 | postconditions = constraintList_doFixResult (postconditions, fcnCall); | |
2185 | } | |
2186 | else | |
2187 | { | |
2188 | postconditions = constraintList_makeNew(); | |
2189 | } | |
2190 | ||
2191 | return postconditions; | |
2192 | } | |
2193 | ||
86d93ed3 | 2194 | /* |
2195 | comment this out for now | |
2196 | we'll include it in a production release when its stable... | |
2197 | ||
abd7f895 | 2198 | void findStructs (exprNodeList arglist) |
86d93ed3 | 2199 | { |
2200 | ||
2201 | ctype ct, rt; | |
2202 | ||
24633cea | 2203 | DPRINTF(( |
abd7f895 | 2204 | message("doing findStructs: %s", exprNodeList_unparse(arglist)) |
2205 | )); | |
86d93ed3 | 2206 | |
2207 | ||
2208 | exprNodeList_elements(arglist, expr) | |
2209 | { | |
2210 | ct = exprNode_getType(expr); | |
2211 | ||
2212 | rt = ctype_realType (ct); | |
2213 | ||
abd7f895 | 2214 | if (ctype_isStruct (rt)) |
8f58355a | 2215 | DPRINTF((message("Found structure %s", exprNode_unparse(expr)) |
abd7f895 | 2216 | )); |
2217 | if (hasInvariants(ct)) | |
86d93ed3 | 2218 | { |
2219 | constraintList invars; | |
2220 | ||
2221 | invars = getInvariants(ct); | |
2222 | ||
2223 | ||
8f58355a | 2224 | DPRINTF((message ("findStructs has invariants %s ", constraintList_unparse (invars)) |
abd7f895 | 2225 | )); |
86d93ed3 | 2226 | |
abd7f895 | 2227 | invars = constraintList_doSRefFixStructConstraint(invars, exprNode_getSref(expr), ct); |
86d93ed3 | 2228 | |
2229 | ||
8f58355a | 2230 | DPRINTF((message ("findStructs finded invariants to be %s ", constraintList_unparse (invars)) |
abd7f895 | 2231 | )); |
86d93ed3 | 2232 | } |
2233 | } | |
2234 | end_exprNodeList_elements; | |
2235 | } | |
2236 | ||
2237 | */ | |
28bf4b0b | 2238 | |
2239 | /*drl moved out of constraintResolve.c 07-02-001 */ | |
2240 | constraintList checkCall (/*@dependent@*/ exprNode fcn, exprNodeList arglist) | |
2241 | { | |
2242 | constraintList preconditions; | |
2243 | uentry temp; | |
abd7f895 | 2244 | DPRINTF((message ("Got call that %s (%s) ", exprNode_unparse(fcn), exprNodeList_unparse (arglist)))); |
28bf4b0b | 2245 | |
2246 | temp = exprNode_getUentry (fcn); | |
2247 | ||
2248 | preconditions = uentry_getFcnPreconditions (temp); | |
2249 | ||
abd7f895 | 2250 | if (constraintList_isDefined(preconditions)) |
28bf4b0b | 2251 | { |
2252 | preconditions = constraintList_togglePost (preconditions); | |
2253 | preconditions = constraintList_preserveCallInfo(preconditions, fcn); | |
2254 | preconditions = constraintList_doSRefFixConstraintParam (preconditions, arglist); | |
2255 | } | |
2256 | else | |
2257 | { | |
abd7f895 | 2258 | if (constraintList_isUndefined(preconditions)) |
28bf4b0b | 2259 | preconditions = constraintList_makeNew(); |
2260 | } | |
312c9815 | 2261 | |
6317f163 | 2262 | if (context_getFlag (FLG_IMPBOUNDSCONSTRAINTS)) |
312c9815 | 2263 | { |
4287634e | 2264 | |
2265 | /* | |
2266 | uentryList_elements (arglist, el) | |
312c9815 | 2267 | { |
4287634e | 2268 | sRef s; |
8f58355a | 2269 | DPRINTF((message("setImplicitfcnConstraints doing: %s", uentry_unparse(el) ) )); |
312c9815 | 2270 | |
2271 | s = uentry_getSref(el); | |
2272 | if (sRef_isReference (s) ) | |
2273 | { | |
8f58355a | 2274 | DPRINTF((message ("%s is a pointer", sRef_unparse(s) ) )); |
312c9815 | 2275 | } |
2276 | else | |
2277 | { | |
8f58355a | 2278 | DPRINTF((message ("%s is NOT a pointer", sRef_unparse(s) ) )); |
312c9815 | 2279 | } |
2280 | //drl 4/26/01 | |
2281 | //chagned this from MaxSet(s) == 0 to MaxSet(s) >= 0 | |
2282 | c = constraint_makeSRefWriteSafeInt (s, 0); | |
2283 | ||
2284 | implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c); | |
2285 | ||
2286 | //drl 10/23/2002 added support for out | |
2287 | if (!uentry_isOut(el) ) | |
2288 | { | |
2289 | c = constraint_makeSRefReadSafeInt (s, 0); | |
312c9815 | 2290 | implicitFcnConstraints = constraintList_add(implicitFcnConstraints , c); |
2291 | } | |
4287634e | 2292 | |
312c9815 | 2293 | |
2294 | } | |
4287634e | 2295 | */ |
312c9815 | 2296 | } |
4287634e | 2297 | |
abd7f895 | 2298 | DPRINTF ((message("Done checkCall\n"))); |
9a48d98c | 2299 | DPRINTF ((message("Returning list %q ", constraintList_unparseDetailed(preconditions)))); |
86d93ed3 | 2300 | |
2301 | /* | |
2302 | drl we're going to comment this out for now | |
2303 | we'll include it if we're sure it's working | |
2304 | ||
2305 | findStructs(arglist); | |
2306 | */ | |
2307 | ||
28bf4b0b | 2308 | return preconditions; |
2309 | } | |
e5f31c00 | 2310 | |
2311 | /*drl added this function 10.29.001 | |
2312 | takes an exprNode of the form const + const | |
2313 | and sets the value | |
2314 | */ | |
2315 | /*drl | |
2316 | I'm a bit nervous about modifying the exprNode | |
2317 | but this is the easy way to do this | |
2318 | If I have time I'd like to cause the exprNode to get created correctly in the first place */ | |
abd7f895 | 2319 | void exprNode_findValue(exprNode e) |
e5f31c00 | 2320 | { |
2321 | exprData data; | |
2322 | ||
2323 | exprNode t1, t2; | |
2324 | lltok tok; | |
2325 | ||
965143f0 | 2326 | llassert(exprNode_isDefined(e) ); |
2327 | ||
e5f31c00 | 2328 | data = e->edata; |
2329 | ||
abd7f895 | 2330 | if (exprNode_hasValue(e)) |
e5f31c00 | 2331 | return; |
2332 | ||
2333 | if (e->kind == XPR_OP) | |
2334 | { | |
2335 | t1 = exprData_getOpA (data); | |
2336 | t2 = exprData_getOpB (data); | |
2337 | tok = exprData_getOpTok (data); | |
2338 | ||
2339 | exprNode_findValue(t1); | |
2340 | exprNode_findValue(t2); | |
2341 | ||
abd7f895 | 2342 | if (!(exprNode_knownIntValue(t1) && (exprNode_knownIntValue(t2)))) |
e5f31c00 | 2343 | return; |
2344 | ||
abd7f895 | 2345 | if (lltok_isPlus_Op (tok)) |
e5f31c00 | 2346 | { |
2347 | long v1, v2; | |
2348 | ||
2349 | v1 = exprNode_getLongValue(t1); | |
2350 | v2 = exprNode_getLongValue(t2); | |
2351 | ||
abd7f895 | 2352 | if (multiVal_isDefined(e->val)) |
e5f31c00 | 2353 | multiVal_free (e->val); |
2354 | ||
2355 | e->val = multiVal_makeInt (v1 + v2); | |
2356 | } | |
2357 | ||
abd7f895 | 2358 | if (lltok_isMinus_Op (tok)) |
e5f31c00 | 2359 | { |
2360 | long v1, v2; | |
2361 | ||
2362 | v1 = exprNode_getLongValue(t1); | |
2363 | v2 = exprNode_getLongValue(t2); | |
2364 | ||
abd7f895 | 2365 | if (multiVal_isDefined(e->val)) |
2366 | { | |
2367 | multiVal_free (e->val); | |
2368 | } | |
e5f31c00 | 2369 | |
2370 | e->val = multiVal_makeInt (v1 - v2); | |
2371 | } | |
2372 | ||
2373 | /*drl I should really do * and / at some point */ | |
2374 | ||
2375 | } | |
2376 | ||
2377 | } | |
2378 |