aboutsummaryrefslogtreecommitdiff
path: root/gdb/ch-exp.y
diff options
context:
space:
mode:
authorFred Fish <fnf@specifix.com>1993-01-14 05:10:12 +0000
committerFred Fish <fnf@specifix.com>1993-01-14 05:10:12 +0000
commitc7da3ed3cd1cf1168a969567f4b0741718fe61f3 (patch)
tree56f6182cad9e333090634900354e51144d42ed15 /gdb/ch-exp.y
parent31883f012edd3136e402c13a5a14971cde5cb31f (diff)
downloadgdb-c7da3ed3cd1cf1168a969567f4b0741718fe61f3.zip
gdb-c7da3ed3cd1cf1168a969567f4b0741718fe61f3.tar.gz
gdb-c7da3ed3cd1cf1168a969567f4b0741718fe61f3.tar.bz2
* c-valprint.c (cp_print_class_member): Add extern decl.
* c-valprint.c (c_val_print): Extract code for printing methods and move it to cp_print_class_method in cp-valprint.c. * c-valprint.c (c_val_print): Extract code to print strings and move it to val_print_string in valprint.c. * cp-valprint.c (cp_print_class_method): New function using code extracted from c_val_print. * valprint.c (val_print_string): New function using code extracted from c_val_print. * value.h (val_print_string): Add prototype. **** start-sanitize-chill **** * ch-exp.y (CHARACTER_STRING_LITERAL): Set correct token type. * ch-exp.y (literal): Add action for CHARACTER_STRING_LITERAL. * ch-exp.y (tempbuf, tempbufsize, tempbufindex, GROWBY_MIN_SIZE, CHECKBUF, growbuf_by_size): New variables, macros, and support functions for implementing a dynamically expandable temp buffer. * ch-exp.y (match_string_literal): New lexer function. * ch-exp.y (match_bitstring_literal): Dynamic buffer code removed and replaced with new CHECKBUF macro. * ch-exp.y (yylex): Call match_string_literal when appropriate. * ch-valprint.c (ch_val_print): Add code for TYPE_CODE_PTR. **** end-sanitize-chill ****
Diffstat (limited to 'gdb/ch-exp.y')
-rw-r--r--gdb/ch-exp.y134
1 files changed, 113 insertions, 21 deletions
diff --git a/gdb/ch-exp.y b/gdb/ch-exp.y
index 40865c0..279a0cd 100644
--- a/gdb/ch-exp.y
+++ b/gdb/ch-exp.y
@@ -149,7 +149,7 @@ yyerror PARAMS ((char *));
%token <ssym> LOCATION_NAME
%token <voidval> SET_LITERAL
%token <voidval> EMPTINESS_LITERAL
-%token <voidval> CHARACTER_STRING_LITERAL
+%token <sval> CHARACTER_STRING_LITERAL
%token <sval> BIT_STRING_LITERAL
%token <voidval> STRING
@@ -493,7 +493,9 @@ literal : INTEGER_LITERAL
}
| CHARACTER_STRING_LITERAL
{
- $$ = 0; /* FIXME */
+ write_exp_elt_opcode (OP_STRING);
+ write_exp_string ($1);
+ write_exp_elt_opcode (OP_STRING);
}
| BIT_STRING_LITERAL
{
@@ -973,6 +975,45 @@ buffer_location : FIXME { $$ = 0; }
%%
+/* Implementation of a dynamically expandable buffer for processing input
+ characters acquired through lexptr and building a value to return in
+ yylval. */
+
+static char *tempbuf; /* Current buffer contents */
+static int tempbufsize; /* Size of allocated buffer */
+static int tempbufindex; /* Current index into buffer */
+
+#define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
+
+#define CHECKBUF(size) \
+ do { \
+ if (tempbufindex + (size) >= tempbufsize) \
+ { \
+ growbuf_by_size (size); \
+ } \
+ } while (0);
+
+/* Grow the static temp buffer if necessary, including allocating the first one
+ on demand. */
+
+static void
+growbuf_by_size (count)
+ int count;
+{
+ int growby;
+
+ growby = max (count, GROWBY_MIN_SIZE);
+ tempbufsize += growby;
+ if (tempbuf == NULL)
+ {
+ tempbuf = (char *) malloc (tempbufsize);
+ }
+ else
+ {
+ tempbuf = (char *) realloc (tempbuf, tempbufsize);
+ }
+}
+
/* Try to consume a simple name string token. If successful, returns
a pointer to a nullbyte terminated copy of the name that can be used
in symbol table lookups. If not successful, returns NULL. */
@@ -1270,6 +1311,49 @@ match_float_literal ()
return (0);
}
+/* Recognize a string literal. A string literal is a nonzero sequence
+ of characters enclosed in matching single or double quotes, except that
+ a single character inside single quotes is a character literal, which
+ we reject as a string literal. To embed the terminator character inside
+ a string, it is simply doubled (I.E. "this""is""one""string") */
+
+static int
+match_string_literal ()
+{
+ char *tokptr = lexptr;
+
+ for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
+ {
+ CHECKBUF (1);
+ if (*tokptr == *lexptr)
+ {
+ if (*(tokptr + 1) == *lexptr)
+ {
+ tokptr++;
+ }
+ else
+ {
+ break;
+ }
+ }
+ tempbuf[tempbufindex++] = *tokptr;
+ }
+ if (*tokptr == '\0' /* no terminator */
+ || tempbufindex == 0 /* no string */
+ || (tempbufindex == 1 && *tokptr == '\'')) /* char literal */
+ {
+ return (0);
+ }
+ else
+ {
+ tempbuf[tempbufindex] = '\0';
+ yylval.sval.ptr = tempbuf;
+ yylval.sval.length = tempbufindex;
+ lexptr = ++tokptr;
+ return (CHARACTER_STRING_LITERAL);
+ }
+}
+
/* Recognize a character literal. A character literal is single character
or a control sequence, enclosed in single quotes. A control sequence
is a comma separated list of one or more integer literals, enclosed
@@ -1280,6 +1364,9 @@ match_float_literal ()
As a GNU chill extension, the syntax C'xx' is also recognized as a
character literal, where xx is a hex value for the character.
+ Note that more than a single character, enclosed in single quotes, is
+ a string literal.
+
Returns CHARACTER_LITERAL if a match is found.
*/
@@ -1383,10 +1470,9 @@ match_bitstring_literal ()
int bitcount = 0;
int base;
int digit;
- static char *tempbuf;
- static int tempbufsize;
- static int tempbufindex;
+ tempbufindex = 0;
+
/* Look for the required explicit base specifier. */
switch (*tokptr++)
@@ -1448,20 +1534,7 @@ match_bitstring_literal ()
for (mask = (base >> 1); mask > 0; mask >>= 1)
{
bitcount++;
- /* Grow the static temp buffer if necessary, including allocating
- the first one on demand. */
- if (tempbufindex >= tempbufsize)
- {
- tempbufsize += 64;
- if (tempbuf == NULL)
- {
- tempbuf = (char *) malloc (tempbufsize);
- }
- else
- {
- tempbuf = (char *) realloc (tempbuf, tempbufsize);
- }
- }
+ CHECKBUF (1);
if (digit & mask)
{
tempbuf[tempbufindex] |= (1 << bitoffset);
@@ -1707,12 +1780,31 @@ yylex ()
}
/* Look for characters which start a particular kind of multicharacter
token, such as a character literal, register name, convenience
- variable name, etc. */
+ variable name, string literal, etc. */
switch (*lexptr)
{
+ case '\'':
+ case '\"':
+ /* First try to match a string literal, which is any nonzero
+ sequence of characters enclosed in matching single or double
+ quotes, except that a single character inside single quotes
+ is a character literal, so we have to catch that case also. */
+ token = match_string_literal ();
+ if (token != 0)
+ {
+ return (token);
+ }
+ if (*lexptr == '\'')
+ {
+ token = match_character_literal ();
+ if (token != 0)
+ {
+ return (token);
+ }
+ }
+ break;
case 'C':
case 'c':
- case '\'':
token = match_character_literal ();
if (token != 0)
{