Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: sami wagiaalla <swagiaal@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch 1/2] Fix overload resolution of int* vs void*
Date: Fri, 08 Oct 2010 18:39:00 -0000	[thread overview]
Message-ID: <4CAF6546.4070603@redhat.com> (raw)
In-Reply-To: <m362yrkgzj.fsf@fleche.redhat.com>

[-- Attachment #1: Type: text/plain, Size: 275 bytes --]

is_ancestor and is_public_ancestor have a lot of redundant code. This 
patch shares the code between that two. This way improvements the the 
function can be shared between the two functions. I don't like the name 
do_is_ancestor but I could not come up with anything better

[-- Attachment #2: is_ancestor_cleanup.patch --]
[-- Type: text/x-patch, Size: 2467 bytes --]

Eliminate 'is_ancestor' redundant code.

2010-10-08  Sami Wagiaalla  <swagiaal@redhat.com>

	* gdbtypes.c (do_is_ancestor): New function.
	(is_ancestor): Use do_is_ancestor.
	(is_public_ancestor): Use do_is_ancestor.

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c35adbb..e2a8a62 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1871,13 +1871,12 @@ class_types_same_p (const struct type *a, const struct type *b)
 }
 
 /* Check whether BASE is an ancestor or base class or DCLASS 
-   Return 1 if so, and 0 if not.
-   Note: callers may want to check for identity of the types before
-   calling this function -- identical types are considered to satisfy
-   the ancestor relationship even if they're identical.  */
+   Return 1 if so, and 0 if not.  If PUBLIC is 1 then only public
+   ancestors ancestors are considered, and the function returns 1 only
+   if BASE is a public ancestor of DCLASS.  */
 
-int
-is_ancestor (struct type *base, struct type *dclass)
+static int
+do_is_ancestor (struct type *base, struct type *dclass, int public)
 {
   int i;
 
@@ -1889,6 +1888,9 @@ is_ancestor (struct type *base, struct type *dclass)
 
   for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
     {
+      if (public && ! BASETYPE_VIA_PUBLIC (dclass, i))
+	continue;
+
       if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
 	return 1;
     }
@@ -1896,29 +1898,25 @@ is_ancestor (struct type *base, struct type *dclass)
   return 0;
 }
 
+/* Check whether BASE is an ancestor or base class or DCLASS
+   Return 1 if so, and 0 if not.
+   Note: callers may want to check for identity of the types before
+   calling this function -- identical types are considered to satisfy
+   the ancestor relationship even if they're identical.  */
+
+int
+is_ancestor (struct type *base, struct type *dclass)
+{
+  return do_is_ancestor (base, dclass, 0);
+}
+
 /* Like is_ancestor, but only returns true when BASE is a public
    ancestor of DCLASS.  */
 
 int
 is_public_ancestor (struct type *base, struct type *dclass)
 {
-  int i;
-
-  CHECK_TYPEDEF (base);
-  CHECK_TYPEDEF (dclass);
-
-  if (class_types_same_p (base, dclass))
-    return 1;
-
-  for (i = 0; i < TYPE_N_BASECLASSES (dclass); ++i)
-    {
-      if (! BASETYPE_VIA_PUBLIC (dclass, i))
-	continue;
-      if (is_public_ancestor (base, TYPE_BASECLASS (dclass, i)))
-	return 1;
-    }
-
-  return 0;
+  return do_is_ancestor (base, dclass, 1);
 }
 
 /* A helper function for is_unique_ancestor.  */

  reply	other threads:[~2010-10-08 18:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-30 15:24 [patch] " sami wagiaalla
2010-08-30 16:13 ` sami wagiaalla
2010-08-30 20:01 ` Tom Tromey
2010-10-08 18:39   ` sami wagiaalla [this message]
2010-10-08 18:54     ` [patch 1/2] " Tom Tromey
2010-10-08 19:35       ` sami wagiaalla
2010-10-08 21:30         ` Tom Tromey
2010-10-08 19:05   ` [patch 2/2] " sami wagiaalla
2010-10-08 20:46     ` Eli Zaretskii
2010-10-08 21:10       ` sami wagiaalla
2010-10-08 22:54         ` Tom Tromey
2010-10-12 20:01           ` sami wagiaalla
2010-10-12 20:41             ` Tom Tromey
2010-10-13 15:16               ` sami wagiaalla
2010-10-13 15:49                 ` Tom Tromey
2010-10-13 18:29                   ` sami wagiaalla
2010-10-15 14:46                   ` sami wagiaalla
2010-10-15 22:48                     ` Tom Tromey

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=4CAF6546.4070603@redhat.com \
    --to=swagiaal@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@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