From patchwork Mon May 29 08:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 100143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1361538vqr; Mon, 29 May 2023 01:32:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71nXGmCTrvvQhdNtg36zJe09fZNK+B6etylOfHQgIWsh93JCsajAnBedUajdggl+OSSaig X-Received: by 2002:a17:907:7b9b:b0:94f:2916:7d7 with SMTP id ne27-20020a1709077b9b00b0094f291607d7mr6430505ejc.19.1685349178830; Mon, 29 May 2023 01:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685349178; cv=none; d=google.com; s=arc-20160816; b=br8ktAT1Y+Y+xwYnsnIYhfyUxHJBoadfqDbE89EkwNcBQD62/dPybWL4xfdoWcPl9u h+lsXT+BrjkmgXPsi/IVJKP8u710IO7MC7VxSnQo8nbuFTM8EmsJ2ndcV7M54xI9gDAV QG5/wWN1x9fFMJy9JBIxrXobFDR6JYqG11WJKIczd0VzAC/EhjF+rBGWYisdqgBK/WxA HBYcvYV4L3JIusIG+buvHvoocHdY1L1PLrhBrmMPAO0+W9i8OOoKssRU5PplpcLTh3sF +2qlVB1MuTBOXQ+Mplt/RwjFuWcwbR8tK5EWrElhoZHtY2Oy/9sDr8PVt8Xa84KzbChe jwnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=jMFrB2tA0Gn4i9PtLBidjls+UNnxmqkwn3H7FLEVtcw=; b=N/ZDiCCBVn/WKfaf8uXHcqItrTlUzfASWuD337YIs+MrPP1TmKlNwk+bcL2gKGsXVq qQMzB5p8Osa5JDlEklw4BlOo4cPE49Cv9eNsnOIe6c48UU8c+gaCWPg89J5O6Xu0St7w Pr5bf5QSuMfLz5Vj2DX9Ve0x762MKNdnEyf4RG9vnDBOnzzLs9yKPobU2fW7JrjTXZoN p2//n6T0KCZe9QEPt6IFJGV2tdrJHNx49GquyyY+4wM3xDgc+XuFlEteGjD/lx8Uh1Ss pGEEv97qukpz8XAXWrJXYtdfWn9qFWnyx9StaIYkt/JPPnNpj6iECNk7OVuCVlxLlbHi tYNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=amRBtIvB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o13-20020a170906358d00b00973aaa0277bsi6344756ejb.766.2023.05.29.01.32.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 01:32:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=amRBtIvB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F28FB3857016 for ; Mon, 29 May 2023 08:31:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F28FB3857016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685349074; bh=jMFrB2tA0Gn4i9PtLBidjls+UNnxmqkwn3H7FLEVtcw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=amRBtIvB+hKXnPYlSiNH9soqN5Ue1pctzcXYWHd6tRFmiANyErsgOJ6kzDTMV8Kfn DkPZS/jPlrTfEe76SPL1oaVT4TFLhSVnku8/z1pIHL/2fVMC2vbKxfmXbeQSQbf1P3 4LfkzqjKUdzKhTs7XWTv5Bg6ztTYi7Xfl7wCVUhI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 5F0F73858410 for ; Mon, 29 May 2023 08:28:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F0F73858410 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-30ae69ef78aso738154f8f.1 for ; Mon, 29 May 2023 01:28:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685348938; x=1687940938; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jMFrB2tA0Gn4i9PtLBidjls+UNnxmqkwn3H7FLEVtcw=; b=QYA+5AH2igr1fMPUjsqB7PuXGnGSu1xEUq9ABM2QENaHjzF3X7MymySJyAGLnKYOhz bOpSLkxSYk6tWaUi5t7lOUdV5V2OS0h0Qm8xLpdQQU/efEJCNp7WUDk8x/m+W6Ybnwj8 UZCujSUOUKpCoYUt4OF/lcsXgwXgKJt45YMnr7P3iMfZBDLTBydBEwgzLv4YRlcgqDI+ CxixBNVY4Me4u6viWUAlIofK4mVjTa5nja+UuPBNqlwFuWyn2acsimlbw0L9GcH3CATa c4oWobKGqGpSQtlHUiVsynsuGPl5IayhSUUm31xFzqSKIE721uKIZDqyKauGRepkFQKY XxVQ== X-Gm-Message-State: AC+VfDyJwnjpeN3UvscOtJwgSEk4df9zsD0ungwM7bPeeFF1G6FRB9r9 slo6TbSpP59sVWP+npWOYNww2N/RdDuHvU3c3hituA== X-Received: by 2002:a5d:6a07:0:b0:30a:8eae:3cc1 with SMTP id m7-20020a5d6a07000000b0030a8eae3cc1mr5842708wru.16.1685348938097; Mon, 29 May 2023 01:28:58 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id x11-20020a1c7c0b000000b003f50876905dsm13436973wmc.6.2023.05.29.01.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 01:28:57 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: Spurious error on string interpolation Date: Mon, 29 May 2023 10:28:56 +0200 Message-Id: <20230529082856.2409220-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767216700323817410?= X-GMAIL-MSGID: =?utf-8?q?1767216700323817410?= From: Javier Miranda The frontend reports spurious errors on operators found in interpolated string literals. gcc/ada/ * scans.ads (Inside_Interpolated_String_Expression): New variable. * par-ch2.adb (P_Interpolated_String_Literal): Set/clear new variable when parsing interpolated string expressions. * scng.adb (Set_String): Skip processing operator symbols when we arescanning an interpolated string literal. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/par-ch2.adb | 17 +++++++++++++---- gcc/ada/scans.ads | 3 +++ gcc/ada/scng.adb | 10 +++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gcc/ada/par-ch2.adb b/gcc/ada/par-ch2.adb index b6814bdec17..af92f5ac353 100644 --- a/gcc/ada/par-ch2.adb +++ b/gcc/ada/par-ch2.adb @@ -225,6 +225,7 @@ package body Ch2 is function P_Interpolated_String_Literal return Node_Id is Elements_List : constant List_Id := New_List; NL_Node : Node_Id; + Saved_State : constant Boolean := Inside_Interpolated_String_Literal; String_Node : Node_Id; begin @@ -245,9 +246,17 @@ package body Ch2 is -- Interpolated expression if Token = Tok_Left_Curly_Bracket then - Scan; -- past '{' - Append_To (Elements_List, P_Expression); - T_Right_Curly_Bracket; + declare + Saved_In_Expr : constant Boolean := + Inside_Interpolated_String_Expression; + + begin + Scan; -- past '{' + Inside_Interpolated_String_Expression := True; + Append_To (Elements_List, P_Expression); + Inside_Interpolated_String_Expression := Saved_In_Expr; + T_Right_Curly_Bracket; + end; else if Prev_Token = Tok_String_Literal then NL_Node := New_Node (N_String_Literal, Token_Ptr); @@ -266,7 +275,7 @@ package body Ch2 is end loop; end if; - Inside_Interpolated_String_Literal := False; + Inside_Interpolated_String_Literal := Saved_State; Set_Expressions (String_Node, Elements_List); return String_Node; diff --git a/gcc/ada/scans.ads b/gcc/ada/scans.ads index 19e13b6c703..00381bb4a55 100644 --- a/gcc/ada/scans.ads +++ b/gcc/ada/scans.ads @@ -482,6 +482,9 @@ package Scans is -- or aspect. Used to allow/require nonstandard style rules for =>+ with -- -gnatyt. + Inside_Interpolated_String_Expression : Boolean := False; + -- True while parsing an interpolated string expression + Inside_Interpolated_String_Literal : Boolean := False; -- True while parsing an interpolated string literal diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb index abf9c68cd3d..c2707df5cab 100644 --- a/gcc/ada/scng.adb +++ b/gcc/ada/scng.adb @@ -951,12 +951,20 @@ package body Scng is C3 : Character; begin + -- Skip processing operator symbols if we are scanning an + -- interpolated string literal. + + if Inside_Interpolated_String_Literal + and then not Inside_Interpolated_String_Expression + then + null; + -- Token_Name is currently set to Error_Name. The following -- section of code resets Token_Name to the proper Name_Op_xx -- value if the string is a valid operator symbol, otherwise it is -- left set to Error_Name. - if Slen = 1 then + elsif Slen = 1 then C1 := Source (Token_Ptr + 1); case C1 is