Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Paul Hilfinger <hilfingr@gnat.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA]: Extend some arithmetic operations to range types.
Date: Fri, 26 Mar 2004 10:59:00 -0000	[thread overview]
Message-ID: <20040326105916.3FAA5F2DA7@nile.gnat.com> (raw)


The following patch extends a few operations on struct value*s that 
currently fail when an operand has a range type.  For C/C++ these 
extensions have no effect, since those languages don't make use of 
range types, but it is an issue in Ada.

Paul N. Hilfinger
ACT, Inc.


2004-03-26  Paul N. Hilfinger  <Hilfinger@gnat.com>

	* gdbtypes.c (base_type): New function.
	* gdbtypes.h (base_type): Declare.
	* valarith.c: Update copyright notice.
	(value_add): Handle range types.
	(value_sub): Ditto.
	(value_equal): Ditto.
	(value_less): Ditto.
	(value_neg): Ditto.
	(value_complement): Ditto.
	* value.h (COERCE_ENUM): Extend to ranges of enumerated types.

Index: current-public.55/gdb/gdbtypes.c
--- current-public.55/gdb/gdbtypes.c Fri, 12 Mar 2004 22:56:54 -0800 hilfingr (GdbPub/h/48_gdbtypes.c 1.1.1.5.1.1.1.1.1.1.3.1.1.1.1.1.2.1 644)
+++ submit.47(w)/gdb/gdbtypes.c Sat, 13 Mar 2004 01:57:12 -0800 hilfingr (GdbPub/h/48_gdbtypes.c 1.1.1.5.1.1.1.1.1.1.3.1.1.1.1.1.2.1.1.1 644)
@@ -720,6 +720,22 @@ get_discrete_bounds (struct type *type, 
     }
 }
 
