gdb: add type::target_type / type::set_target_type

Add the `target_type` and `set_target_type` methods on `struct type`, in order
to remove the `TYPE_TARGET_TYPE` macro.  In this patch, the macro is changed to
use the getter, so all the call sites of the macro that are used as a setter
are changed to use the setter method directly.  The next patch will remove the
macro completely.

Change-Id: I85ce24d847763badd34fdee3e14b8c8c14cb3161
This commit is contained in:
Simon Marchi
2022-07-30 12:07:39 -04:00
parent 0242db993f
commit 8a50fdcefc
10 changed files with 70 additions and 61 deletions

View File

@@ -371,7 +371,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
TYPE_CHAIN (ntype) = chain;
}
TYPE_TARGET_TYPE (ntype) = type;
ntype->set_target_type (type);
TYPE_POINTER_TYPE (type) = ntype;
/* FIXME! Assumes the machine has only one representation for pointers! */
@@ -449,7 +449,7 @@ make_reference_type (struct type *type, struct type **typeptr,
TYPE_CHAIN (ntype) = chain;
}
TYPE_TARGET_TYPE (ntype) = type;
ntype->set_target_type (type);
reftype = (refcode == TYPE_CODE_REF ? &TYPE_REFERENCE_TYPE (type)
: &TYPE_RVALUE_REFERENCE_TYPE (type));
@@ -522,7 +522,7 @@ make_function_type (struct type *type, struct type **typeptr)
smash_type (ntype);
}
TYPE_TARGET_TYPE (ntype) = type;
ntype->set_target_type (type);
TYPE_LENGTH (ntype) = 1;
ntype->set_code (TYPE_CODE_FUNC);
@@ -876,7 +876,7 @@ allocate_stub_method (struct type *type)
mtype->set_code (TYPE_CODE_METHOD);
TYPE_LENGTH (mtype) = 1;
mtype->set_is_stub (true);
TYPE_TARGET_TYPE (mtype) = type;
mtype->set_target_type (type);
/* TYPE_SELF_TYPE (mtype) = unknown yet */
return mtype;
}
@@ -941,7 +941,7 @@ create_range_type (struct type *result_type, struct type *index_type,
if (result_type == NULL)
result_type = alloc_type_copy (index_type);
result_type->set_code (TYPE_CODE_RANGE);
TYPE_TARGET_TYPE (result_type) = index_type;
result_type->set_target_type (index_type);
if (index_type->is_stub ())
result_type->set_target_is_stub (true);
else
@@ -1378,7 +1378,7 @@ create_array_type_with_stride (struct type *result_type,
result_type = alloc_type_copy (range_type);
result_type->set_code (TYPE_CODE_ARRAY);
TYPE_TARGET_TYPE (result_type) = element_type;
result_type->set_target_type (element_type);
result_type->set_num_fields (1);
result_type->set_fields
@@ -1522,7 +1522,7 @@ make_vector_type (struct type *array_type)
type_instance_flags flags
= elt_type->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT;
elt_type = make_qualified_type (elt_type, flags, NULL);
TYPE_TARGET_TYPE (inner_array) = elt_type;
inner_array->set_target_type (elt_type);
}
array_type->set_is_vector (true);
@@ -1610,7 +1610,7 @@ smash_to_memberptr_type (struct type *type, struct type *self_type,
{
smash_type (type);
type->set_code (TYPE_CODE_MEMBERPTR);
TYPE_TARGET_TYPE (type) = to_type;
type->set_target_type (to_type);
set_type_self_type (type, self_type);
/* Assume that a data member pointer is the same size as a normal
pointer. */
@@ -1628,7 +1628,7 @@ smash_to_methodptr_type (struct type *type, struct type *to_type)
{
smash_type (type);
type->set_code (TYPE_CODE_METHODPTR);
TYPE_TARGET_TYPE (type) = to_type;
type->set_target_type (to_type);
set_type_self_type (type, TYPE_SELF_TYPE (to_type));
TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
}
@@ -1647,7 +1647,7 @@ smash_to_method_type (struct type *type, struct type *self_type,
{
smash_type (type);
type->set_code (TYPE_CODE_METHOD);
TYPE_TARGET_TYPE (type) = to_type;
type->set_target_type (to_type);
set_type_self_type (type, self_type);
type->set_fields (args);
type->set_num_fields (nargs);
@@ -2438,10 +2438,10 @@ resolve_dynamic_array_or_string (struct type *type,
struct type *rank_type = type;
for (int i = 1; i < rank; i++)
{
TYPE_TARGET_TYPE (rank_type) = copy_type (rank_type);
rank_type->set_target_type (copy_type (rank_type));
rank_type = TYPE_TARGET_TYPE (rank_type);
}
TYPE_TARGET_TYPE (rank_type) = element_type;
rank_type->set_target_type (element_type);
}
}
else
@@ -2782,7 +2782,7 @@ resolve_dynamic_struct (struct type *type,
/* The Ada language uses this field as a cache for static fixed types: reset
it as RESOLVED_TYPE must have its own static fixed type. */
TYPE_TARGET_TYPE (resolved_type) = NULL;
resolved_type->set_target_type (nullptr);
return resolved_type;
}
@@ -2811,11 +2811,11 @@ resolve_dynamic_type_internal (struct type *type,
if (type->code () == TYPE_CODE_TYPEDEF)
{
resolved_type = copy_type (type);
TYPE_TARGET_TYPE (resolved_type)
= resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
top_level);
resolved_type->set_target_type
(resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack,
top_level));
}
else
else
{
/* Before trying to resolve TYPE, make sure it is not a stub. */
type = real_type;
@@ -2836,9 +2836,9 @@ resolve_dynamic_type_internal (struct type *type,
pinfo.next = addr_stack;
resolved_type = copy_type (type);
TYPE_TARGET_TYPE (resolved_type)
= resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
&pinfo, top_level);
resolved_type->set_target_type
(resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type),
&pinfo, top_level));
break;
}
@@ -3034,9 +3034,9 @@ check_typedef (struct type *type)
}
sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
if (sym)
TYPE_TARGET_TYPE (type) = sym->type ();
type->set_target_type (sym->type ());
else /* TYPE_CODE_UNDEF */
TYPE_TARGET_TYPE (type) = alloc_type_arch (type->arch ());
type->set_target_type (alloc_type_arch (type->arch ()));
}
type = TYPE_TARGET_TYPE (type);
@@ -3582,7 +3582,7 @@ init_complex_type (const char *name, struct type *target_type)
TYPE_LENGTH (t) = 2 * TYPE_LENGTH (target_type);
t->set_name (name);
TYPE_TARGET_TYPE (t) = target_type;
t->set_target_type (target_type);
TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type = t;
}
@@ -3601,7 +3601,7 @@ init_pointer_type (struct objfile *objfile,
struct type *t;
t = init_type (objfile, TYPE_CODE_PTR, bit, name);
TYPE_TARGET_TYPE (t) = target_type;
t->set_target_type (target_type);
t->set_is_unsigned (true);
return t;
}
@@ -5728,8 +5728,8 @@ copy_type_recursive (struct type *type, htab_t copied_types)
/* Copy pointers to other types. */
if (TYPE_TARGET_TYPE (type))
TYPE_TARGET_TYPE (new_type) =
copy_type_recursive (TYPE_TARGET_TYPE (type), copied_types);
new_type->set_target_type
(copy_type_recursive (TYPE_TARGET_TYPE (type), copied_types));
/* Maybe copy the type_specific bits.
@@ -5919,7 +5919,7 @@ arch_pointer_type (struct gdbarch *gdbarch,
struct type *t;
t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
TYPE_TARGET_TYPE (t) = target_type;
t->set_target_type (target_type);
t->set_is_unsigned (true);
return t;
}