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:
Tom Tromey 2020-04-01 14:09:52 -06:00 committed by Tom Tromey
parent 3d1cfd43be
commit 5b930b4538
10 changed files with 71 additions and 57 deletions

View file

@ -1,3 +1,22 @@
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.
2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> 2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* infrun.c (stop_all_threads): Update assertion, plus when * infrun.c (stop_all_threads): Update assertion, plus when

View file

@ -553,7 +553,7 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid)
{ {
struct type *t struct type *t
= ctf_init_float_type (of, cet.cte_bits / 2, NULL, name); = ctf_init_float_type (of, cet.cte_bits / 2, NULL, name);
type = init_complex_type (of, name, t); type = init_complex_type (name, t);
} }
} }
else else

View file

@ -314,14 +314,11 @@ build_d_types (struct gdbarch *gdbarch)
= arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch), = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
"ireal", gdbarch_long_double_format (gdbarch)); "ireal", gdbarch_long_double_format (gdbarch));
builtin_d_type->builtin_cfloat builtin_d_type->builtin_cfloat
= arch_complex_type (gdbarch, "cfloat", = init_complex_type ("cfloat", builtin_d_type->builtin_float);
builtin_d_type->builtin_float);
builtin_d_type->builtin_cdouble builtin_d_type->builtin_cdouble
= arch_complex_type (gdbarch, "cdouble", = init_complex_type ("cdouble", builtin_d_type->builtin_double);
builtin_d_type->builtin_double);
builtin_d_type->builtin_creal builtin_d_type->builtin_creal
= arch_complex_type (gdbarch, "creal", = init_complex_type ("creal", builtin_d_type->builtin_real);
builtin_d_type->builtin_real);
/* Character types. */ /* Character types. */
builtin_d_type->builtin_char builtin_d_type->builtin_char

View file

@ -16880,7 +16880,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
case DW_ATE_complex_float: case DW_ATE_complex_float:
type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name, type = dwarf2_init_complex_target_type (cu, objfile, bits / 2, name,
byte_order); byte_order);
type = init_complex_type (objfile, name, type); type = init_complex_type (name, type);
break; break;
case DW_ATE_decimal_float: case DW_ATE_decimal_float:
type = init_decfloat_type (objfile, bits, name); type = init_decfloat_type (objfile, bits, name);

View file

@ -741,14 +741,11 @@ build_fortran_types (struct gdbarch *gdbarch)
= arch_type (gdbarch, TYPE_CODE_ERROR, 128, "real*16"); = arch_type (gdbarch, TYPE_CODE_ERROR, 128, "real*16");
builtin_f_type->builtin_complex_s8 builtin_f_type->builtin_complex_s8
= arch_complex_type (gdbarch, "complex*8", = init_complex_type ("complex*8", builtin_f_type->builtin_real);
builtin_f_type->builtin_real);
builtin_f_type->builtin_complex_s16 builtin_f_type->builtin_complex_s16
= arch_complex_type (gdbarch, "complex*16", = init_complex_type ("complex*16", builtin_f_type->builtin_real_s8);
builtin_f_type->builtin_real_s8);
builtin_f_type->builtin_complex_s32 builtin_f_type->builtin_complex_s32
= arch_complex_type (gdbarch, "complex*32", = init_complex_type ("complex*32", builtin_f_type->builtin_real_s16);
builtin_f_type->builtin_real_s16);
return builtin_f_type; return builtin_f_type;
} }

View file

