Update copyright notices to reflect the fact that Transmeta
[smatch.git] / evaluate.c
blob23613afd1904a24d8833ab556b88fe09060985c3
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;
322 mod1 = target->ctype.modifiers;
323 as1 = target->ctype.as;
324 mod2 = source->ctype.modifiers;
325 as2 = source->ctype.as;
327 if (target->type != source->type) {
328 int type1 = target->type;
329 int type2 = source->type;
331 /* Ignore ARRAY/PTR differences, as long as they point to the same type */
332 type1 = type1 == SYM_ARRAY ? SYM_PTR : type1;
333 type2 = type2 == SYM_ARRAY ? SYM_PTR : type2;
335 if ((type1 == SYM_PTR) && (target->ctype.base_type->type == SYM_FN)) {
336 target = target->ctype.base_type;
337 type1 = SYM_FN;
340 if ((type2 == SYM_PTR) && (source->ctype.base_type->type == SYM_FN)) {
341 source = source->ctype.base_type;
342 type2 = SYM_FN;
345 if (type1 != type2)
346 return "different base types";
349 /* Must be same address space to be comparable */
350 if (as1 != as2)
351 return "different address spaces";
353 /* Ignore differences in storage types, sign, or addressability */
354 diff = (mod1 ^ mod2) & ~MOD_IGNORE;
355 if (diff) {
356 mod1 &= diff & ~target_mod_ignore;
357 mod2 &= diff & ~source_mod_ignore;
358 if (mod1 | mod2) {
359 if ((mod1 | mod2) & MOD_SIZE)
360 return "different type sizes";
361 return "different modifiers";
365 if (target->type == SYM_FN) {
366 int i;
367 struct symbol *arg1, *arg2;
368 if (target->variadic != source->variadic)
369 return "incompatible variadic arguments";
370 PREPARE_PTR_LIST(target->arguments, arg1);
371 PREPARE_PTR_LIST(source->arguments, arg2);
372 i = 1;
373 for (;;) {
374 const char *diff;
375 diff = type_difference(arg1, arg2, 0, 0);
376 if (diff) {
377 static char argdiff[80];
378 sprintf(argdiff, "incompatible argument %d (%s)", i, diff);
379 return argdiff;
381 if (!arg1)
382 break;
383 NEXT_PTR_LIST(arg1);
384 NEXT_PTR_LIST(arg2);
385 i++;
387 FINISH_PTR_LIST(arg2);
388 FINISH_PTR_LIST(arg1);
391 target = target->ctype.base_type;
392 source = source->ctype.base_type;
394 return NULL;
397 static struct symbol *common_ptr_type(struct expression *l, struct expression *r)
399 /* NULL expression? Just return the type of the "other side" */
400 if (r->type == EXPR_VALUE && !r->value)
401 return l->ctype;
402 if (l->type == EXPR_VALUE && !l->value)
403 return r->ctype;
404 return NULL;
408 * Ignore differences in "volatile" and "const"ness when
409 * subtracting pointers
411 #define MOD_IGN (MOD_VOLATILE | MOD_CONST)
413 static struct symbol *evaluate_ptr_sub(struct expression *expr, struct expression *l, struct expression *r)
415 const char *typediff;
416 struct symbol *ctype;
417 struct symbol *ltype = l->ctype, *rtype = r->ctype;
420 * If it is an integer subtract: the ptr add case will do the
421 * right thing.
423 if (!is_ptr_type(rtype))
424 return evaluate_ptr_add(expr, l, r);
426 ctype = ltype;
427 typediff = type_difference(ltype, rtype, MOD_IGN, MOD_IGN);
428 if (typediff) {
429 ctype = common_ptr_type(l, r);
430 if (!ctype) {
431 warn(expr->pos, "subtraction of different types can't work (%s)", typediff);
432 return NULL;
435 examine_symbol_type(ctype);
437 /* Figure out the base type we point to */
438 if (ctype->type == SYM_NODE)
439 ctype = ctype->ctype.base_type;
440 if (ctype->type != SYM_PTR && ctype->type != SYM_ARRAY) {
441 warn(expr->pos, "subtraction of functions? Share your drugs");
442 return NULL;
444 ctype = ctype->ctype.base_type;
446 expr->ctype = ssize_t_ctype;
447 if (ctype->bit_size > BITS_IN_CHAR) {
448 struct expression *sub = alloc_expression(expr->pos, EXPR_BINOP);
449 struct expression *div = expr;
450 struct expression *val = alloc_expression(expr->pos, EXPR_VALUE);
452 val->ctype = size_t_ctype;
453 val->value = ctype->bit_size >> 3;
455 sub->op = '-';
456 sub->ctype = ssize_t_ctype;
457 sub->left = l;
458 sub->right = r;
460 div->op = '/';
461 div->left = sub;
462 div->right = val;
465 return ssize_t_ctype;
468 static struct symbol *evaluate_sub(struct expression *expr)
470 struct expression *left = expr->left, *right = expr->right;
471 struct symbol *ltype = left->ctype;
473 if (is_ptr_type(ltype))
474 return evaluate_ptr_sub(expr, left, right);
476 // FIXME! FP promotion
477 return evaluate_int_binop(expr);
480 static struct symbol *evaluate_logical(struct expression *expr)
482 if (!evaluate_expression(expr->left))
483 return NULL;
484 if (!evaluate_expression(expr->right))
485 return NULL;
486 expr->ctype = &bool_ctype;
487 return &bool_ctype;
490 static struct symbol *evaluate_arithmetic(struct expression *expr)
492 // FIXME! Floating-point promotion!
493 return evaluate_int_binop(expr);
496 static struct symbol *evaluate_binop(struct expression *expr)
498 switch (expr->op) {
499 // addition can take ptr+int, fp and int
500 case '+':
501 return evaluate_add(expr);
503 // subtraction can take ptr-ptr, fp and int
504 case '-':
505 return evaluate_sub(expr);
507 // Arithmetic operations can take fp and int
508 case '*': case '/': case '%':
509 return evaluate_arithmetic(expr);
511 // The rest are integer operations (bitops)
512 // SPECIAL_LEFTSHIFT, SPECIAL_RIGHTSHIFT
513 // '&', '^', '|'
514 default:
515 return evaluate_int_binop(expr);
519 static struct symbol *evaluate_comma(struct expression *expr)
521 expr->ctype = expr->right->ctype;
522 return expr->ctype;
525 static struct symbol *evaluate_compare(struct expression *expr)
527 struct expression *left = expr->left, *right = expr->right;
528 struct symbol *ltype = left->ctype, *rtype = right->ctype;
529 struct symbol *ctype;
531 /* Pointer types? */
532 if (is_ptr_type(ltype) || is_ptr_type(rtype)) {
533 expr->ctype = &bool_ctype;
534 // FIXME! Check the types for compatibility
535 return &bool_ctype;
538 ctype = compatible_integer_binop(expr, &expr->left, &expr->right);
539 if (ctype) {
540 expr->ctype = &bool_ctype;
541 return &bool_ctype;
544 return bad_expr_type(expr);
547 static int compatible_integer_types(struct symbol *ltype, struct symbol *rtype)
549 /* Integer promotion? */
550 if (ltype->type == SYM_NODE)
551 ltype = ltype->ctype.base_type;
552 if (rtype->type == SYM_NODE)
553 rtype = rtype->ctype.base_type;
554 if (ltype->type == SYM_ENUM || ltype->type == SYM_BITFIELD)
555 ltype = &int_ctype;
556 if (rtype->type == SYM_ENUM || rtype->type == SYM_BITFIELD)
557 rtype = &int_ctype;
558 return (is_int_type(ltype) && is_int_type(rtype));
561 static int is_null_ptr(struct expression *expr)
563 return (expr->type == EXPR_VALUE &&
564 expr->value == 0);
568 * FIXME!! This should do casts, array degeneration etc..
570 static struct symbol *compatible_ptr_type(struct expression *left, struct expression *right)
572 struct symbol *ltype = left->ctype, *rtype = right->ctype;
574 if (ltype->type == SYM_NODE)
575 ltype = ltype->ctype.base_type;
577 if (ltype->type == SYM_PTR) {
578 if (is_null_ptr(right) || rtype->ctype.base_type == &void_ctype)
579 return ltype;
582 if (rtype->type == SYM_NODE)
583 rtype = rtype->ctype.base_type;
585 if (rtype->type == SYM_PTR) {
586 if (is_null_ptr(left) || ltype->ctype.base_type == &void_ctype)
587 return rtype;
589 return NULL;
592 static struct symbol *do_degenerate(struct expression **ep)
594 struct expression *expr = *ep;
595 return degenerate(expr, expr->ctype, ep);
598 static struct symbol * evaluate_conditional(struct expression *expr)
600 struct expression *cond, *true, *false;
601 struct symbol *ctype, *ltype, *rtype;
602 const char * typediff;
604 ctype = do_degenerate(&expr->conditional);
605 cond = expr->conditional;
607 ltype = ctype;
608 true = cond;
609 if (expr->cond_true) {
610 ltype = do_degenerate(&expr->cond_true);
611 true = expr->cond_true;
614 rtype = do_degenerate(&expr->cond_false);
615 false = expr->cond_false;
617 ctype = ltype;
618 typediff = type_difference(ltype, rtype, MOD_IGN, MOD_IGN);
619 if (typediff) {
620 ctype = compatible_integer_binop(expr, &true, &expr->cond_false);
621 if (!ctype) {
622 ctype = compatible_ptr_type(true, expr->cond_false);
623 if (!ctype) {
624 warn(expr->pos, "incompatible types in conditional expression (%s)", typediff);
625 return NULL;
630 expr->ctype = ctype;
631 return ctype;
634 static int compatible_assignment_types(struct expression *expr, struct symbol *target,
635 struct expression **rp, struct symbol *source, const char *where)
637 const char *typediff;
638 struct symbol *t;
639 int target_as;
641 /* It's ok if the target is more volatile or const than the source */
642 typediff = type_difference(target, source, MOD_VOLATILE | MOD_CONST, 0);
643 if (!typediff)
644 return 1;
646 if (compatible_integer_types(target, source)) {
647 if (target->bit_size != source->bit_size)
648 *rp = cast_to(*rp, target);
649 return 1;
652 /* Pointer destination? */
653 t = target;
654 target_as = t->ctype.as;
655 if (t->type == SYM_NODE) {
656 t = t->ctype.base_type;
657 target_as |= t->ctype.as;
659 if (t->type == SYM_PTR || t->type == SYM_FN) {
660 struct expression *right = *rp;
661 struct symbol *s = source;
662 int source_as;
664 // NULL pointer is always ok
665 if (right->type == EXPR_VALUE && !right->value)
666 return 1;
668 /* "void *" matches anything as long as the address space is ok */
669 source_as = s->ctype.as;
670 if (s->type == SYM_NODE) {
671 s = s->ctype.base_type;
672 source_as |= s->ctype.as;
674 if (source_as == target_as && (s->type == SYM_PTR || s->type == SYM_ARRAY)) {
675 s = s->ctype.base_type;
676 t = t->ctype.base_type;
677 if (s == &void_ctype || t == &void_ctype)
678 return 1;
682 // FIXME!! Cast it?
683 warn(expr->pos, "incorrect type in %s (%s)", where, typediff);
684 warn(expr->pos, " expected %s", show_typename(target));
685 warn(expr->pos, " got %s", show_typename(source));
686 return 0;
690 * FIXME!! This is wrong from a double evaluation standpoint. We can't
691 * just expand the expression twice, that would make any side effects
692 * happen twice too.
694 static struct symbol *evaluate_binop_assignment(struct expression *expr, struct expression *left, struct expression *right)
696 int op = expr->op;
697 struct expression *subexpr = alloc_expression(expr->pos, EXPR_BINOP);
698 static const int op_trans[] = {
699 [SPECIAL_ADD_ASSIGN - SPECIAL_BASE] = '+',
700 [SPECIAL_SUB_ASSIGN - SPECIAL_BASE] = '-',
701 [SPECIAL_MUL_ASSIGN - SPECIAL_BASE] = '*',
702 [SPECIAL_DIV_ASSIGN - SPECIAL_BASE] = '/',
703 [SPECIAL_MOD_ASSIGN - SPECIAL_BASE] = '%',
704 [SPECIAL_SHL_ASSIGN - SPECIAL_BASE] = SPECIAL_LEFTSHIFT,
705 [SPECIAL_SHR_ASSIGN - SPECIAL_BASE] = SPECIAL_RIGHTSHIFT,
706 [SPECIAL_AND_ASSIGN - SPECIAL_BASE] = '&',
707 [SPECIAL_OR_ASSIGN - SPECIAL_BASE] = '|',
708 [SPECIAL_XOR_ASSIGN - SPECIAL_BASE] = '^'
711 subexpr->left = left;
712 subexpr->right = right;
713 subexpr->op = op_trans[op - SPECIAL_BASE];
714 expr->op = '=';
715 expr->right = subexpr;
716 return evaluate_binop(subexpr);
719 static struct symbol *evaluate_assignment(struct expression *expr)
721 struct expression *left = expr->left, *right = expr->right;
722 struct symbol *ltype, *rtype;
724 ltype = left->ctype;
725 rtype = right->ctype;
726 if (expr->op != '=') {
727 rtype = evaluate_binop_assignment(expr, left, right);
728 if (!rtype)
729 return 0;
730 right = expr->right;
733 if (!lvalue_expression(left)) {
734 warn(expr->pos, "not an lvalue");
735 return NULL;
738 rtype = degenerate(right, rtype, &expr->right);
740 if (!compatible_assignment_types(expr, ltype, &expr->right, rtype, "assignment"))
741 return 0;
743 if (ltype->type == SYM_NODE)
744 ltype->ctype.modifiers |= MOD_ASSIGNED;
746 expr->ctype = ltype;
747 return ltype;
750 static struct symbol *evaluate_addressof(struct expression *expr)
752 struct symbol *ctype, *symbol;
753 struct expression *op = expr->unop;
755 if (op->op != '*' || op->type != EXPR_PREOP) {
756 warn(expr->pos, "not addressable");
757 return NULL;
760 symbol = alloc_symbol(expr->pos, SYM_PTR);
761 symbol->ctype.alignment = POINTER_ALIGNMENT;
762 symbol->bit_size = BITS_IN_POINTER;
764 ctype = op->ctype;
765 if (ctype->type == SYM_NODE) {
766 ctype->ctype.modifiers |= MOD_ADDRESSABLE;
767 if (ctype->ctype.modifiers & MOD_REGISTER) {
768 warn(expr->pos, "taking address of 'register' variable '%s'", show_ident(ctype->ident));
769 ctype->ctype.modifiers &= ~MOD_REGISTER;
771 symbol->ctype.modifiers = ctype->ctype.modifiers;
772 symbol->ctype.as = ctype->ctype.as;
773 symbol->ctype.context = ctype->ctype.context;
774 symbol->ctype.contextmask = ctype->ctype.contextmask;
775 ctype = ctype->ctype.base_type;
778 symbol->ctype.base_type = ctype;
779 *expr = *op->unop;
780 expr->ctype = symbol;
781 return symbol;
785 static struct symbol *evaluate_dereference(struct expression *expr)
787 struct expression *op = expr->unop;
788 struct symbol *ctype = op->ctype, *sym;
790 sym = alloc_symbol(expr->pos, SYM_NODE);
791 if (ctype->type == SYM_NODE) {
792 ctype = ctype->ctype.base_type;
793 merge_type(sym, ctype);
795 sym->ctype = ctype->ctype;
796 if (ctype->type != SYM_PTR && ctype->type != SYM_ARRAY) {
797 warn(expr->pos, "cannot derefence this type");
798 return 0;
801 ctype = ctype->ctype.base_type;
802 examine_symbol_type(ctype);
803 if (!ctype) {
804 warn(expr->pos, "undefined type");
805 return NULL;
808 sym->bit_size = ctype->bit_size;
809 sym->array_size = ctype->array_size;
811 /* Simplify: *&(expr) => (expr) */
812 if (op->type == EXPR_PREOP && op->op == '&') {
813 *expr = *op->unop;
816 expr->ctype = sym;
817 return sym;
821 * Unary post-ops: x++ and x--
823 static struct symbol *evaluate_postop(struct expression *expr)
825 struct expression *op = expr->unop;
826 struct symbol *ctype = op->ctype;
828 if (!lvalue_expression(expr->unop)) {
829 warn(expr->pos, "need lvalue expression for ++/--");
830 return NULL;
832 expr->ctype = ctype;
833 return ctype;
836 static struct symbol *evaluate_preop(struct expression *expr)
838 struct symbol *ctype = expr->unop->ctype;
840 switch (expr->op) {
841 case '(':
842 case '+':
843 *expr = *expr->unop;
844 return ctype;
846 case '*':
847 return evaluate_dereference(expr);
849 case '&':
850 return evaluate_addressof(expr);
852 case SPECIAL_INCREMENT:
853 case SPECIAL_DECREMENT:
855 * From a type evaluation standpoint the pre-ops are
856 * the same as the postops
858 return evaluate_postop(expr);
860 case '!':
861 ctype = &bool_ctype;
862 break;
864 default:
865 break;
867 expr->ctype = ctype;
868 return &bool_ctype;
871 struct symbol *find_identifier(struct ident *ident, struct symbol_list *_list, int *offset)
873 struct ptr_list *head = (struct ptr_list *)_list;
874 struct ptr_list *list = head;
876 if (!head)
877 return NULL;
878 do {
879 int i;
880 for (i = 0; i < list->nr; i++) {
881 struct symbol *sym = (struct symbol *) list->list[i];
882 if (sym->ident) {
883 if (sym->ident != ident)
884 continue;
885 *offset = sym->offset;
886 return sym;
887 } else {
888 struct symbol *ctype = sym->ctype.base_type;
889 struct symbol *sub;
890 if (!ctype)
891 continue;
892 if (ctype->type != SYM_UNION && ctype->type != SYM_STRUCT)
893 continue;
894 sub = find_identifier(ident, ctype->symbol_list, offset);
895 if (!sub)
896 continue;
897 *offset += sym->offset;
898 return sub;
901 } while ((list = list->next) != head);
902 return NULL;
905 static struct expression *evaluate_offset(struct expression *expr, unsigned long offset)
907 struct expression *add;
909 if (!offset)
910 return expr;
912 /* Create a new add-expression */
913 add = alloc_expression(expr->pos, EXPR_BINOP);
914 add->op = '+';
915 add->ctype = &ptr_ctype;
916 add->left = expr;
917 add->right = alloc_expression(expr->pos, EXPR_VALUE);
918 add->right->ctype = &int_ctype;
919 add->right->value = offset;
921 return add;
924 /* structure/union dereference */
925 static struct symbol *evaluate_member_dereference(struct expression *expr)
927 int offset;
928 struct symbol *ctype, *member, *sym;
929 struct expression *deref = expr->deref, *add;
930 struct ident *ident = expr->member;
931 unsigned int mod;
932 int address_space;
934 if (!evaluate_expression(deref))
935 return NULL;
936 if (!ident) {
937 warn(expr->pos, "bad member name");
938 return NULL;
941 ctype = deref->ctype;
942 address_space = ctype->ctype.as;
943 mod = ctype->ctype.modifiers;
944 if (ctype->type == SYM_NODE) {
945 ctype = ctype->ctype.base_type;
946 address_space |= ctype->ctype.as;
947 mod |= ctype->ctype.modifiers;
949 if (expr->op == SPECIAL_DEREFERENCE) {
950 /* Arrays will degenerate into pointers for '->' */
951 if (ctype->type != SYM_PTR && ctype->type != SYM_ARRAY) {
952 warn(expr->pos, "expected a pointer to a struct/union");
953 return NULL;
955 mod = ctype->ctype.modifiers;
956 address_space = ctype->ctype.as;
957 ctype = ctype->ctype.base_type;
958 if (ctype->type == SYM_NODE) {
959 mod |= ctype->ctype.modifiers;
960 address_space |= ctype->ctype.as;
961 ctype = ctype->ctype.base_type;
963 } else {
964 if (!lvalue_expression(deref)) {
965 warn(deref->pos, "expected lvalue for member dereference");
966 return NULL;
968 deref = deref->unop;
969 expr->deref = deref;
971 if (!ctype || (ctype->type != SYM_STRUCT && ctype->type != SYM_UNION)) {
972 warn(expr->pos, "expected structure or union");
973 return NULL;
975 offset = 0;
976 member = find_identifier(ident, ctype->symbol_list, &offset);
977 if (!member) {
978 const char *type = ctype->type == SYM_STRUCT ? "struct" : "union";
979 const char *name = "<unnamed>";
980 int namelen = 9;
981 if (ctype->ident) {
982 name = ctype->ident->name;
983 namelen = ctype->ident->len;
985 warn(expr->pos, "no member '%s' in %s %.*s",
986 show_ident(ident), type, namelen, name);
987 return NULL;
990 add = evaluate_offset(deref, offset);
992 sym = alloc_symbol(expr->pos, SYM_NODE);
993 sym->bit_size = member->bit_size;
994 sym->array_size = member->array_size;
995 sym->ctype = member->ctype;
996 sym->ctype.modifiers = mod;
997 sym->ctype.as = address_space;
998 ctype = member->ctype.base_type;
999 if (ctype->type == SYM_BITFIELD) {
1000 ctype = ctype->ctype.base_type;
1001 expr->type = EXPR_BITFIELD;
1002 expr->bitpos = member->bit_offset;
1003 expr->nrbits = member->fieldwidth;
1004 expr->address = add;
1005 } else {
1006 expr->type = EXPR_PREOP;
1007 expr->op = '*';
1008 expr->unop = add;
1011 expr->ctype = sym;
1012 return sym;
1015 static struct symbol *evaluate_sizeof(struct expression *expr)
1017 int size;
1019 if (expr->cast_type) {
1020 examine_symbol_type(expr->cast_type);
1021 size = expr->cast_type->bit_size;
1022 } else {
1023 if (!evaluate_expression(expr->cast_expression))
1024 return 0;
1025 size = expr->cast_expression->ctype->bit_size;
1027 if (size & 7) {
1028 warn(expr->pos, "cannot size expression");
1029 return 0;
1031 expr->type = EXPR_VALUE;
1032 expr->value = size >> 3;
1033 expr->ctype = size_t_ctype;
1034 return size_t_ctype;
1037 static int context_clash(struct symbol *sym1, struct symbol *sym2)
1039 unsigned long clash = (sym1->ctype.context ^ sym2->ctype.context);
1040 clash &= (sym1->ctype.contextmask & sym2->ctype.contextmask);
1041 return clash != 0;
1044 static int evaluate_arguments(struct symbol *f, struct symbol *fn, struct expression_list *head)
1046 struct expression *expr;
1047 struct symbol_list *argument_types = fn->arguments;
1048 struct symbol *argtype;
1049 int i = 1;
1051 PREPARE_PTR_LIST(argument_types, argtype);
1052 FOR_EACH_PTR (head, expr) {
1053 struct expression **p = THIS_ADDRESS(expr);
1054 struct symbol *ctype, *target;
1055 ctype = evaluate_expression(expr);
1057 if (!ctype)
1058 return 0;
1060 if (context_clash(f, ctype))
1061 warn(expr->pos, "argument %d used in wrong context", i);
1063 ctype = degenerate(expr, ctype, p);
1065 target = argtype;
1066 if (!target && ctype->bit_size < BITS_IN_INT)
1067 target = &int_ctype;
1068 if (target) {
1069 static char where[30];
1070 examine_symbol_type(target);
1071 sprintf(where, "argument %d", i);
1072 compatible_assignment_types(expr, target, p, ctype, where);
1075 i++;
1076 NEXT_PTR_LIST(argtype);
1077 } END_FOR_EACH_PTR;
1078 FINISH_PTR_LIST(argtype);
1079 return 1;
1082 static int evaluate_initializer(struct symbol *ctype, struct expression **ep, unsigned long offset);
1083 static int evaluate_array_initializer(struct symbol *ctype, struct expression *expr, unsigned long offset)
1085 struct expression *entry;
1086 int current = 0;
1087 int max = 0;
1089 FOR_EACH_PTR(expr->expr_list, entry) {
1090 struct expression **p = THIS_ADDRESS(entry);
1092 if (entry->type == EXPR_INDEX) {
1093 current = entry->idx_to;
1094 continue;
1096 evaluate_initializer(ctype, p, offset + current*(ctype->bit_size>>3));
1097 current++;
1098 if (current > max)
1099 max = current;
1100 } END_FOR_EACH_PTR;
1101 return max;
1104 static int evaluate_struct_or_union_initializer(struct symbol *ctype, struct expression *expr, int multiple, unsigned long offset)
1106 struct expression *entry;
1107 struct symbol *sym;
1109 PREPARE_PTR_LIST(ctype->symbol_list, sym);
1110 FOR_EACH_PTR(expr->expr_list, entry) {
1111 struct expression **p = THIS_ADDRESS(entry);
1113 if (entry->type == EXPR_IDENTIFIER) {
1114 struct ident *ident = entry->expr_ident;
1115 /* We special-case the "already right place" case */
1116 if (sym && sym->ident == ident)
1117 continue;
1118 RESET_PTR_LIST(sym);
1119 for (;;) {
1120 if (!sym) {
1121 warn(entry->pos, "unknown named initializer '%s'", show_ident(ident));
1122 return 0;
1124 if (sym->ident == ident)
1125 break;
1126 NEXT_PTR_LIST(sym);
1128 continue;
1131 if (!sym) {
1132 warn(expr->pos, "too many initializers for struct/union");
1133 return 0;
1136 evaluate_initializer(sym, p, offset + sym->offset);
1138 NEXT_PTR_LIST(sym);
1139 } END_FOR_EACH_PTR;
1140 FINISH_PTR_LIST(sym);
1142 return 0;
1146 * Initializers are kind of like assignments. Except
1147 * they can be a hell of a lot more complex.
1149 static int evaluate_initializer(struct symbol *ctype, struct expression **ep, unsigned long offset)
1151 struct expression *expr = *ep;
1154 * Simple non-structure/array initializers are the simple
1155 * case, and look (and parse) largely like assignments.
1157 if (expr->type != EXPR_INITIALIZER) {
1158 int size = 0;
1159 struct symbol *rtype = evaluate_expression(expr);
1160 if (rtype) {
1161 struct expression *pos;
1163 // FIXME! char array[] = "string" special case
1164 // should _not_ degenerate.
1165 rtype = degenerate(expr, rtype, ep);
1166 expr = *ep;
1167 compatible_assignment_types(expr, ctype, ep, rtype, "initializer");
1168 /* strings are special: char arrays */
1169 if (rtype->type == SYM_ARRAY)
1170 size = rtype->array_size;
1172 * Don't bother creating a position expression for
1173 * the simple initializer cases that don't need it.
1175 * We need a position if the initializer has a byte
1176 * offset, _or_ if we're initializing a bitfield.
1178 if (offset || ctype->fieldwidth) {
1179 pos = alloc_expression(expr->pos, EXPR_POS);
1180 pos->init_offset = offset;
1181 pos->init_sym = ctype;
1182 pos->init_expr = *ep;
1183 pos->ctype = expr->ctype;
1184 *ep = pos;
1187 return size;
1190 expr->ctype = ctype;
1191 if (ctype->type == SYM_NODE)
1192 ctype = ctype->ctype.base_type;
1194 switch (ctype->type) {
1195 case SYM_ARRAY:
1196 case SYM_PTR:
1197 return evaluate_array_initializer(ctype->ctype.base_type, expr, offset);
1198 case SYM_UNION:
1199 return evaluate_struct_or_union_initializer(ctype, expr, 0, offset);
1200 case SYM_STRUCT:
1201 return evaluate_struct_or_union_initializer(ctype, expr, 1, offset);
1202 default:
1203 break;
1205 warn(expr->pos, "unexpected compound initializer");
1206 return 0;
1209 static struct symbol *evaluate_cast(struct expression *expr)
1211 struct expression *target = expr->cast_expression;
1212 struct symbol *ctype = examine_symbol_type(expr->cast_type);
1214 expr->ctype = ctype;
1215 expr->cast_type = ctype;
1218 * Special case: a cast can be followed by an
1219 * initializer, in which case we need to pass
1220 * the type value down to that initializer rather
1221 * than trying to evaluate it as an expression
1223 if (target->type == EXPR_INITIALIZER) {
1224 evaluate_initializer(ctype, &expr->cast_expression, 0);
1225 return ctype;
1228 evaluate_expression(target);
1231 * Casts of constant values are special: they
1232 * can be NULL, and thus need to be simplified
1233 * early.
1235 if (target->type == EXPR_VALUE)
1236 cast_value(expr, ctype, target, target->ctype);
1238 return ctype;
1242 * Evaluate a call expression with a symbol. This
1243 * should expand inline functions, and evaluate
1244 * builtins.
1246 static int evaluate_symbol_call(struct expression *expr)
1248 struct expression *fn = expr->fn;
1249 struct symbol *ctype = fn->ctype;
1251 if (fn->type != EXPR_PREOP)
1252 return 0;
1254 if (ctype->op && ctype->op->evaluate)
1255 return ctype->op->evaluate(expr);
1257 if (ctype->ctype.modifiers & MOD_INLINE) {
1258 int ret;
1259 struct symbol *curr = current_fn;
1260 unsigned long context = current_context;
1261 unsigned long mask = current_contextmask;
1263 current_context |= ctype->ctype.context;
1264 current_contextmask |= ctype->ctype.contextmask;
1265 current_fn = ctype->ctype.base_type;
1266 ret = inline_function(expr, ctype);
1268 /* restore the old function context */
1269 current_fn = curr;
1270 current_context = context;
1271 current_contextmask = mask;
1272 return ret;
1275 return 0;
1278 static struct symbol *evaluate_call(struct expression *expr)
1280 int args, fnargs;
1281 struct symbol *ctype, *sym;
1282 struct expression *fn = expr->fn;
1283 struct expression_list *arglist = expr->args;
1285 if (!evaluate_expression(fn))
1286 return NULL;
1287 sym = ctype = fn->ctype;
1288 if (ctype->type == SYM_NODE)
1289 ctype = ctype->ctype.base_type;
1290 if (ctype->type == SYM_PTR || ctype->type == SYM_ARRAY)
1291 ctype = ctype->ctype.base_type;
1292 if (!evaluate_arguments(sym, ctype, arglist))
1293 return NULL;
1294 if (sym->type == SYM_NODE) {
1295 if (evaluate_symbol_call(expr))
1296 return expr->ctype;
1298 if (sym->type == SYM_NODE) {
1299 if (evaluate_symbol_call(expr))
1300 return expr->ctype;
1302 if (ctype->type != SYM_FN) {
1303 warn(expr->pos, "not a function");
1304 return NULL;
1306 args = expression_list_size(expr->args);
1307 fnargs = symbol_list_size(ctype->arguments);
1308 if (args < fnargs)
1309 warn(expr->pos, "not enough arguments for function");
1310 if (args > fnargs && !ctype->variadic)
1311 warn(expr->pos, "too many arguments for function");
1312 expr->ctype = ctype->ctype.base_type;
1313 return expr->ctype;
1316 struct symbol *evaluate_expression(struct expression *expr)
1318 if (!expr)
1319 return NULL;
1320 if (expr->ctype)
1321 return expr->ctype;
1323 switch (expr->type) {
1324 case EXPR_VALUE:
1325 warn(expr->pos, "value expression without a type");
1326 return NULL;
1327 case EXPR_STRING:
1328 return evaluate_string(expr);
1329 case EXPR_SYMBOL:
1330 return evaluate_symbol_expression(expr);
1331 case EXPR_BINOP:
1332 if (!evaluate_expression(expr->left))
1333 return NULL;
1334 if (!evaluate_expression(expr->right))
1335 return NULL;
1336 return evaluate_binop(expr);
1337 case EXPR_LOGICAL:
1338 return evaluate_logical(expr);
1339 case EXPR_COMMA:
1340 if (!evaluate_expression(expr->left))
1341 return NULL;
1342 if (!evaluate_expression(expr->right))
1343 return NULL;
1344 return evaluate_comma(expr);
1345 case EXPR_COMPARE:
1346 if (!evaluate_expression(expr->left))
1347 return NULL;
1348 if (!evaluate_expression(expr->right))
1349 return NULL;
1350 return evaluate_compare(expr);
1351 case EXPR_ASSIGNMENT:
1352 if (!evaluate_expression(expr->left))
1353 return NULL;
1354 if (!evaluate_expression(expr->right))
1355 return NULL;
1356 return evaluate_assignment(expr);
1357 case EXPR_PREOP:
1358 if (!evaluate_expression(expr->unop))
1359 return NULL;
1360 return evaluate_preop(expr);
1361 case EXPR_POSTOP:
1362 if (!evaluate_expression(expr->unop))
1363 return NULL;
1364 return evaluate_postop(expr);
1365 case EXPR_CAST:
1366 return evaluate_cast(expr);
1367 case EXPR_SIZEOF:
1368 return evaluate_sizeof(expr);
1369 case EXPR_DEREF:
1370 return evaluate_member_dereference(expr);
1371 case EXPR_CALL:
1372 return evaluate_call(expr);
1373 case EXPR_BITFIELD:
1374 warn(expr->pos, "bitfield generated by parser");
1375 return NULL;
1376 case EXPR_CONDITIONAL:
1377 if (!evaluate_expression(expr->conditional))
1378 return NULL;
1379 if (!evaluate_expression(expr->cond_false))
1380 return NULL;
1381 if (expr->cond_true && !evaluate_expression(expr->cond_true))
1382 return NULL;
1383 return evaluate_conditional(expr);
1384 case EXPR_STATEMENT:
1385 expr->ctype = evaluate_statement(expr->statement);
1386 return expr->ctype;
1388 case EXPR_LABEL:
1389 expr->ctype = &ptr_ctype;
1390 return &ptr_ctype;
1392 /* These can not exist as stand-alone expressions */
1393 case EXPR_INITIALIZER:
1394 case EXPR_IDENTIFIER:
1395 case EXPR_INDEX:
1396 case EXPR_POS:
1397 warn(expr->pos, "internal front-end error: initializer in expression");
1398 return NULL;
1400 return NULL;
1403 void check_duplicates(struct symbol *sym)
1405 struct symbol *next = sym;
1407 while ((next = next->same_symbol) != NULL) {
1408 const char *typediff;
1409 evaluate_symbol(next);
1410 typediff = type_difference(sym, next, 0, 0);
1411 if (typediff) {
1412 warn(sym->pos, "symbol '%s' redeclared with different type (originally declared at %s:%d) - %s",
1413 show_ident(sym->ident),
1414 input_streams[next->pos.stream].name, next->pos.line, typediff);
1415 return;
1420 struct symbol *evaluate_symbol(struct symbol *sym)
1422 struct symbol *base_type;
1424 if (!sym)
1425 return sym;
1427 sym = examine_symbol_type(sym);
1428 base_type = sym->ctype.base_type;
1429 if (!base_type)
1430 return NULL;
1432 /* Evaluate the initializers */
1433 if (sym->initializer) {
1434 int count = evaluate_initializer(sym, &sym->initializer, 0);
1435 if (base_type->type == SYM_ARRAY && base_type->array_size < 0) {
1436 int bit_size = count * base_type->ctype.base_type->bit_size;
1437 base_type->array_size = count;
1438 base_type->bit_size = bit_size;
1439 sym->array_size = count;
1440 sym->bit_size = bit_size;
1444 /* And finally, evaluate the body of the symbol too */
1445 if (base_type->type == SYM_FN) {
1446 struct symbol *s;
1448 FOR_EACH_PTR(base_type->arguments, s) {
1449 evaluate_symbol(s);
1450 } END_FOR_EACH_PTR;
1452 if (base_type->stmt) {
1453 current_fn = base_type;
1454 current_contextmask = sym->ctype.contextmask;
1455 current_context = sym->ctype.context;
1456 evaluate_statement(base_type->stmt);
1460 return base_type;
1463 struct symbol *evaluate_return_expression(struct statement *stmt)
1465 struct expression *expr = stmt->expression;
1466 struct symbol *ctype, *fntype;
1468 fntype = current_fn->ctype.base_type;
1469 if (!fntype || fntype == &void_ctype) {
1470 if (expr)
1471 warn(expr->pos, "return expression in %s function", fntype?"void":"typeless");
1472 return NULL;
1475 if (!expr) {
1476 warn(stmt->pos, "return with no return value");
1477 return NULL;
1479 ctype = evaluate_expression(expr);
1480 if (!ctype)
1481 return NULL;
1482 ctype = degenerate(expr, ctype, &expr);
1483 expr->ctype = ctype;
1484 compatible_assignment_types(expr, fntype, &expr, ctype, "return expression");
1485 stmt->expression = expr;
1486 return NULL;
1489 static void evaluate_if_statement(struct statement *stmt)
1491 struct expression *expr = stmt->if_conditional;
1492 struct symbol *ctype;
1494 if (!expr)
1495 return;
1496 if (expr->type == EXPR_ASSIGNMENT)
1497 warn(expr->pos, "assignment expression in conditional");
1499 ctype = evaluate_expression(expr);
1500 if (!ctype)
1501 return;
1503 evaluate_statement(stmt->if_true);
1504 evaluate_statement(stmt->if_false);
1507 struct symbol *evaluate_statement(struct statement *stmt)
1509 if (!stmt)
1510 return NULL;
1512 switch (stmt->type) {
1513 case STMT_RETURN:
1514 return evaluate_return_expression(stmt);
1516 case STMT_EXPRESSION:
1517 return evaluate_expression(stmt->expression);
1519 case STMT_COMPOUND: {
1520 struct statement *s;
1521 struct symbol *type = NULL;
1522 struct symbol *sym;
1524 /* Evaluate each symbol in the compound statement */
1525 FOR_EACH_PTR(stmt->syms, sym) {
1526 evaluate_symbol(sym);
1527 } END_FOR_EACH_PTR;
1528 evaluate_symbol(stmt->ret);
1531 * Then, evaluate each statement, making the type of the
1532 * compound statement be the type of the last statement
1534 type = NULL;
1535 FOR_EACH_PTR(stmt->stmts, s) {
1536 type = evaluate_statement(s);
1537 } END_FOR_EACH_PTR;
1538 return type;
1540 case STMT_IF:
1541 evaluate_if_statement(stmt);
1542 return NULL;
1543 case STMT_ITERATOR:
1544 evaluate_expression(stmt->iterator_pre_condition);
1545 evaluate_expression(stmt->iterator_post_condition);
1546 evaluate_statement(stmt->iterator_pre_statement);
1547 evaluate_statement(stmt->iterator_statement);
1548 evaluate_statement(stmt->iterator_post_statement);
1549 return NULL;
1550 case STMT_SWITCH:
1551 evaluate_expression(stmt->switch_expression);
1552 evaluate_statement(stmt->switch_statement);
1553 return NULL;
1554 case STMT_CASE:
1555 evaluate_expression(stmt->case_expression);
1556 evaluate_expression(stmt->case_to);
1557 evaluate_statement(stmt->case_statement);
1558 return NULL;
1559 case STMT_LABEL:
1560 evaluate_statement(stmt->label_statement);
1561 return NULL;
1562 case STMT_GOTO:
1563 evaluate_expression(stmt->goto_expression);
1564 return NULL;
1565 case STMT_NONE:
1566 break;
1567 case STMT_ASM:
1568 /* FIXME! Do the asm parameter evaluation! */
1569 break;
1571 return NULL;