From 5b0da2b14ce2402a102875a3d7209f7a31774271 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 24 Dec 2020 09:57:24 +0900 Subject: [PATCH] [util] Add an int to uint cast for cexpr --- libs/util/cexpr-parse.y | 6 +----- libs/util/cexpr-type.c | 8 ++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libs/util/cexpr-parse.y b/libs/util/cexpr-parse.y index e789a40e9..eb56ed588 100644 --- a/libs/util/cexpr-parse.y +++ b/libs/util/cexpr-parse.y @@ -150,11 +150,7 @@ assign_expr (exprval_t *dst, const exprval_t *src, exprctx_t *context) if (!src) { return; } - for (binop = dst->type->binops; binop && binop->op; binop++) { - if (binop->op == '=' && binop->other == src->type) { - break; - } - } + binop = cexpr_find_cast (dst->type, src->type); if (binop && binop->op) { binop->func (dst, src, dst, context); } else { diff --git a/libs/util/cexpr-type.c b/libs/util/cexpr-type.c index c0610b13d..c1dbbafb0 100644 --- a/libs/util/cexpr-type.c +++ b/libs/util/cexpr-type.c @@ -125,6 +125,13 @@ BINOP(uint, bor, unsigned, |) BINOP(uint, xor, unsigned, ^) BINOP(uint, rem, unsigned, %) +static void +uint_cast_int (const exprval_t *val1, const exprval_t *src, exprval_t *result, + exprctx_t *ctx) +{ + *(unsigned *) result->value = *(int *) src->value; +} + UNOP(uint, pos, unsigned, +) UNOP(uint, neg, unsigned, -) UNOP(uint, tnot, unsigned, !) @@ -142,6 +149,7 @@ binop_t uint_binops[] = { { '^', &cexpr_uint, &cexpr_uint, uint_xor }, { '%', &cexpr_uint, &cexpr_uint, uint_rem }, { MOD, &cexpr_uint, &cexpr_uint, uint_rem }, + { '=', &cexpr_int, &cexpr_uint, uint_cast_int }, {} };