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
->op
== '~') {
262 old
->unop
= cast_to(old
->unop
, type
);
267 case EXPR_IMPLIED_CAST
:
268 if (old
->ctype
->bit_size
>= type
->bit_size
) {
269 struct expression
*orig
= old
->cast_expression
;
270 if (same_cast_type(orig
->ctype
, type
))
272 if (old
->ctype
->bit_offset
== type
->bit_offset
) {
274 old
->cast_type
= type
;
284 expr
= alloc_expression(old
->pos
, EXPR_IMPLIED_CAST
);
286 expr
->cast_type
= type
;
287 expr
->cast_expression
= old
;
291 static int is_type_type(struct symbol
*type
)
293 return (type
->ctype
.modifiers
& MOD_TYPE
) != 0;
296 int is_ptr_type(struct symbol
*type
)
298 if (type
->type
== SYM_NODE
)
299 type
= type
->ctype
.base_type
;
300 return type
->type
== SYM_PTR
|| type
->type
== SYM_ARRAY
|| type
->type
== SYM_FN
;
303 static inline int is_float_type(struct symbol
*type
)
305 if (type
->type
== SYM_NODE
)
306 type
= type
->ctype
.base_type
;
307 return type
->ctype
.base_type
== &fp_type
;
310 static inline int is_byte_type(struct symbol
*type
)
312 return type
->bit_size
== bits_in_char
&& type
->type
!= SYM_BITFIELD
;
315 static inline int is_string_type(struct symbol
*type
)
317 if (type
->type
== SYM_NODE
)
318 type
= type
->ctype
.base_type
;
319 return type
->type
== SYM_ARRAY
&& is_byte_type(type
->ctype
.base_type
);
322 static struct symbol
*bad_expr_type(struct expression
*expr
)
324 sparse_error(expr
->pos
, "incompatible types for operation (%s)", show_special(expr
->op
));
325 switch (expr
->type
) {
328 info(expr
->pos
, " left side has type %s", show_typename(expr
->left
->ctype
));
329 info(expr
->pos
, " right side has type %s", show_typename(expr
->right
->ctype
));
333 info(expr
->pos
, " argument has type %s", show_typename(expr
->unop
->ctype
));
342 static struct symbol
*compatible_float_binop(struct expression
**lp
, struct expression
**rp
)
344 struct expression
*left
= *lp
, *right
= *rp
;
345 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
347 if (ltype
->type
== SYM_NODE
)
348 ltype
= ltype
->ctype
.base_type
;
349 if (rtype
->type
== SYM_NODE
)
350 rtype
= rtype
->ctype
.base_type
;
351 if (is_float_type(ltype
)) {
352 if (is_int_type(rtype
))
354 if (is_float_type(rtype
)) {
355 unsigned long lmod
= ltype
->ctype
.modifiers
;
356 unsigned long rmod
= rtype
->ctype
.modifiers
;
357 lmod
&= MOD_LONG
| MOD_LONGLONG
;
358 rmod
&= MOD_LONG
| MOD_LONGLONG
;
368 if (!is_float_type(rtype
) || !is_int_type(ltype
))
371 *lp
= cast_to(left
, rtype
);
374 *rp
= cast_to(right
, ltype
);
378 static struct symbol
*compatible_integer_binop(struct expression
**lp
, struct expression
**rp
)
380 struct expression
*left
= *lp
, *right
= *rp
;
381 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
383 if (ltype
->type
== SYM_NODE
)
384 ltype
= ltype
->ctype
.base_type
;
385 if (rtype
->type
== SYM_NODE
)
386 rtype
= rtype
->ctype
.base_type
;
387 if (is_int_type(ltype
) && is_int_type(rtype
)) {
388 struct symbol
*ctype
= bigger_int_type(ltype
, rtype
);
390 *lp
= cast_to(left
, ctype
);
391 *rp
= cast_to(right
, ctype
);
397 static int restricted_value(struct expression
*v
, struct symbol
*type
)
399 if (v
->type
!= EXPR_VALUE
)
406 static int restricted_binop(int op
, struct symbol
*type
)
415 case SPECIAL_NOTEQUAL
:
416 case SPECIAL_AND_ASSIGN
:
417 case SPECIAL_OR_ASSIGN
:
418 case SPECIAL_XOR_ASSIGN
:
425 static int restricted_unop(int op
, struct symbol
*type
)
427 if (op
== '~' && type
->bit_size
>= bits_in_int
)
434 static struct symbol
*compatible_restricted_binop(int op
, struct expression
**lp
, struct expression
**rp
)
436 struct expression
*left
= *lp
, *right
= *rp
;
437 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
438 struct symbol
*type
= NULL
;
440 if (ltype
->type
== SYM_NODE
)
441 ltype
= ltype
->ctype
.base_type
;
442 if (ltype
->type
== SYM_ENUM
)
443 ltype
= ltype
->ctype
.base_type
;
444 if (rtype
->type
== SYM_NODE
)
445 rtype
= rtype
->ctype
.base_type
;
446 if (rtype
->type
== SYM_ENUM
)
447 rtype
= rtype
->ctype
.base_type
;
448 if (is_restricted_type(ltype
)) {
449 if (is_restricted_type(rtype
)) {
453 if (!restricted_value(right
, ltype
))
456 } else if (is_restricted_type(rtype
)) {
457 if (!restricted_value(left
, rtype
))
462 if (restricted_binop(op
, type
))
467 static struct symbol
*evaluate_arith(struct expression
*expr
, int float_ok
)
469 struct symbol
*ctype
= compatible_integer_binop(&expr
->left
, &expr
->right
);
470 if (!ctype
&& float_ok
)
471 ctype
= compatible_float_binop(&expr
->left
, &expr
->right
);
473 ctype
= compatible_restricted_binop(expr
->op
, &expr
->left
, &expr
->right
);
478 return bad_expr_type(expr
);
481 static inline int lvalue_expression(struct expression
*expr
)
483 return expr
->type
== EXPR_PREOP
&& expr
->op
== '*';
486 static int ptr_object_size(struct symbol
*ptr_type
)
488 if (ptr_type
->type
== SYM_NODE
)
489 ptr_type
= ptr_type
->ctype
.base_type
;
490 if (ptr_type
->type
== SYM_PTR
)
491 ptr_type
= get_base_type(ptr_type
);
492 return ptr_type
->bit_size
;
495 static struct symbol
*evaluate_ptr_add(struct expression
*expr
, struct symbol
*ctype
, struct expression
**ip
)
497 struct expression
*i
= *ip
;
498 struct symbol
*ptr_type
= ctype
;
501 if (ptr_type
->type
== SYM_NODE
)
502 ptr_type
= ptr_type
->ctype
.base_type
;
504 if (!is_int_type(i
->ctype
))
505 return bad_expr_type(expr
);
507 examine_symbol_type(ctype
);
509 if (!ctype
->ctype
.base_type
) {
510 sparse_error(expr
->pos
, "missing type information");
514 /* Get the size of whatever the pointer points to */
515 bit_size
= ptr_object_size(ctype
);
517 if (bit_size
> bits_in_char
) {
518 int multiply
= bit_size
>> 3;
519 struct expression
*val
= alloc_expression(expr
->pos
, EXPR_VALUE
);
521 if (i
->type
== EXPR_VALUE
) {
522 val
->value
= i
->value
* multiply
;
523 val
->ctype
= size_t_ctype
;
526 struct expression
*mul
= alloc_expression(expr
->pos
, EXPR_BINOP
);
528 val
->ctype
= size_t_ctype
;
529 val
->value
= bit_size
>> 3;
532 mul
->ctype
= size_t_ctype
;
544 static struct symbol
*evaluate_add(struct expression
*expr
)
546 struct expression
*left
= expr
->left
, *right
= expr
->right
;
547 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
549 if (is_ptr_type(ltype
))
550 return evaluate_ptr_add(expr
, degenerate(left
), &expr
->right
);
552 if (is_ptr_type(rtype
))
553 return evaluate_ptr_add(expr
, degenerate(right
), &expr
->left
);
555 return evaluate_arith(expr
, 1);
558 const char * type_difference(struct symbol
*target
, struct symbol
*source
,
559 unsigned long target_mod_ignore
, unsigned long source_mod_ignore
)
562 unsigned long mod1
, mod2
, diff
;
563 unsigned long as1
, as2
;
565 struct symbol
*base1
, *base2
;
567 if (target
== source
)
569 if (!target
|| !source
)
570 return "different types";
572 * Peel of per-node information.
573 * FIXME! Check alignment and context too here!
575 mod1
= target
->ctype
.modifiers
;
576 as1
= target
->ctype
.as
;
577 mod2
= source
->ctype
.modifiers
;
578 as2
= source
->ctype
.as
;
579 if (target
->type
== SYM_NODE
) {
580 target
= target
->ctype
.base_type
;
583 if (target
->type
== SYM_PTR
) {
587 mod1
|= target
->ctype
.modifiers
;
588 as1
|= target
->ctype
.as
;
590 if (source
->type
== SYM_NODE
) {
591 source
= source
->ctype
.base_type
;
594 if (source
->type
== SYM_PTR
) {
598 mod2
|= source
->ctype
.modifiers
;
599 as2
|= source
->ctype
.as
;
601 if (target
->type
== SYM_ENUM
) {
602 target
= target
->ctype
.base_type
;
606 if (source
->type
== SYM_ENUM
) {
607 source
= source
->ctype
.base_type
;
612 if (target
== source
)
614 if (!target
|| !source
)
615 return "different types";
617 type1
= target
->type
;
618 base1
= target
->ctype
.base_type
;
620 type2
= source
->type
;
621 base2
= source
->ctype
.base_type
;
624 * Pointers to functions compare as the function itself
626 if (type1
== SYM_PTR
&& base1
) {
627 base1
= examine_symbol_type(base1
);
628 switch (base1
->type
) {
632 base1
= base1
->ctype
.base_type
;
637 if (type2
== SYM_PTR
&& base2
) {
638 base2
= examine_symbol_type(base2
);
639 switch (base2
->type
) {
643 base2
= base2
->ctype
.base_type
;
649 /* Arrays degenerate to pointers for type comparisons */
650 type1
= (type1
== SYM_ARRAY
) ? SYM_PTR
: type1
;
651 type2
= (type2
== SYM_ARRAY
) ? SYM_PTR
: type2
;
653 if (type1
!= type2
|| type1
== SYM_RESTRICT
)
654 return "different base types";
656 /* Must be same address space to be comparable */
658 return "different address spaces";
660 /* Ignore differences in storage types or addressability */
661 diff
= (mod1
^ mod2
) & ~MOD_IGNORE
;
662 diff
&= (mod1
& ~target_mod_ignore
) | (mod2
& ~source_mod_ignore
);
665 return "different type sizes";
666 if (diff
& ~MOD_SIGNEDNESS
)
667 return "different modifiers";
669 /* Differs in signedness only.. */
672 * Warn if both are explicitly signed ("unsigned" is obvously
673 * always explicit, and since we know one of them has to be
674 * unsigned, we check if the signed one was explicit).
676 if ((mod1
| mod2
) & MOD_EXPLICITLY_SIGNED
)
677 return "different explicit signedness";
680 * "char" matches both "unsigned char" and "signed char",
681 * so if the explicit test didn't trigger, then we should
682 * not warn about a char.
684 if (!(mod1
& MOD_CHAR
))
685 return "different signedness";
689 if (type1
== SYM_FN
) {
691 struct symbol
*arg1
, *arg2
;
692 if (base1
->variadic
!= base2
->variadic
)
693 return "incompatible variadic arguments";
694 PREPARE_PTR_LIST(target
->arguments
, arg1
);
695 PREPARE_PTR_LIST(source
->arguments
, arg2
);
699 diff
= type_difference(arg1
, arg2
, 0, 0);
701 static char argdiff
[80];
702 sprintf(argdiff
, "incompatible argument %d (%s)", i
, diff
);
711 FINISH_PTR_LIST(arg2
);
712 FINISH_PTR_LIST(arg1
);
721 static int is_null_ptr(struct expression
*expr
)
723 if (expr
->type
!= EXPR_VALUE
|| expr
->value
)
725 if (!is_ptr_type(expr
->ctype
))
726 warning(expr
->pos
, "Using plain integer as NULL pointer");
730 static struct symbol
*common_ptr_type(struct expression
*l
, struct expression
*r
)
732 /* NULL expression? Just return the type of the "other side" */
741 * Ignore differences in "volatile" and "const"ness when
742 * subtracting pointers
744 #define MOD_IGN (MOD_VOLATILE | MOD_CONST)
746 static struct symbol
*evaluate_ptr_sub(struct expression
*expr
, struct expression
*l
, struct expression
**rp
)
748 const char *typediff
;
749 struct symbol
*ctype
;
750 struct symbol
*ltype
, *rtype
;
751 struct expression
*r
= *rp
;
753 ltype
= degenerate(l
);
754 rtype
= degenerate(r
);
757 * If it is an integer subtract: the ptr add case will do the
760 if (!is_ptr_type(rtype
))
761 return evaluate_ptr_add(expr
, degenerate(l
), rp
);
764 typediff
= type_difference(ltype
, rtype
, ~MOD_SIZE
, ~MOD_SIZE
);
766 ctype
= common_ptr_type(l
, r
);
768 sparse_error(expr
->pos
, "subtraction of different types can't work (%s)", typediff
);
772 examine_symbol_type(ctype
);
774 /* Figure out the base type we point to */
775 if (ctype
->type
== SYM_NODE
)
776 ctype
= ctype
->ctype
.base_type
;
777 if (ctype
->type
!= SYM_PTR
&& ctype
->type
!= SYM_ARRAY
) {
778 sparse_error(expr
->pos
, "subtraction of functions? Share your drugs");
781 ctype
= get_base_type(ctype
);
783 expr
->ctype
= ssize_t_ctype
;
784 if (ctype
->bit_size
> bits_in_char
) {
785 struct expression
*sub
= alloc_expression(expr
->pos
, EXPR_BINOP
);
786 struct expression
*div
= expr
;
787 struct expression
*val
= alloc_expression(expr
->pos
, EXPR_VALUE
);
788 unsigned long value
= ctype
->bit_size
>> 3;
790 val
->ctype
= size_t_ctype
;
793 if (value
& (value
-1)) {
794 if (Wptr_subtraction_blows
)
795 warning(expr
->pos
, "potentially expensive pointer subtraction");
799 sub
->ctype
= ssize_t_ctype
;
808 return ssize_t_ctype
;
811 static struct symbol
*evaluate_sub(struct expression
*expr
)
813 struct expression
*left
= expr
->left
;
814 struct symbol
*ltype
= left
->ctype
;
816 if (is_ptr_type(ltype
))
817 return evaluate_ptr_sub(expr
, left
, &expr
->right
);
819 return evaluate_arith(expr
, 1);
822 #define is_safe_type(type) ((type)->ctype.modifiers & MOD_SAFE)
824 static struct symbol
*evaluate_conditional(struct expression
*expr
, int iterator
)
826 struct symbol
*ctype
;
831 if (!iterator
&& expr
->type
== EXPR_ASSIGNMENT
&& expr
->op
== '=')
832 warning(expr
->pos
, "assignment expression in conditional");
834 ctype
= evaluate_expression(expr
);
836 if (is_safe_type(ctype
))
837 warning(expr
->pos
, "testing a 'safe expression'");
843 static struct symbol
*evaluate_logical(struct expression
*expr
)
845 if (!evaluate_conditional(expr
->left
, 0))
847 if (!evaluate_conditional(expr
->right
, 0))
850 expr
->ctype
= &bool_ctype
;
854 static struct symbol
*evaluate_shift(struct expression
*expr
)
856 struct expression
*left
= expr
->left
, *right
= expr
->right
;
857 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
859 if (ltype
->type
== SYM_NODE
)
860 ltype
= ltype
->ctype
.base_type
;
861 if (rtype
->type
== SYM_NODE
)
862 rtype
= rtype
->ctype
.base_type
;
863 if (is_int_type(ltype
) && is_int_type(rtype
)) {
864 struct symbol
*ctype
= integer_promotion(ltype
);
865 expr
->left
= cast_to(expr
->left
, ctype
);
867 ctype
= integer_promotion(rtype
);
868 expr
->right
= cast_to(expr
->right
, ctype
);
871 return bad_expr_type(expr
);
874 static struct symbol
*evaluate_binop(struct expression
*expr
)
877 // addition can take ptr+int, fp and int
879 return evaluate_add(expr
);
881 // subtraction can take ptr-ptr, fp and int
883 return evaluate_sub(expr
);
885 // Arithmetic operations can take fp and int
887 return evaluate_arith(expr
, 1);
889 // shifts do integer promotions, but that's it.
890 case SPECIAL_LEFTSHIFT
: case SPECIAL_RIGHTSHIFT
:
891 return evaluate_shift(expr
);
893 // The rest are integer operations
894 // '%', '&', '^', '|'
896 return evaluate_arith(expr
, 0);
900 static struct symbol
*evaluate_comma(struct expression
*expr
)
902 expr
->ctype
= expr
->right
->ctype
;
906 static int modify_for_unsigned(int op
)
909 op
= SPECIAL_UNSIGNED_LT
;
911 op
= SPECIAL_UNSIGNED_GT
;
912 else if (op
== SPECIAL_LTE
)
913 op
= SPECIAL_UNSIGNED_LTE
;
914 else if (op
== SPECIAL_GTE
)
915 op
= SPECIAL_UNSIGNED_GTE
;
919 static struct symbol
*evaluate_compare(struct expression
*expr
)
921 struct expression
*left
= expr
->left
, *right
= expr
->right
;
922 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
923 struct symbol
*ctype
;
926 if (is_type_type(ltype
) && is_type_type(rtype
))
929 if (is_safe_type(ltype
) || is_safe_type(rtype
))
930 warning(expr
->pos
, "testing a 'safe expression'");
933 if (is_ptr_type(ltype
) || is_ptr_type(rtype
)) {
934 // FIXME! Check the types for compatibility
935 expr
->op
= modify_for_unsigned(expr
->op
);
939 ctype
= compatible_integer_binop(&expr
->left
, &expr
->right
);
941 if (ctype
->ctype
.modifiers
& MOD_UNSIGNED
)
942 expr
->op
= modify_for_unsigned(expr
->op
);
946 ctype
= compatible_float_binop(&expr
->left
, &expr
->right
);
950 ctype
= compatible_restricted_binop(expr
->op
, &expr
->left
, &expr
->right
);
952 if (ctype
->ctype
.modifiers
& MOD_UNSIGNED
)
953 expr
->op
= modify_for_unsigned(expr
->op
);
960 expr
->ctype
= &bool_ctype
;
965 * FIXME!! This should do casts, array degeneration etc..
967 static struct symbol
*compatible_ptr_type(struct expression
*left
, struct expression
*right
)
969 struct symbol
*ltype
= left
->ctype
, *rtype
= right
->ctype
;
971 if (ltype
->type
== SYM_NODE
)
972 ltype
= ltype
->ctype
.base_type
;
974 if (rtype
->type
== SYM_NODE
)
975 rtype
= rtype
->ctype
.base_type
;
977 if (ltype
->type
== SYM_PTR
) {
978 if (is_null_ptr(right
) || rtype
->ctype
.base_type
== &void_ctype
)
982 if (rtype
->type
== SYM_PTR
) {
983 if (is_null_ptr(left
) || ltype
->ctype
.base_type
== &void_ctype
)
990 * NOTE! The degenerate case of "x ? : y", where we don't
991 * have a true case, this will possibly promote "x" to the
992 * same type as "y", and thus _change_ the conditional
993 * test in the expression. But since promotion is "safe"
994 * for testing, that's ok.
996 static struct symbol
*evaluate_conditional_expression(struct expression
*expr
)
998 struct expression
**true;
999 struct symbol
*ctype
, *ltype
, *rtype
;
1000 const char * typediff
;
1002 if (!evaluate_conditional(expr
->conditional
, 0))
1004 if (!evaluate_expression(expr
->cond_false
))
1007 ctype
= degenerate(expr
->conditional
);
1008 rtype
= degenerate(expr
->cond_false
);
1010 true = &expr
->conditional
;
1012 if (expr
->cond_true
) {
1013 if (!evaluate_expression(expr
->cond_true
))
1015 ltype
= degenerate(expr
->cond_true
);
1016 true = &expr
->cond_true
;
1019 ctype
= compatible_integer_binop(true, &expr
->cond_false
);
1022 ctype
= compatible_ptr_type(*true, expr
->cond_false
);
1025 ctype
= compatible_float_binop(true, &expr
->cond_false
);
1028 ctype
= compatible_restricted_binop('?', true, &expr
->cond_false
);
1032 typediff
= type_difference(ltype
, rtype
, MOD_IGN
, MOD_IGN
);
1035 sparse_error(expr
->pos
, "incompatible types in conditional expression (%s)", typediff
);
1039 expr
->ctype
= ctype
;
1043 /* FP assignments can not do modulo or bit operations */
1044 static int compatible_float_op(int op
)
1047 op
== SPECIAL_ADD_ASSIGN
||
1048 op
== SPECIAL_SUB_ASSIGN
||
1049 op
== SPECIAL_MUL_ASSIGN
||
1050 op
== SPECIAL_DIV_ASSIGN
;
1053 static int compatible_assignment_types(struct expression
*expr
, struct symbol
*target
,
1054 struct expression
**rp
, struct symbol
*source
, const char *where
, int op
)
1056 const char *typediff
;
1060 if (is_int_type(target
)) {
1061 if (is_int_type(source
))
1063 if (is_float_type(source
))
1065 } else if (is_float_type(target
)) {
1066 if (!compatible_float_op(op
)) {
1067 sparse_error(expr
->pos
, "invalid assignment");
1070 if (is_int_type(source
))
1072 if (is_float_type(source
))
1074 } else if (is_restricted_type(target
)) {
1075 if (restricted_binop(op
, target
)) {
1076 sparse_error(expr
->pos
, "bad restricted assignment");
1079 if (!restricted_value(*rp
, target
))
1081 } else if (is_ptr_type(target
)) {
1082 if (op
== SPECIAL_ADD_ASSIGN
|| op
== SPECIAL_SUB_ASSIGN
) {
1083 evaluate_ptr_add(expr
, target
, rp
);
1087 sparse_error(expr
->pos
, "invalid pointer assignment");
1090 } else if (op
!= '=') {
1091 sparse_error(expr
->pos
, "invalid assignment");
1095 /* It's ok if the target is more volatile or const than the source */
1096 typediff
= type_difference(target
, source
, MOD_VOLATILE
| MOD_CONST
, 0);
1100 /* Pointer destination? */
1102 target_as
= t
->ctype
.as
;
1103 if (t
->type
== SYM_NODE
) {
1104 t
= t
->ctype
.base_type
;
1105 target_as
|= t
->ctype
.as
;
1107 if (t
->type
== SYM_PTR
|| t
->type
== SYM_FN
|| t
->type
== SYM_ARRAY
) {
1108 struct expression
*right
= *rp
;
1109 struct symbol
*s
= source
;
1112 // NULL pointer is always ok
1113 if (is_null_ptr(right
))
1116 /* "void *" matches anything as long as the address space is ok */
1117 source_as
= s
->ctype
.as
;
1118 if (s
->type
== SYM_NODE
) {
1119 s
= s
->ctype
.base_type
;
1120 source_as
|= s
->ctype
.as
;
1122 if (source_as
== target_as
&& (s
->type
== SYM_PTR
|| s
->type
== SYM_ARRAY
)) {
1123 s
= get_base_type(s
);
1124 t
= get_base_type(t
);
1125 if (s
== &void_ctype
|| t
== &void_ctype
)
1130 warning(expr
->pos
, "incorrect type in %s (%s)", where
, typediff
);
1131 info(expr
->pos
, " expected %s", show_typename(target
));
1132 info(expr
->pos
, " got %s", show_typename(source
));
1133 *rp
= cast_to(*rp
, target
);
1136 *rp
= cast_to(*rp
, target
);
1140 static void mark_assigned(struct expression
*expr
)
1146 switch (expr
->type
) {
1151 if (sym
->type
!= SYM_NODE
)
1153 sym
->ctype
.modifiers
|= MOD_ASSIGNED
;
1157 mark_assigned(expr
->left
);
1158 mark_assigned(expr
->right
);
1161 mark_assigned(expr
->cast_expression
);
1164 mark_assigned(expr
->base
);
1172 static void evaluate_assign_to(struct expression
*left
, struct symbol
*type
)
1174 if (type
->ctype
.modifiers
& MOD_CONST
)
1175 sparse_error(left
->pos
, "assignment to const expression");
1177 /* We know left is an lvalue, so it's a "preop-*" */
1178 mark_assigned(left
->unop
);
1181 static struct symbol
*evaluate_assignment(struct expression
*expr
)
1183 struct expression
*left
= expr
->left
, *right
= expr
->right
;
1184 struct expression
*where
= expr
;
1185 struct symbol
*ltype
, *rtype
;
1187 if (!lvalue_expression(left
)) {
1188 sparse_error(expr
->pos
, "not an lvalue");
1192 ltype
= left
->ctype
;
1194 rtype
= degenerate(right
);
1196 if (!compatible_assignment_types(where
, ltype
, &where
->right
, rtype
, "assignment", expr
->op
))
1199 evaluate_assign_to(left
, ltype
);
1201 expr
->ctype
= ltype
;
1205 static void examine_fn_arguments(struct symbol
*fn
)
1209 FOR_EACH_PTR(fn
->arguments
, s
) {
1210 struct symbol
*arg
= evaluate_symbol(s
);
1211 /* Array/function arguments silently degenerate into pointers */
1217 ptr
= alloc_symbol(s
->pos
, SYM_PTR
);
1218 if (arg
->type
== SYM_ARRAY
)
1219 ptr
->ctype
= arg
->ctype
;
1221 ptr
->ctype
.base_type
= arg
;
1222 ptr
->ctype
.as
|= s
->ctype
.as
;
1223 ptr
->ctype
.modifiers
|= s
->ctype
.modifiers
;
1225 s
->ctype
.base_type
= ptr
;
1227 s
->ctype
.modifiers
= 0;
1230 examine_symbol_type(s
);
1237 } END_FOR_EACH_PTR(s
);
1240 static struct symbol
*convert_to_as_mod(struct symbol
*sym
, int as
, int mod
)
1242 /* Take the modifiers of the pointer, and apply them to the member */
1243 mod
|= sym
->ctype
.modifiers
;
1244 if (sym
->ctype
.as
!= as
|| sym
->ctype
.modifiers
!= mod
) {
1245 struct symbol
*newsym
= alloc_symbol(sym
->pos
, SYM_NODE
);
1247 newsym
->ctype
.as
= as
;
1248 newsym
->ctype
.modifiers
= mod
;
1254 #define MOD_PTRINHERIT (MOD_VOLATILE | MOD_CONST | MOD_NODEREF | MOD_STORAGE)
1256 static struct symbol
*create_pointer(struct expression
*expr
, struct symbol
*sym
, int degenerate
)
1258 struct symbol
*node
= alloc_symbol(expr
->pos
, SYM_NODE
);
1259 struct symbol
*ptr
= alloc_symbol(expr
->pos
, SYM_PTR
);
1261 node
->ctype
.base_type
= ptr
;
1262 ptr
->bit_size
= bits_in_pointer
;
1263 ptr
->ctype
.alignment
= pointer_alignment
;
1265 node
->bit_size
= bits_in_pointer
;
1266 node
->ctype
.alignment
= pointer_alignment
;
1269 if (sym
->ctype
.modifiers
& MOD_REGISTER
) {
1270 warning(expr
->pos
, "taking address of 'register' variable '%s'", show_ident(sym
->ident
));
1271 sym
->ctype
.modifiers
&= ~MOD_REGISTER
;
1273 if (sym
->type
== SYM_NODE
) {
1274 ptr
->ctype
.as
|= sym
->ctype
.as
;
1275 ptr
->ctype
.modifiers
|= sym
->ctype
.modifiers
& MOD_PTRINHERIT
;
1276 sym
= sym
->ctype
.base_type
;
1278 if (degenerate
&& sym
->type
== SYM_ARRAY
) {
1279 ptr
->ctype
.as
|= sym
->ctype
.as
;
1280 ptr
->ctype
.modifiers
|= sym
->ctype
.modifiers
& MOD_PTRINHERIT
;
1281 sym
= sym
->ctype
.base_type
;
1283 ptr
->ctype
.base_type
= sym
;
1288 /* Arrays degenerate into pointers on pointer arithmetic */
1289 static struct symbol
*degenerate(struct expression
*expr
)
1291 struct symbol
*ctype
, *base
;
1295 ctype
= expr
->ctype
;
1298 base
= examine_symbol_type(ctype
);
1299 if (ctype
->type
== SYM_NODE
)
1300 base
= ctype
->ctype
.base_type
;
1302 * Arrays degenerate into pointers to the entries, while
1303 * functions degenerate into pointers to themselves.
1304 * If array was part of non-lvalue compound, we create a copy
1305 * of that compound first and then act as if we were dealing with
1306 * the corresponding field in there.
1308 switch (base
->type
) {
1310 if (expr
->type
== EXPR_SLICE
) {
1311 struct symbol
*a
= alloc_symbol(expr
->pos
, SYM_NODE
);
1312 struct expression
*e0
, *e1
, *e2
, *e3
, *e4
;
1314 a
->ctype
.base_type
= expr
->base
->ctype
;
1315 a
->bit_size
= expr
->base
->ctype
->bit_size
;
1316 a
->array_size
= expr
->base
->ctype
->array_size
;
1318 e0
= alloc_expression(expr
->pos
, EXPR_SYMBOL
);
1320 e0
->ctype
= &lazy_ptr_ctype
;
1322 e1
= alloc_expression(expr
->pos
, EXPR_PREOP
);
1325 e1
->ctype
= expr
->base
->ctype
; /* XXX */
1327 e2
= alloc_expression(expr
->pos
, EXPR_ASSIGNMENT
);
1329 e2
->right
= expr
->base
;
1331 e2
->ctype
= expr
->base
->ctype
;
1333 if (expr
->r_bitpos
) {
1334 e3
= alloc_expression(expr
->pos
, EXPR_BINOP
);
1337 e3
->right
= alloc_const_expression(expr
->pos
,
1338 expr
->r_bitpos
>> 3);
1339 e3
->ctype
= &lazy_ptr_ctype
;
1344 e4
= alloc_expression(expr
->pos
, EXPR_COMMA
);
1347 e4
->ctype
= &lazy_ptr_ctype
;
1350 expr
->type
= EXPR_PREOP
;
1354 if (expr
->op
!= '*' || expr
->type
!= EXPR_PREOP
) {
1355 sparse_error(expr
->pos
, "strange non-value function or array");
1358 *expr
= *expr
->unop
;
1359 ctype
= create_pointer(expr
, ctype
, 1);
1360 expr
->ctype
= ctype
;
1367 static struct symbol
*evaluate_addressof(struct expression
*expr
)
1369 struct expression
*op
= expr
->unop
;
1370 struct symbol
*ctype
;
1372 if (op
->op
!= '*' || op
->type
!= EXPR_PREOP
) {
1373 sparse_error(expr
->pos
, "not addressable");
1379 if (expr
->type
== EXPR_SYMBOL
) {
1380 struct symbol
*sym
= expr
->symbol
;
1381 sym
->ctype
.modifiers
|= MOD_ADDRESSABLE
;
1385 * symbol expression evaluation is lazy about the type
1386 * of the sub-expression, so we may have to generate
1387 * the type here if so..
1389 if (expr
->ctype
== &lazy_ptr_ctype
) {
1390 ctype
= create_pointer(expr
, ctype
, 0);
1391 expr
->ctype
= ctype
;
1397 static struct symbol
*evaluate_dereference(struct expression
*expr
)
1399 struct expression
*op
= expr
->unop
;
1400 struct symbol
*ctype
= op
->ctype
, *node
, *target
;
1402 /* Simplify: *&(expr) => (expr) */
1403 if (op
->type
== EXPR_PREOP
&& op
->op
== '&') {
1408 /* Dereferencing a node drops all the node information. */
1409 if (ctype
->type
== SYM_NODE
)
1410 ctype
= ctype
->ctype
.base_type
;
1412 node
= alloc_symbol(expr
->pos
, SYM_NODE
);
1413 target
= ctype
->ctype
.base_type
;
1415 switch (ctype
->type
) {
1417 sparse_error(expr
->pos
, "cannot derefence this type");
1420 node
->ctype
.modifiers
= target
->ctype
.modifiers
& MOD_SPECIFIER
;
1421 merge_type(node
, ctype
);
1425 if (!lvalue_expression(op
)) {
1426 sparse_error(op
->pos
, "non-lvalue array??");
1430 /* Do the implied "addressof" on the array */
1434 * When an array is dereferenced, we need to pick
1435 * up the attributes of the original node too..
1437 merge_type(node
, op
->ctype
);
1438 merge_type(node
, ctype
);
1442 node
->bit_size
= target
->bit_size
;
1443 node
->array_size
= target
->array_size
;
1450 * Unary post-ops: x++ and x--
1452 static struct symbol
*evaluate_postop(struct expression
*expr
)
1454 struct expression
*op
= expr
->unop
;
1455 struct symbol
*ctype
= op
->ctype
;
1457 if (!lvalue_expression(expr
->unop
)) {
1458 sparse_error(expr
->pos
, "need lvalue expression for ++/--");
1461 if (is_restricted_type(ctype
) && restricted_unop(expr
->op
, ctype
)) {
1462 sparse_error(expr
->pos
, "bad operation on restricted");
1466 evaluate_assign_to(op
, ctype
);
1468 expr
->ctype
= ctype
;
1470 if (is_ptr_type(ctype
))
1471 expr
->op_value
= ptr_object_size(ctype
) >> 3;
1476 static struct symbol
*evaluate_sign(struct expression
*expr
)
1478 struct symbol
*ctype
= expr
->unop
->ctype
;
1479 if (is_int_type(ctype
)) {
1480 struct symbol
*rtype
= rtype
= integer_promotion(ctype
);
1481 expr
->unop
= cast_to(expr
->unop
, rtype
);
1483 } else if (is_float_type(ctype
) && expr
->op
!= '~') {
1484 /* no conversions needed */
1485 } else if (is_restricted_type(ctype
) && !restricted_unop(expr
->op
, ctype
)) {
1486 /* no conversions needed */
1488 return bad_expr_type(expr
);
1490 if (expr
->op
== '+')
1491 *expr
= *expr
->unop
;
1492 expr
->ctype
= ctype
;
1496 static struct symbol
*evaluate_preop(struct expression
*expr
)
1498 struct symbol
*ctype
= expr
->unop
->ctype
;
1502 *expr
= *expr
->unop
;
1508 return evaluate_sign(expr
);
1511 return evaluate_dereference(expr
);
1514 return evaluate_addressof(expr
);
1516 case SPECIAL_INCREMENT
:
1517 case SPECIAL_DECREMENT
:
1519 * From a type evaluation standpoint the pre-ops are
1520 * the same as the postops
1522 return evaluate_postop(expr
);
1525 if (is_safe_type(ctype
))
1526 warning(expr
->pos
, "testing a 'safe expression'");
1527 if (is_float_type(ctype
)) {
1528 struct expression
*arg
= expr
->unop
;
1529 expr
->type
= EXPR_BINOP
;
1530 expr
->op
= SPECIAL_EQUAL
;
1532 expr
->right
= alloc_expression(expr
->pos
, EXPR_FVALUE
);
1533 expr
->right
->ctype
= ctype
;
1534 expr
->right
->fvalue
= 0;
1536 ctype
= &bool_ctype
;
1542 expr
->ctype
= ctype
;
1546 static struct symbol
*find_identifier(struct ident
*ident
, struct symbol_list
*_list
, int *offset
)
1548 struct ptr_list
*head
= (struct ptr_list
*)_list
;
1549 struct ptr_list
*list
= head
;
1555 for (i
= 0; i
< list
->nr
; i
++) {
1556 struct symbol
*sym
= (struct symbol
*) list
->list
[i
];
1558 if (sym
->ident
!= ident
)
1560 *offset
= sym
->offset
;
1563 struct symbol
*ctype
= sym
->ctype
.base_type
;
1567 if (ctype
->type
!= SYM_UNION
&& ctype
->type
!= SYM_STRUCT
)
1569 sub
= find_identifier(ident
, ctype
->symbol_list
, offset
);
1572 *offset
+= sym
->offset
;
1576 } while ((list
= list
->next
) != head
);
1580 static struct expression
*evaluate_offset(struct expression
*expr
, unsigned long offset
)
1582 struct expression
*add
;
1585 * Create a new add-expression
1587 * NOTE! Even if we just add zero, we need a new node
1588 * for the member pointer, since it has a different
1589 * type than the original pointer. We could make that
1590 * be just a cast, but the fact is, a node is a node,
1591 * so we might as well just do the "add zero" here.
1593 add
= alloc_expression(expr
->pos
, EXPR_BINOP
);
1596 add
->right
= alloc_expression(expr
->pos
, EXPR_VALUE
);
1597 add
->right
->ctype
= &int_ctype
;
1598 add
->right
->value
= offset
;
1601 * The ctype of the pointer will be lazily evaluated if
1602 * we ever take the address of this member dereference..
1604 add
->ctype
= &lazy_ptr_ctype
;
1608 /* structure/union dereference */
1609 static struct symbol
*evaluate_member_dereference(struct expression
*expr
)
1612 struct symbol
*ctype
, *member
;
1613 struct expression
*deref
= expr
->deref
, *add
;
1614 struct ident
*ident
= expr
->member
;
1618 if (!evaluate_expression(deref
))
1621 sparse_error(expr
->pos
, "bad member name");
1625 ctype
= deref
->ctype
;
1626 address_space
= ctype
->ctype
.as
;
1627 mod
= ctype
->ctype
.modifiers
;
1628 if (ctype
->type
== SYM_NODE
) {
1629 ctype
= ctype
->ctype
.base_type
;
1630 address_space
|= ctype
->ctype
.as
;
1631 mod
|= ctype
->ctype
.modifiers
;
1633 if (!ctype
|| (ctype
->type
!= SYM_STRUCT
&& ctype
->type
!= SYM_UNION
)) {
1634 sparse_error(expr
->pos
, "expected structure or union");
1637 examine_symbol_type(ctype
);
1639 member
= find_identifier(ident
, ctype
->symbol_list
, &offset
);
1641 const char *type
= ctype
->type
== SYM_STRUCT
? "struct" : "union";
1642 const char *name
= "<unnamed>";
1645 name
= ctype
->ident
->name
;
1646 namelen
= ctype
->ident
->len
;
1648 sparse_error(expr
->pos
, "no member '%s' in %s %.*s",
1649 show_ident(ident
), type
, namelen
, name
);
1654 * The member needs to take on the address space and modifiers of
1655 * the "parent" type.
1657 member
= convert_to_as_mod(member
, address_space
, mod
);
1658 ctype
= get_base_type(member
);
1660 if (!lvalue_expression(deref
)) {
1661 if (deref
->type
!= EXPR_SLICE
) {
1665 expr
->base
= deref
->base
;
1666 expr
->r_bitpos
= deref
->r_bitpos
;
1668 expr
->r_bitpos
+= offset
<< 3;
1669 expr
->type
= EXPR_SLICE
;
1670 expr
->r_nrbits
= member
->bit_size
;
1671 expr
->r_bitpos
+= member
->bit_offset
;
1672 expr
->ctype
= member
;
1676 deref
= deref
->unop
;
1677 expr
->deref
= deref
;
1679 add
= evaluate_offset(deref
, offset
);
1680 expr
->type
= EXPR_PREOP
;
1684 expr
->ctype
= member
;
1688 static int is_promoted(struct expression
*expr
)
1691 switch (expr
->type
) {
1694 case EXPR_CONDITIONAL
:
1718 static struct symbol
*evaluate_cast(struct expression
*);
1720 static struct symbol
*evaluate_type_information(struct expression
*expr
)
1722 struct symbol
*sym
= expr
->cast_type
;
1724 sym
= evaluate_expression(expr
->cast_expression
);
1728 * Expressions of restricted types will possibly get
1729 * promoted - check that here
1731 if (is_restricted_type(sym
)) {
1732 if (sym
->bit_size
< bits_in_int
&& is_promoted(expr
))
1736 examine_symbol_type(sym
);
1737 if (is_bitfield_type(sym
)) {
1738 sparse_error(expr
->pos
, "trying to examine bitfield type");
1744 static struct symbol
*evaluate_sizeof(struct expression
*expr
)
1746 struct symbol
*type
;
1749 type
= evaluate_type_information(expr
);
1753 size
= type
->bit_size
;
1754 if ((size
< 0) || (size
& 7))
1755 sparse_error(expr
->pos
, "cannot size expression");
1756 expr
->type
= EXPR_VALUE
;
1757 expr
->value
= size
>> 3;
1758 expr
->ctype
= size_t_ctype
;
1759 return size_t_ctype
;
1762 static struct symbol
*evaluate_ptrsizeof(struct expression
*expr
)
1764 struct symbol
*type
;
1767 type
= evaluate_type_information(expr
);
1771 if (type
->type
== SYM_NODE
)
1772 type
= type
->ctype
.base_type
;
1775 switch (type
->type
) {
1779 type
= get_base_type(type
);
1783 sparse_error(expr
->pos
, "expected pointer expression");
1786 size
= type
->bit_size
;
1789 expr
->type
= EXPR_VALUE
;
1790 expr
->value
= size
>> 3;
1791 expr
->ctype
= size_t_ctype
;
1792 return size_t_ctype
;
1795 static struct symbol
*evaluate_alignof(struct expression
*expr
)
1797 struct symbol
*type
;
1799 type
= evaluate_type_information(expr
);
1803 expr
->type
= EXPR_VALUE
;
1804 expr
->value
= type
->ctype
.alignment
;
1805 expr
->ctype
= size_t_ctype
;
1806 return size_t_ctype
;
1809 static int evaluate_arguments(struct symbol
*f
, struct symbol
*fn
, struct expression_list
*head
)
1811 struct expression
*expr
;
1812 struct symbol_list
*argument_types
= fn
->arguments
;
1813 struct symbol
*argtype
;
1816 PREPARE_PTR_LIST(argument_types
, argtype
);
1817 FOR_EACH_PTR (head
, expr
) {
1818 struct expression
**p
= THIS_ADDRESS(expr
);
1819 struct symbol
*ctype
, *target
;
1820 ctype
= evaluate_expression(expr
);
1825 ctype
= degenerate(expr
);
1828 if (!target
&& ctype
->bit_size
< bits_in_int
)
1829 target
= &int_ctype
;
1831 static char where
[30];
1832 examine_symbol_type(target
);
1833 sprintf(where
, "argument %d", i
);
1834 compatible_assignment_types(expr
, target
, p
, ctype
, where
, '=');
1838 NEXT_PTR_LIST(argtype
);
1839 } END_FOR_EACH_PTR(expr
);
1840 FINISH_PTR_LIST(argtype
);
1844 static void evaluate_initializer(struct symbol
*ctype
, struct expression
**ep
);
1846 static int evaluate_one_array_initializer(struct symbol
*ctype
, struct expression
**ep
, int current
)
1848 struct expression
*entry
= *ep
;
1849 struct expression
**parent
, *reuse
= NULL
;
1850 unsigned long offset
;
1852 unsigned long from
, to
;
1853 int accept_string
= is_byte_type(ctype
);
1858 if (entry
->type
== EXPR_INDEX
) {
1859 from
= entry
->idx_from
;
1860 to
= entry
->idx_to
+1;
1861 parent
= &entry
->idx_expression
;
1863 entry
= entry
->idx_expression
;
1866 offset
= from
* (ctype
->bit_size
>>3);
1868 if (!reuse
) reuse
= alloc_expression(entry
->pos
, EXPR_POS
);
1869 reuse
->type
= EXPR_POS
;
1870 reuse
->ctype
= ctype
;
1871 reuse
->init_offset
= offset
;
1872 reuse
->init_nr
= to
- from
;
1873 reuse
->init_expr
= entry
;
1874 parent
= &reuse
->init_expr
;
1879 if (accept_string
&& entry
->type
== EXPR_STRING
) {
1880 sym
= evaluate_expression(entry
);
1881 to
= from
+ get_expression_value(sym
->array_size
);
1883 evaluate_initializer(ctype
, parent
);
1888 static void evaluate_array_initializer(struct symbol
*ctype
, struct expression
*expr
)
1890 struct expression
*entry
;
1893 FOR_EACH_PTR(expr
->expr_list
, entry
) {
1894 current
= evaluate_one_array_initializer(ctype
, THIS_ADDRESS(entry
), current
);
1895 } END_FOR_EACH_PTR(entry
);
1898 /* A scalar initializer is allowed, and acts pretty much like an array of one */
1899 static void evaluate_scalar_initializer(struct symbol
*ctype
, struct expression
*expr
)
1901 if (expression_list_size(expr
->expr_list
) != 1) {
1902 sparse_error(expr
->pos
, "unexpected compound initializer");
1905 evaluate_array_initializer(ctype
, expr
);
1909 static struct symbol
*find_struct_ident(struct symbol
*ctype
, struct ident
*ident
)
1913 FOR_EACH_PTR(ctype
->symbol_list
, sym
) {
1914 if (sym
->ident
== ident
)
1916 } END_FOR_EACH_PTR(sym
);
1920 static int evaluate_one_struct_initializer(struct symbol
*ctype
, struct expression
**ep
, struct symbol
*sym
)
1922 struct expression
*entry
= *ep
;
1923 struct expression
**parent
;
1924 struct expression
*reuse
= NULL
;
1925 unsigned long offset
;
1928 sparse_error(entry
->pos
, "unknown named initializer");
1932 if (entry
->type
== EXPR_IDENTIFIER
) {
1934 entry
= entry
->ident_expression
;
1938 offset
= sym
->offset
;
1941 reuse
= alloc_expression(entry
->pos
, EXPR_POS
);
1942 reuse
->type
= EXPR_POS
;
1944 reuse
->init_offset
= offset
;
1946 reuse
->init_expr
= entry
;
1947 parent
= &reuse
->init_expr
;
1951 evaluate_initializer(sym
, parent
);
1955 static void evaluate_struct_or_union_initializer(struct symbol
*ctype
, struct expression
*expr
, int multiple
)
1957 struct expression
*entry
;
1960 PREPARE_PTR_LIST(ctype
->symbol_list
, sym
);
1961 FOR_EACH_PTR(expr
->expr_list
, entry
) {
1962 if (entry
->type
== EXPR_IDENTIFIER
) {
1963 struct ident
*ident
= entry
->expr_ident
;
1964 /* We special-case the "already right place" case */
1965 if (!sym
|| sym
->ident
!= ident
) {
1966 RESET_PTR_LIST(sym
);
1970 if (sym
->ident
== ident
)
1976 if (evaluate_one_struct_initializer(ctype
, THIS_ADDRESS(entry
), sym
))
1979 } END_FOR_EACH_PTR(entry
);
1980 FINISH_PTR_LIST(sym
);
1984 * Initializers are kind of like assignments. Except
1985 * they can be a hell of a lot more complex.
1987 static void evaluate_initializer(struct symbol
*ctype
, struct expression
**ep
)
1989 struct expression
*expr
= *ep
;
1992 * Simple non-structure/array initializers are the simple
1993 * case, and look (and parse) largely like assignments.
1995 switch (expr
->type
) {
1997 int is_string
= expr
->type
== EXPR_STRING
;
1998 struct symbol
*rtype
= evaluate_expression(expr
);
2002 * char array[] = "string"
2003 * should _not_ degenerate.
2005 if (!is_string
|| !is_string_type(ctype
))
2006 rtype
= degenerate(expr
);
2007 compatible_assignment_types(expr
, ctype
, ep
, rtype
, "initializer", '=');
2012 case EXPR_INITIALIZER
:
2013 expr
->ctype
= ctype
;
2014 if (ctype
->type
== SYM_NODE
)
2015 ctype
= ctype
->ctype
.base_type
;
2017 switch (ctype
->type
) {
2020 evaluate_array_initializer(get_base_type(ctype
), expr
);
2023 evaluate_struct_or_union_initializer(ctype
, expr
, 0);
2026 evaluate_struct_or_union_initializer(ctype
, expr
, 1);
2029 evaluate_scalar_initializer(ctype
, expr
);
2033 case EXPR_IDENTIFIER
:
2034 if (ctype
->type
== SYM_NODE
)
2035 ctype
= ctype
->ctype
.base_type
;
2036 if (ctype
->type
!= SYM_STRUCT
&& ctype
->type
!= SYM_UNION
) {
2037 sparse_error(expr
->pos
, "expected structure or union for '%s' dereference", show_ident(expr
->expr_ident
));
2041 evaluate_one_struct_initializer(ctype
, ep
,
2042 find_struct_ident(ctype
, expr
->expr_ident
));
2046 if (ctype
->type
== SYM_NODE
)
2047 ctype
= ctype
->ctype
.base_type
;
2048 if (ctype
->type
!= SYM_ARRAY
) {
2049 sparse_error(expr
->pos
, "expected array");
2052 evaluate_one_array_initializer(ctype
->ctype
.base_type
, ep
, 0);
2057 * An EXPR_POS expression has already been evaluated, and we don't
2058 * need to do anything more
2064 static int get_as(struct symbol
*sym
)
2072 mod
= sym
->ctype
.modifiers
;
2073 if (sym
->type
== SYM_NODE
) {
2074 sym
= sym
->ctype
.base_type
;
2075 as
|= sym
->ctype
.as
;
2076 mod
|= sym
->ctype
.modifiers
;
2080 * At least for now, allow casting to a "unsigned long".
2081 * That's how we do things like pointer arithmetic and
2082 * store pointers to registers.
2084 if (sym
== &ulong_ctype
)
2087 if (sym
&& sym
->type
== SYM_PTR
) {
2088 sym
= get_base_type(sym
);
2089 as
|= sym
->ctype
.as
;
2090 mod
|= sym
->ctype
.modifiers
;
2092 if (mod
& MOD_FORCE
)
2097 static void cast_to_as(struct expression
*e
, int as
)
2099 struct expression
*v
= e
->cast_expression
;
2101 if (!Wcast_to_address_space
)
2104 /* cast from constant 0 to pointer is OK */
2105 if (v
->type
== EXPR_VALUE
&& is_int_type(v
->ctype
) && !v
->value
)
2108 warning(e
->pos
, "cast adds address space to expression (<asn:%d>)", as
);
2111 static struct symbol
*evaluate_cast(struct expression
*expr
)
2113 struct expression
*target
= expr
->cast_expression
;
2114 struct symbol
*ctype
= examine_symbol_type(expr
->cast_type
);
2115 struct symbol
*t1
, *t2
;
2116 enum type type1
, type2
;
2122 expr
->ctype
= ctype
;
2123 expr
->cast_type
= ctype
;
2126 * Special case: a cast can be followed by an
2127 * initializer, in which case we need to pass
2128 * the type value down to that initializer rather
2129 * than trying to evaluate it as an expression
2131 * A more complex case is when the initializer is
2132 * dereferenced as part of a post-fix expression.
2133 * We need to produce an expression that can be dereferenced.
2135 if (target
->type
== EXPR_INITIALIZER
) {
2136 struct symbol
*sym
= expr
->cast_type
;
2137 struct expression
*addr
= alloc_expression(expr
->pos
, EXPR_SYMBOL
);
2139 sym
->initializer
= expr
->cast_expression
;
2140 evaluate_symbol(sym
);
2142 addr
->ctype
= &lazy_ptr_ctype
; /* Lazy eval */
2145 expr
->type
= EXPR_PREOP
;
2153 evaluate_expression(target
);
2157 if (t1
->type
== SYM_NODE
)
2158 t1
= t1
->ctype
.base_type
;
2159 if (t1
->type
== SYM_ENUM
)
2160 t1
= t1
->ctype
.base_type
;
2163 * You can always throw a value away by casting to
2164 * "void" - that's an implicit "force". Note that
2165 * the same is _not_ true of "void *".
2167 if (t1
== &void_ctype
)
2171 if (type1
== SYM_ARRAY
|| type1
== SYM_UNION
|| type1
== SYM_STRUCT
)
2172 warning(expr
->pos
, "cast to non-scalar");
2176 sparse_error(expr
->pos
, "cast from unknown type");
2179 if (t2
->type
== SYM_NODE
)
2180 t2
= t2
->ctype
.base_type
;
2181 if (t2
->type
== SYM_ENUM
)
2182 t2
= t2
->ctype
.base_type
;
2185 if (type2
== SYM_ARRAY
|| type2
== SYM_UNION
|| type2
== SYM_STRUCT
)
2186 warning(expr
->pos
, "cast from non-scalar");
2188 if (!(ctype
->ctype
.modifiers
& MOD_FORCE
) && t1
!= t2
) {
2189 if (t1
->type
== SYM_RESTRICT
)
2190 warning(expr
->pos
, "cast to restricted type");
2191 if (t2
->type
== SYM_RESTRICT
)
2192 warning(expr
->pos
, "cast from restricted type");
2195 as1
= get_as(ctype
);
2196 as2
= get_as(target
->ctype
);
2197 if (!as1
&& as2
> 0)
2198 warning(expr
->pos
, "cast removes address space of expression");
2199 if (as1
> 0 && as2
> 0 && as1
!= as2
)
2200 warning(expr
->pos
, "cast between address spaces (<asn:%d>-><asn:%d>)", as2
, as1
);
2201 if (as1
> 0 && !as2
)
2202 cast_to_as(expr
, as1
);
2205 * Casts of constant values are special: they
2206 * can be NULL, and thus need to be simplified
2209 if (target
->type
== EXPR_VALUE
)
2210 cast_value(expr
, ctype
, target
, target
->ctype
);
2217 * Evaluate a call expression with a symbol. This
2218 * should expand inline functions, and evaluate
2221 static int evaluate_symbol_call(struct expression
*expr
)
2223 struct expression
*fn
= expr
->fn
;
2224 struct symbol
*ctype
= fn
->ctype
;
2226 if (fn
->type
!= EXPR_PREOP
)
2229 if (ctype
->op
&& ctype
->op
->evaluate
)
2230 return ctype
->op
->evaluate(expr
);
2232 if (ctype
->ctype
.modifiers
& MOD_INLINE
) {
2234 struct symbol
*curr
= current_fn
;
2235 current_fn
= ctype
->ctype
.base_type
;
2236 examine_fn_arguments(current_fn
);
2238 ret
= inline_function(expr
, ctype
);
2240 /* restore the old function */
2248 static struct symbol
*evaluate_call(struct expression
*expr
)
2251 struct symbol
*ctype
, *sym
;
2252 struct expression
*fn
= expr
->fn
;
2253 struct expression_list
*arglist
= expr
->args
;
2255 if (!evaluate_expression(fn
))
2257 sym
= ctype
= fn
->ctype
;
2258 if (ctype
->type
== SYM_NODE
)
2259 ctype
= ctype
->ctype
.base_type
;
2260 if (ctype
->type
== SYM_PTR
|| ctype
->type
== SYM_ARRAY
)
2261 ctype
= get_base_type(ctype
);
2262 if (!evaluate_arguments(sym
, ctype
, arglist
))
2264 if (ctype
->type
!= SYM_FN
) {
2265 sparse_error(expr
->pos
, "not a function %s", show_ident(sym
->ident
));
2268 args
= expression_list_size(expr
->args
);
2269 fnargs
= symbol_list_size(ctype
->arguments
);
2271 sparse_error(expr
->pos
, "not enough arguments for function %s", show_ident(sym
->ident
));
2272 if (args
> fnargs
&& !ctype
->variadic
)
2273 sparse_error(expr
->pos
, "too many arguments for function %s", show_ident(sym
->ident
));
2274 if (sym
->type
== SYM_NODE
) {
2275 if (evaluate_symbol_call(expr
))
2278 expr
->ctype
= ctype
->ctype
.base_type
;
2282 struct symbol
*evaluate_expression(struct expression
*expr
)
2289 switch (expr
->type
) {
2292 sparse_error(expr
->pos
, "value expression without a type");
2295 return evaluate_string(expr
);
2297 return evaluate_symbol_expression(expr
);
2299 if (!evaluate_expression(expr
->left
))
2301 if (!evaluate_expression(expr
->right
))
2303 return evaluate_binop(expr
);
2305 return evaluate_logical(expr
);
2307 evaluate_expression(expr
->left
);
2308 if (!evaluate_expression(expr
->right
))
2310 return evaluate_comma(expr
);
2312 if (!evaluate_expression(expr
->left
))
2314 if (!evaluate_expression(expr
->right
))
2316 return evaluate_compare(expr
);
2317 case EXPR_ASSIGNMENT
:
2318 if (!evaluate_expression(expr
->left
))
2320 if (!evaluate_expression(expr
->right
))
2322 return evaluate_assignment(expr
);
2324 if (!evaluate_expression(expr
->unop
))
2326 return evaluate_preop(expr
);
2328 if (!evaluate_expression(expr
->unop
))
2330 return evaluate_postop(expr
);
2332 case EXPR_IMPLIED_CAST
:
2333 return evaluate_cast(expr
);
2335 return evaluate_sizeof(expr
);
2336 case EXPR_PTRSIZEOF
:
2337 return evaluate_ptrsizeof(expr
);
2339 return evaluate_alignof(expr
);
2341 return evaluate_member_dereference(expr
);
2343 return evaluate_call(expr
);
2345 case EXPR_CONDITIONAL
:
2346 return evaluate_conditional_expression(expr
);
2347 case EXPR_STATEMENT
:
2348 expr
->ctype
= evaluate_statement(expr
->statement
);
2352 expr
->ctype
= &ptr_ctype
;
2356 /* Evaluate the type of the symbol .. */
2357 evaluate_symbol(expr
->symbol
);
2358 /* .. but the type of the _expression_ is a "type" */
2359 expr
->ctype
= &type_ctype
;
2362 /* These can not exist as stand-alone expressions */
2363 case EXPR_INITIALIZER
:
2364 case EXPR_IDENTIFIER
:
2367 sparse_error(expr
->pos
, "internal front-end error: initializer in expression");
2370 sparse_error(expr
->pos
, "internal front-end error: SLICE re-evaluated");
2376 static void check_duplicates(struct symbol
*sym
)
2379 struct symbol
*next
= sym
;
2381 while ((next
= next
->same_symbol
) != NULL
) {
2382 const char *typediff
;
2383 evaluate_symbol(next
);
2385 typediff
= type_difference(sym
, next
, 0, 0);
2387 sparse_error(sym
->pos
, "symbol '%s' redeclared with different type (originally declared at %s:%d) - %s",
2388 show_ident(sym
->ident
),
2389 stream_name(next
->pos
.stream
), next
->pos
.line
, typediff
);
2394 unsigned long mod
= sym
->ctype
.modifiers
;
2395 if (mod
& (MOD_STATIC
| MOD_REGISTER
))
2397 if (!(mod
& MOD_TOPLEVEL
))
2401 if (sym
->ident
== &main_ident
)
2403 warning(sym
->pos
, "symbol '%s' was not declared. Should it be static?", show_ident(sym
->ident
));
2407 static struct symbol
*evaluate_symbol(struct symbol
*sym
)
2409 struct symbol
*base_type
;
2417 sym
= examine_symbol_type(sym
);
2418 base_type
= get_base_type(sym
);
2422 /* Evaluate the initializers */
2423 if (sym
->initializer
)
2424 evaluate_initializer(sym
, &sym
->initializer
);
2426 /* And finally, evaluate the body of the symbol too */
2427 if (base_type
->type
== SYM_FN
) {
2428 struct symbol
*curr
= current_fn
;
2430 current_fn
= base_type
;
2432 examine_fn_arguments(base_type
);
2433 if (!base_type
->stmt
&& base_type
->inline_stmt
)
2435 if (base_type
->stmt
)
2436 evaluate_statement(base_type
->stmt
);
2444 void evaluate_symbol_list(struct symbol_list
*list
)
2448 FOR_EACH_PTR(list
, sym
) {
2449 check_duplicates(sym
);
2450 evaluate_symbol(sym
);
2451 } END_FOR_EACH_PTR(sym
);
2454 static struct symbol
*evaluate_return_expression(struct statement
*stmt
)
2456 struct expression
*expr
= stmt
->expression
;
2457 struct symbol
*ctype
, *fntype
;
2459 evaluate_expression(expr
);
2460 ctype
= degenerate(expr
);
2461 fntype
= current_fn
->ctype
.base_type
;
2462 if (!fntype
|| fntype
== &void_ctype
) {
2463 if (expr
&& ctype
!= &void_ctype
)
2464 sparse_error(expr
->pos
, "return expression in %s function", fntype
?"void":"typeless");
2469 sparse_error(stmt
->pos
, "return with no return value");
2474 compatible_assignment_types(expr
, fntype
, &stmt
->expression
, ctype
, "return expression", '=');
2478 static void evaluate_if_statement(struct statement
*stmt
)
2480 if (!stmt
->if_conditional
)
2483 evaluate_conditional(stmt
->if_conditional
, 0);
2484 evaluate_statement(stmt
->if_true
);
2485 evaluate_statement(stmt
->if_false
);
2488 static void evaluate_iterator(struct statement
*stmt
)
2490 evaluate_conditional(stmt
->iterator_pre_condition
, 1);
2491 evaluate_conditional(stmt
->iterator_post_condition
,1);
2492 evaluate_statement(stmt
->iterator_pre_statement
);
2493 evaluate_statement(stmt
->iterator_statement
);
2494 evaluate_statement(stmt
->iterator_post_statement
);
2497 static void verify_output_constraint(struct expression
*expr
, const char *constraint
)
2499 switch (*constraint
) {
2500 case '=': /* Assignment */
2501 case '+': /* Update */
2504 sparse_error(expr
->pos
, "output constraint is not an assignment constraint (\"%s\")", constraint
);
2508 static void verify_input_constraint(struct expression
*expr
, const char *constraint
)
2510 switch (*constraint
) {
2511 case '=': /* Assignment */
2512 case '+': /* Update */
2513 sparse_error(expr
->pos
, "input constraint with assignment (\"%s\")", constraint
);
2517 static void evaluate_asm_statement(struct statement
*stmt
)
2519 struct expression
*expr
;
2522 expr
= stmt
->asm_string
;
2523 if (!expr
|| expr
->type
!= EXPR_STRING
) {
2524 sparse_error(stmt
->pos
, "need constant string for inline asm");
2529 FOR_EACH_PTR(stmt
->asm_outputs
, expr
) {
2530 struct ident
*ident
;
2533 case 0: /* Identifier */
2535 ident
= (struct ident
*)expr
;
2538 case 1: /* Constraint */
2540 if (!expr
|| expr
->type
!= EXPR_STRING
) {
2541 sparse_error(expr
? expr
->pos
: stmt
->pos
, "asm output constraint is not a string");
2542 *THIS_ADDRESS(expr
) = NULL
;
2545 verify_output_constraint(expr
, expr
->string
->data
);
2548 case 2: /* Expression */
2550 if (!evaluate_expression(expr
))
2552 if (!lvalue_expression(expr
))
2553 warning(expr
->pos
, "asm output is not an lvalue");
2554 evaluate_assign_to(expr
, expr
->ctype
);
2557 } END_FOR_EACH_PTR(expr
);
2560 FOR_EACH_PTR(stmt
->asm_inputs
, expr
) {
2561 struct ident
*ident
;
2564 case 0: /* Identifier */
2566 ident
= (struct ident
*)expr
;
2569 case 1: /* Constraint */
2571 if (!expr
|| expr
->type
!= EXPR_STRING
) {
2572 sparse_error(expr
? expr
->pos
: stmt
->pos
, "asm input constraint is not a string");
2573 *THIS_ADDRESS(expr
) = NULL
;
2576 verify_input_constraint(expr
, expr
->string
->data
);
2579 case 2: /* Expression */
2581 if (!evaluate_expression(expr
))
2585 } END_FOR_EACH_PTR(expr
);
2587 FOR_EACH_PTR(stmt
->asm_clobbers
, expr
) {
2589 sparse_error(stmt
->pos
, "bad asm output");
2592 if (expr
->type
== EXPR_STRING
)
2594 sparse_error(expr
->pos
, "asm clobber is not a string");
2595 } END_FOR_EACH_PTR(expr
);
2598 static void evaluate_case_statement(struct statement
*stmt
)
2600 evaluate_expression(stmt
->case_expression
);
2601 evaluate_expression(stmt
->case_to
);
2602 evaluate_statement(stmt
->case_statement
);
2605 static void check_case_type(struct expression
*switch_expr
, struct expression
*case_expr
)
2607 struct symbol
*switch_type
, *case_type
;
2610 switch_type
= switch_expr
->ctype
;
2611 case_type
= evaluate_expression(case_expr
);
2613 if (case_type
&& switch_type
) {
2614 /* Both integer types? */
2615 if (is_int_type(switch_type
) && is_int_type(case_type
))
2617 if (compatible_restricted_binop(SPECIAL_EQUAL
, &switch_expr
, &case_expr
))
2621 sparse_error(case_expr
->pos
, "incompatible types for 'case' statement");
2624 static void evaluate_switch_statement(struct statement
*stmt
)
2628 evaluate_expression(stmt
->switch_expression
);
2629 evaluate_statement(stmt
->switch_statement
);
2630 if (!stmt
->switch_expression
)
2632 FOR_EACH_PTR(stmt
->switch_case
->symbol_list
, sym
) {
2633 struct statement
*case_stmt
= sym
->stmt
;
2634 check_case_type(stmt
->switch_expression
, case_stmt
->case_expression
);
2635 check_case_type(stmt
->switch_expression
, case_stmt
->case_to
);
2636 } END_FOR_EACH_PTR(sym
);
2639 struct symbol
*evaluate_statement(struct statement
*stmt
)
2644 switch (stmt
->type
) {
2646 return evaluate_return_expression(stmt
);
2648 case STMT_EXPRESSION
:
2649 if (!evaluate_expression(stmt
->expression
))
2651 return degenerate(stmt
->expression
);
2653 case STMT_COMPOUND
: {
2654 struct statement
*s
;
2655 struct symbol
*type
= NULL
;
2658 /* Evaluate each symbol in the compound statement */
2659 FOR_EACH_PTR(stmt
->syms
, sym
) {
2660 evaluate_symbol(sym
);
2661 } END_FOR_EACH_PTR(sym
);
2662 evaluate_symbol(stmt
->ret
);
2665 * Then, evaluate each statement, making the type of the
2666 * compound statement be the type of the last statement
2669 FOR_EACH_PTR(stmt
->stmts
, s
) {
2670 type
= evaluate_statement(s
);
2671 } END_FOR_EACH_PTR(s
);
2677 evaluate_if_statement(stmt
);
2680 evaluate_iterator(stmt
);
2683 evaluate_switch_statement(stmt
);
2686 evaluate_case_statement(stmt
);
2689 return evaluate_statement(stmt
->label_statement
);
2691 evaluate_expression(stmt
->goto_expression
);
2696 evaluate_asm_statement(stmt
);
2699 evaluate_expression(stmt
->expression
);
2702 evaluate_expression(stmt
->range_expression
);
2703 evaluate_expression(stmt
->range_low
);
2704 evaluate_expression(stmt
->range_high
);