From c05e4ec794f2f32afc5811377aa7d8595da98013 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 8 Apr 2024 12:50:27 -0700 Subject: expr: Remove evalexpr() and just use condexpr() with eval() evalexpr() was originally named `constexpr`, since it matched the constant-expression rule in the grammar. It had to be renamed due to conflict with the C23 constexpr keyword. However, since 2e3ecc70, eval has just one argument, so just call eval(condexpr()) directly. --- cc.h | 2 +- decl.c | 2 +- expr.c | 12 ++---------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/cc.h b/cc.h index 068eb72..97d3e66 100644 --- a/cc.h +++ b/cc.h @@ -518,7 +518,7 @@ struct type *stringconcat(struct stringlit *, bool); struct expr *expr(struct scope *); struct expr *assignexpr(struct scope *); -struct expr *evalexpr(struct scope *); +struct expr *condexpr(struct scope *); unsigned long long intconstexpr(struct scope *, bool); void delexpr(struct expr *); diff --git a/decl.c b/decl.c index 0075baf..9b7f664 100644 --- a/decl.c +++ b/decl.c @@ -247,7 +247,7 @@ tagspec(struct scope *s) next(); attr(NULL, 0); if (consume(TASSIGN)) { - e = evalexpr(s); + e = eval(condexpr(s)); if (e->kind != EXPRCONST || !(e->type->prop & PROPINT)) error(&tok.loc, "expected integer constant expression"); value = e->u.constant.u; diff --git a/expr.c b/expr.c index e1cd271..bcf4fc7 100644 --- a/expr.c +++ b/expr.c @@ -734,8 +734,6 @@ primaryexpr(struct scope *s) return e; } -static struct expr *condexpr(struct scope *); - /* TODO: merge with init.c:designator() */ static void designator(struct scope *s, struct type *t, unsigned long long *offset) @@ -1201,7 +1199,7 @@ binaryexpr(struct scope *s, struct expr *l, int i) return l; } -static struct expr * +struct expr * condexpr(struct scope *s) { struct expr *e, *l, *r; @@ -1257,18 +1255,12 @@ condexpr(struct scope *s) return e; } -struct expr * -evalexpr(struct scope *s) -{ - return eval(condexpr(s)); -} - unsigned long long intconstexpr(struct scope *s, bool allowneg) { struct expr *e; - e = evalexpr(s); + e = eval(condexpr(s)); if (e->kind != EXPRCONST || !(e->type->prop & PROPINT)) error(&tok.loc, "not an integer constant expression"); if (!allowneg && e->type->u.basic.issigned && e->u.constant.u >> 63) -- cgit v1.2.3