1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

etags: Fix handling of quoted symbol names in Erlang

* lib-src/etags.c (erlang_attribute): Fix handling of quoted
symbol names in Erlang (bug#24960).
This commit is contained in:
David Hull 2019-06-25 19:12:22 +02:00 committed by Lars Ingebrigtsen
parent a8457f0ada
commit f0151e17d2

View file

@ -6043,7 +6043,7 @@ prolog_atom (char *s, size_t pos)
* Assumes that Erlang functions start at column 0. * Assumes that Erlang functions start at column 0.
* Original code by Anders Lindgren (1996) * Original code by Anders Lindgren (1996)
*/ */
static int erlang_func (char *, char *); static int erlang_func (char *, char *, int *);
static void erlang_attribute (char *); static void erlang_attribute (char *);
static int erlang_atom (char *); static int erlang_atom (char *);
@ -6053,6 +6053,7 @@ Erlang_functions (FILE *inf)
char *cp, *last; char *cp, *last;
int len; int len;
int allocated; int allocated;
int name_offset = 0;
allocated = 0; allocated = 0;
len = 0; len = 0;
@ -6077,7 +6078,7 @@ Erlang_functions (FILE *inf)
last = NULL; last = NULL;
} }
} }
else if ((len = erlang_func (cp, last)) > 0) else if ((len = erlang_func (cp, last, &name_offset)) > 0)
{ {
/* /*
* Function. Store the function name so that we only * Function. Store the function name so that we only
@ -6088,7 +6089,7 @@ Erlang_functions (FILE *inf)
else if (len + 1 > allocated) else if (len + 1 > allocated)
xrnew (last, len + 1, char); xrnew (last, len + 1, char);
allocated = len + 1; allocated = len + 1;
memcpy (last, cp, len); memcpy (last, cp + name_offset, len);
last[len] = '\0'; last[len] = '\0';
} }
} }
@ -6107,12 +6108,13 @@ Erlang_functions (FILE *inf)
* was found. * was found.
*/ */
static int static int
erlang_func (char *s, char *last) erlang_func (char *s, char *last, int *name_offset)
/* Name of last clause. */ /* Name of last clause. */
{ {
int pos; int pos;
int len; int len;
char *name = s;
pos = erlang_atom (s); pos = erlang_atom (s);
if (pos < 1) if (pos < 1)
@ -6121,13 +6123,23 @@ erlang_func (char *s, char *last)
len = pos; len = pos;
pos = skip_spaces (s + pos) - s; pos = skip_spaces (s + pos) - s;
/* If the name is quoted, the quotes are not part of the name. */
if (len > 2 && name[0] == '\'' && name[len - 1] == '\'')
{
*name_offset = 1;
name++;
len -= 2;
}
else
*name_offset = 0;
/* Save only the first clause. */ /* Save only the first clause. */
if (s[pos++] == '(' if (s[pos++] == '('
&& (last == NULL && (last == NULL
|| len != (int)strlen (last) || len != (int)strlen (last)
|| !strneq (s, last, len))) || !strneq (name, last, len)))
{ {
make_tag (s, len, true, s, pos, lineno, linecharno); make_tag (name, len, true, s, pos, lineno, linecharno);
return len; return len;
} }
@ -6148,13 +6160,25 @@ static void
erlang_attribute (char *s) erlang_attribute (char *s)
{ {
char *cp = s; char *cp = s;
int pos;
int len;
if ((LOOKING_AT (cp, "-define") || LOOKING_AT (cp, "-record")) if ((LOOKING_AT (cp, "-define") || LOOKING_AT (cp, "-record"))
&& *cp++ == '(') && *cp++ == '(')
{ {
int len = erlang_atom (skip_spaces (cp)); cp = skip_spaces (cp);
len = erlang_atom (cp);
pos = cp + len - s;
if (len > 0) if (len > 0)
make_tag (cp, len, true, s, cp + len - s, lineno, linecharno); {
/* If the name is quoted, the quotes are not part of the name. */
if (len > 2 && cp[0] == '\'' && cp[len - 1] == '\'')
{
cp++;
len -= 2;
}
make_tag (cp, len, true, s, pos, lineno, linecharno);
}
} }
return; return;
} }