aboutsummaryrefslogtreecommitdiff
path: root/gdb/p-exp.y
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2024-01-15 15:55:28 +0000
committerAndrew Burgess <aburgess@redhat.com>2024-03-25 17:47:43 +0000
commit17640f65fc6d42bfcaac9bcd0c72121c461c555b (patch)
treebb0cc4b771bda8e327f2da71a60c31029452f66b /gdb/p-exp.y
parent7879fba359f185d674d4e981af4f23a066bfe644 (diff)
downloadgdb-17640f65fc6d42bfcaac9bcd0c72121c461c555b.zip
gdb-17640f65fc6d42bfcaac9bcd0c72121c461c555b.tar.gz
gdb-17640f65fc6d42bfcaac9bcd0c72121c461c555b.tar.bz2
gdb: remove skip_quoted and skip_quoted_chars
The function skip_quoted_chars (completer.c) is only used by skip_quoted (also completer.c), so could be made static. The function skip_quoted just calls directly to skip_quoted_chars but fills in some default arguments. The function skip_quoted is only used by the Pascal expression parser, and is only used in one place. The skip_quoted_chars function skips a single string; it either looks for a string between matching quotes, or for a string up to a word break character. However, given how the Pascal expression parser calls this function, we know that the first character will always be a single quote, in which case skip_quoted_chars will looks for a string between matching single quotes. The skip_quoted_chars doesn't do any escaped character handling, it will just stop at the next single quote character. In this commit I propose to remove skip_quoted and skip_quoted_chars, and replace these with a smaller function pascal_skip_string which I've placed in p-exp.y. This new function only skips a string between matching single quotes, which is exactly the use case that we need. The benefit of this change is to remove (some) code duplication. It feels like skip_quoted is similar in some ways to extract_string_maybe_quoted, however, there are some differences; skip_quoted uses the quotes and word break characters from the completion engine which extract_string_maybe_quoted does not. However, I'm currently working on improving filename completion, one part of this is that I'm looking at allowing filenames to be quoted with single or double quotes, while the default string quoting in GDB (for expressions) can only use single quotes. If I do end up allowing single and double quotes in some cases, but we retain the single quotes only for expressions then skip_quoted starts to become a problem, should it accept both quote types, or only one? But given how skip_quoted is used, I can avoid worrying about this by simply removing skip_quoted. The Pascal tests do still pass. The code that called skip_quoted is called at least once in the Pascal tests (adding an abort() call causes gdb.pascal/types.exp to fail), but I doubt the testing is extensive. Not sure how widely used GDB for Pascal actually is though.
Diffstat (limited to 'gdb/p-exp.y')
-rw-r--r--gdb/p-exp.y26
1 files changed, 25 insertions, 1 deletions
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index ea7eb8c..bfb1cad 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -76,6 +76,8 @@ static void yyerror (const char *);
static char *uptok (const char *, int);
+static const char *pascal_skip_string (const char *str);
+
using namespace expr;
%}
@@ -1042,6 +1044,28 @@ uptok (const char *tokstart, int namelen)
return uptokstart;
}
+/* Skip over a Pascal string. STR must point to the opening single quote
+ character. This function returns a pointer to the character after the
+ closing single quote character.
+
+ This function does not support embedded, escaped single quotes, which
+ is done by placing two consecutive single quotes into a string.
+ Support for this would be easy to add, but this function is only used
+ from the Python expression parser, and if we did skip over escaped
+ quotes then the rest of the expression parser wouldn't handle them
+ correctly. */
+static const char *
+pascal_skip_string (const char *str)
+{
+ gdb_assert (*str == '\'');
+
+ do
+ ++str;
+ while (*str != '\0' && *str != '\'');
+
+ return str;
+}
+
/* Read one token, getting characters through lexptr. */
static int
@@ -1120,7 +1144,7 @@ yylex (void)
c = *pstate->lexptr++;
if (c != '\'')
{
- namelen = skip_quoted (tokstart) - tokstart;
+ namelen = pascal_skip_string (tokstart) - tokstart;
if (namelen > 2)
{
pstate->lexptr = tokstart + namelen;