From: Tom Tromey Date: Wed, 11 Feb 2026 21:49:44 +0000 (-0700) Subject: Add helper method to ada_name_association X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f13feb6044200ee2d195a5f2bdb194535e1f28b;p=thirdparty%2Fbinutils-gdb.git Add helper method to ada_name_association This adds a helper method to ada_name_association, factoring out part of ada_name_association::assign. This will be useful in the next patch. Tested-By: Tom de Vries --- diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index 6d400a207a2..05124ebdd3e 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -900,6 +900,11 @@ public: private: + /* A helper function to find the plain name of the LHS. If OP + represents a plain name, the unqualified name is returned as a + string. Otherwise, nullptr is returned. */ + const char *find_name (operation_up &op) const; + operation_up m_val; }; diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index c7533921b77..ae594378047 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -9611,6 +9611,30 @@ ada_name_association::dump (ui_file *stream, int depth) m_val->dump (stream, depth + 1); } +/* See ada-exp.h. */ + +const char * +ada_name_association::find_name (operation_up &op) const +{ + ada_string_operation *strop + = dynamic_cast (m_val.get ()); + + if (strop != nullptr) + return strop->get_name (); + + ada_var_value_operation *vvo + = dynamic_cast (m_val.get ()); + if (vvo == nullptr) + return nullptr; + /* In this scenario, the user wrote (name => expr), but + write_name_assoc found some fully-qualified name and substituted + it. This happens because, at parse time, the meaning of the + expression isn't known; but here we know that just the base name + was supplied and it refers to the name of a field. */ + const char *name = vvo->get_symbol ()->natural_name (); + return ada_unqualified_name (name); +} + void ada_name_association::assign (aggregate_assigner &assigner, operation_up &op) @@ -9624,27 +9648,9 @@ ada_name_association::assign (aggregate_assigner &assigner, } else { - ada_string_operation *strop - = dynamic_cast (m_val.get ()); - - const char *name; - if (strop != nullptr) - name = strop->get_name (); - else - { - ada_var_value_operation *vvo - = dynamic_cast (m_val.get ()); - if (vvo == nullptr) - error (_("Invalid record component association.")); - name = vvo->get_symbol ()->natural_name (); - /* In this scenario, the user wrote (name => expr), but - write_name_assoc found some fully-qualified name and - substituted it. This happens because, at parse time, the - meaning of the expression isn't known; but here we know - that just the base name was supplied and it refers to the - name of a field. */ - name = ada_unqualified_name (name); - } + const char *name = find_name (op); + if (name == nullptr) + error (_("Invalid record component association.")); index = 0; if (! find_struct_field (name, assigner.lhs->type (), 0,