aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-exp.y
diff options
context:
space:
mode:
authorFred Fish <fnf@specifix.com>1992-11-24 03:02:10 +0000
committerFred Fish <fnf@specifix.com>1992-11-24 03:02:10 +0000
commitbac89d6ca8b50de6fb01ccbab2b006ededcfce36 (patch)
tree68618a3057f63c48fc80a0dc3fc7607a9667f074 /gdb/c-exp.y
parent0d44b3d1f0b36d94283f27042f7d3fbd6d8b63ed (diff)
downloadgdb-bac89d6ca8b50de6fb01ccbab2b006ededcfce36.zip
gdb-bac89d6ca8b50de6fb01ccbab2b006ededcfce36.tar.gz
gdb-bac89d6ca8b50de6fb01ccbab2b006ededcfce36.tar.bz2
* c-exp.y (yylex): Add tempbuf, tempbufindex, and tempbufsize,
which together maintain a dynamically expandable static buffer for the lexer to use when translating C strings to their internal form (other future uses possible). Fix parsing of C style strings to do the normal C style input conversions of escaped character sequences. * valops.c (value_string): Remove translation of escaped character sequences, now done in C expression parser.
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r--gdb/c-exp.y70
1 files changed, 54 insertions, 16 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 397931e..c368aa9 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1079,11 +1079,15 @@ const static struct token tokentab2[] =
int
yylex ()
{
- register int c;
- register int namelen;
- register unsigned i;
- register char *tokstart;
-
+ int c;
+ int namelen;
+ unsigned int i;
+ char *tokstart;
+ char *tokptr;
+ int tempbufindex;
+ static char *tempbuf;
+ static int tempbufsize;
+
retry:
tokstart = lexptr;
@@ -1250,21 +1254,55 @@ yylex ()
return c;
case '"':
- for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
- if (c == '\\')
+
+ /* Build the gdb internal form of the input string in tempbuf,
+ translating any standard C escape forms seen. Note that the
+ buffer is null byte terminated *only* for the convenience of
+ debugging gdb itself and printing the buffer contents when
+ the buffer contains no embedded nulls. Gdb does not depend
+ upon the buffer being null byte terminated, it uses the length
+ string instead. This allows gdb to handle C strings (as well
+ as strings in other languages) with embedded null bytes */
+
+ tokptr = ++tokstart;
+ tempbufindex = 0;
+
+ do {
+ /* Grow the static temp buffer if necessary, including allocating
+ the first one on demand. */
+ if (tempbufindex + 1 >= tempbufsize)
{
- c = tokstart[++namelen];
- if (c >= '0' && c <= '9')
+ tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
+ }
+ switch (*tokptr)
+ {
+ case '\0':
+ case '"':
+ /* Do nothing, loop will terminate. */
+ break;
+ case '\\':
+ tokptr++;
+ c = parse_escape (&tokptr);
+ if (c == -1)
{
- c = tokstart[++namelen];
- if (c >= '0' && c <= '9')
- c = tokstart[++namelen];
+ continue;
}
+ tempbuf[tempbufindex++] = c;
+ break;
+ default:
+ tempbuf[tempbufindex++] = *tokptr++;
+ break;
}
- yylval.sval.ptr = tokstart + 1;
- yylval.sval.length = namelen - 1;
- lexptr += namelen + 1;
- return STRING;
+ } while ((*tokptr != '"') && (*tokptr != '\0'));
+ if (*tokptr++ != '"')
+ {
+ error ("Unterminated string in expression.");
+ }
+ tempbuf[tempbufindex] = '\0'; /* See note above */
+ yylval.sval.ptr = tempbuf;
+ yylval.sval.length = tempbufindex;
+ lexptr = tokptr;
+ return (STRING);
}
if (!(c == '_' || c == '$'