gdb: add type::is_unsigned / type::set_is_unsigned

Add the `is_unsigned` and `set_is_unsigned` methods on `struct type`, in
order to remove the `TYPE_UNSIGNED` macro.  In this patch, the
`TYPE_UNSIGNED` macro is changed to use `type::is_unsigned`, so all the
call sites that are used to set this property on a type are changed to
use the new method.  The next patch will remove the macro completely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <is_unsigned, set_is_unsigned>: New
	methods.
	(TYPE_UNSIGNED): Use type::is_unsigned.  Change all write call
	sites to use type::set_is_unsigned.

Change-Id: Ib09ddce84eda160a801a8f288cccf61c8ef136bc
This commit is contained in:
Simon Marchi 2020-09-14 11:07:56 -04:00
parent 55ea94da36
commit 653223d356
10 changed files with 48 additions and 27 deletions

View file

@ -1,3 +1,10 @@
2020-09-14 Simon Marchi <simon.marchi@efficios.com>
* gdbtypes.h (struct type) <is_unsigned, set_is_unsigned>: New
methods.
(TYPE_UNSIGNED): Use type::is_unsigned. Change all write call
sites to use type::set_is_unsigned.
2020-09-14 Fredrik Hederstierna <fredrik.hederstierna@verisure.com> 2020-09-14 Fredrik Hederstierna <fredrik.hederstierna@verisure.com>
Adam Renquinha <arenquinha@cimeq.qc.ca> Adam Renquinha <arenquinha@cimeq.qc.ca>

View file

