From patchwork Wed Sep 5 14:57:07 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: 966428 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-485225-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="j0yh9BZV"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lxWMtVdQ"; 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 4256Lh0X4wz9sCw for ; Thu, 6 Sep 2018 00:59:55 +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=TaN YXSxJNk86gP5bCgL12q2GuPROZJCsXBkkqkjuInPoLIGoGSOTKCmVJQMLyhEFd6p sHP1Co3LdFbPxP5C9cvNZ+Sl1d956KxOeA8Bj24JVWp9HRIIS6QXRwIsP21CAaXv 3E5RPdp4/rDuB+fUFBRy18fuQ8stMwzxOZd6//Xw= 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=6iD7rf1Xq JzPJ/w3NYHqQwxxrxk=; b=j0yh9BZVqFkHQ6Ky+LnGIwUNe9St59uLxtMzAUY06 g7Tf9BuCFRWwB92qF0dXRZwso1VS8WzbNpS/50luI4ahMdDkaqhs/X/JX4eG/A+5 1cDNA+lq6Qmk9EFoTSjMvwdOoVKgEncMQscPf8LBEHQPwMb5rQkFpb0njG3IOc9n o0= Received: (qmail 68673 invoked by alias); 5 Sep 2018 14:57:55 -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 68230 invoked by uid 89); 5 Sep 2018 14:57:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.6 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=obtained, 66513, H*Ad:U*aldot X-HELO: mail-wr1-f42.google.com Received: from mail-wr1-f42.google.com (HELO mail-wr1-f42.google.com) (209.85.221.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Sep 2018 14:57:49 +0000 Received: by mail-wr1-f42.google.com with SMTP id n2-v6so8024516wrw.7; 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=9ZLxbku5i1nUe+8DkLO3akxAmqT4+VoBkE1tLkcos7w=; b=lxWMtVdQTBUlVqcs9+i/SIyhbIDjFC95K55ZEMoz+zd9Oml6qjLEDMbIu9ml8rwxCg A0PdCZG4KfkjSEdNbrarwG+gYNaodUK0or1v2xOfCr49A67YQL/1+EQ3yNJZuWddSSYC xJSRsrwOGOO7DMGzM6o4kO4uxcGQYssJuZHrWKLqDlw3S25px9EnHpfMWekqYnLw4IaV SXy8PlovMl4ZGnlK5fwaeK9XNXXOTT83iYpM/l1mXimnRXuP4tSknDlaLWBQLeOSuLlb dTafr2vkTHX83rIKWwRP7Xi4TAJvRGSZA4cASs/Yu+EJGZW9+jPX+rcjJz6KbhGSWPZz nstQ== Received: from s46.loc (91-119-125-11.dsl.dynamic.surfer.at. [91.119.125.11]) by smtp.gmail.com with ESMTPSA id k63-v6sm2789404wmd.46.2018.09.05.07.57.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Sep 2018 07:57:45 -0700 (PDT) Received: from cow by s46.loc with local (Exim 4.91) (envelope-from ) id 1fxZFX-00007N-Qd; Wed, 05 Sep 2018 14:57:43 +0000 From: Bernhard Reutner-Fischer To: fortran@gcc.gnu.org Cc: Bernhard Reutner-Fischer , gcc-patches@gcc.gnu.org Subject: [PATCH,FORTRAN 04/29] Use stringpool for gfc_match_generic_spec Date: Wed, 5 Sep 2018 14:57:07 +0000 Message-Id: <20180905145732.404-5-rep.dot.nop@gmail.com> In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes From: Bernhard Reutner-Fischer Ideally we would populate mstrings structs with strings obtained through the stringpool. Doing so by means of minit wouldn't work out too well though, see comment in gfortran.h. We could replace the initialized strings in gfc_init_1 but that's for a later patch. gcc/fortran/ChangeLog: 2017-10-23 Bernhard Reutner-Fischer * match.h (gfc_match_generic_spec): Pass argument name by reference. Adjust all callers. * decl.c (access_attr_decl): Adjust. (gfc_match_generic): Adjust. * interface.c (gfc_match_generic_spec, gfc_match_interface, gfc_match_end_interface): Adjust. * module.c (gfc_match_use): Adjust. --- gcc/fortran/decl.c | 11 +++++------ gcc/fortran/gfortran.h | 5 +++++ gcc/fortran/interface.c | 20 +++++++++----------- gcc/fortran/match.h | 3 ++- gcc/fortran/module.c | 16 +++++++++------- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index f0ff5138ca1..2f8d2aca695 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -8582,7 +8582,7 @@ gfc_match_target (void) static match access_attr_decl (gfc_statement st) { - char name[GFC_MAX_SYMBOL_LEN + 1]; + const char *name = NULL; interface_type type; gfc_user_op *uop; gfc_symbol *sym, *dt_sym; @@ -10768,7 +10768,7 @@ syntax: match gfc_match_generic (void) { - char name[GFC_MAX_SYMBOL_LEN + 1]; + const char *name = NULL; char bind_name[GFC_MAX_SYMBOL_LEN + 16]; /* Allow space for OPERATOR(...). */ gfc_symbol* block; gfc_typebound_proc tbattr; /* Used for match_binding_attributes. */ @@ -10931,9 +10931,8 @@ gfc_match_generic (void) { gfc_symtree* target_st; gfc_tbp_generic* target; - const char *name2 = NULL; - m = gfc_match_name (&name2); + m = gfc_match_name (&name); if (m == MATCH_ERROR) goto error; if (m == MATCH_NO) @@ -10942,14 +10941,14 @@ gfc_match_generic (void) goto error; } - target_st = gfc_get_tbp_symtree (&ns->tb_sym_root, name2); + target_st = gfc_get_tbp_symtree (&ns->tb_sym_root, name); /* See if this is a duplicate specification. */ for (target = tb->u.generic; target; target = target->next) if (target_st == target->specific_st) { gfc_error ("%qs already defined as specific binding for the" - " generic %qs at %C", name2, bind_name); + " generic %qs at %C", name, bind_name); goto error; } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 04b0024a992..774a6de6168 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -95,6 +95,11 @@ not after. /* Macro to initialize an mstring structure. */ #define minit(s, t) { s, NULL, t } +/* Ideally we would want that to be + { IDENTIFIER_POINTER (get_identifier_with_length (s, sizeof(s)-1)), NULL, t } + but stringpool's hash table is not allocated yet and we would have to do + tricks to have a ctor to initialize it. And even that wouldn't work too + well as toplevel would later on wipe ident_hash. */ /* Structure for storing strings to be matched by gfc_match_string. */ typedef struct diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index de58eed23f0..6a5fe928b93 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -136,11 +136,10 @@ dtio_op (char* mode) match gfc_match_generic_spec (interface_type *type, - char *name, + const char *&name, gfc_intrinsic_op *op) { char buffer[GFC_MAX_SYMBOL_LEN + 1]; - const char *name2 = NULL; match m; gfc_intrinsic_op i; @@ -174,7 +173,7 @@ gfc_match_generic_spec (interface_type *type, if (m != MATCH_YES) return MATCH_ERROR; - strcpy (name, oper); + name = oper; *type = INTERFACE_USER_OP; return MATCH_YES; } @@ -184,12 +183,12 @@ gfc_match_generic_spec (interface_type *type, *op = dtio_op (buffer); if (*op == INTRINSIC_FORMATTED) { - strcpy (name, gfc_code2string (dtio_procs, DTIO_RF)); + name = gfc_code2string (dtio_procs, DTIO_RF); *type = INTERFACE_DTIO; } if (*op == INTRINSIC_UNFORMATTED) { - strcpy (name, gfc_code2string (dtio_procs, DTIO_RUF)); + name = gfc_code2string (dtio_procs, DTIO_RUF); *type = INTERFACE_DTIO; } if (*op != INTRINSIC_NONE) @@ -201,21 +200,20 @@ gfc_match_generic_spec (interface_type *type, *op = dtio_op (buffer); if (*op == INTRINSIC_FORMATTED) { - strcpy (name, gfc_code2string (dtio_procs, DTIO_WF)); + name = gfc_code2string (dtio_procs, DTIO_WF); *type = INTERFACE_DTIO; } if (*op == INTRINSIC_UNFORMATTED) { - strcpy (name, gfc_code2string (dtio_procs, DTIO_WUF)); + name = gfc_code2string (dtio_procs, DTIO_WUF); *type = INTERFACE_DTIO; } if (*op != INTRINSIC_NONE) return MATCH_YES; } - if (gfc_match_name (&name2) == MATCH_YES) + if (gfc_match_name (&name) == MATCH_YES) { - strcpy (name, name2); *type = INTERFACE_GENERIC; return MATCH_YES; } @@ -235,7 +233,7 @@ syntax: match gfc_match_interface (void) { - char name[GFC_MAX_SYMBOL_LEN + 1]; + const char *name = NULL; interface_type type; gfc_symbol *sym; gfc_intrinsic_op op; @@ -327,7 +325,7 @@ gfc_match_abstract_interface (void) match gfc_match_end_interface (void) { - char name[GFC_MAX_SYMBOL_LEN + 1]; + const char *name = NULL; interface_type type; gfc_intrinsic_op op; match m; diff --git a/gcc/fortran/match.h b/gcc/fortran/match.h index 62554d9667e..75e0d9204d7 100644 --- a/gcc/fortran/match.h +++ b/gcc/fortran/match.h @@ -296,7 +296,8 @@ match gfc_match_array_constructor (gfc_expr **); /* interface.c. */ match gfc_match_abstract_interface (void); -match gfc_match_generic_spec (interface_type *, char *, gfc_intrinsic_op *); +match gfc_match_generic_spec (interface_type *, const char *&, + gfc_intrinsic_op *); match gfc_match_interface (void); match gfc_match_end_interface (void); diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index f31677b3b5e..1064f3c80cb 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -68,9 +68,9 @@ along with GCC; see the file COPYING3. If not see #include "system.h" #include "coretypes.h" #include "options.h" +#include "stringpool.h" #include "tree.h" #include "gfortran.h" -#include "stringpool.h" #include "arith.h" #include "match.h" #include "parse.h" /* FIXME */ @@ -519,8 +519,8 @@ free_rename (gfc_use_rename *list) match gfc_match_use (void) { - char name[GFC_MAX_SYMBOL_LEN + 1], module_nature[GFC_MAX_SYMBOL_LEN + 1]; - const char *name2 = NULL; + char module_nature[GFC_MAX_SYMBOL_LEN + 1]; + const char *name = NULL; gfc_use_rename *tail = NULL, *new_use; interface_type type, type2; gfc_intrinsic_op op; @@ -584,14 +584,14 @@ gfc_match_use (void) use_list->where = gfc_current_locus; - m = gfc_match_name (&name2); + m = gfc_match_name (&name); if (m != MATCH_YES) { free (use_list); return m; } - use_list->module_name = name2; + use_list->module_name = name; if (gfc_match_eos () == MATCH_YES) goto done; @@ -650,13 +650,14 @@ gfc_match_use (void) else { strcpy (new_use->local_name, name); - m = gfc_match_generic_spec (&type2, new_use->use_name, &op); + m = gfc_match_generic_spec (&type2, name, &op); if (type != type2) goto syntax; if (m == MATCH_NO) goto syntax; if (m == MATCH_ERROR) goto cleanup; + strcpy (new_use->use_name, name); } } else @@ -665,13 +666,14 @@ gfc_match_use (void) goto syntax; strcpy (new_use->local_name, name); - m = gfc_match_generic_spec (&type2, new_use->use_name, &op); + m = gfc_match_generic_spec (&type2, name, &op); if (type != type2) goto syntax; if (m == MATCH_NO) goto syntax; if (m == MATCH_ERROR) goto cleanup; + strcpy (new_use->use_name, name); } if (strcmp (new_use->use_name, use_list->module_name) == 0