From patchwork Sun May 25 02:14:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 352217 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B0106140085 for ; Sun, 25 May 2014 12:15:15 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=r2YSwKHBl+Kua9xNS/KcBvk/Ve1dguDwcMs4+YKEdJS kz/kviXws5UNLlypdxhLgo9zqMwSqVxYeLhfaE3pOFM7Kya8GD+QZcX6w+Sjkf0q 6p753lsvy5QugNPF1+tFZ0N6hkpDLW75EJu0rbcfW32fLO2vXYCypGzG/IdOp4PE = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=EJkaJMl4xklW4EyEcks1w7snDAo=; b=oBLsmk+J0uKTZhZ8W 2evZVbDOdupX3ATXtp+NNNX4qCT43cJYRocYtHxvKAq1quCtoCwr8YlLhjuwA0Sk KwsKzfJQWbo6uNuq6H3F9VJqacbPdiVui1Y0eMycX9l+RHstxnyYXez0OcezgIP8 4RKKjDUzeZNUx4ee8fkhYEWGaQ= Received: (qmail 14292 invoked by alias); 25 May 2014 02:14:57 -0000 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 Received: (qmail 14260 invoked by uid 89); 25 May 2014 02:14:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mta21.charter.net Received: from mta21.charter.net (HELO mta21.charter.net) (216.33.127.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 25 May 2014 02:14:47 +0000 Received: from imp11 ([10.20.200.11]) by mta21.charter.net (InterMail vM.8.01.05.09 201-2260-151-124-20120717) with ESMTP id <20140525021445.HZCS10448.mta21.charter.net@imp11>; Sat, 24 May 2014 22:14:45 -0400 Received: from pavilion.localdomain ([72.194.69.199]) by imp11 with smtp.charter.net id 62Ej1o00J4Hxx8Q052Ek8M; Sat, 24 May 2014 22:14:45 -0400 X-Authority-Analysis: v=2.0 cv=F7QP7ddN c=1 sm=1 a=B1S/AlkX9gmsrZinFLYKFA==:17 a=HlLLTiFvtacA:10 a=-p_ZFzD1-0wA:10 a=yUnIBFQkZM0A:10 a=hOpmn2quAAAA:8 a=mDV3o1hIAAAA:8 a=IG05eHrKxpF553vBL_4A:9 a=wPNLvfGTeEIA:10 a=h8ddDy1WG_sA:10 a=BFHccc_2bOS0ni9cVwIA:9 a=n1qbBRLkaBTIbkWL:21 a=Ez3RYg98j-0E7tte:21 a=8NK0-bqS8e00o-KI5PMA:9 a=B1S/AlkX9gmsrZinFLYKFA==:117 X-Auth-id: anZkZWxpc2xlQGNoYXJ0ZXIubmV0 Message-ID: <5381520C.1060904@charter.net> Date: Sat, 24 May 2014 19:14:36 -0700 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: gfortran CC: gcc patches Subject: [patch, fortran] PR55117 Programs fails to read namelist (contains derived types objects) Hi folks, This patch combines Tobias front-end patch with my libgfortran patch to resolve this PR. To denote extended derived types (classes) we use a '+' rather than '%' in certain parts of the namelist name internally to identify that an extended type is being dealt with. The runtime is modified to look for this '+' and when it is seen, scan ahead for the varname match. For inherited types, a match could be found in two different ways. parent%cousin%child parent%child This would be internally represented as: parent+cousin%child So the '+' sign is used to signal that we have to do a special matching check for both possible cases depending on how the user chose to represent it, usually as the shorter version of the name. Admittedly, I do not have very many examples of code that use this feature yet. Regression tested on x86-64. Test case attached with patch. OK for trunk? Regards, Jerry 2014-05-24 Tobias Burnus PR fortran/55117 * trans-io.c (nml_full_name, transfer_namelist_element): Insert a '+' rather then '%' to differentiate namelist variable names that are based on extended derived types. 2014-05-24 Jerry DeLisle PR libgfortran/55117 * io/list_read.c (extended_look_ahead): New helper function to scan the namelist name and look for matches with the new '+' extended type parent indicator. (str_comp_extended): New helper function to compare the namelist name with the varname namelist. (find_nml_name): Use the new helper functions to match the extended type varnames. Index: gcc/fortran/trans-io.c =================================================================== --- gcc/fortran/trans-io.c (revision 210573) +++ gcc/fortran/trans-io.c (working copy) @@ -1452,10 +1452,10 @@ gfc_trans_wait (gfc_code * code) /* nml_full_name builds up the fully qualified name of a - derived type component. */ + derived type component. '+' is used to denote a type extension. */ static char* -nml_full_name (const char* var_name, const char* cmp_name) +nml_full_name (const char* var_name, const char* cmp_name, bool parent) { int full_name_length; char * full_name; @@ -1463,7 +1463,7 @@ static char* full_name_length = strlen (var_name) + strlen (cmp_name) + 1; full_name = XCNEWVEC (char, full_name_length + 1); strcpy (full_name, var_name); - full_name = strcat (full_name, "%"); + full_name = strcat (full_name, parent ? "+" : "%"); full_name = strcat (full_name, cmp_name); return full_name; } @@ -1634,7 +1634,8 @@ transfer_namelist_element (stmtblock_t * block, co for (cmp = ts->u.derived->components; cmp; cmp = cmp->next) { - char *full_name = nml_full_name (var_name, cmp->name); + char *full_name = nml_full_name (var_name, cmp->name, + ts->u.derived->attr.extension); transfer_namelist_element (block, full_name, NULL, cmp, expr); Index: libgfortran/io/list_read.c =================================================================== --- libgfortran/io/list_read.c (revision 210898) +++ libgfortran/io/list_read.c (working copy) @@ -2557,6 +2557,38 @@ err_ret: return false; } + +static bool +extended_look_ahead (char *p, char *q) +{ + char *r, *s; + + /* Scan ahead to find a '%' in the p string. */ + for(r = p, s = q; *r && *s; s++) + if ((*s == '%' || *s == '+') && strcmp (r + 1, s + 1) == 0) + return true; + return false; +} + + +static bool +strcmp_extended_type (char *p, char *q) +{ + char *r, *s; + + for (r = p, s = q; *r && *s; r++, s++) + { + if (*r != *s) + { + if (*r == '%' && *s == '+' && extended_look_ahead (r, s)) + return true; + break; + } + } + return false; +} + + static namelist_info * find_nml_node (st_parameter_dt *dtp, char * var_name) { @@ -2568,6 +2600,11 @@ find_nml_node (st_parameter_dt *dtp, char * var_na t->touched = 1; return t; } + if (strcmp_extended_type (var_name, t->var_name)) + { + t->touched = 1; + return t; + } t = t->next; } return NULL;