]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Clean up value_struct_elt_bitpos
authorTom Tromey <tromey@adacore.com>
Tue, 15 Apr 2025 18:29:50 +0000 (12:29 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 17 Apr 2025 15:25:55 +0000 (09:25 -0600)
value_struct_elt_bitpos is weird: it takes an in/out value parameter,
and it takes an error string parameter.  However, it only has a single
caller, which never uses the "out" value.

I think it was done this way to mimic value_struct_elt.  However,
value_struct_elt is pretty ugly and I don't think it's worth
imitating.

This patch cleans up value_struct_elt_bitpos a bit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/python/py-value.c
gdb/valops.c
gdb/value.h

index 3855bdecc16600d866b9d71511d63821a55980f3..8a2e26368d785ae4fb96a61963f0ad7cd9770ef8 100644 (file)
@@ -1096,8 +1096,7 @@ valpy_getitem (PyObject *self, PyObject *key)
        res_val = value_struct_elt (&tmp, {}, field.get (), NULL,
                                    "struct/class/union");
       else if (bitpos >= 0)
-       res_val = value_struct_elt_bitpos (&tmp, bitpos, field_type,
-                                          "struct/class/union");
+       res_val = value_struct_elt_bitpos (tmp, bitpos, field_type);
       else if (base_class_type != NULL)
        {
          struct type *val_type;
index 1b63343c4a77d0ee17c8fa44e230e33b56932e05..94f908df420c14c4b6a743016c281e3e6e8ec1db 100644 (file)
@@ -2420,47 +2420,42 @@ value_struct_elt (struct value **argp,
   return v;
 }
 
-/* Given *ARGP, a value of type structure or union, or a pointer/reference
+/* Given VAL, a value of type structure or union, or a pointer/reference
    to a structure or union, extract and return its component (field) of
    type FTYPE at the specified BITPOS.
    Throw an exception on error.  */
 
 struct value *
-value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
-                        const char *err)
+value_struct_elt_bitpos (struct value *val, int bitpos, struct type *ftype)
 {
   struct type *t;
   int i;
 
-  *argp = coerce_array (*argp);
+  val = coerce_array (val);
 
-  t = check_typedef ((*argp)->type ());
+  t = check_typedef (val->type ());
 
   while (t->is_pointer_or_reference ())
     {
-      *argp = value_ind (*argp);
-      if (check_typedef ((*argp)->type ())->code () != TYPE_CODE_FUNC)
-       *argp = coerce_array (*argp);
-      t = check_typedef ((*argp)->type ());
+      val = value_ind (val);
+      if (check_typedef (val->type ())->code () != TYPE_CODE_FUNC)
+       val = coerce_array (val);
+      t = check_typedef (val->type ());
     }
 
   if (t->code () != TYPE_CODE_STRUCT
       && t->code () != TYPE_CODE_UNION)
-    error (_("Attempt to extract a component of a value that is not a %s."),
-          err);
+    error (_("Attempt to extract a component of non-aggregate value."));
 
   for (i = TYPE_N_BASECLASSES (t); i < t->num_fields (); i++)
     {
       if (!t->field (i).is_static ()
          && bitpos == t->field (i).loc_bitpos ()
          && types_equal (ftype, t->field (i).type ()))
-       return (*argp)->primitive_field (0, i, t);
+       return val->primitive_field (0, i, t);
     }
 
   error (_("No field with matching bitpos and type."));
-
-  /* Never hit.  */
-  return NULL;
 }
 
 /* Search through the methods of an object (and its bases) to find a
index 0cbcfca267f588fd40c5e58de9ba839f8ed5576b..71d0ba17f437e8e571ee2cd171cffde19e06aab0 100644 (file)
@@ -1297,10 +1297,9 @@ extern struct value *value_struct_elt (struct value **argp,
                                       const char *name, int *static_memfuncp,
                                       const char *err);
 
-extern struct value *value_struct_elt_bitpos (struct value **argp,
+extern struct value *value_struct_elt_bitpos (struct value *val,
                                              int bitpos,
-                                             struct type *field_type,
-                                             const char *err);
+                                             struct type *field_type);
 
 extern struct value *value_aggregate_elt (struct type *curtype,
                                          const char *name,