public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
From: gdb-buildbot@sergiodj.net
To: gdb-testers@sourceware.org
Subject: [binutils-gdb] Add accessors for members of complex numbers
Date: Wed, 15 Apr 2020 05:52:43 -0400	[thread overview]
Message-ID: <4c99290df04ba757b74a21ac5a6d16fe300e49ed@gdb-build> (raw)

*** TEST RESULTS FOR COMMIT 4c99290df04ba757b74a21ac5a6d16fe300e49ed ***

commit 4c99290df04ba757b74a21ac5a6d16fe300e49ed
Author:     Tom Tromey <tom@tromey.com>
AuthorDate: Wed Apr 1 14:09:52 2020 -0600
Commit:     Tom Tromey <tromey@adacore.com>
CommitDate: Wed Apr 1 14:09:52 2020 -0600

    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.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7a883e81c2..d1f408f1a4 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+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)
diff --git a/gdb/valops.c b/gdb/valops.c
index d48474665c..83fd2584b5 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 *
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 108a21b684..80b7514b7e 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -811,16 +811,11 @@ generic_value_print_complex (struct value *val, struct ui_file *stream,
 {
   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);
 }
diff --git a/gdb/value.c b/gdb/value.c
index ceaeb835fa..f722c272d8 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3962,7 +3962,7 @@ creal_internal_fn (struct gdbarch *gdbarch,
   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
@@ -3981,8 +3981,7 @@ cimag_internal_fn (struct gdbarch *gdbarch,
   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
diff --git a/gdb/value.h b/gdb/value.h
index e4fd258aa8..85fe6c297f 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1141,6 +1141,14 @@ extern struct value *value_slice (struct value *, int, int);
 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 **);
 


             reply	other threads:[~2020-04-15  9:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15  9:52 gdb-buildbot [this message]
2020-04-15  9:52 ` Failures on Fedora-i686, branch master gdb-buildbot
2020-04-15 10:03 ` Failures on Fedora-x86_64-cc-with-index, " gdb-buildbot
2020-04-15 10:42 ` Failures on Fedora-x86_64-m32, " gdb-buildbot
2020-04-15 10:51 ` Failures on Fedora-x86_64-m64, " gdb-buildbot
2020-04-15 11:41 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " gdb-buildbot
2020-04-15 11:54 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " gdb-buildbot
2020-04-17 21:16 ` Failures on Fedora-x86_64-native-gdbserver-m32, " gdb-buildbot
2020-04-18 15:51 ` Failures on Fedora-x86_64-native-gdbserver-m64, " gdb-buildbot
2020-04-20 16:07 ` Failures on Ubuntu-Aarch64-m64, " gdb-buildbot
2020-04-20 16:25 ` Failures on Ubuntu-Aarch64-native-extended-gdbserver-m64, " gdb-buildbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4c99290df04ba757b74a21ac5a6d16fe300e49ed@gdb-build \
    --to=gdb-buildbot@sergiodj.net \
    --cc=gdb-testers@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).