handle void properly, avoid 0-alignments, handle #if defined(..)

This commit is contained in:
ceriel 1986-12-01 10:00:23 +00:00
parent 36adbe54a5
commit ad40a77afd
16 changed files with 187 additions and 148 deletions

View file

@ -267,7 +267,7 @@ go_on: /* rescan, the following character has been read */
if (idef->id_macro && ReplaceMacros && replace(idef)) if (idef->id_macro && ReplaceMacros && replace(idef))
/* macro replacement should be performed */ /* macro replacement should be performed */
goto again; goto again;
if (UnknownIdIsZero) { if (UnknownIdIsZero && idef->id_reserved != SIZEOF) {
ptok->tk_ival = (arith)0; ptok->tk_ival = (arith)0;
ptok->tk_fund = INT; ptok->tk_fund = INT;
return ptok->tk_symb = INTEGER; return ptok->tk_symb = INTEGER;

View file

@ -464,7 +464,7 @@ any2opnd(expp, oper)
#ifndef NOBITFIELD #ifndef NOBITFIELD
field2arith(expp) field2arith(expp)
struct expr **expp; register struct expr **expp;
{ {
/* The expression to extract the bitfield value from the /* The expression to extract the bitfield value from the
memory word is put in the tree. memory word is put in the tree.
@ -500,7 +500,7 @@ field2arith(expp)
take care of the first byte the fl_value pointer points to. take care of the first byte the fl_value pointer points to.
*/ */
switch_sign_fp(expr) switch_sign_fp(expr)
struct expr *expr; register struct expr *expr;
{ {
if (*(expr->FL_VALUE) == '-') if (*(expr->FL_VALUE) == '-')
++(expr->FL_VALUE); ++(expr->FL_VALUE);

View file

@ -128,7 +128,7 @@ ch7sel(expp, oper, idf)
} }
ch7incr(expp, oper) ch7incr(expp, oper)
register struct expr **expp; struct expr **expp;
{ {
/* The monadic prefix/postfix incr/decr operator oper is /* The monadic prefix/postfix incr/decr operator oper is
applied to *expp. applied to *expp.

View file

@ -20,6 +20,9 @@ extern char *symbol2str();
depending on the constancy of the operands. depending on the constancy of the operands.
*/ */
#define commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 1)
#define non_commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, 0)
ch7bin(expp, oper, expr) ch7bin(expp, oper, expr)
register struct expr **expp; register struct expr **expp;
struct expr *expr; struct expr *expr;
@ -82,24 +85,28 @@ ch7bin(expp, oper, expr)
break; break;
case '%': case '%':
case MODAB: case MODAB:
case ANDAB:
case XORAB:
case ORAB:
opnd2integral(expp, oper); opnd2integral(expp, oper);
opnd2integral(&expr, oper); opnd2integral(&expr, oper);
fund = arithbalance(expp, oper, &expr); /* Fall through */
non_commutative_binop(expp, oper, expr);
break;
case '/': case '/':
case DIVAB: case DIVAB:
fund = arithbalance(expp, oper, &expr);
non_commutative_binop(expp, oper, expr);
break;
case '*':
fund = arithbalance(expp, oper, &expr);
commutative_binop(expp, oper, expr);
break;
case TIMESAB: case TIMESAB:
fund = arithbalance(expp, oper, &expr); fund = arithbalance(expp, oper, &expr);
non_commutative_binop(expp, oper, expr); non_commutative_binop(expp, oper, expr);
break; break;
case '&':
case '^':
case '|':
opnd2integral(expp, oper);
opnd2integral(&expr, oper);
/* Fall through */
case '*':
fund = arithbalance(expp, oper, &expr);
commutative_binop(expp, oper, expr);
break;
case '+': case '+':
if (expr->ex_type->tp_fund == POINTER) { /* swap operands */ if (expr->ex_type->tp_fund == POINTER) { /* swap operands */
struct expr *etmp = expr; struct expr *etmp = expr;
@ -161,41 +168,27 @@ ch7bin(expp, oper, expr)
non_commutative_binop(expp, oper, expr); non_commutative_binop(expp, oper, expr);
(*expp)->ex_type = int_type; (*expp)->ex_type = int_type;
break; break;
case '&':
case '^':
case '|':
opnd2integral(expp, oper);
opnd2integral(&expr, oper);
fund = arithbalance(expp, oper, &expr);
commutative_binop(expp, oper, expr);
break;
case ANDAB:
case XORAB:
case ORAB:
opnd2integral(expp, oper);
opnd2integral(&expr, oper);
fund = arithbalance(expp, oper, &expr);
non_commutative_binop(expp, oper, expr);
break;
case AND: case AND:
case OR: case OR:
opnd2test(expp, oper); opnd2test(expp, oper);
opnd2test(&expr, oper); opnd2test(&expr, oper);
if (is_cp_cst(*expp)) { if (is_cp_cst(*expp)) {
struct expr *ex = *expp; register struct expr *ex = *expp;
/* the following condition is a short-hand for /* the following condition is a short-hand for
((oper == AND) && o1) || ((oper == OR) && !o1) ((oper == AND) && o1) || ((oper == OR) && !o1)
where o1 == (*expp)->VL_VALUE; where o1 == (*expp)->VL_VALUE;
and ((oper == AND) || (oper == OR)) and ((oper == AND) || (oper == OR))
*/ */
if ((oper == AND) == ((*expp)->VL_VALUE != (arith)0)) if ((oper == AND) == (ex->VL_VALUE != (arith)0))
*expp = expr; *expp = expr;
else { else {
ex->ex_flags |= expr->ex_flags;
free_expression(expr); free_expression(expr);
*expp = intexpr((arith)((oper == AND) ? 0 : 1), *expp = intexpr((arith)((oper == AND) ? 0 : 1),
INT); INT);
} }
(*expp)->ex_flags |= ex->ex_flags;
free_expression(ex); free_expression(ex);
} }
else else
@ -205,8 +198,10 @@ ch7bin(expp, oper, expr)
where o2 == expr->VL_VALUE where o2 == expr->VL_VALUE
and ((oper == AND) || (oper == OR)) and ((oper == AND) || (oper == OR))
*/ */
if ((oper == AND) == (expr->VL_VALUE != (arith)0)) if ((oper == AND) == (expr->VL_VALUE != (arith)0)) {
(*expp)->ex_flags |= expr->ex_flags;
free_expression(expr); free_expression(expr);
}
else { else {
if (oper == OR) if (oper == OR)
expr->VL_VALUE = (arith)1; expr->VL_VALUE = (arith)1;
@ -270,31 +265,22 @@ pntminuspnt(expp, oper, expr)
ch7cast(expp, CAST, int_type); /* result will be an integer expr */ ch7cast(expp, CAST, int_type); /* result will be an integer expr */
} }
non_commutative_binop(expp, oper, expr) mk_binop(expp, oper, expr, commutative)
register struct expr **expp, *expr; register struct expr **expp, *expr;
{ {
/* Constructs in *expp the operation indicated by the operands. /* Constructs in *expp the operation indicated by the operands.
"oper" is a non-commutative operator "commutative" indicates wether "oper" is a commutative
operator.
*/ */
if (is_cp_cst(expr) && is_cp_cst(*expp)) register struct expr *ex = *expp;
cstbin(expp, oper, expr);
else
*expp = new_oper((*expp)->ex_type, *expp, oper, expr);
}
commutative_binop(expp, oper, expr) if (is_cp_cst(expr) && is_cp_cst(ex))
register struct expr **expp, *expr;
{
/* Constructs in *expp the operation indicated by the operands.
"oper" is a commutative operator
*/
if (is_cp_cst(expr) && is_cp_cst(*expp))
cstbin(expp, oper, expr); cstbin(expp, oper, expr);
else else {
if ((*expp)->ex_depth > expr->ex_depth) *expp = (commutative && expr->ex_depth >= ex->ex_depth) ?
*expp = new_oper((*expp)->ex_type, *expp, oper, expr); new_oper(ex->ex_type, expr, oper, ex) :
else new_oper(ex->ex_type, ex, oper, expr);
*expp = new_oper((*expp)->ex_type, expr, oper, *expp); }
} }
pointer_arithmetic(expp1, oper, expp2) pointer_arithmetic(expp1, oper, expp2)

View file

@ -151,9 +151,9 @@ ch7mon(oper, expp)
warning("sizeof formal array %s is sizeof pointer!", warning("sizeof formal array %s is sizeof pointer!",
(*expp)->VL_IDF->id_text); (*expp)->VL_IDF->id_text);
expr = intexpr(size_of_type((*expp)->ex_type, "object"), INT); expr = intexpr(size_of_type((*expp)->ex_type, "object"), INT);
expr->ex_flags |= EX_SIZEOF;
free_expression(*expp); free_expression(*expp);
*expp = expr; *expp = expr;
(*expp)->ex_flags |= EX_SIZEOF;
break; break;
} }
} }

View file

@ -437,8 +437,13 @@ bss(idf)
/* Since bss() is only called if df_alloc is non-zero, and /* Since bss() is only called if df_alloc is non-zero, and
since df_alloc is only non-zero if size >= 0, we have: since df_alloc is only non-zero if size >= 0, we have:
*/ */
/* but we already gave a warning at the declaration of the
array. Besides, the message given here does not apply to
voids
if (options['R'] && size == 0) if (options['R'] && size == 0)
warning("actual array of size 0"); warning("actual array of size 0");
*/
C_df_dnam(idf->id_text); C_df_dnam(idf->id_text);
C_bss_cst(align(size, word_align), (arith)0, 1); C_bss_cst(align(size, word_align), (arith)0, 1);
} }
@ -455,7 +460,9 @@ formal_cvt(df)
(tp->tp_fund == CHAR || tp->tp_fund == SHORT) (tp->tp_fund == CHAR || tp->tp_fund == SHORT)
) { ) {
C_lol(df->df_address); C_lol(df->df_address);
/* conversion(int_type, df->df_type); ??? */ /* conversion(int_type, df->df_type); ???
No, you can't do this on the stack! (CJ)
*/
C_lal(df->df_address); C_lal(df->df_address);
C_sti(tp->tp_size); C_sti(tp->tp_size);
df->df_register = REG_NONE; df->df_register = REG_NONE;

View file

@ -120,15 +120,13 @@ cstbin(expp, oper, expr)
o1 >>= o2; o1 >>= o2;
break; break;
case '<': case '<':
if (uns) { {
o1 = (o1 & mach_long_sign ? arith tmp = o1;
(o2 & mach_long_sign ? o1 < o2 : 0) :
(o2 & mach_long_sign ? 1 : o1 < o2) o1 = o2;
); o2 = tmp;
} }
else /* Fall through */
o1 = o1 < o2;
break;
case '>': case '>':
if (uns) { if (uns) {
o1 = (o1 & mach_long_sign ? o1 = (o1 & mach_long_sign ?
@ -140,15 +138,13 @@ cstbin(expp, oper, expr)
o1 = o1 > o2; o1 = o1 > o2;
break; break;
case LESSEQ: case LESSEQ:
if (uns) { {
o1 = (o1 & mach_long_sign ? arith tmp = o1;
(o2 & mach_long_sign ? o1 <= o2 : 0) :
(o2 & mach_long_sign ? 1 : o1 <= o2) o1 = o2;
); o2 = tmp;
} }
else /* Fall through */
o1 = o1 <= o2;
break;
case GREATEREQ: case GREATEREQ:
if (uns) { if (uns) {
o1 = (o1 & mach_long_sign ? o1 = (o1 & mach_long_sign ?

View file

@ -101,7 +101,6 @@ check_array_subscript(expr)
else else
if (size == 0) { if (size == 0) {
warning("empty array declaration"); warning("empty array declaration");
expr->VL_VALUE = (arith)-1;
} }
else else
if (size & ~max_unsigned) { /* absolutely ridiculous */ if (size & ~max_unsigned) { /* absolutely ridiculous */

View file

@ -39,8 +39,8 @@ do_decspecs(ds)
ds->ds_sc != REGISTER){ ds->ds_sc != REGISTER){
extern char *symbol2str(); extern char *symbol2str();
error("%s formal illegal", symbol2str(ds->ds_sc)); error("%s formal illegal", symbol2str(ds->ds_sc));
ds->ds_sc = FORMAL;
} }
ds->ds_sc = FORMAL;
} }
/* The tests concerning types require a full knowledge of the /* The tests concerning types require a full knowledge of the
type and will have to be postponed to declare_idf. type and will have to be postponed to declare_idf.

View file

@ -96,14 +96,16 @@ EVAL(expr, val, code, true_label, false_label)
if (tp->tp_fund == ERRONEOUS) /* stop immediately */ if (tp->tp_fund == ERRONEOUS) /* stop immediately */
break; break;
if (tp->tp_fund == VOID)
gencode = 0;
switch (oper) { switch (oper) {
case '+': case '+':
/* We have the following possibilities : /* We have the following possibilities :
int + int, pointer + int, pointer + long, int + int, pointer + int, pointer + long,
long + long, double + double long + long, double + double
*/ */
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) { if (gencode) {
switch (tp->tp_fund) { switch (tp->tp_fund) {
case INT: case INT:
@ -128,7 +130,7 @@ EVAL(expr, val, code, true_label, false_label)
break; break;
case '-': case '-':
if (left == 0) { /* unary */ if (left == 0) { /* unary */
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) { if (gencode) {
switch (tp->tp_fund) { switch (tp->tp_fund) {
case INT: case INT:
@ -151,8 +153,8 @@ EVAL(expr, val, code, true_label, false_label)
int - int, pointer - int, pointer - long, int - int, pointer - int, pointer - long,
pointer - pointer, long - long, double - double pointer - pointer, long - long, double - double
*/ */
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (!gencode) if (!gencode)
break; break;
switch (tp->tp_fund) { switch (tp->tp_fund) {
@ -182,10 +184,10 @@ EVAL(expr, val, code, true_label, false_label)
break; break;
case '*': case '*':
if (left == 0) /* unary */ if (left == 0) /* unary */
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
else { /* binary */ else { /* binary */
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) if (gencode)
switch (tp->tp_fund) { switch (tp->tp_fund) {
case INT: case INT:
@ -207,8 +209,8 @@ EVAL(expr, val, code, true_label, false_label)
} }
break; break;
case '/': case '/':
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) if (gencode)
switch (tp->tp_fund) { switch (tp->tp_fund) {
case INT: case INT:
@ -229,8 +231,8 @@ EVAL(expr, val, code, true_label, false_label)
} }
break; break;
case '%': case '%':
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG); ASSERT(tp->tp_fund==INT || tp->tp_fund==LONG);
if (gencode) if (gencode)
if (tp->tp_unsigned) if (tp->tp_unsigned)
@ -239,8 +241,8 @@ EVAL(expr, val, code, true_label, false_label)
C_rmi(tp->tp_size); C_rmi(tp->tp_size);
break; break;
case LEFT: case LEFT:
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) if (gencode)
if (tp->tp_unsigned) if (tp->tp_unsigned)
C_slu(tp->tp_size); C_slu(tp->tp_size);
@ -248,8 +250,8 @@ EVAL(expr, val, code, true_label, false_label)
C_sli(tp->tp_size); C_sli(tp->tp_size);
break; break;
case RIGHT: case RIGHT:
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) if (gencode)
if (tp->tp_unsigned) if (tp->tp_unsigned)
C_sru(tp->tp_size); C_sru(tp->tp_size);
@ -262,8 +264,8 @@ EVAL(expr, val, code, true_label, false_label)
case GREATEREQ: case GREATEREQ:
case EQUAL: case EQUAL:
case NOTEQUAL: case NOTEQUAL:
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) { if (gencode) {
/* The operands have the same type */ /* The operands have the same type */
arith size = left->ex_type->tp_size; arith size = left->ex_type->tp_size;
@ -312,8 +314,8 @@ EVAL(expr, val, code, true_label, false_label)
case '|': case '|':
case '^': case '^':
/* both operands should have type int */ /* both operands should have type int */
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) { if (gencode) {
arith size = tp->tp_size; arith size = tp->tp_size;
@ -332,23 +334,26 @@ EVAL(expr, val, code, true_label, false_label)
} }
} }
break; break;
case '=': case '=': {
int newcode = tp->tp_size > 0; /* CJ */
#ifndef NOBITFIELD #ifndef NOBITFIELD
if (left->ex_type->tp_fund == FIELD) { if (left->ex_type->tp_fund == FIELD) {
eval_field(expr, code); eval_field(expr, gencode);
break; break;
} }
#endif NOBITFIELD #endif NOBITFIELD
EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); EVAL(right, RVAL, newcode, NO_LABEL, NO_LABEL);
if (gencode) if (gencode)
C_dup(ATW(tp->tp_size)); C_dup(ATW(tp->tp_size));
if (left->ex_class != Value) { if (left->ex_class != Value) {
EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL);
store_block(tp->tp_size, tp->tp_align); if (newcode)
store_block(tp->tp_size, tp->tp_align);
} }
else else if (newcode)
store_val(&(left->ex_object.ex_value), store_val(&(left->ex_object.ex_value),
left->ex_type); left->ex_type);
}
break; break;
case PLUSAB: case PLUSAB:
case MINAB: case MINAB:
@ -367,13 +372,14 @@ EVAL(expr, val, code, true_label, false_label)
{ {
arith old_offset, tmp; arith old_offset, tmp;
int compl; /* Complexity of left operand */ int compl; /* Complexity of left operand */
int newcode = left->ex_type->tp_size > 0; /* CJ */
#ifndef NOBITFIELD #ifndef NOBITFIELD
if (left->ex_type->tp_fund == FIELD) { if (left->ex_type->tp_fund == FIELD) {
eval_field(expr, code); eval_field(expr, gencode);
break; break;
} }
#endif NOBITFIELD #endif NOBITFIELD
if (left->ex_class == Value) { if (newcode && left->ex_class == Value) {
compl = 0; /* Value */ compl = 0; /* Value */
load_val(left, RVAL); load_val(left, RVAL);
} }
@ -381,34 +387,42 @@ EVAL(expr, val, code, true_label, false_label)
if (left->ex_depth == 1 && left->OP_OPER == ARROW) { if (left->ex_depth == 1 && left->OP_OPER == ARROW) {
compl = 1; /* Value->sel */ compl = 1; /* Value->sel */
ASSERT(left->OP_LEFT->ex_class == Value); ASSERT(left->OP_LEFT->ex_class == Value);
EVAL(left, RVAL, TRUE, NO_LABEL, NO_LABEL); EVAL(left, RVAL, newcode, NO_LABEL, NO_LABEL);
} }
else { else {
compl = 2; /* otherwise */ compl = 2; /* otherwise */
tmp = tmp_pointer_var(&old_offset); EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL);
EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); if (newcode) {
C_dup(pointer_size); tmp = tmp_pointer_var(&old_offset);
C_lal(tmp); C_dup(pointer_size);
C_sti(pointer_size); C_lal(tmp);
C_loi(left->ex_type->tp_size); C_sti(pointer_size);
C_loi(left->ex_type->tp_size);
}
} }
conversion(left->ex_type, tp); if (newcode) {
if (gencode && (oper == POSTINCR || oper == POSTDECR)) conversion(left->ex_type, tp);
C_dup(tp->tp_size); if (gencode && (oper == POSTINCR ||
EVAL(right, RVAL, TRUE, NO_LABEL, NO_LABEL); oper == POSTDECR))
assop(tp, oper); C_dup(tp->tp_size);
if (gencode && oper != POSTINCR && oper != POSTDECR) }
C_dup(tp->tp_size); EVAL(right, RVAL, newcode, NO_LABEL, NO_LABEL);
conversion(tp, left->ex_type); if (newcode) {
if (compl == 0) assop(tp, oper);
if (gencode && oper != POSTINCR &&
oper != POSTDECR)
C_dup(tp->tp_size);
conversion(tp, left->ex_type);
}
if (newcode && compl == 0)
store_val(&(left->ex_object.ex_value), store_val(&(left->ex_object.ex_value),
left->ex_type); left->ex_type);
else else
if (compl == 1) { if (compl == 1) {
EVAL(left, LVAL, TRUE, NO_LABEL, NO_LABEL); EVAL(left, LVAL, newcode, NO_LABEL, NO_LABEL);
C_sti(left->ex_type->tp_size); if (newcode) C_sti(left->ex_type->tp_size);
} }
else { else if (newcode) {
C_lal(tmp); /* always init'd */ C_lal(tmp); /* always init'd */
C_loi(pointer_size); C_loi(pointer_size);
C_sti(left->ex_type->tp_size); C_sti(left->ex_type->tp_size);
@ -426,12 +440,14 @@ EVAL(expr, val, code, true_label, false_label)
while ( ex->ex_class == Oper && while ( ex->ex_class == Oper &&
ex->OP_OPER == PARCOMMA ex->OP_OPER == PARCOMMA
) { ) {
EVAL(ex->OP_RIGHT, RVAL, TRUE, EVAL(ex->OP_RIGHT, RVAL,
ex->ex_type->tp_size > 0,
NO_LABEL, NO_LABEL); NO_LABEL, NO_LABEL);
ParSize += ATW(ex->ex_type->tp_size); ParSize += ATW(ex->ex_type->tp_size);
ex = ex->OP_LEFT; ex = ex->OP_LEFT;
} }
EVAL(ex, RVAL, TRUE, NO_LABEL, NO_LABEL); EVAL(ex, RVAL, ex->ex_type->tp_size > 0,
NO_LABEL, NO_LABEL);
ParSize += ATW(ex->ex_type->tp_size); ParSize += ATW(ex->ex_type->tp_size);
} }
if (left->ex_class == Value && left->VL_CLASS == Name) { if (left->ex_class == Value && left->VL_CLASS == Name) {
@ -463,23 +479,23 @@ EVAL(expr, val, code, true_label, false_label)
break; break;
} }
case '.': case '.':
EVAL(left, LVAL, code, NO_LABEL, NO_LABEL); EVAL(left, LVAL, gencode, NO_LABEL, NO_LABEL);
ASSERT(is_cp_cst(right)); ASSERT(is_cp_cst(right));
if (gencode) if (gencode)
C_adp(right->VL_VALUE); C_adp(right->VL_VALUE);
break; break;
case ARROW: case ARROW:
EVAL(left, RVAL, code, NO_LABEL, NO_LABEL); EVAL(left, RVAL, gencode, NO_LABEL, NO_LABEL);
ASSERT(is_cp_cst(right)); ASSERT(is_cp_cst(right));
if (gencode) if (gencode)
C_adp(right->VL_VALUE); C_adp(right->VL_VALUE);
break; break;
case ',': case ',':
EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL); EVAL(left, RVAL, FALSE, NO_LABEL, NO_LABEL);
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
break; break;
case '~': case '~':
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) if (gencode)
C_com(tp->tp_size); C_com(tp->tp_size);
break; break;
@ -491,10 +507,10 @@ EVAL(expr, val, code, true_label, false_label)
EVAL(left, RVAL, TRUE, l_true, l_false); EVAL(left, RVAL, TRUE, l_true, l_false);
C_df_ilb(l_true); C_df_ilb(l_true);
EVAL(right->OP_LEFT, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right->OP_LEFT, RVAL, gencode, NO_LABEL, NO_LABEL);
C_bra(l_end); C_bra(l_end);
C_df_ilb(l_false); C_df_ilb(l_false);
EVAL(right->OP_RIGHT, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right->OP_RIGHT, RVAL, gencode, NO_LABEL, NO_LABEL);
C_df_ilb(l_end); C_df_ilb(l_end);
break; break;
} }
@ -528,7 +544,7 @@ EVAL(expr, val, code, true_label, false_label)
EVAL(left, RVAL, TRUE, l_maybe, false_label); EVAL(left, RVAL, TRUE, l_maybe, false_label);
C_df_ilb(l_maybe); C_df_ilb(l_maybe);
EVAL(right, RVAL, code, true_label, EVAL(right, RVAL, gencode, true_label,
false_label); false_label);
} }
break; break;
@ -562,7 +578,7 @@ EVAL(expr, val, code, true_label, false_label)
EVAL(left, RVAL, TRUE, true_label, l_maybe); EVAL(left, RVAL, TRUE, true_label, l_maybe);
C_df_ilb(l_maybe); C_df_ilb(l_maybe);
EVAL(right, RVAL, code, true_label, EVAL(right, RVAL, gencode, true_label,
false_label); false_label);
} }
break; break;
@ -587,7 +603,7 @@ EVAL(expr, val, code, true_label, false_label)
NO_LABEL); NO_LABEL);
} }
else else
EVAL(right, RVAL, code, false_label, EVAL(right, RVAL, gencode, false_label,
true_label); true_label);
break; break;
case INT2INT: case INT2INT:
@ -596,7 +612,7 @@ EVAL(expr, val, code, true_label, false_label)
case FLOAT2INT: case FLOAT2INT:
case FLOAT2FLOAT: case FLOAT2FLOAT:
#endif NOFLOAT #endif NOFLOAT
EVAL(right, RVAL, code, NO_LABEL, NO_LABEL); EVAL(right, RVAL, gencode, NO_LABEL, NO_LABEL);
if (gencode) if (gencode)
conversion(right->ex_type, left->ex_type); conversion(right->ex_type, left->ex_type);
break; break;

View file

@ -187,17 +187,23 @@ declare_idf(ds, dc, lvl)
else { else {
/* combine the decspecs and the declarator into one type */ /* combine the decspecs and the declarator into one type */
type = declare_type(ds->ds_type, dc); type = declare_type(ds->ds_type, dc);
if (type->tp_size == (arith)-1) { if (type->tp_size <= (arith)0 &&
/* the type is not yet known */ actual_declaration(sc, type)) {
if (actual_declaration(sc, type)) { if (type->tp_size == (arith) -1) {
/* but it has to be: */ /* the type is not yet known,
but it has to be:
*/
extern char *symbol2str(); extern char *symbol2str();
error("unknown %s-type", error("unknown %s-type",
symbol2str(type->tp_fund)); symbol2str(type->tp_fund));
} }
else {
/* CJ */
warning("%s has size 0", idf->id_text);
}
} }
} }
/* some additional work for formal definitions */ /* some additional work for formal definitions */
if (lvl == L_FORMAL2) { if (lvl == L_FORMAL2) {
switch (type->tp_fund) { switch (type->tp_fund) {
@ -276,9 +282,8 @@ declare_idf(ds, dc, lvl)
def->df_type = type; def->df_type = type;
def->df_formal_array = formal_array; def->df_formal_array = formal_array;
def->df_sc = sc; def->df_sc = sc;
if (def->df_sc != FORMAL) def->df_level = L_FORMAL2; /* CJ */
crash("non-formal formal"); if (sc == REGISTER) def->df_register = REG_BONUS;
def->df_register = (sc == REGISTER) ? REG_BONUS : REG_DEFAULT;
} }
else else
if ( lvl >= L_LOCAL && if ( lvl >= L_LOCAL &&
@ -303,6 +308,8 @@ declare_idf(ds, dc, lvl)
newdef->df_level = lvl; newdef->df_level = lvl;
newdef->df_type = type; newdef->df_type = type;
newdef->df_sc = sc; newdef->df_sc = sc;
if (lvl == L_FORMAL1) /* CJ */
newdef->df_register = REG_DEFAULT;
/* link it into the name list in the proper place */ /* link it into the name list in the proper place */
idf->id_def = newdef; idf->id_def = newdef;
update_ahead(idf); update_ahead(idf);
@ -323,17 +330,17 @@ declare_idf(ds, dc, lvl)
idf->id_text); idf->id_text);
/** type = idf->id_def->df_type = int_type; **/ /** type = idf->id_def->df_type = int_type; **/
} }
idf->id_def->df_register = newdef->df_register =
(sc == REGISTER) ? REG_BONUS (sc == REGISTER) ? REG_BONUS
: REG_DEFAULT; : REG_DEFAULT;
idf->id_def->df_address = newdef->df_address =
stl->sl_max_block = stl->sl_max_block =
stl->sl_local_offset = stl->sl_local_offset =
-align(-stl->sl_local_offset + -align(-stl->sl_local_offset +
type->tp_size, type->tp_align); type->tp_size, type->tp_align);
break; break;
case STATIC: case STATIC:
idf->id_def->df_address = (arith) data_label(); newdef->df_address = (arith) data_label();
break; break;
} }
} }
@ -504,7 +511,7 @@ global_redecl(idf, new_sc, tp)
int int
good_formal(def, idf) good_formal(def, idf)
register struct def *def; register struct def *def;
struct idf *idf; register struct idf *idf;
{ {
/* Succeeds if def is a proper L_FORMAL1 definition and /* Succeeds if def is a proper L_FORMAL1 definition and
gives an error message otherwise. gives an error message otherwise.
@ -514,6 +521,7 @@ good_formal(def, idf)
error("%s not in parameter list", idf->id_text); error("%s not in parameter list", idf->id_text);
return 0; return 0;
} }
ASSERT(def->df_sc == FORMAL); /* CJ */
return 1; return 1;
} }
@ -533,7 +541,7 @@ declare_params(dc)
} }
init_idf(idf) init_idf(idf)
struct idf *idf; register struct idf *idf;
{ {
/* The topmost definition of idf is set to initialized. /* The topmost definition of idf is set to initialized.
*/ */
@ -593,6 +601,7 @@ declare_formals(fp)
f_offset = align(f_offset + def->df_type->tp_size, word_align); f_offset = align(f_offset + def->df_type->tp_size, word_align);
formal_cvt(def); /* cvt int to char or short, if necessary */ formal_cvt(def); /* cvt int to char or short, if necessary */
se = se->next; se = se->next;
def->df_level = L_FORMAL2; /* CJ */
} }
*fp = f_offset; *fp = f_offset;
} }
@ -637,7 +646,8 @@ free_formals(fm)
register struct formal *fm; register struct formal *fm;
{ {
while (fm) { while (fm) {
register struct formal *tmp = fm->next; struct formal *tmp = fm->next;
free_formal(fm); free_formal(fm);
fm = tmp; fm = tmp;
} }

View file

@ -75,6 +75,9 @@ init_pp()
/* __FILE__ */ /* __FILE__ */
macro_def(str2idf("__FILE__"), "", -1, 1, FUNC); macro_def(str2idf("__FILE__"), "", -1, 1, FUNC);
/* defined(??) */
macro_def(str2idf("defined"), "", 1, 1, FUNC);
#ifdef PREDEFINE #ifdef PREDEFINE
{ {
/* PREDEFINE is a compile-time defined string /* PREDEFINE is a compile-time defined string

View file

@ -170,7 +170,7 @@ compile(argc, argv)
tmpfile = mktemp(tmpf); tmpfile = mktemp(tmpf);
#endif USE_TMP #endif USE_TMP
if (strcmp(destination, "-") == 0) if (destination && strcmp(destination, "-") == 0)
destination = 0; destination = 0;
if (!InsertFile(source, (char **) 0)) /* read the source file */ if (!InsertFile(source, (char **) 0)) /* read the source file */
fatal("%s: no source file %s\n", prog_name, fatal("%s: no source file %s\n", prog_name,
@ -246,7 +246,7 @@ init()
float_type = standard_type(FLOAT, 0, float_align, float_size); float_type = standard_type(FLOAT, 0, float_align, float_size);
double_type = standard_type(DOUBLE, 0, double_align, double_size); double_type = standard_type(DOUBLE, 0, double_align, double_size);
#endif NOFLOAT #endif NOFLOAT
void_type = standard_type(VOID, 0, 0, (arith)0); void_type = standard_type(VOID, 0, 1, (arith)0);
label_type = standard_type(LABEL, 0, 0, (arith)0); label_type = standard_type(LABEL, 0, 0, (arith)0);
error_type = standard_type(ERRONEOUS, 0, 1, (arith)1); error_type = standard_type(ERRONEOUS, 0, 1, (arith)1);

View file

@ -41,6 +41,15 @@ replace(idef)
int size; int size;
if (idef->id_macro->mc_nps != -1) { /* with parameter list */ if (idef->id_macro->mc_nps != -1) { /* with parameter list */
if (flags & FUNC) {
/* must be "defined".
Unfortunately, the next assertion
will not compile ...
ASSERT( ! strcmp("defined", idef->id_text));
*/
if (! AccDefined)
return 0;
}
LoadChar(c); LoadChar(c);
c = skipspaces(c); c = skipspaces(c);
if (c != '(') { /* no replacement if no () */ if (c != '(') { /* no replacement if no () */
@ -50,10 +59,20 @@ replace(idef)
return 0; return 0;
} }
actpars = getactuals(idef); /* get act.param. list */ actpars = getactuals(idef); /* get act.param. list */
if (flags & FUNC) {
struct idf *param = str2idf(*actpars);
if (param->id_macro)
reptext = "\0001";
else
reptext = "\0000";
InsertText(reptext, 2);
return 1;
}
} }
if ((flags & PREDEF) && (UnknownIdIsZero == 0)) /* don't replace */ if ((flags & PREDEF) && (UnknownIdIsZero == 0)) /* don't replace */
return 0; return 0;
if (flags & FUNC) /* this macro leads to special action */ if (flags & FUNC) /* this macro leads to special action */
macro_func(idef); macro_func(idef);
reptext = macro2buffer(idef, actpars, &size); /* create input buffer */ reptext = macro2buffer(idef, actpars, &size); /* create input buffer */
InsertText(reptext, size); InsertText(reptext, size);

View file

@ -118,6 +118,7 @@ unstack_level()
if (level == L_LOCAL || level == L_FORMAL1) { if (level == L_LOCAL || level == L_FORMAL1) {
if ( def->df_register != REG_NONE && if ( def->df_register != REG_NONE &&
def->df_sc != STATIC && def->df_sc != STATIC &&
def->df_type->tp_size > 0 &&
options['n'] == 0 options['n'] == 0
) { ) {
int reg; int reg;

View file

@ -88,6 +88,8 @@ construct_type(fund, tp, count)
error("cannot construct array of unknown type"); error("cannot construct array of unknown type");
count = (arith)-1; count = (arith)-1;
} }
else if (tp->tp_size == 0) /* CJ */
warning("array elements have size 0");
if (count >= (arith)0) if (count >= (arith)0)
count *= tp->tp_size; count *= tp->tp_size;
dtp = array_of(tp, count); dtp = array_of(tp, count);