From: eck Date: Mon, 27 Nov 1989 11:37:11 +0000 (+0000) Subject: improved type-checking, fixed preprocessor bug, fixed syntax bug X-Git-Tag: release-5-5~2043 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=671556cfc40f572bd8200d190303e12ad9f9aa8d;p=ack.git improved type-checking, fixed preprocessor bug, fixed syntax bug --- diff --git a/lang/cem/cemcom.ansi/ch3.c b/lang/cem/cemcom.ansi/ch3.c index 3a880c953..1b1e6da50 100644 --- a/lang/cem/cemcom.ansi/ch3.c +++ b/lang/cem/cemcom.ansi/ch3.c @@ -170,7 +170,7 @@ ch3cast(expp, oper, tp) expression of class Type. */ register struct type *oldtp; - int qual_lev; + int qual_lev, ascompat = 0; if (oper == RETURN && tp->tp_fund == VOID) { expr_strict(*expp, "return in function returning void"); @@ -196,14 +196,28 @@ ch3cast(expp, oper, tp) return; } #endif NOBITFIELD - if (oper == CASTAB || oper == '=' || oper == RETURN) { - qual_lev = -2; - } else if (oper == CAST) qual_lev = -999; /* ??? hack */ - else qual_lev = -1; + switch (oper) { + default: qual_lev = -1; break; + case CAST: qual_lev = -999; break; /* ??? hack */ + case CASTAB: + case '=': + case RETURN: ascompat = 1; /* assignment compatibility */ + /* fallthrough */ + case '-': + case '<': + case '>': + case LESSEQ: + case GREATEREQ: + case EQUAL: + case NOTEQUAL: + case ':': + qual_lev = -2; + break; + } if (equal_type(tp, oldtp, qual_lev)) { /* life is easy */ - if (qual_lev == -2 && tp->tp_fund == POINTER) { + if (ascompat && tp->tp_fund == POINTER) { if ((tp->tp_up->tp_typequal & oldtp->tp_up->tp_typequal) != oldtp->tp_up->tp_typequal) { expr_strict( *expp, "qualifier error"); @@ -377,13 +391,10 @@ equal_type(tp, otp, qual_lev) if (!tp || !otp || (tp->tp_fund != otp->tp_fund) + || (tp->tp_size != otp->tp_size) || (tp->tp_unsigned != otp->tp_unsigned) || (tp->tp_align != otp->tp_align)) return 0; - if (tp->tp_fund != ARRAY) { - if (tp->tp_size != otp->tp_size) - return 0; - } if (qual_lev >= 0) { if (tp->tp_typequal != otp->tp_typequal) strict("illegal qualifiers"); diff --git a/lang/cem/cemcom.ansi/ch3mon.c b/lang/cem/cemcom.ansi/ch3mon.c index e3ed3287a..eeab43001 100644 --- a/lang/cem/cemcom.ansi/ch3mon.c +++ b/lang/cem/cemcom.ansi/ch3mon.c @@ -28,7 +28,8 @@ ch3mon(oper, expp) */ register struct expr *expr; - any2opnd(expp, oper); + if (oper != PLUSPLUS && oper != MINMIN) + any2opnd(expp, oper); switch (oper) { case '*': /* 3.3.3.2 */ diff --git a/lang/cem/cemcom.ansi/domacro.c b/lang/cem/cemcom.ansi/domacro.c index 8f6f0b265..f6b5270ad 100644 --- a/lang/cem/cemcom.ansi/domacro.c +++ b/lang/cem/cemcom.ansi/domacro.c @@ -604,6 +604,7 @@ get_text(formals, length) c = GetChar(); repl->r_ptr = repl->r_text = Malloc(repl->r_size = ITEXTSIZE); + *repl->r_ptr = '\0'; while ((c != EOI) && (class(c) != STNL)) { if (BLANK(c)) { if (!blank++) add2repl(repl, ' '); diff --git a/lang/cem/cemcom.ansi/expression.g b/lang/cem/cemcom.ansi/expression.g index 2aad3bbcb..53933cf8a 100644 --- a/lang/cem/cemcom.ansi/expression.g +++ b/lang/cem/cemcom.ansi/expression.g @@ -92,15 +92,14 @@ postfix_expression(register struct expr **expp;) | [ '.' | ARROW ] { oper = DOT; } identifier(&idf) { ch3sel(expp, oper, idf); } - ]* - [ + | [ PLUSPLUS { oper = POSTINCR; } | MINMIN { oper = POSTDECR; } ] { ch3incr(expp, oper); } - ]? + ]* ; parameter_list(struct expr **expp;) diff --git a/lang/cem/cemcom.ansi/replace.c b/lang/cem/cemcom.ansi/replace.c index d4a0c8927..7fae3a96d 100644 --- a/lang/cem/cemcom.ansi/replace.c +++ b/lang/cem/cemcom.ansi/replace.c @@ -549,6 +549,7 @@ macro2buffer(repl, idf, args) int err = 0; char *stringify(); + ASSERT(ptr[idf->id_macro->mc_length] == '\0'); while (*ptr) { if (*ptr == '\'' || *ptr == '"') { register int delim = *ptr;