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 65a3036d8cb03b107aca6e21597b582a46f283a0
parent 06c40b7914efefaaf85392353537a28c0ece3b47
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 24 Apr 2019 21:17:45 -0700

expr: Free subexpressions in delexpr

Diffstat:
Mexpr.c | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 53 insertions(+), 6 deletions(-)

diff --git a/expr.c b/expr.c @@ -26,6 +26,59 @@ mkexpr(enum exprkind k, struct type *t) return e; } +void +delexpr(struct expr *e) +{ + struct expr *sub; + + switch (e->kind) { + case EXPRCALL: + delexpr(e->call.func); + while (sub = e->call.args) { + e->call.args = sub->next; + delexpr(sub); + } + break; + case EXPRBITFIELD: + delexpr(e->bitfield.base); + break; + case EXPRINCDEC: + delexpr(e->incdec.base); + break; + case EXPRUNARY: + delexpr(e->unary.base); + break; + case EXPRCAST: + delexpr(e->cast.e); + break; + case EXPRBINARY: + delexpr(e->binary.l); + delexpr(e->binary.r); + break; + case EXPRCOND: + delexpr(e->cond.e); + delexpr(e->cond.t); + delexpr(e->cond.f); + break; + /* + XXX: compound assignment causes some reuse of expressions, + so we can't free them without risk of a double-free + + case EXPRASSIGN: + delexpr(e->assign.l); + delexpr(e->assign.r); + break; + */ + case EXPRCOMMA: + while (sub = e->comma.exprs) { + e->comma.exprs = sub->next; + delexpr(sub); + } + break; + } + free(e); +} + static struct expr * mkconstexpr(struct type *t, uint64_t n) { @@ -37,12 +90,6 @@ mkconstexpr(struct type *t, uint64_t n) return e; } -void -delexpr(struct expr *e) -{ - free(e); -} - static struct expr *mkunaryexpr(enum tokenkind, struct expr *); /* 6.3.2.1 Conversion of arrays and function designators */