+/* The identity on non-range types.  For range types, the underlying
+   non-range scalar type. */  
+
+struct type*
+base_type (struct type* type)
+{
+  while (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE)
+    {
+      if (type == TYPE_TARGET_TYPE (type) 
+	  || TYPE_TARGET_TYPE (type) == NULL)	
+	return type;
+      type = TYPE_TARGET_TYPE (type);
+    }
+  return type;
+}
+
 /* Create an array type using either a blank type supplied in RESULT_TYPE,
    or creating a new type, inheriting the objfile from RANGE_TYPE.
 
Index: current-public.55/gdb/gdbtypes.h
--- current-public.55/gdb/gdbtypes.h Mon, 09 Feb 2004 01:03:21 -0800 hilfingr (GdbPub/h/49_gdbtypes.h 1.1.1.3.1.1.1.1.1.1.3.1 644)
+++ submit.47(w)/gdb/gdbtypes.h Sat, 06 Mar 2004 02:39:59 -0800 hilfingr (GdbPub/h/49_gdbtypes.h 1.1.1.3.1.1.1.1.1.1.3.1.1.1 644)
@@ -1135,6 +1146,8 @@ extern struct type *lookup_function_type
 
 extern struct type *create_range_type (struct type *, struct type *, int,
 				       int);
+
+extern struct type* base_type (struct type*);
 
 extern struct type *create_array_type (struct type *, struct type *,
 				       struct type *);
Index: current-public.55/gdb/valarith.c
--- current-public.55/gdb/valarith.c Wed, 17 Sep 2003 23:22:28 -0700 hilfingr (GdbPub/l/16_valarith.c 1.1.1.3 644)
+++ submit.47(w)/gdb/valarith.c Fri, 26 Mar 2004 01:48:40 -0800 hilfingr (GdbPub/l/16_valarith.c 1.1.1.3.2.1 644)
@@ -1,7 +1,7 @@
 /* Perform arithmetic and other operations on values, for GDB.
 
    Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
    Foundation, Inc.
 
    This file is part of GDB.
@@ -99,8 +99,8 @@ value_add (struct value *arg1, struct va
   if ((TYPE_CODE (type1) == TYPE_CODE_PTR
        || TYPE_CODE (type2) == TYPE_CODE_PTR)
       &&
-      (TYPE_CODE (type1) == TYPE_CODE_INT
-       || TYPE_CODE (type2) == TYPE_CODE_INT))
+      (TYPE_CODE (base_type (type1)) == TYPE_CODE_INT
+       || TYPE_CODE (base_type (type2)) == TYPE_CODE_INT))
     /* Exactly one argument is a pointer, and one is an integer.  */
     {
       struct value *retval;
@@ -141,7 +141,7 @@ value_sub (struct value *arg1, struct va
 
   if (TYPE_CODE (type1) == TYPE_CODE_PTR)
     {
-      if (TYPE_CODE (type2) == TYPE_CODE_INT)
+      if (TYPE_CODE (base_type (type2)) == TYPE_CODE_INT)
 	{
 	  /* pointer - integer.  */
 	  LONGEST sz = find_size_for_pointer_math (type1);
@@ -1227,8 +1227,8 @@ value_equal (struct value *arg1, struct 
 
   type1 = check_typedef (VALUE_TYPE (arg1));
   type2 = check_typedef (VALUE_TYPE (arg2));
-  code1 = TYPE_CODE (type1);
-  code2 = TYPE_CODE (type2);
+  code1 = TYPE_CODE (base_type (type1));
+  code2 = TYPE_CODE (base_type (type2));
 
   if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL) &&
       (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
@@ -1284,8 +1284,8 @@ value_less (struct value *arg1, struct v
 
   type1 = check_typedef (VALUE_TYPE (arg1));
   type2 = check_typedef (VALUE_TYPE (arg2));
-  code1 = TYPE_CODE (type1);
-  code2 = TYPE_CODE (type2);
+  code1 = TYPE_CODE (base_type (type1));
+  code2 = TYPE_CODE (base_type (type2));
 
   if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_BOOL) &&
       (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_BOOL))
@@ -1323,7 +1323,7 @@ value_neg (struct value *arg1)
   COERCE_REF (arg1);
   COERCE_ENUM (arg1);
 
-  type = check_typedef (VALUE_TYPE (arg1));
+  type = base_type (check_typedef (VALUE_TYPE (arg1)));
 
   if (TYPE_CODE (type) == TYPE_CODE_FLT)
     return value_from_double (result_type, -value_as_double (arg1));
@@ -1353,7 +1353,7 @@ value_complement (struct value *arg1)
   COERCE_REF (arg1);
   COERCE_ENUM (arg1);
 
-  type = check_typedef (VALUE_TYPE (arg1));
+  type = base_type (check_typedef (VALUE_TYPE (arg1)));
 
   typecode = TYPE_CODE (type);
   if ((typecode != TYPE_CODE_INT) && (typecode != TYPE_CODE_BOOL))
Index: current-public.55/gdb/value.h
--- current-public.55/gdb/value.h Thu, 30 Oct 2003 00:47:47 -0800 hilfingr (GdbPub/l/20_value.h 1.9 644)
+++ submit.47(w)/gdb/value.h Fri, 26 Mar 2004 01:48:40 -0800 hilfingr (GdbPub/l/20_value.h 1.9.1.1 644)
@@ -267,7 +267,7 @@ extern int value_fetch_lazy (struct valu
 
 #define COERCE_ENUM(arg) \
   do {									\
-    if (TYPE_CODE (check_typedef (VALUE_TYPE (arg))) == TYPE_CODE_ENUM)	\
+    if (TYPE_CODE (base_type (check_typedef (VALUE_TYPE (arg)))) == TYPE_CODE_ENUM)	\
       arg = value_cast (builtin_type_unsigned_int, arg);		\
   } while (0)
 


             reply	other threads:[~2004-03-26 10:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-26 10:59 Paul Hilfinger [this message]
2004-03-26 18:07 ` Daniel Jacobowitz
2004-03-26 19:03   ` Joel Brobecker
2004-03-26 20:32     ` Daniel Jacobowitz
2004-03-29 11:29   ` Paul Hilfinger
2004-03-31 19:05     ` Daniel Jacobowitz
2004-04-01 12:11       ` Paul Hilfinger

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=20040326105916.3FAA5F2DA7@nile.gnat.com \
    --to=hilfingr@gnat.com \
    --cc=gdb-patches@sources.redhat.com \
    /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