]>
Commit | Line | Data |
---|---|---|
4cccc6ad | 1 | |
2 | /* | |
3 | ** constraintList.c | |
4 | */ | |
5 | ||
6 | # include <ctype.h> /* for isdigit */ | |
7 | # include "lclintMacros.nf" | |
8 | # include "basic.h" | |
9 | # include "cgrammar.h" | |
10 | # include "cgrammar_tokens.h" | |
11 | ||
12 | # include "exprChecks.h" | |
13 | # include "aliasChecks.h" | |
14 | # include "exprNodeSList.h" | |
15 | # include "exprData.i" | |
16 | ||
17 | void /*@alt bool@*/ exprNode_generateConstraints (/*@temp@*/ exprNode e); | |
18 | static bool exprNode_handleError( exprNode p_e); | |
19 | ||
361091cc | 20 | //static cstring exprNode_findConstraints ( exprNode p_e); |
4cccc6ad | 21 | static bool exprNode_isMultiStatement(exprNode p_e); |
22 | static bool exprNode_multiStatement (exprNode p_e); | |
23 | bool exprNode_exprTraverse (exprNode e, bool definatelv, bool definaterv, fileloc sequencePoint); | |
361091cc | 24 | //static void exprNode_constraintPropagateUp (exprNode p_e); |
25 | constraintList exprNode_traversRequiresConstraints (exprNode e); | |
26 | constraintList exprNode_traversEnsuresConstraints (exprNode e); | |
27 | void mergeResolve (exprNode parent, exprNode child1, exprNode child2); | |
4cccc6ad | 28 | |
29 | ||
361091cc | 30 | |
4cccc6ad | 31 | bool exprNode_isUnhandled (exprNode e) |
32 | { | |
33 | llassert( exprNode_isDefined(e) ); | |
34 | switch (e->kind) | |
35 | { | |
36 | case XPR_INITBLOCK: | |
37 | case XPR_EMPTY: | |
38 | case XPR_LABEL: | |
39 | case XPR_CONST: | |
40 | case XPR_VAR: | |
41 | case XPR_BODY: | |
42 | case XPR_OFFSETOF: | |
43 | case XPR_ALIGNOFT: | |
44 | case XPR_ALIGNOF: | |
45 | case XPR_VAARG: | |
46 | case XPR_ITERCALL: | |
47 | case XPR_ITER: | |
48 | case XPR_CAST: | |
49 | case XPR_GOTO: | |
50 | case XPR_CONTINUE: | |
51 | case XPR_BREAK: | |
52 | case XPR_COMMA: | |
53 | case XPR_COND: | |
54 | case XPR_TOK: | |
55 | case XPR_FTDEFAULT: | |
56 | case XPR_DEFAULT: | |
57 | case XPR_SWITCH: | |
58 | case XPR_FTCASE: | |
59 | case XPR_CASE: | |
60 | case XPR_INIT: | |
61 | case XPR_NODE: | |
62 | DPRINTF((message ("Warning current constraint generation does not handle expression %s", exprNode_unparse(e)) ) ); | |
63 | return FALSE; | |
64 | /*@notreached@*/ | |
65 | break; | |
66 | default: | |
67 | return TRUE; | |
68 | ||
69 | } | |
70 | /*not reached*/ | |
71 | return FALSE; | |
72 | } | |
73 | ||
74 | bool exprNode_handleError( exprNode e) | |
75 | { | |
76 | if (exprNode_isError (e) || !exprNode_isUnhandled(e) ) | |
77 | { | |
78 | static /*@only@*/ cstring error = cstring_undefined; | |
79 | ||
80 | if (!cstring_isDefined (error)) | |
81 | { | |
82 | error = cstring_makeLiteral ("<error>"); | |
83 | } | |
84 | ||
85 | /*@-unqualifiedtrans*/ return TRUE; /*@=unqualifiedtrans*/ | |
86 | } | |
87 | return FALSE; | |
88 | } | |
89 | ||
90 | void /*@alt bool@*/ exprNode_generateConstraints (/*@temp@*/ exprNode e) | |
91 | { | |
92 | DPRINTF((message ("exprNode_gnerateConstraints Analysising %s %s at", exprNode_unparse( e), | |
93 | fileloc_unparse(exprNode_getfileloc(e) ) ) ) ); | |
94 | ||
95 | if (exprNode_isMultiStatement ( e) ) | |
96 | { | |
97 | return exprNode_multiStatement(e); | |
98 | } | |
99 | else | |
100 | { | |
101 | llassert(FALSE); | |
102 | } | |
103 | ||
104 | return FALSE; | |
105 | } | |
106 | ||
107 | ||
108 | /* handles multiple statements */ | |
109 | ||
110 | bool exprNode_isMultiStatement(exprNode e) | |
111 | { | |
112 | if (exprNode_handleError (e) != NULL) | |
113 | return FALSE; | |
114 | ||
115 | switch (e->kind) | |
116 | { | |
117 | case XPR_FOR: | |
118 | case XPR_FORPRED: | |
119 | case XPR_IF: | |
120 | case XPR_IFELSE: | |
121 | case XPR_WHILE: | |
122 | case XPR_WHILEPRED: | |
123 | case XPR_DOWHILE: | |
124 | case XPR_BLOCK: | |
125 | case XPR_STMT: | |
126 | case XPR_STMTLIST: | |
127 | return TRUE; | |
128 | default: | |
129 | return FALSE; | |
130 | } | |
131 | ||
132 | } | |
133 | ||
134 | bool exprNode_stmt (exprNode e) | |
135 | { | |
136 | exprNode snode; | |
361091cc | 137 | fileloc loc; |
138 | bool notError; | |
4cccc6ad | 139 | |
140 | if (exprNode_isError(e) ) | |
141 | { | |
142 | return FALSE; | |
143 | } | |
361091cc | 144 | e->requiresConstraints = constraintList_new(); |
145 | e->ensuresConstraints = constraintList_new(); | |
4cccc6ad | 146 | |
361091cc | 147 | |
148 | DPRINTF(( "STMT:") ); | |
149 | DPRINTF ( ( cstring_toCharsSafe ( exprNode_unparse(e)) ) | |
4cccc6ad | 150 | ); |
151 | if (e->kind != XPR_STMT) | |
152 | { | |
153 | ||
361091cc | 154 | DPRINTF (("Not Stmt") ); |
155 | DPRINTF ( (message ("%s ", exprNode_unparse (e)) ) ); | |
4cccc6ad | 156 | if (exprNode_isMultiStatement (e) ) |
157 | { | |
158 | return exprNode_multiStatement (e ); | |
159 | } | |
160 | llassert(FALSE); | |
161 | } | |
361091cc | 162 | |
163 | DPRINTF (("Stmt") ); | |
164 | DPRINTF ( (message ("%s ", exprNode_unparse (e)) ) ); | |
165 | ||
4cccc6ad | 166 | snode = exprData_getUopNode (e->edata); |
167 | ||
168 | /* could be stmt involving multiple statements: | |
169 | i.e. if, while for ect. | |
170 | */ | |
171 | ||
172 | if (exprNode_isMultiStatement (snode)) | |
173 | { | |
174 | llassert(FALSE); | |
175 | return exprNode_multiStatement (snode); | |
176 | } | |
361091cc | 177 | |
178 | loc = exprNode_getNextSequencePoint(e); /* reduces to an expression */ | |
179 | notError = exprNode_exprTraverse (snode, FALSE, FALSE, loc); | |
180 | e->requiresConstraints = exprNode_traversRequiresConstraints(snode); | |
181 | printf ("%s\n", constraintList_print(e->requiresConstraints) ); | |
182 | e->ensuresConstraints = exprNode_traversEnsuresConstraints(snode); | |
183 | printf ("Ensures that:\n %s\n", constraintList_print(e->ensuresConstraints) ); | |
184 | llassert(notError); | |
185 | return notError; | |
186 | ||
4cccc6ad | 187 | } |
188 | ||
189 | ||
190 | bool exprNode_stmtList (exprNode e) | |
191 | { | |
361091cc | 192 | exprNode stmt1, stmt2; |
4cccc6ad | 193 | if (exprNode_isError (e) ) |
194 | { | |
195 | return FALSE; | |
196 | } | |
361091cc | 197 | |
198 | e->requiresConstraints = constraintList_new(); | |
199 | e->ensuresConstraints = constraintList_new(); | |
200 | ||
4cccc6ad | 201 | /*Handle case of stmtList with only one statement: |
202 | The parse tree stores this as stmt instead of stmtList*/ | |
203 | if (e->kind != XPR_STMTLIST) | |
204 | { | |
205 | return exprNode_stmt(e); | |
206 | } | |
207 | llassert (e->kind == XPR_STMTLIST); | |
361091cc | 208 | DPRINTF(( "STMTLIST:") ); |
209 | DPRINTF ((cstring_toCharsSafe (exprNode_unparse(e)) ) ); | |
210 | stmt1 = exprData_getPairA (e->edata); | |
211 | stmt2 = exprData_getPairB (e->edata); | |
212 | ||
213 | ||
214 | exprNode_stmt (stmt1); | |
215 | DPRINTF(("\nstmt after stmtList call " )); | |
216 | ||
217 | exprNode_stmt (stmt2); | |
218 | ||
219 | mergeResolve (e, stmt1, stmt2 ); | |
220 | TPRINTF ( (message ("smtlist constraints are: pre: %s \n and \t post %s\n", | |
221 | constraintList_print(e->requiresConstraints), | |
222 | constraintList_print(e->ensuresConstraints) ) ) ); | |
223 | return TRUE; | |
4cccc6ad | 224 | } |
225 | ||
361091cc | 226 | |
4cccc6ad | 227 | bool exprNode_multiStatement (exprNode e) |
228 | { | |
229 | ||
230 | bool ret; | |
231 | exprData data; | |
232 | ||
233 | ||
234 | DPRINTF((message ("exprNode_multistatement Analysising %s %s at", exprNode_unparse( e), | |
235 | fileloc_unparse(exprNode_getfileloc(e) ) ) ) ); | |
236 | ||
237 | if (exprNode_handleError (e)) | |
238 | { | |
239 | return FALSE; | |
240 | } | |
241 | ||
242 | data = e->edata; | |
243 | ||
244 | ret = TRUE; | |
245 | ||
246 | switch (e->kind) | |
247 | { | |
248 | ||
249 | case XPR_FOR: | |
250 | // ret = message ("%s %s", | |
251 | exprNode_generateConstraints (exprData_getPairA (data)); | |
252 | exprNode_generateConstraints (exprData_getPairB (data)); | |
253 | break; | |
254 | ||
255 | case XPR_FORPRED: | |
256 | // ret = message ("for (%s; %s; %s)", | |
257 | exprNode_generateConstraints (exprData_getTripleInit (data)); | |
258 | exprNode_generateConstraints (exprData_getTripleTest (data)); | |
259 | exprNode_generateConstraints (exprData_getTripleInc (data)); | |
260 | break; | |
261 | case XPR_IF: | |
361091cc | 262 | DPRINTF(( "IF:") ); |
263 | DPRINTF ((exprNode_unparse(e) ) ); | |
4cccc6ad | 264 | // ret = message ("if (%s) %s", |
265 | exprNode_generateConstraints (exprData_getPairA (data)); | |
266 | exprNode_generateConstraints (exprData_getPairB (data)); | |
267 | // e->constraints = constraintList_exprNodemerge (exprData_getPairA (data),exprData_getPairB(data)); | |
268 | break; | |
269 | ||
270 | case XPR_IFELSE: | |
271 | // ret = message ("if (%s) %s else %s", | |
272 | exprNode_generateConstraints (exprData_getTriplePred (data)); | |
273 | exprNode_generateConstraints (exprData_getTripleTrue (data)); | |
274 | exprNode_generateConstraints (exprData_getTripleFalse (data)); | |
275 | break; | |
276 | case XPR_WHILE: | |
277 | // ret = message ("while (%s) %s", | |
278 | exprNode_generateConstraints (exprData_getPairA (data)); | |
279 | exprNode_generateConstraints (exprData_getPairB (data)); | |
280 | // e->constraints = constraintList_exprNodemerge (exprData_getPairA (data), exprData_getPairB (data) ); | |
281 | break; | |
282 | ||
283 | case XPR_WHILEPRED: | |
284 | // ret = | |
285 | // cstring_copy ( | |
286 | exprNode_generateConstraints (exprData_getSingle (data)); | |
287 | break; | |
288 | ||
289 | case XPR_DOWHILE: | |
290 | // ret = message ("do { %s } while (%s)", | |
291 | exprNode_generateConstraints (exprData_getPairB (data)); | |
292 | exprNode_generateConstraints (exprData_getPairA (data)); | |
293 | break; | |
294 | ||
295 | case XPR_BLOCK: | |
296 | // ret = message ("{ %s }", | |
297 | exprNode_generateConstraints (exprData_getSingle (data)); | |
361091cc | 298 | e->requiresConstraints = constraintList_copy ( (exprData_getSingle (data))->requiresConstraints ); |
299 | e->ensuresConstraints = constraintList_copy ( (exprData_getSingle (data))->ensuresConstraints ); | |
300 | // e->constraints = (exprData_getSingle (data))->constraints; | |
4cccc6ad | 301 | break; |
302 | ||
303 | case XPR_STMT: | |
304 | case XPR_STMTLIST: | |
305 | return exprNode_stmtList (e); | |
306 | /*@notreached@*/ | |
307 | break; | |
308 | default: | |
309 | ret=FALSE; | |
310 | } | |
311 | return ret; | |
312 | } | |
313 | ||
314 | ||
4cccc6ad | 315 | bool exprNode_exprTraverse (exprNode e, bool definatelv, bool definaterv, fileloc sequencePoint) |
316 | { | |
317 | exprNode t1, t2; | |
318 | ||
319 | bool handledExprNode; | |
4cccc6ad | 320 | exprData data; |
4cccc6ad | 321 | constraint cons; |
322 | ||
323 | DPRINTF((message ("exprNode_exprTraverset Analysising %s %s at", exprNode_unparse( e), | |
324 | fileloc_unparse(exprNode_getfileloc(e) ) ) ) ); | |
361091cc | 325 | |
326 | e->requiresConstraints = constraintList_new(); | |
327 | e->ensuresConstraints = constraintList_new(); | |
4cccc6ad | 328 | |
329 | if (exprNode_handleError (e)) | |
330 | { | |
331 | return FALSE; | |
332 | } | |
333 | ||
334 | handledExprNode = TRUE; | |
335 | ||
336 | data = e->edata; | |
337 | ||
338 | switch (e->kind) | |
339 | { | |
340 | ||
341 | case XPR_FETCH: | |
342 | ||
4cccc6ad | 343 | if (definatelv ) |
344 | { | |
345 | t1 = (exprData_getPairA (data) ); | |
346 | t2 = (exprData_getPairB (data) ); | |
361091cc | 347 | cons = constraint_makeWriteSafeExprNode (t1, t2); |
4cccc6ad | 348 | } |
349 | else | |
350 | { | |
351 | t1 = (exprData_getPairA (data) ); | |
352 | t2 = (exprData_getPairB (data) ); | |
361091cc | 353 | cons = constraint_makeReadSafeExprNode (t1, t2 ); |
4cccc6ad | 354 | } |
361091cc | 355 | |
356 | e->requiresConstraints = constraintList_add(e->requiresConstraints, cons); | |
4cccc6ad | 357 | cons = constraint_makeEnsureMaxReadAtLeast (t1, t2, sequencePoint); |
361091cc | 358 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); |
4cccc6ad | 359 | cons = constraint_makeEnsureMinReadAtMost (t1, t2, sequencePoint); |
361091cc | 360 | e->ensuresConstraints = constraintList_add(e->ensuresConstraints, cons); |
361 | ||
4cccc6ad | 362 | exprNode_exprTraverse (exprData_getPairA (data), FALSE, TRUE, sequencePoint); |
363 | exprNode_exprTraverse (exprData_getPairB (data), FALSE, TRUE, sequencePoint); | |
364 | ||
365 | /*@i325 Should check which is array/index. */ | |
4cccc6ad | 366 | break; |
367 | case XPR_PREOP: | |
368 | t1 = exprData_getUopNode(data); | |
369 | lltok_unparse (exprData_getUopTok (data)); | |
370 | exprNode_exprTraverse (exprData_getUopNode (data), definatelv, definaterv, sequencePoint ); | |
371 | /*handle * pointer access */ | |
372 | ||
373 | /*@ i 325 do ++ and -- */ | |
374 | if (lltok_isMult( exprData_getUopTok (data) ) ) | |
375 | { | |
376 | if (definatelv) | |
377 | { | |
361091cc | 378 | cons = constraint_makeWriteSafeInt (t1, 0); |
4cccc6ad | 379 | } |
380 | else | |
381 | { | |
382 | cons = constraint_makeReadSafeInt (t1, 0); | |
4cccc6ad | 383 | } |
361091cc | 384 | e->requiresConstraints = constraintList_add(e->requiresConstraints, cons); |
385 | } | |
386 | if (lltok_isInc_Op (exprData_getUopTok (data) ) ) | |
387 | { | |
388 | // cons = constraint_makeSideEffectPostIncrement (t1, sequencePoint); | |
389 | // e->ensuresConstraints = constraintList_add(e->requiresConstraints, cons); | |
4cccc6ad | 390 | } |
4cccc6ad | 391 | break; |
392 | ||
393 | case XPR_PARENS: | |
394 | exprNode_exprTraverse (exprData_getUopNode (e->edata), definatelv, definaterv, sequencePoint); | |
361091cc | 395 | // e->constraints = constraintList_exprNodemerge (exprData_getUopNode (e->edata), exprNode_undefined); |
4cccc6ad | 396 | break; |
397 | case XPR_ASSIGN: | |
398 | exprNode_exprTraverse (exprData_getOpA (data), TRUE, definaterv, sequencePoint ); | |
399 | lltok_unparse (exprData_getOpTok (data)); | |
400 | exprNode_exprTraverse (exprData_getOpB (data), definatelv, TRUE, sequencePoint ); | |
361091cc | 401 | // e->constraints = constraintList_exprNodemerge (exprData_getOpA (data), exprData_getOpB (data) ); |
4cccc6ad | 402 | break; |
403 | case XPR_OP: | |
404 | exprNode_exprTraverse (exprData_getOpA (data), definatelv, definaterv, sequencePoint ); | |
405 | lltok_unparse (exprData_getOpTok (data)); | |
406 | exprNode_exprTraverse (exprData_getOpB (data), definatelv, definaterv, sequencePoint ); | |
407 | ||
361091cc | 408 | // e->constraints = constraintList_exprNodemerge (exprData_getOpA (data), exprData_getOpB (data)); |
4cccc6ad | 409 | break; |
410 | case XPR_SIZEOFT: | |
411 | ctype_unparse (qtype_getType (exprData_getType (data) ) ); | |
412 | ||
413 | break; | |
414 | ||
415 | case XPR_SIZEOF: | |
416 | exprNode_exprTraverse (exprData_getSingle (data), definatelv, definaterv, sequencePoint ); | |
361091cc | 417 | // e->constraints = constraintList_exprNodemerge (exprData_getSingle (e->edata), exprNode_undefined); |
4cccc6ad | 418 | break; |
419 | ||
420 | case XPR_CALL: | |
421 | exprNode_exprTraverse (exprData_getFcn (data), definatelv, definaterv, sequencePoint ); | |
422 | exprNodeList_unparse (exprData_getArgs (data) ); | |
423 | // e->constraints = constraintList_add (e->constraints, constraint_create (e,exprNode_undefined, GT, CALLSAFE ) ); | |
424 | break; | |
425 | ||
426 | case XPR_RETURN: | |
427 | exprNode_exprTraverse (exprData_getSingle (data), definatelv, definaterv, sequencePoint ); | |
428 | break; | |
429 | ||
430 | case XPR_NULLRETURN: | |
431 | cstring_makeLiteral ("return");; | |
432 | break; | |
433 | ||
434 | ||
435 | case XPR_FACCESS: | |
436 | exprNode_exprTraverse (exprData_getFieldNode (data), definatelv, definaterv, sequencePoint ); | |
437 | exprData_getFieldName (data) ; | |
438 | break; | |
439 | ||
440 | case XPR_ARROW: | |
441 | exprNode_exprTraverse (exprData_getFieldNode (data), definatelv, definaterv, sequencePoint ); | |
442 | exprData_getFieldName (data); | |
443 | break; | |
444 | ||
445 | case XPR_STRINGLITERAL: | |
446 | cstring_copy (exprData_getLiteral (data)); | |
447 | break; | |
448 | ||
449 | case XPR_NUMLIT: | |
450 | cstring_copy (exprData_getLiteral (data)); | |
451 | break; | |
452 | case XPR_POSTOP: | |
453 | ||
454 | exprNode_exprTraverse (exprData_getUopNode (data), TRUE, definaterv, sequencePoint ); | |
455 | lltok_unparse (exprData_getUopTok (data)); | |
4cccc6ad | 456 | if (lltok_isInc_Op (exprData_getUopTok (data) ) ) |
457 | { | |
361091cc | 458 | TPRINTF(("doing ++")); |
4cccc6ad | 459 | t1 = exprData_getUopNode (data); |
361091cc | 460 | cons = constraint_makeMaxSetSideEffectPostIncrement (t1, sequencePoint ); |
461 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); | |
462 | cons = constraint_makeMaxReadSideEffectPostIncrement (t1, sequencePoint ); | |
463 | e->ensuresConstraints = constraintList_add (e->ensuresConstraints, cons); | |
4cccc6ad | 464 | } |
465 | break; | |
466 | default: | |
467 | handledExprNode = FALSE; | |
468 | } | |
469 | ||
470 | return handledExprNode; | |
471 | } | |
472 | ||
361091cc | 473 | /* walk down the tree and get all requires Constraints in each subexpression*/ |
474 | constraintList exprNode_traversRequiresConstraints (exprNode e) | |
475 | { | |
476 | // exprNode t1, t2; | |
477 | ||
478 | bool handledExprNode; | |
479 | // char * mes; | |
480 | exprData data; | |
481 | constraintList ret; | |
482 | ret = constraintList_copy (e->requiresConstraints ); | |
483 | if (exprNode_handleError (e)) | |
484 | { | |
485 | return ret; | |
486 | } | |
487 | ||
488 | handledExprNode = TRUE; | |
489 | ||
490 | data = e->edata; | |
491 | ||
492 | switch (e->kind) | |
493 | { | |
494 | ||
495 | case XPR_FETCH: | |
496 | ||
497 | ret = constraintList_addList (ret, | |
498 | exprNode_traversRequiresConstraints | |
499 | (exprData_getPairA (data) ) ); | |
500 | ||
501 | ret = constraintList_addList (ret, | |
502 | exprNode_traversRequiresConstraints | |
503 | (exprData_getPairB (data) ) ); | |
504 | break; | |
505 | case XPR_PREOP: | |
506 | ||
507 | ret = constraintList_addList (ret, | |
508 | exprNode_traversRequiresConstraints | |
509 | (exprData_getUopNode (data) ) ); | |
510 | break; | |
511 | ||
512 | case XPR_PARENS: | |
513 | ret = constraintList_addList (ret, exprNode_traversRequiresConstraints | |
514 | (exprData_getUopNode (data) ) ); | |
515 | break; | |
516 | case XPR_ASSIGN: | |
517 | ret = constraintList_addList (ret, | |
518 | exprNode_traversRequiresConstraints | |
519 | (exprData_getOpA (data) ) ); | |
520 | ||
521 | ret = constraintList_addList (ret, | |
522 | exprNode_traversRequiresConstraints | |
523 | (exprData_getOpB (data) ) ); | |
524 | break; | |
525 | case XPR_OP: | |
526 | ret = constraintList_addList (ret, | |
527 | exprNode_traversRequiresConstraints | |
528 | (exprData_getOpA (data) ) ); | |
529 | ||
530 | ret = constraintList_addList (ret, | |
531 | exprNode_traversRequiresConstraints | |
532 | (exprData_getOpB (data) ) ); | |
533 | break; | |
534 | case XPR_SIZEOFT: | |
535 | ||
536 | // ctype_unparse (qtype_getType (exprData_getType (data) ) ); | |
537 | ||
538 | break; | |
539 | ||
540 | case XPR_SIZEOF: | |
541 | ||
542 | ret = constraintList_addList (ret, | |
543 | exprNode_traversRequiresConstraints | |
544 | (exprData_getSingle (data) ) ); | |
545 | break; | |
546 | ||
547 | case XPR_CALL: | |
548 | ret = constraintList_addList (ret, | |
549 | exprNode_traversRequiresConstraints | |
550 | (exprData_getFcn (data) ) ); | |
551 | /*@i11*/ // exprNodeList_unparse (exprData_getArgs (data) ); | |
552 | break; | |
553 | ||
554 | case XPR_RETURN: | |
555 | ret = constraintList_addList (ret, | |
556 | exprNode_traversRequiresConstraints | |
557 | (exprData_getSingle (data) ) ); | |
558 | break; | |
559 | ||
560 | case XPR_NULLRETURN: | |
561 | // cstring_makeLiteral ("return");; | |
562 | break; | |
563 | ||
564 | case XPR_FACCESS: | |
565 | ret = constraintList_addList (ret, | |
566 | exprNode_traversRequiresConstraints | |
567 | (exprData_getFieldNode (data) ) ); | |
568 | //exprData_getFieldName (data) ; | |
569 | break; | |
570 | ||
571 | case XPR_ARROW: | |
572 | ret = constraintList_addList (ret, | |
573 | exprNode_traversRequiresConstraints | |
574 | (exprData_getFieldNode (data) ) ); | |
575 | // exprData_getFieldName (data); | |
576 | break; | |
577 | ||
578 | case XPR_STRINGLITERAL: | |
579 | // cstring_copy (exprData_getLiteral (data)); | |
580 | break; | |
581 | ||
582 | case XPR_NUMLIT: | |
583 | // cstring_copy (exprData_getLiteral (data)); | |
584 | break; | |
585 | case XPR_POSTOP: | |
586 | ||
587 | ret = constraintList_addList (ret, | |
588 | exprNode_traversRequiresConstraints | |
589 | (exprData_getUopNode (data) ) ); | |
590 | break; | |
591 | default: | |
592 | break; | |
593 | } | |
594 | ||
595 | return ret; | |
596 | } | |
597 | ||
598 | ||
599 | /* walk down the tree and get all Ensures Constraints in each subexpression*/ | |
600 | constraintList exprNode_traversEnsuresConstraints (exprNode e) | |
601 | { | |
602 | // exprNode t1, t2; | |
603 | ||
604 | bool handledExprNode; | |
605 | // char * mes; | |
606 | exprData data; | |
607 | // constraintExpr tmp; | |
608 | // constraint cons; | |
609 | constraintList ret; | |
610 | ret = constraintList_copy (e->ensuresConstraints ); | |
611 | if (exprNode_handleError (e)) | |
612 | { | |
613 | return ret; | |
614 | } | |
615 | ||
616 | handledExprNode = TRUE; | |
617 | ||
618 | data = e->edata; | |
619 | ||
620 | DPRINTF( (message ( | |
621 | "exprnode_traversEnsuresConstraints call for %s with constraintList of %s", | |
622 | exprNode_unparse (e), | |
623 | constraintList_print(e->ensuresConstraints) | |
624 | ) | |
625 | )); | |
626 | ||
627 | ||
628 | switch (e->kind) | |
629 | { | |
630 | ||
631 | case XPR_FETCH: | |
632 | ||
633 | ret = constraintList_addList (ret, | |
634 | exprNode_traversEnsuresConstraints | |
635 | (exprData_getPairA (data) ) ); | |
636 | ||
637 | ret = constraintList_addList (ret, | |
638 | exprNode_traversEnsuresConstraints | |
639 | (exprData_getPairB (data) ) ); | |
640 | break; | |
641 | case XPR_PREOP: | |
642 | ||
643 | ret = constraintList_addList (ret, | |
644 | exprNode_traversEnsuresConstraints | |
645 | (exprData_getUopNode (data) ) ); | |
646 | break; | |
647 | ||
648 | case XPR_PARENS: | |
649 | ret = constraintList_addList (ret, exprNode_traversEnsuresConstraints | |
650 | (exprData_getUopNode (data) ) ); | |
651 | break; | |
652 | case XPR_ASSIGN: | |
653 | ret = constraintList_addList (ret, | |
654 | exprNode_traversEnsuresConstraints | |
655 | (exprData_getOpA (data) ) ); | |
656 | ||
657 | ret = constraintList_addList (ret, | |
658 | exprNode_traversEnsuresConstraints | |
659 | (exprData_getOpB (data) ) ); | |
660 | break; | |
661 | case XPR_OP: | |
662 | ret = constraintList_addList (ret, | |
663 | exprNode_traversEnsuresConstraints | |
664 | (exprData_getOpA (data) ) ); | |
665 | ||
666 | ret = constraintList_addList (ret, | |
667 | exprNode_traversEnsuresConstraints | |
668 | (exprData_getOpB (data) ) ); | |
669 | break; | |
670 | case XPR_SIZEOFT: | |
671 | ||
672 | // ctype_unparse (qtype_getType (exprData_getType (data) ) ); | |
673 | ||
674 | break; | |
675 | ||
676 | case XPR_SIZEOF: | |
677 | ||
678 | ret = constraintList_addList (ret, | |
679 | exprNode_traversEnsuresConstraints | |
680 | (exprData_getSingle (data) ) ); | |
681 | break; | |
682 | ||
683 | case XPR_CALL: | |
684 | ret = constraintList_addList (ret, | |
685 | exprNode_traversEnsuresConstraints | |
686 | (exprData_getFcn (data) ) ); | |
687 | /*@i11*/ // exprNodeList_unparse (exprData_getArgs (data) ); | |
688 | break; | |
689 | ||
690 | case XPR_RETURN: | |
691 | ret = constraintList_addList (ret, | |
692 | exprNode_traversEnsuresConstraints | |
693 | (exprData_getSingle (data) ) ); | |
694 | break; | |
695 | ||
696 | case XPR_NULLRETURN: | |
697 | // cstring_makeLiteral ("return");; | |
698 | break; | |
699 | ||
700 | case XPR_FACCESS: | |
701 | ret = constraintList_addList (ret, | |
702 | exprNode_traversEnsuresConstraints | |
703 | (exprData_getFieldNode (data) ) ); | |
704 | //exprData_getFieldName (data) ; | |
705 | break; | |
706 | ||
707 | case XPR_ARROW: | |
708 | ret = constraintList_addList (ret, | |
709 | exprNode_traversEnsuresConstraints | |
710 | (exprData_getFieldNode (data) ) ); | |
711 | // exprData_getFieldName (data); | |
712 | break; | |
713 | ||
714 | case XPR_STRINGLITERAL: | |
715 | // cstring_copy (exprData_getLiteral (data)); | |
716 | break; | |
717 | ||
718 | case XPR_NUMLIT: | |
719 | // cstring_copy (exprData_getLiteral (data)); | |
720 | break; | |
721 | case XPR_POSTOP: | |
722 | ||
723 | ret = constraintList_addList (ret, | |
724 | exprNode_traversEnsuresConstraints | |
725 | (exprData_getUopNode (data) ) ); | |
726 | break; | |
727 | default: | |
728 | break; | |
729 | } | |
730 | DPRINTF( (message ( | |
731 | "exprnode_traversEnsuresConstraints call for %s with constraintList of is returning %s", | |
732 | exprNode_unparse (e), | |
733 | // constraintList_print(e->ensuresConstraints), | |
734 | constraintList_print(ret) | |
735 | ) | |
736 | )); | |
737 | ||
738 | ||
739 | return ret; | |
740 | } | |
741 |