diff --git a/lang/cem/cemcom.ansi/BigPars b/lang/cem/cemcom.ansi/BigPars index c00a753dd..c8c22d317 100644 --- a/lang/cem/cemcom.ansi/BigPars +++ b/lang/cem/cemcom.ansi/BigPars @@ -124,6 +124,7 @@ !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ +#undef UNSIGNED_ARITH unsigned arith !File: static.h diff --git a/lang/cem/cemcom.ansi/LLlex.c b/lang/cem/cemcom.ansi/LLlex.c index a997ddafe..1f9be7f5d 100644 --- a/lang/cem/cemcom.ansi/LLlex.c +++ b/lang/cem/cemcom.ansi/LLlex.c @@ -535,7 +535,7 @@ string_token(nm, stop_char, plen) ch = quoted(GetChar()); str[pos++] = ch; if (pos == str_size) - str = Srealloc(str, (unsigned) (str_size += RSTRSIZE)); + str = Realloc(str, (unsigned) (str_size += RSTRSIZE)); ch = GetChar(); } str[pos++] = '\0'; /* for filenames etc. */ diff --git a/lang/cem/cemcom.ansi/SmallPars b/lang/cem/cemcom.ansi/SmallPars index b5d103fd4..9ae5e0fbf 100644 --- a/lang/cem/cemcom.ansi/SmallPars +++ b/lang/cem/cemcom.ansi/SmallPars @@ -124,6 +124,7 @@ !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ +#undef UNSIGNED_ARITH unsigned arith !File: static.h diff --git a/lang/cem/cemcom.ansi/ch3.c b/lang/cem/cemcom.ansi/ch3.c index c8ceab339..25ad70b5a 100644 --- a/lang/cem/cemcom.ansi/ch3.c +++ b/lang/cem/cemcom.ansi/ch3.c @@ -416,14 +416,14 @@ check_pseudoproto(pl, opl) if (pl->pl_flag & PL_ELLIPSIS) { error("illegal ellipsis terminator"); - return 2; + return 0; } if (opl->pl_flag & PL_VOID) { if (!(pl->pl_flag & PL_VOID)) error("function is defined without parameters"); pl->pl_flag |= PL_ERRGIVEN; opl->pl_flag |= PL_ERRGIVEN; - return 2; + return 0; } while (pl && opl) { if (!equal_type(pl->pl_type, opl->pl_type, 0)) { @@ -433,14 +433,14 @@ check_pseudoproto(pl, opl) opl->pl_idf->id_text); pl->pl_flag |= PL_ERRGIVEN; opl->pl_flag |= PL_ERRGIVEN; - retval = 2; + retval = 0; } pl = pl->next; opl = opl->next; } if (pl || opl) { error("incorrect number of parameters"); - retval = 2; + retval = 0; } return retval; } @@ -468,10 +468,9 @@ legal_mixture(tp, otp) if (pl) error("illegal ellipsis terminator"); else error("ellipsis terminator in previous (prototype) declaration"); + prot->pl_flag |= PL_ERRGIVEN; } - prot->pl_flag |= PL_ERRGIVEN; - prot = prot->next; - return 2; + return 0; } while (prot) { /* if (!(prot->pl_flag & PL_ELLIPSIS)) {} */ @@ -481,7 +480,7 @@ legal_mixture(tp, otp) error("illegal %s parameter in %sdeclaration", symbol2str(fund), (opl ? "previous (prototype) " : "" )); prot->pl_flag |= PL_ERRGIVEN; - retval = 2; + retval = 0; } prot = prot->next; } @@ -500,10 +499,8 @@ equal_proto(pl, opl) */ while ( pl && opl) { - if ((pl->pl_flag & ~PL_ERRGIVEN) != (opl->pl_flag & ~PL_ERRGIVEN)) - return 0; - - if (!equal_type(pl->pl_type, opl->pl_type, 0)) + if ((pl->pl_flag & ~PL_ERRGIVEN) != (opl->pl_flag & ~PL_ERRGIVEN) || + !equal_type(pl->pl_type, opl->pl_type, 0)) return 0; pl = pl->next; @@ -519,7 +516,6 @@ struct type *tp; register struct sdef *sdf; ASSERT(tp); - if (!tp) return 0; if (tp->tp_typequal & TQ_CONST) return 1; sdf = tp->tp_sdef; while (sdf) { diff --git a/lang/cem/cemcom.ansi/ch3bin.c b/lang/cem/cemcom.ansi/ch3bin.c index 61601bf33..3a12327f8 100644 --- a/lang/cem/cemcom.ansi/ch3bin.c +++ b/lang/cem/cemcom.ansi/ch3bin.c @@ -35,13 +35,15 @@ ch3bin(expp, oper, expr) /* apply binary operator oper between *expp and expr. NB: don't swap operands if op is one of the op= operators!!! */ + register struct type *expp_tp; any2opnd(expp, oper); + expp_tp = (*expp)->ex_type; any2opnd(&expr, oper); switch (oper) { case '[': /* 3.3.2.1 */ /* indexing follows the commutative laws */ - switch ((*expp)->ex_type->tp_fund) { + switch (expp_tp->tp_fund) { case POINTER: case ARRAY: break; @@ -57,7 +59,7 @@ ch3bin(expp, oper, expr) default: expr_error(*expp, "indexing an object of type %s", - symbol2str((*expp)->ex_type->tp_fund)); + symbol2str(expp_tp->tp_fund)); return; } break; @@ -67,27 +69,28 @@ ch3bin(expp, oper, expr) break; case '(': /* 3.3.2.2 */ - if ( (*expp)->ex_type->tp_fund == POINTER && - (*expp)->ex_type->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; } - if ((*expp)->ex_type->tp_fund != FUNCTION) { + if (expp_tp->tp_fund != FUNCTION) { expr_error(*expp, "call of non-function (%s)", - symbol2str((*expp)->ex_type->tp_fund)); + 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); } else - *expp = new_oper((*expp)->ex_type->tp_up, + *expp = new_oper(expp_tp->tp_up, *expp, '(', expr); (*expp)->ex_flags |= EX_SIDEEFFECTS; break; case PARCOMMA: /* 3.3.2.2 */ - if ((*expp)->ex_type->tp_fund == FUNCTION) + if (expp_tp->tp_fund == FUNCTION) function2pointer(*expp); *expp = new_oper(expr->ex_type, *expp, PARCOMMA, expr); break; @@ -128,7 +131,7 @@ ch3bin(expp, oper, expr) case PLUSAB: case POSTINCR: case PLUSPLUS: - if ((*expp)->ex_type->tp_fund == POINTER) { + if (expp_tp->tp_fund == POINTER) { pointer_arithmetic(expp, oper, &expr); if (expr->ex_type->tp_size != (*expp)->ex_type->tp_size) ch3cast(&expr, CAST, (*expp)->ex_type); @@ -147,7 +150,7 @@ ch3bin(expp, oper, expr) case MINAB: case POSTDECR: case MINMIN: - if ((*expp)->ex_type->tp_fund == POINTER) { + if (expp_tp->tp_fund == POINTER) { if (expr->ex_type->tp_fund == POINTER) pntminuspnt(expp, oper, expr); else { @@ -230,10 +233,10 @@ ch3bin(expp, oper, expr) break; case ':': - if ( is_struct_or_union((*expp)->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)->ex_type, expr->ex_type, 0)) + if (!equal_type(expp_tp, expr->ex_type, 0)) expr_error(*expp, "illegal balance"); } else diff --git a/lang/cem/cemcom.ansi/cstoper.c b/lang/cem/cemcom.ansi/cstoper.c index b2c185ea5..0162a16a5 100644 --- a/lang/cem/cemcom.ansi/cstoper.c +++ b/lang/cem/cemcom.ansi/cstoper.c @@ -46,6 +46,9 @@ cstbin(expp, oper, expr) break; } if (uns) { +#ifdef UNSIGNED_ARITH + o1 /= (UNSIGNED_ARITH) o2; +#else /* this is more of a problem than you might think on C compilers which do not have unsigned arith (== long (probably)). @@ -73,6 +76,7 @@ cstbin(expp, oper, expr) rem >= o2 for o2 <= max_arith */ } +#endif } else o1 /= o2; @@ -86,6 +90,9 @@ cstbin(expp, oper, expr) break; } if (uns) { +#ifdef UNSIGNED_ARITH + o1 %= (UNSIGNED_ARITH) o2; +#else if (o2 & arith_sign) {/* o2 > max_arith */ o1 = (o1 >= 0 || o1 < o2) ? o1 : o1 - o2; /* this is the unsigned test @@ -105,6 +112,7 @@ cstbin(expp, oper, expr) rem = 2 * hrem + bit; o1 = (rem < 0 || rem >= o2) ? rem - o2 : rem; } +#endif } else o1 %= o2; @@ -122,12 +130,10 @@ cstbin(expp, oper, expr) if (o2 == 0) break; if (uns) { - o1 >>= 1; - o1 &= ~arith_sign; - o1 >>= (o2-1); + o1 = (o1 >> 1) & ~arith_sign; + o1 >>= (o2 - 1); } - else - o1 >>= o2; + else o1 >>= o2; break; case '<': { @@ -139,10 +145,14 @@ cstbin(expp, oper, expr) /* Fall through */ case '>': if (uns) { +#ifdef UNSIGNED_ARITH + o1 = (UNSIGNED_ARITH) o1 > (UNSIGNED_ARITH) o2; +#else o1 = (o1 & arith_sign ? (o2 & arith_sign ? o1 > o2 : 1) : (o2 & arith_sign ? 0 : o1 > o2) ); +#endif } else o1 = o1 > o2; @@ -157,10 +167,14 @@ cstbin(expp, oper, expr) /* Fall through */ case GREATEREQ: if (uns) { +#ifdef UNSIGNED_ARITH + o1 = (UNSIGNED_ARITH) o1 >= (UNSIGNED_ARITH) o2; +#else o1 = (o1 & arith_sign ? (o2 & arith_sign ? o1 >= o2 : 1) : (o2 & arith_sign ? 0 : o1 >= o2) ); +#endif } else o1 = o1 >= o2; @@ -219,8 +233,7 @@ cut_size(expr) if (remainder != 0 && remainder != ~full_mask[size]) if (!ResultKnown) expr_warning(expr,"overflow in constant expression"); - o1 <<= nbits; /* ??? */ - o1 >>= nbits; + o1 = (o1 << nbits) >> nbits; /* ??? */ } expr->VL_VALUE = o1; } diff --git a/lang/cem/cemcom.ansi/domacro.c b/lang/cem/cemcom.ansi/domacro.c index bb38e8f04..6b02fe9e8 100644 --- a/lang/cem/cemcom.ansi/domacro.c +++ b/lang/cem/cemcom.ansi/domacro.c @@ -592,7 +592,7 @@ get_text(formals, length) do { /* being careful, as ever */ if (pos+3 >= text_size) - text = Srealloc(text, + text = Realloc(text, (unsigned) (text_size += RTEXTSIZE)); text[pos++] = c; if (c == '\\') @@ -606,7 +606,7 @@ get_text(formals, length) if (c == '/') { c = GetChar(); if (pos+1 >= text_size) - text = Srealloc(text, + text = Realloc(text, (unsigned) (text_size += RTEXTSIZE)); if (c == '*') { skipcomment(); @@ -633,7 +633,7 @@ get_text(formals, length) if (n = find_name(id_buf, formals)) { /* construct the formal parameter mark */ if (pos+1 >= text_size) - text = Srealloc(text, + text = Realloc(text, (unsigned) (text_size += RTEXTSIZE)); text[pos++] = FORMALP | (char) n; } @@ -641,7 +641,7 @@ get_text(formals, length) register char *ptr = &id_buf[0]; while (pos + id_size >= text_size) - text = Srealloc(text, + text = Realloc(text, (unsigned) (text_size += RTEXTSIZE)); while (text[pos++] = *ptr++) /* EMPTY */ ; @@ -650,7 +650,7 @@ get_text(formals, length) } else { if (pos+1 >= text_size) - text = Srealloc(text, + text = Realloc(text, (unsigned) (text_size += RTEXTSIZE)); text[pos++] = c; c = GetChar(); @@ -697,7 +697,7 @@ GetIdentifier(skiponerr) int skiponerr; /* skip the rest of the line on error */ { /* returns a pointer to the descriptor of the identifier that is - read from the input stream. When the input doe not contain + read from the input stream. When the input does not contain an identifier, the rest of the line is skipped when skiponerr is on, and a null-pointer is returned. The substitution of macros is disabled. @@ -720,26 +720,23 @@ domacro() EoiForNewline = 1; if ((tok = GetToken(&tk)) == IDENTIFIER) { - if (strcmp(tk.tk_idf->id_text, "line") - && strcmp(tk.tk_idf->id_text, "pragma")) { - error("illegal # line"); - SkipToNewLine(); - return; + if (! strcmp(tk.tk_idf->id_text, "line")) { + tok = GetToken(&tk); + if (tok == INTEGER) { + do_line((unsigned int) tk.tk_ival); + EoiForNewline = 0; + return; + } } - else if ( !strcmp(tk.tk_idf->id_text, "pragma")) { + else if (! strcmp(tk.tk_idf->id_text, "pragma")) { do_pragma(); EoiForNewline = 0; return; } - tok = GetToken(&tk); } - if (tok != INTEGER) { - error("illegal # line"); - SkipToNewLine(); - return; - } - do_line((unsigned int) tk.tk_ival); + error("illegal # line"); EoiForNewline = 0; + SkipToNewLine(); } #endif NOPP diff --git a/lang/cem/cemcom.ansi/expression.g b/lang/cem/cemcom.ansi/expression.g index dd6a62416..f06506fd9 100644 --- a/lang/cem/cemcom.ansi/expression.g +++ b/lang/cem/cemcom.ansi/expression.g @@ -67,7 +67,7 @@ string(register struct expr **expp;) */ if (dot.tk_fund != fund) warning("illegal pasting of string literals"); - str = Srealloc(str, (unsigned) (--len + dot.tk_len)); + str = Realloc(str, (unsigned) (--len + dot.tk_len)); for (i = 0; i < dot.tk_len; i++) str[len++] = dot.tk_bts[i]; } diff --git a/lang/cem/cemcom.ansi/fltcstoper.c b/lang/cem/cemcom.ansi/fltcstoper.c index 690ba7c42..f126cdb0d 100644 --- a/lang/cem/cemcom.ansi/fltcstoper.c +++ b/lang/cem/cemcom.ansi/fltcstoper.c @@ -31,7 +31,7 @@ fltcstbin(expp, oper, expr) */ flt_arith o1, o2; int compar = 0; - arith cmpval; + int cmpval; o1 = (*expp)->FL_ARITH; o2 = expr->FL_ARITH; @@ -103,7 +103,7 @@ fltcstbin(expp, oper, expr) if ((*expp)->FL_VALUE) free((*expp)->FL_VALUE); (*expp)->FL_VALUE = 0; if (compar) { - fill_int_expr(*expp, cmpval, INT); + fill_int_expr(*expp, (arith)cmpval, INT); } else { (*expp)->FL_ARITH = o1; } diff --git a/lang/cem/cemcom.ansi/idf.c b/lang/cem/cemcom.ansi/idf.c index dabf7bcac..1c17c2091 100644 --- a/lang/cem/cemcom.ansi/idf.c +++ b/lang/cem/cemcom.ansi/idf.c @@ -412,12 +412,10 @@ global_redecl(idf, new_sc, tp) in storage class. */ register struct def *def = idf->id_def; - int retval; - if (!(retval = equal_type(tp, def->df_type, 0))) + if (!equal_type(tp, def->df_type, 0)) error("redeclaration of %s with different type", idf->id_text); - else if (retval == 1) - update_proto(tp, def->df_type); + else update_proto(tp, def->df_type); if (tp->tp_fund == ARRAY) { /* Multiple array declaration; this may be interesting */ if (tp->tp_size < 0) { /* new decl has [] */ diff --git a/lang/cem/cemcom.ansi/init.c b/lang/cem/cemcom.ansi/init.c index 212ce68ac..5b30f95a3 100644 --- a/lang/cem/cemcom.ansi/init.c +++ b/lang/cem/cemcom.ansi/init.c @@ -34,8 +34,6 @@ struct mkey { {0, K_UNKNOWN} }; -char *strcpy(); - init_pp() { static char *months[12] = { diff --git a/lang/cem/cemcom.ansi/main.c b/lang/cem/cemcom.ansi/main.c index e940aaf9d..e2e59077d 100644 --- a/lang/cem/cemcom.ansi/main.c +++ b/lang/cem/cemcom.ansi/main.c @@ -265,12 +265,6 @@ init() pointer arithmetic type which is equal to either int_type or long_type, depending on the pointer_size */ - if ((int)pointer_size == (int)word_size) - pa_type = word_type; - else - if ((int)pointer_size == (int)short_size) - pa_type = short_type; - else if ((int)pointer_size == (int)int_size) pa_type = int_type; else @@ -283,6 +277,8 @@ init() fatal("int_size and word_size are not equal"); if ((int)short_size > (int)int_size || (int)int_size > (int)long_size) fatal("sizes of short/int/long decreasing"); + if ((int)float_size > (int)double_size || (int)double_size > (int)lngdbl_size) + fatal("sizes of float/double/long double decreasing"); /* Build a type for function returning int (3.3.2.2) */ funint_type = construct_type(FUNCTION, int_type, 0, (arith)0, NO_PROTO); diff --git a/lang/cem/cemcom.ansi/proto.c b/lang/cem/cemcom.ansi/proto.c index 4fc7d641f..a090073b7 100644 --- a/lang/cem/cemcom.ansi/proto.c +++ b/lang/cem/cemcom.ansi/proto.c @@ -62,8 +62,8 @@ add_proto(pl, ds, dc, level) later on it's decided whether they were prototypes or actual declarations. */ - register struct idf *idf; - register struct def *def = (struct def *)0; + register struct idf *idf = dc->dc_idf; + register struct def *def = idf ? idf->id_def : (struct def *)0; register int sc = ds->ds_sc; register struct type *type; char formal_array = 0; @@ -71,8 +71,6 @@ add_proto(pl, ds, dc, level) ASSERT(ds->ds_type != (struct type *)0); pl->pl_flag = PL_FORMAL; - if ((idf = dc->dc_idf) != (struct idf *)0) - def = idf->id_def; type = declare_type(ds->ds_type, dc); if (type->tp_size < (arith)0 && actual_declaration(sc, type)) { extern char *symbol2str(); @@ -159,7 +157,7 @@ gettag(tp, idpp) struct type *tp; struct idf **idpp; { - struct tag *tg; + struct tag *tg = (struct tag *)0; while (tp->tp_up) tp = tp->tp_up; *idpp = tp->tp_idf; @@ -167,7 +165,6 @@ struct idf **idpp; case ENUM: tg = tp->tp_idf->id_enum; break; case UNION: case STRUCT: tg = tp->tp_idf->id_struct; break; - default: return (struct tag *)0; } return tg; }