+2020-05-14 Simon Marchi <simon.marchi@efficios.com>
+
+ * gdbtypes.h (struct type) <code, set_code>: New methods.
+ (TYPE_CODE): Use type::code. Change all call sites used to set
+ the code to use type::set_code instead.
+
2020-05-14 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Tom de Vries <tdevries@suse.de>
Pedro Alves <palves@redhat.com>
{
struct type *type = alloc_type_copy (templ);
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
TYPE_NFIELDS (type) = 0;
TYPE_FIELDS (type) = NULL;
INIT_NONE_SPECIFIC (type);
}
rtype = alloc_type_copy (type);
- TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
+ rtype->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (rtype);
TYPE_NFIELDS (rtype) = nfields;
TYPE_FIELDS (rtype) = (struct field *)
if (type == type0)
{
TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
- TYPE_CODE (type) = TYPE_CODE (type0);
+ type->set_code (TYPE_CODE(type0));
INIT_NONE_SPECIFIC (type);
TYPE_NFIELDS (type) = nfields;
TYPE_FIELDS (type) = (struct field *)
dval = dval0;
rtype = alloc_type_copy (type);
- TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
+ rtype->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (rtype);
TYPE_NFIELDS (rtype) = nfields;
TYPE_FIELDS (rtype) =
/* The result type will have code OP_STRING, bashed there from
OP_ARRAY. Bash it back. */
if (TYPE_CODE (value_type (result)) == TYPE_CODE_STRING)
- TYPE_CODE (value_type (result)) = TYPE_CODE_ARRAY;
+ value_type (result)->set_code (TYPE_CODE_ARRAY);
return result;
}
{
/* Anonymous structure type. */
type = coff_alloc_type (cs->c_symnum);
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
TYPE_NAME (type) = NULL;
INIT_CPLUS_SPECIFIC (type);
TYPE_LENGTH (type) = 0;
aux->x_sym.x_fcnary.x_fcn.x_endndx.l,
objfile);
}
- TYPE_CODE (type) = TYPE_CODE_UNION;
+ type->set_code (TYPE_CODE_UNION);
return type;
case T_ENUM:
{
/* Anonymous enum type. */
type = coff_alloc_type (cs->c_symnum);
- TYPE_CODE (type) = TYPE_CODE_ENUM;
+ type->set_code (TYPE_CODE_ENUM);
TYPE_NAME (type) = NULL;
TYPE_LENGTH (type) = 0;
TYPE_FIELDS (type) = 0;
int done = 0;
type = coff_alloc_type (index);
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
INIT_CPLUS_SPECIFIC (type);
TYPE_LENGTH (type) = length;
TYPE_LENGTH (type) = length;
else /* Assume ints. */
TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
- TYPE_CODE (type) = TYPE_CODE_ENUM;
+ type->set_code (TYPE_CODE_ENUM);
TYPE_NFIELDS (type) = nsyms;
TYPE_FIELDS (type) = (struct field *)
TYPE_ALLOC (type, sizeof (struct field) * nsyms);
kind = ctf_type_kind (fp, tid);
if (kind == CTF_K_UNION)
- TYPE_CODE (type) = TYPE_CODE_UNION;
+ type->set_code (TYPE_CODE_UNION);
else
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
TYPE_LENGTH (type) = ctf_type_size (fp, tid);
set_type_align (type, ctf_type_align (fp, tid));
if (name != NULL && strlen (name.get ()) != 0)
TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name.get ());
- TYPE_CODE (type) = TYPE_CODE_FUNC;
+ type->set_code (TYPE_CODE_FUNC);
ctf_func_type_info (fp, tid, &cfi);
rettype = get_tid_type (of, cfi.ctc_return);
TYPE_TARGET_TYPE (type) = rettype;
if (name != NULL && strlen (name.get ()) != 0)
TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name.get ());
- TYPE_CODE (type) = TYPE_CODE_ENUM;
+ type->set_code (TYPE_CODE_ENUM);
TYPE_LENGTH (type) = ctf_type_size (fp, tid);
ctf_func_type_info (fp, tid, &fi);
target_type = get_tid_type (of, fi.ctc_return);
/* Smash this type to be a structure type. We have to do this
because the type has already been recorded. */
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
TYPE_NFIELDS (type) = 3;
/* Save the field we care about. */
struct field saved_field = TYPE_FIELD (type, 0);
{
/* Smash this type to be a structure type. We have to do this
because the type has already been recorded. */
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
struct type *field_type = TYPE_FIELD_TYPE (type, 0);
const char *variant_name
/* Smash this type to be a structure type. We have to do this
because the type has already been recorded. */
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
/* Make space for the discriminant field. */
struct field *disr_field = &TYPE_FIELD (disr_type, 0);
if (die->tag == DW_TAG_structure_type)
{
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
}
else if (die->tag == DW_TAG_union_type)
{
- TYPE_CODE (type) = TYPE_CODE_UNION;
+ type->set_code (TYPE_CODE_UNION);
}
else
{
- TYPE_CODE (type) = TYPE_CODE_STRUCT;
+ type->set_code (TYPE_CODE_STRUCT);
}
if (cu->language == language_cplus && die->tag == DW_TAG_class_type)
type = alloc_type (objfile);
- TYPE_CODE (type) = TYPE_CODE_ENUM;
+ type->set_code (TYPE_CODE_ENUM);
name = dwarf2_full_name (NULL, die, cu);
if (name != NULL)
TYPE_NAME (type) = name;
TYPE_MAIN_TYPE (type) = &m_main_type;
TYPE_LENGTH (type) = 1;
- TYPE_CODE (type) = TYPE_CODE_METHOD;
+ type->set_code (TYPE_CODE_METHOD);
TYPE_CHAIN (type) = type;
TYPE_INSTANCE_FLAGS (type) = flags;
if (num_types > 0)
/* Initialize the fields that might not be zero. */
- TYPE_CODE (type) = TYPE_CODE_UNDEF;
+ type->set_code (TYPE_CODE_UNDEF);
TYPE_CHAIN (type) = type; /* Chain back to itself. */
return type;
/* Initialize the fields that might not be zero. */
- TYPE_CODE (type) = TYPE_CODE_UNDEF;
+ type->set_code (TYPE_CODE_UNDEF);
TYPE_CHAIN (type) = type; /* Chain back to itself. */
return type;
TYPE_LENGTH (ntype)
= gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
- TYPE_CODE (ntype) = TYPE_CODE_PTR;
+ ntype->set_code (TYPE_CODE_PTR);
/* Mark pointers as unsigned. The target converts between pointers
and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and
TYPE_LENGTH (ntype) =
gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
- TYPE_CODE (ntype) = refcode;
+ ntype->set_code (refcode);
*reftype = ntype;
TYPE_TARGET_TYPE (ntype) = type;
TYPE_LENGTH (ntype) = 1;
- TYPE_CODE (ntype) = TYPE_CODE_FUNC;
+ ntype->set_code (TYPE_CODE_FUNC);
INIT_FUNC_SPECIFIC (ntype);
struct type *mtype;
mtype = alloc_type_copy (type);
- TYPE_CODE (mtype) = TYPE_CODE_METHOD;
+ mtype->set_code (TYPE_CODE_METHOD);
TYPE_LENGTH (mtype) = 1;
TYPE_STUB (mtype) = 1;
TYPE_TARGET_TYPE (mtype) = type;
if (result_type == NULL)
result_type = alloc_type_copy (index_type);
- TYPE_CODE (result_type) = TYPE_CODE_RANGE;
+ result_type->set_code (TYPE_CODE_RANGE);
TYPE_TARGET_TYPE (result_type) = index_type;
if (TYPE_STUB (index_type))
TYPE_TARGET_STUB (result_type) = 1;
if (result_type == NULL)
result_type = alloc_type_copy (range_type);
- TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
+ result_type->set_code (TYPE_CODE_ARRAY);
TYPE_TARGET_TYPE (result_type) = element_type;
TYPE_NFIELDS (result_type) = 1;
result_type = create_array_type (result_type,
string_char_type,
range_type);
- TYPE_CODE (result_type) = TYPE_CODE_STRING;
+ result_type->set_code (TYPE_CODE_STRING);
return result_type;
}
result_type = lookup_array_range_type (string_char_type,
low_bound, high_bound);
- TYPE_CODE (result_type) = TYPE_CODE_STRING;
+ result_type->set_code (TYPE_CODE_STRING);
return result_type;
}
if (result_type == NULL)
result_type = alloc_type_copy (domain_type);
- TYPE_CODE (result_type) = TYPE_CODE_SET;
+ result_type->set_code (TYPE_CODE_SET);
TYPE_NFIELDS (result_type) = 1;
TYPE_FIELDS (result_type)
= (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
struct type *to_type)
{
smash_type (type);
- TYPE_CODE (type) = TYPE_CODE_MEMBERPTR;
+ type->set_code (TYPE_CODE_MEMBERPTR);
TYPE_TARGET_TYPE (type) = to_type;
set_type_self_type (type, self_type);
/* Assume that a data member pointer is the same size as a normal
smash_to_methodptr_type (struct type *type, struct type *to_type)
{
smash_type (type);
- TYPE_CODE (type) = TYPE_CODE_METHODPTR;
+ type->set_code (TYPE_CODE_METHODPTR);
TYPE_TARGET_TYPE (type) = to_type;
set_type_self_type (type, TYPE_SELF_TYPE (to_type));
TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
int nargs, int varargs)
{
smash_type (type);
- TYPE_CODE (type) = TYPE_CODE_METHOD;
+ type->set_code (TYPE_CODE_METHOD);
TYPE_TARGET_TYPE (type) = to_type;
set_type_self_type (type, self_type);
TYPE_FIELDS (type) = args;
static void
set_type_code (struct type *type, enum type_code code)
{
- TYPE_CODE (type) = code;
+ type->set_code (code);
switch (code)
{
struct type
{
+ /* Get the type code of this type.
+
+ Note that the code can be TYPE_CODE_TYPEDEF, so if you want the real
+ type, you need to do `check_typedef (type)->code ()`. */
+ type_code code () const
+ {
+ return this->main_type->code;
+ }
+
+ /* Set the type code of this type. */
+ void set_code (type_code code)
+ {
+ this->main_type->code = code;
+ }
+
/* * Return the dynamic property of the requested KIND from this type's
list of dynamic properties. */
dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
space in struct type. */
extern bool set_type_align (struct type *, ULONGEST);
-/* * Note that TYPE_CODE can be TYPE_CODE_TYPEDEF, so if you want the real
- type, you need to do TYPE_CODE (check_type (this_type)). */
-#define TYPE_CODE(thistype) TYPE_MAIN_TYPE(thistype)->code
+#define TYPE_CODE(thistype) ((thistype)->code ())
#define TYPE_NFIELDS(thistype) TYPE_MAIN_TYPE(thistype)->nfields
#define TYPE_FIELDS(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.fields
TYPE_NAME (t) = obconcat (&mdebugread_objfile->objfile_obstack,
name, (char *) NULL);
- TYPE_CODE (t) = type_code;
+ t->set_code (type_code);
TYPE_LENGTH (t) = sh->value;
TYPE_NFIELDS (t) = nfields;
TYPE_FIELDS (t) = f = ((struct field *)
if (TYPE_CODE (tp) != type_code)
{
- TYPE_CODE (tp) = type_code;
+ tp->set_code (type_code);
}
/* Do not set the tag name if it is a compiler generated tag name
if (TYPE_CODE (tp) != type_code)
{
bad_tag_guess_complaint (sym_name);
- TYPE_CODE (tp) = type_code;
+ tp->set_code (type_code);
}
if (TYPE_NAME (tp) == NULL
|| strcmp (TYPE_NAME (tp), name) != 0)
if (field2 != NULL)
++nfields;
- TYPE_CODE (result) = TYPE_CODE_STRUCT;
+ result->set_code (TYPE_CODE_STRUCT);
TYPE_NAME (result) = name;
TYPE_NFIELDS (result) = nfields;
fill in the rest of the fields when we get the full
type. */
type = dbx_alloc_type (typenums, objfile);
- TYPE_CODE (type) = code;
+ type->set_code (code);
TYPE_NAME (type) = type_name;
INIT_CPLUS_SPECIFIC (type);
TYPE_STUB (type) = 1;
/* Allocate and enter the typedef type first.
This handles recursive types. */
type = dbx_alloc_type (typenums, objfile);
- TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
+ type->set_code (TYPE_CODE_TYPEDEF);
{
struct type *xtype = read_type (pp, objfile);
if (type == xtype)
{
/* It's being defined as itself. That means it is "void". */
- TYPE_CODE (type) = TYPE_CODE_VOID;
+ type->set_code (TYPE_CODE_VOID);
TYPE_LENGTH (type) = 1;
}
else if (type_size >= 0 || is_string)
type = dbx_alloc_type (typenums, objfile);
type = read_array_type (pp, type, objfile);
if (is_string)
- TYPE_CODE (type) = TYPE_CODE_STRING;
+ type->set_code (TYPE_CODE_STRING);
if (is_vector)
make_vector_type (type);
break;
/* These are methods, not functions. */
if (TYPE_CODE (new_sublist->fn_field.type) == TYPE_CODE_FUNC)
- TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
+ new_sublist->fn_field.type->set_code (TYPE_CODE_METHOD);
else
gdb_assert (TYPE_CODE (new_sublist->fn_field.type)
== TYPE_CODE_METHOD);
}
INIT_CPLUS_SPECIFIC (type);
- TYPE_CODE (type) = type_code;
+ type->set_code (type_code);
TYPE_STUB (type) = 0;
/* First comes the total size in bytes. */
TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
set_length_in_type_chain (type);
- TYPE_CODE (type) = TYPE_CODE_ENUM;
+ type->set_code (TYPE_CODE_ENUM);
TYPE_STUB (type) = 0;
if (unsigned_enum)
TYPE_UNSIGNED (type) = 1;
slice_type = create_array_type (NULL,
element_type,
slice_range_type);
- TYPE_CODE (slice_type) = TYPE_CODE (array_type);
+ slice_type->set_code (TYPE_CODE (array_type));
if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
slice = allocate_value_lazy (slice_type);