Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Improve handling of Fortran keywords
@ 2010-12-14 16:18 Greg Watson
  2010-12-14 17:41 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Watson @ 2010-12-14 16:18 UTC (permalink / raw)
  To: gdb-patches

Hi,

Currently, gdb 7.2 will not allow me to use identifier names such as "integer_var" as it treats the first "integer" part as a keyword without checking that the identifier is actually longer than the keyword. Here's a simple patch to fix this (and make Fortran debugging more useful).

Regards,
Greg

*** f-exp.y.orig	2010-12-14 10:28:34.542834692 -0500
--- f-exp.y	2010-12-14 11:06:04.798853514 -0500
***************
*** 955,960 ****
--- 955,961 ----
  {
    int c;
    int namelen;
+   int keylen;
    unsigned int i,token;
    char *tokstart;
    
***************
*** 1149,1162 ****
    
    /* Catch specific keywords.  */
    
!   for (i = 0; f77_keywords[i].operator != NULL; i++)
!     if (strncmp (tokstart, f77_keywords[i].operator,
! 		 strlen(f77_keywords[i].operator)) == 0)
        {
  	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
  	yylval.opcode = f77_keywords[i].opcode;
  	return f77_keywords[i].token;
        }
    
    yylval.sval.ptr = tokstart;
    yylval.sval.length = namelen;
--- 1150,1165 ----
    
    /* Catch specific keywords.  */
    
!   for (i = 0; f77_keywords[i].operator != NULL; i++) {
!     keylen = strlen(f77_keywords[i].operator);
!     if (strlen(tokstart) == keylen &&
!             strncmp (tokstart, f77_keywords[i].operator, keylen) == 0)
        {
  	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
  	yylval.opcode = f77_keywords[i].opcode;
  	return f77_keywords[i].token;
        }
+   }
    
    yylval.sval.ptr = tokstart;
    yylval.sval.length = namelen;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improve handling of Fortran keywords
  2010-12-14 16:18 Improve handling of Fortran keywords Greg Watson
@ 2010-12-14 17:41 ` Tom Tromey
  2010-12-15 18:52   ` Greg Watson
  0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2010-12-14 17:41 UTC (permalink / raw)
  To: Greg Watson; +Cc: gdb-patches

>>>>> "Greg" == Greg Watson <g.watson@computer.org> writes:

Greg> Currently, gdb 7.2 will not allow me to use identifier names such
Greg> as "integer_var" as it treats the first "integer" part as a
Greg> keyword without checking that the identifier is actually longer
Greg> than the keyword. Here's a simple patch to fix this (and make
Greg> Fortran debugging more useful).

Could you try this patch instead?

I think it should have the same effect, but it is simpler.

Tom

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 415819a..487b00d 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1150,8 +1150,7 @@ yylex ()
   /* Catch specific keywords.  */
   
   for (i = 0; f77_keywords[i].operator != NULL; i++)
-    if (strncmp (tokstart, f77_keywords[i].operator,
-		 strlen(f77_keywords[i].operator)) == 0)
+    if (strncmp (tokstart, f77_keywords[i].operator, namelen)) == 0)
       {
 	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
 	yylval.opcode = f77_keywords[i].opcode;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improve handling of Fortran keywords
  2010-12-14 17:41 ` Tom Tromey
@ 2010-12-15 18:52   ` Greg Watson
  2010-12-15 19:28     ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Watson @ 2010-12-15 18:52 UTC (permalink / raw)
  To: gdb-patches

Nope, this is not going to work. If the identifier being printed is shorter than the keyword, they will match. You really have to check the length as well.

If you want to use namelen, then I think this is the minimum required change.

Greg

*** f-exp.y.orig	2010-12-14 10:28:34.542834692 -0500
--- f-exp.y	2010-12-15 13:49:51.189819361 -0500
***************
*** 1150,1157 ****
    /* Catch specific keywords.  */
    
    for (i = 0; f77_keywords[i].operator != NULL; i++)
!     if (strncmp (tokstart, f77_keywords[i].operator,
! 		 strlen(f77_keywords[i].operator)) == 0)
        {
  	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
  	yylval.opcode = f77_keywords[i].opcode;
--- 1150,1157 ----
    /* Catch specific keywords.  */
    
    for (i = 0; f77_keywords[i].operator != NULL; i++)
!     if (strlen(f77_keywords[i].operator) == namelen &&
!             strncmp (tokstart, f77_keywords[i].operator, namelen) == 0)
        {
  	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
  	yylval.opcode = f77_keywords[i].opcode;


On Dec 14, 2010, at 12:41 PM, Tom Tromey wrote:

>>>>>> "Greg" == Greg Watson <g.watson@computer.org> writes:
> 
> Greg> Currently, gdb 7.2 will not allow me to use identifier names such
> Greg> as "integer_var" as it treats the first "integer" part as a
> Greg> keyword without checking that the identifier is actually longer
> Greg> than the keyword. Here's a simple patch to fix this (and make
> Greg> Fortran debugging more useful).
> 
> Could you try this patch instead?
> 
> I think it should have the same effect, but it is simpler.
> 
> Tom
> 
> diff --git a/gdb/f-exp.y b/gdb/f-exp.y
> index 415819a..487b00d 100644
> --- a/gdb/f-exp.y
> +++ b/gdb/f-exp.y
> @@ -1150,8 +1150,7 @@ yylex ()
>   /* Catch specific keywords.  */
> 
>   for (i = 0; f77_keywords[i].operator != NULL; i++)
> -    if (strncmp (tokstart, f77_keywords[i].operator,
> -		 strlen(f77_keywords[i].operator)) == 0)
> +    if (strncmp (tokstart, f77_keywords[i].operator, namelen)) == 0)
>       {
> 	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
> 	yylval.opcode = f77_keywords[i].opcode;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Improve handling of Fortran keywords
  2010-12-15 18:52   ` Greg Watson
@ 2010-12-15 19:28     ` Tom Tromey
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2010-12-15 19:28 UTC (permalink / raw)
  To: Greg Watson; +Cc: gdb-patches

>>>>> "Greg" == Greg Watson <g.watson@computer.org> writes:

Greg> Nope, this is not going to work. If the identifier being printed
Greg> is shorter than the keyword, they will match. You really have to
Greg> check the length as well.

Oops, duh.

Greg> If you want to use namelen, then I think this is the minimum
Greg> required change.

Thanks.

I am checking it in.  Here is the final patch with ChangeLog entry.

Tom

2010-12-15  Greg Watson  <g.watson@computer.org>

	* f-exp.y (yylex): Check entire token against keywords.

Index: f-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/f-exp.y,v
retrieving revision 1.33
diff -u -r1.33 f-exp.y
--- f-exp.y	2 Jun 2010 22:41:55 -0000	1.33
+++ f-exp.y	15 Dec 2010 19:20:18 -0000
@@ -1150,8 +1150,8 @@
   /* Catch specific keywords.  */
   
   for (i = 0; f77_keywords[i].operator != NULL; i++)
-    if (strncmp (tokstart, f77_keywords[i].operator,
-		 strlen(f77_keywords[i].operator)) == 0)
+    if (strlen (f77_keywords[i].operator) == namelen
+	&& strncmp (tokstart, f77_keywords[i].operator, namelen) == 0)
       {
 	/* 	lexptr += strlen(f77_keywords[i].operator); */ 
 	yylval.opcode = f77_keywords[i].opcode;


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-12-15 19:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-14 16:18 Improve handling of Fortran keywords Greg Watson
2010-12-14 17:41 ` Tom Tromey
2010-12-15 18:52   ` Greg Watson
2010-12-15 19:28     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox