]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add helper method to ada_name_association
authorTom Tromey <tromey@adacore.com>
Wed, 11 Feb 2026 21:49:44 +0000 (14:49 -0700)
committerTom Tromey <tromey@adacore.com>
Thu, 12 Feb 2026 21:34:20 +0000 (14:34 -0700)
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 <tdevries@suse.de>
gdb/ada-exp.h
gdb/ada-lang.c

index 6d400a207a29e4003de533996fd9eeab987b1d0e..05124ebdd3e1de9f2c640d9a214c89ec44a997ce 100644 (file)
@@ -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;
 };
 
index c7533921b778bb15f6e31ec147cd09c25de4a2a5..ae594378047772e8a10a9fe522e8e9f341e4b888 100644 (file)
@@ -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<ada_string_operation *> (m_val.get ());
+
+  if (strop != nullptr)
+    return strop->get_name ();
+
+  ada_var_value_operation *vvo
+    = dynamic_cast<ada_var_value_operation *> (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<ada_string_operation *> (m_val.get ());
-
-      const char *name;
-      if (strop != nullptr)
-       name = strop->get_name ();
-      else
-       {
-         ada_var_value_operation *vvo
-           = dynamic_cast<ada_var_value_operation *> (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,