]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: use gdb::optional instead of passing a pointer to gdb::array_view
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 22 Jun 2021 18:27:53 +0000 (19:27 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 25 Jun 2021 19:43:06 +0000 (20:43 +0100)
Following on from the previous commit, this commit changes the API of
value_struct_elt to take gdb::optional<gdb::array_view<value *>>
instead of a pointer to the gdb::array_view.

This makes the optional nature of the array_view parameter explicit.

This commit is purely a refactoring commit, there should be no user
visible change after this commit.

I have deliberately kept this refactor separate from the previous two
commits as this is a more extensive change, and I'm not 100% sure that
using gdb::optional for the parameter type, instead of a pointer, is
going to be to everyone's taste.  If there's push back on this patch
then this one can be dropped from the series.

gdb/ChangeLog:

* ada-lang.c (desc_bounds): Use '{}' instead of NULL to indicate
an empty gdb::optional when calling value_struct_elt.
(desc_data): Likewise.
(desc_one_bound): Likewise.
* eval.c (structop_base_operation::evaluate_funcall): Pass
gdb::array_view, not a gdb::array_view* to value_struct_elt.
(eval_op_structop_struct): Use '{}' instead of NULL to indicate
an empty gdb::optional when calling value_struct_elt.
(eval_op_structop_ptr): Likewise.
* f-lang.c (fortran_structop_operation::evaluate): Likewise.
* guile/scm-value.c (gdbscm_value_field): Likewise.
* m2-lang.c (eval_op_m2_high): Likewise.
(eval_op_m2_subscript): Likewise.
* opencl-lang.c (opencl_structop_operation::evaluate): Likewise.
* python/py-value.c (valpy_getitem): Likewise.
* rust-lang.c (rust_val_print_str): Likewise.
(rust_range): Likewise.
(rust_subscript): Likewise.
(eval_op_rust_structop): Likewise.
(rust_aggregate_operation::evaluate): Likewise.
* valarith.c (value_user_defined_op): Likewise.
* valops.c (search_struct_method): Change parameter type, update
function body accordingly, and update header comment.
(value_struct_elt): Change parameter type, update function body
accordingly.
* value.h (value_struct_elt): Update declaration.

12 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/eval.c
gdb/f-lang.c
gdb/guile/scm-value.c
gdb/m2-lang.c
gdb/opencl-lang.c
gdb/python/py-value.c
gdb/rust-lang.c
gdb/valarith.c
gdb/valops.c
gdb/value.h

index 9396aadca9d43b0230fa6615c64eabc136d3304c..1d10ae0f6c8b965639ef1f34768acd92d1fa7f2d 100644 (file)
@@ -1,3 +1,32 @@
+2021-06-25  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * ada-lang.c (desc_bounds): Use '{}' instead of NULL to indicate
+       an empty gdb::optional when calling value_struct_elt.
+       (desc_data): Likewise.
+       (desc_one_bound): Likewise.
+       * eval.c (structop_base_operation::evaluate_funcall): Pass
+       gdb::array_view, not a gdb::array_view* to value_struct_elt.
+       (eval_op_structop_struct): Use '{}' instead of NULL to indicate
+       an empty gdb::optional when calling value_struct_elt.
+       (eval_op_structop_ptr): Likewise.
+       * f-lang.c (fortran_structop_operation::evaluate): Likewise.
+       * guile/scm-value.c (gdbscm_value_field): Likewise.
+       * m2-lang.c (eval_op_m2_high): Likewise.
+       (eval_op_m2_subscript): Likewise.
+       * opencl-lang.c (opencl_structop_operation::evaluate): Likewise.
+       * python/py-value.c (valpy_getitem): Likewise.
+       * rust-lang.c (rust_val_print_str): Likewise.
+       (rust_range): Likewise.
+       (rust_subscript): Likewise.
+       (eval_op_rust_structop): Likewise.
+       (rust_aggregate_operation::evaluate): Likewise.
+       * valarith.c (value_user_defined_op): Likewise.
+       * valops.c (search_struct_method): Change parameter type, update
+       function body accordingly, and update header comment.
+       (value_struct_elt): Change parameter type, update function body
+       accordingly.
+       * value.h (value_struct_elt): Update declaration.
+
 2021-06-25  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        PR gdb/27994
index 49a7d5b36b6ca18a69aae2333b8b651b1854c4aa..f2270c0f6afe65d2d1c997e13c6a9d3fe197b8a7 100644 (file)
@@ -1484,7 +1484,7 @@ desc_bounds (struct value *arr)
 
   else if (is_thick_pntr (type))
     {
-      struct value *p_bounds = value_struct_elt (&arr, NULL, "P_BOUNDS", NULL,
+      struct value *p_bounds = value_struct_elt (&arr, {}, "P_BOUNDS", NULL,
                                               _("Bad GNAT array descriptor"));
       struct type *p_bounds_type = value_type (p_bounds);
 
@@ -1566,7 +1566,7 @@ desc_data (struct value *arr)
   if (is_thin_pntr (type))
     return thin_data_pntr (arr);
   else if (is_thick_pntr (type))
-    return value_struct_elt (&arr, NULL, "P_ARRAY", NULL,
+    return value_struct_elt (&arr, {}, "P_ARRAY", NULL,
                             _("Bad GNAT array descriptor"));
   else
     return NULL;
@@ -1606,7 +1606,7 @@ desc_one_bound (struct value *bounds, int i, int which)
   char bound_name[20];
   xsnprintf (bound_name, sizeof (bound_name), "%cB%d",
             which ? 'U' : 'L', i - 1);
-  return value_struct_elt (&bounds, NULL, bound_name, NULL,
+  return value_struct_elt (&bounds, {}, bound_name, NULL,
                           _("Bad GNAT array descriptor bounds"));
 }
 
index 5a72bf1becb215953ef6d159bfd945bbdf2b0c4d..5c348c34e6656870a1fa36d9863521df39423483 100644 (file)
@@ -947,7 +947,7 @@ structop_base_operation::evaluate_funcall
     {
       struct value *temp = vals[0];
 
-      callee = value_struct_elt (&temp, &arg_view, tstr,
+      callee = value_struct_elt (&temp, arg_view, tstr,
                                 &static_memfuncp,
                                 op == STRUCTOP_STRUCT
                                 ? "structure" : "structure pointer");
@@ -1132,7 +1132,7 @@ eval_op_structop_struct (struct type *expect_type, struct expression *exp,
                         enum noside noside,
                         struct value *arg1, const char *string)
 {
-  struct value *arg3 = value_struct_elt (&arg1, NULL, string,
+  struct value *arg3 = value_struct_elt (&arg1, {}, string,
                                         NULL, "structure");
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
@@ -1188,7 +1188,7 @@ eval_op_structop_ptr (struct type *expect_type, struct expression *exp,
       }
   }
 
-  struct value *arg3 = value_struct_elt (&arg1, NULL, string,
+  struct value *arg3 = value_struct_elt (&arg1, {}, string,
                                         NULL, "structure pointer");
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
index 5731c40030545e176e88bf152e29d7bca900b0eb..16ec9e04044b899b59560e9cdc72a15441f98372 100644 (file)
@@ -1511,7 +1511,7 @@ fortran_structop_operation::evaluate (struct type *expect_type,
        arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, EVAL_NORMAL);
     }
 
-  value *elt = value_struct_elt (&arg1, NULL, str, NULL, "structure");
+  value *elt = value_struct_elt (&arg1, {}, str, NULL, "structure");
 
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     {
index 24bb55479570fa0ed86369f1c53ad8d467fcbe72..d4d76df0411d529b976eee927807a0c393ce4c68 100644 (file)
@@ -694,7 +694,7 @@ gdbscm_value_field (SCM self, SCM field_scm)
 
       struct value *tmp = v_smob->value;
 
-      struct value *res_val = value_struct_elt (&tmp, NULL, field.get (), NULL,
+      struct value *res_val = value_struct_elt (&tmp, {}, field.get (), NULL,
                                                "struct/class/union");
 
       return vlscm_scm_from_value (res_val);
index be1a8ed143739f20b30282dc929d2f476ffebfc1..911d67d86721d1d665087c789fa482177077e6e6 100644 (file)
@@ -50,7 +50,7 @@ eval_op_m2_high (struct type *expect_type, struct expression *exp,
 
          type = type->field (1).type ();
          /* i18n: Do not translate the "_m2_high" part!  */
-         arg1 = value_struct_elt (&temp, NULL, "_m2_high", NULL,
+         arg1 = value_struct_elt (&temp, {}, "_m2_high", NULL,
                                   _("unbounded structure "
                                     "missing _m2_high field"));
 
@@ -83,7 +83,7 @@ eval_op_m2_subscript (struct type *expect_type, struct expression *exp,
        error (_("internal error: unbounded "
                 "array structure is unknown"));
       /* i18n: Do not translate the "_m2_contents" part!  */
-      arg1 = value_struct_elt (&temp, NULL, "_m2_contents", NULL,
+      arg1 = value_struct_elt (&temp, {}, "_m2_contents", NULL,
                               _("unbounded structure "
                                 "missing _m2_contents field"));
          
index 1d6117a928518f72103f1f5e67d65e412e748922..136969ead7664928efa72a7ec621a414b9fe09d3 100644 (file)
@@ -708,7 +708,7 @@ opencl_structop_operation::evaluate (struct type *expect_type,
                                 noside);
   else
     {
-      struct value *v = value_struct_elt (&arg1, NULL,
+      struct value *v = value_struct_elt (&arg1, {},
                                          std::get<1> (m_storage).c_str (),
                                          NULL, "structure");
 
index 43da8f0fbc49b6a2224cb6373a1510cfae1dc0e6..8df8a15f8d6b2697118cadfd45d7aff55812dc0e 100644 (file)
@@ -992,7 +992,7 @@ valpy_getitem (PyObject *self, PyObject *key)
       scoped_value_mark free_values;
 
       if (field)
-       res_val = value_struct_elt (&tmp, NULL, field.get (), NULL,
+       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,
index 3b15bb22a27c0e7c7b2b4a755bcee57f7c740111..60ea89b139493947a5cda159f98dd6ae8decb7c9 100644 (file)
@@ -302,9 +302,9 @@ static void
 rust_val_print_str (struct ui_file *stream, struct value *val,
                    const struct value_print_options *options)
 {
-  struct value *base = value_struct_elt (&val, NULL, "data_ptr", NULL,
+  struct value *base = value_struct_elt (&val, {}, "data_ptr", NULL,
                                         "slice");
-  struct value *len = value_struct_elt (&val, NULL, "length", NULL, "slice");
+  struct value *len = value_struct_elt (&val, {}, "length", NULL, "slice");
 
   val_print_string (TYPE_TARGET_TYPE (value_type (base)), "UTF-8",
                    value_as_address (base), value_as_long (len), stream,
@@ -1030,7 +1030,7 @@ rust_range (struct type *expect_type, struct expression *exp,
 
   if (low != NULL)
     {
-      struct value *start = value_struct_elt (&result, NULL, "start", NULL,
+      struct value *start = value_struct_elt (&result, {}, "start", NULL,
                                              "range");
 
       value_assign (start, low);
@@ -1038,7 +1038,7 @@ rust_range (struct type *expect_type, struct expression *exp,
 
   if (high != NULL)
     {
-      struct value *end = value_struct_elt (&result, NULL, "end", NULL,
+      struct value *end = value_struct_elt (&result, {}, "end", NULL,
                                            "range");
 
       value_assign (end, high);
@@ -1176,8 +1176,8 @@ rust_subscript (struct type *expect_type, struct expression *exp,
        {
          struct value *len;
 
-         base = value_struct_elt (&lhs, NULL, "data_ptr", NULL, "slice");
-         len = value_struct_elt (&lhs, NULL, "length", NULL, "slice");
+         base = value_struct_elt (&lhs, {}, "data_ptr", NULL, "slice");
+         len = value_struct_elt (&lhs, {}, "length", NULL, "slice");
          low_bound = 0;
          high_bound = value_as_long (len);
        }
@@ -1400,7 +1400,7 @@ eval_op_rust_structop (struct type *expect_type, struct expression *exp,
 
       try
        {
-         result = value_struct_elt (&lhs, NULL, field_name,
+         result = value_struct_elt (&lhs, {}, field_name,
                                     NULL, "structure");
        }
       catch (const gdb_exception_error &except)
@@ -1411,7 +1411,7 @@ eval_op_rust_structop (struct type *expect_type, struct expression *exp,
        }
     }
   else
-    result = value_struct_elt (&lhs, NULL, field_name, NULL, "structure");
+    result = value_struct_elt (&lhs, {}, field_name, NULL, "structure");
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     result = value_zero (value_type (result), VALUE_LVAL (result));
   return result;
@@ -1457,7 +1457,7 @@ rust_aggregate_operation::evaluate (struct type *expect_type,
       if (noside == EVAL_NORMAL)
        {
          const char *fieldname = item.first.c_str ();
-         value *field = value_struct_elt (&result, nullptr, fieldname,
+         value *field = value_struct_elt (&result, {}, fieldname,
                                           nullptr, "structure");
          value_assign (field, val);
        }
index d61ad9170f819cb13754f29cb87af045c8ed814f..9ebad648b27bd6f7a23973c26a53b829452d0877 100644 (file)
@@ -344,7 +344,7 @@ value_user_defined_op (struct value **argp, gdb::array_view<value *> args,
                                          noside);
     }
   else
-    result = value_struct_elt (argp, &args, name, static_memfuncp,
+    result = value_struct_elt (argp, args, name, static_memfuncp,
                               "structure");
 
   return result;
index 0af7a6c3f27c18e892f76c252fe1c865b878fc5b..bd547923496f4b39a3651b47679771eaf3feb4fc 100644 (file)
@@ -51,7 +51,7 @@ static struct value *search_struct_field (const char *, struct value *,
                                          struct type *, int);
 
 static struct value *search_struct_method (const char *, struct value **,
-                                          gdb::array_view<value *> *,
+                                          gdb::optional<gdb::array_view<value *>>,
                                           LONGEST, int *, struct type *);
 
 static int find_oload_champ_namespace (gdb::array_view<value *> args,
@@ -2177,17 +2177,18 @@ search_struct_field (const char *name, struct value *arg1,
    ARG1 by OFFSET bytes, and search in it assuming it has (class) type
    TYPE.
 
-   The ARGS array pointer is to a list of argument values used to help
-   finding NAME, though ARGS can be nullptr.  The contents of ARGS can be
-   adjusted if type coercion is required in order to find a matching NAME.
+   ARGS is an optional array of argument values used to help finding NAME.
+   The contents of ARGS can be adjusted if type coercion is required in
+   order to find a matching NAME.
 
    If found, return value, else if name matched and args not return
    (value) -1, else return NULL.  */
 
 static struct value *
 search_struct_method (const char *name, struct value **arg1p,
-                     gdb::array_view<value *> *args, LONGEST offset,
-                     int *static_memfuncp, struct type *type)
+                     gdb::optional<gdb::array_view<value *>> args,
+                     LONGEST offset, int *static_memfuncp,
+                     struct type *type)
 {
   int i;
   struct value *v;
@@ -2205,10 +2206,10 @@ search_struct_method (const char *name, struct value **arg1p,
 
          name_matched = 1;
          check_stub_method_group (type, i);
-         if (j > 0 && args == nullptr)
+         if (j > 0 && !args.has_value ())
            error (_("cannot resolve overloaded method "
                     "`%s': no arguments supplied"), name);
-         else if (j == 0 && args == nullptr)
+         else if (j == 0 && !args.has_value ())
            {
              v = value_fn_field (arg1p, f, j, type, offset);
              if (v != NULL)
@@ -2217,7 +2218,7 @@ search_struct_method (const char *name, struct value **arg1p,
          else
            while (j >= 0)
              {
-               gdb_assert (args != nullptr);
+               gdb_assert (args.has_value ());
                if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j),
                              TYPE_FN_FIELD_TYPE (f, j)->has_varargs (),
                              TYPE_FN_FIELD_TYPE (f, j)->num_fields (),
@@ -2320,7 +2321,8 @@ search_struct_method (const char *name, struct value **arg1p,
    found.  */
 
 struct value *
-value_struct_elt (struct value **argp, gdb::array_view<value *> *args,
+value_struct_elt (struct value **argp,
+                 gdb::optional<gdb::array_view<value *>> args,
                  const char *name, int *static_memfuncp, const char *err)
 {
   struct type *t;
@@ -2350,7 +2352,7 @@ value_struct_elt (struct value **argp, gdb::array_view<value *> *args,
   if (static_memfuncp)
     *static_memfuncp = 0;
 
-  if (args == nullptr)
+  if (!args.has_value ())
     {
       /* if there are no arguments ...do this...  */
 
index 40ad28e3dbb2787b921f35f9fc97f4e0672403b5..379cddafbe7fa8064110d7595cf296ca0b3127e1 100644 (file)
@@ -826,7 +826,7 @@ extern struct value *value_neg (struct value *arg1);
 extern struct value *value_complement (struct value *arg1);
 
 extern struct value *value_struct_elt (struct value **argp,
-                                      gdb::array_view <value *> *args,
+                                      gdb::optional<gdb::array_view <value *>> args,
                                       const char *name, int *static_memfuncp,
                                       const char *err);