fixed unary & and indirect calls

This commit is contained in:
eck 1989-11-22 16:41:09 +00:00
parent 96da16ce33
commit d50600e263
8 changed files with 29 additions and 6 deletions

View file

@ -495,7 +495,7 @@ any2opnd(expp, oper)
if (!*expp)
return;
if (oper == SIZEOF || oper == '&') return;
if (oper == SIZEOF || oper == ADDRESSOF) return;
switch ((*expp)->ex_type->tp_fund) {
case CHAR:

View file

@ -70,12 +70,25 @@ 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
) {
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));
@ -84,6 +97,7 @@ ch3bin(expp, oper, expr)
*expp = new_oper(error_type,
*expp, '(', (struct expr *)0);
}
#endif
else
*expp = new_oper(expp_tp->tp_up,
*expp, '(', expr);

View file

@ -56,7 +56,7 @@ ch3mon(oper, expp)
(*expp)->ex_flags &= ~EX_ILVALUE;
}
break;
case '&':
case ADDRESSOF:
if ((*expp)->ex_type->tp_fund == ARRAY) {
(*expp)->ex_type = pointer_to((*expp)->ex_type, 0);
}
@ -87,7 +87,7 @@ ch3mon(oper, expp)
if (def->df_sc == REGISTER) {
expr_error(*expp,
"& on register variable not allowed");
break; /* break case '&' */
break; /* break case ADDRESSOF */
}
}
(*expp)->ex_type = pointer_to((*expp)->ex_type,

View file

@ -70,7 +70,9 @@ EVAL(expr, val, code, true_label, false_label)
int val, code;
label true_label, false_label;
{
register int gencode = (code == TRUE && expr->ex_type->tp_size > 0);
register int gencode = (code == TRUE
&& (expr->ex_type->tp_size > 0
|| expr->ex_type->tp_fund == FUNCTION));
switch (expr->ex_class) {
case Value: /* just a simple value */

View file

@ -48,6 +48,7 @@ rank_of(oper)
case MINMIN:
case CAST:
case SIZEOF:
case ADDRESSOF:
return 2; /* monadic */
case '*':
case '/':

View file

@ -283,7 +283,9 @@ expression(struct expr **expp;)
unop(int *oper;) :
['*' | '&' | '-' | '+' | '!' | '~' | PLUSPLUS | MINMIN]
{*oper = DOT;}
{ if (DOT == '&') DOT = ADDRESSOF;
*oper = DOT;
}
;
multop:

View file

@ -61,7 +61,10 @@ initial_value(register struct type **tpp; register struct expr **expp;) :
if ((*expp)->ex_type->tp_fund == ARRAY)
array2pointer(*expp);
if (tpp) {
if (is_ld_cst(*expp) || is_fp_cst(*expp) || level >= L_LOCAL) {
if (level >= L_LOCAL
|| is_ld_cst(*expp)
|| is_fp_cst(*expp)
|| (*expp)->ex_class == String) {
gen_simple_exp(tpp, expp);
free_expression(*expp);
*expp = 0;

View file

@ -120,6 +120,7 @@ struct tokenname tkfunny[] = { /* internal keywords */
{INITCOMMA, "initcomma"},
{CAST, "cast"},
{CASTAB, "castab"},
{ADDRESSOF,"unary &"},
{POSTINCR, "postfix ++"},
{POSTDECR, "postfix --"},