diff options
author | Michael Forney <mforney@mforney.org> | 2024-04-08 12:50:27 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2024-04-08 12:50:27 -0700 |
commit | c05e4ec794f2f32afc5811377aa7d8595da98013 (patch) | |
tree | 02c2c75f325039767a0e2f7e73ab8f176c89c63b | |
parent | 1e66f1ce8a8df863042ab54ba6b68bd6d2e52396 (diff) |
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.
-rw-r--r-- | cc.h | 2 | ||||
-rw-r--r-- | decl.c | 2 | ||||
-rw-r--r-- | expr.c | 12 |
3 files changed, 4 insertions, 12 deletions
@@ -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 *); @@ -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; @@ -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) |