From patchwork Tue Jun 20 10:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1797171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qlk2C3gRqz20XZ for ; Tue, 20 Jun 2023 20:50:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D24D3856961 for ; Tue, 20 Jun 2023 10:50:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id E3E6B3858D1E; Tue, 20 Jun 2023 10:50:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3E6B3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.00,256,1681200000"; d="diff'?scan'208";a="10399804" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 20 Jun 2023 02:50:41 -0800 IronPort-SDR: GcOjihDAzsZtEkV+H10tyHfTjvH66tvOnS0bY75gWLV5j/uPd4cppXo5DDDTJF0n5P39NeDAwZ 5dM8VvnPX1GjFtUk4zLfcVRtEk/OFh9fVXRjKpVM2n3m7WpEW612qLVaXCgJU3u9yX+RZh2z7o E/5bQfj8rnUcj8cWPfMj9wJoIfKSwMktOwFiCV0t3/idERpK2Rk3lcIcnkuWIB4s4wPTJ6lYtK 0KrPRUaTsTwqqN1uJ1rcuqicPRSe4P3e8lyrcKe7IFY5V8U4PahZXS4YWg3nDL95aSa+rIntfv Mvc= Message-ID: <7e2f6b2d-b1e2-8aed-f9ea-11f5a72c5794@codesourcery.com> Date: Tue, 20 Jun 2023 12:50:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US To: gcc-patches , fortran From: Tobias Burnus Subject: [Patch] Fortran's gfc_match_char: %S to match symbol with host_assoc X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When just matching a symbol, one can use 'gfc_match_symbol (&sym, host_assoc)' and has the option to match with and without host association. However, when matching something more complex via 'gfc_match' like "something ( %s ) , " the match uses host_assoc = false. While it can be combined ("something (" + symbol + " ) ,"), this requires keeping track of the previous location and resetting it. It seems to be much simply to add a new flag supporting host_assoc = true, which this patch does (using '%S'). The advantage is also that when looking at the comment or at the "%s" implementation, it is clear that there are two variants, making it less likely to choose the wrong matching. OK for mainline? Tobias PS: I will use it in an upcoming OpenMP to parse 'uses_allocators'. ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran's gfc_match_char: %S to match symbol with host_assoc gfc_match ("... %s ...", ...) matches a gfc_symbol but with host_assoc = 0. This commit adds '%S' as variant which matches with host_assoc = 1 gcc/fortran/ChangeLog: * match.cc (gfc_match_char): Match with '%S' a symbol with host_assoc = 1. diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index e7be7fddc64..a350ebf754e 100644 --- a/gcc/fortran/match.cc +++ b/gcc/fortran/match.cc @@ -1084,7 +1084,8 @@ gfc_match_char (char c, bool gobble_ws) %% Literal percent sign %e Expression, pointer to a pointer is set - %s Symbol, pointer to the symbol is set + %s Symbol, pointer to the symbol is set (host_assoc = 0) + %S Symbol, pointer to the symbol is set (host_assoc = 1) %n Name, character buffer is set to name %t Matches end of statement. %o Matches an intrinsic operator, returned as an INTRINSIC enum. @@ -1151,8 +1152,9 @@ loop: goto loop; case 's': + case 'S': vp = va_arg (argp, void **); - n = gfc_match_symbol ((gfc_symbol **) vp, 0); + n = gfc_match_symbol ((gfc_symbol **) vp, c == 'S'); if (n != MATCH_YES) { m = n;