git: 9f35eb8f96a5 - main - ctags: Recognize __attribute__ in function declarations.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 25 May 2023 18:16:50 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=9f35eb8f96a55aac92fc0c7d08f4b6ab0ae9bc39
commit 9f35eb8f96a55aac92fc0c7d08f4b6ab0ae9bc39
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-05-25 17:07:25 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-05-25 18:02:24 +0000
ctags: Recognize __attribute__ in function declarations.
MFC after: 1 week
Obtained from: NetBSD
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D40264
---
usr.bin/ctags/C.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/usr.bin/ctags/C.c b/usr.bin/ctags/C.c
index aca50c67226b..80b6c42a7a5c 100644
--- a/usr.bin/ctags/C.c
+++ b/usr.bin/ctags/C.c
@@ -39,6 +39,7 @@ static char sccsid[] = "@(#)C.c 8.4 (Berkeley) 4/2/94";
__FBSDID("$FreeBSD$");
#include <limits.h>
+#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -261,6 +262,9 @@ func_entry(void)
{
int c; /* current character */
int level = 0; /* for matching '()' */
+ static char attribute[] = "__attribute__";
+ char maybe_attribute[sizeof attribute + 1],
+ *anext;
/*
* Find the end of the assumed function declaration.
@@ -298,10 +302,37 @@ fnd:
* is a token character if it's a function and a non-token
* character if it's a declaration. Comments don't count...
*/
- for (;;) {
+ for (anext = maybe_attribute;;) {
while (GETC(!=, EOF) && iswhite(c))
if (c == '\n')
SETLINE;
+ if (c == EOF)
+ return NO;
+ /*
+ * Recognize the gnu __attribute__ extension, which would
+ * otherwise make the heuristic test DTWT
+ */
+ if (anext == maybe_attribute) {
+ if (intoken(c)) {
+ *anext++ = c;
+ continue;
+ }
+ } else {
+ if (intoken(c)) {
+ if (anext - maybe_attribute
+ < (ptrdiff_t)(sizeof attribute - 1))
+ *anext++ = c;
+ else break;
+ continue;
+ } else {
+ *anext++ = '\0';
+ if (strcmp(maybe_attribute, attribute) == 0) {
+ (void)ungetc(c, inf);
+ return NO;
+ }
+ break;
+ }
+ }
if (intoken(c) || c == '{')
break;
if (c == '/' && (GETC(==, '*') || c == '/'))