aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lex.l
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-01-26 07:11:18 -0700
committerTom Tromey <tromey@adacore.com>2022-02-28 10:49:29 -0700
commitc9f66f0005000492739dd063ea2949045bf70bc6 (patch)
tree7298f37b0e63711abc336fa0695d80a67d5c9144 /gdb/ada-lex.l
parenta7041de85a0cc43b86989eb697cef7a6cecdbdb7 (diff)
downloadgdb-c9f66f0005000492739dd063ea2949045bf70bc6.zip
gdb-c9f66f0005000492739dd063ea2949045bf70bc6.tar.gz
gdb-c9f66f0005000492739dd063ea2949045bf70bc6.tar.bz2
Handle multi-byte bracket sequences in Ada lexer
As noted in an earlier patch, the Ada lexer does not handle multi-byte bracket sequences. This patch adds support for these for character literals. gdb does not generally seem to handle the Ada wide string types, so for the time being these continue to be excluded -- but an explicit error is added to make this more clear.
Diffstat (limited to 'gdb/ada-lex.l')
-rw-r--r--gdb/ada-lex.l24
1 files changed, 14 insertions, 10 deletions
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index d64496a..f61efba 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -1,4 +1,4 @@
-/* FLEX lexer for Ada expressions, for GDB.
+/* FLEX lexer for Ada expressions, for GDB. -*- c++ -*-
Copyright (C) 1994-2022 Free Software Foundation, Inc.
This file is part of GDB.
@@ -150,20 +150,22 @@ static int paren_depth;
}
<INITIAL>"'"({GRAPHIC}|\")"'" {
- yylval.typed_val.type = type_char (pstate);
yylval.typed_val.val = yytext[1];
+ yylval.typed_val.type = type_for_char (pstate, yytext[1]);
return CHARLIT;
}
-<INITIAL>"'[\""{HEXDIG}{2}"\"]'" {
- int v;
- yylval.typed_val.type = type_char (pstate);
- sscanf (yytext+3, "%2x", &v);
+<INITIAL>"'[\""{HEXDIG}{2,}"\"]'" {
+ ULONGEST v = strtoulst (yytext+3, nullptr, 16);
yylval.typed_val.val = v;
+ yylval.typed_val.type = type_for_char (pstate, v);
return CHARLIT;
}
-\"({GRAPHIC}|"[\""({HEXDIG}{2}|\")"\"]")*\" {
+ /* Note that we don't handle bracket sequences of more than 2
+ digits here. Currently there's no support for wide or
+ wide-wide strings. */
+\"({GRAPHIC}|"[\""({HEXDIG}{2,}|\")"\"]")*\" {
yylval.sval = processString (yytext+1, yyleng-2);
return STRING;
}
@@ -513,10 +515,12 @@ processString (const char *text, int len)
}
else
{
- int chr;
- sscanf (p+2, "%2x", &chr);
+ const char *end;
+ ULONGEST chr = strtoulst (p + 2, &end, 16);
+ if (chr > 0xff)
+ error (_("wide strings are not yet supported"));
*q = (char) chr;
- p += 5;
+ p = end + 1;
}
}
else