more calls of expr_error() for better error reporting
This commit is contained in:
parent
c80f2c0817
commit
021d8d1fec
|
@ -111,7 +111,7 @@ ch76pointer(expp, oper, tp)
|
|||
ch7cast(expp, CAST, tp);
|
||||
else {
|
||||
if ((*expp)->ex_type != error_type)
|
||||
error("%s on %s and pointer",
|
||||
expr_error(*expp, "%s on %s and pointer",
|
||||
symbol2str(oper),
|
||||
symbol2str((*expp)->ex_type->tp_fund)
|
||||
);
|
||||
|
@ -147,7 +147,7 @@ any2arith(expp, oper)
|
|||
)
|
||||
{}
|
||||
else
|
||||
warning("%s on enum", symbol2str(oper));
|
||||
expr_warning(*expp, "%s on enum", symbol2str(oper));
|
||||
int2int(expp, int_type);
|
||||
break;
|
||||
case FLOAT:
|
||||
|
@ -161,7 +161,7 @@ any2arith(expp, oper)
|
|||
break;
|
||||
#endif NOBITFIELD
|
||||
default:
|
||||
error("operator %s on non-numerical operand (%s)",
|
||||
expr_error(*expp, "operator %s on non-numerical operand (%s)",
|
||||
symbol2str(oper), symbol2str(fund));
|
||||
case ERRONEOUS:
|
||||
erroneous2int(expp);
|
||||
|
@ -292,7 +292,7 @@ opnd2integral(expp, oper)
|
|||
|
||||
if (fund != INT && fund != LONG) {
|
||||
if (fund != ERRONEOUS)
|
||||
error("%s operand to %s",
|
||||
expr_error(*expp, "%s operand to %s",
|
||||
symbol2str(fund), symbol2str(oper));
|
||||
erroneous2int(expp);
|
||||
/* fund = INT; */
|
||||
|
@ -327,7 +327,7 @@ opnd2logical(expp, oper)
|
|||
case DOUBLE:
|
||||
break;
|
||||
default:
|
||||
error("%s operand to %s",
|
||||
expr_error(*expp, "%s operand to %s",
|
||||
symbol2str(fund), symbol2str(oper));
|
||||
case ERRONEOUS:
|
||||
erroneous2int(expp);
|
||||
|
|
|
@ -49,7 +49,7 @@ ch7sel(expp, oper, idf)
|
|||
tp = sd->sd_stype;
|
||||
break;
|
||||
default:
|
||||
error("-> applied to %s",
|
||||
expr_error(*expp, "-> applied to %s",
|
||||
symbol2str(tp->tp_fund));
|
||||
case ERRONEOUS:
|
||||
(*expp)->ex_type = error_type;
|
||||
|
@ -60,7 +60,7 @@ ch7sel(expp, oper, idf)
|
|||
else { /* oper == '.' */
|
||||
/* filter out illegal expressions "non_lvalue.sel" */
|
||||
if (!(*expp)->ex_lvalue) {
|
||||
error("dot requires lvalue");
|
||||
expr_error(*expp, "dot requires lvalue");
|
||||
(*expp)->ex_type = error_type;
|
||||
return;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ ch7sel(expp, oper, idf)
|
|||
break;
|
||||
default:
|
||||
if (!is_anon_idf(idf))
|
||||
error("selector %s applied to %s",
|
||||
expr_error(*expp, "selector %s applied to %s",
|
||||
idf->id_text, symbol2str(tp->tp_fund));
|
||||
case ERRONEOUS:
|
||||
(*expp)->ex_type = error_type;
|
||||
|
@ -133,11 +133,11 @@ ch7incr(expp, oper)
|
|||
register int fund = (*expp)->ex_type->tp_fund;
|
||||
|
||||
if (!(*expp)->ex_lvalue) {
|
||||
error("no lvalue with %s", symbol2str(oper));
|
||||
expr_error(*expp, "no lvalue with %s", symbol2str(oper));
|
||||
return;
|
||||
}
|
||||
if (fund == ENUM) {
|
||||
warning("%s on enum", symbol2str(oper));
|
||||
expr_warning(*expp, "%s on enum", symbol2str(oper));
|
||||
addend = (arith)1;
|
||||
}
|
||||
else
|
||||
|
@ -153,7 +153,7 @@ ch7incr(expp, oper)
|
|||
#endif NOBITFIELD
|
||||
else {
|
||||
if ((*expp)->ex_type != error_type)
|
||||
error("%s on %s",
|
||||
expr_error(*expp, "%s on %s",
|
||||
symbol2str(oper),
|
||||
symbol2str((*expp)->ex_type->tp_fund)
|
||||
);
|
||||
|
@ -210,15 +210,17 @@ ch7cast(expp, oper, tp)
|
|||
tp->tp_fund == ENUM &&
|
||||
oper != CAST
|
||||
)
|
||||
warning("%s on enums of different types",
|
||||
symbol2str(oper));
|
||||
expr_warning(*expp,
|
||||
"%s on enums of different types",
|
||||
symbol2str(oper));
|
||||
int2int(expp, tp);
|
||||
}
|
||||
else
|
||||
if (oldi && !i) {
|
||||
if (oldtp->tp_fund == ENUM && oper != CAST)
|
||||
warning("conversion of enum to %s\n",
|
||||
symbol2str(tp->tp_fund));
|
||||
expr_warning(*expp,
|
||||
"conversion of enum to %s\n",
|
||||
symbol2str(tp->tp_fund));
|
||||
int2float(expp, tp);
|
||||
}
|
||||
else
|
||||
|
@ -230,7 +232,7 @@ ch7cast(expp, oper, tp)
|
|||
else
|
||||
if (oldtp->tp_fund == POINTER && tp->tp_fund == POINTER) {
|
||||
if (oper != CAST)
|
||||
warning("incompatible pointers in %s",
|
||||
expr_warning(*expp, "incompatible pointers in %s",
|
||||
symbol2str(oper));
|
||||
(*expp)->ex_type = tp; /* free conversion */
|
||||
}
|
||||
|
@ -238,10 +240,12 @@ ch7cast(expp, oper, tp)
|
|||
if (oldtp->tp_fund == POINTER && is_integral_type(tp)) {
|
||||
/* from pointer to integral */
|
||||
if (oper != CAST)
|
||||
warning("illegal conversion of pointer to %s",
|
||||
expr_warning(*expp,
|
||||
"illegal conversion of pointer to %s",
|
||||
symbol2str(tp->tp_fund));
|
||||
if (oldtp->tp_size > tp->tp_size)
|
||||
warning("conversion of pointer to %s loses accuracy",
|
||||
expr_warning(*expp,
|
||||
"conversion of pointer to %s loses accuracy",
|
||||
symbol2str(tp->tp_fund));
|
||||
if (oldtp->tp_size != tp->tp_size)
|
||||
int2int(expp, tp);
|
||||
|
@ -261,12 +265,14 @@ ch7cast(expp, oper, tp)
|
|||
if (is_cp_cst(*expp) && (*expp)->VL_VALUE == (arith)0)
|
||||
break;
|
||||
default:
|
||||
warning("illegal conversion of %s to pointer",
|
||||
expr_warning(*expp,
|
||||
"illegal conversion of %s to pointer",
|
||||
symbol2str(oldtp->tp_fund));
|
||||
break;
|
||||
}
|
||||
if (oldtp->tp_size > tp->tp_size)
|
||||
warning("conversion of %s to pointer loses accuracy",
|
||||
expr_warning(*expp,
|
||||
"conversion of %s to pointer loses accuracy",
|
||||
symbol2str(oldtp->tp_fund));
|
||||
if (oldtp->tp_size != tp->tp_size)
|
||||
int2int(expp, tp);
|
||||
|
@ -275,7 +281,7 @@ ch7cast(expp, oper, tp)
|
|||
}
|
||||
else
|
||||
if (oldtp->tp_size == tp->tp_size && oper == CAST) {
|
||||
warning("dubious conversion based on equal size");
|
||||
expr_warning(*expp, "dubious conversion based on equal size");
|
||||
(*expp)->ex_type = tp; /* brute force */
|
||||
}
|
||||
else
|
||||
|
@ -299,7 +305,7 @@ ch7asgn(expp, oper, expr)
|
|||
|
||||
/* We expect an lvalue */
|
||||
if (!(*expp)->ex_lvalue) {
|
||||
error("no lvalue in lhs of %s", symbol2str(oper));
|
||||
expr_error(*expp, "no lvalue in lhs of %s", symbol2str(oper));
|
||||
(*expp)->ex_depth = 99; /* no direct store/load at EVAL() */
|
||||
/* what is 99 ??? DG */
|
||||
}
|
||||
|
@ -310,8 +316,7 @@ ch7asgn(expp, oper, expr)
|
|||
case TIMESAB:
|
||||
case DIVAB:
|
||||
case MODAB:
|
||||
if (!is_arith_type((*expp)->ex_type))
|
||||
error("%s on %s", symbol2str(oper), symbol2str(fund));
|
||||
check_arith_type(expp, oper);
|
||||
any2arith(&expr, oper);
|
||||
ch7cast(&expr, CAST, (*expp)->ex_type);
|
||||
break;
|
||||
|
@ -319,9 +324,7 @@ ch7asgn(expp, oper, expr)
|
|||
case MINAB:
|
||||
any2arith(&expr, oper);
|
||||
if (fund == POINTER) {
|
||||
if (!is_integral_type(expr->ex_type))
|
||||
error("%s on non-integral type (%s)",
|
||||
symbol2str(oper), symbol2str(fund));
|
||||
check_integral_type(&expr, oper);
|
||||
ch7bin(&expr, '*',
|
||||
intexpr(
|
||||
size_of_type(
|
||||
|
@ -332,23 +335,20 @@ ch7asgn(expp, oper, expr)
|
|||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
if (!is_arith_type((*expp)->ex_type))
|
||||
error("%s on %s", symbol2str(oper), symbol2str(fund));
|
||||
else
|
||||
else {
|
||||
check_arith_type(expp, oper);
|
||||
ch7cast(&expr, CAST, (*expp)->ex_type);
|
||||
}
|
||||
break;
|
||||
case LEFTAB:
|
||||
case RIGHTAB:
|
||||
check_integral_type(expp, oper);
|
||||
ch7cast(&expr, oper, int_type);
|
||||
if (!is_integral_type((*expp)->ex_type))
|
||||
error("%s on %s", symbol2str(oper), symbol2str(fund));
|
||||
break;
|
||||
case ANDAB:
|
||||
case XORAB:
|
||||
case ORAB:
|
||||
if (!is_integral_type((*expp)->ex_type))
|
||||
error("%s on %s", symbol2str(oper), symbol2str(fund));
|
||||
check_integral_type(expp, oper);
|
||||
ch7cast(&expr, oper, (*expp)->ex_type);
|
||||
break;
|
||||
}
|
||||
|
@ -382,6 +382,18 @@ is_integral_type(tp)
|
|||
}
|
||||
}
|
||||
|
||||
check_integral_type(expp, oper)
|
||||
struct expr **expp;
|
||||
{
|
||||
register struct expr *expr = *expp;
|
||||
|
||||
if (!is_integral_type(expr->ex_type)) {
|
||||
expr_error(expr, "%s on non-integral type (%s)",
|
||||
symbol2str(oper), symbol2str(expr->ex_type->tp_fund));
|
||||
}
|
||||
erroneous2int(expp);
|
||||
}
|
||||
|
||||
int
|
||||
is_arith_type(tp)
|
||||
struct type *tp;
|
||||
|
@ -403,3 +415,15 @@ is_arith_type(tp)
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
check_arith_type(expp, oper)
|
||||
struct expr **expp;
|
||||
{
|
||||
register struct expr *expr = *expp;
|
||||
|
||||
if (!is_arith_type(expr->ex_type)) {
|
||||
expr_error(expr, "%s on non-arithmetical type (%s)",
|
||||
symbol2str(oper), symbol2str(expr->ex_type->tp_fund));
|
||||
}
|
||||
erroneous2int(expp);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ ch7bin(expp, oper, expr)
|
|||
case ERRONEOUS:
|
||||
return;
|
||||
default:
|
||||
error("indexing an object of type %s",
|
||||
expr_error(*expp,
|
||||
"indexing an object of type %s",
|
||||
symbol2str((*expp)->ex_type->tp_fund));
|
||||
return;
|
||||
}
|
||||
|
@ -64,7 +65,7 @@ ch7bin(expp, oper, expr)
|
|||
}
|
||||
if ((*expp)->ex_type->tp_fund != FUNCTION) {
|
||||
if ((*expp)->ex_type != error_type)
|
||||
error("call of non-function (%s)",
|
||||
expr_error(*expp, "call of non-function (%s)",
|
||||
symbol2str((*expp)->ex_type->tp_fund));
|
||||
/* leave the expression; it may still serve */
|
||||
free_expression(expr); /* there go the parameters */
|
||||
|
@ -81,7 +82,7 @@ ch7bin(expp, oper, expr)
|
|||
case '%':
|
||||
fund = arithbalance(expp, oper, &expr);
|
||||
if (fund == DOUBLE) {
|
||||
error("floating operand to %%");
|
||||
expr_error(*expp, "floating operand to %%");
|
||||
erroneous2int(expp);
|
||||
}
|
||||
else
|
||||
|
@ -197,7 +198,7 @@ ch7bin(expp, oper, expr)
|
|||
|| is_struct_or_union(expr->ex_type->tp_fund)
|
||||
) {
|
||||
if ((*expp)->ex_type != expr->ex_type) {
|
||||
error("illegal balance");
|
||||
expr_error(*expp, "illegal balance");
|
||||
(*expp)->ex_type = error_type;
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +234,7 @@ pntminuspnt(expp, oper, expr)
|
|||
struct type *up_type = (*expp)->ex_type->tp_up;
|
||||
|
||||
if (up_type != expr->ex_type->tp_up) {
|
||||
error("subtracting incompatible pointers");
|
||||
expr_error(*expp, "subtracting incompatible pointers");
|
||||
free_expression(expr);
|
||||
erroneous2int(expp);
|
||||
return;
|
||||
|
|
|
@ -29,7 +29,8 @@ ch7mon(oper, expp)
|
|||
array2pointer(expp);
|
||||
if ((*expp)->ex_type->tp_fund != POINTER) {
|
||||
if ((*expp)->ex_type != error_type)
|
||||
error("* applied to non-pointer (%s)",
|
||||
expr_error(*expp,
|
||||
"* applied to non-pointer (%s)",
|
||||
symbol2str((*expp)->ex_type->tp_fund));
|
||||
(*expp)->ex_type = error_type;
|
||||
}
|
||||
|
@ -57,13 +58,13 @@ ch7mon(oper, expp)
|
|||
else
|
||||
#ifndef NOBITFIELD
|
||||
if ((*expp)->ex_type->tp_fund == FIELD) {
|
||||
error("& applied to field variable");
|
||||
expr_error(*expp, "& applied to field variable");
|
||||
(*expp)->ex_type = error_type;
|
||||
}
|
||||
else
|
||||
#endif NOBITFIELD
|
||||
if (!(*expp)->ex_lvalue) {
|
||||
error("& applied to non-lvalue");
|
||||
expr_error(*expp, "& applied to non-lvalue");
|
||||
(*expp)->ex_type = error_type;
|
||||
}
|
||||
else {
|
||||
|
@ -76,7 +77,8 @@ ch7mon(oper, expp)
|
|||
be used as register anymore
|
||||
*/
|
||||
if (def->df_sc == REGISTER) {
|
||||
error("& on register variable not allowed");
|
||||
expr_error(*expp,
|
||||
"& on register variable not allowed");
|
||||
(*expp)->ex_type = error_type;
|
||||
break; /* break case '&' */
|
||||
}
|
||||
|
@ -91,7 +93,7 @@ ch7mon(oper, expp)
|
|||
int fund = (*expp)->ex_type->tp_fund;
|
||||
|
||||
if (fund == FLOAT || fund == DOUBLE) {
|
||||
error("~ not allowed on %s operands",
|
||||
expr_error(*expp, "~ not allowed on %s operands",
|
||||
symbol2str(fund));
|
||||
erroneous2int(expp);
|
||||
break;
|
||||
|
|
|
@ -109,7 +109,7 @@ check_conditional(expr, oper, pos_descr)
|
|||
the operator oper.
|
||||
*/
|
||||
if (options['R'] && rank_of_expression(expr) >= rank_of(oper))
|
||||
warning("%s %s is ungrammatical",
|
||||
expr_warning(expr, "%s %s is ungrammatical",
|
||||
symbol2str(expr->OP_OPER), pos_descr);
|
||||
}
|
||||
|
||||
|
|
|
@ -457,7 +457,7 @@ check_ival(expr, type)
|
|||
case LONG:
|
||||
case ENUM:
|
||||
ch7cast(&expr, '=', type);
|
||||
if (expr->ex_class != Value || expr->VL_IDF != 0) {
|
||||
if (!is_cp_cst(expr)) {
|
||||
illegal_init_cst(expr);
|
||||
break;
|
||||
}
|
||||
|
@ -466,7 +466,7 @@ check_ival(expr, type)
|
|||
#ifndef NOBITFIELD
|
||||
case FIELD:
|
||||
ch7cast(&expr, '=', type->tp_up);
|
||||
if (expr->ex_class != Value || expr->VL_IDF != 0) {
|
||||
if (!is_cp_cst(expr)) {
|
||||
illegal_init_cst(expr);
|
||||
break;
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ check_ival(expr, type)
|
|||
else
|
||||
if (expr->ex_class == Oper && expr->OP_OPER == INT2FLOAT) {
|
||||
expr = expr->OP_RIGHT;
|
||||
if (expr->ex_class != Value || expr->VL_IDF != 0) {
|
||||
if (!is_cp_cst(expr)) {
|
||||
illegal_init_cst(expr);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue