aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-04-08 12:50:27 -0700
committerMichael Forney <mforney@mforney.org>2024-04-08 12:50:27 -0700
commitc05e4ec794f2f32afc5811377aa7d8595da98013 (patch)
tree02c2c75f325039767a0e2f7e73ab8f176c89c63b
parent1e66f1ce8a8df863042ab54ba6b68bd6d2e52396 (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.h2
-rw-r--r--decl.c2
-rw-r--r--expr.c12
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)