From patchwork Tue May 23 08:08:14 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: 97857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1975281vqo; Tue, 23 May 2023 01:15:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sg90FIjs/exQUlv3JY3YXuOeeJvsUbx6gI1rWW8uYC6mNU8BPhtFAav9RBeW+U+f4aJlr X-Received: by 2002:a17:906:9b84:b0:96a:1f7c:3207 with SMTP id dd4-20020a1709069b8400b0096a1f7c3207mr16543936ejc.19.1684829712777; Tue, 23 May 2023 01:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684829712; cv=none; d=google.com; s=arc-20160816; b=eOeRCPODbEBnFvsT1n6gonWvIKUH1To/u+pDlcDuc8OssnpmpUp3D4kBxpKBrDmLYl whi+2z+F1dp+UwnagZaEM3nS7lYjzWKvDMzUf0Ga/iUQj/Xwf8Hq30CfMhfiatJ/7wb0 ddeLL+82ACdOG426Q4iDfmM1Q6YDUCztZqLVMOpku91bsgrvXr9mw2LgtKNQZS715jbZ 7LxpVTPZXBfOEOpvs7H2upEwmnKMIH5dI73ylZ/Pr+iUZBUkLOmLrjMXfPqziCNGiH13 kYuShI9YY1MujIbNSZCAto+cCznnA4x26jpwce6vY2p8HmDoO/mrbRWuZFepzCuKg8JZ 2Zag== 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=gHBd6WLgQN2XtC0W7J36iR0fGi5e3w0eD80Ilvuluhg=; b=MP7sIh4Qcacls+Gk/DSmPkTU8b8hHAzMTtFouvwIBbr8o0cO+fD6arpxBSRweNxB2r uk0eUa9Ax6dsc+Dbw4TGyu3g/Vl4LmOLr/Tg+7ZtgXGeeh0NpAH+HO8IkK37FxBk6fFR gWcv87AhtcuB9IQeNAHjdIdONXZ3ilyxscF5kt0G7g/YGVSTJmdRCjTMQXBz0wRJVKvC TKZLfiFu5qgIMcXd8Mzsxbz7Sf8yXupidO5Sg6c5dQ/IGGRqzevEHQ1Imyw7UevHD1n8 xS1AFWpfJVBcdwcxWD0firNqmt3rlal2CJ70H7o0YJmct5Xw/TcHRCH1DknN3EOS3o+4 s5aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="S/9Ms7ZJ"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gc10-20020a1709072b0a00b0096b441124f8si191132ejc.669.2023.05.23.01.15.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:15:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="S/9Ms7ZJ"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 9291A389A131 for ; Tue, 23 May 2023 08:11:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9291A389A131 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684829472; bh=gHBd6WLgQN2XtC0W7J36iR0fGi5e3w0eD80Ilvuluhg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=S/9Ms7ZJ1vkUkR9EnC4UNvvV6pCR38yJ0RMRe+gUAGiSX9Kp2sTv9jU3ZxUPr4GEB gbO+YxzWa/bHKTWeOcWyv0f89wR9M0uIb+aEXxdZLeguW2mQkO2zv8NC4+kPKDxC4D g2WonTTd4VVoRCpaSyDiJPtGJPCQRifzcJW/1Ohw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 6941E38323ED for ; Tue, 23 May 2023 08:08:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6941E38323ED Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f608074b50so13317055e9.0 for ; Tue, 23 May 2023 01:08:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684829296; x=1687421296; 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=gHBd6WLgQN2XtC0W7J36iR0fGi5e3w0eD80Ilvuluhg=; b=APbI3wiugiF4PEWF6LgtkgSBe0gIP9BscpJI3/begzeVuJFWWFyJJXnoOZ882FEGTz PbF2daNfFkT0s3sPv709M2LkDiBC7g5j3jQO7LhfobDUen3aD/o7HC9eujszUuCOP6lf SYf62y0iNwPGTtr765BhOe9em5fIzfBrVxraNSDwdnnlHK3qjk7D4KZoZumpmr0hqgn3 AthpAVTnC94dvIusLwz16NfgCtbjdEoWuEaUShbb3zNvy8lOafJDKNKka61XDZN9MiCl DtNJ6d0zeXWS88Kw2fjpFm6fW0+sR+hl1Q3SDZ53EImLNdGG/aOwoePyMZVpSYgUHG/P BYTg== X-Gm-Message-State: AC+VfDxGAZJ2gSXwsNGrklGgyRTOrkZ3TxsWeD5Wx4KT0Ev5T8SggkZ6 F70wPUns5L/wUmZt4nmDK1D7xHJ4CjyrRtHnIA4rMw== X-Received: by 2002:a05:600c:21d1:b0:3f6:42e:579d with SMTP id x17-20020a05600c21d100b003f6042e579dmr3884181wmj.27.1684829296288; Tue, 23 May 2023 01:08:16 -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 s9-20020a7bc389000000b003f60514bdd7sm5160361wmj.4.2023.05.23.01.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 01:08:15 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Fix endings of pretty-printed numeric literals Date: Tue, 23 May 2023 10:08:14 +0200 Message-Id: <20230523080814.1873488-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 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?1766672000651393047?= X-GMAIL-MSGID: =?utf-8?q?1766672000651393047?= From: Piotr Trojanek When looking for the end of an numeric literal we consumed '+' and '-' characters, because they might appear in the exponent part. This was too aggressive when they separated the number from the subsequent operand, like in "123+456". Now we skip past numeric literals by strictly following their grammar and only consume '+' and '-' when they belong to the exponent. gcc/ada/ * errout.adb (Last_Sloc): Rewrite skipping past numeric literals. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/errout.adb | 130 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 113 insertions(+), 17 deletions(-) diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index 5c3e76c5eca..6531410f0d2 100644 --- a/gcc/ada/errout.adb +++ b/gcc/ada/errout.adb @@ -2021,33 +2021,129 @@ package body Errout is when N_Character_Literal => return S + 2; - -- Skip past numeric literals, but they allow a wider set of - -- characters than keywords and identifiers. + -- Skip past integer literals, both decimal and based, integer and + -- real. We can't greedily accept all allowed character, because + -- we would consme too many of them in expressions like "123+ABC" + -- or "123..456", so we follow quite precisely the Ada grammar and + -- consume different characters depending on the context. when N_Integer_Literal => - while S in SF .. SL - 1 - and then Src (S + 1) - in - '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' | '#' | '+' | '-' + + -- Skip past the initial numeral, which either leads the decimal + -- literal or is the base of a based literal. + + while S < SL + and then Src (S + 1) in '0' .. '9' | '_' loop S := S + 1; end loop; - when N_Real_Literal => - declare - Dot_Seen : Boolean := False; - begin - while S in SF .. SL - 1 + -- Skip past #based_numeral#, if present + + if S < SL + and then Src (S + 1) = '#' + then + S := S + 1; + + while S < SL and then - (Src (S + 1) in '0' .. '9' - | 'a' .. 'f' | 'A' .. 'F' - | '_' | '#' | '+' | '-' - or else (Src (S + 1) = '.' and then not Dot_Seen)) + Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' loop - Dot_Seen := Src (S + 1) = '.'; S := S + 1; end loop; - end; + + pragma Assert (S < SL and then Src (S + 1) = '#'); + + S := S + 1; + end if; + + -- Skip past exponent, if present + + if S < SL + 1 + and then Src (S + 1) in 'e' | 'E' + then + -- For positive exponents the plus sign is optional, but we + -- can simply skip past both plus and minus. + + if Src (S + 2) in '+' | '-' then + S := S + 1; + end if; + + -- Skip past the numeral part + + while S < SL + and then Src (S + 1) in '0' .. '9' | '_' + loop + S := S + 1; + end loop; + end if; + + when N_Real_Literal => + -- Skip past the initial numeral, which either leads the decimal + -- literal or is the base of a based literal. + + while S < SL + and then Src (S + 1) in '0' .. '9' | '_' + loop + S := S + 1; + end loop; + + if S < SL then + if Src (S + 1) = '.' then + while S < SL + and then Src (S + 1) in '0' .. '9' | '_' + loop + S := S + 1; + end loop; + else + pragma Assert (Src (S + 1) = '#'); + + S := S + 1; + + while S < SL + and then + Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' + loop + S := S + 1; + end loop; + + pragma Assert (S < SL and then Src (S + 1) = '.'); + + S := S + 1; + + while S < SL + and then + Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' + loop + S := S + 1; + end loop; + + pragma Assert (S < SL and then Src (S + 1) = '#'); + + S := S + 1; + end if; + end if; + + -- Skip past exponent, if present + + if S < SL + 1 + and then Src (S + 1) in 'e' | 'E' + then + -- For positive exponents the plus sign is optional, but we + -- can simply skip past both plus and minus. + + if Src (S + 2) in '+' | '-' then + S := S + 1; + end if; + + -- Skip past the numeral part + + while S < SL + and then Src (S + 1) in '0' .. '9' | '_' + loop + S := S + 1; + end loop; + end if; -- For other nodes simply skip past a keyword/identifier