1987-03-10 17:51:10 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1986-03-10 13:07:55 +00:00
|
|
|
/* SEMANTIC ANALYSIS (CHAPTER 7RM) -- MONADIC OPERATORS */
|
|
|
|
|
1987-01-24 00:25:56 +00:00
|
|
|
#include "botch_free.h"
|
|
|
|
#include <alloc.h>
|
1986-09-24 13:53:16 +00:00
|
|
|
#include "nofloat.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
#include "nobitfield.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "arith.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "label.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "def.h"
|
|
|
|
|
|
|
|
extern char options[];
|
1986-09-09 09:47:43 +00:00
|
|
|
extern long full_mask[/*MAXSIZE*/]; /* cstoper.c */
|
1986-03-10 13:07:55 +00:00
|
|
|
char *symbol2str();
|
|
|
|
|
|
|
|
ch7mon(oper, expp)
|
|
|
|
register struct expr **expp;
|
|
|
|
{
|
|
|
|
/* The monadic prefix operator oper is applied to *expp.
|
|
|
|
*/
|
|
|
|
register struct expr *expr;
|
|
|
|
|
|
|
|
switch (oper) {
|
|
|
|
case '*': /* RM 7.2 */
|
|
|
|
/* no FIELD type allowed */
|
|
|
|
if ((*expp)->ex_type->tp_fund == ARRAY)
|
1987-03-25 23:14:43 +00:00
|
|
|
array2pointer(*expp);
|
1986-03-10 13:07:55 +00:00
|
|
|
if ((*expp)->ex_type->tp_fund != POINTER) {
|
1986-03-27 18:17:48 +00:00
|
|
|
expr_error(*expp,
|
|
|
|
"* applied to non-pointer (%s)",
|
|
|
|
symbol2str((*expp)->ex_type->tp_fund));
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
expr = *expp;
|
1989-01-23 15:37:57 +00:00
|
|
|
if (expr->ex_lvalue == 0 && expr->ex_class != String)
|
1986-03-10 13:07:55 +00:00
|
|
|
/* dereference in administration only */
|
|
|
|
expr->ex_type = expr->ex_type->tp_up;
|
|
|
|
else /* runtime code */
|
|
|
|
*expp = new_oper(expr->ex_type->tp_up, NILEXPR,
|
|
|
|
'*', expr);
|
|
|
|
(*expp)->ex_lvalue = (
|
|
|
|
(*expp)->ex_type->tp_fund != ARRAY &&
|
|
|
|
(*expp)->ex_type->tp_fund != FUNCTION);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '&':
|
1986-04-03 11:33:32 +00:00
|
|
|
if ((*expp)->ex_type->tp_fund == ARRAY) {
|
1989-05-29 11:32:23 +00:00
|
|
|
expr_warning(*expp, "& before array ignored");
|
1987-03-25 23:14:43 +00:00
|
|
|
array2pointer(*expp);
|
1986-04-03 11:33:32 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
1986-04-03 11:33:32 +00:00
|
|
|
if ((*expp)->ex_type->tp_fund == FUNCTION) {
|
1989-05-29 11:32:23 +00:00
|
|
|
expr_warning(*expp, "& before function ignored");
|
1987-03-25 23:14:43 +00:00
|
|
|
function2pointer(*expp);
|
1986-04-03 11:33:32 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
|
|
|
#ifndef NOBITFIELD
|
1986-04-03 11:33:32 +00:00
|
|
|
if ((*expp)->ex_type->tp_fund == FIELD)
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_error(*expp, "& applied to field variable");
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOBITFIELD */
|
1986-04-03 11:33:32 +00:00
|
|
|
if (!(*expp)->ex_lvalue)
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_error(*expp, "& applied to non-lvalue");
|
1986-03-10 13:07:55 +00:00
|
|
|
else {
|
|
|
|
/* assume that enums are already filtered out */
|
1989-02-02 13:57:07 +00:00
|
|
|
if (ISNAME(*expp)) {
|
1986-03-10 13:07:55 +00:00
|
|
|
register struct def *def =
|
|
|
|
(*expp)->VL_IDF->id_def;
|
|
|
|
|
1986-04-02 08:37:17 +00:00
|
|
|
/* &<var> indicates that <var>
|
|
|
|
cannot be used as register
|
|
|
|
anymore
|
1986-03-10 13:07:55 +00:00
|
|
|
*/
|
|
|
|
if (def->df_sc == REGISTER) {
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_error(*expp,
|
1986-03-17 17:47:04 +00:00
|
|
|
"& on register variable not allowed");
|
1986-03-10 13:07:55 +00:00
|
|
|
break; /* break case '&' */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(*expp)->ex_type = pointer_to((*expp)->ex_type);
|
|
|
|
(*expp)->ex_lvalue = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '~':
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
int fund = (*expp)->ex_type->tp_fund;
|
|
|
|
|
|
|
|
if (fund == FLOAT || fund == DOUBLE) {
|
1986-04-03 11:33:32 +00:00
|
|
|
expr_error(
|
|
|
|
*expp,
|
|
|
|
"~ not allowed on %s operands",
|
|
|
|
symbol2str(fund)
|
|
|
|
);
|
1986-03-14 16:15:16 +00:00
|
|
|
erroneous2int(expp);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
}
|
1986-09-09 09:47:43 +00:00
|
|
|
/* FALLTHROUGH */
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOFLOAT */
|
1986-03-10 13:07:55 +00:00
|
|
|
case '-':
|
|
|
|
any2arith(expp, oper);
|
|
|
|
if (is_cp_cst(*expp)) {
|
|
|
|
arith o1 = (*expp)->VL_VALUE;
|
1986-09-09 09:47:43 +00:00
|
|
|
|
1989-05-31 12:42:56 +00:00
|
|
|
o1 = (oper == '-') ? -o1 : ~o1;
|
|
|
|
(*expp)->VL_VALUE =
|
1986-09-09 09:47:43 +00:00
|
|
|
((*expp)->ex_type->tp_unsigned ?
|
1989-05-31 12:42:56 +00:00
|
|
|
o1 & full_mask[(*expp)->ex_type->tp_size] :
|
|
|
|
o1
|
1986-09-09 09:47:43 +00:00
|
|
|
);
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
if (is_fp_cst(*expp))
|
|
|
|
switch_sign_fp(*expp);
|
|
|
|
else
|
1991-12-17 14:11:15 +00:00
|
|
|
#endif /* NOFLOAT */
|
1986-03-17 17:47:04 +00:00
|
|
|
*expp = new_oper((*expp)->ex_type,
|
1986-04-03 11:33:32 +00:00
|
|
|
NILEXPR, oper, *expp);
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
case '!':
|
|
|
|
if ((*expp)->ex_type->tp_fund == FUNCTION)
|
1987-03-25 23:14:43 +00:00
|
|
|
function2pointer(*expp);
|
1986-03-10 13:07:55 +00:00
|
|
|
if ((*expp)->ex_type->tp_fund != POINTER)
|
|
|
|
any2arith(expp, oper);
|
|
|
|
opnd2test(expp, '!');
|
|
|
|
if (is_cp_cst(*expp)) {
|
1986-04-02 08:37:17 +00:00
|
|
|
(*expp)->VL_VALUE = !((*expp)->VL_VALUE);
|
1986-04-03 11:33:32 +00:00
|
|
|
(*expp)->ex_type = int_type; /* a cast ???(EB) */
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*expp = new_oper(int_type, NILEXPR, oper, *expp);
|
|
|
|
(*expp)->ex_flags |= EX_LOGICAL;
|
|
|
|
break;
|
|
|
|
case PLUSPLUS:
|
|
|
|
case MINMIN:
|
|
|
|
ch7incr(expp, oper);
|
|
|
|
break;
|
|
|
|
case SIZEOF:
|
1989-02-02 13:57:07 +00:00
|
|
|
if (ISNAME(*expp) && (*expp)->VL_IDF->id_def->df_formal_array)
|
1989-05-29 11:32:23 +00:00
|
|
|
expr_warning(*expp, "sizeof formal array %s is sizeof pointer!",
|
1986-03-10 13:07:55 +00:00
|
|
|
(*expp)->VL_IDF->id_text);
|
1989-02-06 19:06:55 +00:00
|
|
|
expr = intexpr((*expp)->ex_class == String ?
|
1988-12-12 14:21:45 +00:00
|
|
|
(arith)((*expp)->SG_LEN) :
|
|
|
|
size_of_type((*expp)->ex_type, "object"),
|
|
|
|
INT);
|
1986-12-01 10:00:23 +00:00
|
|
|
expr->ex_flags |= EX_SIZEOF;
|
1986-03-10 13:07:55 +00:00
|
|
|
free_expression(*expp);
|
|
|
|
*expp = expr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|