diff options
author | Tom Tromey <tromey@adacore.com> | 2024-03-05 07:59:55 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-04-02 11:24:27 -0600 |
commit | 542ea7fe46deb713268364fa7b1a3333360e1044 (patch) | |
tree | dd60ed83af06b59536e6bef47e61f7dfedbdb1cc /gdb/ada-lang.c | |
parent | d9d782dd8b6c3665c28f6b610175a0756a7805a4 (diff) | |
download | binutils-542ea7fe46deb713268364fa7b1a3333360e1044.zip binutils-542ea7fe46deb713268364fa7b1a3333360e1044.tar.gz binutils-542ea7fe46deb713268364fa7b1a3333360e1044.tar.bz2 |
Implement Ada 2022 iterated assignment
Ada 2022 includes iterated assignment for array initialization. This
patch implements a subset of this for gdb. In particular, only arrays
with integer index types really work -- currently there's no decent
way to get the index type in EVAL_AVOID_SIDE_EFFECTS mode during
parsing. Fixing this probably requires the Ada parser to take a
somewhat more sophisticated approach to type resolution; and while
this would help fix another bug in this area, this patch is already
useful without it.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r-- | gdb/ada-lang.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 84576e7..a387002 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -9342,6 +9342,8 @@ aggregate_assigner::assign (LONGEST index, operation_up &arg) elt = ada_to_fixed_value (elt); } + scoped_restore save_index = make_scoped_restore (&m_current_index, index); + ada_aggregate_operation *ag_op = dynamic_cast<ada_aggregate_operation *> (arg.get ()); if (ag_op != nullptr) @@ -9352,6 +9354,18 @@ aggregate_assigner::assign (LONGEST index, operation_up &arg) EVAL_NORMAL)); } +/* See ada-exp.h. */ + +value * +aggregate_assigner::current_value () const +{ + /* Note that using an integer type here is incorrect -- the type + should be the array's index type. Unfortunately, though, this + isn't currently available during parsing and type resolution. */ + struct type *index_type = builtin_type (exp->gdbarch)->builtin_int; + return value_from_longest (index_type, m_current_index); +} + bool ada_aggregate_component::uses_objfile (struct objfile *objfile) { @@ -9597,8 +9611,15 @@ ada_choices_component::uses_objfile (struct objfile *objfile) void ada_choices_component::dump (ui_file *stream, int depth) { - gdb_printf (stream, _("%*sChoices:\n"), depth, ""); + if (m_name.empty ()) + gdb_printf (stream, _("%*sChoices:\n"), depth, ""); + else + { + gdb_printf (stream, _("%*sIterated choices:\n"), depth, ""); + gdb_printf (stream, _("%*sName: %s\n"), depth + 1, "", m_name.c_str ()); + } m_op->dump (stream, depth + 1); + for (const auto &item : m_assocs) item->dump (stream, depth + 1); } @@ -9610,10 +9631,36 @@ ada_choices_component::dump (ui_file *stream, int depth) void ada_choices_component::assign (aggregate_assigner &assigner) { + scoped_restore save_index = make_scoped_restore (&m_assigner, &assigner); for (auto &item : m_assocs) item->assign (assigner, m_op); } +void +ada_index_var_operation::dump (struct ui_file *stream, int depth) const +{ + gdb_printf (stream, _("%*sIndex variable: %s\n"), depth, "", + m_var->name ().c_str ()); +} + +value * +ada_index_var_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + /* Note that using an integer type here is incorrect -- the type + should be the array's index type. Unfortunately, though, + this isn't currently available during parsing and type + resolution. */ + struct type *index_type = builtin_type (exp->gdbarch)->builtin_int; + return value::zero (index_type, not_lval); + } + + return m_var->current_value (); +} + bool ada_others_component::uses_objfile (struct objfile *objfile) { |