Some consistency changes to library & headers flags.
[splint-patched.git] / src / exprData.c
blobd23443f17bb35d0fea296f72091f82a4b777b6d9
1 /*
2 ** exprData.c
3 */
5 # include "splintMacros.nf"
6 # include "basic.h"
8 void exprData_freeShallow (/*@only@*/ exprData data, exprKind kind)
10 /*@-compdestroy@*/
12 if (data == exprData_undefined)
14 return;
17 switch (kind)
19 case XPR_INITBLOCK:
20 case XPR_CALL:
21 exprNode_freeShallow (data->call->fcn);
22 exprNodeList_freeShallow (data->call->args);
23 sfree (data->call);
24 break;
25 case XPR_COMMA:
26 case XPR_FETCH:
27 case XPR_OP:
28 case XPR_ASSIGN:
29 case XPR_IF:
30 case XPR_WHILE:
31 case XPR_DOWHILE:
32 case XPR_STMTLIST:
33 case XPR_SWITCH:
34 case XPR_FOR:
35 exprNode_freeShallow (data->op->a);
36 exprNode_freeShallow (data->op->b);
37 sfree (data->op);
38 break;
40 case XPR_STMT:
41 case XPR_PREOP:
42 case XPR_POSTOP:
43 case XPR_PARENS:
44 exprNode_freeShallow (data->uop->a);
45 sfree (data->uop);
46 break;
48 case XPR_FTCASE:
49 case XPR_CASE:
50 case XPR_RETURN:
51 case XPR_WHILEPRED:
52 case XPR_BLOCK:
53 exprNode_freeShallow (data->single);
54 break;
56 case XPR_CAST:
57 case XPR_VAARG:
58 exprNode_freeShallow (data->cast->exp);
59 /* NO: qtype_free (data->cast->q); */
60 sfree (data->cast);
61 break;
63 case XPR_ITERCALL:
64 exprNodeList_freeShallow (data->itercall->args);
65 sfree (data->itercall);
66 break;
68 case XPR_ITER:
69 exprNodeList_freeShallow (data->iter->args);
70 exprNode_freeShallow (data->iter->body);
71 sfree (data->iter);
72 break;
74 case XPR_FORPRED:
75 case XPR_COND:
76 case XPR_IFELSE:
77 exprNode_freeShallow (data->triple->pred);
78 exprNode_freeShallow (data->triple->tbranch);
79 exprNode_freeShallow (data->triple->fbranch);
80 sfree (data->triple);
81 break;
83 case XPR_INIT:
84 exprNode_freeShallow (data->init->exp);
85 /* NO: idDecl_free (data->init->id); */
86 sfree (data->init);
87 break;
89 case XPR_FACCESS:
90 case XPR_ARROW:
91 exprNode_freeShallow (data->field->rec);
92 /* NO: cstring_free (data->field->field); */
93 sfree (data->field);
94 break;
96 case XPR_LABEL:
97 case XPR_CONST:
98 case XPR_VAR:
99 break;
101 case XPR_OFFSETOF:
102 case XPR_ALIGNOFT:
103 case XPR_ALIGNOF:
104 case XPR_SIZEOFT:
105 case XPR_SIZEOF:
106 case XPR_GOTO:
107 case XPR_CONTINUE:
108 case XPR_BREAK:
109 case XPR_NULLRETURN:
110 case XPR_TOK:
111 case XPR_FTDEFAULT:
112 case XPR_DEFAULT:
113 break;
115 case XPR_STRINGLITERAL:
116 case XPR_NUMLIT:
117 llcontbuglit ("exprData_freeShallow: not shallow!");
118 break;
120 case XPR_EMPTY:
121 llcontbuglit ("XPR_EMPTY case!");
122 break;
124 case XPR_BODY:
125 llcontbuglit ("XPR_BODY case!");
126 break;
127 case XPR_NODE:
128 llcontbuglit ("XPR_NODE case!");
129 break;
132 sfree (data);
133 /*@=compdestroy@*/
136 void exprData_free (/*@only@*/ exprData data, exprKind kind)
138 if (data == exprData_undefined)
140 return;
143 switch (kind)
145 case XPR_INITBLOCK:
146 case XPR_CALL:
147 exprNode_free (data->call->fcn);
148 exprNodeList_free (data->call->args);
149 sfree (data->call);
150 break;
152 case XPR_LABEL:
153 case XPR_CONST:
154 case XPR_VAR:
155 cstring_free (data->id);
156 break;
158 case XPR_COMMA:
159 case XPR_FETCH:
160 case XPR_OP:
161 case XPR_ASSIGN:
162 case XPR_IF:
163 case XPR_WHILE:
164 case XPR_DOWHILE:
165 case XPR_STMTLIST:
166 case XPR_SWITCH:
167 case XPR_FOR:
168 exprNode_free (data->op->a);
169 exprNode_free (data->op->b);
170 sfree (data->op);
171 break;
173 case XPR_STMT:
174 case XPR_PREOP:
175 case XPR_POSTOP:
176 case XPR_PARENS:
177 exprNode_free (data->uop->a);
178 sfree (data->uop);
179 break;
181 case XPR_OFFSETOF:
182 qtype_free (data->offset->q);
183 cstringList_free (data->offset->field);
184 sfree (data->offset);
185 break;
187 case XPR_ALIGNOFT:
188 case XPR_SIZEOFT:
189 qtype_free (data->qt);
190 break;
192 case XPR_FTCASE:
193 case XPR_CASE:
194 case XPR_SIZEOF:
195 case XPR_ALIGNOF:
196 case XPR_RETURN:
197 case XPR_WHILEPRED:
198 case XPR_BLOCK:
199 exprNode_free (data->single);
200 break;
202 case XPR_CAST:
203 case XPR_VAARG:
204 exprNode_free (data->cast->exp);
205 qtype_free (data->cast->q);
206 sfree (data->cast);
207 break;
209 case XPR_ITERCALL:
210 exprNodeList_free (data->itercall->args);
211 sfree (data->itercall);
212 break;
214 case XPR_ITER:
215 exprNodeList_free (data->iter->args);
216 exprNode_free (data->iter->body);
217 sfree (data->iter);
218 break;
220 case XPR_FORPRED:
221 case XPR_COND:
222 case XPR_IFELSE:
223 exprNode_free (data->triple->pred);
224 exprNode_free (data->triple->tbranch);
225 exprNode_free (data->triple->fbranch);
226 sfree (data->triple);
227 break;
229 case XPR_GOTO:
230 case XPR_STRINGLITERAL:
231 case XPR_NUMLIT:
232 cstring_free (data->literal);
233 break;
235 case XPR_CONTINUE:
236 case XPR_BREAK:
237 case XPR_NULLRETURN:
238 break;
240 case XPR_FTDEFAULT:
241 case XPR_DEFAULT:
242 case XPR_TOK:
243 break;
245 case XPR_INIT:
246 exprNode_free (data->init->exp);
247 idDecl_free (data->init->id);
248 sfree (data->init);
249 break;
251 case XPR_FACCESS:
252 case XPR_ARROW:
253 exprNode_free (data->field->rec);
254 cstring_free (data->field->field);
255 sfree (data->field);
256 break;
258 case XPR_EMPTY:
259 llcontbuglit ("XPR_EMPTY case!");
260 break;
261 case XPR_BODY:
262 llcontbuglit ("XPR_BODY case!");
263 break;
264 case XPR_NODE:
265 llcontbuglit ("XPR_NODE case!");
266 break;
269 sfree (data);
272 /*@exposed@*/ exprNode exprData_getInitNode (exprData data) /*@*/
274 llassert (data != exprData_undefined);
275 return (data->init->exp);
278 /*@exposed@*/ idDecl exprData_getInitId (exprData data) /*@*/
280 llassert (data != exprData_undefined);
281 return (data->init->id);
284 /*@exposed@*/ exprNode exprData_getOpA (exprData data) /*@*/
286 llassert (data != exprData_undefined);
287 return (data->op->a);
290 /*@exposed@*/ exprNode exprData_getOpB (exprData data) /*@*/
292 llassertretval (data != exprData_undefined, exprNode_undefined);
293 return (data->op->b);
296 /*@observer@*/ lltok exprData_getOpTok (exprData data) /*@*/
298 llassert (data != exprData_undefined);
299 return (data->op->op);
302 /*@exposed@*/ exprNode exprData_getPairA (exprData data) /*@*/
304 llassertretval (data != exprData_undefined, exprNode_undefined);
305 return (data->pair->a);
308 /*@exposed@*/ exprNode exprData_getPairB (exprData data) /*@*/
310 llassertretval (data != exprData_undefined, exprNode_undefined);
311 return (data->pair->b);
314 /*@exposed@*/ uentry exprData_getIterSname (exprData data) /*@*/
316 llassertretval (data != exprData_undefined, uentry_undefined);
317 return (data->iter->sname);
320 /*@exposed@*/ exprNodeList exprData_getIterAlist (exprData data) /*@*/
322 llassert (data != exprData_undefined);
323 return (data->iter->args);
326 /*@exposed@*/ exprNode exprData_getIterBody (exprData data) /*@*/
328 llassertretval (data != exprData_undefined, exprNode_undefined);
329 return (data->iter->body);
332 /*@exposed@*/ uentry exprData_getIterEname (exprData data) /*@*/
334 llassertretval (data != exprData_undefined, uentry_undefined);
335 return (data->iter->ename);
338 /*@exposed@*/ exprNode exprData_getFcn (exprData data) /*@*/
340 llassertretval (data != exprData_undefined, exprNode_undefined);
341 return (data->call->fcn);
344 /*@exposed@*/ exprNodeList exprData_getArgs (exprData data) /*@*/
346 llassert (data != exprData_undefined);
347 return (data->call->args);
350 /*@exposed@*/ exprNode exprData_getTriplePred (exprData data) /*@*/
352 llassert (data != exprData_undefined);
353 return (data->triple->pred);
356 /*@exposed@*/ uentry exprData_getIterCallIter (exprData data) /*@*/
358 llassert (data != exprData_undefined);
359 return (data->itercall->iter);
362 /*@exposed@*/ exprNodeList
363 exprData_getIterCallArgs (exprData data) /*@*/
365 llassert (data != exprData_undefined);
366 return (data->itercall->args);
369 /*@exposed@*/ exprNode exprData_getTripleInit (exprData data) /*@*/
371 llassert (data != exprData_undefined);
372 return (data->triple->pred);
375 /*@exposed@*/ exprNode exprData_getTripleTrue (exprData data) /*@*/
377 llassert (data != exprData_undefined);
378 return (data->triple->tbranch);
381 /*@exposed@*/ exprNode exprData_getTripleTest (exprData data) /*@*/
383 llassert (data != exprData_undefined);
384 return (data->triple->tbranch);
387 /*@exposed@*/ exprNode exprData_getTripleFalse (exprData data) /*@*/
389 llassert (data != exprData_undefined);
390 return (data->triple->fbranch);
393 /*@exposed@*/ exprNode exprData_getTripleInc (exprData data) /*@*/
395 llassert (data != exprData_undefined);
396 return (data->triple->fbranch);
399 /*@exposed@*/ exprNode exprData_getFieldNode (exprData data) /*@*/
401 llassert (data != exprData_undefined);
402 return (data->field->rec);
405 /*@exposed@*/ cstring exprData_getFieldName (exprData data) /*@*/
407 llassert (data != exprData_undefined);
408 return (data->field->field);
411 /*@observer@*/ lltok exprData_getUopTok (exprData data) /*@*/
413 llassert (data != exprData_undefined);
414 return (data->uop->op);
417 /*@exposed@*/ exprNode exprData_getUopNode (exprData data) /*@*/
419 llassert (data != exprData_undefined);
420 return (data->uop->a);
423 /*@exposed@*/ exprNode exprData_getCastNode (exprData data) /*@*/
425 llassert (data != exprData_undefined);
426 return (data->cast->exp);
429 /*@observer@*/ lltok exprData_getCastTok (exprData data) /*@*/
431 llassert (data != exprData_undefined);
432 return (data->cast->tok);
435 /*@exposed@*/ qtype exprData_getCastType (exprData data) /*@*/
437 llassert (data != exprData_undefined);
438 return (data->cast->q);
441 /*@exposed@*/ cstring exprData_getLiteral (exprData data) /*@*/
443 llassert (data != exprData_undefined);
444 return (data->literal);
447 /*@exposed@*/ cstring exprData_getId (exprData data) /*@*/
449 llassert (data != exprData_undefined);
450 return (data->id);
453 /*@observer@*/ lltok exprData_getTok (exprData data) /*@*/
455 llassert (data != exprData_undefined);
456 return data->tok;
459 /*@exposed@*/ qtype exprData_getType (exprData data) /*@*/
461 llassert (data != exprData_undefined);
462 return (data->qt);
465 /*@exposed@*/ qtype exprData_getOffsetType (exprData data) /*@*/
467 llassert (data != exprData_undefined);
468 return (data->offset->q);
471 /*@exposed@*/ cstringList exprData_getOffsetName (exprData data) /*@*/
473 llassert (data != exprData_undefined);
474 return (data->offset->field);
477 /*@exposed@*/ exprNode exprData_getSingle (exprData data) /*@*/
479 exprNode ret;
480 llassert (data != exprData_undefined);
482 ret = data->single;
483 return (ret);
487 /*@only@*/ exprData
488 exprData_makeOp (/*@keep@*/ exprNode a, /*@keep@*/ exprNode b, /*@keep@*/ lltok op)
490 exprData ed = (exprData) dmalloc (sizeof (*ed));
492 ed->op = (exprOp) dmalloc (sizeof (*ed->op));
493 ed->op->a = a;
494 ed->op->b = b;
495 ed->op->op = op;
497 return ed;
500 /*@only@*/ exprData exprData_makeUop (/*@keep@*/ exprNode a, /*@keep@*/ lltok op)
502 exprData ed = (exprData) dmalloc (sizeof (*ed));
504 ed->uop = (exprUop) dmalloc (sizeof (*ed->uop));
505 ed->uop->a = a;
506 ed->uop->op = op;
508 return ed;
511 /*@only@*/ exprData exprData_makeSingle (/*@only@*/ exprNode a)
513 exprData ed = (exprData) dmalloc (sizeof (*ed));
515 ed->single = a;
516 return ed;
519 /*@only@*/ exprData exprData_makeTok (/*@only@*/ lltok op)
521 exprData ed = (exprData) dmalloc (sizeof (*ed));
522 ed->tok = op;
524 return ed;
527 /*@only@*/ exprData
528 exprData_makeIter (/*@exposed@*/ uentry sname, /*@keep@*/ exprNodeList args,
529 /*@keep@*/ exprNode body, /*@exposed@*/ uentry ename)
531 exprData ed = (exprData) dmalloc (sizeof (*ed));
533 ed->iter = (exprIter) dmalloc (sizeof (*ed->iter));
534 ed->iter->sname = uentry_isVar (sname) ? uentry_copy (sname) : sname;
535 ed->iter->args = args;
536 ed->iter->body = body;
537 ed->iter->ename = uentry_isVar (ename) ? uentry_copy (ename) : ename;
538 return ed;
541 static /*@only@*/ exprData exprData_makeTriple (/*@keep@*/ exprNode pred,
542 /*@keep@*/ exprNode tbranch,
543 /*@keep@*/ exprNode fbranch)
545 exprData ed = (exprData) dmalloc (sizeof (*ed));
547 ed->triple = (exprTriple) dmalloc (sizeof (*ed->triple));
548 ed->triple->pred = pred;
549 ed->triple->tbranch = tbranch;
550 ed->triple->fbranch = fbranch;
552 return ed;
555 /*@only@*/ exprData exprData_makeCall (/*@keep@*/ exprNode fcn,
556 /*@keep@*/ exprNodeList args)
558 exprData ed = (exprData) dmalloc (sizeof (*ed));
560 ed->call = (exprCall) dmalloc (sizeof (*ed->call));
561 ed->call->fcn = fcn;
562 ed->call->args = args;
564 return ed;
567 /*@only@*/ exprData exprData_makeIterCall (/*@dependent@*/ uentry iter,
568 /*@keep@*/ exprNodeList args)
570 exprData ed = (exprData) dmalloc (sizeof (*ed));
572 ed->itercall = (exprIterCall) dmalloc (sizeof (*ed->itercall));
573 ed->itercall->iter = uentry_isVar (iter) ? uentry_copy (iter) : iter;
574 ed->itercall->args = args;
576 return ed;
579 /*@only@*/ exprData exprData_makeField (/*@keep@*/ exprNode rec,
580 /*@keep@*/ cstring field)
582 exprData ed = (exprData) dmalloc (sizeof (*ed));
584 ed->field = (exprField) dmalloc (sizeof (*ed->field));
585 ed->field->rec = rec;
586 ed->field->field = field;
588 return ed;
591 /*@only@*/ exprData exprData_makeOffsetof (/*@only@*/ qtype q,
592 /*@keep@*/ cstringList s)
594 exprData ed = (exprData) dmalloc (sizeof (*ed));
595 ed->offset = (exprOffsetof) dmalloc (sizeof (*ed->offset));
597 ed->offset->q = q;
598 ed->offset->field = s;
599 return ed;
602 /*@only@*/ exprData exprData_makeSizeofType (/*@only@*/ qtype q)
604 exprData ed = (exprData) dmalloc (sizeof (*ed));
606 ed->qt = q;
607 return ed;
610 /*@only@*/ exprData
611 exprData_makeCast (/*@keep@*/ lltok tok, /*@keep@*/ exprNode e, /*@only@*/ qtype q)
613 exprData ed = (exprData) dmalloc (sizeof (*ed));
615 ed->cast = (exprCast) dmalloc (sizeof (*ed->cast));
616 ed->cast->tok = tok;
617 ed->cast->exp = e;
618 ed->cast->q = q;
620 return ed;
623 /*@only@*/ exprData
624 exprData_makeInit (/*@keep@*/ idDecl t, /*@keep@*/ exprNode e)
626 exprData ed = (exprData) dmalloc (sizeof (*ed));
628 ed->init = (exprInit) dmalloc (sizeof (*ed->init));
629 ed->init->exp = e;
630 ed->init->id = t;
632 return ed;
635 /*@only@*/ exprData exprData_makeCond (/*@keep@*/ exprNode pred,
636 /*@keep@*/ exprNode ifclause,
637 /*@keep@*/ exprNode elseclause)
639 return exprData_makeTriple (pred, ifclause, elseclause);
642 /*@only@*/ exprData exprData_makeFor (/*@keep@*/ exprNode init,
643 /*@keep@*/ exprNode pred,
644 /*@keep@*/ exprNode inc)
646 return exprData_makeTriple (init, pred, inc);
650 /*@only@*/ exprData exprData_makeLiteral (/*@only@*/ cstring s)
652 exprData ed = (exprData) dmalloc (sizeof (*ed));
654 ed->literal = s;
655 return ed;
658 /*@only@*/ exprData exprData_makeId (/*@temp@*/ uentry id)
660 exprData ed = (exprData) dmalloc (sizeof (*ed));
661 ed->id = cstring_copy (uentry_rawName (id));
662 return ed;
665 /*@only@*/ exprData exprData_makePair (/*@keep@*/ exprNode a, /*@keep@*/ exprNode b)
667 exprData ed = (exprData) dmalloc (sizeof (*ed));
669 ed->pair = (exprPair) dmalloc (sizeof (*ed->pair));
670 ed->pair->a = a;
671 ed->pair->b = b;
673 return ed;