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.
This commit is contained in:
Tom Tromey
2024-03-05 07:59:55 -07:00
parent d9d782dd8b
commit 542ea7fe46
8 changed files with 284 additions and 5 deletions

View File

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