@ -43,7 +43,7 @@ adjust_type_signedness (struct type *type)
{ {
if (type != NULL && type->code () == TYPE_CODE_RANGE if (type != NULL && type->code () == TYPE_CODE_RANGE
&& type->bounds ()->low.const_val () >= 0) && type->bounds ()->low.const_val () >= 0)
TYPE_UNSIGNED (type) = 1; type->set_is_unsigned (true);
} }
/* Assuming TYPE is a simple array type, prints its lower bound on STREAM, /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,

View file

@ -2152,7 +2152,7 @@ coff_read_enum_type (int index, int length, int lastsym,
} }
if (unsigned_enum) if (unsigned_enum)
TYPE_UNSIGNED (type) = 1; type->set_is_unsigned (true);
return type; return type;
} }

View file

@ -16568,7 +16568,8 @@ update_enumeration_type_from_children (struct die_info *die,
} }
if (unsigned_enum) if (unsigned_enum)
TYPE_UNSIGNED (type) = 1; type->set_is_unsigned (true);
if (flag_enum) if (flag_enum)
TYPE_FLAG_ENUM (type) = 1; TYPE_FLAG_ENUM (type) = 1;
} }
@ -16643,9 +16644,12 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
{ {
struct type *underlying_type = TYPE_TARGET_TYPE (type); struct type *underlying_type = TYPE_TARGET_TYPE (type);
underlying_type = check_typedef (underlying_type); underlying_type = check_typedef (underlying_type);
TYPE_UNSIGNED (type) = TYPE_UNSIGNED (underlying_type);
type->set_is_unsigned (underlying_type->is_unsigned ());
if (TYPE_LENGTH (type) == 0) if (TYPE_LENGTH (type) == 0)
TYPE_LENGTH (type) = TYPE_LENGTH (underlying_type); TYPE_LENGTH (type) = TYPE_LENGTH (underlying_type);
if (TYPE_RAW_ALIGN (type) == 0 if (TYPE_RAW_ALIGN (type) == 0
&& TYPE_RAW_ALIGN (underlying_type) != 0) && TYPE_RAW_ALIGN (underlying_type) != 0)
set_type_align (type, TYPE_RAW_ALIGN (underlying_type)); set_type_align (type, TYPE_RAW_ALIGN (underlying_type));

View file

@ -375,7 +375,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
/* Mark pointers as unsigned. The target converts between pointers /* Mark pointers as unsigned. The target converts between pointers
and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
gdbarch_address_to_pointer. */ gdbarch_address_to_pointer. */
TYPE_UNSIGNED (ntype) = 1; ntype->set_is_unsigned (true);
/* Update the length of all the other variants of this type. */ /* Update the length of all the other variants of this type. */
chain = TYPE_CHAIN (ntype); chain = TYPE_CHAIN (ntype);
@ -949,14 +949,14 @@ create_range_type (struct type *result_type, struct type *index_type,
result_type->set_bounds (bounds); result_type->set_bounds (bounds);
if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0) if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0)
TYPE_UNSIGNED (result_type) = 1; result_type->set_is_unsigned (true);
/* Ada allows the declaration of range types whose upper bound is /* Ada allows the declaration of range types whose upper bound is
less than the lower bound, so checking the lower bound is not less than the lower bound, so checking the lower bound is not
enough. Make sure we do not mark a range type whose upper bound enough. Make sure we do not mark a range type whose upper bound
is negative as unsigned. */ is negative as unsigned. */
if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0) if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0)
TYPE_UNSIGNED (result_type) = 0; result_type->set_is_unsigned (false);
TYPE_ENDIANITY_NOT_DEFAULT (result_type) TYPE_ENDIANITY_NOT_DEFAULT (result_type)
= TYPE_ENDIANITY_NOT_DEFAULT (index_type); = TYPE_ENDIANITY_NOT_DEFAULT (index_type);
@ -1073,9 +1073,7 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
/* Set unsigned indicator if warranted. */ /* Set unsigned indicator if warranted. */
if (*lowp >= 0) if (*lowp >= 0)
{ type->set_is_unsigned (true);
TYPE_UNSIGNED (type) = 1;
}
} }
else else
{ {
@ -1400,7 +1398,7 @@ create_set_type (struct type *result_type, struct type *domain_type)
TYPE_LENGTH (result_type) TYPE_LENGTH (result_type)
= (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
if (low_bound >= 0) if (low_bound >= 0)
TYPE_UNSIGNED (result_type) = 1; result_type->set_is_unsigned (true);
} }
result_type->field (0).set_type (domain_type); result_type->field (0).set_type (domain_type);
@ -3191,7 +3189,7 @@ init_integer_type (struct objfile *objfile,
t = init_type (objfile, TYPE_CODE_INT, bit, name); t = init_type (objfile, TYPE_CODE_INT, bit, name);
if (unsigned_p) if (unsigned_p)
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -3208,7 +3206,7 @@ init_character_type (struct objfile *objfile,
t = init_type (objfile, TYPE_CODE_CHAR, bit, name); t = init_type (objfile, TYPE_CODE_CHAR, bit, name);
if (unsigned_p) if (unsigned_p)
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -3225,7 +3223,7 @@ init_boolean_type (struct objfile *objfile,
t = init_type (objfile, TYPE_CODE_BOOL, bit, name); t = init_type (objfile, TYPE_CODE_BOOL, bit, name);
if (unsigned_p) if (unsigned_p)
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -3319,7 +3317,7 @@ init_pointer_type (struct objfile *objfile,
t = init_type (objfile, TYPE_CODE_PTR, bit, name); t = init_type (objfile, TYPE_CODE_PTR, bit, name);
TYPE_TARGET_TYPE (t) = target_type; TYPE_TARGET_TYPE (t) = target_type;
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -5477,7 +5475,7 @@ arch_integer_type (struct gdbarch *gdbarch,
t = arch_type (gdbarch, TYPE_CODE_INT, bit, name); t = arch_type (gdbarch, TYPE_CODE_INT, bit, name);
if (unsigned_p) if (unsigned_p)
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -5494,7 +5492,7 @@ arch_character_type (struct gdbarch *gdbarch,
t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name); t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name);
if (unsigned_p) if (unsigned_p)
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -5511,7 +5509,7 @@ arch_boolean_type (struct gdbarch *gdbarch,
t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name); t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name);
if (unsigned_p) if (unsigned_p)
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -5561,7 +5559,7 @@ arch_pointer_type (struct gdbarch *gdbarch,
t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name); t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
TYPE_TARGET_TYPE (t) = target_type; TYPE_TARGET_TYPE (t) = target_type;
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
return t; return t;
} }
@ -5574,7 +5572,7 @@ arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
struct type *type; struct type *type;
type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name); type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name);
TYPE_UNSIGNED (type) = 1; type->set_is_unsigned (true);
type->set_num_fields (0); type->set_num_fields (0);
/* Pre-allocate enough space assuming every field is one bit. */ /* Pre-allocate enough space assuming every field is one bit. */
type->set_fields type->set_fields

