expression nodes now can have a flag EX_ERROR

This commit is contained in:
dick 1986-03-27 18:17:48 +00:00
parent f2764393be
commit ad1feaf35c
11 changed files with 50 additions and 38 deletions

View file

@ -110,12 +110,10 @@ ch76pointer(expp, oper, tp)
) /* ch 7.7 */ ) /* ch 7.7 */
ch7cast(expp, CAST, tp); ch7cast(expp, CAST, tp);
else { else {
if ((*expp)->ex_type != error_type) expr_error(*expp, "%s on %s and pointer",
expr_error(*expp, "%s on %s and pointer",
symbol2str(oper), symbol2str(oper),
symbol2str((*expp)->ex_type->tp_fund) symbol2str((*expp)->ex_type->tp_fund)
); );
(*expp)->ex_type = error_type;
ch7cast(expp, oper, tp); ch7cast(expp, oper, tp);
} }
} }
@ -177,8 +175,11 @@ erroneous2int(expp)
/* the (erroneous) expression *expp is replaced by an /* the (erroneous) expression *expp is replaced by an
int expression int expression
*/ */
int flags = (*expp)->ex_flags;
free_expression(*expp); free_expression(*expp);
*expp = intexpr((arith)0, INT); *expp = intexpr((arith)0, INT);
(*expp)->ex_flags = (flags | EX_ERROR);
} }
struct expr * struct expr *
@ -291,8 +292,7 @@ opnd2integral(expp, oper)
register int fund = (*expp)->ex_type->tp_fund; register int fund = (*expp)->ex_type->tp_fund;
if (fund != INT && fund != LONG) { if (fund != INT && fund != LONG) {
if (fund != ERRONEOUS) expr_error(*expp, "%s operand to %s",
expr_error(*expp, "%s operand to %s",
symbol2str(fund), symbol2str(oper)); symbol2str(fund), symbol2str(oper));
erroneous2int(expp); erroneous2int(expp);
/* fund = INT; */ /* fund = INT; */

View file

@ -61,7 +61,6 @@ ch7sel(expp, oper, idf)
/* filter out illegal expressions "non_lvalue.sel" */ /* filter out illegal expressions "non_lvalue.sel" */
if (!(*expp)->ex_lvalue) { if (!(*expp)->ex_lvalue) {
expr_error(*expp, "dot requires lvalue"); expr_error(*expp, "dot requires lvalue");
(*expp)->ex_type = error_type;
return; return;
} }
} }
@ -102,6 +101,8 @@ ch7sel(expp, oper, idf)
*/ */
(*expp)->VL_VALUE += sd->sd_offset; (*expp)->VL_VALUE += sd->sd_offset;
(*expp)->ex_type = sd->sd_type; (*expp)->ex_type = sd->sd_type;
if ((*expp)->ex_type == error_type)
(*expp)->ex_flags |= EX_ERROR;
} }
else else
if ((*expp)->ex_class == Oper) { if ((*expp)->ex_class == Oper) {
@ -110,16 +111,20 @@ ch7sel(expp, oper, idf)
if (op->op_oper == '.' || op->op_oper == ARROW) { if (op->op_oper == '.' || op->op_oper == ARROW) {
op->op_right->VL_VALUE += sd->sd_offset; op->op_right->VL_VALUE += sd->sd_offset;
(*expp)->ex_type = sd->sd_type; (*expp)->ex_type = sd->sd_type;
if ((*expp)->ex_type == error_type)
(*expp)->ex_flags |= EX_ERROR;
} }
else else
*expp = new_oper(sd->sd_type, *expp, '.', *expp = new_oper(sd->sd_type, *expp, '.',
intexpr(sd->sd_offset, INT)); intexpr(sd->sd_offset, INT));
} }
} }
else /* oper == ARROW */ else {
/* oper == ARROW */
*expp = new_oper(sd->sd_type, *expp = new_oper(sd->sd_type,
*expp, oper, intexpr(sd->sd_offset, INT)); *expp, oper, intexpr(sd->sd_offset, INT));
(*expp)->ex_lvalue = sd->sd_type->tp_fund != ARRAY; }
(*expp)->ex_lvalue = (sd->sd_type->tp_fund != ARRAY);
} }
ch7incr(expp, oper) ch7incr(expp, oper)
@ -152,8 +157,7 @@ ch7incr(expp, oper)
addend = (arith)1; addend = (arith)1;
#endif NOBITFIELD #endif NOBITFIELD
else { else {
if ((*expp)->ex_type != error_type) expr_error(*expp, "%s on %s",
expr_error(*expp, "%s on %s",
symbol2str(oper), symbol2str(oper),
symbol2str((*expp)->ex_type->tp_fund) symbol2str((*expp)->ex_type->tp_fund)
); );
@ -280,18 +284,22 @@ ch7cast(expp, oper, tp)
(*expp)->ex_type = tp; (*expp)->ex_type = tp;
} }
else else
if (oldtp->tp_fund == ERRONEOUS) {
/* we just won't look */
(*expp)->ex_type = tp; /* brute force */
}
else
if (oldtp->tp_size == tp->tp_size && oper == CAST) { if (oldtp->tp_size == tp->tp_size && oper == CAST) {
expr_warning(*expp, "dubious conversion based on equal size"); expr_warning(*expp, "dubious conversion based on equal size");
(*expp)->ex_type = tp; /* brute force */ (*expp)->ex_type = tp; /* brute force */
} }
else else {
{
if (oldtp->tp_fund != ERRONEOUS && tp->tp_fund != ERRONEOUS) if (oldtp->tp_fund != ERRONEOUS && tp->tp_fund != ERRONEOUS)
expr_error(*expp, "cannot convert %s to %s", expr_error(*expp, "cannot convert %s to %s",
symbol2str(oldtp->tp_fund), symbol2str(oldtp->tp_fund),
symbol2str(tp->tp_fund) symbol2str(tp->tp_fund)
); );
(*expp)->ex_type = tp; (*expp)->ex_type = tp; /* brute force */
} }
} }

