From patchwork Wed Sep 5 14:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 966425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-485222-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="aG0SMET5"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZBxUZQvA"; dkim-atps=neutral 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 4256Kl6BkDz9sCn for ; Thu, 6 Sep 2018 00:59:07 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; q=dns; s=default; b=dYE SlcO3750SYIREOcQPVZ63TY1iTQeye/hEyorda76nRQ2XnV13NnZrhXScWPusyc7 qE7GozBO8ib5cfNL2CmjZXNj+vlkephFJ/oQwQZ8Q+7zt3HYIe1l8kh9N9mAYxVr 5kvIXZi9rbbCMCc5HCVNTV00V0NsO4zjEkM8yXOs= 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:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=default; bh=dU80BdnjZ 1vny4TM7Ue9avLzhwY=; b=aG0SMET5vfzC6JcLe2M0wx/uV+uNxYLvXN5gf0YSh mS8sxPzoumR1q3MunuVThUI4GgD4n6XDxpvJyyc9pMmYzalB2Pquf7P/wDZcG3LL pQBbPg489rINDWoESFZsGffn0azqvix0NpXLMBzyUQC5iFjGK2v33a3rldDV2L29 a4= Received: (qmail 68320 invoked by alias); 5 Sep 2018 14:57:53 -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 68054 invoked by uid 89); 5 Sep 2018 14:57:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*Ad:U*aldot, management, HContent-Transfer-Encoding:8bit X-HELO: mail-wr1-f41.google.com Received: from mail-wr1-f41.google.com (HELO mail-wr1-f41.google.com) (209.85.221.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Sep 2018 14:57:49 +0000 Received: by mail-wr1-f41.google.com with SMTP id g33-v6so8045398wrd.1; Wed, 05 Sep 2018 07:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bn/U5UKqtMCOYhKCRgwt8j7UhDdYFp+4u9mW13k1kLE=; b=ZBxUZQvAeDZMRKE5/PO5whbNQuXVac/cmQugmBwQfFAsv1imhyHrEun50QqxvlDdc/ a+zM0t83jeqUrpjgD7NMh6fsG2hLNuqwVmaT1Z+P5rdjQTfJ2YliVNzvVNfQ9jyv7Jvx xvlLHMccLEAL/OgX7eLB1CFq1YoASCrKuCVlB5XRooiz4AYk7ZDPDACgaZLdEZuUv2vY HPAFwCTL250pJxOdcUJCeMuPqSEleIjRiBuG8p36ciOeKUir+bNnsTmQZn0V4GvMWrFw 9pUJbmBBMWexaHNXo4qqjWoxD8IWPKUs4pLCILSoPeqE8CoIB9j8k6zdrd6n3n9qy8ur p+ZA== Received: from s46.loc (91-119-125-11.dsl.dynamic.surfer.at. [91.119.125.11]) by smtp.gmail.com with ESMTPSA id 124-v6sm4021089wmk.20.2018.09.05.07.57.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Sep 2018 07:57:47 -0700 (PDT) Received: from cow by s46.loc with local (Exim 4.91) (envelope-from ) id 1fxZFY-00007c-EJ; Wed, 05 Sep 2018 14:57:44 +0000 From: Bernhard Reutner-Fischer To: fortran@gcc.gnu.org Cc: Bernhard Reutner-Fischer , gcc-patches@gcc.gnu.org Subject: [PATCH,FORTRAN 08/29] Add uop/name helpers Date: Wed, 5 Sep 2018 14:57:11 +0000 Message-Id: <20180905145732.404-9-rep.dot.nop@gmail.com> In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes From: Bernhard Reutner-Fischer Introduce a helper to construct a user operator from a name and the reverse operation, i.e. a helper to construct a name from a user operator. gcc/fortran/ChangeLog: 2017-10-29 Bernhard Reutner-Fischer * gfortran.h (gfc_get_uop_from_name): (gfc_get_name_from_uop): Declare. * symbol.c (gfc_get_uop_from_name): (gfc_get_name_from_uop): Define. * module.c (load_omp_udrs): Use them. --- gcc/fortran/gfortran.h | 2 ++ gcc/fortran/module.c | 21 +++------------------ gcc/fortran/symbol.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index ff42b39b453..6c32b8ac71f 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3019,6 +3019,8 @@ void gfc_delete_symtree (gfc_symtree **, const char *); gfc_symtree *gfc_get_unique_symtree (gfc_namespace *); gfc_user_op *gfc_get_uop (const char *); gfc_user_op *gfc_find_uop (const char *, gfc_namespace *); +const char *gfc_get_uop_from_name (const char*); +const char *gfc_get_name_from_uop (const char*); void gfc_free_symbol (gfc_symbol *); void gfc_release_symbol (gfc_symbol *); gfc_symbol *gfc_new_symbol (const char *, gfc_namespace *); diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 8628f3aeda9..b3f68b8803f 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -4785,7 +4785,7 @@ load_omp_udrs (void) while (peek_atom () != ATOM_RPAREN) { const char *name = NULL, *newname; - char *altname; + const char *altname = NULL; gfc_typespec ts; gfc_symtree *st; gfc_omp_reduction_op rop = OMP_REDUCTION_USER; @@ -4812,15 +4812,8 @@ load_omp_udrs (void) else if (strcmp (p, ".neqv.") == 0) rop = OMP_REDUCTION_NEQV; } - altname = NULL; if (rop == OMP_REDUCTION_USER && name[0] == '.') - { - size_t len = strlen (name + 1); - altname = XALLOCAVEC (char, len); - gcc_assert (name[len] == '.'); - memcpy (altname, name + 1, len - 1); - altname[len - 1] = '\0'; - } + altname = gfc_get_name_from_uop (name); newname = name; if (rop == OMP_REDUCTION_USER) newname = find_use_name (altname ? altname : name, !!altname); @@ -4832,15 +4825,7 @@ load_omp_udrs (void) continue; } if (altname && newname != altname) - { - size_t len = strlen (newname); - altname = XALLOCAVEC (char, len + 3); - altname[0] = '.'; - memcpy (altname + 1, newname, len); - altname[len + 1] = '.'; - altname[len + 2] = '\0'; - name = gfc_get_string ("%s", altname); - } + name = altname = gfc_get_uop_from_name (newname); st = gfc_find_symtree (gfc_current_ns->omp_udr_root, name); gfc_omp_udr *udr = gfc_omp_udr_find (st, &ts); if (udr) diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index 0a4f7c1711b..a8f841185f1 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -3026,6 +3026,27 @@ gfc_find_uop (const char *name, gfc_namespace *ns) return (st == NULL) ? NULL : st->n.uop; } +/* Given a name return a string usable as user operator name. */ +const char * +gfc_get_uop_from_name (const char* name) { + gcc_assert (name[0] != '.'); + return gfc_get_string (".%s.", name); +} + +/* Given a user operator name return a string usable as name. */ +const char * +gfc_get_name_from_uop (const char* name) { + gcc_assert (name[0] == '.'); + const size_t len = strlen (name) - 1; + gcc_assert (len > 1); + gcc_assert (name[len] == '.'); + char *buffer = XNEWVEC (char, len); + memcpy (buffer, name + 1, len - 1); + buffer[len - 1] = '\0'; + const char *ret = gfc_get_string ("%s", buffer); + XDELETEVEC (buffer); + return ret; +} /* Update a symbol's common_block field, and take care of the associated memory management. */