From b7a96ed22e95c04c80b07f2f3e36a0d6e1d1d375 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: [PATCH] Split out eval_op_member This splits STRUCTOP_MEMBER into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey * eval.c (eval_op_member): New function. (evaluate_subexp_standard): Use it. --- gdb/ChangeLog | 5 ++++ gdb/eval.c | 76 +++++++++++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fb4299e0798..a0a98b99cb9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-08 Tom Tromey + + * eval.c (eval_op_member): New function. + (evaluate_subexp_standard): Use it. + 2021-03-08 Tom Tromey * eval.c (eval_op_structop_ptr): New function. diff --git a/gdb/eval.c b/gdb/eval.c index 4800438b121..d609b737a59 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1413,6 +1413,49 @@ eval_op_structop_ptr (struct type *expect_type, struct expression *exp, return arg3; } +/* A helper function for STRUCTOP_MEMBER. */ + +static struct value * +eval_op_member (struct type *expect_type, struct expression *exp, + enum noside noside, + struct value *arg1, struct value *arg2) +{ + long mem_offset; + + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + + struct value *arg3; + struct type *type = check_typedef (value_type (arg2)); + switch (type->code ()) + { + case TYPE_CODE_METHODPTR: + if (noside == EVAL_AVOID_SIDE_EFFECTS) + return value_zero (TYPE_TARGET_TYPE (type), not_lval); + else + { + arg2 = cplus_method_ptr_to_value (&arg1, arg2); + gdb_assert (value_type (arg2)->code () == TYPE_CODE_PTR); + return value_ind (arg2); + } + + case TYPE_CODE_MEMBERPTR: + /* Now, convert these values to an address. */ + arg1 = value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type)), + arg1, 1); + + mem_offset = value_as_long (arg2); + + arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)), + value_as_long (arg1) + mem_offset); + return value_ind (arg3); + + default: + error (_("non-pointer-to-member value used " + "in pointer-to-member construct")); + } +} + struct value * evaluate_subexp_standard (struct type *expect_type, struct expression *exp, int *pos, @@ -1428,7 +1471,6 @@ evaluate_subexp_standard (struct type *expect_type, int nargs; struct value **argvec; int ix; - long mem_offset; struct type **arg_types; pc = (*pos)++; @@ -2023,37 +2065,7 @@ evaluate_subexp_standard (struct type *expect_type, arg2 = evaluate_subexp (nullptr, exp, pos, noside); - if (noside == EVAL_SKIP) - return eval_skip_value (exp); - - type = check_typedef (value_type (arg2)); - switch (type->code ()) - { - case TYPE_CODE_METHODPTR: - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return value_zero (TYPE_TARGET_TYPE (type), not_lval); - else - { - arg2 = cplus_method_ptr_to_value (&arg1, arg2); - gdb_assert (value_type (arg2)->code () == TYPE_CODE_PTR); - return value_ind (arg2); - } - - case TYPE_CODE_MEMBERPTR: - /* Now, convert these values to an address. */ - arg1 = value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type)), - arg1, 1); - - mem_offset = value_as_long (arg2); - - arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)), - value_as_long (arg1) + mem_offset); - return value_ind (arg3); - - default: - error (_("non-pointer-to-member value used " - "in pointer-to-member construct")); - } + return eval_op_member (expect_type, exp, noside, arg1, arg2); case TYPE_INSTANCE: { -- 2.30.2