[util] Support struct pointer accesses in cexpr

This commit is contained in:
Bill Currie 2021-01-10 01:35:39 +09:00
parent 0c1699fdbb
commit 16334158bd
2 changed files with 17 additions and 0 deletions

View file

@ -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

View file

@ -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)
{