diff options
author | Tom Tromey <tom@tromey.com> | 2021-03-08 07:27:57 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-03-08 07:28:00 -0700 |
commit | 288d26bcd841072069237b03d8c1197aa68560d0 (patch) | |
tree | 9f54b446ad3a89ea376a641963e721f56e4554b1 | |
parent | 7cdcdd02b38fde4c2bab83c70b65e81cb879f6d7 (diff) | |
download | binutils-288d26bcd841072069237b03d8c1197aa68560d0.zip binutils-288d26bcd841072069237b03d8c1197aa68560d0.tar.gz binutils-288d26bcd841072069237b03d8c1197aa68560d0.tar.bz2 |
Split out eval_op_subscript
This splits BINOP_SUBSCRIPT into a new function for future use.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* eval.c (eval_op_subscript): New function.
(evaluate_subexp_standard): Use it.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/eval.c | 63 |
2 files changed, 42 insertions, 26 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b637fce..dfbf126 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2021-03-08 Tom Tromey <tom@tromey.com> + * eval.c (eval_op_subscript): New function. + (evaluate_subexp_standard): Use it. + +2021-03-08 Tom Tromey <tom@tromey.com> + * eval.c (eval_op_binary): New function. (evaluate_subexp_standard): Use it. @@ -1555,6 +1555,42 @@ eval_op_binary (struct type *expect_type, struct expression *exp, } } +/* A helper function for BINOP_SUBSCRIPT. */ + +static struct value * +eval_op_subscript (struct type *expect_type, struct expression *exp, + enum noside noside, enum exp_opcode op, + struct value *arg1, struct value *arg2) +{ + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + if (binop_user_defined_p (op, arg1, arg2)) + return value_x_binop (arg1, arg2, op, OP_NULL, noside); + else + { + /* If the user attempts to subscript something that is not an + array or pointer type (like a plain int variable for example), + then report this as an error. */ + + arg1 = coerce_ref (arg1); + struct type *type = check_typedef (value_type (arg1)); + if (type->code () != TYPE_CODE_ARRAY + && type->code () != TYPE_CODE_PTR) + { + if (type->name ()) + error (_("cannot subscript something of type `%s'"), + type->name ()); + else + error (_("cannot subscript requested type")); + } + + if (noside == EVAL_AVOID_SIDE_EFFECTS) + return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1)); + else + return value_subscript (arg1, value_as_long (arg2)); + } +} + struct value * evaluate_subexp_standard (struct type *expect_type, struct expression *exp, int *pos, @@ -2266,33 +2302,8 @@ evaluate_subexp_standard (struct type *expect_type, case BINOP_SUBSCRIPT: arg1 = evaluate_subexp (nullptr, exp, pos, noside); arg2 = evaluate_subexp (nullptr, exp, pos, noside); - if (noside == EVAL_SKIP) - return eval_skip_value (exp); - if (binop_user_defined_p (op, arg1, arg2)) - return value_x_binop (arg1, arg2, op, OP_NULL, noside); - else - { - /* If the user attempts to subscript something that is not an - array or pointer type (like a plain int variable for example), - then report this as an error. */ + return eval_op_subscript (expect_type, exp, noside, op, arg1, arg2); - arg1 = coerce_ref (arg1); - type = check_typedef (value_type (arg1)); - if (type->code () != TYPE_CODE_ARRAY - && type->code () != TYPE_CODE_PTR) - { - if (type->name ()) - error (_("cannot subscript something of type `%s'"), - type->name ()); - else - error (_("cannot subscript requested type")); - } - - if (noside == EVAL_AVOID_SIDE_EFFECTS) - return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1)); - else - return value_subscript (arg1, value_as_long (arg2)); - } case MULTI_SUBSCRIPT: (*pos) += 2; nargs = longest_to_int (exp->elts[pc + 1].longconst); |