all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* etags treats "interface" as a keyword in plain C
@ 2007-02-01 11:07 Per Cederqvist
  0 siblings, 0 replies; 2+ messages in thread
From: Per Cederqvist @ 2007-02-01 11:07 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1448 bytes --]

Revision 3.67 of lib-src/etags.c, fetched from CVS earlier today,
fails to properly handle the following C file:

-- cut here for foo.c --
struct interface *
interface_locate(void)
{
  return 0;
}
-- foo.c ends on the previous line --

The interface_locate function is not detected:

$ etags foo.c
$ cat TAGS


foo.c,0
$

The reason is that "interface" is treated specially.  If I change the
first line by altering a single character, I get the expected result:

-- cut here for bar.c --
struct interlace *
interface_locate(void)
{
  return 0;
}
-- bar.c ends on the previous line --

$ etags bar.c
$ cat TAGS


bar.c,23
interface_locate(2,19
$

The reason seems to be this code in etags.c:

import,		(C_JAVA & !C_PLPL),	st_C_ignore
package,	(C_JAVA & !C_PLPL),	st_C_ignore
friend,		C_PLPL,			st_C_ignore
extends,	(C_JAVA & !C_PLPL),	st_C_javastruct
implements,	(C_JAVA & !C_PLPL),	st_C_javastruct
interface,	(C_JAVA & !C_PLPL),	st_C_struct

As we have the following definitions:

#define C_JAVA	0x00005		/* JAVA */
#define C_PLPL	0x00001		/* C++ */

The expression evaluates to:

(0x00005 & !0x00001)

Since !0x00001 is 0, this evaluates to 0.  My guess is that the author
intended to write ~C_PLPL, not !C_PLPL.

The attached patch fixes the above test case.  However, I'm not
certain that it doesn't break anything else.  If this isn't good,
maybe the value should be reverted back to plain C_JAVA as it was
prior to revision 3.40.

    /ceder


[-- Attachment #2: Suggested fix --]
[-- Type: text/x-patch, Size: 2907 bytes --]

--- ChangeLog~	2007-01-21 05:49:26.000000000 +0100
+++ ChangeLog	2007-02-01 11:57:43.000000000 +0100
@@ -1,3 +1,11 @@
+2007-02-01  Per Cederqvist  <ceder@ingate.com>
+
+	* etags.c: (gperf, in_word_set): changed attribute for Java to
+	(C_JAVA & ~C_PLPL).  The previous change introduced 2004-09-13 was
+	broken, as (C_JAVA & !C_PLPL) always evaluates to 0.  This caused
+	import, package, extends, implements and interface to be treated
+	specially for all kinds of C-style files, not just Java files.
+
 2007-01-02  Francesco Potortì  <pot@gnu.org>
 
 	* etags.c: (longopts): New undocumented option --no-duplicates.
--- etags.c~	2007-01-21 05:49:26.000000000 +0100
+++ etags.c	2007-02-01 11:44:38.000000000 +0100
@@ -2418,12 +2418,12 @@
 @protocol,	0,			st_C_objprot
 @implementation,0,			st_C_objimpl
 @end,		0,			st_C_objend
-import,		(C_JAVA & !C_PLPL),	st_C_ignore
-package,	(C_JAVA & !C_PLPL),	st_C_ignore
+import,		(C_JAVA & ~C_PLPL),	st_C_ignore
+package,	(C_JAVA & ~C_PLPL),	st_C_ignore
 friend,		C_PLPL,			st_C_ignore
-extends,	(C_JAVA & !C_PLPL),	st_C_javastruct
-implements,	(C_JAVA & !C_PLPL),	st_C_javastruct
-interface,	(C_JAVA & !C_PLPL),	st_C_struct
+extends,	(C_JAVA & ~C_PLPL),	st_C_javastruct
+implements,	(C_JAVA & ~C_PLPL),	st_C_javastruct
+interface,	(C_JAVA & ~C_PLPL),	st_C_struct
 class,		0,			st_C_class
 namespace,	C_PLPL,			st_C_struct
 domain,		C_STAR,			st_C_struct
@@ -2534,19 +2534,19 @@
       {"@end",		0,			st_C_objend},
       {"union",		0,			st_C_struct},
       {"define",		0,			st_C_define},
-      {"import",		(C_JAVA & !C_PLPL),	st_C_ignore},
+      {"import",		(C_JAVA & ~C_PLPL),	st_C_ignore},
       {"template",	0,			st_C_template},
       {"operator",	C_PLPL,			st_C_operator},
       {"@interface",	0,			st_C_objprot},
-      {"implements",	(C_JAVA & !C_PLPL),	st_C_javastruct},
+      {"implements",	(C_JAVA & ~C_PLPL),	st_C_javastruct},
       {"friend",		C_PLPL,			st_C_ignore},
       {"typedef",	0,			st_C_typedef},
       {"return",		0,			st_C_ignore},
       {"@implementation",0,			st_C_objimpl},
       {"@protocol",	0,			st_C_objprot},
-      {"interface",	(C_JAVA & !C_PLPL),	st_C_struct},
+      {"interface",	(C_JAVA & ~C_PLPL),	st_C_struct},
       {"extern",		0,			st_C_extern},
-      {"extends",	(C_JAVA & !C_PLPL),	st_C_javastruct},
+      {"extends",	(C_JAVA & ~C_PLPL),	st_C_javastruct},
       {"struct",		0,			st_C_struct},
       {"domain",		C_STAR,			st_C_struct},
       {"switch",		0,			st_C_ignore},
@@ -2556,7 +2556,7 @@
       {"class",		0,			st_C_class},
       {"while",		0,			st_C_ignore},
       {"undef",		0,			st_C_define},
-      {"package",	(C_JAVA & !C_PLPL),	st_C_ignore},
+      {"package",	(C_JAVA & ~C_PLPL),	st_C_ignore},
       {"__attribute__",	0,			st_C_attribute},
       {"SYSCALL",	0,			st_C_gnumacro},
       {"ENTRY",		0,			st_C_gnumacro},

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

_______________________________________________
bug-gnu-emacs mailing list
bug-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnu-emacs

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

* Re: etags treats "interface" as a keyword in plain C
@ 2007-02-04 22:25 Francesco Potorti`
  0 siblings, 0 replies; 2+ messages in thread
From: Francesco Potorti` @ 2007-02-04 22:25 UTC (permalink / raw)
  To: Per Cederqvist; +Cc: bug-gnu-emacs, rms

Thank you for your fix to etags.c, which is in fact correct and which I
have just installed.

What annoys me is that
1) I made such a trivial mistake (using ! instead of ~)
2) it passed all my regression tests
3) I have not noticed it for over two years

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

end of thread, other threads:[~2007-02-04 22:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-01 11:07 etags treats "interface" as a keyword in plain C Per Cederqvist
  -- strict thread matches above, loose matches on Subject: below --
2007-02-04 22:25 Francesco Potorti`

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.