Change how complex types are created
This patch changes how complex types are created. init_complex_type and arch_complex_type are unified, and complex types are reused, by attaching them to the underlying scalar type. gdb/ChangeLog 2020-04-01 Tom Tromey <tom@tromey.com> * stabsread.c (rs6000_builtin_type, read_sun_floating_type) (read_range_type): Update. * mdebugread.c (basic_type): Update. * go-lang.c (build_go_types): Use init_complex_type. * gdbtypes.h (struct main_type) <complex_type>: New member. (init_complex_type): Update. (arch_complex_type): Don't declare. * gdbtypes.c (init_complex_type): Remove "objfile" parameter. Make name if none given. Use alloc_type_copy. Look for cached complex type. (arch_complex_type): Remove. (gdbtypes_post_init): Use init_complex_type. * f-lang.c (build_fortran_types): Use init_complex_type. * dwarf2/read.c (read_base_type): Update. * d-lang.c (build_d_types): Use init_complex_type. * ctfread.c (read_base_type): Update.
This commit is contained in:
parent
3d1cfd43be
commit
5b930b4538
10 changed files with 71 additions and 57 deletions
|
@ -3025,19 +3025,40 @@ init_decfloat_type (struct objfile *objfile, int bit, const char *name)
|
|||
return t;
|
||||
}
|
||||
|
||||
/* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE.
|
||||
NAME is the type name. TARGET_TYPE is the component float type. */
|
||||
/* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type
|
||||
name. TARGET_TYPE is the component type. */
|
||||
|
||||
struct type *
|
||||
init_complex_type (struct objfile *objfile,
|
||||
const char *name, struct type *target_type)
|
||||
init_complex_type (const char *name, struct type *target_type)
|
||||
{
|
||||
struct type *t;
|
||||
|
||||
t = init_type (objfile, TYPE_CODE_COMPLEX,
|
||||
2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
|
||||
TYPE_TARGET_TYPE (t) = target_type;
|
||||
return t;
|
||||
gdb_assert (TYPE_CODE (target_type) == TYPE_CODE_INT
|
||||
|| TYPE_CODE (target_type) == TYPE_CODE_FLT);
|
||||
|
||||
if (TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type == nullptr)
|
||||
{
|
||||
if (name == nullptr)
|
||||
{
|
||||
char *new_name
|
||||
= (char *) TYPE_ALLOC (target_type,
|
||||
strlen (TYPE_NAME (target_type))
|
||||
+ strlen ("_Complex ") + 1);
|
||||
strcpy (new_name, "_Complex ");
|
||||
strcat (new_name, TYPE_NAME (target_type));
|
||||
name = new_name;
|
||||
}
|
||||
|
||||
t = alloc_type_copy (target_type);
|
||||
set_type_code (t, TYPE_CODE_COMPLEX);
|
||||
TYPE_LENGTH (t) = 2 * TYPE_LENGTH (target_type);
|
||||
TYPE_NAME (t) = name;
|
||||
|
||||
TYPE_TARGET_TYPE (t) = target_type;
|
||||
TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type = t;
|
||||
}
|
||||
|
||||
return TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type;
|
||||
}
|
||||
|
||||
/* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
|
||||
|
@ -5259,21 +5280,6 @@ arch_decfloat_type (struct gdbarch *gdbarch, int bit, const char *name)
|
|||
return t;
|
||||
}
|
||||
|
||||
/* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH.
|
||||
NAME is the type name. TARGET_TYPE is the component float type. */
|
||||
|
||||
struct type *
|
||||
arch_complex_type (struct gdbarch *gdbarch,
|
||||
const char *name, struct type *target_type)
|
||||
{
|
||||
struct type *t;
|
||||
|
||||
t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
|
||||
2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
|
||||
TYPE_TARGET_TYPE (t) = target_type;
|
||||
return t;
|
||||
}
|
||||
|
||||
/* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
|
||||
BIT is the pointer type size in bits. NAME is the type name.
|
||||
TARGET_TYPE is the pointer target type. Always sets the pointer type's
|
||||
|
@ -5497,11 +5503,9 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
|
|||
= arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
|
||||
"long double", gdbarch_long_double_format (gdbarch));
|
||||
builtin_type->builtin_complex
|
||||
= arch_complex_type (gdbarch, "complex",
|
||||
builtin_type->builtin_float);
|
||||
= init_complex_type ("complex", builtin_type->builtin_float);
|
||||
builtin_type->builtin_double_complex
|
||||
= arch_complex_type (gdbarch, "double complex",
|
||||
builtin_type->builtin_double);
|
||||
= init_complex_type ("double complex", builtin_type->builtin_double);
|
||||
builtin_type->builtin_string
|
||||
= arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
|
||||
builtin_type->builtin_bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue