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".
|
|
|
|
*/
|
1986-03-10 13:07:55 +00:00
|
|
|
/* $Header$ */
|
|
|
|
/* S E M A N T I C A N A L Y S I S -- C H A P T E R 7 RM */
|
|
|
|
|
1988-09-20 16:44:27 +00:00
|
|
|
#include "lint.h"
|
1986-09-24 13:53:16 +00:00
|
|
|
#include "nofloat.h"
|
1986-03-10 13:07:55 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "nobitfield.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "arith.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "struct.h"
|
|
|
|
#include "label.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "Lpars.h"
|
|
|
|
#include "assert.h"
|
|
|
|
|
|
|
|
extern char options[];
|
|
|
|
extern char *symbol2str();
|
|
|
|
|
|
|
|
/* Most expression-handling routines have a pointer to a
|
|
|
|
(struct type *) as first parameter. The object under the pointer
|
|
|
|
gets updated in the process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ch7sel(expp, oper, idf)
|
1987-03-25 23:14:43 +00:00
|
|
|
struct expr **expp;
|
1986-03-10 13:07:55 +00:00
|
|
|
struct idf *idf;
|
|
|
|
{
|
|
|
|
/* The selector idf is applied to *expp; oper may be '.' or
|
|
|
|
ARROW.
|
|
|
|
*/
|
1987-07-06 18:24:46 +00:00
|
|
|
register struct expr *exp;
|
|
|
|
register struct type *tp;
|
1986-03-10 13:07:55 +00:00
|
|
|
register struct sdef *sd;
|
|
|
|
|
1987-07-06 18:24:46 +00:00
|
|
|
any2opnd(expp, oper);
|
|
|
|
exp = *expp;
|
|
|
|
tp = exp->ex_type;
|
1986-03-10 13:07:55 +00:00
|
|
|
if (oper == ARROW) {
|
1987-08-06 14:19:06 +00:00
|
|
|
if (tp->tp_fund == POINTER &&
|
|
|
|
( tp->tp_up->tp_fund == STRUCT ||
|
|
|
|
tp->tp_up->tp_fund == UNION)) /* normal case */
|
1986-03-10 13:07:55 +00:00
|
|
|
tp = tp->tp_up;
|
|
|
|
else { /* constructions like "12->selector" and
|
|
|
|
"char c; c->selector"
|
|
|
|
*/
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
/* Allowed by RM 14.1 */
|
|
|
|
ch7cast(expp, CAST, pa_type);
|
|
|
|
sd = idf2sdef(idf, tp);
|
|
|
|
tp = sd->sd_stype;
|
|
|
|
break;
|
1987-08-06 14:19:06 +00:00
|
|
|
case POINTER:
|
|
|
|
break;
|
1986-03-10 13:07:55 +00:00
|
|
|
default:
|
1987-03-25 23:14:43 +00:00
|
|
|
expr_error(exp, "-> applied to %s",
|
1986-03-10 13:07:55 +00:00
|
|
|
symbol2str(tp->tp_fund));
|
|
|
|
case ERRONEOUS:
|
1987-03-25 23:14:43 +00:00
|
|
|
exp->ex_type = error_type;
|
1986-03-10 13:07:55 +00:00
|
|
|
return;
|
|
|
|
}
|
1987-08-06 14:19:06 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
} /* oper == ARROW */
|
|
|
|
else { /* oper == '.' */
|
|
|
|
/* filter out illegal expressions "non_lvalue.sel" */
|
1987-03-25 23:14:43 +00:00
|
|
|
if (!exp->ex_lvalue) {
|
|
|
|
expr_error(exp, "dot requires lvalue");
|
1986-03-10 13:07:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1987-03-25 23:14:43 +00:00
|
|
|
exp = *expp;
|
1986-03-10 13:07:55 +00:00
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case POINTER: /* for int *p; p->next = ... */
|
|
|
|
case STRUCT:
|
|
|
|
case UNION:
|
|
|
|
break;
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
/* warning will be given by idf2sdef() */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (!is_anon_idf(idf))
|
1987-03-25 23:14:43 +00:00
|
|
|
expr_error(exp, "selector %s applied to %s",
|
1986-03-10 13:07:55 +00:00
|
|
|
idf->id_text, symbol2str(tp->tp_fund));
|
|
|
|
case ERRONEOUS:
|
1987-03-25 23:14:43 +00:00
|
|
|
exp->ex_type = error_type;
|
1986-03-10 13:07:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sd = idf2sdef(idf, tp);
|
|
|
|
if (oper == '.') {
|
|
|
|
/* there are 3 cases in which the selection can be
|
|
|
|
performed compile-time:
|
|
|
|
I: n.sel (n either an identifier or a constant)
|
|
|
|
II: (e.s1).s2 (transformed into (e.(s1+s2)))
|
|
|
|
III: (e->s1).s2 (transformed into (e->(s1+s2)))
|
|
|
|
The code performing these conversions is
|
|
|
|
extremely obscure.
|
|
|
|
*/
|
1987-03-25 23:14:43 +00:00
|
|
|
if (exp->ex_class == Value) {
|
1986-03-10 13:07:55 +00:00
|
|
|
/* It is an object we know the address of; so
|
|
|
|
we can calculate the address of the
|
|
|
|
selected member
|
|
|
|
*/
|
1987-03-25 23:14:43 +00:00
|
|
|
exp->VL_VALUE += sd->sd_offset;
|
|
|
|
exp->ex_type = sd->sd_type;
|
|
|
|
if (exp->ex_type == error_type)
|
|
|
|
exp->ex_flags |= EX_ERROR;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else
|
1987-03-25 23:14:43 +00:00
|
|
|
if (exp->ex_class == Oper) {
|
|
|
|
struct oper *op = &(exp->ex_object.ex_oper);
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
if (op->op_oper == '.' || op->op_oper == ARROW) {
|
1986-04-02 08:37:17 +00:00
|
|
|
ASSERT(is_cp_cst(op->op_right));
|
1986-03-10 13:07:55 +00:00
|
|
|
op->op_right->VL_VALUE += sd->sd_offset;
|
1987-03-25 23:14:43 +00:00
|
|
|
exp->ex_type = sd->sd_type;
|
|
|
|
if (exp->ex_type == error_type)
|
|
|
|
exp->ex_flags |= EX_ERROR;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else
|
1987-03-25 23:14:43 +00:00
|
|
|
exp = new_oper(sd->sd_type, exp, '.',
|
1986-03-10 13:07:55 +00:00
|
|
|
intexpr(sd->sd_offset, INT));
|
|
|
|
}
|
|
|
|
}
|
1986-09-29 14:01:34 +00:00
|
|
|
else /* oper == ARROW */
|
1987-03-25 23:14:43 +00:00
|
|
|
exp = new_oper(sd->sd_type,
|
|
|
|
exp, oper, intexpr(sd->sd_offset, INT));
|
|
|
|
exp->ex_lvalue = (sd->sd_type->tp_fund != ARRAY);
|
|
|
|
*expp = exp;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ch7incr(expp, oper)
|
1986-12-01 10:00:23 +00:00
|
|
|
struct expr **expp;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
/* The monadic prefix/postfix incr/decr operator oper is
|
|
|
|
applied to *expp.
|
|
|
|
*/
|
1986-09-29 14:01:34 +00:00
|
|
|
ch7asgn(expp, oper, intexpr((arith)1, INT));
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ch7cast(expp, oper, tp)
|
|
|
|
register struct expr **expp;
|
|
|
|
register struct type *tp;
|
|
|
|
{
|
|
|
|
/* The expression *expp is cast to type tp; the cast is
|
|
|
|
caused by the operator oper. If the cast has
|
|
|
|
to be passed on to run time, its left operand will be an
|
|
|
|
expression of class Type.
|
|
|
|
*/
|
|
|
|
register struct type *oldtp;
|
|
|
|
|
|
|
|
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 == ARRAY)
|
1987-03-25 23:14:43 +00:00
|
|
|
array2pointer(*expp);
|
1986-04-02 08:37:17 +00:00
|
|
|
if ((*expp)->ex_class == String)
|
1987-03-25 23:14:43 +00:00
|
|
|
string2pointer(*expp);
|
1986-03-10 13:07:55 +00:00
|
|
|
oldtp = (*expp)->ex_type;
|
1988-09-29 15:24:02 +00:00
|
|
|
|
1986-03-10 13:07:55 +00:00
|
|
|
#ifndef NOBITFIELD
|
|
|
|
if (oldtp->tp_fund == FIELD) {
|
|
|
|
field2arith(expp);
|
|
|
|
ch7cast(expp, oper, tp);
|
|
|
|
}
|
|
|
|
else
|
1988-09-29 15:24:02 +00:00
|
|
|
if (tp->tp_fund == FIELD) {
|
1986-03-10 13:07:55 +00:00
|
|
|
ch7cast(expp, oper, tp->tp_up);
|
1988-09-29 15:24:02 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
|
|
|
#endif NOBITFIELD
|
1988-09-29 15:24:02 +00:00
|
|
|
if (oldtp == tp) {
|
|
|
|
/* life is easy */
|
|
|
|
}
|
1986-08-13 10:05:39 +00:00
|
|
|
else
|
1988-09-29 15:24:02 +00:00
|
|
|
if (tp->tp_fund == VOID) {
|
|
|
|
/* Easy again */
|
1986-03-10 13:07:55 +00:00
|
|
|
(*expp)->ex_type = void_type;
|
1988-09-29 15:24:02 +00:00
|
|
|
}
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
|
|
|
if (is_arith_type(oldtp) && is_arith_type(tp)) {
|
|
|
|
int oldi = is_integral_type(oldtp);
|
|
|
|
int i = is_integral_type(tp);
|
|
|
|
|
|
|
|
if (oldi && i) {
|
1988-09-30 16:43:04 +00:00
|
|
|
if ( oper != CAST
|
|
|
|
&& ( tp->tp_fund == ENUM
|
|
|
|
|| oldtp->tp_fund == ENUM
|
|
|
|
)
|
|
|
|
) {
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp,
|
1988-09-30 16:43:04 +00:00
|
|
|
"dubious %s on enum",
|
1986-03-15 18:16:30 +00:00
|
|
|
symbol2str(oper));
|
1988-09-30 16:43:04 +00:00
|
|
|
}
|
1988-09-29 15:24:02 +00:00
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
|
|
|
(*expp)->ex_type = tp;
|
|
|
|
else
|
|
|
|
int2int(expp, tp);
|
|
|
|
#else LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
int2int(expp, tp);
|
1988-09-29 15:24:02 +00:00
|
|
|
#endif LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
|
|
|
if (oldi && !i) {
|
|
|
|
if (oldtp->tp_fund == ENUM && oper != CAST)
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp,
|
|
|
|
"conversion of enum to %s\n",
|
|
|
|
symbol2str(tp->tp_fund));
|
1988-09-29 15:24:02 +00:00
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
|
|
|
(*expp)->ex_type = tp;
|
|
|
|
else
|
|
|
|
int2float(expp, tp);
|
|
|
|
#else LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
int2float(expp, tp);
|
1988-09-29 15:24:02 +00:00
|
|
|
#endif LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else
|
1988-09-29 15:24:02 +00:00
|
|
|
if (!oldi && i) {
|
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
|
|
|
(*expp)->ex_type = tp;
|
|
|
|
else
|
|
|
|
float2int(expp, tp);
|
|
|
|
#else LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
float2int(expp, tp);
|
1988-09-29 15:24:02 +00:00
|
|
|
#endif LINT
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* !oldi && !i */
|
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
|
|
|
(*expp)->ex_type = tp;
|
|
|
|
else
|
|
|
|
float2float(expp, tp);
|
|
|
|
#else LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
float2float(expp, tp);
|
1988-09-29 15:24:02 +00:00
|
|
|
#endif LINT
|
|
|
|
}
|
1986-09-12 09:16:07 +00:00
|
|
|
#else NOFLOAT
|
1988-09-16 23:19:50 +00:00
|
|
|
else {
|
1986-09-12 09:16:07 +00:00
|
|
|
crash("(ch7cast) floats not implemented\n");
|
1988-09-16 23:19:50 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) {
|
|
|
|
if (oper != CAST)
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp, "incompatible pointers in %s",
|
1986-03-10 13:07:55 +00:00
|
|
|
symbol2str(oper));
|
1988-09-20 16:44:27 +00:00
|
|
|
#ifdef LINT
|
|
|
|
if (oper == CAST)
|
|
|
|
lint_ptr_conv(oldtp->tp_up->tp_fund, tp->tp_up->tp_fund);
|
|
|
|
#endif LINT
|
1986-03-10 13:07:55 +00:00
|
|
|
(*expp)->ex_type = tp; /* free conversion */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (oldtp->tp_fund == POINTER && is_integral_type(tp)) {
|
|
|
|
/* from pointer to integral */
|
|
|
|
if (oper != CAST)
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp,
|
|
|
|
"illegal conversion of pointer to %s",
|
1986-03-10 13:07:55 +00:00
|
|
|
symbol2str(tp->tp_fund));
|
|
|
|
if (oldtp->tp_size > tp->tp_size)
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp,
|
|
|
|
"conversion of pointer to %s loses accuracy",
|
1986-03-10 13:07:55 +00:00
|
|
|
symbol2str(tp->tp_fund));
|
|
|
|
if (oldtp->tp_size != tp->tp_size)
|
|
|
|
int2int(expp, tp);
|
|
|
|
else
|
|
|
|
(*expp)->ex_type = tp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (tp->tp_fund == POINTER && is_integral_type(oldtp)) {
|
|
|
|
/* from integral to pointer */
|
|
|
|
switch (oper) {
|
|
|
|
case CAST:
|
|
|
|
break;
|
|
|
|
case EQUAL:
|
|
|
|
case NOTEQUAL:
|
|
|
|
case '=':
|
|
|
|
case RETURN:
|
1986-03-14 16:15:16 +00:00
|
|
|
if (is_cp_cst(*expp) && (*expp)->VL_VALUE == (arith)0)
|
1986-03-10 13:07:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp,
|
|
|
|
"illegal conversion of %s to pointer",
|
1986-03-10 13:07:55 +00:00
|
|
|
symbol2str(oldtp->tp_fund));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (oldtp->tp_size > tp->tp_size)
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp,
|
|
|
|
"conversion of %s to pointer loses accuracy",
|
1986-03-10 13:07:55 +00:00
|
|
|
symbol2str(oldtp->tp_fund));
|
|
|
|
if (oldtp->tp_size != tp->tp_size)
|
|
|
|
int2int(expp, tp);
|
|
|
|
else
|
|
|
|
(*expp)->ex_type = tp;
|
|
|
|
}
|
|
|
|
else
|
1988-09-29 15:24:02 +00:00
|
|
|
if (oldtp->tp_fund == ERRONEOUS) {
|
|
|
|
/* we just won't look */
|
1986-09-29 14:01:34 +00:00
|
|
|
(*expp)->ex_type = tp; /* brute force */
|
1988-09-29 15:24:02 +00:00
|
|
|
}
|
1986-03-27 18:17:48 +00:00
|
|
|
else
|
1986-03-10 13:07:55 +00:00
|
|
|
if (oldtp->tp_size == tp->tp_size && oper == CAST) {
|
1986-03-15 18:16:30 +00:00
|
|
|
expr_warning(*expp, "dubious conversion based on equal size");
|
1986-03-10 13:07:55 +00:00
|
|
|
(*expp)->ex_type = tp; /* brute force */
|
|
|
|
}
|
1986-03-27 18:17:48 +00:00
|
|
|
else {
|
1986-03-10 13:07:55 +00:00
|
|
|
if (oldtp->tp_fund != ERRONEOUS && tp->tp_fund != ERRONEOUS)
|
|
|
|
expr_error(*expp, "cannot convert %s to %s",
|
|
|
|
symbol2str(oldtp->tp_fund),
|
|
|
|
symbol2str(tp->tp_fund)
|
|
|
|
);
|
1986-03-27 18:17:48 +00:00
|
|
|
(*expp)->ex_type = tp; /* brute force */
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ch7asgn(expp, oper, expr)
|
1987-03-25 23:14:43 +00:00
|
|
|
struct expr **expp;
|
1986-03-10 13:07:55 +00:00
|
|
|
struct expr *expr;
|
|
|
|
{
|
|
|
|
/* The assignment operators.
|
1986-08-13 10:05:39 +00:00
|
|
|
"f op= e" should be interpreted as
|
|
|
|
"f = (typeof f)((typeof (f op e))f op (typeof (f op e))e)"
|
|
|
|
and not as "f = f op (typeof f)e".
|
|
|
|
Consider, for example, (i == 10) i *= 0.9; (i == 9), where
|
|
|
|
typeof i == int.
|
|
|
|
The resulting expression tree becomes:
|
|
|
|
op=
|
|
|
|
/ \
|
|
|
|
/ \
|
|
|
|
f (typeof (f op e))e
|
|
|
|
EVAL should however take care of evaluating (typeof (f op e))f
|
1986-03-10 13:07:55 +00:00
|
|
|
*/
|
1987-03-25 23:14:43 +00:00
|
|
|
register struct expr *exp = *expp;
|
|
|
|
int fund = exp->ex_type->tp_fund;
|
1986-09-10 10:23:26 +00:00
|
|
|
struct type *tp;
|
1986-03-10 13:07:55 +00:00
|
|
|
|
|
|
|
/* We expect an lvalue */
|
1987-03-25 23:14:43 +00:00
|
|
|
if (!exp->ex_lvalue) {
|
|
|
|
expr_error(exp, "no lvalue in lhs of %s", symbol2str(oper));
|
|
|
|
exp->ex_depth = 99; /* no direct store/load at EVAL() */
|
1986-03-10 13:07:55 +00:00
|
|
|
/* what is 99 ??? DG */
|
|
|
|
}
|
1986-08-13 10:05:39 +00:00
|
|
|
if (oper == '=') {
|
1987-03-25 23:14:43 +00:00
|
|
|
ch7cast(&expr, oper, exp->ex_type);
|
1986-09-10 10:23:26 +00:00
|
|
|
tp = expr->ex_type;
|
1986-08-13 10:05:39 +00:00
|
|
|
}
|
|
|
|
else { /* turn e into e' where typeof(e') = typeof (f op e) */
|
1986-08-26 14:59:36 +00:00
|
|
|
struct expr *extmp = intexpr((arith)0, INT);
|
1986-08-13 10:05:39 +00:00
|
|
|
|
|
|
|
/* this is really $#@&*%$# ! */
|
1988-09-29 15:24:02 +00:00
|
|
|
/* if you correct this, please correct lint_new_oper() too */
|
1986-08-13 10:05:39 +00:00
|
|
|
extmp->ex_lvalue = 1;
|
1987-03-25 23:14:43 +00:00
|
|
|
extmp->ex_type = exp->ex_type;
|
1986-08-13 10:05:39 +00:00
|
|
|
ch7bin(&extmp, oper, expr);
|
1986-09-10 10:23:26 +00:00
|
|
|
/* Note that ch7bin creates a tree of the expression
|
1986-08-13 10:05:39 +00:00
|
|
|
((typeof (f op e))f op (typeof (f op e))e),
|
1986-09-10 10:23:26 +00:00
|
|
|
where f ~ extmp and e ~ expr.
|
|
|
|
We want to use (typeof (f op e))e.
|
1986-08-13 10:05:39 +00:00
|
|
|
Ch7bin does not create a tree if both operands
|
|
|
|
were illegal or constants!
|
|
|
|
*/
|
1986-09-10 10:23:26 +00:00
|
|
|
tp = extmp->ex_type; /* perform the arithmetic in type tp */
|
1986-08-13 10:05:39 +00:00
|
|
|
if (extmp->ex_class == Oper) {
|
|
|
|
expr = extmp->OP_RIGHT;
|
|
|
|
extmp->OP_RIGHT = NILEXPR;
|
|
|
|
free_expression(extmp);
|
1986-03-15 18:16:30 +00:00
|
|
|
}
|
1986-08-13 10:05:39 +00:00
|
|
|
else
|
|
|
|
expr = extmp;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
if (fund == FIELD)
|
1987-03-25 23:14:43 +00:00
|
|
|
exp = new_oper(exp->ex_type->tp_up, exp, oper, expr);
|
1986-03-10 13:07:55 +00:00
|
|
|
else
|
1987-03-25 23:14:43 +00:00
|
|
|
exp = new_oper(exp->ex_type, exp, oper, expr);
|
1986-09-10 10:23:26 +00:00
|
|
|
#else NOBITFIELD
|
1987-03-25 23:14:43 +00:00
|
|
|
exp = new_oper(exp->ex_type, exp, oper, expr);
|
1986-09-10 10:23:26 +00:00
|
|
|
#endif NOBITFIELD
|
1987-03-25 23:14:43 +00:00
|
|
|
exp->OP_TYPE = tp; /* for EVAL() */
|
|
|
|
exp->ex_flags |= EX_SIDEEFFECTS;
|
|
|
|
*expp = exp;
|
1986-03-10 13:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Some interesting (?) questions answered.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
is_integral_type(tp)
|
1987-02-09 23:19:42 +00:00
|
|
|
register struct type *tp;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case CHAR:
|
|
|
|
case SHORT:
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
case ENUM:
|
|
|
|
return 1;
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
case FIELD:
|
|
|
|
return is_integral_type(tp->tp_up);
|
|
|
|
#endif NOBITFIELD
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
is_arith_type(tp)
|
1987-02-09 23:19:42 +00:00
|
|
|
register struct type *tp;
|
1986-03-10 13:07:55 +00:00
|
|
|
{
|
|
|
|
switch (tp->tp_fund) {
|
|
|
|
case CHAR:
|
|
|
|
case SHORT:
|
|
|
|
case INT:
|
|
|
|
case LONG:
|
|
|
|
case ENUM:
|
1986-09-12 09:16:07 +00:00
|
|
|
#ifndef NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
case FLOAT:
|
|
|
|
case DOUBLE:
|
1986-09-12 09:16:07 +00:00
|
|
|
#endif NOFLOAT
|
1986-03-10 13:07:55 +00:00
|
|
|
return 1;
|
|
|
|
#ifndef NOBITFIELD
|
|
|
|
case FIELD:
|
|
|
|
return is_arith_type(tp->tp_up);
|
|
|
|
#endif NOBITFIELD
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|