4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Licensed under the Open Software License version 1.1
9 * Evaluate constant expressions.
27 #include "expression.h"
29 struct symbol
*current_fn
;
31 static struct symbol
*degenerate(struct expression
*expr
);
32 static struct symbol
*evaluate_symbol(struct symbol
*sym
);
34 static struct symbol
*evaluate_symbol_expression(struct expression
*expr
)
36 struct expression
*addr
;
37 struct symbol
*sym
= expr
->symbol
;
38 struct symbol
*base_type
;
41 sparse_error(expr
->pos
, "undefined identifier '%s'", show_ident(expr
->symbol_name
));
45 examine_symbol_type(sym
);
47 base_type
= get_base_type(sym
);
49 sparse_error(expr
->pos
, "identifier '%s' has no type", show_ident(expr
->symbol_name
));
53 addr
= alloc_expression(expr
->pos
, EXPR_SYMBOL
);
55 addr
->symbol_name
= expr
->symbol_name
;
56 addr
->ctype
= &lazy_ptr_ctype
; /* Lazy evaluation: we need to do a proper job if somebody does &sym */
57 expr
->type
= EXPR_PREOP
;
61 /* The type of a symbol is the symbol itself! */
66 static struct symbol
*evaluate_string(struct expression
*expr
)
68 struct symbol
*sym
= alloc_symbol(expr
->pos
, SYM_NODE
);
69 struct symbol
*array
= alloc_symbol(expr
->pos
, SYM_ARRAY
);
70 struct expression
*addr
= alloc_expression(expr
->pos
, EXPR_SYMBOL
);
71 struct expression
*initstr
= alloc_expression(expr
->pos
, EXPR_STRING
);
72 unsigned int length
= expr
->string
->length
;
74 sym
->array_size
= alloc_const_expression(expr
->pos
, length
);
75 sym
->bit_size
= bits_in_char
* length
;
76 sym
->ctype
.alignment
= 1;
77 sym
->ctype
.modifiers
= MOD_STATIC
;
78 sym
->ctype
.base_type
= array
;
79 sym
->initializer
= initstr
;
82 initstr
->string
= expr
->string
;
84 array
->array_size
= sym
->array_size
;
85 array
->bit_size
= bits_in_char
* length
;
86 array
->ctype
.alignment
= 1;
87 array
->ctype
.modifiers
= MOD_STATIC
;
88 array
->ctype
.base_type
= &char_ctype
;
91 addr
->ctype
= &lazy_ptr_ctype
;
93 expr
->type
= EXPR_PREOP
;
100 static inline struct symbol
*integer_promotion(struct symbol
*type
)
102 struct symbol
*orig_type
= type
;
103 unsigned long mod
= type
->ctype
.modifiers
;
106 if (type
->type
== SYM_NODE
)
107 type
= type
->ctype
.base_type
;
108 if (type
->type
== SYM_ENUM
)
109 type
= type
->ctype
.base_type
;
110 width
= type
->bit_size
;
113 * Bitfields always promote to the base type,
114 * even if the bitfield might be bigger than
117 if (type
->type
== SYM_BITFIELD
) {
118 type
= type
->ctype
.base_type
;
121 mod
= type
->ctype
.modifiers
;
122 if (width
< bits_in_int
)
125 /* If char/short has as many bits as int, it still gets "promoted" */
126 if (mod
& (MOD_CHAR
| MOD_SHORT
)) {
127 if (mod
& MOD_UNSIGNED
)
135 * integer part of usual arithmetic conversions:
136 * integer promotions are applied
137 * if left and right are identical, we are done
138 * if signedness is the same, convert one with lower rank
139 * unless unsigned argument has rank lower than signed one, convert the
141 * if signed argument is bigger than unsigned one, convert the unsigned.
142 * otherwise, convert signed.
144 * Leaving aside the integer promotions, that is equivalent to
145 * if identical, don't convert
146 * if left is bigger than right, convert right
147 * if right is bigger than left, convert right
148 * otherwise, if signedness is the same, convert one with lower rank
149 * otherwise convert the signed one.
151 static struct symbol
*bigger_int_type(struct symbol
*left
, struct symbol
*right
)
153 unsigned long lmod
, rmod
;
155 left
= integer_promotion(left
);
156 right
= integer_promotion(right
);
161 if (left
->bit_size
> right
->bit_size
)
164 if (right
->bit_size
> left
->bit_size
)
167 lmod
= left
->ctype
.modifiers
;
168 rmod
= right
->ctype
.modifiers
;
169 if ((lmod
^ rmod
) & MOD_UNSIGNED
) {
170 if (lmod
& MOD_UNSIGNED
)
172 } else if ((lmod
& ~rmod
) & (MOD_LONG
| MOD_LONGLONG
))
180 static int same_cast_type(struct symbol
*orig
, struct symbol
*new)
182 return orig
->bit_size
== new->bit_size
&& orig
->bit_offset
== orig
->bit_offset
;
185 static struct symbol
*base_type(struct symbol
*node
, unsigned long *modp
, unsigned long *asp
)
187 unsigned long mod
, as
;
191 mod
|= node
->ctype
.modifiers
;
192 as
|= node
->ctype
.as
;
193 if (node
->type
== SYM_NODE
) {
194 node
= node
->ctype
.base_type
;
199 *modp
= mod
& ~MOD_IGNORE
;
204 static int is_same_type(struct expression
*expr
, struct symbol
*new)
206 struct symbol
*old
= expr
->ctype
;
207 unsigned long oldmod
, newmod
, oldas
, newas
;
209 old
= base_type(old
, &oldmod
, &oldas
);
210 new = base_type(new, &newmod
, &newas
);
212 /* Same base type, same address space? */
213 if (old
== new && oldas
== newas
) {
214 unsigned long difmod
;
216 /* Check the modifier bits. */
217 difmod
= (oldmod
^ newmod
) & ~MOD_NOCAST
;
219 /* Exact same type? */
224 * Not the same type, but differs only in "const".
225 * Don't warn about MOD_NOCAST.
227 if (difmod
== MOD_CONST
)
230 if ((oldmod
| newmod
) & MOD_NOCAST
) {
231 const char *tofrom
= "to/from";
232 if (!(newmod
& MOD_NOCAST
))
234 if (!(oldmod
& MOD_NOCAST
))
236 warning(expr
->pos
, "implicit cast %s nocast type", tofrom
);
242 * This gets called for implicit casts in assignments and
243 * integer promotion. We often want to try to move the
244 * cast down, because the ops involved may have been
245 * implicitly cast up, and we can get rid of the casts
248 static struct expression
* cast_to(struct expression
*old
, struct symbol
*type
)
250 struct expression
*expr
;
252 if (is_same_type(old
, type
))
256 * See if we can simplify the op. Move the cast down.
260 if (old
->ctype
->bit_size
< type
->bit_size
)
262 if (old
->op
== '~') {
264 old
->unop
= cast_to(old
->unop
, type
);
269 case EXPR_IMPLIED_CAST
:
270 if (old
->ctype
->bit_size
>= type
->bit_size
) {
271 struct expression
*orig
= old
->cast_expression
;
272 if (same_cast_type(orig
->ctype
, type
))
274 if (old
->ctype
->bit_offset
== type
->bit_offset
) {
276 old
->cast_type
= type
;
286 expr
= alloc_expression(old
->pos
, EXPR_IMPLIED_CAST
);
288 expr
->cast_type
= type
;
289 expr
->cast_expression
= old
;
293 static int is_type_type(struct symbol
*type
)
295 return (type
->ctype
.modifiers
& MOD_TYPE
) != 0;
298 int is_ptr_type(struct symbol
*type
)
300 if (type
->type
== SYM_NODE
)
301 type
= type
->ctype
.base_type
;
302 return type
->type
== SYM_PTR
|| type
->type
== SYM_ARRAY
|| type
->type
== SYM_FN
;
305 static inline int is_float_type(struct symbol
*type
)
307 if (type
->type
== SYM_NODE
)
308 type
= type
->ctype
.base_type
;
309 return type
->ctype
.base_type
== &fp_type
;
312 static inline int is_byte_type(struct symbol
*type
)
314 return type
->bit_size
== bits_in_char
&& type
->type
!= SYM_BITFIELD
;
317 static inline int is_string_type(struct symbol
*type
)
319 if (type
->type
== SYM_NODE
)
320 type
= type
->ctype
.base_type
;
321 return type
->type
== SYM_ARRAY
&& is_byte_type(type
->ctype
.base_type
);
324 static struct symbol
*bad_expr_type(struct expression
*expr
)
326 sparse_error(expr
->pos
, "incompatible types for operation (%s)", show_special(expr
->op
));
327 switch (expr
->type
) {
330 info(expr
->pos
, " left side has type %s", show_typename(expr
->left
->ctype
));
331 info(expr
->pos
, " right side has type %s", show_typename(expr
->right
->ctype
));
335 info(expr
->pos
, " argument has type %s", show_typename(expr
->unop
->ctype
));
344 static struct symbol
*compatible_float_binop(struct expression
**lp
, struct expression
**rp
)
346 struct expression
*left
= *lp
, *right
= *rp
;
347 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
349 if (ltype
->type
== SYM_NODE
)
350 ltype
= ltype
->ctype
.base_type
;
351 if (rtype
->type
== SYM_NODE
)
352 rtype
= rtype
->ctype
.base_type
;
353 if (is_float_type(ltype
)) {
354 if (is_int_type(rtype
))
356 if (is_float_type(rtype
)) {
357 unsigned long lmod
= ltype
->ctype
.modifiers
;
358 unsigned long rmod
= rtype
->ctype
.modifiers
;
359 lmod
&= MOD_LONG
| MOD_LONGLONG
;
360 rmod
&= MOD_LONG
| MOD_LONGLONG
;
370 if (!is_float_type(rtype
) || !is_int_type(ltype
))
373 *lp
= cast_to(left
, rtype
);
376 *rp
= cast_to(right
, ltype
);
380 static struct symbol
*compatible_integer_binop(struct expression
**lp
, struct expression
**rp
)
382 struct expression
*left
= *lp
, *right
= *rp
;
383 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
385 if (ltype
->type
== SYM_NODE
)
386 ltype
= ltype
->ctype
.base_type
;
387 if (rtype
->type
== SYM_NODE
)
388 rtype
= rtype
->ctype
.base_type
;
389 if (is_int_type(ltype
) && is_int_type(rtype
)) {
390 struct symbol
*ctype
= bigger_int_type(ltype
, rtype
);
392 *lp
= cast_to(left
, ctype
);
393 *rp
= cast_to(right
, ctype
);
399 static int restricted_value(struct expression
*v
, struct symbol
*type
)
401 if (v
->type
!= EXPR_VALUE
)
408 static int restricted_binop(int op
, struct symbol
*type
)
417 case SPECIAL_NOTEQUAL
:
418 case SPECIAL_AND_ASSIGN
:
419 case SPECIAL_OR_ASSIGN
:
420 case SPECIAL_XOR_ASSIGN
:
427 static int restricted_unop(int op
, struct symbol
*type
)
429 if (op
== '~' && type
->bit_size
>= bits_in_int
)
436 static struct symbol
*compatible_restricted_binop(int op
, struct expression
**lp
, struct expression
**rp
)
438 struct expression
*left
= *lp
, *right
= *rp
;
439 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
440 struct symbol
*type
= NULL
;
442 if (ltype
->type
== SYM_NODE
)
443 ltype
= ltype
->ctype
.base_type
;
444 if (ltype
->type
== SYM_ENUM
)
445 ltype
= ltype
->ctype
.base_type
;
446 if (rtype
->type
== SYM_NODE
)
447 rtype
= rtype
->ctype
.base_type
;
448 if (rtype
->type
== SYM_ENUM
)
449 rtype
= rtype
->ctype
.base_type
;
450 if (is_restricted_type(ltype
)) {
451 if (is_restricted_type(rtype
)) {
455 if (!restricted_value(right
, ltype
))
458 } else if (is_restricted_type(rtype
)) {
459 if (!restricted_value(left
, rtype
))
464 if (restricted_binop(op
, type
))
469 static struct symbol
*evaluate_arith(struct expression
*expr
, int float_ok
)
471 struct symbol
*ctype
= compatible_integer_binop(&expr
->left
, &expr
->right
);
472 if (!ctype
&& float_ok
)
473 ctype
= compatible_float_binop(&expr
->left
, &expr
->right
);
475 ctype
= compatible_restricted_binop(expr
->op
, &expr
->left
, &expr
->right
);
480 return bad_expr_type(expr
);
483 static inline int lvalue_expression(struct expression
*expr
)
485 return expr
->type
== EXPR_PREOP
&& expr
->op
== '*';
488 static int ptr_object_size(struct symbol
*ptr_type
)
490 if (ptr_type
->type
== SYM_NODE
)
491 ptr_type
= ptr_type
->ctype
.base_type
;
492 if (ptr_type
->type
== SYM_PTR
)
493 ptr_type
= get_base_type(ptr_type
);
494 return ptr_type
->bit_size
;
497 static struct symbol
*evaluate_ptr_add(struct expression
*expr
, struct symbol
*ctype
, struct expression
**ip
)
499 struct expression
*i
= *ip
;
500 struct symbol
*ptr_type
= ctype
;
503 if (ptr_type
->type
== SYM_NODE
)
504 ptr_type
= ptr_type
->ctype
.base_type
;
506 if (!is_int_type(i
->ctype
))
507 return bad_expr_type(expr
);
509 examine_symbol_type(ctype
);
511 if (!ctype
->ctype
.base_type
) {
512 sparse_error(expr
->pos
, "missing type information");
516 /* Get the size of whatever the pointer points to */
517 bit_size
= ptr_object_size(ctype
);
519 if (bit_size
> bits_in_char
) {
520 int multiply
= bit_size
>> 3;
521 struct expression
*val
= alloc_expression(expr
->pos
, EXPR_VALUE
);
523 if (i
->type
== EXPR_VALUE
) {
524 val
->value
= i
->value
* multiply
;
525 val
->ctype
= size_t_ctype
;
528 struct expression
*mul
= alloc_expression(expr
->pos
, EXPR_BINOP
);
530 val
->ctype
= size_t_ctype
;
531 val
->value
= bit_size
>> 3;
534 mul
->ctype
= size_t_ctype
;
546 static struct symbol
*evaluate_add(struct expression
*expr
)
548 struct expression
*left
= expr
->left
, *right
= expr
->right
;
549 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
551 if (is_ptr_type(ltype
))
552 return evaluate_ptr_add(expr
, degenerate(left
), &expr
->right
);
554 if (is_ptr_type(rtype
))
555 return evaluate_ptr_add(expr
, degenerate(right
), &expr
->left
);
557 return evaluate_arith(expr
, 1);
560 const char * type_difference(struct symbol
*target
, struct symbol
*source
,
561 unsigned long target_mod_ignore
, unsigned long source_mod_ignore
)
564 unsigned long mod1
, mod2
, diff
;
565 unsigned long as1
, as2
;
567 struct symbol
*base1
, *base2
;
569 if (target
== source
)
571 if (!target
|| !source
)
572 return "different types";
574 * Peel of per-node information.
575 * FIXME! Check alignment and context too here!
577 mod1
= target
->ctype
.modifiers
;
578 as1
= target
->ctype
.as
;
579 mod2
= source
->ctype
.modifiers
;
580 as2
= source
->ctype
.as
;
581 if (target
->type
== SYM_NODE
) {
582 target
= target
->ctype
.base_type
;
585 if (target
->type
== SYM_PTR
) {
589 mod1
|= target
->ctype
.modifiers
;
590 as1
|= target
->ctype
.as
;
592 if (source
->type
== SYM_NODE
) {
593 source
= source
->ctype
.base_type
;
596 if (source
->type
== SYM_PTR
) {
600 mod2
|= source
->ctype
.modifiers
;
601 as2
|= source
->ctype
.as
;
603 if (target
->type
== SYM_ENUM
) {
604 target
= target
->ctype
.base_type
;
608 if (source
->type
== SYM_ENUM
) {
609 source
= source
->ctype
.base_type
;
614 if (target
== source
)
616 if (!target
|| !source
)
617 return "different types";
619 type1
= target
->type
;
620 base1
= target
->ctype
.base_type
;
622 type2
= source
->type
;
623 base2
= source
->ctype
.base_type
;
626 * Pointers to functions compare as the function itself
628 if (type1
== SYM_PTR
&& base1
) {
629 base1
= examine_symbol_type(base1
);
630 switch (base1
->type
) {
634 base1
= base1
->ctype
.base_type
;
639 if (type2
== SYM_PTR
&& base2
) {
640 base2
= examine_symbol_type(base2
);
641 switch (base2
->type
) {
645 base2
= base2
->ctype
.base_type
;
651 /* Arrays degenerate to pointers for type comparisons */
652 type1
= (type1
== SYM_ARRAY
) ? SYM_PTR
: type1
;
653 type2
= (type2
== SYM_ARRAY
) ? SYM_PTR
: type2
;
655 if (type1
!= type2
|| type1
== SYM_RESTRICT
)
656 return "different base types";
658 /* Must be same address space to be comparable */
660 return "different address spaces";
662 /* Ignore differences in storage types or addressability */
663 diff
= (mod1
^ mod2
) & ~MOD_IGNORE
;
664 diff
&= (mod1
& ~target_mod_ignore
) | (mod2
& ~source_mod_ignore
);
667 return "different type sizes";
668 if (diff
& ~MOD_SIGNEDNESS
)
669 return "different modifiers";
671 /* Differs in signedness only.. */
674 * Warn if both are explicitly signed ("unsigned" is obvously
675 * always explicit, and since we know one of them has to be
676 * unsigned, we check if the signed one was explicit).
678 if ((mod1
| mod2
) & MOD_EXPLICITLY_SIGNED
)
679 return "different explicit signedness";
682 * "char" matches both "unsigned char" and "signed char",
683 * so if the explicit test didn't trigger, then we should
684 * not warn about a char.
686 if (!(mod1
& MOD_CHAR
))
687 return "different signedness";
691 if (type1
== SYM_FN
) {
693 struct symbol
*arg1
, *arg2
;
694 if (base1
->variadic
!= base2
->variadic
)
695 return "incompatible variadic arguments";
696 PREPARE_PTR_LIST(target
->arguments
, arg1
);
697 PREPARE_PTR_LIST(source
->arguments
, arg2
);
701 diff
= type_difference(arg1
, arg2
, 0, 0);
703 static char argdiff
[80];
704 sprintf(argdiff
, "incompatible argument %d (%s)", i
, diff
);
713 FINISH_PTR_LIST(arg2
);
714 FINISH_PTR_LIST(arg1
);
723 static int is_null_ptr(struct expression
*expr
)
725 if (expr
->type
!= EXPR_VALUE
|| expr
->value
)
727 if (!is_ptr_type(expr
->ctype
))
728 warning(expr
->pos
, "Using plain integer as NULL pointer");
732 static struct symbol
*common_ptr_type(struct expression
*l
, struct expression
*r
)
734 /* NULL expression? Just return the type of the "other side" */
743 * Ignore differences in "volatile" and "const"ness when
744 * subtracting pointers
746 #define MOD_IGN (MOD_VOLATILE | MOD_CONST)
748 static struct symbol
*evaluate_ptr_sub(struct expression
*expr
, struct expression
*l
, struct expression
**rp
)
750 const char *typediff
;
751 struct symbol
*ctype
;
752 struct symbol
*ltype
, *rtype
;
753 struct expression
*r
= *rp
;
755 ltype
= degenerate(l
);
756 rtype
= degenerate(r
);
759 * If it is an integer subtract: the ptr add case will do the
762 if (!is_ptr_type(rtype
))
763 return evaluate_ptr_add(expr
, degenerate(l
), rp
);
766 typediff
= type_difference(ltype
, rtype
, ~MOD_SIZE
, ~MOD_SIZE
);
768 ctype
= common_ptr_type(l
, r
);
770 sparse_error(expr
->pos
, "subtraction of different types can't work (%s)", typediff
);
774 examine_symbol_type(ctype
);
776 /* Figure out the base type we point to */
777 if (ctype
->type
== SYM_NODE
)
778 ctype
= ctype
->ctype
.base_type
;
779 if (ctype
->type
!= SYM_PTR
&& ctype
->type
!= SYM_ARRAY
) {
780 sparse_error(expr
->pos
, "subtraction of functions? Share your drugs");
783 ctype
= get_base_type(ctype
);
785 expr
->ctype
= ssize_t_ctype
;
786 if (ctype
->bit_size
> bits_in_char
) {
787 struct expression
*sub
= alloc_expression(expr
->pos
, EXPR_BINOP
);
788 struct expression
*div
= expr
;
789 struct expression
*val
= alloc_expression(expr
->pos
, EXPR_VALUE
);
790 unsigned long value
= ctype
->bit_size
>> 3;
792 val
->ctype
= size_t_ctype
;
795 if (value
& (value
-1)) {
796 if (Wptr_subtraction_blows
)
797 warning(expr
->pos
, "potentially expensive pointer subtraction");
801 sub
->ctype
= ssize_t_ctype
;
810 return ssize_t_ctype
;
813 static struct symbol
*evaluate_sub(struct expression
*expr
)
815 struct expression
*left
= expr
->left
;
816 struct symbol
*ltype
= left
->ctype
;
818 if (is_ptr_type(ltype
))
819 return evaluate_ptr_sub(expr
, left
, &expr
->right
);
821 return evaluate_arith(expr
, 1);
824 #define is_safe_type(type) ((type)->ctype.modifiers & MOD_SAFE)
826 static struct symbol
*evaluate_conditional(struct expression
*expr
, int iterator
)
828 struct symbol
*ctype
;
833 if (!iterator
&& expr
->type
== EXPR_ASSIGNMENT
&& expr
->op
== '=')
834 warning(expr
->pos
, "assignment expression in conditional");
836 ctype
= evaluate_expression(expr
);
838 if (is_safe_type(ctype
))
839 warning(expr
->pos
, "testing a 'safe expression'");
845 static struct symbol
*evaluate_logical(struct expression
*expr
)
847 if (!evaluate_conditional(expr
->left
, 0))
849 if (!evaluate_conditional(expr
->right
, 0))
852 expr
->ctype
= &bool_ctype
;
856 static struct symbol
*evaluate_shift(struct expression
*expr
)
858 struct expression
*left
= expr
->left
, *right
= expr
->right
;
859 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
861 if (ltype
->type
== SYM_NODE
)
862 ltype
= ltype
->ctype
.base_type
;
863 if (rtype
->type
== SYM_NODE
)
864 rtype
= rtype
->ctype
.base_type
;
865 if (is_int_type(ltype
) && is_int_type(rtype
)) {
866 struct symbol
*ctype
= integer_promotion(ltype
);
867 expr
->left
= cast_to(expr
->left
, ctype
);
869 ctype
= integer_promotion(rtype
);
870 expr
->right
= cast_to(expr
->right
, ctype
);
873 return bad_expr_type(expr
);
876 static struct symbol
*evaluate_binop(struct expression
*expr
)
879 // addition can take ptr+int, fp and int
881 return evaluate_add(expr
);
883 // subtraction can take ptr-ptr, fp and int
885 return evaluate_sub(expr
);
887 // Arithmetic operations can take fp and int
889 return evaluate_arith(expr
, 1);
891 // shifts do integer promotions, but that's it.
892 case SPECIAL_LEFTSHIFT
: case SPECIAL_RIGHTSHIFT
:
893 return evaluate_shift(expr
);
895 // The rest are integer operations
896 // '%', '&', '^', '|'
898 return evaluate_arith(expr
, 0);
902 static struct symbol
*evaluate_comma(struct expression
*expr
)
904 expr
->ctype
= expr
->right
->ctype
;
908 static int modify_for_unsigned(int op
)
911 op
= SPECIAL_UNSIGNED_LT
;
913 op
= SPECIAL_UNSIGNED_GT
;
914 else if (op
== SPECIAL_LTE
)
915 op
= SPECIAL_UNSIGNED_LTE
;
916 else if (op
== SPECIAL_GTE
)
917 op
= SPECIAL_UNSIGNED_GTE
;
921 static struct symbol
*evaluate_compare(struct expression
*expr
)
923 struct expression
*left
= expr
->left
, *right
= expr
->right
;
924 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
925 struct symbol
*ctype
;
928 if (is_type_type(ltype
) && is_type_type(rtype
))
931 if (is_safe_type(ltype
) || is_safe_type(rtype
))
932 warning(expr
->pos
, "testing a 'safe expression'");
935 if (is_ptr_type(ltype
) || is_ptr_type(rtype
)) {
936 // FIXME! Check the types for compatibility
937 expr
->op
= modify_for_unsigned(expr
->op
);
941 ctype
= compatible_integer_binop(&expr
->left
, &expr
->right
);
943 if (ctype
->ctype
.modifiers
& MOD_UNSIGNED
)
944 expr
->op
= modify_for_unsigned(expr
->op
);
948 ctype
= compatible_float_binop(&expr
->left
, &expr
->right
);
952 ctype
= compatible_restricted_binop(expr
->op
, &expr
->left
, &expr
->right
);
954 if (ctype
->ctype
.modifiers
& MOD_UNSIGNED
)
955 expr
->op
= modify_for_unsigned(expr
->op
);
962 expr
->ctype
= &bool_ctype
;
967 * FIXME!! This should do casts, array degeneration etc..
969 static struct symbol
*compatible_ptr_type(struct expression
*left
, struct expression
*right
)
971 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
973 if (ltype
->type
== SYM_NODE
)
974 ltype
= ltype
->ctype
.base_type
;
976 if (rtype
->type
== SYM_NODE
)
977 rtype
= rtype
->ctype
.base_type
;
979 if (ltype
->type
== SYM_PTR
) {
980 if (is_null_ptr(right
) || rtype
->ctype
.base_type
== &void_ctype
)
984 if (rtype
->type
== SYM_PTR
) {
985 if (is_null_ptr(left
) || ltype
->ctype
.base_type
== &void_ctype
)
992 * NOTE! The degenerate case of "x ? : y", where we don't
993 * have a true case, this will possibly promote "x" to the
994 * same type as "y", and thus _change_ the conditional
995 * test in the expression. But since promotion is "safe"
996 * for testing, that's ok.
998 static struct symbol
*evaluate_conditional_expression(struct expression
*expr
)
1000 struct expression
**true;
1001 struct symbol
*ctype
, *ltype
, *rtype
;
1002 const char * typediff
;
1004 if (!evaluate_conditional(expr
->conditional
, 0))
1006 if (!evaluate_expression(expr
->cond_false
))
1009 ctype
= degenerate(expr
->conditional
);
1010 rtype
= degenerate(expr
->cond_false
);
1012 true = &expr
->conditional
;
1014 if (expr
->cond_true
) {
1015 if (!evaluate_expression(expr
->cond_true
))
1017 ltype
= degenerate(expr
->cond_true
);
1018 true = &expr
->cond_true
;
1021 ctype
= compatible_integer_binop(true, &expr
->cond_false
);
1024 ctype
= compatible_ptr_type(*true, expr
->cond_false
);
1027 ctype
= compatible_float_binop(true, &expr
->cond_false
);
1030 ctype
= compatible_restricted_binop('?', true, &expr
->cond_false
);
1034 typediff
= type_difference(ltype
, rtype
, MOD_IGN
, MOD_IGN
);
1037 sparse_error(expr
->pos
, "incompatible types in conditional expression (%s)", typediff
);
1041 expr
->ctype
= ctype
;
1045 /* FP assignments can not do modulo or bit operations */
1046 static int compatible_float_op(int op
)
1049 op
== SPECIAL_ADD_ASSIGN
||
1050 op
== SPECIAL_SUB_ASSIGN
||
1051 op
== SPECIAL_MUL_ASSIGN
||
1052 op
== SPECIAL_DIV_ASSIGN
;
1055 static int compatible_assignment_types(struct expression
*expr
, struct symbol
*target
,
1056 struct expression
**rp
, struct symbol
*source
, const char *where
, int op
)
1058 const char *typediff
;
1062 if (is_int_type(target
)) {
1063 if (is_int_type(source
))
1065 if (is_float_type(source
))
1067 } else if (is_float_type(target
)) {
1068 if (!compatible_float_op(op
)) {
1069 sparse_error(expr
->pos
, "invalid assignment");
1072 if (is_int_type(source
))
1074 if (is_float_type(source
))
1076 } else if (is_restricted_type(target
)) {
1077 if (restricted_binop(op
, target
)) {
1078 sparse_error(expr
->pos
, "bad restricted assignment");
1081 if (!restricted_value(*rp
, target
))
1083 } else if (is_ptr_type(target
)) {
1084 if (op
== SPECIAL_ADD_ASSIGN
|| op
== SPECIAL_SUB_ASSIGN
) {
1085 evaluate_ptr_add(expr
, target
, rp
);
1089 sparse_error(expr
->pos
, "invalid pointer assignment");
1092 } else if (op
!= '=') {
1093 sparse_error(expr
->pos
, "invalid assignment");
1097 /* It's ok if the target is more volatile or const than the source */
1098 typediff
= type_difference(target
, source
, MOD_VOLATILE
| MOD_CONST
, 0);
1102 /* Pointer destination? */
1104 target_as
= t
->ctype
.as
;
1105 if (t
->type
== SYM_NODE
) {
1106 t
= t
->ctype
.base_type
;
1107 target_as
|= t
->ctype
.as
;
1109 if (t
->type
== SYM_PTR
|| t
->type
== SYM_FN
|| t
->type
== SYM_ARRAY
) {
1110 struct expression
*right
= *rp
;
1111 struct symbol
*s
= source
;
1114 // NULL pointer is always ok
1115 if (is_null_ptr(right
))
1118 /* "void *" matches anything as long as the address space is ok */
1119 source_as
= s
->ctype
.as
;
1120 if (s
->type
== SYM_NODE
) {
1121 s
= s
->ctype
.base_type
;
1122 source_as
|= s
->ctype
.as
;
1124 if (source_as
== target_as
&& (s
->type
== SYM_PTR
|| s
->type
== SYM_ARRAY
)) {
1125 s
= get_base_type(s
);
1126 t
= get_base_type(t
);
1127 if (s
== &void_ctype
|| t
== &void_ctype
)
1132 warning(expr
->pos
, "incorrect type in %s (%s)", where
, typediff
);
1133 info(expr
->pos
, " expected %s", show_typename(target
));
1134 info(expr
->pos
, " got %s", show_typename(source
));
1135 *rp
= cast_to(*rp
, target
);
1138 *rp
= cast_to(*rp
, target
);
1142 static void mark_assigned(struct expression
*expr
)
1148 switch (expr
->type
) {
1153 if (sym
->type
!= SYM_NODE
)
1155 sym
->ctype
.modifiers
|= MOD_ASSIGNED
;
1159 mark_assigned(expr
->left
);
1160 mark_assigned(expr
->right
);
1163 mark_assigned(expr
->cast_expression
);
1166 mark_assigned(expr
->base
);
1174 static void evaluate_assign_to(struct expression
*left
, struct symbol
*type
)
1176 if (type
->ctype
.modifiers
& MOD_CONST
)
1177 sparse_error(left
->pos
, "assignment to const expression");
1179 /* We know left is an lvalue, so it's a "preop-*" */
1180 mark_assigned(left
->unop
);
1183 static struct symbol
*evaluate_assignment(struct expression
*expr
)
1185 struct expression
*left
= expr
->left
, *right
= expr
->right
;
1186 struct expression
*where
= expr
;
1187 struct symbol
*ltype
, *rtype
;
1189 if (!lvalue_expression(left
)) {
1190 sparse_error(expr
->pos
, "not an lvalue");
1194 ltype
= left
->ctype
;
1196 rtype
= degenerate(right
);
1198 if (!compatible_assignment_types(where
, ltype
, &where
->right
, rtype
, "assignment", expr
->op
))
1201 evaluate_assign_to(left
, ltype
);
1203 expr
->ctype
= ltype
;
1207 static void examine_fn_arguments(struct symbol
*fn
)
1211 FOR_EACH_PTR(fn
->arguments
, s
) {
1212 struct symbol
*arg
= evaluate_symbol(s
);
1213 /* Array/function arguments silently degenerate into pointers */
1219 ptr
= alloc_symbol(s
->pos
, SYM_PTR
);
1220 if (arg
->type
== SYM_ARRAY
)
1221 ptr
->ctype
= arg
->ctype
;
1223 ptr
->ctype
.base_type
= arg
;
1224 ptr
->ctype
.as
|= s
->ctype
.as
;
1225 ptr
->ctype
.modifiers
|= s
->ctype
.modifiers
;
1227 s
->ctype
.base_type
= ptr
;
1229 s
->ctype
.modifiers
= 0;
1232 examine_symbol_type(s
);
1239 } END_FOR_EACH_PTR(s
);
1242 static struct symbol
*convert_to_as_mod(struct symbol
*sym
, int as
, int mod
)
1244 /* Take the modifiers of the pointer, and apply them to the member */
1245 mod
|= sym
->ctype
.modifiers
;
1246 if (sym
->ctype
.as
!= as
|| sym
->ctype
.modifiers
!= mod
) {
1247 struct symbol
*newsym
= alloc_symbol(sym
->pos
, SYM_NODE
);
1249 newsym
->ctype
.as
= as
;
1250 newsym
->ctype
.modifiers
= mod
;
1256 #define MOD_PTRINHERIT (MOD_VOLATILE | MOD_CONST | MOD_NODEREF | MOD_STORAGE)
1258 static struct symbol
*create_pointer(struct expression
*expr
, struct symbol
*sym
, int degenerate
)
1260 struct symbol
*node
= alloc_symbol(expr
->pos
, SYM_NODE
);
1261 struct symbol
*ptr
= alloc_symbol(expr
->pos
, SYM_PTR
);
1263 node
->ctype
.base_type
= ptr
;
1264 ptr
->bit_size
= bits_in_pointer
;
1265 ptr
->ctype
.alignment
= pointer_alignment
;
1267 node
->bit_size
= bits_in_pointer
;
1268 node
->ctype
.alignment
= pointer_alignment
;
1271 if (sym
->ctype
.modifiers
& MOD_REGISTER
) {
1272 warning(expr
->pos
, "taking address of 'register' variable '%s'", show_ident(sym
->ident
));
1273 sym
->ctype
.modifiers
&= ~MOD_REGISTER
;
1275 if (sym
->type
== SYM_NODE
) {
1276 ptr
->ctype
.as
|= sym
->ctype
.as
;
1277 ptr
->ctype
.modifiers
|= sym
->ctype
.modifiers
& MOD_PTRINHERIT
;
1278 sym
= sym
->ctype
.base_type
;
1280 if (degenerate
&& sym
->type
== SYM_ARRAY
) {
1281 ptr
->ctype
.as
|= sym
->ctype
.as
;
1282 ptr
->ctype
.modifiers
|= sym
->ctype
.modifiers
& MOD_PTRINHERIT
;
1283 sym
= sym
->ctype
.base_type
;
1285 ptr
->ctype
.base_type
= sym
;
1290 /* Arrays degenerate into pointers on pointer arithmetic */
1291 static struct symbol
*degenerate(struct expression
*expr
)
1293 struct symbol
*ctype
, *base
;
1297 ctype
= expr
->ctype
;
1300 base
= examine_symbol_type(ctype
);
1301 if (ctype
->type
== SYM_NODE
)
1302 base
= ctype
->ctype
.base_type
;
1304 * Arrays degenerate into pointers to the entries, while
1305 * functions degenerate into pointers to themselves.
1306 * If array was part of non-lvalue compound, we create a copy
1307 * of that compound first and then act as if we were dealing with
1308 * the corresponding field in there.
1310 switch (base
->type
) {
1312 if (expr
->type
== EXPR_SLICE
) {
1313 struct symbol
*a
= alloc_symbol(expr
->pos
, SYM_NODE
);
1314 struct expression
*e0
, *e1
, *e2
, *e3
, *e4
;
1316 a
->ctype
.base_type
= expr
->base
->ctype
;
1317 a
->bit_size
= expr
->base
->ctype
->bit_size
;
1318 a
->array_size
= expr
->base
->ctype
->array_size
;
1320 e0
= alloc_expression(expr
->pos
, EXPR_SYMBOL
);
1322 e0
->ctype
= &lazy_ptr_ctype
;
1324 e1
= alloc_expression(expr
->pos
, EXPR_PREOP
);
1327 e1
->ctype
= expr
->base
->ctype
; /* XXX */
1329 e2
= alloc_expression(expr
->pos
, EXPR_ASSIGNMENT
);
1331 e2
->right
= expr
->base
;
1333 e2
->ctype
= expr
->base
->ctype
;
1335 if (expr
->r_bitpos
) {
1336 e3
= alloc_expression(expr
->pos
, EXPR_BINOP
);
1339 e3
->right
= alloc_const_expression(expr
->pos
,
1340 expr
->r_bitpos
>> 3);
1341 e3
->ctype
= &lazy_ptr_ctype
;
1346 e4
= alloc_expression(expr
->pos
, EXPR_COMMA
);
1349 e4
->ctype
= &lazy_ptr_ctype
;
1352 expr
->type
= EXPR_PREOP
;
1356 if (expr
->op
!= '*' || expr
->type
!= EXPR_PREOP
) {
1357 sparse_error(expr
->pos
, "strange non-value function or array");
1360 *expr
= *expr
->unop
;
1361 ctype
= create_pointer(expr
, ctype
, 1);
1362 expr
->ctype
= ctype
;
1369 static struct symbol
*evaluate_addressof(struct expression
*expr
)
1371 struct expression
*op
= expr
->unop
;
1372 struct symbol
*ctype
;
1374 if (op
->op
!= '*' || op
->type
!= EXPR_PREOP
) {
1375 sparse_error(expr
->pos
, "not addressable");
1381 if (expr
->type
== EXPR_SYMBOL
) {
1382 struct symbol
*sym
= expr
->symbol
;
1383 sym
->ctype
.modifiers
|= MOD_ADDRESSABLE
;
1387 * symbol expression evaluation is lazy about the type
1388 * of the sub-expression, so we may have to generate
1389 * the type here if so..
1391 if (expr
->ctype
== &lazy_ptr_ctype
) {
1392 ctype
= create_pointer(expr
, ctype
, 0);
1393 expr
->ctype
= ctype
;
1399 static struct symbol
*evaluate_dereference(struct expression
*expr
)
1401 struct expression
*op
= expr
->unop
;
1402 struct symbol
*ctype
= op
->ctype
, *node
, *target
;
1404 /* Simplify: *&(expr) => (expr) */
1405 if (op
->type
== EXPR_PREOP
&& op
->op
== '&') {
1410 /* Dereferencing a node drops all the node information. */
1411 if (ctype
->type
== SYM_NODE
)
1412 ctype
= ctype
->ctype
.base_type
;
1414 node
= alloc_symbol(expr
->pos
, SYM_NODE
);
1415 target
= ctype
->ctype
.base_type
;
1417 switch (ctype
->type
) {
1419 sparse_error(expr
->pos
, "cannot derefence this type");
1422 node
->ctype
.modifiers
= target
->ctype
.modifiers
& MOD_SPECIFIER
;
1423 merge_type(node
, ctype
);
1427 if (!lvalue_expression(op
)) {
1428 sparse_error(op
->pos
, "non-lvalue array??");
1432 /* Do the implied "addressof" on the array */
1436 * When an array is dereferenced, we need to pick
1437 * up the attributes of the original node too..
1439 merge_type(node
, op
->ctype
);
1440 merge_type(node
, ctype
);
1444 node
->bit_size
= target
->bit_size
;
1445 node
->array_size
= target
->array_size
;
1452 * Unary post-ops: x++ and x--
1454 static struct symbol
*evaluate_postop(struct expression
*expr
)
1456 struct expression
*op
= expr
->unop
;
1457 struct symbol
*ctype
= op
->ctype
;
1459 if (!lvalue_expression(expr
->unop
)) {
1460 sparse_error(expr
->pos
, "need lvalue expression for ++/--");
1463 if (is_restricted_type(ctype
) && restricted_unop(expr
->op
, ctype
)) {
1464 sparse_error(expr
->pos
, "bad operation on restricted");
1468 evaluate_assign_to(op
, ctype
);
1470 expr
->ctype
= ctype
;
1472 if (is_ptr_type(ctype
))
1473 expr
->op_value
= ptr_object_size(ctype
) >> 3;
1478 static struct symbol
*evaluate_sign(struct expression
*expr
)
1480 struct symbol
*ctype
= expr
->unop
->ctype
;
1481 if (is_int_type(ctype
)) {
1482 struct symbol
*rtype
= rtype
= integer_promotion(ctype
);
1483 expr
->unop
= cast_to(expr
->unop
, rtype
);
1485 } else if (is_float_type(ctype
) && expr
->op
!= '~') {
1486 /* no conversions needed */
1487 } else if (is_restricted_type(ctype
) && !restricted_unop(expr
->op
, ctype
)) {
1488 /* no conversions needed */
1490 return bad_expr_type(expr
);
1492 if (expr
->op
== '+')
1493 *expr
= *expr
->unop
;
1494 expr
->ctype
= ctype
;
1498 static struct symbol
*evaluate_preop(struct expression
*expr
)
1500 struct symbol
*ctype
= expr
->unop
->ctype
;
1504 *expr
= *expr
->unop
;
1510 return evaluate_sign(expr
);
1513 return evaluate_dereference(expr
);
1516 return evaluate_addressof(expr
);
1518 case SPECIAL_INCREMENT
:
1519 case SPECIAL_DECREMENT
:
1521 * From a type evaluation standpoint the pre-ops are
1522 * the same as the postops
1524 return evaluate_postop(expr
);
1527 if (is_safe_type(ctype
))
1528 warning(expr
->pos
, "testing a 'safe expression'");
1529 if (is_float_type(ctype
)) {
1530 struct expression
*arg
= expr
->unop
;
1531 expr
->type
= EXPR_BINOP
;
1532 expr
->op
= SPECIAL_EQUAL
;
1534 expr
->right
= alloc_expression(expr
->pos
, EXPR_FVALUE
);
1535 expr
->right
->ctype
= ctype
;
1536 expr
->right
->fvalue
= 0;
1538 ctype
= &bool_ctype
;
1544 expr
->ctype
= ctype
;
1548 static struct symbol
*find_identifier(struct ident
*ident
, struct symbol_list
*_list
, int *offset
)
1550 struct ptr_list
*head
= (struct ptr_list
*)_list
;
1551 struct ptr_list
*list
= head
;
1557 for (i
= 0; i
< list
->nr
; i
++) {
1558 struct symbol
*sym
= (struct symbol
*) list
->list
[i
];
1560 if (sym
->ident
!= ident
)
1562 *offset
= sym
->offset
;
1565 struct symbol
*ctype
= sym
->ctype
.base_type
;
1569 if (ctype
->type
!= SYM_UNION
&& ctype
->type
!= SYM_STRUCT
)
1571 sub
= find_identifier(ident
, ctype
->symbol_list
, offset
);
1574 *offset
+= sym
->offset
;
1578 } while ((list
= list
->next
) != head
);
1582 static struct expression
*evaluate_offset(struct expression
*expr
, unsigned long offset
)
1584 struct expression
*add
;
1587 * Create a new add-expression
1589 * NOTE! Even if we just add zero, we need a new node
1590 * for the member pointer, since it has a different
1591 * type than the original pointer. We could make that
1592 * be just a cast, but the fact is, a node is a node,
1593 * so we might as well just do the "add zero" here.
1595 add
= alloc_expression(expr
->pos
, EXPR_BINOP
);
1598 add
->right
= alloc_expression(expr
->pos
, EXPR_VALUE
);
1599 add
->right
->ctype
= &int_ctype
;
1600 add
->right
->value
= offset
;
1603 * The ctype of the pointer will be lazily evaluated if
1604 * we ever take the address of this member dereference..
1606 add
->ctype
= &lazy_ptr_ctype
;
1610 /* structure/union dereference */
1611 static struct symbol
*evaluate_member_dereference(struct expression
*expr
)
1614 struct symbol
*ctype
, *member
;
1615 struct expression
*deref
= expr
->deref
, *add
;
1616 struct ident
*ident
= expr
->member
;
1620 if (!evaluate_expression(deref
))
1623 sparse_error(expr
->pos
, "bad member name");
1627 ctype
= deref
->ctype
;
1628 address_space
= ctype
->ctype
.as
;
1629 mod
= ctype
->ctype
.modifiers
;
1630 if (ctype
->type
== SYM_NODE
) {
1631 ctype
= ctype
->ctype
.base_type
;
1632 address_space
|= ctype
->ctype
.as
;
1633 mod
|= ctype
->ctype
.modifiers
;
1635 if (!ctype
|| (ctype
->type
!= SYM_STRUCT
&& ctype
->type
!= SYM_UNION
)) {
1636 sparse_error(expr
->pos
, "expected structure or union");
1639 examine_symbol_type(ctype
);
1641 member
= find_identifier(ident
, ctype
->symbol_list
, &offset
);
1643 const char *type
= ctype
->type
== SYM_STRUCT
? "struct" : "union";
1644 const char *name
= "<unnamed>";
1647 name
= ctype
->ident
->name
;
1648 namelen
= ctype
->ident
->len
;
1650 sparse_error(expr
->pos
, "no member '%s' in %s %.*s",
1651 show_ident(ident
), type
, namelen
, name
);
1656 * The member needs to take on the address space and modifiers of
1657 * the "parent" type.
1659 member
= convert_to_as_mod(member
, address_space
, mod
);
1660 ctype
= get_base_type(member
);
1662 if (!lvalue_expression(deref
)) {
1663 if (deref
->type
!= EXPR_SLICE
) {
1667 expr
->base
= deref
->base
;
1668 expr
->r_bitpos
= deref
->r_bitpos
;
1670 expr
->r_bitpos
+= offset
<< 3;
1671 expr
->type
= EXPR_SLICE
;
1672 expr
->r_nrbits
= member
->bit_size
;
1673 expr
->r_bitpos
+= member
->bit_offset
;
1674 expr
->ctype
= member
;
1678 deref
= deref
->unop
;
1679 expr
->deref
= deref
;
1681 add
= evaluate_offset(deref
, offset
);
1682 expr
->type
= EXPR_PREOP
;
1686 expr
->ctype
= member
;
1690 static int is_promoted(struct expression
*expr
)
1693 switch (expr
->type
) {
1696 case EXPR_CONDITIONAL
:
1720 static struct symbol
*evaluate_cast(struct expression
*);
1722 static struct symbol
*evaluate_type_information(struct expression
*expr
)
1724 struct symbol
*sym
= expr
->cast_type
;
1726 sym
= evaluate_expression(expr
->cast_expression
);
1730 * Expressions of restricted types will possibly get
1731 * promoted - check that here
1733 if (is_restricted_type(sym
)) {
1734 if (sym
->bit_size
< bits_in_int
&& is_promoted(expr
))
1738 examine_symbol_type(sym
);
1739 if (is_bitfield_type(sym
)) {
1740 sparse_error(expr
->pos
, "trying to examine bitfield type");
1746 static struct symbol
*evaluate_sizeof(struct expression
*expr
)
1748 struct symbol
*type
;
1751 type
= evaluate_type_information(expr
);
1755 size
= type
->bit_size
;
1756 if ((size
< 0) || (size
& 7))
1757 sparse_error(expr
->pos
, "cannot size expression");
1758 expr
->type
= EXPR_VALUE
;
1759 expr
->value
= size
>> 3;
1760 expr
->ctype
= size_t_ctype
;
1761 return size_t_ctype
;
1764 static struct symbol
*evaluate_ptrsizeof(struct expression
*expr
)
1766 struct symbol
*type
;
1769 type
= evaluate_type_information(expr
);
1773 if (type
->type
== SYM_NODE
)
1774 type
= type
->ctype
.base_type
;
1777 switch (type
->type
) {
1781 type
= get_base_type(type
);
1785 sparse_error(expr
->pos
, "expected pointer expression");
1788 size
= type
->bit_size
;
1791 expr
->type
= EXPR_VALUE
;
1792 expr
->value
= size
>> 3;
1793 expr
->ctype
= size_t_ctype
;
1794 return size_t_ctype
;
1797 static struct symbol
*evaluate_alignof(struct expression
*expr
)
1799 struct symbol
*type
;
1801 type
= evaluate_type_information(expr
);
1805 expr
->type
= EXPR_VALUE
;
1806 expr
->value
= type
->ctype
.alignment
;
1807 expr
->ctype
= size_t_ctype
;
1808 return size_t_ctype
;
1811 static int evaluate_arguments(struct symbol
*f
, struct symbol
*fn
, struct expression_list
*head
)
1813 struct expression
*expr
;
1814 struct symbol_list
*argument_types
= fn
->arguments
;
1815 struct symbol
*argtype
;
1818 PREPARE_PTR_LIST(argument_types
, argtype
);
1819 FOR_EACH_PTR (head
, expr
) {
1820 struct expression
**p
= THIS_ADDRESS(expr
);
1821 struct symbol
*ctype
, *target
;
1822 ctype
= evaluate_expression(expr
);
1827 ctype
= degenerate(expr
);
1830 if (!target
&& ctype
->bit_size
< bits_in_int
)
1831 target
= &int_ctype
;
1833 static char where
[30];
1834 examine_symbol_type(target
);
1835 sprintf(where
, "argument %d", i
);
1836 compatible_assignment_types(expr
, target
, p
, ctype
, where
, '=');
1840 NEXT_PTR_LIST(argtype
);
1841 } END_FOR_EACH_PTR(expr
);
1842 FINISH_PTR_LIST(argtype
);
1846 static void evaluate_initializer(struct symbol
*ctype
, struct expression
**ep
);
1848 static int evaluate_one_array_initializer(struct symbol
*ctype
, struct expression
**ep
, int current
)
1850 struct expression
*entry
= *ep
;
1851 struct expression
**parent
, *reuse
= NULL
;
1852 unsigned long offset
;
1854 unsigned long from
, to
;
1855 int accept_string
= is_byte_type(ctype
);
1860 if (entry
->type
== EXPR_INDEX
) {
1861 from
= entry
->idx_from
;
1862 to
= entry
->idx_to
+1;
1863 parent
= &entry
->idx_expression
;
1865 entry
= entry
->idx_expression
;
1868 offset
= from
* (ctype
->bit_size
>>3);
1870 if (!reuse
) reuse
= alloc_expression(entry
->pos
, EXPR_POS
);
1871 reuse
->type
= EXPR_POS
;
1872 reuse
->ctype
= ctype
;
1873 reuse
->init_offset
= offset
;
1874 reuse
->init_nr
= to
- from
;
1875 reuse
->init_expr
= entry
;
1876 parent
= &reuse
->init_expr
;
1881 if (accept_string
&& entry
->type
== EXPR_STRING
) {
1882 sym
= evaluate_expression(entry
);
1883 to
= from
+ get_expression_value(sym
->array_size
);
1885 evaluate_initializer(ctype
, parent
);
1890 static void evaluate_array_initializer(struct symbol
*ctype
, struct expression
*expr
)
1892 struct expression
*entry
;
1895 FOR_EACH_PTR(expr
->expr_list
, entry
) {
1896 current
= evaluate_one_array_initializer(ctype
, THIS_ADDRESS(entry
), current
);
1897 } END_FOR_EACH_PTR(entry
);
1900 /* A scalar initializer is allowed, and acts pretty much like an array of one */
1901 static void evaluate_scalar_initializer(struct symbol
*ctype
, struct expression
*expr
)
1903 if (expression_list_size(expr
->expr_list
) != 1) {
1904 sparse_error(expr
->pos
, "unexpected compound initializer");
1907 evaluate_array_initializer(ctype
, expr
);
1911 static struct symbol
*find_struct_ident(struct symbol
*ctype
, struct ident
*ident
)
1915 FOR_EACH_PTR(ctype
->symbol_list
, sym
) {
1916 if (sym
->ident
== ident
)
1918 } END_FOR_EACH_PTR(sym
);
1922 static int evaluate_one_struct_initializer(struct symbol
*ctype
, struct expression
**ep
, struct symbol
*sym
)
1924 struct expression
*entry
= *ep
;
1925 struct expression
**parent
;
1926 struct expression
*reuse
= NULL
;
1927 unsigned long offset
;
1930 sparse_error(entry
->pos
, "unknown named initializer");
1934 if (entry
->type
== EXPR_IDENTIFIER
) {
1936 entry
= entry
->ident_expression
;
1940 offset
= sym
->offset
;
1943 reuse
= alloc_expression(entry
->pos
, EXPR_POS
);
1944 reuse
->type
= EXPR_POS
;
1946 reuse
->init_offset
= offset
;
1948 reuse
->init_expr
= entry
;
1949 parent
= &reuse
->init_expr
;
1953 evaluate_initializer(sym
, parent
);
1957 static void evaluate_struct_or_union_initializer(struct symbol
*ctype
, struct expression
*expr
, int multiple
)
1959 struct expression
*entry
;
1962 PREPARE_PTR_LIST(ctype
->symbol_list
, sym
);
1963 FOR_EACH_PTR(expr
->expr_list
, entry
) {
1964 if (entry
->type
== EXPR_IDENTIFIER
) {
1965 struct ident
*ident
= entry
->expr_ident
;
1966 /* We special-case the "already right place" case */
1967 if (!sym
|| sym
->ident
!= ident
) {
1968 RESET_PTR_LIST(sym
);
1972 if (sym
->ident
== ident
)
1978 if (evaluate_one_struct_initializer(ctype
, THIS_ADDRESS(entry
), sym
))
1981 } END_FOR_EACH_PTR(entry
);
1982 FINISH_PTR_LIST(sym
);
1986 * Initializers are kind of like assignments. Except
1987 * they can be a hell of a lot more complex.
1989 static void evaluate_initializer(struct symbol
*ctype
, struct expression
**ep
)
1991 struct expression
*expr
= *ep
;
1994 * Simple non-structure/array initializers are the simple
1995 * case, and look (and parse) largely like assignments.
1997 switch (expr
->type
) {
1999 int is_string
= expr
->type
== EXPR_STRING
;
2000 struct symbol
*rtype
= evaluate_expression(expr
);
2004 * char array[] = "string"
2005 * should _not_ degenerate.
2007 if (!is_string
|| !is_string_type(ctype
))
2008 rtype
= degenerate(expr
);
2009 compatible_assignment_types(expr
, ctype
, ep
, rtype
, "initializer", '=');
2014 case EXPR_INITIALIZER
:
2015 expr
->ctype
= ctype
;
2016 if (ctype
->type
== SYM_NODE
)
2017 ctype
= ctype
->ctype
.base_type
;
2019 switch (ctype
->type
) {
2022 evaluate_array_initializer(get_base_type(ctype
), expr
);
2025 evaluate_struct_or_union_initializer(ctype
, expr
, 0);
2028 evaluate_struct_or_union_initializer(ctype
, expr
, 1);
2031 evaluate_scalar_initializer(ctype
, expr
);
2035 case EXPR_IDENTIFIER
:
2036 if (ctype
->type
== SYM_NODE
)
2037 ctype
= ctype
->ctype
.base_type
;
2038 if (ctype
->type
!= SYM_STRUCT
&& ctype
->type
!= SYM_UNION
) {
2039 sparse_error(expr
->pos
, "expected structure or union for '%s' dereference", show_ident(expr
->expr_ident
));
2043 evaluate_one_struct_initializer(ctype
, ep
,
2044 find_struct_ident(ctype
, expr
->expr_ident
));
2048 if (ctype
->type
== SYM_NODE
)
2049 ctype
= ctype
->ctype
.base_type
;
2050 if (ctype
->type
!= SYM_ARRAY
) {
2051 sparse_error(expr
->pos
, "expected array");
2054 evaluate_one_array_initializer(ctype
->ctype
.base_type
, ep
, 0);
2059 * An EXPR_POS expression has already been evaluated, and we don't
2060 * need to do anything more
2066 static int get_as(struct symbol
*sym
)
2074 mod
= sym
->ctype
.modifiers
;
2075 if (sym
->type
== SYM_NODE
) {
2076 sym
= sym
->ctype
.base_type
;
2077 as
|= sym
->ctype
.as
;
2078 mod
|= sym
->ctype
.modifiers
;
2082 * At least for now, allow casting to a "unsigned long".
2083 * That's how we do things like pointer arithmetic and
2084 * store pointers to registers.
2086 if (sym
== &ulong_ctype
)
2089 if (sym
&& sym
->type
== SYM_PTR
) {
2090 sym
= get_base_type(sym
);
2091 as
|= sym
->ctype
.as
;
2092 mod
|= sym
->ctype
.modifiers
;
2094 if (mod
& MOD_FORCE
)
2099 static void cast_to_as(struct expression
*e
, int as
)
2101 struct expression
*v
= e
->cast_expression
;
2103 if (!Wcast_to_address_space
)
2106 /* cast from constant 0 to pointer is OK */
2107 if (v
->type
== EXPR_VALUE
&& is_int_type(v
->ctype
) && !v
->value
)
2110 warning(e
->pos
, "cast adds address space to expression (<asn:%d>)", as
);
2113 static struct symbol
*evaluate_cast(struct expression
*expr
)
2115 struct expression
*target
= expr
->cast_expression
;
2116 struct symbol
*ctype
= examine_symbol_type(expr
->cast_type
);
2117 struct symbol
*t1
, *t2
;
2118 enum type type1
, type2
;
2124 expr
->ctype
= ctype
;
2125 expr
->cast_type
= ctype
;
2128 * Special case: a cast can be followed by an
2129 * initializer, in which case we need to pass
2130 * the type value down to that initializer rather
2131 * than trying to evaluate it as an expression
2133 * A more complex case is when the initializer is
2134 * dereferenced as part of a post-fix expression.
2135 * We need to produce an expression that can be dereferenced.
2137 if (target
->type
== EXPR_INITIALIZER
) {
2138 struct symbol
*sym
= expr
->cast_type
;
2139 struct expression
*addr
= alloc_expression(expr
->pos
, EXPR_SYMBOL
);
2141 sym
->initializer
= expr
->cast_expression
;
2142 evaluate_symbol(sym
);
2144 addr
->ctype
= &lazy_ptr_ctype
; /* Lazy eval */
2147 expr
->type
= EXPR_PREOP
;
2155 evaluate_expression(target
);
2159 if (t1
->type
== SYM_NODE
)
2160 t1
= t1
->ctype
.base_type
;
2161 if (t1
->type
== SYM_ENUM
)
2162 t1
= t1
->ctype
.base_type
;
2165 * You can always throw a value away by casting to
2166 * "void" - that's an implicit "force". Note that
2167 * the same is _not_ true of "void *".
2169 if (t1
== &void_ctype
)
2173 if (type1
== SYM_ARRAY
|| type1
== SYM_UNION
|| type1
== SYM_STRUCT
)
2174 warning(expr
->pos
, "cast to non-scalar");
2178 sparse_error(expr
->pos
, "cast from unknown type");
2181 if (t2
->type
== SYM_NODE
)
2182 t2
= t2
->ctype
.base_type
;
2183 if (t2
->type
== SYM_ENUM
)
2184 t2
= t2
->ctype
.base_type
;
2187 if (type2
== SYM_ARRAY
|| type2
== SYM_UNION
|| type2
== SYM_STRUCT
)
2188 warning(expr
->pos
, "cast from non-scalar");
2190 if (!(ctype
->ctype
.modifiers
& MOD_FORCE
) && t1
!= t2
) {
2191 if (t1
->type
== SYM_RESTRICT
)
2192 warning(expr
->pos
, "cast to restricted type");
2193 if (t2
->type
== SYM_RESTRICT
)
2194 warning(expr
->pos
, "cast from restricted type");
2197 as1
= get_as(ctype
);
2198 as2
= get_as(target
->ctype
);
2199 if (!as1
&& as2
> 0)
2200 warning(expr
->pos
, "cast removes address space of expression");
2201 if (as1
> 0 && as2
> 0 && as1
!= as2
)
2202 warning(expr
->pos
, "cast between address spaces (<asn:%d>-><asn:%d>)", as2
, as1
);
2203 if (as1
> 0 && !as2
)
2204 cast_to_as(expr
, as1
);
2207 * Casts of constant values are special: they
2208 * can be NULL, and thus need to be simplified
2211 if (target
->type
== EXPR_VALUE
)
2212 cast_value(expr
, ctype
, target
, target
->ctype
);
2219 * Evaluate a call expression with a symbol. This
2220 * should expand inline functions, and evaluate
2223 static int evaluate_symbol_call(struct expression
*expr
)
2225 struct expression
*fn
= expr
->fn
;
2226 struct symbol
*ctype
= fn
->ctype
;
2228 if (fn
->type
!= EXPR_PREOP
)
2231 if (ctype
->op
&& ctype
->op
->evaluate
)
2232 return ctype
->op
->evaluate(expr
);
2234 if (ctype
->ctype
.modifiers
& MOD_INLINE
) {
2236 struct symbol
*curr
= current_fn
;
2237 current_fn
= ctype
->ctype
.base_type
;
2238 examine_fn_arguments(current_fn
);
2240 ret
= inline_function(expr
, ctype
);
2242 /* restore the old function */
2250 static struct symbol
*evaluate_call(struct expression
*expr
)
2253 struct symbol
*ctype
, *sym
;
2254 struct expression
*fn
= expr
->fn
;
2255 struct expression_list
*arglist
= expr
->args
;
2257 if (!evaluate_expression(fn
))
2259 sym
= ctype
= fn
->ctype
;
2260 if (ctype
->type
== SYM_NODE
)
2261 ctype
= ctype
->ctype
.base_type
;
2262 if (ctype
->type
== SYM_PTR
|| ctype
->type
== SYM_ARRAY
)
2263 ctype
= get_base_type(ctype
);
2264 if (!evaluate_arguments(sym
, ctype
, arglist
))
2266 if (ctype
->type
!= SYM_FN
) {
2267 sparse_error(expr
->pos
, "not a function %s", show_ident(sym
->ident
));
2270 args
= expression_list_size(expr
->args
);
2271 fnargs
= symbol_list_size(ctype
->arguments
);
2273 sparse_error(expr
->pos
, "not enough arguments for function %s", show_ident(sym
->ident
));
2274 if (args
> fnargs
&& !ctype
->variadic
)
2275 sparse_error(expr
->pos
, "too many arguments for function %s", show_ident(sym
->ident
));
2276 if (sym
->type
== SYM_NODE
) {
2277 if (evaluate_symbol_call(expr
))
2280 expr
->ctype
= ctype
->ctype
.base_type
;
2284 struct symbol
*evaluate_expression(struct expression
*expr
)
2291 switch (expr
->type
) {
2294 sparse_error(expr
->pos
, "value expression without a type");
2297 return evaluate_string(expr
);
2299 return evaluate_symbol_expression(expr
);
2301 if (!evaluate_expression(expr
->left
))
2303 if (!evaluate_expression(expr
->right
))
2305 return evaluate_binop(expr
);
2307 return evaluate_logical(expr
);
2309 evaluate_expression(expr
->left
);
2310 if (!evaluate_expression(expr
->right
))
2312 return evaluate_comma(expr
);
2314 if (!evaluate_expression(expr
->left
))
2316 if (!evaluate_expression(expr
->right
))
2318 return evaluate_compare(expr
);
2319 case EXPR_ASSIGNMENT
:
2320 if (!evaluate_expression(expr
->left
))
2322 if (!evaluate_expression(expr
->right
))
2324 return evaluate_assignment(expr
);
2326 if (!evaluate_expression(expr
->unop
))
2328 return evaluate_preop(expr
);
2330 if (!evaluate_expression(expr
->unop
))
2332 return evaluate_postop(expr
);
2334 case EXPR_IMPLIED_CAST
:
2335 return evaluate_cast(expr
);
2337 return evaluate_sizeof(expr
);
2338 case EXPR_PTRSIZEOF
:
2339 return evaluate_ptrsizeof(expr
);
2341 return evaluate_alignof(expr
);
2343 return evaluate_member_dereference(expr
);
2345 return evaluate_call(expr
);
2347 case EXPR_CONDITIONAL
:
2348 return evaluate_conditional_expression(expr
);
2349 case EXPR_STATEMENT
:
2350 expr
->ctype
= evaluate_statement(expr
->statement
);
2354 expr
->ctype
= &ptr_ctype
;
2358 /* Evaluate the type of the symbol .. */
2359 evaluate_symbol(expr
->symbol
);
2360 /* .. but the type of the _expression_ is a "type" */
2361 expr
->ctype
= &type_ctype
;
2364 /* These can not exist as stand-alone expressions */
2365 case EXPR_INITIALIZER
:
2366 case EXPR_IDENTIFIER
:
2369 sparse_error(expr
->pos
, "internal front-end error: initializer in expression");
2372 sparse_error(expr
->pos
, "internal front-end error: SLICE re-evaluated");
2378 static void check_duplicates(struct symbol
*sym
)
2381 struct symbol
*next
= sym
;
2383 while ((next
= next
->same_symbol
) != NULL
) {
2384 const char *typediff
;
2385 evaluate_symbol(next
);
2387 typediff
= type_difference(sym
, next
, 0, 0);
2389 sparse_error(sym
->pos
, "symbol '%s' redeclared with different type (originally declared at %s:%d) - %s",
2390 show_ident(sym
->ident
),
2391 stream_name(next
->pos
.stream
), next
->pos
.line
, typediff
);
2396 unsigned long mod
= sym
->ctype
.modifiers
;
2397 if (mod
& (MOD_STATIC
| MOD_REGISTER
))
2399 if (!(mod
& MOD_TOPLEVEL
))
2403 if (sym
->ident
== &main_ident
)
2405 warning(sym
->pos
, "symbol '%s' was not declared. Should it be static?", show_ident(sym
->ident
));
2409 static struct symbol
*evaluate_symbol(struct symbol
*sym
)
2411 struct symbol
*base_type
;
2419 sym
= examine_symbol_type(sym
);
2420 base_type
= get_base_type(sym
);
2424 /* Evaluate the initializers */
2425 if (sym
->initializer
)
2426 evaluate_initializer(sym
, &sym
->initializer
);
2428 /* And finally, evaluate the body of the symbol too */
2429 if (base_type
->type
== SYM_FN
) {
2430 struct symbol
*curr
= current_fn
;
2432 current_fn
= base_type
;
2434 examine_fn_arguments(base_type
);
2435 if (!base_type
->stmt
&& base_type
->inline_stmt
)
2437 if (base_type
->stmt
)
2438 evaluate_statement(base_type
->stmt
);
2446 void evaluate_symbol_list(struct symbol_list
*list
)
2450 FOR_EACH_PTR(list
, sym
) {
2451 check_duplicates(sym
);
2452 evaluate_symbol(sym
);
2453 } END_FOR_EACH_PTR(sym
);
2456 static struct symbol
*evaluate_return_expression(struct statement
*stmt
)
2458 struct expression
*expr
= stmt
->expression
;
2459 struct symbol
*ctype
, *fntype
;
2461 evaluate_expression(expr
);
2462 ctype
= degenerate(expr
);
2463 fntype
= current_fn
->ctype
.base_type
;
2464 if (!fntype
|| fntype
== &void_ctype
) {
2465 if (expr
&& ctype
!= &void_ctype
)
2466 sparse_error(expr
->pos
, "return expression in %s function", fntype
?"void":"typeless");
2471 sparse_error(stmt
->pos
, "return with no return value");
2476 compatible_assignment_types(expr
, fntype
, &stmt
->expression
, ctype
, "return expression", '=');
2480 static void evaluate_if_statement(struct statement
*stmt
)
2482 if (!stmt
->if_conditional
)
2485 evaluate_conditional(stmt
->if_conditional
, 0);
2486 evaluate_statement(stmt
->if_true
);
2487 evaluate_statement(stmt
->if_false
);
2490 static void evaluate_iterator(struct statement
*stmt
)
2492 evaluate_conditional(stmt
->iterator_pre_condition
, 1);
2493 evaluate_conditional(stmt
->iterator_post_condition
,1);
2494 evaluate_statement(stmt
->iterator_pre_statement
);
2495 evaluate_statement(stmt
->iterator_statement
);
2496 evaluate_statement(stmt
->iterator_post_statement
);
2499 static void verify_output_constraint(struct expression
*expr
, const char *constraint
)
2501 switch (*constraint
) {
2502 case '=': /* Assignment */
2503 case '+': /* Update */
2506 sparse_error(expr
->pos
, "output constraint is not an assignment constraint (\"%s\")", constraint
);
2510 static void verify_input_constraint(struct expression
*expr
, const char *constraint
)
2512 switch (*constraint
) {
2513 case '=': /* Assignment */
2514 case '+': /* Update */
2515 sparse_error(expr
->pos
, "input constraint with assignment (\"%s\")", constraint
);
2519 static void evaluate_asm_statement(struct statement
*stmt
)
2521 struct expression
*expr
;
2524 expr
= stmt
->asm_string
;
2525 if (!expr
|| expr
->type
!= EXPR_STRING
) {
2526 sparse_error(stmt
->pos
, "need constant string for inline asm");
2531 FOR_EACH_PTR(stmt
->asm_outputs
, expr
) {
2532 struct ident
*ident
;
2535 case 0: /* Identifier */
2537 ident
= (struct ident
*)expr
;
2540 case 1: /* Constraint */
2542 if (!expr
|| expr
->type
!= EXPR_STRING
) {
2543 sparse_error(expr
? expr
->pos
: stmt
->pos
, "asm output constraint is not a string");
2544 *THIS_ADDRESS(expr
) = NULL
;
2547 verify_output_constraint(expr
, expr
->string
->data
);
2550 case 2: /* Expression */
2552 if (!evaluate_expression(expr
))
2554 if (!lvalue_expression(expr
))
2555 warning(expr
->pos
, "asm output is not an lvalue");
2556 evaluate_assign_to(expr
, expr
->ctype
);
2559 } END_FOR_EACH_PTR(expr
);
2562 FOR_EACH_PTR(stmt
->asm_inputs
, expr
) {
2563 struct ident
*ident
;
2566 case 0: /* Identifier */
2568 ident
= (struct ident
*)expr
;
2571 case 1: /* Constraint */
2573 if (!expr
|| expr
->type
!= EXPR_STRING
) {
2574 sparse_error(expr
? expr
->pos
: stmt
->pos
, "asm input constraint is not a string");
2575 *THIS_ADDRESS(expr
) = NULL
;
2578 verify_input_constraint(expr
, expr
->string
->data
);
2581 case 2: /* Expression */
2583 if (!evaluate_expression(expr
))
2587 } END_FOR_EACH_PTR(expr
);
2589 FOR_EACH_PTR(stmt
->asm_clobbers
, expr
) {
2591 sparse_error(stmt
->pos
, "bad asm output");
2594 if (expr
->type
== EXPR_STRING
)
2596 sparse_error(expr
->pos
, "asm clobber is not a string");
2597 } END_FOR_EACH_PTR(expr
);
2600 static void evaluate_case_statement(struct statement
*stmt
)
2602 evaluate_expression(stmt
->case_expression
);
2603 evaluate_expression(stmt
->case_to
);
2604 evaluate_statement(stmt
->case_statement
);
2607 static void check_case_type(struct expression
*switch_expr
, struct expression
*case_expr
)
2609 struct symbol
*switch_type
, *case_type
;
2612 switch_type
= switch_expr
->ctype
;
2613 case_type
= evaluate_expression(case_expr
);
2615 if (case_type
&& switch_type
) {
2616 /* Both integer types? */
2617 if (is_int_type(switch_type
) && is_int_type(case_type
))
2619 if (compatible_restricted_binop(SPECIAL_EQUAL
, &switch_expr
, &case_expr
))
2623 sparse_error(case_expr
->pos
, "incompatible types for 'case' statement");
2626 static void evaluate_switch_statement(struct statement
*stmt
)
2630 evaluate_expression(stmt
->switch_expression
);
2631 evaluate_statement(stmt
->switch_statement
);
2632 if (!stmt
->switch_expression
)
2634 FOR_EACH_PTR(stmt
->switch_case
->symbol_list
, sym
) {
2635 struct statement
*case_stmt
= sym
->stmt
;
2636 check_case_type(stmt
->switch_expression
, case_stmt
->case_expression
);
2637 check_case_type(stmt
->switch_expression
, case_stmt
->case_to
);
2638 } END_FOR_EACH_PTR(sym
);
2641 struct symbol
*evaluate_statement(struct statement
*stmt
)
2646 switch (stmt
->type
) {
2647 case STMT_DECLARATION
: {
2649 FOR_EACH_PTR(stmt
->declaration
, s
) {
2651 } END_FOR_EACH_PTR(s
);
2656 return evaluate_return_expression(stmt
);
2658 case STMT_EXPRESSION
:
2659 if (!evaluate_expression(stmt
->expression
))
2661 return degenerate(stmt
->expression
);
2663 case STMT_COMPOUND
: {
2664 struct statement
*s
;
2665 struct symbol
*type
= NULL
;
2667 /* Evaluate the return symbol in the compound statement */
2668 evaluate_symbol(stmt
->ret
);
2671 * Then, evaluate each statement, making the type of the
2672 * compound statement be the type of the last statement
2675 FOR_EACH_PTR(stmt
->stmts
, s
) {
2676 type
= evaluate_statement(s
);
2677 } END_FOR_EACH_PTR(s
);
2683 evaluate_if_statement(stmt
);
2686 evaluate_iterator(stmt
);
2689 evaluate_switch_statement(stmt
);
2692 evaluate_case_statement(stmt
);
2695 return evaluate_statement(stmt
->label_statement
);
2697 evaluate_expression(stmt
->goto_expression
);
2702 evaluate_asm_statement(stmt
);
2705 evaluate_expression(stmt
->expression
);
2708 evaluate_expression(stmt
->range_expression
);
2709 evaluate_expression(stmt
->range_low
);
2710 evaluate_expression(stmt
->range_high
);