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:19 -0700 |
commit | 224d6424bab021a0a8e16f07d52f8af5e153e91f (patch) | |
tree | 8f2d47a925f9b24ea251bde9fb2801f678065ee0 /gdb/eval.c | |
parent | 373907ffb2db9232af14d2a7e4433f41cc1fc56c (diff) | |
download | gdb-224d6424bab021a0a8e16f07d52f8af5e153e91f.zip gdb-224d6424bab021a0a8e16f07d52f8af5e153e91f.tar.gz gdb-224d6424bab021a0a8e16f07d52f8af5e153e91f.tar.bz2 |
Introduce subscript_operation
This adds class subscript_operation, which implements BINOP_SUBSCRIPT.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* expop.h (class subscript_operation): New.
* eval.c (eval_op_subscript): No longer static.
Diffstat (limited to 'gdb/eval.c')
-rw-r--r-- | gdb/eval.c | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1558,7 +1558,7 @@ eval_op_binary (struct type *expect_type, struct expression *exp, /* A helper function for BINOP_SUBSCRIPT. */ -static struct value * +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) @@ -3536,6 +3536,39 @@ var_msym_value_operation::evaluate_for_sizeof (struct expression *exp, return value_from_longest (size_type, TYPE_LENGTH (type)); } +value * +subscript_operation::evaluate_for_sizeof (struct expression *exp, + enum noside noside) +{ + if (noside == EVAL_NORMAL) + { + value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, + EVAL_AVOID_SIDE_EFFECTS); + struct type *type = check_typedef (value_type (val)); + if (type->code () == TYPE_CODE_ARRAY) + { + type = check_typedef (TYPE_TARGET_TYPE (type)); + if (type->code () == TYPE_CODE_ARRAY) + { + type = type->index_type (); + /* Only re-evaluate the right hand side if the resulting type + is a variable length type. */ + if (type->bounds ()->flag_bound_evaluated) + { + val = evaluate (nullptr, exp, EVAL_NORMAL); + /* FIXME: This should be size_t. */ + struct type *size_type + = builtin_type (exp->gdbarch)->builtin_int; + return value_from_longest + (size_type, (LONGEST) TYPE_LENGTH (value_type (val))); + } + } + } + } + + return operation::evaluate_for_sizeof (exp, noside); +} + } /* Evaluate a subexpression of EXP, at index *POS, and return a value |