bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#38511: etags seems to be confused by macros


From: Skip Montanaro
Subject: bug#38511: etags seems to be confused by macros
Date: Mon, 9 Dec 2019 06:39:33 -0600

> Eli Zaretskii:

> Etags works by looking at the source at face value, and it doesn't
> expand macros as a C compiler would.  So this:
>
>  Py_LOCAL_INLINE(void) stackdepth_push(basicblock ***sp, basicblock *b, int 
> depth)
>
> looks to its naïve lexical analysis very much like a K&R definition of
> a function and declaration of its arguments:
...
> Patches are welcome, if someone has an idea for how to fix that.

> Franceso:

> Unless some C code wizard steps up and contradicts me, I'd say that it
> is in principle impossible for Etags to detect such macros.  This is a
> work for the --regex feature of Etags, which is thought just for this
> sort of situations.
>
> The Etags man page explains it with examples, as does the info page.

I read the documentation and didn't understand how the regex feature
would help. It seems to be useful to identify other constructs which
you'd like tagged (such as the DEFVAR macro in the Emacs source), not
transform the source in some way. Put another way, I need a
"find/replace" sort of feature, not just a "find" feature.

FWIW, here's the simple shell script I came up with:

#!/bin/bash

# etags gets confused by Python's use of the Py_LOCAL and Py_LOCAL_INLINE
# macros to select compiler-dependent static storage syntax. This script is
# a stand-in for etags which performs the macro expansion manually, then
# pipes the result to etags. $@ are the args to pass to etags.

sed -E -e 's/Py_LOCAL_INLINE *\(([^(]+)\)/static inline \1/' \
    -e 's/Py_LOCAL *\(([^(]+)\)/static \1/' \
    | etags "$@"

I set speedbar-fetch-etags-command to that script. Seems to work well
enough for my needs. It clearly isn't a general solution though. I
suppose I could try to run the source through cpp, though I don't know
if etags is smart enough to use the "# <line> <file>" output of cpp.

I'll take a look at etags.c, but don't hold your breath waiting for a
miracle. :-)

Skip





reply via email to

[Prev in Thread] Current Thread [Next in Thread]