From patchwork Sat Mar 2 16:54:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 224514 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 3C1E32C02C4 for ; Sun, 3 Mar 2013 03:55:27 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1362848127; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:From:To:Message-ID:In-Reply-To:References: User-Agent:Subject:Date:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=rCQAhRx6vOZSm5efw0qlMiMViXY=; b=L04tzI37Hr9zzj1 BDsYqq+w+jv1yCtrTip7nOWM/sHOO7rVHM2+2UHdaLLhtDnrnFjv2xNDZRIg2uvr rz09JZgdvx1Of1XRiON1QegUIBKLFR7cNx5xzqFhEbbTPo1xYxsQN9Lssedge0g9 mZNHRaOjdhjnmC5JxpnyFChSFWek= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:X-SFR-UUID:MIME-Version:From:To:Message-ID:In-Reply-To:References:User-Agent:Subject:Date:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=wGPxuhwJifGLoaCc+yD/bXxyne/QBGlLRkCAOUfz8JVVG62vZqilWgax9hD25B NJuOBAVicVOQvUiIiCmPI+I2mtWyZJh+giN/IDgzxho+Kx7I5gH7IfywdLMx3EyG 83V/hEPE8AMiafOk2X+8AbWbP0P3Gcd6HZXBa/MjHYHBQ=; Received: (qmail 11986 invoked by alias); 2 Mar 2013 16:54:19 -0000 Received: (qmail 11953 invoked by uid 22791); 2 Mar 2013 16:54:15 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, RCVD_IN_DNSWL_NONE, RCVD_IN_HOSTKARMA_NO, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp23.services.sfr.fr (HELO smtp23.services.sfr.fr) (93.17.128.20) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 02 Mar 2013 16:54:08 +0000 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2306.sfr.fr (SMTP Server) with ESMTP id A1D2B7000099; Sat, 2 Mar 2013 17:54:07 +0100 (CET) Received: from [192.168.1.58] (95.183.72.86.rev.sfr.net [86.72.183.95]) by msfrf2306.sfr.fr (SMTP Server) with ESMTP id 4575370000A2; Sat, 2 Mar 2013 17:54:07 +0100 (CET) X-SFR-UUID: 20130302165407284.4575370000A2@msfrf2306.sfr.fr MIME-Version: 1.0 From: Mikael Morin To: gfortran , GCC patches Message-ID: <20130302165407.10658.98225@marvin> In-Reply-To: <20130302165401.10658.5226@marvin> References: <20130302165401.10658.5226@marvin> User-Agent: patchspam.py Subject: [Patch, fortran] [1/4] C binding access to C_PTR type: preliminary cleanups Date: Sat, 2 Mar 2013 17:54:07 +0100 (CET) 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 contains some preliminary cleanup. - generate_isocbinding_symbol handles NULL symbol names just fine. Thus, there is no need to pass explicitly the "c_ptr" or "c_funptr" strings. - There is a lot of code that looks like if (cond) { foo (c_ptr); bar (c_ptr); } else { foo (c_funptr); bar (c_funptr); } That code is changed by this patch to: if (cond) ptr_id = c_ptr_id; else ptr_id = c_funptr_id; foo (ptr_id); bar (ptr_id); 2013-03-02 Mikael Morin * symbol.c (gen_special_c_interop_ptr, gen_cptr_param, generate_isocbinding_symbol): Use symbol ID explicitly. Pass a NULL string to generate_isocbinding_symbol. diff --git a/symbol.c b/symbol.c index acfebc5..4e6004f 100644 --- a/symbol.c +++ b/symbol.c @@ -3817,6 +3817,7 @@ gen_special_c_interop_ptr (int ptr_id, const char *ptr_name, gfc_symtree *tmp_symtree; gfc_symbol *tmp_sym; gfc_constructor *c; + iso_c_binding_symbol type_id; tmp_symtree = gfc_find_symtree (gfc_current_ns->sym_root, ptr_name); @@ -3838,25 +3839,19 @@ gen_special_c_interop_ptr (int ptr_id, const char *ptr_name, /* The c_ptr and c_funptr derived types will provide the definition for c_null_ptr and c_null_funptr, respectively. */ if (ptr_id == ISOCBINDING_NULL_PTR) - tmp_sym->ts.u.derived = get_iso_c_binding_dt (ISOCBINDING_PTR); + type_id = ISOCBINDING_PTR; else - tmp_sym->ts.u.derived = get_iso_c_binding_dt (ISOCBINDING_FUNPTR); + type_id = ISOCBINDING_FUNPTR; + tmp_sym->ts.u.derived = get_iso_c_binding_dt (type_id); if (tmp_sym->ts.u.derived == NULL) { /* This can occur if the user forgot to declare c_ptr or - c_funptr and they're trying to use one of the procedures - that has arg(s) of the missing type. In this case, a - regular version of the thing should have been put in the - current ns. */ - - generate_isocbinding_symbol (module_name, ptr_id == ISOCBINDING_NULL_PTR - ? ISOCBINDING_PTR : ISOCBINDING_FUNPTR, - (const char *) (ptr_id == ISOCBINDING_NULL_PTR - ? "c_ptr" - : "c_funptr")); - tmp_sym->ts.u.derived = - get_iso_c_binding_dt (ptr_id == ISOCBINDING_NULL_PTR - ? ISOCBINDING_PTR : ISOCBINDING_FUNPTR); + c_funptr and they're trying to use one of the procedures + that has arg(s) of the missing type. In this case, a + regular version of the thing should have been put in the + current ns. */ + generate_isocbinding_symbol (module_name, type_id, NULL); + tmp_sym->ts.u.derived = get_iso_c_binding_dt (type_id); } /* Module name is some mangled version of iso_c_binding. */ @@ -3929,6 +3924,7 @@ gen_cptr_param (gfc_formal_arglist **head, gfc_formal_arglist *formal_arg = NULL; const char *c_ptr_in; const char *c_ptr_type = NULL; + iso_c_binding_symbol c_ptr_id; if (iso_c_sym_id == ISOCBINDING_F_PROCPOINTER) c_ptr_type = "c_funptr"; @@ -3957,23 +3953,18 @@ gen_cptr_param (gfc_formal_arglist **head, param_sym->attr.value = 1; param_sym->attr.use_assoc = 1; - /* Get the symbol for c_ptr or c_funptr, no matter what it's name is + /* Get the symbol for c_ptr or c_funptr, no matter what it's name is (user renamed). */ if (iso_c_sym_id == ISOCBINDING_F_PROCPOINTER) - c_ptr_sym = get_iso_c_binding_dt (ISOCBINDING_FUNPTR); + c_ptr_id = ISOCBINDING_FUNPTR; else - c_ptr_sym = get_iso_c_binding_dt (ISOCBINDING_PTR); + c_ptr_id = ISOCBINDING_PTR; + c_ptr_sym = get_iso_c_binding_dt (c_ptr_id); if (c_ptr_sym == NULL) { /* This can happen if the user did not define c_ptr but they are - trying to use one of the iso_c_binding functions that need it. */ - if (iso_c_sym_id == ISOCBINDING_F_PROCPOINTER) - generate_isocbinding_symbol (module_name, ISOCBINDING_FUNPTR, - (const char *)c_ptr_type); - else - generate_isocbinding_symbol (module_name, ISOCBINDING_PTR, - (const char *)c_ptr_type); - + trying to use one of the iso_c_binding functions that need it. */ + generate_isocbinding_symbol (module_name, c_ptr_id, NULL); gfc_get_ha_symbol (c_ptr_type, &(c_ptr_sym)); } @@ -4556,31 +4547,25 @@ generate_isocbinding_symbol (const char *mod_name, iso_c_binding_symbol s, } else { - /* Here, we're taking the simple approach. We're defining - c_loc as an external identifier so the compiler will put - what we expect on the stack for the address we want the - C address of. */ + iso_c_binding_symbol c_ptr_id; + + /* Here, we're taking the simple approach. We're defining + c_loc as an external identifier so the compiler will put + what we expect on the stack for the address we want the + C address of. */ tmp_sym->ts.type = BT_DERIVED; - if (s == ISOCBINDING_LOC) - tmp_sym->ts.u.derived = - get_iso_c_binding_dt (ISOCBINDING_PTR); - else - tmp_sym->ts.u.derived = - get_iso_c_binding_dt (ISOCBINDING_FUNPTR); + if (s == ISOCBINDING_LOC) + c_ptr_id = ISOCBINDING_PTR; + else + c_ptr_id = ISOCBINDING_FUNPTR; + tmp_sym->ts.u.derived = get_iso_c_binding_dt (c_ptr_id); if (tmp_sym->ts.u.derived == NULL) { - /* Create the necessary derived type so we can continue - processing the file. */ - generate_isocbinding_symbol - (mod_name, s == ISOCBINDING_FUNLOC - ? ISOCBINDING_FUNPTR : ISOCBINDING_PTR, - (const char *)(s == ISOCBINDING_FUNLOC - ? "c_funptr" : "c_ptr")); - tmp_sym->ts.u.derived = - get_iso_c_binding_dt (s == ISOCBINDING_FUNLOC - ? ISOCBINDING_FUNPTR - : ISOCBINDING_PTR); + /* Create the necessary derived type so we can continue + processing the file. */ + generate_isocbinding_symbol (mod_name, c_ptr_id, NULL); + tmp_sym->ts.u.derived = get_iso_c_binding_dt (c_ptr_id); } /* The function result is itself (no result clause). */