Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: GitHub noreply@github.com Date: Tue, 23 Apr 2024 22:09:36 UTC Commit: de4f029fb23c4058a71db6f05a4c892643a0ec62 https://github.com/geany/geany/commit/de4f029fb23c4058a71db6f05a4c892643a0ec...
Log Message: ----------- Merge pull request #3785 from techee/anon_fix
Rename both scope and var_type of anonymous types
Modified Paths: -------------- src/tagmanager/tm_ctags.c tests/ctags/Makefile.am tests/ctags/nested_anon.c tests/ctags/nested_anon.c.tags tests/meson.build
Modified: src/tagmanager/tm_ctags.c 59 lines changed, 34 insertions(+), 25 deletions(-) =================================================================== @@ -241,6 +241,33 @@ void tm_ctags_clear_ignore_symbols(void) }
+static gboolean replace_str(gchar **where, const gchar *what, guint what_len, + const gchar *replacement, guint replacement_len) +{ + if (where && *where) + { + gchar *pos = strstr(*where, what); + + if (pos) + { + gsize where_len = strlen(*where); + gchar *str = g_malloc(where_len + replacement_len - what_len + 1); + gsize prefix_len = (gsize) (pos - *where); + + strncpy(str, *where, prefix_len); + strcpy(str + prefix_len, replacement); + strcpy(str + prefix_len + replacement_len, pos + what_len); + g_free(*where); + *where = str; + + return TRUE; + } + } + + return FALSE; +} + + /* call after all tags have been collected so we don't have to handle reparses * with the counter (which gets complicated when also subparsers are involved) */ static void rename_anon_tags(TMSourceFile *source_file) @@ -336,7 +363,6 @@ static void rename_anon_tags(TMSourceFile *source_file) { TMTag *nested_tag = TM_TAG(source_file->tags_array->pdata[j]); guint nested_scope_len = nested_tag->scope ? strlen(nested_tag->scope) : 0; - gchar *pos;
/* Tags can be interleaved with scopeless macros - skip those */ if (is_c && nested_tag->type & (tm_tag_macro_t | tm_tag_macro_with_arg_t)) @@ -361,22 +387,14 @@ static void rename_anon_tags(TMSourceFile *source_file) if (nested_scope_len <= scope_len) break;
- pos = strstr(nested_tag->scope, orig_name); /* We found the parent name in the nested tag scope - replace it * with the new name. Note: anonymous tag names generated by * ctags are unique enough that we don't have to check for * scope separators here. */ - if (pos) - { - gchar *str = g_malloc(nested_scope_len + 50); - guint prefix_len = pos - nested_tag->scope; - - strncpy(str, nested_tag->scope, prefix_len); - strcpy(str + prefix_len, new_name); - strcpy(str + prefix_len + new_name_len, pos + orig_name_len); - g_free(nested_tag->scope); - nested_tag->scope = str; - } + replace_str(&nested_tag->scope, orig_name, orig_name_len, new_name, new_name_len); + + /* Do the same for var_type as well */ + replace_str(&nested_tag->var_type, orig_name, orig_name_len, new_name, new_name_len); }
/* We are out of the nesting - the next tags could be variables @@ -385,22 +403,13 @@ static void rename_anon_tags(TMSourceFile *source_file) { TMTag *var_tag = TM_TAG(source_file->tags_array->pdata[j]); guint var_scope_len = var_tag->scope ? strlen(var_tag->scope) : 0; - gchar *pos;
/* Should be at the same scope level as the anon tag */ - if (var_scope_len == scope_len && - var_tag->var_type && (pos = strstr(var_tag->var_type, orig_name))) + if (var_scope_len != scope_len || ! var_tag->var_type || + ! replace_str(&var_tag->var_type, orig_name, orig_name_len, new_name, new_name_len)) { - GString *str = g_string_new(var_tag->var_type); - gssize p = pos - var_tag->var_type; - g_string_erase(str, p, strlen(orig_name)); - g_string_insert(str, p, new_name); - g_free(var_tag->var_type); - var_tag->var_type = str->str; - g_string_free(str, FALSE); - } - else break; + }
j++; }
Modified: tests/ctags/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -252,6 +252,7 @@ test_sources = \ namespace.cpp \ namespaces2.php \ namespaces.php \ + nested_anon.c \ no_terminator.js \ non-ascii-ident1.php \ numlib.f90 \
Modified: tests/ctags/nested_anon.c 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,5 @@ +typedef struct { + struct + { + } __value32; +} __atomic_wide_counter;
Modified: tests/ctags/nested_anon.c.tags 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,6 @@ +__atomic_wide_counter�2048�0 +struct: __atomic_wide_counter +__value32�64�__atomic_wide_counter�0�__atomic_wide_counter::anon_struct_1 +member: __atomic_wide_counter::anon_struct_1 __atomic_wide_counter :: __value32 +anon_struct_1�2048�__atomic_wide_counter�1 +struct: __atomic_wide_counter :: anon_struct_1 flags: 1
Modified: tests/meson.build 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -249,6 +249,7 @@ ctags_tests = files([ 'ctags/namespace.cpp.tags', 'ctags/namespaces2.php.tags', 'ctags/namespaces.php.tags', + 'ctags/nested_anon.c.tags', 'ctags/no_terminator.js.tags', 'ctags/non-ascii-ident1.php.tags', 'ctags/numlib.f90.tags',
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).