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);
{
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:
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)
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,