From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3110 invoked by alias); 12 Apr 2002 19:43:43 -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 3101 invoked from network); 12 Apr 2002 19:43:41 -0000 Received: from unknown (HELO cygnus.com) (205.180.83.203) by sources.redhat.com with SMTP; 12 Apr 2002 19:43:41 -0000 Received: from reddwarf.sfbay.redhat.com (reddwarf.sfbay.redhat.com [172.16.24.50]) by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id MAA25235 for ; Fri, 12 Apr 2002 12:43:41 -0700 (PDT) Received: (from msnyder@localhost) by reddwarf.sfbay.redhat.com (8.11.2/8.11.2) id g3CJVae12068 for gdb-patches@sources.redhat.com; Fri, 12 Apr 2002 12:31:36 -0700 Date: Fri, 12 Apr 2002 12:43:00 -0000 From: Michael Snyder Message-Id: <200204121931.g3CJVae12068@reddwarf.sfbay.redhat.com> To: gdb-patches@sources.redhat.com Subject: [RFA] Change to parse error reporting X-SW-Source: 2002-04/txt/msg00467.txt.bz2 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? 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); }