From 4c99290df04ba757b74a21ac5a6d16fe300e49ed Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 1 Apr 2020 14:09:52 -0600 Subject: Add accessors for members of complex numbers This introduces two new functions that make it simpler to access the components of a complex number. gdb/ChangeLog 2020-04-01 Tom Tromey * valprint.c (generic_value_print_complex): Use accessors. * value.h (value_real_part, value_imaginary_part): Declare. * valops.c (value_real_part, value_imaginary_part): New functions. * value.c (creal_internal_fn, cimag_internal_fn): Use accessors. --- gdb/valops.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'gdb/valops.c') diff --git a/gdb/valops.c b/gdb/valops.c index d484746..83fd258 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3877,6 +3877,31 @@ value_literal_complex (struct value *arg1, return val; } +/* See value.h. */ + +struct value * +value_real_part (struct value *value) +{ + struct type *type = check_typedef (value_type (value)); + struct type *ttype = TYPE_TARGET_TYPE (type); + + gdb_assert (TYPE_CODE (type) == TYPE_CODE_COMPLEX); + return value_from_component (value, ttype, 0); +} + +/* See value.h. */ + +struct value * +value_imaginary_part (struct value *value) +{ + struct type *type = check_typedef (value_type (value)); + struct type *ttype = TYPE_TARGET_TYPE (type); + + gdb_assert (TYPE_CODE (type) == TYPE_CODE_COMPLEX); + return value_from_component (value, ttype, + TYPE_LENGTH (check_typedef (ttype))); +} + /* Cast a value into the appropriate complex data type. */ static struct value * -- cgit v1.1