From: eck Date: Tue, 12 Dec 1989 12:52:03 +0000 (+0000) Subject: fixed null-pointer constants and SkipToNewLine() X-Git-Tag: release-5-5~2013 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b3a142e244e11c57b1cc903b3d5a5cff14f90d69;p=ack.git fixed null-pointer constants and SkipToNewLine() --- diff --git a/lang/cem/cemcom.ansi/LLlex.c b/lang/cem/cemcom.ansi/LLlex.c index 443f6cd5b..12f08f47b 100644 --- a/lang/cem/cemcom.ansi/LLlex.c +++ b/lang/cem/cemcom.ansi/LLlex.c @@ -115,7 +115,6 @@ GetToken(ptok) */ char buf[(IDFSIZE > NUMSIZE ? IDFSIZE : NUMSIZE) + 1]; register int ch, nch; - int nlflag = 0; token_nmb++; @@ -590,7 +589,7 @@ quoted(ch) for (;;) { ch = GetChar(); - if (vch = hex_val(ch), vch == -1) + if ((vch = hex_val(ch)) == -1) break; hex = hex * 16 + vch; } diff --git a/lang/cem/cemcom.ansi/arith.c b/lang/cem/cemcom.ansi/arith.c index ece5613a3..dea510fe7 100644 --- a/lang/cem/cemcom.ansi/arith.c +++ b/lang/cem/cemcom.ansi/arith.c @@ -135,21 +135,31 @@ relbalance(e1p, oper, e2p) register struct expr **e1p, **e2p; { /* The expressions *e1p and *e2p are balanced to be operands - of the relational operator oper. + of the relational operator oper, or the ':'. + Care is taken to switch the operands in case of a + null-pointer constant. This is done so that ch3cast() + allows assignments of a null-pointer to a function + pointer. */ - if ((*e1p)->ex_type->tp_fund == FUNCTION) - function2pointer(*e1p); - if ((*e2p)->ex_type->tp_fund == FUNCTION) - function2pointer(*e2p); - if ((*e1p)->ex_type->tp_fund == POINTER) - ch3pointer(e2p, oper, (*e1p)->ex_type); - else if ((*e2p)->ex_type->tp_fund == POINTER) - ch3pointer(e1p, oper, (*e2p)->ex_type); - else if ((*e1p)->ex_type == (*e2p)->ex_type - && (*e1p)->ex_type->tp_fund == ENUM) {} + register struct expr *e1 = *e1p, *e2 = *e2p; + struct expr *tmpexpr; + + if (e1->ex_type->tp_fund == POINTER + && is_cp_cst(e1) + && e1->VL_VALUE == 0) { + tmpexpr = e1; + e1 = e2; + e2 = tmpexpr; + } + if (e1->ex_type->tp_fund == POINTER) + ch3pointer(e2p, oper, e1->ex_type); + else if (e2->ex_type->tp_fund == POINTER) + ch3pointer(e1p, oper, e2->ex_type); + else if (e1->ex_type == e2->ex_type + && e1->ex_type->tp_fund == ENUM) {} else if (oper == ':' - && (*e1p)->ex_type->tp_fund == VOID - && (*e2p)->ex_type->tp_fund == VOID) {} + && e1->ex_type->tp_fund == VOID + && e2->ex_type->tp_fund == VOID) {} else arithbalance(e1p, oper, e2p); } diff --git a/lang/cem/cemcom.ansi/ch3.c b/lang/cem/cemcom.ansi/ch3.c index 6960f9bf3..4808442fa 100644 --- a/lang/cem/cemcom.ansi/ch3.c +++ b/lang/cem/cemcom.ansi/ch3.c @@ -177,8 +177,9 @@ ch3cast(expp, oper, tp) (*expp)->ex_type = void_type; return; } - if ((*expp)->ex_type->tp_fund == FUNCTION) + if ((*expp)->ex_type->tp_fund == FUNCTION) { function2pointer(*expp); + } if ((*expp)->ex_type->tp_fund == ARRAY) array2pointer(*expp); if ((*expp)->ex_class == String) @@ -287,6 +288,7 @@ ch3cast(expp, oper, tp) case '=': case CASTAB: case RETURN: + case ':': if (tp->tp_up && oldtp->tp_up) { if (tp->tp_up->tp_fund == VOID && oldtp->tp_up->tp_fund != FUNCTION) { @@ -296,13 +298,17 @@ ch3cast(expp, oper, tp) && tp->tp_up->tp_fund != FUNCTION) { break; /* switch */ } + if (oldtp->tp_up->tp_fund == VOID + && is_cp_cst(*expp) + && (*expp)->VL_VALUE == (arith)0) + break; /* switch */ } /* falltrough */ default: if (oper == CASTAB) - expr_warning(*expp, "incompatible pointers"); + expr_strict(*expp, "incompatible pointers in call"); else - expr_warning(*expp, "incompatible pointers in %s", + expr_strict(*expp, "incompatible pointers in %s", symbol2str(oper)); break; case CAST: break; diff --git a/lang/cem/cemcom.ansi/ch3bin.c b/lang/cem/cemcom.ansi/ch3bin.c index 10a9a45c2..6a65a7a32 100644 --- a/lang/cem/cemcom.ansi/ch3bin.c +++ b/lang/cem/cemcom.ansi/ch3bin.c @@ -70,25 +70,11 @@ ch3bin(expp, oper, expr) break; case '(': /* 3.3.2.2 */ -#if 1 - if ( expp_tp->tp_fund == POINTER && - expp_tp->tp_up->tp_fund == FUNCTION - ) { + if (expp_tp->tp_fund == POINTER + && expp_tp->tp_up->tp_fund == FUNCTION) { ch3mon('*', expp); expp_tp = (*expp)->ex_type; } -#else - if (expp_tp->tp_fund != POINTER - || expp->tp_up->tp_fund != FUNCTION) { - expr_error(*expp, "call of non-function (%s)", - symbol2str(expp_tp->tp_fund)); - /* leave the expression; it may still serve */ - free_expression(expr); /* there go the parameters */ - *expp = new_oper(error_type, - *expp, '(', (struct expr *)0); - } -#endif -#if 1 if (expp_tp->tp_fund != FUNCTION) { expr_error(*expp, "call of non-function (%s)", symbol2str(expp_tp->tp_fund)); @@ -97,7 +83,6 @@ ch3bin(expp, oper, expr) *expp = new_oper(error_type, *expp, '(', (struct expr *)0); } -#endif else *expp = new_oper(expp_tp->tp_up, *expp, '(', expr); @@ -105,8 +90,6 @@ ch3bin(expp, oper, expr) break; case PARCOMMA: /* 3.3.2.2 */ - if (expp_tp->tp_fund == FUNCTION) - function2pointer(*expp); *expp = new_oper(expr->ex_type, *expp, PARCOMMA, expr); break; @@ -249,13 +232,12 @@ ch3bin(expp, oper, expr) break; case ':': - if ( is_struct_or_union(expp_tp->tp_fund) - || is_struct_or_union(expr->ex_type->tp_fund) - ) { + if (is_struct_or_union(expp_tp->tp_fund) + || is_struct_or_union(expr->ex_type->tp_fund)) { if (!equal_type(expp_tp, expr->ex_type, -1)) expr_error(*expp, "illegal balance"); } - else + else relbalance(expp, oper, &expr); #ifdef LINT if ( (is_cp_cst(*expp) && is_cp_cst(expr)) @@ -333,9 +315,10 @@ mk_binop(expp, oper, expr, commutative) else if (is_fp_cst(expr) && is_fp_cst(ex)) fltcstbin(expp, oper, expr); else { - *expp = (commutative && expr->ex_depth >= ex->ex_depth) ? - new_oper(ex->ex_type, expr, oper, ex) : - new_oper(ex->ex_type, ex, oper, expr); + *expp = (commutative && (expr->ex_depth >= ex->ex_depth + || is_cp_cst(ex))) + ? new_oper(ex->ex_type, expr, oper, ex) + : new_oper(ex->ex_type, ex, oper, expr); } } diff --git a/lang/cem/cemcom.ansi/ch3mon.c b/lang/cem/cemcom.ansi/ch3mon.c index eeab43001..be2692f64 100644 --- a/lang/cem/cemcom.ansi/ch3mon.c +++ b/lang/cem/cemcom.ansi/ch3mon.c @@ -150,7 +150,7 @@ ch3mon(oper, expp) (arith)((*expp)->SG_LEN) : size_of_type((*expp)->ex_type, symbol2str((*expp)->ex_type->tp_fund)) - , INT); + , ULONG); expr->ex_flags |= EX_SIZEOF; free_expression(*expp); *expp = expr; diff --git a/lang/cem/cemcom.ansi/expression.g b/lang/cem/cemcom.ansi/expression.g index 53933cf8a..cc388bbe4 100644 --- a/lang/cem/cemcom.ansi/expression.g +++ b/lang/cem/cemcom.ansi/expression.g @@ -146,7 +146,7 @@ size_of(register struct expr **expp;) [%if (first_of_type_specifier(AHEAD) && AHEAD != IDENTIFIER) cast(&tp) { - *expp = intexpr(size_of_type(tp, "type"), INT); + *expp = intexpr(size_of_type(tp, "type"), ULONG); (*expp)->ex_flags |= EX_SIZEOF; } | diff --git a/lang/cem/cemcom.ansi/skip.c b/lang/cem/cemcom.ansi/skip.c index 998d46e40..9c1e71306 100644 --- a/lang/cem/cemcom.ansi/skip.c +++ b/lang/cem/cemcom.ansi/skip.c @@ -63,10 +63,24 @@ SkipToNewLine() { register int ch; register int garbage = 0; +#ifndef NOPP + register int delim = 0; +#endif while ((ch = GetChar()) != '\n') { #ifndef NOPP - if (ch == '/') { + if (delim) { + if (ch == '\\') { + if (GetChar() == '\n') break; + } else if (ch == delim) { + delim = 0; + } + continue; + } + else if (ch == '\'' || ch == '\"') { + delim = ch; + garbage = 1; + } else if (ch == '/') { if ((ch = GetChar()) == '*' && !InputLevel ) { @@ -78,6 +92,9 @@ SkipToNewLine() if (!is_wsp(ch)) garbage = 1; } +#ifndef NOPP + if (delim) strict("unclosed opening %c", delim); +#endif ++LineNumber; return garbage; }