View file

@ -213,7 +213,7 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
/* * Unsigned integer type. If this is not set for a TYPE_CODE_INT, /* * Unsigned integer type. If this is not set for a TYPE_CODE_INT,
the type is signed (unless TYPE_NOSIGN (below) is set). */ the type is signed (unless TYPE_NOSIGN (below) is set). */
#define TYPE_UNSIGNED(t) (TYPE_MAIN_TYPE (t)->flag_unsigned) #define TYPE_UNSIGNED(t) ((t)->is_unsigned ())
/* * No sign for this type. In C++, "char", "signed char", and /* * No sign for this type. In C++, "char", "signed char", and
"unsigned char" are distinct types; so we need an extra flag to "unsigned char" are distinct types; so we need an extra flag to
@ -855,7 +855,7 @@ struct main_type
because they packs nicely here. See the TYPE_* macros for because they packs nicely here. See the TYPE_* macros for
documentation about these fields. */ documentation about these fields. */
unsigned int flag_unsigned : 1; unsigned int m_flag_unsigned : 1;
unsigned int flag_nosign : 1; unsigned int flag_nosign : 1;
unsigned int flag_stub : 1; unsigned int flag_stub : 1;
unsigned int flag_target_stub : 1; unsigned int flag_target_stub : 1;
@ -1068,6 +1068,16 @@ struct type
return this->bounds ()->bit_stride (); return this->bounds ()->bit_stride ();
} }
bool is_unsigned () const
{
return this->main_type->m_flag_unsigned;
}
void set_is_unsigned (bool is_unsigned)
{
this->main_type->m_flag_unsigned = is_unsigned;
}
/* * Return the dynamic property of the requested KIND from this type's /* * Return the dynamic property of the requested KIND from this type's
list of dynamic properties. */ list of dynamic properties. */
dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const; dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;

View file

@ -1072,7 +1072,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
f++; f++;
} }
if (unsigned_enum) if (unsigned_enum)
TYPE_UNSIGNED (t) = 1; t->set_is_unsigned (true);
} }
/* Make this the current type. */ /* Make this the current type. */
top_stack->cur_type = t; top_stack->cur_type = t;

View file

@ -3616,7 +3616,7 @@ read_enum_type (const char **pp, struct type *type,
type->set_code (TYPE_CODE_ENUM); type->set_code (TYPE_CODE_ENUM);
TYPE_STUB (type) = 0; TYPE_STUB (type) = 0;
if (unsigned_enum) if (unsigned_enum)
TYPE_UNSIGNED (type) = 1; type->set_is_unsigned (true);
type->set_num_fields (nsyms); type->set_num_fields (nsyms);
type->set_fields type->set_fields
((struct field *) ((struct field *)
@ -3731,7 +3731,8 @@ read_sun_builtin_type (const char **pp, int typenums[2], struct objfile *objfile
struct type *type = init_type (objfile, TYPE_CODE_VOID, struct type *type = init_type (objfile, TYPE_CODE_VOID,
TARGET_CHAR_BIT, NULL); TARGET_CHAR_BIT, NULL);
if (unsigned_type) if (unsigned_type)
TYPE_UNSIGNED (type) = 1; type->set_is_unsigned (true);
return type; return type;
} }

View file

@ -289,7 +289,8 @@ make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype)
m_type = arch_type (m_gdbarch, TYPE_CODE_ENUM, e->size * TARGET_CHAR_BIT, m_type = arch_type (m_gdbarch, TYPE_CODE_ENUM, e->size * TARGET_CHAR_BIT,
e->name.c_str ()); e->name.c_str ());
TYPE_UNSIGNED (m_type) = 1; m_type->set_is_unsigned (true);
for (const tdesc_type_field &f : e->fields) for (const tdesc_type_field &f : e->fields)
{ {
struct field *fld struct field *fld

View file

@ -754,7 +754,7 @@ create_enum (struct gdbarch *gdbarch, int bit, const char *name,
type->set_num_fields (count); type->set_num_fields (count);
type->set_fields type->set_fields
((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count)); ((struct field *) TYPE_ZALLOC (type, sizeof (struct field) * count));
TYPE_UNSIGNED (type) = 1; type->set_is_unsigned (true);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {