+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.
+
2020-04-01 Tom Tromey <tom@tromey.com>
* stabsread.c (rs6000_builtin_type, read_sun_floating_type)
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 *
{
fprintf_filtered (stream, "%s", decorations->complex_prefix);
- struct type *type = check_typedef (value_type (val));
- struct value *real_part
- = value_from_component (val, TYPE_TARGET_TYPE (type), 0);
+ struct value *real_part = value_real_part (val);
value_print_scalar_formatted (real_part, options, 0, stream);
fprintf_filtered (stream, "%s", decorations->complex_infix);
- struct value *imag_part
- = value_from_component (val, TYPE_TARGET_TYPE (type),
- TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
-
+ struct value *imag_part = value_imaginary_part (val);
value_print_scalar_formatted (imag_part, options, 0, stream);
fprintf_filtered (stream, "%s", decorations->complex_suffix);
}
type *ctype = check_typedef (value_type (cval));
if (TYPE_CODE (ctype) != TYPE_CODE_COMPLEX)
error (_("expected a complex number"));
- return value_from_component (cval, TYPE_TARGET_TYPE (ctype), 0);
+ return value_real_part (cval);
}
/* Implementation of the convenience function $_cimag. Extracts the
type *ctype = check_typedef (value_type (cval));
if (TYPE_CODE (ctype) != TYPE_CODE_COMPLEX)
error (_("expected a complex number"));
- return value_from_component (cval, TYPE_TARGET_TYPE (ctype),
- TYPE_LENGTH (TYPE_TARGET_TYPE (ctype)));
+ return value_imaginary_part (cval);
}
#if GDB_SELF_TEST
extern struct value *value_literal_complex (struct value *, struct value *,
struct type *);
+/* Return the real part of a complex value. */
+
+extern struct value *value_real_part (struct value *value);
+
+/* Return the imaginary part of a complex value. */
+
+extern struct value *value_imaginary_part (struct value *value);
+
extern struct value *find_function_in_inferior (const char *,
struct objfile **);