From 2b6c69c6b7f9dd4b30f00f3b1d9552c5b1c6077e Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Fri, 26 Apr 2024 18:09:23 -0700 Subject: expr: Collapse *& when parsing --- expr.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/expr.c b/expr.c index f686da2..7e7e649 100644 --- a/expr.c +++ b/expr.c @@ -121,6 +121,7 @@ static struct expr * mkunaryexpr(enum tokenkind op, struct expr *base) { struct expr *expr; + struct type *type; switch (op) { case TBAND: @@ -143,10 +144,16 @@ mkunaryexpr(enum tokenkind op, struct expr *base) case TMUL: if (base->type->kind != TYPEPOINTER) error(&tok.loc, "cannot dereference non-pointer"); - expr = mkexpr(EXPRUNARY, base->type->base, base); - expr->qual = base->type->qual; - expr->lvalue = true; - expr->op = op; + if (base->kind == EXPRUNARY && base->op == TBAND) { + type = base->type->base; + expr = base->base; + expr->type = type; + } else { + expr = mkexpr(EXPRUNARY, base->type->base, base); + expr->qual = base->type->qual; + expr->lvalue = true; + expr->op = op; + } return decay(expr); } /* other unary operators get compiled as equivalent binary ones */ -- cgit v1.2.3