diff options
author | Tom Tromey <tromey@adacore.com> | 2023-04-27 10:59:59 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-05-05 13:52:52 -0600 |
commit | 100c7a99a5d4c30bb73d49a65eb45d1039646eaa (patch) | |
tree | 0924efb9c477c0c16b78f1e0e7b2a307cbef8b09 /gdb | |
parent | 3965bff5b9ae0957dfa882f7480dd20dae7adbfc (diff) | |
download | binutils-100c7a99a5d4c30bb73d49a65eb45d1039646eaa.zip binutils-100c7a99a5d4c30bb73d49a65eb45d1039646eaa.tar.gz binutils-100c7a99a5d4c30bb73d49a65eb45d1039646eaa.tar.bz2 |
Use discrete_position in ada-valprint.c
I found a couple of spots in ada-valprint.c that use an explicit loop,
but where discrete_position could be used instead.
Reviewed-by: Keith Seitz <keiths@redhat.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ada-valprint.c | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 24a7ea2..ca5608f 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -364,9 +364,6 @@ ada_printchar (int c, struct type *type, struct ui_file *stream) void ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) { - unsigned int i; - unsigned len; - if (!type) { print_longest (stream, 'd', 0, val); @@ -379,23 +376,14 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) { case TYPE_CODE_ENUM: - len = type->num_fields (); - for (i = 0; i < len; i++) - { - if (type->field (i).loc_enumval () == val) - { - break; - } - } - if (i < len) - { - fputs_styled (ada_enum_name (type->field (i).name ()), + { + gdb::optional<LONGEST> posn = discrete_position (type, val); + if (posn.has_value ()) + fputs_styled (ada_enum_name (type->field (*posn).name ()), variable_name_style.style (), stream); - } - else - { + else print_longest (stream, 'd', 0, val); - } + } break; case TYPE_CODE_INT: @@ -818,8 +806,6 @@ static void ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse, const struct value_print_options *options) { - int i; - unsigned int len; LONGEST val; if (options->format) @@ -832,18 +818,11 @@ ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse, const gdb_byte *valaddr = value->contents_for_printing ().data (); int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr; - len = type->num_fields (); val = unpack_long (type, valaddr + offset_aligned); - for (i = 0; i < len; i++) - { - QUIT; - if (val == type->field (i).loc_enumval ()) - break; - } - - if (i < len) + gdb::optional<LONGEST> posn = discrete_position (type, val); + if (posn.has_value ()) { - const char *name = ada_enum_name (type->field (i).name ()); + const char *name = ada_enum_name (type->field (*posn).name ()); if (name[0] == '\'') gdb_printf (stream, "%ld %ps", (long) val, |