2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 /* $Id: ch7mon.c,v 3.24 1994/06/24 12:02:32 ceriel Exp $ */
6 /* SEMANTIC ANALYSIS (CHAPTER 7RM) -- MONADIC OPERATORS */
8 #include "botch_free.h"
11 #include "nobitfield.h"
20 extern char options[];
21 extern long full_mask[/*MAXSIZE*/]; /* cstoper.c */
25 register struct expr **expp;
27 /* The monadic prefix operator oper is applied to *expp.
29 register struct expr *expr;
32 case '*': /* RM 7.2 */
33 /* no FIELD type allowed */
34 if ((*expp)->ex_type->tp_fund == ARRAY)
36 if ((*expp)->ex_type->tp_fund != POINTER) {
38 "* applied to non-pointer (%s)",
39 symbol2str((*expp)->ex_type->tp_fund));
43 if (expr->ex_lvalue == 0 && expr->ex_class != String)
44 /* dereference in administration only */
45 expr->ex_type = expr->ex_type->tp_up;
46 else /* runtime code */
47 *expp = new_oper(expr->ex_type->tp_up, NILEXPR,
49 (*expp)->ex_lvalue = (
50 (*expp)->ex_type->tp_fund != ARRAY &&
51 (*expp)->ex_type->tp_fund != FUNCTION);
55 if ((*expp)->ex_type->tp_fund == ARRAY) {
56 expr_warning(*expp, "& before array ignored");
60 if ((*expp)->ex_type->tp_fund == FUNCTION) {
61 expr_warning(*expp, "& before function ignored");
62 function2pointer(*expp);
66 if ((*expp)->ex_type->tp_fund == FIELD)
67 expr_error(*expp, "& applied to field variable");
69 #endif /* NOBITFIELD */
70 if (!(*expp)->ex_lvalue)
71 expr_error(*expp, "& applied to non-lvalue");
73 /* assume that enums are already filtered out */
75 register struct def *def =
76 (*expp)->VL_IDF->id_def;
78 /* &<var> indicates that <var>
79 cannot be used as register
82 if (def->df_sc == REGISTER) {
84 "& on register variable not allowed");
85 break; /* break case '&' */
88 (*expp)->ex_type = pointer_to((*expp)->ex_type);
89 (*expp)->ex_lvalue = 0;
95 int fund = (*expp)->ex_type->tp_fund;
97 if (fund == FLOAT || fund == DOUBLE) {
100 "~ not allowed on %s operands",
110 any2arith(expp, oper);
111 if (is_cp_cst(*expp)) {
112 arith o1 = (*expp)->VL_VALUE;
114 o1 = (oper == '-') ? -o1 : ~o1;
116 ((*expp)->ex_type->tp_unsigned ?
117 o1 & full_mask[(*expp)->ex_type->tp_size] :
123 if (is_fp_cst(*expp))
124 switch_sign_fp(*expp);
127 *expp = new_oper((*expp)->ex_type,
128 NILEXPR, oper, *expp);
131 if ((*expp)->ex_type->tp_fund == FUNCTION)
132 function2pointer(*expp);
133 if ((*expp)->ex_type->tp_fund != POINTER)
134 any2arith(expp, oper);
135 opnd2test(expp, '!');
136 if (is_cp_cst(*expp)) {
137 (*expp)->VL_VALUE = !((*expp)->VL_VALUE);
138 (*expp)->ex_type = int_type; /* a cast ???(EB) */
141 *expp = new_oper(int_type, NILEXPR, oper, *expp);
142 (*expp)->ex_flags |= EX_LOGICAL;
149 if (ISNAME(*expp) && (*expp)->VL_IDF->id_def->df_formal_array)
150 expr_warning(*expp, "sizeof formal array %s is sizeof pointer!",
151 (*expp)->VL_IDF->id_text);
152 expr = intexpr((*expp)->ex_class == String ?
153 (arith)((*expp)->SG_LEN) :
154 size_of_type((*expp)->ex_type, "object"),
156 expr->ex_flags |= EX_SIZEOF;
157 free_expression(*expp);