From patchwork Fri May 20 13:58:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Froyd X-Patchwork-Id: 96605 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 5298DB71A2 for ; Fri, 20 May 2011 23:59:09 +1000 (EST) Received: (qmail 31775 invoked by alias); 20 May 2011 13:59:07 -0000 Received: (qmail 31764 invoked by uid 22791); 20 May 2011 13:59:06 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 May 2011 13:58:53 +0000 Received: (qmail 14133 invoked from network); 20 May 2011 13:58:52 -0000 Received: from unknown (HELO codesourcery.com) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 20 May 2011 13:58:52 -0000 Date: Fri, 20 May 2011 09:58:50 -0400 From: Nathan Froyd To: gcc-patches@gcc.gnu.org Subject: [PATCH] remove some TYPE_ARG_TYPES usage in objc/ Message-ID: <20110520135848.GA22416@nightcrawler> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch removes one of the two remaining uses of TYPE_ARG_TYPES in the ObjC/C++ frontends. (The other one should be addressed in a different manner.) Given the constraints of the function_args_iterator interface, I thought rewriting the logic of the loop would make things slightly clearer. Tested on x86_64-unknown-linux-gnu with ObjC/C++. OK to commit? -Nathan gcc/objc/ * objc-act.c (objc_compare_types): Use function_args_iterator instead of TYPE_ARG_TYPES to compare function argument types. diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 7e69b0d..0e15fe5 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -2420,6 +2420,8 @@ objc_compare_types (tree ltyp, tree rtyp, int argno, tree callee) lenient than C or C++ on this. */ if (TREE_CODE (ltyp) == FUNCTION_TYPE && TREE_CODE (rtyp) == FUNCTION_TYPE) { + function_args_iterator liter, riter; + /* Return types must be covariant. */ if (!comptypes (TREE_TYPE (ltyp), TREE_TYPE (rtyp)) && !objc_compare_types (TREE_TYPE (ltyp), TREE_TYPE (rtyp), @@ -2427,16 +2429,31 @@ objc_compare_types (tree ltyp, tree rtyp, int argno, tree callee) return false; /* Argument types must be contravariant. */ - for (ltyp = TYPE_ARG_TYPES (ltyp), rtyp = TYPE_ARG_TYPES (rtyp); - ltyp && rtyp; ltyp = TREE_CHAIN (ltyp), rtyp = TREE_CHAIN (rtyp)) + function_args_iter_init (&liter, ltyp); + function_args_iter_init (&riter, rtyp); + + while (1) { - if (!comptypes (TREE_VALUE (rtyp), TREE_VALUE (ltyp)) - && !objc_compare_types (TREE_VALUE (rtyp), TREE_VALUE (ltyp), - argno, callee)) + ltyp = function_args_iter_cond (&liter); + rtyp = function_args_iter_cond (&riter); + + /* If we've exhaused both lists simulateously, we're done. */ + if (ltyp == NULL_TREE && rtyp == NULL_TREE) + break; + + /* If one list is shorter than the other, they fail to match. */ + if (ltyp == NULL_TREE || rtyp == NULL_TREE) return false; - } - return (ltyp == rtyp); + if (!comptypes (rtyp, ltyp) + && !objc_compare_types (rtyp, ltyp, argno, callee)) + return false; + + function_args_iter_next (&liter); + function_args_iter_next (&riter); + } + + return true; } /* Past this point, we are only interested in ObjC class instances,