cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 4b32dcf6f1cb086c5e122f1e8dc5c6613359f8c9
parent c557c2dbe484a725ae9233b706dffc2a184bdcc2
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 23 Apr 2019 20:41:50 -0700

expr: Add mkincdecexpr for pre/postfix inc/decrement operators

Diffstat:
Mexpr.c | 30++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/expr.c b/expr.c @@ -523,6 +523,22 @@ builtinfunc(struct scope *s, enum builtinkind kind) } static struct expr * +mkincdecexpr(enum tokenkind op, struct expr *base, bool post) +{ + struct expr *e; + + if (!base->lvalue) + error(&tok.loc, "operand of '%s' operator must be an lvalue", tokstr[op]); + if (base->qual & QUALCONST) + error(&tok.loc, "operand of '%s' operator is const qualified", tokstr[op]); + e = mkexpr(EXPRINCDEC, base->type); + e->incdec.op = op; + e->incdec.base = base; + e->incdec.post = post; + return e; +} + +static struct expr * postfixexpr(struct scope *s, struct expr *r) { struct expr *e, *arr, *idx, *tmp, **end; @@ -630,10 +646,7 @@ postfixexpr(struct scope *s, struct expr *r) break; case TINC: case TDEC: - e = mkexpr(EXPRINCDEC, r->type); - e->incdec.op = tok.kind; - e->incdec.base = r; - e->incdec.post = 1; + e = mkincdecexpr(tok.kind, r, true); next(); break; default: @@ -658,14 +671,7 @@ unaryexpr(struct scope *s) case TDEC: next(); l = unaryexpr(s); - if (!l->lvalue) - error(&tok.loc, "operand of '%s' operator must be an lvalue", tokstr[op]); - if (l->qual & QUALCONST) - error(&tok.loc, "operand of '%s' operator is const qualified", tokstr[op]); - e = mkexpr(EXPRINCDEC, l->type); - e->incdec.op = op; - e->incdec.base = l; - e->incdec.post = 0; + e = mkincdecexpr(op, l, false); break; case TBAND: case TMUL: