Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Remove ada_value_slice
Date: Fri,  5 Jun 2026 15:51:04 -0600	[thread overview]
Message-ID: <20260605215104.656469-1-tromey@adacore.com> (raw)

ada_value_slice and ada_value_slice_from_ptr are nearly identical.
From what I can tell, the former can be removed without any problem.
---
 gdb/ada-lang.c | 46 ++--------------------------------------------
 1 file changed, 2 insertions(+), 44 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index bb044e2c5a0..153debc6569 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3183,49 +3183,6 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
 }
 
 
-static struct value *
-ada_value_slice (struct value *array, LONGEST low, LONGEST high)
-{
-  struct type *type = ada_check_typedef (array->type ());
-  struct type *base_index_type = type->index_type ()->target_type ();
-  type_allocator alloc (type->index_type ());
-  struct type *index_type
-    = create_static_range_type (alloc, type->index_type (), low, high);
-
-  dynamic_prop prop_storage;
-  dynamic_prop *prop = type->dyn_prop (DYN_PROP_BYTE_STRIDE);
-  bool is_byte_stride = true;
-  if (prop == nullptr)
-    {
-      prop = type->dyn_prop (DYN_PROP_BIT_STRIDE);
-      is_byte_stride = false;
-      if (prop == nullptr)
-	{
-	  prop = &prop_storage;
-	  prop->set_const_val (type->field (0).bitsize ());
-	}
-    }
-
-  struct type *slice_type = create_array_type_with_stride
-			      (alloc, type->target_type (), index_type,
-			       prop, is_byte_stride);
-  std::optional<LONGEST> low_pos, high_pos;
-
-
-  low_pos = discrete_position (base_index_type, low);
-  high_pos = discrete_position (base_index_type, high);
-
-  if (!low_pos.has_value () || !high_pos.has_value ())
-    {
-      warning (_("unable to get positions in slice, use bounds instead"));
-      low_pos = low;
-      high_pos = high;
-    }
-
-  return value_cast (slice_type,
-		     value_slice (array, low, *high_pos - *low_pos + 1));
-}
-
 /* If type is a record type in the form of a standard GNAT array
    descriptor, returns the number of dimensions for type.  If arr is a
    simple array, returns the number of "array of"s that prefix its
@@ -10306,7 +10263,8 @@ ada_ternop_slice_operation::evaluate (struct type *expect_type,
   else if (high_bound < low_bound)
     return empty_array (array->type (), low_bound, high_bound);
   else
-    return ada_value_slice (array, low_bound, high_bound);
+    return ada_value_slice_from_ptr (array, array->type (),
+				     low_bound, high_bound);
 }
 
 /* Implement BINOP_IN_BOUNDS.  */

base-commit: 18ad8c1a54d5d0e3fe3ff6c13f217e0dc840f991
-- 
2.54.0


             reply	other threads:[~2026-06-05 21:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 21:51 Tom Tromey [this message]
2026-06-10 18:38 ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260605215104.656469-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox