From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/3] Fix Ada integer literals with exponents
Date: Tue, 1 Mar 2022 10:00:53 -0700 [thread overview]
Message-ID: <20220301170055.1520935-2-tromey@adacore.com> (raw)
In-Reply-To: <20220301170055.1520935-1-tromey@adacore.com>
While working on another patch, I noticed that Ada integer literals
with exponents did not work. For example, with one form you get an
error:
(gdb) print 8e2
Invalid digit `e' in based literal
And with another form you get an incorrect value:
(gdb) print 16#8#e2
$2 = 8
This patch fixes the bugs and adds tests.
---
gdb/ada-lex.l | 9 +++++---
gdb/testsuite/gdb.ada/literals.exp | 36 ++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 3 deletions(-)
create mode 100644 gdb/testsuite/gdb.ada/literals.exp
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index f61efba81a9..aab53b397ec 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -103,8 +103,9 @@ static int paren_depth;
{NUM10}{POSEXP} {
canonicalizeNumeral (numbuf, yytext);
- return processInt (pstate, NULL, numbuf,
- strrchr (numbuf, 'e') + 1);
+ char *e_ptr = strrchr (numbuf, 'e');
+ *e_ptr = '\0';
+ return processInt (pstate, nullptr, numbuf, e_ptr + 1);
}
{NUM10} {
@@ -114,9 +115,11 @@ static int paren_depth;
{NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} {
canonicalizeNumeral (numbuf, yytext);
+ char *e_ptr = strrchr (numbuf, 'e');
+ *e_ptr = '\0';
return processInt (pstate, numbuf,
strchr (numbuf, '#') + 1,
- strrchr(numbuf, '#') + 1);
+ e_ptr + 1);
}
{NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" {
diff --git a/gdb/testsuite/gdb.ada/literals.exp b/gdb/testsuite/gdb.ada/literals.exp
new file mode 100644
index 00000000000..92a9a1954fc
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/literals.exp
@@ -0,0 +1,36 @@
+# Copyright 2022 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 <http://www.gnu.org/licenses/>.
+
+# Test some literal syntax.
+
+load_lib "ada.exp"
+
+if { [skip_ada_tests] } { return -1 }
+
+clean_restart
+
+gdb_test_no_output "set lang ada"
+gdb_test "print 7#10#" " = 7"
+gdb_test "print 77#10#" "Invalid base: 77."
+gdb_test "print 7#8#" "Invalid digit `8' in based literal"
+
+gdb_test "print 8e2" " = 800"
+gdb_test "print 9999999999999999999999999999999999999999999999" \
+ "Integer literal out of range"
+gdb_test "print 2e1000" "Integer literal out of range"
+
+gdb_test "print 16#ffff#" " = 65535"
+gdb_test "print 16#f#e1" " = 240"
+gdb_test "print 16#1#e10" " = 1099511627776"
--
2.31.1
next prev parent reply other threads:[~2022-03-01 17:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 17:00 [PATCH 0/3] Floating-point literal syntax extension for Ada Tom Tromey
2022-03-01 17:00 ` Tom Tromey [this message]
2022-03-01 17:00 ` [PATCH 2/3] Implement real literal " Tom Tromey
2022-03-01 17:22 ` Eli Zaretskii
2022-03-07 15:28 ` Tom Tromey
2022-03-16 14:33 ` Luis Machado
2022-03-18 18:05 ` Tom Tromey
2022-03-21 9:28 ` Luis Machado
2022-03-29 8:13 ` Luis Machado
2022-03-01 17:00 ` [PATCH 3/3] Fix bug in ada_print_floating Tom Tromey
2022-03-07 15:28 ` [PATCH 0/3] Floating-point literal syntax extension for Ada Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220301170055.1520935-2-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).