From patchwork Wed Sep 5 14:57:22 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: 966447 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-485244-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="UX8cG/MX"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Fbero/t6"; 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 4256Td5fDQz9sDT for ; Thu, 6 Sep 2018 01:05:57 +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=nP0 JCGqOzQ79Aau4mM15HH6CjWu1+66QQYLwUO7be1MsZwuTwfm1l+XmY7IOvlKt2hP pkwDJHn57PcDhP8VNJPoK6hJMh1dDtlyhcTrIIknT+nW7WO19HNS4iOWCYjANxfm ZybtEuJvKXM/S9dpBkg2VpjcCkE9diOZmexzBRY4= 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=9pDYCxM0W lBsXo1YBgz4UejOI3o=; b=UX8cG/MX6bC5skKLyiE4LHnv8k+Tbf8iP7YLaoUH6 S2GvT/yvfI4FtPPB+DFKf+njcA+T7NdeqVfnTu1VQW3QKr0A25IdBjSBO9n08trS 3kLwbQ/1Q8BygZsWi1ps4zLPxTAxPcupDG9L4pNJEv6ZQqcptmRnkPi2UlSu26EN fk= Received: (qmail 101797 invoked by alias); 5 Sep 2018 15:02:46 -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 101600 invoked by uid 89); 5 Sep 2018 15:02:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.8 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=mm, uu, UU, MM X-HELO: mail-wr1-f65.google.com Received: from mail-wr1-f65.google.com (HELO mail-wr1-f65.google.com) (209.85.221.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Sep 2018 15:02:43 +0000 Received: by mail-wr1-f65.google.com with SMTP id u12-v6so8026350wrr.4; Wed, 05 Sep 2018 08:02:42 -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=PEFfP6r9wPZS86+dlZR9Zu3fDTmnX8tbtEMn3mQEcKk=; b=Fbero/t65NvHe5VpaLHIYw6OwAFyHaYsgol5b7vJZJ1kj6ZKfkgJSG5fGRhs25y7ij oIaY1yp0wyxm6yxNiyFjSKjzg4K3/YBUFdn6i2UUH/VlWJ0fBhPw/5u9qptBdTAEEFX2 2wBijv2KMdfEHVTPCCfGGXTNuih3vnDxqJQnn2Wcqo8pkiJEb6KR2VI7lq8uzAvK+fbD qFvhjOGHmv7nZkczYDvjHW1VQxOfWcb1AotgyqzNcsmC9R+ZlyTAQkIlLZxSKzsDRjkC Ewi8Hct09xLN8LszCrdDbigF1u8E3xcyo0gPnqA5M1ixAFu+vS97eDikInRCgmUQHcYF 9yNw== Received: from s46.loc (91-119-125-11.dsl.dynamic.surfer.at. [91.119.125.11]) by smtp.gmail.com with ESMTPSA id 139-v6sm4049625wmp.4.2018.09.05.08.02.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Sep 2018 08:02:40 -0700 (PDT) Received: from cow by s46.loc with local (Exim 4.91) (envelope-from ) id 1fxZFa-000089-Bd; Wed, 05 Sep 2018 14:57:46 +0000 From: Bernhard Reutner-Fischer To: fortran@gcc.gnu.org Cc: Bernhard Reutner-Fischer , gcc-patches@gcc.gnu.org Subject: [PATCH, FORTRAN 19/29] Use stringpool and unified uppercase handling for types Date: Wed, 5 Sep 2018 14:57:22 +0000 Message-Id: <20180905145732.404-20-rep.dot.nop@gmail.com> In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes From: Bernhard Reutner-Fischer Use the existing helper function to create type names. The helper function uses the stringpool already. gcc/fortran/ChangeLog: 2017-11-24 Bernhard Reutner-Fischer * decl.c (build_sym): Use stringpool node instead of stack variables. (gfc_match_map): Likewise. (gfc_match_union): Likewise. * trans-decl.c (gfc_trans_use_stmts): Call gfc_dt_upper_string and thus use stringpool node for the type name. --- gcc/fortran/decl.c | 25 ++++++++++--------------- gcc/fortran/trans-decl.c | 8 +++----- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 48ef5637e36..55a59008f66 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1490,7 +1490,7 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred, { symbol_attribute attr; gfc_symbol *sym; - int upper; + const char *upper; gfc_symtree *st; /* Symbols in a submodule are host associated from the parent module or @@ -1520,20 +1520,15 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred, course, this is only necessary if the upper case letter is actually different. */ - upper = TOUPPER(name[0]); - if (upper != name[0]) + upper = gfc_dt_upper_string (name); + if (upper[0] != name[0]) { - char u_name[GFC_MAX_SYMBOL_LEN + 1]; gfc_symtree *st; - - gcc_assert (strlen(name) <= GFC_MAX_SYMBOL_LEN); - strcpy (u_name, name); - u_name[0] = upper; - - st = gfc_find_symtree (gfc_current_ns->sym_root, u_name); + gcc_assert (strlen (upper) <= GFC_MAX_SYMBOL_LEN); + st = gfc_find_symtree (gfc_current_ns->sym_root, upper); /* STRUCTURE types can alias symbol names */ - if (st != 0 && st->n.sym->attr.flavor != FL_STRUCT) + if (st && st->n.sym->attr.flavor != FL_STRUCT) { gfc_error ("Symbol %qs at %C also declared as a type at %L", name, &st->n.sym->declared_at); @@ -9672,7 +9667,7 @@ gfc_match_map (void) { /* Counter used to give unique internal names to map structures. */ static unsigned int gfc_map_id = 0; - char name[GFC_MAX_SYMBOL_LEN + 1]; + const char *name; gfc_symbol *sym; locus old_loc; @@ -9687,7 +9682,7 @@ gfc_match_map (void) /* Map blocks are anonymous so we make up unique names for the symbol table which are invalid Fortran identifiers. */ - snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "MM$%u", gfc_map_id++); + name = gfc_get_string ("MM$%u", gfc_map_id++); if (!get_struct_decl (name, FL_STRUCT, &old_loc, &sym)) return MATCH_ERROR; @@ -9705,7 +9700,7 @@ gfc_match_union (void) { /* Counter used to give unique internal names to union types. */ static unsigned int gfc_union_id = 0; - char name[GFC_MAX_SYMBOL_LEN + 1]; + const char *name; gfc_symbol *sym; locus old_loc; @@ -9720,7 +9715,7 @@ gfc_match_union (void) /* Unions are anonymous so we make up unique names for the symbol table which are invalid Fortran identifiers. */ - snprintf (name, GFC_MAX_SYMBOL_LEN + 1, "UU$%u", gfc_union_id++); + name = gfc_get_string ("UU$%u", gfc_union_id++); if (!get_struct_decl (name, FL_UNION, &old_loc, &sym)) return MATCH_ERROR; diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 6e717633a8f..023350723ff 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -5053,12 +5053,10 @@ gfc_trans_use_stmts (gfc_namespace * ns) /* The following can happen if a derived type is renamed. */ if (!st) { - char *name; - name = xstrdup (rent->local_name + const char *upper; + upper = gfc_dt_upper_string (rent->local_name ? rent->local_name : rent->use_name); - name[0] = (char) TOUPPER ((unsigned char) name[0]); - st = gfc_find_symtree (ns->sym_root, name); - free (name); + st = gfc_find_symtree (ns->sym_root, upper); gcc_assert (st); }