o create create_builtin_stream
[smatch.git] / evaluate.c
blobad8f15fad49cda8877319bf8c9bab0aac044aa8c
1 /*
2 * sparse/evaluate.c
4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003 Linus Torvalds
7 * Licensed under the Open Software License version 1.1
9 * Evaluate constant expressions.
11 #include <stdlib.h>
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <ctype.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 #include <limits.h>
21 #include "lib.h"
22 #include "parse.h"
23 #include "token.h"
24 #include "symbol.h"
25 #include "target.h"
26 #include "expression.h"
28 static struct symbol *current_fn;
29 static int current_context, current_contextmask;
31 static struct symbol *evaluate_symbol_expression(struct expression *expr)
33 struct symbol *sym = expr->symbol;
34 struct symbol *base_type;
36 if (!sym) {
37 if (preprocessing) {
38 expr->ctype = &int_ctype;
39 return &int_ctype;
41 warn(expr->pos, "undefined identifier '%s'", show_ident(expr->symbol_name));
42 return NULL;
45 examine_symbol_type(sym);
46 if ((sym->ctype.context ^ current_context) & (sym->ctype.contextmask & current_contextmask))
47 warn(expr->pos, "Using symbol '%s' in wrong context", show_ident(expr->symbol_name));
49 base_type = sym->ctype.base_type;
50 if (!base_type) {
51 warn(expr->pos, "identifier '%s' has no type", show_ident(expr->symbol_name));
52 return NULL;
55 /* The type of a symbol is the symbol itself! */
56 expr->ctype = sym;
58 /* enum's can be turned into plain values */
59 if (sym->type != SYM_ENUM) {
60 struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL);
61 addr->symbol = sym;
62 addr->symbol_name = expr->symbol_name;
63 addr->ctype = &ptr_ctype;
64 expr->type = EXPR_PREOP;
65 expr->op = '*';
66 expr->unop = addr;
67 return sym;
69 expr->type = EXPR_VALUE;
70 expr->value = sym->value;
71 expr->ctype = base_type;
72 return sym;
75 static struct symbol *evaluate_string(struct expression *expr)
77 struct symbol *sym = alloc_symbol(expr->pos, SYM_NODE);
78 struct symbol *array = alloc_symbol(expr->pos, SYM_ARRAY);
79 struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL);
80 int length = expr->string->length;
82 sym->array_size = length;
83 sym->bit_size = BITS_IN_CHAR * length;
84 sym->ctype.alignment = 1;
85 sym->ctype.modifiers = MOD_STATIC;
86 sym->ctype.base_type = array;
88 array->array_size = length;
89 array->bit_size = BITS_IN_CHAR * length;
90 array->ctype.alignment = 1;
91 array->ctype.modifiers = MOD_STATIC;
92 array->ctype.base_type = &char_ctype;
94 addr->symbol = sym;
95 addr->ctype = &ptr_ctype;
97 expr->type = EXPR_PREOP;
98 expr->op = '*';
99 expr->unop = addr;
100 expr->ctype = sym;
101 return sym;
104 static struct symbol *bigger_int_type(struct symbol *left, struct symbol *right)
106 unsigned long lmod, rmod, mod;
108 if (left == right)
109 return left;
111 if (left->bit_size > right->bit_size)
112 return left;
114 if (right->bit_size > left->bit_size)
115 return right;
117 /* Same size integers - promote to unsigned, promote to long */
118 lmod = left->ctype.modifiers;
119 rmod = right->ctype.modifiers;
120 mod = lmod | rmod;
121 if (mod == lmod)
122 return left;
123 if (mod == rmod)
124 return right;
125 return ctype_integer(mod);
128 static struct expression * cast_to(struct expression *old, struct symbol *type)
130 struct expression *expr = alloc_expression(old->pos, EXPR_CAST);
131 expr->ctype = type;
132 expr->cast_type = type;
133 expr->cast_expression = old;
134 return expr;
137 static int is_ptr_type(struct symbol *type)
139 if (type->type == SYM_NODE)
140 type = type->ctype.base_type;
141 return type->type == SYM_PTR || type->type == SYM_ARRAY || type->type == SYM_FN;
144 static int is_int_type(struct symbol *type)
146 if (type->type == SYM_NODE)
147 type = type->ctype.base_type;
148 return type->ctype.base_type == &int_type;
151 static struct symbol *bad_expr_type(struct expression *expr)
153 warn(expr->pos, "incompatible types for operation");
154 return NULL;
157 static struct symbol * compatible_integer_binop(struct expression *expr, struct expression **lp, struct expression **rp)
159 struct expression *left = *lp, *right = *rp;
160 struct symbol *ltype = left->ctype, *rtype = right->ctype;
162 if (ltype->type == SYM_NODE)
163 ltype = ltype->ctype.base_type;
164 if (rtype->type == SYM_NODE)
165 rtype = rtype->ctype.base_type;
166 /* Integer promotion? */
167 if (ltype->type == SYM_ENUM || ltype->type == SYM_BITFIELD)
168 ltype = &int_ctype;
169 if (rtype->type == SYM_ENUM || rtype->type == SYM_BITFIELD)
170 rtype = &int_ctype;
171 if (is_int_type(ltype) && is_int_type(rtype)) {
172 struct symbol *ctype = bigger_int_type(ltype, rtype);
174 /* Don't bother promoting same-size entities, it only adds clutter */
175 if (ltype->bit_size != ctype->bit_size)
176 *lp = cast_to(left, ctype);
177 if (rtype->bit_size != ctype->bit_size)
178 *rp = cast_to(right, ctype);
179 return ctype;
181 return NULL;
184 static struct symbol *evaluate_int_binop(struct expression *expr)
186 struct symbol *ctype = compatible_integer_binop(expr, &expr->left, &expr->right);
187 if (ctype) {
188 expr->ctype = ctype;
189 return ctype;
191 return bad_expr_type(expr);
194 static inline int lvalue_expression(struct expression *expr)
196 while (expr->type == EXPR_CAST)
197 expr = expr->cast_expression;
198 return (expr->type == EXPR_PREOP && expr->op == '*') || expr->type == EXPR_BITFIELD;
201 /* Arrays degenerate into pointers on pointer arithmetic */
202 static struct symbol *degenerate(struct expression *expr, struct symbol *ctype, struct expression **ptr_p)
204 struct symbol *base = ctype;
206 if (ctype->type == SYM_NODE)
207 base = ctype->ctype.base_type;
208 if (base->type == SYM_ARRAY || base->type == SYM_FN) {
209 struct symbol *sym = alloc_symbol(expr->pos, SYM_PTR);
210 struct expression *n = alloc_expression(expr->pos, 0);
211 struct expression *ptr;
213 merge_type(sym, ctype);
214 if (base->type == SYM_FN)
215 base = ctype;
216 merge_type(sym, base);
217 sym->bit_size = BITS_IN_POINTER;
218 ctype = sym;
220 ptr = *ptr_p;
221 *n = *ptr->unop;
222 n->ctype = ctype;
223 *ptr_p = n;
226 * This all really assumes that we got the degenerate
227 * array as an lvalue (ie a dereference). If that
228 * is not the case, then holler - because we've screwed
229 * up.
231 if (!lvalue_expression(ptr))
232 warn(ptr->pos, "internal error: strange degenerate array case");
234 return ctype;
237 static struct symbol *evaluate_ptr_add(struct expression *expr, struct expression *ptr, struct expression *i)
239 struct symbol *ctype;
240 struct symbol *ptr_type = ptr->ctype;
241 struct symbol *i_type = i->ctype;
242 int bit_size;
244 if (i_type->type == SYM_NODE)
245 i_type = i_type->ctype.base_type;
246 if (ptr_type->type == SYM_NODE)
247 ptr_type = ptr_type->ctype.base_type;
249 if (i_type->type == SYM_ENUM)
250 i_type = &int_ctype;
251 if (!is_int_type(i_type))
252 return bad_expr_type(expr);
254 ctype = ptr->ctype;
255 examine_symbol_type(ctype);
257 ctype = degenerate(expr, ctype, &ptr);
258 bit_size = ctype->bit_size;
260 /* Special case: adding zero commonly happens as a result of 'array[0]' */
261 if (i->type == EXPR_VALUE && !i->value) {
262 *expr = *ptr;
263 } else if (bit_size > BITS_IN_CHAR) {
264 struct expression *add = expr;
265 struct expression *mul = alloc_expression(expr->pos, EXPR_BINOP);
266 struct expression *val = alloc_expression(expr->pos, EXPR_VALUE);
268 val->ctype = size_t_ctype;
269 val->value = bit_size >> 3;
271 mul->op = '*';
272 mul->ctype = size_t_ctype;
273 mul->left = i;
274 mul->right = val;
276 /* Leave 'add->op' as 'expr->op' - either '+' or '-' */
277 add->left = ptr;
278 add->right = mul;
281 expr->ctype = ctype;
282 return ctype;
285 static struct symbol *evaluate_add(struct expression *expr)
287 struct expression *left = expr->left, *right = expr->right;
288 struct symbol *ltype = left->ctype, *rtype = right->ctype;
290 if (is_ptr_type(ltype))
291 return evaluate_ptr_add(expr, left, right);
293 if (is_ptr_type(rtype))
294 return evaluate_ptr_add(expr, right, left);
296 // FIXME! FP promotion
297 return evaluate_int_binop(expr);
300 #define MOD_SIZE (MOD_CHAR | MOD_SHORT | MOD_LONG | MOD_LONGLONG)
301 #define MOD_IGNORE (MOD_TOPLEVEL | MOD_STORAGE | MOD_ADDRESSABLE | MOD_SIGNED | MOD_UNSIGNED | MOD_ASSIGNED)
303 static const char * type_difference(struct symbol *target, struct symbol *source,
304 unsigned long target_mod_ignore, unsigned long source_mod_ignore)
306 for (;;) {
307 unsigned long mod1, mod2, diff;
308 unsigned long as1, as2;
310 if (target == source)
311 break;
312 if (!target || !source)
313 return "different types";
315 * Peel of per-node information.
316 * FIXME! Check alignment, address space, and context too here!
318 if (target->type == SYM_NODE)
319 target = target->ctype.base_type;
320 if (source->type == SYM_NODE)
321 source = source->ctype.base_type;
323 if (target == source)
324 break;
325 if (!target || !source)
326 return "different types";
328 mod1 = target->ctype.modifiers;
329 as1 = target->ctype.as;
330 mod2 = source->ctype.modifiers;
331 as2 = source->ctype.as;
333 if (target->type != source->type) {
334 int type1 = target->type;
335 int type2 = source->type;
337 /* Ignore ARRAY/PTR differences, as long as they point to the same type */
338 type1 = type1 == SYM_ARRAY ? SYM_PTR : type1;
339 type2 = type2 == SYM_ARRAY ? SYM_PTR : type2;
341 if ((type1 == SYM_PTR) && (target->ctype.base_type->type == SYM_FN)) {
342 target = target->ctype.base_type;
343 type1 = SYM_FN;
346 if ((type2 == SYM_PTR) && (source->ctype.base_type->type == SYM_FN)) {
347 source = source->ctype.base_type;
348 type2 = SYM_FN;
351 if (type1 != type2)
352 return "different base types";
355 /* Must be same address space to be comparable */
356 if (as1 != as2)
357 return "different address spaces";
359 /* Ignore differences in storage types, sign, or addressability */
360 diff = (mod1 ^ mod2) & ~MOD_IGNORE;
361 if (diff) {
362 mod1 &= diff & ~target_mod_ignore;
363 mod2 &= diff & ~source_mod_ignore;
364 if (mod1 | mod2) {
365 if ((mod1 | mod2) & MOD_SIZE)
366 return "different type sizes";
367 return "different modifiers";
371 if (target->type == SYM_FN) {
372 int i;
373 struct symbol *arg1, *arg2;
374 if (target->variadic != source->variadic)
375 return "incompatible variadic arguments";
376 PREPARE_PTR_LIST(target->arguments, arg1);
377 PREPARE_PTR_LIST(source->arguments, arg2);
378 i = 1;
379 for (;;) {
380 const char *diff;
381 diff = type_difference(arg1, arg2, 0, 0);
382 if (diff) {
383 static char argdiff[80];
384 sprintf(argdiff, "incompatible argument %d (%s)", i, diff);
385 return argdiff;
387 if (!arg1)
388 break;
389 NEXT_PTR_LIST(arg1);
390 NEXT_PTR_LIST(arg2);
391 i++;
393 FINISH_PTR_LIST(arg2);
394 FINISH_PTR_LIST(arg1);
397 target = target->ctype.base_type;
398 source = source->ctype.base_type;
400 return NULL;
403 static struct symbol *common_ptr_type(struct expression *l, struct expression *r)
405 /* NULL expression? Just return the type of the "other side" */
406 if (r->type == EXPR_VALUE && !r->value)
407 return l->ctype;
408 if (l->type == EXPR_VALUE && !l->value)
409 return r->ctype;
410 return NULL;
414 * Ignore differences in "volatile" and "const"ness when
415 * subtracting pointers
417 #define MOD_IGN (MOD_VOLATILE | MOD_CONST)
419 static struct symbol *evaluate_ptr_sub(struct expression *expr, struct expression *l, struct expression *r)
421 const char *typediff;
422 struct symbol *ctype;
423 struct symbol *ltype = l->ctype, *rtype = r->ctype;
426 * If it is an integer subtract: the ptr add case will do the
427 * right thing.
429 if (!is_ptr_type(rtype))
430 return evaluate_ptr_add(expr, l, r);
432 ctype = ltype;
433 typediff = type_difference(ltype, rtype, MOD_IGN, MOD_IGN);
434 if (typediff) {
435 ctype = common_ptr_type(l, r);
436 if (!ctype) {
437 warn(expr->pos, "subtraction of different types can't work (%s)", typediff);
438 return NULL;
441 examine_symbol_type(ctype);
443 /* Figure out the base type we point to */
444 if (ctype->type == SYM_NODE)
445 ctype = ctype->ctype.base_type;
446 if (ctype->type != SYM_PTR && ctype->type != SYM_ARRAY) {
447 warn(expr->pos, "subtraction of functions? Share your drugs");
448 return NULL;
450 ctype = ctype->ctype.base_type;
452 expr->ctype = ssize_t_ctype;
453 if (ctype->bit_size > BITS_IN_CHAR) {
454 struct expression *sub = alloc_expression(expr->pos, EXPR_BINOP);
455 struct expression *div = expr;
456 struct expression *val = alloc_expression(expr->pos, EXPR_VALUE);
458 val->ctype = size_t_ctype;
459 val->value = ctype->bit_size >> 3;
461 sub->op = '-';
462 sub->ctype = ssize_t_ctype;
463 sub->left = l;
464 sub->right = r;
466 div->op = '/';
467 div->left = sub;
468 div->right = val;
471 return ssize_t_ctype;
474 static struct symbol *evaluate_sub(struct expression *expr)
476 struct expression *left = expr->left, *right = expr->right;
477 struct symbol *ltype = left->ctype;
479 if (is_ptr_type(ltype))
480 return evaluate_ptr_sub(expr, left, right);
482 // FIXME! FP promotion
483 return evaluate_int_binop(expr);
486 static struct symbol *evaluate_logical(struct expression *expr)
488 if (!evaluate_expression(expr->left))
489 return NULL;
490 if (!evaluate_expression(expr->right))
491 return NULL;
492 expr->ctype = &bool_ctype;
493 return &bool_ctype;
496 static struct symbol *evaluate_arithmetic(struct expression *expr)
498 // FIXME! Floating-point promotion!
499 return evaluate_int_binop(expr);
502 static struct symbol *evaluate_binop(struct expression *expr)
504 switch (expr->op) {
505 // addition can take ptr+int, fp and int
506 case '+':
507 return evaluate_add(expr);
509 // subtraction can take ptr-ptr, fp and int
510 case '-':
511 return evaluate_sub(expr);
513 // Arithmetic operations can take fp and int
514 case '*': case '/': case '%':
515 return evaluate_arithmetic(expr);
517 // The rest are integer operations (bitops)
518 // SPECIAL_LEFTSHIFT, SPECIAL_RIGHTSHIFT
519 // '&', '^', '|'
520 default:
521 return evaluate_int_binop(expr);
525 static struct symbol *evaluate_comma(struct expression *expr)
527 expr->ctype = expr->right->ctype;
528 return expr->ctype;
531 static struct symbol *evaluate_compare(struct expression *expr)
533 struct expression *left = expr->left, *right = expr->right;
534 struct symbol *ltype = left->ctype, *rtype = right->ctype;
535 struct symbol *ctype;
537 /* Pointer types? */
538 if (is_ptr_type(ltype) || is_ptr_type(rtype)) {
539 expr->ctype = &bool_ctype;
540 // FIXME! Check the types for compatibility
541 return &bool_ctype;
544 ctype = compatible_integer_binop(expr, &expr->left, &expr->right);
545 if (ctype) {
546 expr->ctype = &bool_ctype;
547 return &bool_ctype;
550 return bad_expr_type(expr);
553 static int compatible_integer_types(struct symbol *ltype, struct symbol *rtype)
555 /* Integer promotion? */
556 if (ltype->type == SYM_NODE)
557 ltype = ltype->ctype.base_type;
558 if (rtype->type == SYM_NODE)
559 rtype = rtype->ctype.base_type;
560 if (ltype->type == SYM_ENUM || ltype->type == SYM_BITFIELD)
561 ltype = &int_ctype;
562 if (rtype->type == SYM_ENUM || rtype->type == SYM_BITFIELD)
563 rtype = &int_ctype;
564 return (is_int_type(ltype) && is_int_type(rtype));
567 static int is_null_ptr(struct expression *expr)
569 return (expr->type == EXPR_VALUE &&
570 expr->value == 0);
574 * FIXME!! This should do casts, array degeneration etc..
576 static struct symbol *compatible_ptr_type(struct expression *left, struct expression *right)
578 struct symbol *ltype = left->ctype, *rtype = right->ctype;
580 if (ltype->type == SYM_NODE)
581 ltype = ltype->ctype.base_type;
583 if (ltype->type == SYM_PTR) {
584 if (is_null_ptr(right) || rtype->ctype.base_type == &void_ctype)
585 return ltype;
588 if (rtype->type == SYM_NODE)
589 rtype = rtype->ctype.base_type;
591 if (rtype->type == SYM_PTR) {
592 if (is_null_ptr(left) || ltype->ctype.base_type == &void_ctype)
593 return rtype;
595 return NULL;
598 static struct symbol *do_degenerate(struct expression **ep)
600 struct expression *expr = *ep;
601 return degenerate(expr, expr->ctype, ep);
604 static struct symbol * evaluate_conditional(struct expression *expr)
606 struct expression *cond, *true, *false;
607 struct symbol *ctype, *ltype, *rtype;
608 const char * typediff;
610 ctype = do_degenerate(&expr->conditional);
611 cond = expr->conditional;
613 ltype = ctype;
614 true = cond;
615 if (expr->cond_true) {
616 ltype = do_degenerate(&expr->cond_true);
617 true = expr->cond_true;
620 rtype = do_degenerate(&expr->cond_false);
621 false = expr->cond_false;
623 ctype = ltype;
624 typediff = type_difference(ltype, rtype, MOD_IGN, MOD_IGN);
625 if (typediff) {
626 ctype = compatible_integer_binop(expr, &true, &expr->cond_false);
627 if (!ctype) {
628 ctype = compatible_ptr_type(true, expr->cond_false);
629 if (!ctype) {
630 warn(expr->pos, "incompatible types in conditional expression (%s)", typediff);
631 return NULL;
636 expr->ctype = ctype;
637 return ctype;
640 static int compatible_assignment_types(struct expression *expr, struct symbol *target,
641 struct expression **rp, struct symbol *source, const char *where)
643 const char *typediff;
644 struct symbol *t;
645 int target_as;
647 /* It's ok if the target is more volatile or const than the source */
648 typediff = type_difference(target, source, MOD_VOLATILE | MOD_CONST, 0);
649 if (!typediff)
650 return 1;
652 if (compatible_integer_types(target, source)) {
653 if (target->bit_size != source->bit_size)
654 *rp = cast_to(*rp, target);
655 return 1;
658 /* Pointer destination? */
659 t = target;
660 target_as = t->ctype.as;
661 if (t->type == SYM_NODE) {
662 t = t->ctype.base_type;
663 target_as |= t->ctype.as;
665 if (t->type == SYM_PTR || t->type == SYM_FN) {
666 struct expression *right = *rp;
667 struct symbol *s = source;
668 int source_as;
670 // NULL pointer is always ok
671 if (right->type == EXPR_VALUE && !right->value)
672 return 1;
674 /* "void *" matches anything as long as the address space is ok */
675 source_as = s->ctype.as;
676 if (s->type == SYM_NODE) {
677 s = s->ctype.base_type;
678 source_as |= s->ctype.as;
680 if (source_as == target_as && (s->type == SYM_PTR || s->type == SYM_ARRAY)) {
681 s = s->ctype.base_type;
682 t = t->ctype.base_type;
683 if (s == &void_ctype || t == &void_ctype)
684 return 1;
688 // FIXME!! Cast it?
689 warn(expr->pos, "incorrect type in %s (%s)", where, typediff);
690 warn(expr->pos, " expected %s", show_typename(target));
691 warn(expr->pos, " got %s", show_typename(source));
692 return 0;
696 * FIXME!! This is wrong from a double evaluation standpoint. We can't
697 * just expand the expression twice, that would make any side effects
698 * happen twice too.
700 static struct symbol *evaluate_binop_assignment(struct expression *expr, struct expression *left, struct expression *right)
702 int op = expr->op;
703 struct expression *subexpr = alloc_expression(expr->pos, EXPR_BINOP);
704 static const int op_trans[] = {
705 [SPECIAL_ADD_ASSIGN - SPECIAL_BASE] = '+',
706 [SPECIAL_SUB_ASSIGN - SPECIAL_BASE] = '-',
707 [SPECIAL_MUL_ASSIGN - SPECIAL_BASE] = '*',
708 [SPECIAL_DIV_ASSIGN - SPECIAL_BASE] = '/',
709 [SPECIAL_MOD_ASSIGN - SPECIAL_BASE] = '%',
710 [SPECIAL_SHL_ASSIGN - SPECIAL_BASE] = SPECIAL_LEFTSHIFT,
711 [SPECIAL_SHR_ASSIGN - SPECIAL_BASE] = SPECIAL_RIGHTSHIFT,
712 [SPECIAL_AND_ASSIGN - SPECIAL_BASE] = '&',
713 [SPECIAL_OR_ASSIGN - SPECIAL_BASE] = '|',
714 [SPECIAL_XOR_ASSIGN - SPECIAL_BASE] = '^'
717 subexpr->left = left;
718 subexpr->right = right;
719 subexpr->op = op_trans[op - SPECIAL_BASE];
720 expr->op = '=';
721 expr->right = subexpr;
722 return evaluate_binop(subexpr);
725 static struct symbol *evaluate_assignment(struct expression *expr)
727 struct expression *left = expr->left, *right = expr->right;
728 struct symbol *ltype, *rtype;
730 ltype = left->ctype;
731 rtype = right->ctype;
732 if (expr->op != '=') {
733 rtype = evaluate_binop_assignment(expr, left, right);
734 if (!rtype)
735 return 0;
736 right = expr->right;
739 if (!lvalue_expression(left)) {
740 warn(expr->pos, "not an lvalue");
741 return NULL;
744 rtype = degenerate(right, rtype, &expr->right);
746 if (!compatible_assignment_types(expr, ltype, &expr->right, rtype, "assignment"))
747 return 0;
749 if (ltype->type == SYM_NODE)
750 ltype->ctype.modifiers |= MOD_ASSIGNED;
752 expr->ctype = ltype;
753 return ltype;
756 static struct symbol *evaluate_addressof(struct expression *expr)
758 struct symbol *ctype, *symbol;
759 struct expression *op = expr->unop;
761 if (op->op != '*' || op->type != EXPR_PREOP) {
762 warn(expr->pos, "not addressable");
763 return NULL;
766 symbol = alloc_symbol(expr->pos, SYM_PTR);
767 symbol->ctype.alignment = POINTER_ALIGNMENT;
768 symbol->bit_size = BITS_IN_POINTER;
770 ctype = op->ctype;
771 if (ctype->type == SYM_NODE) {
772 ctype->ctype.modifiers |= MOD_ADDRESSABLE;
773 if (ctype->ctype.modifiers & MOD_REGISTER) {
774 warn(expr->pos, "taking address of 'register' variable '%s'", show_ident(ctype->ident));
775 ctype->ctype.modifiers &= ~MOD_REGISTER;
777 symbol->ctype.modifiers = ctype->ctype.modifiers;
778 symbol->ctype.as = ctype->ctype.as;
779 symbol->ctype.context = ctype->ctype.context;
780 symbol->ctype.contextmask = ctype->ctype.contextmask;
781 ctype = ctype->ctype.base_type;
784 symbol->ctype.base_type = ctype;
785 *expr = *op->unop;
786 expr->ctype = symbol;
787 return symbol;
791 static struct symbol *evaluate_dereference(struct expression *expr)
793 struct expression *op = expr->unop;
794 struct symbol *ctype = op->ctype, *sym;
796 sym = alloc_symbol(expr->pos, SYM_NODE);
797 if (ctype->type == SYM_NODE) {
798 ctype = ctype->ctype.base_type;
799 merge_type(sym, ctype);
801 sym->ctype = ctype->ctype;
802 if (ctype->type != SYM_PTR && ctype->type != SYM_ARRAY) {
803 warn(expr->pos, "cannot derefence this type");
804 return 0;
807 ctype = ctype->ctype.base_type;
808 examine_symbol_type(ctype);
809 if (!ctype) {
810 warn(expr->pos, "undefined type");
811 return NULL;
814 sym->bit_size = ctype->bit_size;
815 sym->array_size = ctype->array_size;
817 /* Simplify: *&(expr) => (expr) */
818 if (op->type == EXPR_PREOP && op->op == '&') {
819 *expr = *op->unop;
822 expr->ctype = sym;
823 return sym;
827 * Unary post-ops: x++ and x--
829 static struct symbol *evaluate_postop(struct expression *expr)
831 struct expression *op = expr->unop;
832 struct symbol *ctype = op->ctype;
834 if (!lvalue_expression(expr->unop)) {
835 warn(expr->pos, "need lvalue expression for ++/--");
836 return NULL;
838 expr->ctype = ctype;
839 return ctype;
842 static struct symbol *evaluate_preop(struct expression *expr)
844 struct symbol *ctype = expr->unop->ctype;
846 switch (expr->op) {
847 case '(':
848 case '+':
849 *expr = *expr->unop;
850 return ctype;
852 case '*':
853 return evaluate_dereference(expr);
855 case '&':
856 return evaluate_addressof(expr);
858 case SPECIAL_INCREMENT:
859 case SPECIAL_DECREMENT:
861 * From a type evaluation standpoint the pre-ops are
862 * the same as the postops
864 return evaluate_postop(expr);
866 case '!':
867 ctype = &bool_ctype;
868 break;
870 default:
871 break;
873 expr->ctype = ctype;
874 return &bool_ctype;
877 struct symbol *find_identifier(struct ident *ident, struct symbol_list *_list, int *offset)
879 struct ptr_list *head = (struct ptr_list *)_list;
880 struct ptr_list *list = head;
882 if (!head)
883 return NULL;
884 do {
885 int i;
886 for (i = 0; i < list->nr; i++) {
887 struct symbol *sym = (struct symbol *) list->list[i];
888 if (sym->ident) {
889 if (sym->ident != ident)
890 continue;
891 *offset = sym->offset;
892 return sym;
893 } else {
894 struct symbol *ctype = sym->ctype.base_type;
895 struct symbol *sub;
896 if (!ctype)
897 continue;
898 if (ctype->type != SYM_UNION && ctype->type != SYM_STRUCT)
899 continue;
900 sub = find_identifier(ident, ctype->symbol_list, offset);
901 if (!sub)
902 continue;
903 *offset += sym->offset;
904 return sub;
907 } while ((list = list->next) != head);
908 return NULL;
911 static struct expression *evaluate_offset(struct expression *expr, unsigned long offset)
913 struct expression *add;
915 if (!offset)
916 return expr;
918 /* Create a new add-expression */
919 add = alloc_expression(expr->pos, EXPR_BINOP);
920 add->op = '+';
921 add->ctype = &ptr_ctype;
922 add->left = expr;
923 add->right = alloc_expression(expr->pos, EXPR_VALUE);
924 add->right->ctype = &int_ctype;
925 add->right->value = offset;
927 return add;
930 /* structure/union dereference */
931 static struct symbol *evaluate_member_dereference(struct expression *expr)
933 int offset;
934 struct symbol *ctype, *member, *sym;
935 struct expression *deref = expr->deref, *add;
936 struct ident *ident = expr->member;
937 unsigned int mod;
938 int address_space;
940 if (!evaluate_expression(deref))
941 return NULL;
942 if (!ident) {
943 warn(expr->pos, "bad member name");
944 return NULL;
947 ctype = deref->ctype;
948 address_space = ctype->ctype.as;
949 mod = ctype->ctype.modifiers;
950 if (ctype->type == SYM_NODE) {
951 ctype = ctype->ctype.base_type;
952 address_space |= ctype->ctype.as;
953 mod |= ctype->ctype.modifiers;
955 if (expr->op == SPECIAL_DEREFERENCE) {
956 /* Arrays will degenerate into pointers for '->' */
957 if (ctype->type != SYM_PTR && ctype->type != SYM_ARRAY) {
958 warn(expr->pos, "expected a pointer to a struct/union");
959 return NULL;
961 mod = ctype->ctype.modifiers;
962 address_space = ctype->ctype.as;
963 ctype = ctype->ctype.base_type;
964 if (ctype->type == SYM_NODE) {
965 mod |= ctype->ctype.modifiers;
966 address_space |= ctype->ctype.as;
967 ctype = ctype->ctype.base_type;
969 } else {
970 if (!lvalue_expression(deref)) {
971 warn(deref->pos, "expected lvalue for member dereference");
972 return NULL;
974 deref = deref->unop;
975 expr->deref = deref;
977 if (!ctype || (ctype->type != SYM_STRUCT && ctype->type != SYM_UNION)) {
978 warn(expr->pos, "expected structure or union");
979 return NULL;
981 offset = 0;
982 member = find_identifier(ident, ctype->symbol_list, &offset);
983 if (!member) {
984 const char *type = ctype->type == SYM_STRUCT ? "struct" : "union";
985 const char *name = "<unnamed>";
986 int namelen = 9;
987 if (ctype->ident) {
988 name = ctype->ident->name;
989 namelen = ctype->ident->len;
991 warn(expr->pos, "no member '%s' in %s %.*s",
992 show_ident(ident), type, namelen, name);
993 return NULL;
996 add = evaluate_offset(deref, offset);
998 sym = alloc_symbol(expr->pos, SYM_NODE);
999 sym->bit_size = member->bit_size;
1000 sym->array_size = member->array_size;
1001 sym->ctype = member->ctype;
1002 sym->ctype.modifiers = mod;
1003 sym->ctype.as = address_space;
1004 ctype = member->ctype.base_type;
1005 if (ctype->type == SYM_BITFIELD) {
1006 ctype = ctype->ctype.base_type;
1007 expr->type = EXPR_BITFIELD;
1008 expr->bitpos = member->bit_offset;
1009 expr->nrbits = member->fieldwidth;
1010 expr->address = add;
1011 } else {
1012 expr->type = EXPR_PREOP;
1013 expr->op = '*';
1014 expr->unop = add;
1017 expr->ctype = sym;
1018 return sym;
1021 static struct symbol *evaluate_sizeof(struct expression *expr)
1023 int size;
1025 if (expr->cast_type) {
1026 examine_symbol_type(expr->cast_type);
1027 size = expr->cast_type->bit_size;
1028 } else {
1029 if (!evaluate_expression(expr->cast_expression))
1030 return 0;
1031 size = expr->cast_expression->ctype->bit_size;
1033 if (size & 7) {
1034 warn(expr->pos, "cannot size expression");
1035 return 0;
1037 expr->type = EXPR_VALUE;
1038 expr->value = size >> 3;
1039 expr->ctype = size_t_ctype;
1040 return size_t_ctype;
1043 static int context_clash(struct symbol *sym1, struct symbol *sym2)
1045 unsigned long clash = (sym1->ctype.context ^ sym2->ctype.context);
1046 clash &= (sym1->ctype.contextmask & sym2->ctype.contextmask);
1047 return clash != 0;
1050 static int evaluate_arguments(struct symbol *f, struct symbol *fn, struct expression_list *head)
1052 struct expression *expr;
1053 struct symbol_list *argument_types = fn->arguments;
1054 struct symbol *argtype;
1055 int i = 1;
1057 PREPARE_PTR_LIST(argument_types, argtype);
1058 FOR_EACH_PTR (head, expr) {
1059 struct expression **p = THIS_ADDRESS(expr);
1060 struct symbol *ctype, *target;
1061 ctype = evaluate_expression(expr);
1063 if (!ctype)
1064 return 0;
1066 if (context_clash(f, ctype))
1067 warn(expr->pos, "argument %d used in wrong context", i);
1069 ctype = degenerate(expr, ctype, p);
1071 target = argtype;
1072 if (!target && ctype->bit_size < BITS_IN_INT)
1073 target = &int_ctype;
1074 if (target) {
1075 static char where[30];
1076 examine_symbol_type(target);
1077 sprintf(where, "argument %d", i);
1078 compatible_assignment_types(expr, target, p, ctype, where);
1081 i++;
1082 NEXT_PTR_LIST(argtype);
1083 } END_FOR_EACH_PTR;
1084 FINISH_PTR_LIST(argtype);
1085 return 1;
1088 static int evaluate_initializer(struct symbol *ctype, struct expression **ep, unsigned long offset);
1089 static int evaluate_array_initializer(struct symbol *ctype, struct expression *expr, unsigned long offset)
1091 struct expression *entry;
1092 int current = 0;
1093 int max = 0;
1095 FOR_EACH_PTR(expr->expr_list, entry) {
1096 struct expression **p = THIS_ADDRESS(entry);
1098 if (entry->type == EXPR_INDEX) {
1099 current = entry->idx_to;
1100 continue;
1102 evaluate_initializer(ctype, p, offset + current*(ctype->bit_size>>3));
1103 current++;
1104 if (current > max)
1105 max = current;
1106 } END_FOR_EACH_PTR;
1107 return max;
1110 static int evaluate_struct_or_union_initializer(struct symbol *ctype, struct expression *expr, int multiple, unsigned long offset)
1112 struct expression *entry;
1113 struct symbol *sym;
1115 PREPARE_PTR_LIST(ctype->symbol_list, sym);
1116 FOR_EACH_PTR(expr->expr_list, entry) {
1117 struct expression **p = THIS_ADDRESS(entry);
1119 if (entry->type == EXPR_IDENTIFIER) {
1120 struct ident *ident = entry->expr_ident;
1121 /* We special-case the "already right place" case */
1122 if (sym && sym->ident == ident)
1123 continue;
1124 RESET_PTR_LIST(sym);
1125 for (;;) {
1126 if (!sym) {
1127 warn(entry->pos, "unknown named initializer '%s'", show_ident(ident));
1128 return 0;
1130 if (sym->ident == ident)
1131 break;
1132 NEXT_PTR_LIST(sym);
1134 continue;
1137 if (!sym) {
1138 warn(expr->pos, "too many initializers for struct/union");
1139 return 0;
1142 evaluate_initializer(sym, p, offset + sym->offset);
1144 NEXT_PTR_LIST(sym);
1145 } END_FOR_EACH_PTR;
1146 FINISH_PTR_LIST(sym);
1148 return 0;
1152 * Initializers are kind of like assignments. Except
1153 * they can be a hell of a lot more complex.
1155 static int evaluate_initializer(struct symbol *ctype, struct expression **ep, unsigned long offset)
1157 struct expression *expr = *ep;
1160 * Simple non-structure/array initializers are the simple
1161 * case, and look (and parse) largely like assignments.
1163 if (expr->type != EXPR_INITIALIZER) {
1164 int size = 0;
1165 struct symbol *rtype = evaluate_expression(expr);
1166 if (rtype) {
1167 struct expression *pos;
1169 // FIXME! char array[] = "string" special case
1170 // should _not_ degenerate.
1171 rtype = degenerate(expr, rtype, ep);
1172 expr = *ep;
1173 compatible_assignment_types(expr, ctype, ep, rtype, "initializer");
1174 /* strings are special: char arrays */
1175 if (rtype->type == SYM_ARRAY)
1176 size = rtype->array_size;
1178 * Don't bother creating a position expression for
1179 * the simple initializer cases that don't need it.
1181 * We need a position if the initializer has a byte
1182 * offset, _or_ if we're initializing a bitfield.
1184 if (offset || ctype->fieldwidth) {
1185 pos = alloc_expression(expr->pos, EXPR_POS);
1186 pos->init_offset = offset;
1187 pos->init_sym = ctype;
1188 pos->init_expr = *ep;
1189 pos->ctype = expr->ctype;
1190 *ep = pos;
1193 return size;
1196 expr->ctype = ctype;
1197 if (ctype->type == SYM_NODE)
1198 ctype = ctype->ctype.base_type;
1200 switch (ctype->type) {
1201 case SYM_ARRAY:
1202 case SYM_PTR:
1203 return evaluate_array_initializer(ctype->ctype.base_type, expr, offset);
1204 case SYM_UNION:
1205 return evaluate_struct_or_union_initializer(ctype, expr, 0, offset);
1206 case SYM_STRUCT:
1207 return evaluate_struct_or_union_initializer(ctype, expr, 1, offset);
1208 default:
1209 break;
1211 warn(expr->pos, "unexpected compound initializer");
1212 return 0;
1215 static struct symbol *evaluate_cast(struct expression *expr)
1217 struct expression *target = expr->cast_expression;
1218 struct symbol *ctype = examine_symbol_type(expr->cast_type);
1220 expr->ctype = ctype;
1221 expr->cast_type = ctype;
1224 * Special case: a cast can be followed by an
1225 * initializer, in which case we need to pass
1226 * the type value down to that initializer rather
1227 * than trying to evaluate it as an expression
1229 * A more complex case is when the initializer is
1230 * dereferenced as part of a post-fix expression.
1231 * We need to produce an expression that can be dereferenced.
1233 if (target->type == EXPR_INITIALIZER) {
1234 struct symbol *sym = alloc_symbol(expr->pos, SYM_NODE);
1235 struct expression *addr = alloc_expression(expr->pos, EXPR_SYMBOL);
1237 sym->ctype.base_type = ctype;
1238 sym->initializer = expr->cast_expression;
1239 evaluate_symbol(sym);
1241 addr->ctype = &ptr_ctype;
1242 addr->symbol = sym;
1244 expr->type = EXPR_PREOP;
1245 expr->op = '*';
1246 expr->unop = addr;
1247 expr->ctype = ctype;
1248 return ctype;
1251 evaluate_expression(target);
1254 * Casts of constant values are special: they
1255 * can be NULL, and thus need to be simplified
1256 * early.
1258 if (target->type == EXPR_VALUE)
1259 cast_value(expr, ctype, target, target->ctype);
1261 return ctype;
1265 * Evaluate a call expression with a symbol. This
1266 * should expand inline functions, and evaluate
1267 * builtins.
1269 static int evaluate_symbol_call(struct expression *expr)
1271 struct expression *fn = expr->fn;
1272 struct symbol *ctype = fn->ctype;
1274 if (fn->type != EXPR_PREOP)
1275 return 0;
1277 if (ctype->op && ctype->op->evaluate)
1278 return ctype->op->evaluate(expr);
1280 if (ctype->ctype.modifiers & MOD_INLINE) {
1281 int ret;
1282 struct symbol *curr = current_fn;
1283 unsigned long context = current_context;
1284 unsigned long mask = current_contextmask;
1286 current_context |= ctype->ctype.context;
1287 current_contextmask |= ctype->ctype.contextmask;
1288 current_fn = ctype->ctype.base_type;
1289 ret = inline_function(expr, ctype);
1291 /* restore the old function context */
1292 current_fn = curr;
1293 current_context = context;
1294 current_contextmask = mask;
1295 return ret;
1298 return 0;
1301 static struct symbol *evaluate_call(struct expression *expr)
1303 int args, fnargs;
1304 struct symbol *ctype, *sym;
1305 struct expression *fn = expr->fn;
1306 struct expression_list *arglist = expr->args;
1308 if (!evaluate_expression(fn))
1309 return NULL;
1310 sym = ctype = fn->ctype;
1311 if (ctype->type == SYM_NODE)
1312 ctype = ctype->ctype.base_type;
1313 if (ctype->type == SYM_PTR || ctype->type == SYM_ARRAY)
1314 ctype = ctype->ctype.base_type;
1315 if (!evaluate_arguments(sym, ctype, arglist))
1316 return NULL;
1317 if (sym->type == SYM_NODE) {
1318 if (evaluate_symbol_call(expr))
1319 return expr->ctype;
1321 if (sym->type == SYM_NODE) {
1322 if (evaluate_symbol_call(expr))
1323 return expr->ctype;
1325 if (ctype->type != SYM_FN) {
1326 warn(expr->pos, "not a function %.*s",
1327 sym->ident->len, sym->ident->name);
1328 return NULL;
1330 args = expression_list_size(expr->args);
1331 fnargs = symbol_list_size(ctype->arguments);
1332 if (args < fnargs)
1333 warn(expr->pos, "not enough arguments for function %.*s",
1334 sym->ident->len, sym->ident->name);
1335 if (args > fnargs && !ctype->variadic)
1336 warn(expr->pos, "too many arguments for function %.*s",
1337 sym->ident->len, sym->ident->name);
1338 expr->ctype = ctype->ctype.base_type;
1339 return expr->ctype;
1342 struct symbol *evaluate_expression(struct expression *expr)
1344 if (!expr)
1345 return NULL;
1346 if (expr->ctype)
1347 return expr->ctype;
1349 switch (expr->type) {
1350 case EXPR_VALUE:
1351 warn(expr->pos, "value expression without a type");
1352 return NULL;
1353 case EXPR_STRING:
1354 return evaluate_string(expr);
1355 case EXPR_SYMBOL:
1356 return evaluate_symbol_expression(expr);
1357 case EXPR_BINOP:
1358 if (!evaluate_expression(expr->left))
1359 return NULL;
1360 if (!evaluate_expression(expr->right))
1361 return NULL;
1362 return evaluate_binop(expr);
1363 case EXPR_LOGICAL:
1364 return evaluate_logical(expr);
1365 case EXPR_COMMA:
1366 if (!evaluate_expression(expr->left))
1367 return NULL;
1368 if (!evaluate_expression(expr->right))
1369 return NULL;
1370 return evaluate_comma(expr);
1371 case EXPR_COMPARE:
1372 if (!evaluate_expression(expr->left))
1373 return NULL;
1374 if (!evaluate_expression(expr->right))
1375 return NULL;
1376 return evaluate_compare(expr);
1377 case EXPR_ASSIGNMENT:
1378 if (!evaluate_expression(expr->left))
1379 return NULL;
1380 if (!evaluate_expression(expr->right))
1381 return NULL;
1382 return evaluate_assignment(expr);
1383 case EXPR_PREOP:
1384 if (!evaluate_expression(expr->unop))
1385 return NULL;
1386 return evaluate_preop(expr);
1387 case EXPR_POSTOP:
1388 if (!evaluate_expression(expr->unop))
1389 return NULL;
1390 return evaluate_postop(expr);
1391 case EXPR_CAST:
1392 return evaluate_cast(expr);
1393 case EXPR_SIZEOF:
1394 return evaluate_sizeof(expr);
1395 case EXPR_DEREF:
1396 return evaluate_member_dereference(expr);
1397 case EXPR_CALL:
1398 return evaluate_call(expr);
1399 case EXPR_BITFIELD:
1400 warn(expr->pos, "bitfield generated by parser");
1401 return NULL;
1402 case EXPR_CONDITIONAL:
1403 if (!evaluate_expression(expr->conditional))
1404 return NULL;
1405 if (!evaluate_expression(expr->cond_false))
1406 return NULL;
1407 if (expr->cond_true && !evaluate_expression(expr->cond_true))
1408 return NULL;
1409 return evaluate_conditional(expr);
1410 case EXPR_STATEMENT:
1411 expr->ctype = evaluate_statement(expr->statement);
1412 return expr->ctype;
1414 case EXPR_LABEL:
1415 expr->ctype = &ptr_ctype;
1416 return &ptr_ctype;
1418 /* These can not exist as stand-alone expressions */
1419 case EXPR_INITIALIZER:
1420 case EXPR_IDENTIFIER:
1421 case EXPR_INDEX:
1422 case EXPR_POS:
1423 warn(expr->pos, "internal front-end error: initializer in expression");
1424 return NULL;
1426 return NULL;
1429 void check_duplicates(struct symbol *sym)
1431 struct symbol *next = sym;
1433 while ((next = next->same_symbol) != NULL) {
1434 const char *typediff;
1435 evaluate_symbol(next);
1436 typediff = type_difference(sym, next, 0, 0);
1437 if (typediff) {
1438 warn(sym->pos, "symbol '%s' redeclared with different type (originally declared at %s:%d) - %s",
1439 show_ident(sym->ident),
1440 input_streams[next->pos.stream].name, next->pos.line, typediff);
1441 return;
1446 struct symbol *evaluate_symbol(struct symbol *sym)
1448 struct symbol *base_type;
1450 if (!sym)
1451 return sym;
1453 sym = examine_symbol_type(sym);
1454 base_type = sym->ctype.base_type;
1455 if (!base_type)
1456 return NULL;
1458 /* Evaluate the initializers */
1459 if (sym->initializer) {
1460 int count = evaluate_initializer(sym, &sym->initializer, 0);
1461 if (base_type->type == SYM_ARRAY && base_type->array_size < 0) {
1462 int bit_size = count * base_type->ctype.base_type->bit_size;
1463 base_type->array_size = count;
1464 base_type->bit_size = bit_size;
1465 sym->array_size = count;
1466 sym->bit_size = bit_size;
1470 /* And finally, evaluate the body of the symbol too */
1471 if (base_type->type == SYM_FN) {
1472 struct symbol *s;
1474 FOR_EACH_PTR(base_type->arguments, s) {
1475 evaluate_symbol(s);
1476 } END_FOR_EACH_PTR;
1478 if (base_type->stmt) {
1479 current_fn = base_type;
1480 current_contextmask = sym->ctype.contextmask;
1481 current_context = sym->ctype.context;
1482 evaluate_statement(base_type->stmt);
1486 return base_type;
1489 struct symbol *evaluate_return_expression(struct statement *stmt)
1491 struct expression *expr = stmt->expression;
1492 struct symbol *ctype, *fntype;
1494 fntype = current_fn->ctype.base_type;
1495 if (!fntype || fntype == &void_ctype) {
1496 if (expr)
1497 warn(expr->pos, "return expression in %s function", fntype?"void":"typeless");
1498 return NULL;
1501 if (!expr) {
1502 warn(stmt->pos, "return with no return value");
1503 return NULL;
1505 ctype = evaluate_expression(expr);
1506 if (!ctype)
1507 return NULL;
1508 ctype = degenerate(expr, ctype, &expr);
1509 expr->ctype = ctype;
1510 compatible_assignment_types(expr, fntype, &expr, ctype, "return expression");
1511 stmt->expression = expr;
1512 return NULL;
1515 static void evaluate_if_statement(struct statement *stmt)
1517 struct expression *expr = stmt->if_conditional;
1518 struct symbol *ctype;
1520 if (!expr)
1521 return;
1522 if (expr->type == EXPR_ASSIGNMENT)
1523 warn(expr->pos, "assignment expression in conditional");
1525 ctype = evaluate_expression(expr);
1526 if (!ctype)
1527 return;
1529 evaluate_statement(stmt->if_true);
1530 evaluate_statement(stmt->if_false);
1533 struct symbol *evaluate_statement(struct statement *stmt)
1535 if (!stmt)
1536 return NULL;
1538 switch (stmt->type) {
1539 case STMT_RETURN:
1540 return evaluate_return_expression(stmt);
1542 case STMT_EXPRESSION:
1543 return evaluate_expression(stmt->expression);
1545 case STMT_COMPOUND: {
1546 struct statement *s;
1547 struct symbol *type = NULL;
1548 struct symbol *sym;
1550 /* Evaluate each symbol in the compound statement */
1551 FOR_EACH_PTR(stmt->syms, sym) {
1552 evaluate_symbol(sym);
1553 } END_FOR_EACH_PTR;
1554 evaluate_symbol(stmt->ret);
1557 * Then, evaluate each statement, making the type of the
1558 * compound statement be the type of the last statement
1560 type = NULL;
1561 FOR_EACH_PTR(stmt->stmts, s) {
1562 type = evaluate_statement(s);
1563 } END_FOR_EACH_PTR;
1564 return type;
1566 case STMT_IF:
1567 evaluate_if_statement(stmt);
1568 return NULL;
1569 case STMT_ITERATOR:
1570 evaluate_expression(stmt->iterator_pre_condition);
1571 evaluate_expression(stmt->iterator_post_condition);
1572 evaluate_statement(stmt->iterator_pre_statement);
1573 evaluate_statement(stmt->iterator_statement);
1574 evaluate_statement(stmt->iterator_post_statement);
1575 return NULL;
1576 case STMT_SWITCH:
1577 evaluate_expression(stmt->switch_expression);
1578 evaluate_statement(stmt->switch_statement);
1579 return NULL;
1580 case STMT_CASE:
1581 evaluate_expression(stmt->case_expression);
1582 evaluate_expression(stmt->case_to);
1583 evaluate_statement(stmt->case_statement);
1584 return NULL;
1585 case STMT_LABEL:
1586 evaluate_statement(stmt->label_statement);
1587 return NULL;
1588 case STMT_GOTO:
1589 evaluate_expression(stmt->goto_expression);
1590 return NULL;
1591 case STMT_NONE:
1592 break;
1593 case STMT_ASM:
1594 /* FIXME! Do the asm parameter evaluation! */
1595 break;
1597 return NULL;