From 062f616548f900d522a7aaf7ee8bdba4c23a8dae Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 5 Dec 2021 18:24:59 +0900 Subject: [PATCH] [cexpr] Add support for casting plitems This allows using references in expressions, eg: $frames.size * size_t($properties.limits.maxSamplers) As references remain property list items until actually evaluated. --- libs/util/cexpr-lib.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/util/cexpr-lib.c b/libs/util/cexpr-lib.c index e30a16ece..4fa920752 100644 --- a/libs/util/cexpr-lib.c +++ b/libs/util/cexpr-lib.c @@ -118,6 +118,14 @@ CAST_TO (float) CAST_TO (double) #undef CAST_TO +static void +cast_plitem (const exprval_t **params, exprval_t *result, exprctx_t *context) +{ + // first argument is ignored because cexpr_cast_plitem is meant to used + // in an operator list + cexpr_cast_plitem (0, params[0], result, context); +} + FUNC2 (min, int, int, min) FUNC2 (min, uint, uint, min) FUNC2 (min, size_t, size_t, min) @@ -171,6 +179,12 @@ static exprtype_t *double_params[] = { &cexpr_double, }; +static exprtype_t *plitem_params[] = { + &cexpr_plitem, + &cexpr_plitem, + &cexpr_plitem, +}; + #define FUNC(name, rtype, n, ptype) \ { &cexpr_##rtype, n, ptype##_params, FNAME(name, rtype, ptype) } @@ -228,6 +242,7 @@ static exprfunc_t rtype##_func[] = { \ FUNC (cast, rtype, 1, size_t), \ FUNC (cast, rtype, 1, float), \ FUNC (cast, rtype, 1, double), \ + { &cexpr_##rtype, 1, plitem_params, cast_plitem }, \ {} \ };