diff --git a/include/QF/cexpr.h b/include/QF/cexpr.h index ac6eef683..53fc159e7 100644 --- a/include/QF/cexpr.h +++ b/include/QF/cexpr.h @@ -113,6 +113,8 @@ void cexpr_error(exprctx_t *ctx, const char *fmt, ...) __attribute__((format(pri void cexpr_struct_getfield (const exprval_t *a, const exprval_t *b, exprval_t *c, exprctx_t *ctx); +void cexpr_struct_pointer_getfield (const exprval_t *a, const exprval_t *b, + exprval_t *c, exprctx_t *ctx); exprval_t *cexpr_cvar (const char *name, exprctx_t *ctx); exprval_t *cexpr_cvar_struct (exprctx_t *ctx); @@ -132,5 +134,6 @@ extern exprtype_t cexpr_field; extern exprtype_t cexpr_function; extern binop_t cexpr_struct_binops[]; +extern binop_t cexpr_struct_pointer_binops[]; #endif diff --git a/libs/util/cexpr-vars.c b/libs/util/cexpr-vars.c index 115f0ba64..04c6871ad 100644 --- a/libs/util/cexpr-vars.c +++ b/libs/util/cexpr-vars.c @@ -58,6 +58,20 @@ VISIBLE binop_t cexpr_struct_binops[] = { {} }; +VISIBLE void +cexpr_struct_pointer_getfield (const exprval_t *a, const exprval_t *b, + exprval_t *c, exprctx_t *ctx) +{ + // "dereference" the pointer + exprval_t struct_val = { a->type, *(void **) a->value }; + cexpr_struct_getfield (&struct_val, b, c, ctx); +} + +VISIBLE binop_t cexpr_struct_pointer_binops[] = { + { '.', &cexpr_field, &cexpr_exprval, cexpr_struct_pointer_getfield }, + {} +}; + static void cvar_get (const exprval_t *a, const exprval_t *b, exprval_t *c, exprctx_t *ctx) {