diff options
author | Michael Forney <mforney@mforney.org> | 2024-04-26 18:09:23 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2024-04-27 02:48:40 -0700 |
commit | 2b6c69c6b7f9dd4b30f00f3b1d9552c5b1c6077e (patch) | |
tree | b24ef4e3048b78c87f9d40e7d44b89b7a2724163 | |
parent | 85dd122f81322a6de30e547ada17cf8ccf4869fd (diff) |
expr: Collapse *& when parsing
-rw-r--r-- | expr.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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 */ |