[geany/geany] ea660f: Determine anonymous tags based on name only when necessary

Jiří Techet git-noreply at xxxxx
Sat Feb 12 21:38:22 UTC 2022


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Mon, 10 Jan 2022 21:37:44 UTC
Commit:      ea660f8b1fab4c0da5a399db79487e56b59dc7da
             https://github.com/geany/geany/commit/ea660f8b1fab4c0da5a399db79487e56b59dc7da

Log Message:
-----------
Determine anonymous tags based on name only when necessary

At this point all built in parsers should report anonymous tags correctly
so for them we don't need to determine anonymous tags based on tag name.
Since tag files might be generated without this information, we still
have to determine anonymous tags based on name for them.


Modified Paths:
--------------
    src/tagmanager/tm_ctags.c
    src/tagmanager/tm_parser.c
    src/tagmanager/tm_parser.h
    src/tagmanager/tm_source_file.c
    src/tagmanager/tm_tag.c

Modified: src/tagmanager/tm_ctags.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -122,7 +122,7 @@ static gboolean init_tag(TMTag *tag, TMSourceFile *file, const tagEntryInfo *tag
 	tag->local = tag_entry->isFileScope;
 	tag->flags = tm_tag_flag_none_t;
 	if (isTagExtraBitMarked(tag_entry, XTAG_ANONYMOUS))
-		tag->flags = tm_tag_flag_anon_t;
+		tag->flags |= tm_tag_flag_anon_t;
 	tag->line = tag_entry->lineNumber;
 	if (NULL != tag_entry->extensionFields.signature)
 		tag->arglist = g_strdup(tag_entry->extensionFields.signature);


Modified: src/tagmanager/tm_parser.c
21 lines changed, 21 insertions(+), 0 deletions(-)
===================================================================
@@ -862,6 +862,27 @@ const gchar *tm_parser_get_constructor_method(TMParserType lang)
 }
 
 
+/* determine anonymous tags from tag names only when corresponding
+ * ctags information is not available */
+gboolean tm_parser_is_anon_name(TMParserType lang, gchar *name)
+{
+	guint i;
+	char dummy;
+
+	if (sscanf(name, "__anon%u%c", &i, &dummy) == 1)  /* uctags tags files */
+		return TRUE;
+	else if (lang == TM_PARSER_C || lang == TM_PARSER_CPP)  /* legacy Geany tags files */
+		return sscanf(name, "anon_%*[a-z]_%u%c", &i, &dummy) == 1;
+	else if (lang == TM_PARSER_FORTRAN || lang == TM_PARSER_F77)  /* legacy Geany tags files */
+	{
+		return sscanf(name, "Structure#%u%c", &i, &dummy) == 1 ||
+			sscanf(name, "Interface#%u%c", &i, &dummy) == 1 ||
+			sscanf(name, "Enum#%u%c", &i, &dummy) == 1;
+	}
+	return FALSE;
+}
+
+
 static gchar *replace_string_if_present(gchar *haystack, gchar *needle, gchar *subst)
 {
 	if (strstr(haystack, needle))


Modified: src/tagmanager/tm_parser.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -128,6 +128,8 @@ gint tm_parser_scope_autocomplete_suffix(TMParserType lang, const gchar *str);
 
 const gchar *tm_parser_get_constructor_method(TMParserType lang);
 
+gboolean tm_parser_is_anon_name(TMParserType lang, gchar *name);
+
 gchar *tm_parser_update_scope(TMParserType lang, gchar *scope);
 
 gboolean tm_parser_enable_role(TMParserType lang, gchar kind);


Modified: src/tagmanager/tm_source_file.c
13 lines changed, 10 insertions(+), 3 deletions(-)
===================================================================
@@ -175,7 +175,7 @@ gchar tm_source_file_get_tag_access(const gchar *access)
  @param fp FILE pointer from where the tag line is read
  @return TRUE on success, FALSE on FAILURE
 */
-static gboolean init_tag_from_file(TMTag *tag, TMSourceFile *file, FILE *fp)
+static gboolean init_tag_from_file(TMTag *tag, TMSourceFile *file, FILE *fp, TMParserType lang)
 {
 	guchar buf[BUFSIZ];
 	guchar *start, *end;
@@ -198,7 +198,11 @@ static gboolean init_tag_from_file(TMTag *tag, TMSourceFile *file, FILE *fp)
 			if (!isprint(*start))
 				return FALSE;
 			else
+			{
 				tag->name = g_strdup((gchar*)start);
+				if (tm_parser_is_anon_name(lang, tag->name))
+					tag->flags |= tm_tag_flag_anon_t;
+			}
 		}
 		else
 		{
@@ -220,7 +224,7 @@ static gboolean init_tag_from_file(TMTag *tag, TMSourceFile *file, FILE *fp)
 					tag->scope = g_strdup((gchar*)start + 1);
 					break;
 				case TA_FLAGS:
-					tag->flags = atoi((gchar*)start + 1);
+					tag->flags |= atoi((gchar*)start + 1);
 					break;
 				case TA_VARTYPE:
 					tag->var_type = g_strdup((gchar*)start + 1);
@@ -324,6 +328,9 @@ static gboolean init_tag_from_file_ctags(TMTag *tag, TMSourceFile *file, FILE *f
 	tag->name = g_strndup(p, (gsize)(tab - p));
 	p = tab + 1;
 
+	if (tm_parser_is_anon_name(lang, tag->name))
+		tag->flags |= tm_tag_flag_anon_t;
+
 	/* tagfile, unused */
 	if (! (tab = strchr(p, '\t')))
 	{
@@ -422,7 +429,7 @@ static TMTag *new_tag_from_tags_file(TMSourceFile *file, FILE *fp, TMParserType
 	switch (format)
 	{
 		case TM_FILE_FORMAT_TAGMANAGER:
-			result = init_tag_from_file(tag, file, fp);
+			result = init_tag_from_file(tag, file, fp, mode);
 			break;
 		case TM_FILE_FORMAT_PIPE:
 			result = init_tag_from_file_alt(tag, file, fp);


Modified: src/tagmanager/tm_tag.c
15 lines changed, 2 insertions(+), 13 deletions(-)
===================================================================
@@ -665,21 +665,10 @@ tm_get_current_tag (GPtrArray * file_tags, const gulong line, const TMTagType ta
 	return matching_tag;
 }
 
+
 gboolean tm_tag_is_anon(const TMTag *tag)
 {
-	guint i;
-	char dummy;
-
-	if (tag->flags & tm_tag_flag_anon_t)
-		return TRUE;
-
-	if (tag->lang == TM_PARSER_C || tag->lang == TM_PARSER_CPP)
-		return sscanf(tag->name, "__anon%u%c", &i, &dummy) == 1;
-	else if (tag->lang == TM_PARSER_FORTRAN || tag->lang == TM_PARSER_F77)
-		return sscanf(tag->name, "Structure#%u%c", &i, &dummy) == 1 ||
-			sscanf(tag->name, "Interface#%u%c", &i, &dummy) == 1 ||
-			sscanf(tag->name, "Enum#%u%c", &i, &dummy) == 1;
-	return FALSE;
+	return tag->flags & tm_tag_flag_anon_t;
 }
 
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list