@ -3025,19 +3025,40 @@ init_decfloat_type (struct objfile *objfile, int bit, const char *name)
return t; return t;
} }
/* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE. /* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type
NAME is the type name. TARGET_TYPE is the component float type. */ name. TARGET_TYPE is the component type. */
struct type * struct type *
init_complex_type (struct objfile *objfile, init_complex_type (const char *name, struct type *target_type)
const char *name, struct type *target_type)
{ {
struct type *t; struct type *t;
t = init_type (objfile, TYPE_CODE_COMPLEX, gdb_assert (TYPE_CODE (target_type) == TYPE_CODE_INT
2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name); || TYPE_CODE (target_type) == TYPE_CODE_FLT);
TYPE_TARGET_TYPE (t) = target_type;
return t; 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. /* 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; 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. /* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
BIT is the pointer type size in bits. NAME is the type name. 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 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), = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
"long double", gdbarch_long_double_format (gdbarch)); "long double", gdbarch_long_double_format (gdbarch));
builtin_type->builtin_complex builtin_type->builtin_complex
= arch_complex_type (gdbarch, "complex", = init_complex_type ("complex", builtin_type->builtin_float);
builtin_type->builtin_float);
builtin_type->builtin_double_complex builtin_type->builtin_double_complex
= arch_complex_type (gdbarch, "double complex", = init_complex_type ("double complex", builtin_type->builtin_double);
builtin_type->builtin_double);
builtin_type->builtin_string builtin_type->builtin_string
= arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string"); = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
builtin_type->builtin_bool builtin_type->builtin_bool

View file

@ -803,6 +803,10 @@ struct main_type
struct range_bounds *bounds; struct range_bounds *bounds;
/* If this is a scalar type, then this is its corresponding
complex type. */
struct type *complex_type;
} flds_bnds; } flds_bnds;
/* * Slot to point to additional language-specific fields of this /* * Slot to point to additional language-specific fields of this
@ -1841,8 +1845,7 @@ extern struct type *init_float_type (struct objfile *, int, const char *,
const struct floatformat **, const struct floatformat **,
enum bfd_endian = BFD_ENDIAN_UNKNOWN); enum bfd_endian = BFD_ENDIAN_UNKNOWN);
extern struct type *init_decfloat_type (struct objfile *, int, const char *); extern struct type *init_decfloat_type (struct objfile *, int, const char *);
extern struct type *init_complex_type (struct objfile *, const char *, extern struct type *init_complex_type (const char *, struct type *);
struct type *);
extern struct type *init_pointer_type (struct objfile *, int, const char *, extern struct type *init_pointer_type (struct objfile *, int, const char *,
struct type *); struct type *);
@ -1858,8 +1861,6 @@ extern struct type *arch_boolean_type (struct gdbarch *, int, int,
extern struct type *arch_float_type (struct gdbarch *, int, const char *, extern struct type *arch_float_type (struct gdbarch *, int, const char *,
const struct floatformat **); const struct floatformat **);
extern struct type *arch_decfloat_type (struct gdbarch *, int, const char *); extern struct type *arch_decfloat_type (struct gdbarch *, int, const char *);
extern struct type *arch_complex_type (struct gdbarch *, const char *,
struct type *);
extern struct type *arch_pointer_type (struct gdbarch *, int, const char *, extern struct type *arch_pointer_type (struct gdbarch *, int, const char *,
struct type *); struct type *);

View file

@ -665,11 +665,9 @@ build_go_types (struct gdbarch *gdbarch)
builtin_go_type->builtin_float64 builtin_go_type->builtin_float64
= arch_float_type (gdbarch, 64, "float64", floatformats_ieee_double); = arch_float_type (gdbarch, 64, "float64", floatformats_ieee_double);
builtin_go_type->builtin_complex64 builtin_go_type->builtin_complex64
= arch_complex_type (gdbarch, "complex64", = init_complex_type ("complex64", builtin_go_type->builtin_float32);
builtin_go_type->builtin_float32);
builtin_go_type->builtin_complex128 builtin_go_type->builtin_complex128
= arch_complex_type (gdbarch, "complex128", = init_complex_type ("complex128", builtin_go_type->builtin_float64);
builtin_go_type->builtin_float64);
return builtin_go_type; return builtin_go_type;
} }

View file

@ -1429,13 +1429,11 @@ basic_type (int bt, struct objfile *objfile)
break; break;
case btComplex: case btComplex:
tp = init_complex_type (objfile, "complex", tp = init_complex_type ("complex", basic_type (btFloat, objfile));
basic_type (btFloat, objfile));
break; break;
case btDComplex: case btDComplex:
tp = init_complex_type (objfile, "double complex", tp = init_complex_type ("double complex", basic_type (btFloat, objfile));
basic_type (btFloat, objfile));
break; break;
case btFixedDec: case btFixedDec:

View file

@ -2186,12 +2186,12 @@ rs6000_builtin_type (int typenum, struct objfile *objfile)
break; break;
case 25: case 25:
/* Complex type consisting of two IEEE single precision values. */ /* Complex type consisting of two IEEE single precision values. */
rettype = init_complex_type (objfile, "complex", rettype = init_complex_type ("complex",
rs6000_builtin_type (12, objfile)); rs6000_builtin_type (12, objfile));
break; break;
case 26: case 26:
/* Complex type consisting of two IEEE double precision values. */ /* Complex type consisting of two IEEE double precision values. */
rettype = init_complex_type (objfile, "double complex", rettype = init_complex_type ("double complex",
rs6000_builtin_type (13, objfile)); rs6000_builtin_type (13, objfile));
break; break;
case 27: case 27:
@ -3805,7 +3805,7 @@ read_sun_floating_type (const char **pp, int typenums[2],
|| details == NF_COMPLEX32) || details == NF_COMPLEX32)
{ {
rettype = dbx_init_float_type (objfile, nbits / 2); rettype = dbx_init_float_type (objfile, nbits / 2);
return init_complex_type (objfile, NULL, rettype); return init_complex_type (NULL, rettype);
} }
return dbx_init_float_type (objfile, nbits); return dbx_init_float_type (objfile, nbits);
@ -4099,7 +4099,7 @@ read_range_type (const char **pp, int typenums[2], int type_size,
= dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT); = dbx_init_float_type (objfile, n2 * TARGET_CHAR_BIT);
if (self_subrange) if (self_subrange)
return init_complex_type (objfile, NULL, float_type); return init_complex_type (NULL, float_type);
else else
return float_type; return float_type;
} }