From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8218 invoked by alias); 19 Apr 2002 18:54:07 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 8175 invoked from network); 19 Apr 2002 18:54:03 -0000 Received: from unknown (HELO cygnus.com) (205.180.83.203) by sources.redhat.com with SMTP; 19 Apr 2002 18:54:03 -0000 Received: from redhat.com (reddwarf.sfbay.redhat.com [172.16.24.50]) by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id LAA03427; Fri, 19 Apr 2002 11:54:03 -0700 (PDT) Message-ID: <3CC0650E.35464D1B@redhat.com> Date: Fri, 19 Apr 2002 11:54:00 -0000 From: Michael Snyder Organization: Red Hat, Inc. X-Accept-Language: en MIME-Version: 1.0 To: Michael Snyder CC: gdb-patches@sources.redhat.com Subject: Re: [RFA] Change to parse error reporting References: <200204121931.g3CJVae12068@reddwarf.sfbay.redhat.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2002-04/txt/msg00632.txt.bz2 Michael Snyder wrote: > > Folks, > > I've never liked the way in which "parse error" messages in gdb > always point to the token _after_ the error, instead of at the > token _causing_ the error. > > This change (implemented for the c/c++ parser only) will make it > point at the error token instead of the following token. > Extending the change to the other languages will be trivial, > if you agree with this. > > OK to commit? Does anybody have any opinion about this? If not I'll check it in next week. > > 2002-04-12 Michael Snyder > > * parser-defs.h (prev_lexptr): New external variable. > * parse.c (parse_exp_1): Set prev_lexptr to null before > calling the language-specific parser. > * c-exp.y (yylex): Set prev_lexptr to start of current token. > (yyerror): Use prev_lexptr in error reporting. > > Index: parse.c > =================================================================== > RCS file: /cvs/src/src/gdb/parse.c,v > retrieving revision 1.22 > diff -p -r1.22 parse.c > *** parse.c 9 Apr 2002 22:14:39 -0000 1.22 > --- parse.c 12 Apr 2002 19:40:35 -0000 > *************** int arglist_len; > *** 76,81 **** > --- 76,82 ---- > union type_stack_elt *type_stack; > int type_stack_depth, type_stack_size; > char *lexptr; > + char *prev_lexptr; > char *namecopy; > int paren_depth; > int comma_terminates; > *************** parse_exp_1 (char **stringptr, struct bl > *** 1126,1131 **** > --- 1127,1133 ---- > struct cleanup *old_chain; > > lexptr = *stringptr; > + prev_lexptr = NULL; > > paren_depth = 0; > type_stack_depth = 0; > Index: parser-defs.h > =================================================================== > RCS file: /cvs/src/src/gdb/parser-defs.h,v > retrieving revision 1.7 > diff -p -r1.7 parser-defs.h > *** parser-defs.h 9 Apr 2002 22:14:39 -0000 1.7 > --- parser-defs.h 12 Apr 2002 19:40:35 -0000 > *************** extern struct type *follow_types (struct > *** 150,155 **** > --- 150,159 ---- > > extern char *lexptr; > > + /* After a token has been recognized, this variable points to it. > + Currently used only for error reporting. */ > + extern char *prev_lexptr; > + > /* Tokens that refer to names do so with explicit pointer and length, > so they can share the storage that lexptr is parsing. > > Index: c-exp.y > =================================================================== > RCS file: /cvs/src/src/gdb/c-exp.y,v > retrieving revision 1.7 > diff -p -r1.7 c-exp.y > *** c-exp.y 15 Nov 2001 01:55:59 -0000 1.7 > --- c-exp.y 12 Apr 2002 19:40:35 -0000 > *************** yylex () > *** 1218,1223 **** > --- 1218,1224 ---- > > retry: > > + prev_lexptr = lexptr; > unquoted_expr = 1; > > tokstart = lexptr; > *************** void > *** 1738,1742 **** > --- 1739,1746 ---- > yyerror (msg) > char *msg; > { > + if (prev_lexptr) > + lexptr = prev_lexptr; > + > error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr); > }