From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27159 invoked by alias); 8 Oct 2010 18:39:11 -0000 Received: (qmail 27046 invoked by uid 22791); 8 Oct 2010 18:39:10 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 08 Oct 2010 18:39:05 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o98Id4ER024788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 8 Oct 2010 14:39:04 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o98Id3Jj009219; Fri, 8 Oct 2010 14:39:03 -0400 Received: from [10.15.16.129] (dhcp-10-15-16-129.yyz.redhat.com [10.15.16.129]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o98Id2v9025115; Fri, 8 Oct 2010 14:39:02 -0400 Message-ID: <4CAF6546.4070603@redhat.com> Date: Fri, 08 Oct 2010 18:39:00 -0000 From: sami wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100806 Fedora/3.1.2-1.fc13 Lightning/1.0b2pre Thunderbird/3.1.2 MIME-Version: 1.0 To: Tom Tromey CC: gdb-patches@sourceware.org Subject: Re: [patch 1/2] Fix overload resolution of int* vs void* References: <4C7BCD42.9070308@redhat.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------050804090009050203010106" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00147.txt.bz2 This is a multi-part message in MIME format. --------------050804090009050203010106 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 275 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 --------------050804090009050203010106 Content-Type: text/x-patch; name="is_ancestor_cleanup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="is_ancestor_cleanup.patch" Content-length: 2467 Eliminate 'is_ancestor' redundant code. 2010-10-08 Sami Wagiaalla * 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. */ --------------050804090009050203010106--