From patchwork Sun Apr 21 17:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 88816 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8522C384AB55 for ; Sun, 21 Apr 2024 17:01:24 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 90E363858D37 for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 90E363858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 90E363858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; cv=none; b=rJonQR/W5ZMYXIyMowkCB1EMvyBSrW9KzaSFfuDmZ8ebL/dLIygFZNl5ERDbt82qhrm3OL24DLmiqcDoGCckxFZ54WhzdrLWdQYZRjzjpB/0w43qsNAuC+JTou+27D40PMTVDGsfbQMrIbr0F+TtVEtUB+8HcrZA47QAO5L0LxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718809; c=relaxed/simple; bh=FUvd3E6NY/BaJD6gUap1v040VhTmbBmYpS5VUlxEZaY=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=Gf8CQke2LgwcFjpfIZRmVJaDHi68wl0+qKNXB1gFpeExnuiUnln+G+1Ezdlj2BNPyj39tczshVuHoSqSY3dRAz0AFZaTu0CgAlJxaZShtH0n6yphMene73g4Ew1RBgJQk9OQ5yuZ5oP1C5QxMyo+lg7ZjSrT7DPVVjD3cNN2zTs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTPS id yZwgrgioJl9dRyaXtroVJ3; Sun, 21 Apr 2024 17:00:05 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXsrHUYKqaR9yaXsrFQqV; Sun, 21 Apr 2024 17:00:05 +0000 X-Authority-Analysis: v=2.4 cv=MqZU6Xae c=1 sm=1 tr=0 ts=66254615 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=UccFzhUPhoxR2GDChe0A:9 a=QEXdDO2ut3YA:10 a=CBL1k2pHJFWxAFsS4eF9:22 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=grzSZ7Hz2NxyJ1RpjF3TgEstqVrqY1nov/OJGXJpgbU=; b=hkLu/FXoF+dssEKcPvgRU6EzX0 XosRVcRW39lWTxU6ubbP6OE8t/USyZFcgH4QItDcp/tj1sZ2R0YB75zRKtKElRs3iZxjRd7o7WHIg +ViU+Cfya6L1a3GYSiEZik7bx; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXs-003wVC-0k for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:04 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:08 -0600 Subject: [PATCH 08/10] Implement C++14 numeric separators MIME-Version: 1.0 Message-Id: <20240421-canon-fixes-v1-8-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.86.252 X-Source-L: No X-Exim-ID: 1ryaXs-003wVC-0k X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 9 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfB5iqFnJ3g/4FlYXYhVA6Z4iW08HobEC5Zg7/gl+TxhZnWILsW29Z2gjopd+dQDGfcXIKjHXKKbgxbQLv2LWRYJsYVyr4UV02LcRavFjqsOYrYU/RYLj 9bL2hv181YJDdlh2S5HK+2nx0sDgyf4NdMUxXG/+1ngs29foo1jaBow+yKtfiDPavTstfBEyAoUOKekD9r2rtDOos58hBW75SOw= X-Spam-Status: No, score=-3021.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_FILL_THIS_FORM_SHORT 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org C++14 allows the use of the apostrophe as a numeric separator; that is, "23000" and "23'000" represent the same number. This patch implements this for gdb's C++ parser and the C++ name canonicalizer. I did this unconditionally for all C variants because I think it's unambiguous. For the name canonicalizer, there's at least one compiler that can emit constants with this form, see bug 30845. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23457 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30845 --- gdb/c-exp.y | 28 +++++++++++++++++++++++----- gdb/cp-name-parser.y | 31 ++++++++++++++++++++++++++----- gdb/testsuite/gdb.cp/misc.exp | 4 ++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 663c30f9517..69cea523abd 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2755,6 +2755,10 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) hex = 0; } + /* If the token includes the C++14 digits separator, we make a + copy so that we don't have to handle the separator in + parse_number. */ + std::optional no_tick; for (;; ++p) { /* This test includes !hex because 'e' is a valid hex digit @@ -2771,18 +2775,32 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) else if (((got_e && (p[-1] == 'e' || p[-1] == 'E')) || (got_p && (p[-1] == 'p' || p[-1] == 'P'))) && (*p == '-' || *p == '+')) - /* This is the sign of the exponent, not the end of the - number. */ - continue; + { + /* This is the sign of the exponent, not the end of + the number. */ + } + else if (*p == '\'') + { + if (!no_tick.has_value ()) + no_tick.emplace (tokstart, p); + continue; + } /* We will take any letters or digits. parse_number will complain if past the radix, or if L or U are not final. */ else if ((*p < '0' || *p > '9') && ((*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z'))) break; + if (no_tick.has_value ()) + no_tick->push_back (*p); } - toktype = parse_number (par_state, tokstart, p - tokstart, - got_dot | got_e | got_p, &yylval); + if (no_tick.has_value ()) + toktype = parse_number (par_state, no_tick->c_str (), + no_tick->length (), + got_dot | got_e | got_p, &yylval); + else + toktype = parse_number (par_state, tokstart, p - tokstart, + got_dot | got_e | got_p, &yylval); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index de08f9c0728..3c5dea2de1c 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -1686,6 +1686,10 @@ yylex (YYSTYPE *lvalp, cpname_state *state) hex = 0; } + /* If the token includes the C++14 digits separator, we make a + copy so that we don't have to handle the separator in + parse_number. */ + std::optional no_tick; for (;; ++p) { /* This test includes !hex because 'e' is a valid hex digit @@ -1703,16 +1707,31 @@ yylex (YYSTYPE *lvalp, cpname_state *state) got_dot = 1; else if (got_e && (p[-1] == 'e' || p[-1] == 'E') && (*p == '-' || *p == '+')) - /* This is the sign of the exponent, not the end of the - number. */ - continue; + { + /* This is the sign of the exponent, not the end of + the number. */ + } + /* C++14 allows a separator. */ + else if (*p == '\'') + { + if (!no_tick.has_value ()) + no_tick.emplace (tokstart, p); + continue; + } /* We will take any letters or digits. parse_number will complain if past the radix, or if L or U are not final. */ else if (! ISALNUM (*p)) break; + if (no_tick.has_value ()) + no_tick->push_back (*p); } - toktype = state->parse_number (tokstart, p - tokstart, got_dot|got_e, - lvalp); + if (no_tick.has_value ()) + toktype = state->parse_number (no_tick->c_str (), + no_tick->length (), + got_dot|got_e, lvalp); + else + toktype = state->parse_number (tokstart, p - tokstart, + got_dot|got_e, lvalp); if (toktype == ERROR) { char *err_copy = (char *) alloca (p - tokstart + 1); @@ -2045,6 +2064,8 @@ canonicalize_tests () should_be_the_same ("x::y::z<0b111>", "x::y::z<7>"); should_be_the_same ("x::y::z<0b111>", "x::y::z<0t7>"); should_be_the_same ("x::y::z<0b111>", "x::y::z<0D7>"); + + should_be_the_same ("x::y::z<0xff'ff>", "x::y::z<65535>"); } #endif diff --git a/gdb/testsuite/gdb.cp/misc.exp b/gdb/testsuite/gdb.cp/misc.exp index 264294f857d..bcb20f85eee 100644 --- a/gdb/testsuite/gdb.cp/misc.exp +++ b/gdb/testsuite/gdb.cp/misc.exp @@ -114,3 +114,7 @@ gdb_test "print *(number_ref + v_bool_array)" "\\$\[0-9\]* = false" \ "integer reference addition with pointer" gdb_test "print *(v_bool_array - number_ref)" "\\$\[0-9\]* = false" \ "pointer subtraction with integer reference" + +# C++14 digit separator. +gdb_test "print 23'23" " = 2323" +gdb_test "print 2'3.5" " = 23.5"