From c03c195a274ab4092cc5f2a881a87cb2643d9b3b Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 12 May 2015 19:35:54 +0300 Subject: [PATCH] Fix tagging of symbols in C enumerations * lib-src/etags.c (consider_token): Don't tag symbols in expressions that assign values to enum constants. See http://lists.gnu.org/archive/html/emacs-devel/2015-05/msg00291.html for details. (C_entries): Reset fvdef to fvnone after processing a preprocessor conditional and after a comma outside of parentheses. --- lib-src/etags.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib-src/etags.c b/lib-src/etags.c index b1361dbe7ad..f2438213d04 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -2862,7 +2862,10 @@ consider_token (char *str, int len, int c, int *c_extp, case st_none: if (constantypedefs && structdef == snone - && structtype == st_C_enum && bracelev > structbracelev) + && structtype == st_C_enum && bracelev > structbracelev + /* Don't tag tokens in expressions that assign values to enum + constants. */ + && fvdef != vignore) return true; /* enum constant */ switch (fvdef) { @@ -3176,7 +3179,19 @@ C_entries (int c_ext, FILE *inf) cpptoken = false; } if (cpptoken) - definedef = dsharpseen; + { + definedef = dsharpseen; + /* This is needed for tagging enum values: when there are + preprocessor conditionals inside the enum, we need to + reset the value of fvdef so that the next enum value is + tagged even though the one before it did not end in a + comma. */ + if (fvdef == vignore && instruct && parlev == 0) + { + if (strneq (cp, "#if", 3) || strneq (cp, "#el", 3)) + fvdef = fvnone; + } + } } /* if (definedef == dnone) */ continue; case '[': @@ -3507,7 +3522,10 @@ C_entries (int c_ext, FILE *inf) case fstartlist: case finlist: case fignore: + break; case vignore: + if (instruct && parlev == 0) + fvdef = fvnone; break; case fdefunname: fvdef = fignore; -- 2.39.5