View file

@ -64,9 +64,8 @@ ch7bin(expp, oper, expr)
ch7mon('*', expp); ch7mon('*', expp);
} }
if ((*expp)->ex_type->tp_fund != FUNCTION) { if ((*expp)->ex_type->tp_fund != FUNCTION) {
if ((*expp)->ex_type != error_type) expr_error(*expp, "call of non-function (%s)",
expr_error(*expp, "call of non-function (%s)", symbol2str((*expp)->ex_type->tp_fund));
symbol2str((*expp)->ex_type->tp_fund));
/* leave the expression; it may still serve */ /* leave the expression; it may still serve */
free_expression(expr); /* there go the parameters */ free_expression(expr); /* there go the parameters */
} }
@ -202,7 +201,6 @@ ch7bin(expp, oper, expr)
) { ) {
if ((*expp)->ex_type != expr->ex_type) { if ((*expp)->ex_type != expr->ex_type) {
expr_error(*expp, "illegal balance"); expr_error(*expp, "illegal balance");
(*expp)->ex_type = error_type;
} }
} }
else { else {

View file

@ -28,11 +28,9 @@ ch7mon(oper, expp)
if ((*expp)->ex_type->tp_fund == ARRAY) if ((*expp)->ex_type->tp_fund == ARRAY)
array2pointer(expp); array2pointer(expp);
if ((*expp)->ex_type->tp_fund != POINTER) { if ((*expp)->ex_type->tp_fund != POINTER) {
if ((*expp)->ex_type != error_type) expr_error(*expp,
expr_error(*expp, "* applied to non-pointer (%s)",
"* applied to non-pointer (%s)", symbol2str((*expp)->ex_type->tp_fund));
symbol2str((*expp)->ex_type->tp_fund));
(*expp)->ex_type = error_type;
} }
else { else {
expr = *expp; expr = *expp;
@ -59,13 +57,11 @@ ch7mon(oper, expp)
#ifndef NOBITFIELD #ifndef NOBITFIELD
if ((*expp)->ex_type->tp_fund == FIELD) { if ((*expp)->ex_type->tp_fund == FIELD) {
expr_error(*expp, "& applied to field variable"); expr_error(*expp, "& applied to field variable");
(*expp)->ex_type = error_type;
} }
else else
#endif NOBITFIELD #endif NOBITFIELD
if (!(*expp)->ex_lvalue) { if (!(*expp)->ex_lvalue) {
expr_error(*expp, "& applied to non-lvalue"); expr_error(*expp, "& applied to non-lvalue");
(*expp)->ex_type = error_type;
} }
else { else {
/* assume that enums are already filtered out */ /* assume that enums are already filtered out */
@ -79,7 +75,6 @@ ch7mon(oper, expp)
if (def->df_sc == REGISTER) { if (def->df_sc == REGISTER) {
expr_error(*expp, expr_error(*expp,
"& on register variable not allowed"); "& on register variable not allowed");
(*expp)->ex_type = error_type;
break; /* break case '&' */ break; /* break case '&' */
} }
def->df_register = REG_NONE; def->df_register = REG_NONE;

View file

@ -318,11 +318,11 @@ p1_expr(lvl, expr)
printf("NILEXPR\n"); printf("NILEXPR\n");
return; return;
} }
printf("expr: L=%u, T=%s, %cV, F=%02o, D=%d, %s: ", printf("expr: L=%u, T=%s, %cV, F=%03o, D=%d, %s: ",
expr->ex_line, expr->ex_line,
type2str(expr->ex_type), type2str(expr->ex_type),
expr->ex_lvalue ? 'l' : 'r', expr->ex_lvalue ? 'l' : 'r',
expr->ex_flags, expr->ex_flags & 0xFF,
expr->ex_depth, expr->ex_depth,
expr->ex_class == Value ? "Value" : expr->ex_class == Value ? "Value" :
expr->ex_class == String ? "String" : expr->ex_class == String ? "String" :

View file

@ -56,7 +56,10 @@ expr_error(expr, fmt, args)
struct expr *expr; struct expr *expr;
char *fmt; char *fmt;
{ {
if (expr->ex_flags & EX_ERROR)
return; /* to prevent proliferation */
_error(ERROR, expr, fmt, &args); _error(ERROR, expr, fmt, &args);
expr->ex_flags |= EX_ERROR;
} }
/*VARARGS1*/ /*VARARGS1*/
@ -71,6 +74,8 @@ expr_warning(expr, fmt, args)
struct expr *expr; struct expr *expr;
char *fmt; char *fmt;
{ {
if (expr->ex_flags & EX_ERROR)
return; /* to prevent proliferation */
_error(WARNING, expr, fmt, &args); _error(WARNING, expr, fmt, &args);
} }

View file

@ -169,12 +169,13 @@ idf2expr(expr)
} }
/* now def != 0 */ /* now def != 0 */
if (def->df_type->tp_fund == LABEL) { if (def->df_type->tp_fund == LABEL) {
error("illegal use of label %s", idf->id_text); expr_error(expr, "illegal use of label %s", idf->id_text);
expr->ex_type = error_type;
} }
else { else {
def->df_used = 1; def->df_used = 1;
expr->ex_type = def->df_type; expr->ex_type = def->df_type;
if (expr->ex_type == error_type)
expr->ex_flags |= EX_ERROR;
} }
expr->ex_lvalue = expr->ex_lvalue =
( def->df_type->tp_fund == FUNCTION || ( def->df_type->tp_fund == FUNCTION ||
@ -381,7 +382,6 @@ chk_cst_expr(expp)
if (err) { if (err) {
erroneous2int(expp); erroneous2int(expp);
(*expp)->ex_type = error_type;
} }
} }

View file

@ -68,11 +68,12 @@ struct expr {
/* some bits for the ex_flag field, to keep track of various /* some bits for the ex_flag field, to keep track of various
interesting properties of an expression. interesting properties of an expression.
*/ */
#define EX_SIZEOF 001 /* contains sizeof operator */ #define EX_SIZEOF 0001 /* contains sizeof operator */
#define EX_CAST 002 /* contains cast */ #define EX_CAST 0002 /* contains cast */
#define EX_LOGICAL 004 /* contains logical operator */ #define EX_LOGICAL 0004 /* contains logical operator */
#define EX_COMMA 010 /* contains expression comma */ #define EX_COMMA 0010 /* contains expression comma */
#define EX_PARENS 020 /* the top level is parenthesized */ #define EX_PARENS 0020 /* the top level is parenthesized */
#define EX_ERROR 0200 /* the expression is wrong */
#define NILEXPR ((struct expr *)0) #define NILEXPR ((struct expr *)0)

View file

@ -668,8 +668,7 @@ con_int(expr)
illegal_init_cst(expr) illegal_init_cst(expr)
struct expr *expr; struct expr *expr;
{ {
if (expr->ex_type->tp_fund != ERRONEOUS) expr_error(expr, "illegal initialisation constant");
expr_error(expr, "illegal initialisation constant");
} }
too_many_initialisers(expr) too_many_initialisers(expr)

View file

@ -71,7 +71,8 @@ control_if_expression
{ {
#ifndef NOPP #ifndef NOPP
if (expr->ex_flags & EX_SIZEOF) if (expr->ex_flags & EX_SIZEOF)
error("sizeof not allowed in preprocessor"); expr_error(expr,
"sizeof not allowed in preprocessor");
ifval = expr->VL_VALUE; ifval = expr->VL_VALUE;
free_expression(expr); free_expression(expr);
#endif NOPP #endif NOPP

View file

@ -129,6 +129,11 @@ code_case(expr)
return; return;
} }
if (expr->ex_flags & EX_ERROR) {
/* is probably 0 anyway */
return;
}
expr->ex_type = sh->sh_type; expr->ex_type = sh->sh_type;
cut_size(expr); cut_size(expr);