diff options
author | Michael Forney <mforney@mforney.org> | 2019-04-23 20:41:50 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-04-23 20:44:08 -0700 |
commit | 4b32dcf6f1cb086c5e122f1e8dc5c6613359f8c9 (patch) | |
tree | ed67f4e0e001fcaa9ccc92c21f0f72b358dff58e | |
parent | c557c2dbe484a725ae9233b706dffc2a184bdcc2 (diff) | |
download | cproc-4b32dcf6f1cb086c5e122f1e8dc5c6613359f8c9.tar.xz |
expr: Add mkincdecexpr for pre/postfix inc/decrement operators
-rw-r--r-- | expr.c | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -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: |