aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-04-01 14:09:52 -0600
committerTom Tromey <tromey@adacore.com>2020-04-01 14:09:52 -0600
commit4c99290df04ba757b74a21ac5a6d16fe300e49ed (patch)
treeccb4fc81ef873b8bb729af596360c54817a3e824 /gdb/valops.c
parent5b930b4538f70a9f09280e36164840e48fb1c042 (diff)
downloadgdb-4c99290df04ba757b74a21ac5a6d16fe300e49ed.zip
gdb-4c99290df04ba757b74a21ac5a6d16fe300e49ed.tar.gz
gdb-4c99290df04ba757b74a21ac5a6d16fe300e49ed.tar.bz2
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 <tom@tromey.com> * 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.
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c25
1 files changed, 25 insertions, 0 deletions
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 *