[util] Add an int to uint cast for cexpr

This commit is contained in:
Bill Currie 2020-12-24 09:57:24 +09:00
parent 25ade4c0f3
commit 5b0da2b14c
2 changed files with 9 additions and 5 deletions

View file

@ -150,11 +150,7 @@ assign_expr (exprval_t *dst, const exprval_t *src, exprctx_t *context)
if (!src) { if (!src) {
return; return;
} }
for (binop = dst->type->binops; binop && binop->op; binop++) { binop = cexpr_find_cast (dst->type, src->type);
if (binop->op == '=' && binop->other == src->type) {
break;
}
}
if (binop && binop->op) { if (binop && binop->op) {
binop->func (dst, src, dst, context); binop->func (dst, src, dst, context);
} else { } else {

View file

@ -125,6 +125,13 @@ BINOP(uint, bor, unsigned, |)
BINOP(uint, xor, unsigned, ^) BINOP(uint, xor, unsigned, ^)
BINOP(uint, rem, 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, pos, unsigned, +)
UNOP(uint, neg, unsigned, -) UNOP(uint, neg, unsigned, -)
UNOP(uint, tnot, unsigned, !) UNOP(uint, tnot, unsigned, !)
@ -142,6 +149,7 @@ binop_t uint_binops[] = {
{ '^', &cexpr_uint, &cexpr_uint, uint_xor }, { '^', &cexpr_uint, &cexpr_uint, uint_xor },
{ '%', &cexpr_uint, &cexpr_uint, uint_rem }, { '%', &cexpr_uint, &cexpr_uint, uint_rem },
{ MOD, &cexpr_uint, &cexpr_uint, uint_rem }, { MOD, &cexpr_uint, &cexpr_uint, uint_rem },
{ '=', &cexpr_int, &cexpr_uint, uint_cast_int },
{} {}
}; };