This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[cplus] Parser tweak
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 11 Jan 2004 19:46:31 -0500
- Subject: [cplus] Parser tweak
In response to boost. The demangler can generate <(&extern_variable)>, but
I only expected &extern_variable and &(extern_variable).
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
2004-01-11 Daniel Jacobowitz <drow@mvista.com>
* cp-names.y (orig_lexptr): New variable.
(exp1): New production for parenthesized references.
(yyerror): Print out complete string on parse error.
(demangled_name_to_comp, main): Set orig_lexptr.
Index: cp-names.y
===================================================================
RCS file: /cvs/src/src/gdb/Attic/cp-names.y,v
retrieving revision 1.1.2.17
diff -u -p -r1.1.2.17 cp-names.y
--- cp-names.y 4 Jan 2004 22:42:41 -0000 1.1.2.17
+++ cp-names.y 12 Jan 2004 00:43:23 -0000
@@ -43,7 +43,7 @@ Foundation, Inc., 59 Temple Place - Suit
#define IN_GDB
#include "cp-demangle.h"
-static const char *lexptr, *prev_lexptr;
+static const char *lexptr, *prev_lexptr, *orig_lexptr;
static struct d_comp *d_qualify (struct d_comp *, int, int);
@@ -934,6 +934,13 @@ exp1 : exp '>' exp
{ $$ = d_binary (">", $1, $3); }
;
+/* References. Not allowed everywhere in template parameters, only
+ at the top level, but treat them as expressions in case they are wrapped
+ in parentheses. */
+exp1 : '&' start
+ { $$ = cp_v3_d_make_comp (di, D_COMP_UNARY, cp_v3_d_make_operator_from_string (di, "&"), $2); }
+ ;
+
/* Expressions, not including the comma operator. */
exp : '-' exp %prec UNARY
{ $$ = d_unary ("-", $2); }
@@ -1989,6 +1996,7 @@ yyerror (msg)
if (prev_lexptr)
lexptr = prev_lexptr;
+ printf ("Orig expression: %s\n", orig_lexptr);
error ("A %s in expression, near `%s'.\n", (msg ? msg : "error"), lexptr);
}
@@ -2043,7 +2051,7 @@ demangled_name_to_comp (const char *dema
int len = strlen (demangled_name);
len = len + len / 8;
- lexptr = demangled_name;
+ orig_lexptr = lexptr = demangled_name;
di = cp_v3_d_init_info_alloc (NULL, DMGL_PARAMS | DMGL_ANSI, len);
@@ -2155,7 +2163,7 @@ main (int argc, char **argv)
/* Use DMGL_VERBOSE to get expanded standard substitutions. */
c = trim_chars (buf, &extra_chars);
str2 = cplus_demangle (buf, DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE);
- lexptr = str2;
+ orig_lexptr = lexptr = str2;
if (lexptr == NULL)
{
/* printf ("Demangling error\n"); */
@@ -2182,7 +2190,7 @@ main (int argc, char **argv)
else
{
int len;
- lexptr = argv[arg];
+ orig_lexptr = lexptr = argv[arg];
len = strlen (lexptr);
di = cp_v3_d_init_info_alloc (NULL, DMGL_PARAMS | DMGL_ANSI, len);
if (yyparse () || result == NULL)