fixed small bug (void expr. cast to void), squeezing for MINIX

This commit is contained in:
eck 1990-10-23 14:13:10 +00:00
parent b4f97588b7
commit ba0cc3a57d

View file

@ -179,24 +179,25 @@ ch3cast(expp, oper, tp)
expression of class Type. expression of class Type.
*/ */
register struct type *oldtp; register struct type *oldtp;
register struct expr *exp = *expp;
int qual_lev, ascompat = 0; int qual_lev, ascompat = 0;
if (oper == RETURN && tp->tp_fund == VOID) { if (oper == RETURN && tp->tp_fund == VOID) {
expr_strict(*expp, "return <expression> in function returning void"); expr_strict(exp, "return <expression> in function returning void");
(*expp)->ex_type = void_type; exp->ex_type = void_type;
return; return;
} }
if ((*expp)->ex_type->tp_fund == FUNCTION) { if (exp->ex_type->tp_fund == FUNCTION) {
function2pointer(*expp); function2pointer(exp);
} }
if ((*expp)->ex_type->tp_fund == ARRAY) if (exp->ex_type->tp_fund == ARRAY)
array2pointer(*expp); array2pointer(exp);
if ((*expp)->ex_class == String) if (exp->ex_class == String)
string2pointer(*expp); string2pointer(exp);
oldtp = (*expp)->ex_type; oldtp = exp->ex_type;
if (oldtp->tp_size <= 0) { if (oldtp->tp_size <= 0 && oldtp->tp_fund != VOID) {
expr_error(*expp,"incomplete type in expression"); expr_error(exp,"incomplete type in expression");
} }
#ifndef NOBITFIELD #ifndef NOBITFIELD
@ -234,15 +235,15 @@ ch3cast(expp, oper, tp)
if (ascompat && tp->tp_fund == POINTER) { if (ascompat && tp->tp_fund == POINTER) {
if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal) if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal)
!= oldtp->tp_up->tp_typequal) { != oldtp->tp_up->tp_typequal) {
expr_strict( *expp, "qualifier error"); expr_strict( exp, "qualifier error");
} }
} }
(*expp)->ex_type = tp; /* so qualifiers are allright */ exp->ex_type = tp; /* so qualifiers are allright */
} }
else else
if (tp->tp_fund == VOID) { if (tp->tp_fund == VOID) {
/* easy again */ /* easy again */
(*expp)->ex_type = void_type; exp->ex_type = void_type;
} }
else else
if (is_arith_type(oldtp) && is_arith_type(tp)) { if (is_arith_type(oldtp) && is_arith_type(tp)) {
@ -252,9 +253,10 @@ ch3cast(expp, oper, tp)
if (oldi && i) { if (oldi && i) {
#ifdef LINT #ifdef LINT
if (oper == CAST) if (oper == CAST)
(*expp)->ex_type = tp; exp->ex_type = tp;
else else {
int2int(expp, tp); int2int(expp, tp);
}
#else LINT #else LINT
int2int(expp, tp); int2int(expp, tp);
#endif LINT #endif LINT
@ -263,9 +265,10 @@ ch3cast(expp, oper, tp)
if (oldi && !i) { if (oldi && !i) {
#ifdef LINT #ifdef LINT
if (oper == CAST) if (oper == CAST)
(*expp)->ex_type = tp; exp->ex_type = tp;
else else {
int2float(expp, tp); int2float(expp, tp);
}
#else LINT #else LINT
int2float(expp, tp); int2float(expp, tp);
#endif LINT #endif LINT
@ -274,9 +277,10 @@ ch3cast(expp, oper, tp)
if (!oldi && i) { if (!oldi && i) {
#ifdef LINT #ifdef LINT
if (oper == CAST) if (oper == CAST)
(*expp)->ex_type = tp; exp->ex_type = tp;
else else {
float2int(expp, tp); float2int(expp, tp);
}
#else LINT #else LINT
float2int(expp, tp); float2int(expp, tp);
#endif LINT #endif LINT
@ -285,9 +289,10 @@ ch3cast(expp, oper, tp)
/* !oldi && !i */ /* !oldi && !i */
#ifdef LINT #ifdef LINT
if (oper == CAST) if (oper == CAST)
(*expp)->ex_type = tp; exp->ex_type = tp;
else else {
float2float(expp, tp); float2float(expp, tp);
}
#else LINT #else LINT
float2float(expp, tp); float2float(expp, tp);
#endif LINT #endif LINT
@ -312,16 +317,16 @@ ch3cast(expp, oper, tp)
break; /* switch */ break; /* switch */
} }
if (oldtp->tp_up->tp_fund == VOID if (oldtp->tp_up->tp_fund == VOID
&& is_cp_cst(*expp) && is_cp_cst(exp)
&& (*expp)->VL_VALUE == (arith)0) && exp->VL_VALUE == (arith)0)
break; /* switch */ break; /* switch */
} }
/* falltrough */ /* falltrough */
default: default:
if (oper == CASTAB) if (oper == CASTAB)
expr_strict(*expp, "incompatible pointers in call"); expr_strict(exp, "incompatible pointers in call");
else else
expr_strict(*expp, "incompatible pointers in %s", expr_strict(exp, "incompatible pointers in %s",
symbol2str(oper)); symbol2str(oper));
break; break;
case CAST: break; case CAST: break;
@ -330,23 +335,23 @@ ch3cast(expp, oper, tp)
if (oper != CAST) if (oper != CAST)
lint_ptr_conv(oldtp->tp_up->tp_fund, tp->tp_up->tp_fund); lint_ptr_conv(oldtp->tp_up->tp_fund, tp->tp_up->tp_fund);
#endif LINT #endif LINT
(*expp)->ex_type = tp; /* free conversion */ exp->ex_type = tp; /* free conversion */
} }
else else
if (oldtp->tp_fund == POINTER && is_integral_type(tp)) { if (oldtp->tp_fund == POINTER && is_integral_type(tp)) {
/* from pointer to integral */ /* from pointer to integral */
if (oper != CAST) if (oper != CAST)
expr_warning(*expp, expr_warning(exp,
"illegal conversion of pointer to %s", "illegal conversion of pointer to %s",
symbol2str(tp->tp_fund)); symbol2str(tp->tp_fund));
if (oldtp->tp_size > tp->tp_size) if (oldtp->tp_size > tp->tp_size)
expr_warning(*expp, expr_warning(exp,
"conversion of pointer to %s loses accuracy", "conversion of pointer to %s loses accuracy",
symbol2str(tp->tp_fund)); symbol2str(tp->tp_fund));
if (oldtp->tp_size != tp->tp_size) if (oldtp->tp_size != tp->tp_size) {
int2int(expp, tp); int2int(expp, tp);
else } else
(*expp)->ex_type = tp; exp->ex_type = tp;
} }
else else
if (tp->tp_fund == POINTER && is_integral_type(oldtp)) { if (tp->tp_fund == POINTER && is_integral_type(oldtp)) {
@ -359,43 +364,45 @@ ch3cast(expp, oper, tp)
case NOTEQUAL: case NOTEQUAL:
case '=': case '=':
case RETURN: case RETURN:
if (is_cp_cst(*expp) && (*expp)->VL_VALUE == (arith)0) if (is_cp_cst(exp) && exp->VL_VALUE == (arith)0)
break; break;
default: default:
expr_warning(*expp, expr_warning(exp,
"illegal conversion of %s to pointer", "illegal conversion of %s to pointer",
symbol2str(oldtp->tp_fund)); symbol2str(oldtp->tp_fund));
break; break;
} }
if (oldtp->tp_size > tp->tp_size) if (oldtp->tp_size > tp->tp_size)
expr_warning(*expp, expr_warning(exp,
"conversion of %s to pointer loses accuracy", "conversion of %s to pointer loses accuracy",
symbol2str(oldtp->tp_fund)); symbol2str(oldtp->tp_fund));
if (oldtp->tp_size != tp->tp_size) if (oldtp->tp_size != tp->tp_size) {
int2int(expp, tp); int2int(expp, tp);
else } else
(*expp)->ex_type = tp; exp->ex_type = tp;
} }
else else
if (oldtp->tp_fund == ERRONEOUS) { if (oldtp->tp_fund == ERRONEOUS) {
/* we just won't look */ /* we just won't look */
(*expp)->ex_type = tp; /* brute force */ exp->ex_type = tp; /* brute force */
} }
else 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(exp, "dubious conversion based on equal size");
(*expp)->ex_type = tp; /* brute force */ exp->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(exp, "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; /* brute force */ exp->ex_type = tp; /* brute force */
} }
/* re-initialize exp, since *expp may have changed */
exp = *expp;
if (oper == CAST) { if (oper == CAST) {
(*expp)->ex_flags |= EX_ILVALUE; exp->ex_flags |= EX_ILVALUE;
} }
} }