From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wnew3-smtp.messagingengine.com (wnew3-smtp.messagingengine.com [64.147.123.17]) by sourceware.org (Postfix) with ESMTPS id 6F2853851C09 for ; Sat, 4 Jul 2020 03:04:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6F2853851C09 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dxu@dxuuu.xyz Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id 9404FA5A; Fri, 3 Jul 2020 23:04:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 03 Jul 2020 23:04:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=f/ASaX1dBH0rx3OelpJHKewwQc LfD8CENBNU4vZG+hE=; b=ioOkVOv1oK21ZYsyaoq2pDn5AyToDyUro3YFPzu2zB DKlsoTDYNaVCGdy4vIKVRFS5ARg+VVYl4vVZegRrOsdw3wZk+dtI1FXznFhTX7Jl 7Fy3viC32rNyE7DEDarDZhEoIdg95hHCJKUoehEr4kmS/uKAIRm9rmLZK8tzDlQQ KzMn88gfMsaFlT3gGdAkHshX7/meLaLPizogDSCTItQBd5J5wCES4UuY5Wvy/sFn O9KXiFaaWpSGONyhrxQp1xBZpgIWNx5oUCnB4ex5qD68etY7lpuJA5tAw525/lJq 59uEUQAo8WG6na/h1P1FZloEK50fUTiha8hzcxASSHOQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=f/ASaX1dBH0rx3Oel pJHKewwQcLfD8CENBNU4vZG+hE=; b=XGiBRKXPqZe9jw8oXTh5NL1gtQ0k40akQ Z+w+9+1gQ1UHlMk9KsxKySccjwEf9NvXHP3Lo8mPkEY4ayU0hIEagPIW0GWCUqKP SBvOCC5NPn3rzxk4CGqPRZqmfoh/1pxp3R/XyxJ10u3ewA2qS/VCF8UQ0TaGIziY i+6JMIlqqXmk5U8QqkZGyrg6rd9HjlkFU4kBbje7SLagO81ME0oB/0xYhZGo6rOb gGjCzfUsB5pwkt73BAcdTZdu9fZJ9W6yjdHFex0GE/xgwM8pFPJA/6f3e2irVGDk fxo//yU6oU3+PfGs7EtvpARqm18sjP8c2e0eSy6VFk0QGaioGKa0g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrtdejgdeiiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdefhedmnegovehorghsthgrlh dqhfeguddvqddtvdculdduhedtmdenucfjughrpefhvffufffkofgggfestdekredtredt tdenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenuc ggtffrrghtthgvrhhnpefgieeikefhjeetueehudekgfeluedvkeeugeefffdvheegheev fffhgeduveegieenucffohhmrghinheprhhushhtqdhlrghnghdrohhrghdpghhnuhdroh hrghenucfkphepjeefrdelfedrvdegjedrudefgeenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Received: from localhost.localdomain (c-73-93-247-134.hsd1.ca.comcast.net [73.93.247.134]) by mail.messagingengine.com (Postfix) with ESMTPA id 601CE3280059; Fri, 3 Jul 2020 23:04:41 -0400 (EDT) From: Daniel Xu To: gdb-patches@sourceware.org, tom@tromey.com Subject: [PATCH] rust: Support raw identifiers Date: Fri, 3 Jul 2020 20:04:30 -0700 Message-Id: <20200704030430.822085-1-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_SUSPICIOUS_NTLD, FROM_SUSPICIOUS_NTLD_FP, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_INFOUSMEBIZ, KAM_SHORT, PDS_OTHER_BAD_TLD, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Jul 2020 03:04:47 -0000 This patch adds rust raw identifier support. Raw identifiers are detailed here: https://doc.rust-lang.org/reference/identifiers.html . PR 23427 gdb/ * rust-exp.y: Lex raw identifiers gdb/testsuite/ * gdb.rust/expr.exp: Fix test * gdb.rust/raw_ident.exp: Add test file * gdb.rust/raw_ident.rs: Add test file Signed-off-by: Daniel Xu --- gdb/rust-exp.y | 15 +++++++++++- gdb/testsuite/gdb.rust/expr.exp | 2 +- gdb/testsuite/gdb.rust/raw_ident.exp | 34 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.rust/raw_ident.rs | 23 +++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.rust/raw_ident.exp create mode 100644 gdb/testsuite/gdb.rust/raw_ident.rs diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index 4e7878f67e..c745610df6 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -1402,6 +1402,8 @@ rust_parser::lex_identifier (YYSTYPE *lvalp) while ((pstate->lexptr[0] >= 'a' && pstate->lexptr[0] <= 'z') || (pstate->lexptr[0] >= 'A' && pstate->lexptr[0] <= 'Z') || pstate->lexptr[0] == '_' + || (pstate->lexptr[0] == '#' && pstate->lexptr - start == 1 + && *start == 'r') || (is_gdb_var && pstate->lexptr[0] == '$') || (pstate->lexptr[0] >= '0' && pstate->lexptr[0] <= '9')) ++pstate->lexptr; @@ -1438,9 +1440,17 @@ rust_parser::lex_identifier (YYSTYPE *lvalp) pstate->lexptr = start; return 0; } + else if (token == NULL && length == 2 && strncmp (start, "r#", length) == 0) + error (_("Invalid raw identifier")); if (token == NULL || (pstate->parse_completion && pstate->lexptr[0] == '\0')) - lvalp->sval = make_stoken (copy_name (start, length)); + { + /* Handle raw identifiers */ + if (length > 1 && start[0] == 'r' && start[1] == '#') + start += 2; + + lvalp->sval = make_stoken (copy_name (start, length)); + } if (pstate->parse_completion && pstate->lexptr[0] == '\0') { @@ -2773,6 +2783,8 @@ rust_lex_tests (void) rust_lex_exception_test (&parser, "'\\u{}", "Not enough hex digits seen"); rust_lex_exception_test (&parser, "'\\Q'", "Invalid escape \\Q in literal"); rust_lex_exception_test (&parser, "b'\\Q'", "Invalid escape \\Q in literal"); + rust_lex_exception_test (&parser, "r##if", "Invalid raw identifier"); + rust_lex_exception_test (&parser, "r#", "Invalid raw identifier"); rust_lex_int_test (&parser, "23", 23, DECIMAL_INTEGER); rust_lex_int_test (&parser, "2_344__29", 234429, INTEGER); @@ -2797,6 +2809,7 @@ rust_lex_tests (void) rust_lex_stringish_test (&parser, "hibob", "hibob", IDENT); rust_lex_stringish_test (&parser, "hibob__93", "hibob__93", IDENT); rust_lex_stringish_test (&parser, "thread", "thread", IDENT); + rust_lex_stringish_test (&parser, "r#if", "if", IDENT); rust_lex_stringish_test (&parser, "\"string\"", "string", STRING); rust_lex_stringish_test (&parser, "\"str\\ting\"", "str\ting", STRING); diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp index 29a628ea78..6e700896d9 100644 --- a/gdb/testsuite/gdb.rust/expr.exp +++ b/gdb/testsuite/gdb.rust/expr.exp @@ -136,6 +136,6 @@ gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]" # Test lexer corner cases. gdb_test "print 0x0 as *mut ()" " = \\\(\\*mut \\\(\\\)\\\) 0x0" gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\\\) 0x0" -gdb_test "print r#" "syntax error in expression, near `#'\\." +gdb_test "print r#" "Invalid raw identifier" gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22" diff --git a/gdb/testsuite/gdb.rust/raw_ident.exp b/gdb/testsuite/gdb.rust/raw_ident.exp new file mode 100644 index 0000000000..0a8f7c0c5e --- /dev/null +++ b/gdb/testsuite/gdb.rust/raw_ident.exp @@ -0,0 +1,34 @@ +# Copyright (C) 2017-2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test raw identifier support + +load_lib rust-support.exp +if {[skip_rust_tests]} { + continue +} + +standard_testfile .rs +if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} { + return -1 +} + +set line [gdb_get_line_number "set breakpoint here"] +if {![runto ${srcfile}:$line]} { + untested "could not run to breakpoint" + return -1 +} + +gdb_test "print r#if" "5" diff --git a/gdb/testsuite/gdb.rust/raw_ident.rs b/gdb/testsuite/gdb.rust/raw_ident.rs new file mode 100644 index 0000000000..95ec99fb13 --- /dev/null +++ b/gdb/testsuite/gdb.rust/raw_ident.rs @@ -0,0 +1,23 @@ +// Copyright (C) 2017-2020 Free Software Foundation, Inc. + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(unused_assignments)] + +fn main() { + let r#if = 5; + let z = r#if; // set breakpoint here +} -- 2.27.0