!File: spec_arith.h
/* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */
+#undef UNSIGNED_ARITH unsigned arith
!File: static.h
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. */
!File: spec_arith.h
/* describes internal compiler arithmetics */
#undef SPECIAL_ARITHMETICS /* something different from native long */
+#undef UNSIGNED_ARITH unsigned arith
!File: static.h
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)) {
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;
}
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)) {} */
error("illegal %s parameter in %sdeclaration",
symbol2str(fund), (opl ? "previous (prototype) " : "" ));
prot->pl_flag |= PL_ERRGIVEN;
- retval = 2;
+ retval = 0;
}
prot = prot->next;
}
*/
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;
register struct sdef *sdf;
ASSERT(tp);
- if (!tp) return 0;
if (tp->tp_typequal & TQ_CONST) return 1;
sdf = tp->tp_sdef;
while (sdf) {
/* 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;
default:
expr_error(*expp,
"indexing an object of type %s",
- symbol2str((*expp)->ex_type->tp_fund));
+ symbol2str(expp_tp->tp_fund));
return;
}
break;
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;
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);
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 {
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
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)).
rem >= o2 for o2 <= max_arith
*/
}
+#endif
}
else
o1 /= o2;
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
rem = 2 * hrem + bit;
o1 = (rem < 0 || rem >= o2) ? rem - o2 : rem;
}
+#endif
}
else
o1 %= o2;
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 '<':
{
/* 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;
/* 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;
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;
}
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 == '\\')
if (c == '/') {
c = GetChar();
if (pos+1 >= text_size)
- text = Srealloc(text,
+ text = Realloc(text,
(unsigned) (text_size += RTEXTSIZE));
if (c == '*') {
skipcomment();
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;
}
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 */ ;
}
else {
if (pos+1 >= text_size)
- text = Srealloc(text,
+ text = Realloc(text,
(unsigned) (text_size += RTEXTSIZE));
text[pos++] = c;
c = GetChar();
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.
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
*/
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];
}
*/
flt_arith o1, o2;
int compar = 0;
- arith cmpval;
+ int cmpval;
o1 = (*expp)->FL_ARITH;
o2 = expr->FL_ARITH;
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;
}
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 [] */
{0, K_UNKNOWN}
};
-char *strcpy();
-
init_pp()
{
static char *months[12] = {
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
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);
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;
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();
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;
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;
}