From 344eca020474fb3ce948af529c318bd719f09ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Fri, 17 Oct 2014 00:12:54 +0200 Subject: [PATCH] Add #if 0 around unused TM functions and move them to the end of the file Similarly, add #if TM_DEBUG around various unused debugging functions. The #if 0 surrounded functions are good candidate for future removal if decided they are not needed any more. --- tagmanager/src/tm_source_file.c | 69 ++++--- tagmanager/src/tm_source_file.h | 2 - tagmanager/src/tm_tag.c | 4 + tagmanager/src/tm_tag.h | 5 + tagmanager/src/tm_workspace.c | 354 ++++++++++++++++---------------- tagmanager/src/tm_workspace.h | 16 +- 6 files changed, 230 insertions(+), 220 deletions(-) diff --git a/tagmanager/src/tm_source_file.c b/tagmanager/src/tm_source_file.c index 03fe9677..93acb759 100644 --- a/tagmanager/src/tm_source_file.c +++ b/tagmanager/src/tm_source_file.c @@ -465,40 +465,6 @@ void tm_source_file_buffer_update(TMSourceFile *source_file, guchar* text_buf, #endif } - -/* - Writes all tags of a source file (including the file tag itself) to the passed - file pointer. - @param source_file The source file to write. - @param fp The file pointer to write to. - @param attrs The attributes to write. - @return TRUE on success, FALSE on failure. -*/ -gboolean tm_source_file_write(TMSourceFile *source_file, FILE *fp, guint attrs) -{ - TMTag *tag; - guint i; - - if (NULL != source_file) - { - if (NULL != (tag = tm_tag_new(source_file, NULL))) - { - tm_tag_write(tag, fp, tm_tag_attr_max_t); - tm_tag_unref(tag); - if (NULL != source_file->tags_array) - { - for (i=0; i < source_file->tags_array->len; ++i) - { - tag = TM_TAG(source_file->tags_array->pdata[i]); - if (TRUE != tm_tag_write(tag, fp, attrs)) - return FALSE; - } - } - } - } - return TRUE; -} - /* Gets the name associated with the language index. @param lang The language index. @return The language name, or NULL. @@ -534,3 +500,38 @@ gint tm_source_file_get_named_lang(const gchar *name) } return getNamedLanguage(name); } + +#if 0 +/* + Writes all tags of a source file (including the file tag itself) to the passed + file pointer. + @param source_file The source file to write. + @param fp The file pointer to write to. + @param attrs The attributes to write. + @return TRUE on success, FALSE on failure. +*/ +static gboolean tm_source_file_write(TMSourceFile *source_file, FILE *fp, guint attrs) +{ + TMTag *tag; + guint i; + + if (NULL != source_file) + { + if (NULL != (tag = tm_tag_new(source_file, NULL))) + { + tm_tag_write(tag, fp, tm_tag_attr_max_t); + tm_tag_unref(tag); + if (NULL != source_file->tags_array) + { + for (i=0; i < source_file->tags_array->len; ++i) + { + tag = TM_TAG(source_file->tags_array->pdata[i]); + if (TRUE != tm_tag_write(tag, fp, attrs)) + return FALSE; + } + } + } + } + return TRUE; +} +#endif diff --git a/tagmanager/src/tm_source_file.h b/tagmanager/src/tm_source_file.h index dd2ffaab..20dee4cb 100644 --- a/tagmanager/src/tm_source_file.h +++ b/tagmanager/src/tm_source_file.h @@ -69,8 +69,6 @@ gboolean tm_source_file_buffer_parse(TMSourceFile *source_file, guchar* text_buf int tm_source_file_tags(const tagEntryInfo *tag); -gboolean tm_source_file_write(TMSourceFile *source_file, FILE *fp, guint attrs); - const gchar *tm_source_file_get_lang_name(gint lang); gint tm_source_file_get_named_lang(const gchar *name); diff --git a/tagmanager/src/tm_tag.c b/tagmanager/src/tm_tag.c index c6b0136f..54bfb487 100644 --- a/tagmanager/src/tm_tag.c +++ b/tagmanager/src/tm_tag.c @@ -1103,6 +1103,8 @@ TMTag **tm_tags_find(const GPtrArray *tags_array, const char *name, return (TMTag **) result; } +#ifdef TM_DEBUG /* various debugging functions */ + /* Returns the type of tag as a string @param tag The tag whose type is required @@ -1259,3 +1261,5 @@ gint tm_tag_scope_depth(const TMTag *t) } return depth; } + +#endif /* TM_DEBUG */ diff --git a/tagmanager/src/tm_tag.h b/tagmanager/src/tm_tag.h index e1d6888b..5d25fa3e 100644 --- a/tagmanager/src/tm_tag.h +++ b/tagmanager/src/tm_tag.h @@ -208,6 +208,9 @@ void tm_tag_unref(TMTag *tag); TMTag *tm_tag_ref(TMTag *tag); + +#ifdef TM_DEBUG /* various debugging functions */ + const char *tm_tag_type_name(const TMTag *tag); TMTagType tm_tag_name_type(const char* tag_name); @@ -218,6 +221,8 @@ void tm_tags_array_print(GPtrArray *tags, FILE *fp); gint tm_tag_scope_depth(const TMTag *t); +#endif /* TM_DEBUG */ + #endif /* GEANY_PRIVATE */ #ifdef __cplusplus diff --git a/tagmanager/src/tm_workspace.c b/tagmanager/src/tm_workspace.c index 638289fe..d2b31ed8 100644 --- a/tagmanager/src/tm_workspace.c +++ b/tagmanager/src/tm_workspace.c @@ -577,26 +577,6 @@ void tm_workspace_update(void) tm_workspace_recreate_tags_array(); } -/* Dumps the workspace tree - useful for debugging */ -void tm_workspace_dump(void) -{ - if (theWorkspace) - { -#ifdef TM_DEBUG - g_message("Dumping TagManager workspace tree.."); -#endif - if (theWorkspace->source_files) - { - guint i; - for (i=0; i < theWorkspace->source_files->len; ++i) - { - TMSourceFile *source_file = theWorkspace->source_files->pdata[i]; - fprintf(stderr, "%s", source_file->file_name); - } - } - } -} - /* Returns all matching tags found in the workspace. @param name The name of the tag to find. @param type The tag types to return (TMTagType). Can be a bitmask. @@ -810,17 +790,6 @@ tm_get_current_tag (GPtrArray * file_tags, const gulong line, const guint tag_ty } -/* Returns TMTag to function or method which "own" given line - @param line Current line in edited file. - @param file_tags A GPtrArray of edited file TMTag pointers. - @return TMTag pointers to owner function. */ -const TMTag * -tm_get_current_function (GPtrArray * file_tags, const gulong line) -{ - return tm_get_current_tag (file_tags, line, tm_tag_function_t | tm_tag_method_t); -} - - static int find_scope_members_tags (const GPtrArray * all, GPtrArray * tags, const langType langJava, const char *name, @@ -936,8 +905,184 @@ find_scope_members_tags (const GPtrArray * all, GPtrArray * tags, return (int) tags->len; } +/* Returns all matching members tags found in given struct/union/class name. + @param name Name of the struct/union/class. + @param file_tags A GPtrArray of edited file TMTag pointers (for search speedup, can be NULL). + @return A GPtrArray of TMTag pointers to struct/union/class members */ +const GPtrArray * +tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name, + gboolean search_global, gboolean no_definitions) +{ + static GPtrArray *tags = NULL; + GPtrArray *local = NULL; + char *new_name = (char *) name; + char *filename = NULL; + int found = 0, del = 0; + static langType langJava = -1; + TMTag *tag = NULL; + + /* FIXME */ + /* langJava = getNamedLanguage ("Java"); */ + + g_return_val_if_fail ((theWorkspace && name && name[0] != '\0'), NULL); + + if (!tags) + tags = g_ptr_array_new (); + + while (1) + { + const GPtrArray *tags2; + int got = 0, types = (tm_tag_class_t | tm_tag_namespace_t | + tm_tag_struct_t | tm_tag_typedef_t | + tm_tag_union_t | tm_tag_enum_t); + + if (file_tags) + { + g_ptr_array_set_size (tags, 0); + got = fill_find_tags_array (tags, file_tags, + new_name, NULL, types, FALSE, -1, FALSE); + } + if (got) + { + tags2 = tags; + } + else + { + TMTagAttrType attrs[] = { + tm_tag_attr_name_t, tm_tag_attr_type_t, + tm_tag_attr_none_t + }; + tags2 = tm_workspace_find (new_name, types, attrs, FALSE, -1); + } + + if ((tags2) && (tags2->len == 1) && (tag = TM_TAG (tags2->pdata[0]))) + { + if (tag->type == tm_tag_typedef_t && tag->atts.entry.var_type + && tag->atts.entry.var_type[0] != '\0') + { + char *tmp_name; + tmp_name = tag->atts.entry.var_type; + if (strcmp(tmp_name, new_name) == 0) { + new_name = NULL; + } + else { + new_name = tmp_name; + } + continue; + } + filename = (tag->atts.entry.file ? + tag->atts.entry.file->short_name : NULL); + if (tag->atts.entry.scope && tag->atts.entry.scope[0] != '\0') + { + del = 1; + if (tag->atts.entry.file && + tag->atts.entry.file->lang == langJava) + { + new_name = g_strdup_printf ("%s.%s", + tag->atts.entry.scope, + new_name); + } + else + { + new_name = g_strdup_printf ("%s::%s", + tag->atts.entry.scope, + new_name); + } + } + break; + } + else + { + return NULL; + } + } + + g_ptr_array_set_size (tags, 0); + + if (no_definitions && tag && tag->atts.entry.file) + { + local = tm_tags_extract (tag->atts.entry.file->tags_array, + (tm_tag_function_t | tm_tag_prototype_t | + tm_tag_member_t | tm_tag_field_t | + tm_tag_method_t | tm_tag_enumerator_t)); + } + else + { + local = tm_tags_extract (theWorkspace->tags_array, + (tm_tag_function_t | tm_tag_prototype_t | + tm_tag_member_t | tm_tag_field_t | + tm_tag_method_t | tm_tag_enumerator_t)); + } + if (local) + { + found = find_scope_members_tags (local, tags, langJava, new_name, + filename, no_definitions); + g_ptr_array_free (local, TRUE); + } + if (!found && search_global) + { + GPtrArray *global = tm_tags_extract (theWorkspace->global_tags, + (tm_tag_member_t | + tm_tag_prototype_t | + tm_tag_field_t | + tm_tag_method_t | + tm_tag_function_t | + tm_tag_enumerator_t + |tm_tag_struct_t | tm_tag_typedef_t | + tm_tag_union_t | tm_tag_enum_t)); + if (global) + { + find_scope_members_tags (global, tags, langJava, new_name, + filename, no_definitions); + g_ptr_array_free (global, TRUE); + } + } + if (del) + { + g_free (new_name); + } + + return tags; +} + + +#ifdef TM_DEBUG + +/* Dumps the workspace tree - useful for debugging */ +void tm_workspace_dump(void) +{ + if (theWorkspace) + { +#ifdef TM_DEBUG + g_message("Dumping TagManager workspace tree.."); +#endif + if (theWorkspace->source_files) + { + guint i; + for (i=0; i < theWorkspace->source_files->len; ++i) + { + TMSourceFile *source_file = theWorkspace->source_files->pdata[i]; + fprintf(stderr, "%s", source_file->file_name); + } + } + } +} +#endif /* TM_DEBUG */ + #if 0 + +/* Returns TMTag to function or method which "own" given line + @param line Current line in edited file. + @param file_tags A GPtrArray of edited file TMTag pointers. + @return TMTag pointers to owner function. */ +static const TMTag * +tm_get_current_function (GPtrArray * file_tags, const gulong line) +{ + return tm_get_current_tag (file_tags, line, tm_tag_function_t | tm_tag_method_t); +} + + static int find_namespace_members_tags (const GPtrArray * all, GPtrArray * tags, const langType langJava, const char *name, @@ -994,7 +1139,7 @@ find_namespace_members_tags (const GPtrArray * all, GPtrArray * tags, return (int) tags->len; } -const GPtrArray * +static const GPtrArray * tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *name, gboolean search_global) { @@ -1138,152 +1283,11 @@ tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *na return tags; } -#endif - -/* Returns all matching members tags found in given struct/union/class name. - @param name Name of the struct/union/class. - @param file_tags A GPtrArray of edited file TMTag pointers (for search speedup, can be NULL). - @return A GPtrArray of TMTag pointers to struct/union/class members */ -const GPtrArray * -tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name, - gboolean search_global, gboolean no_definitions) -{ - static GPtrArray *tags = NULL; - GPtrArray *local = NULL; - char *new_name = (char *) name; - char *filename = NULL; - int found = 0, del = 0; - static langType langJava = -1; - TMTag *tag = NULL; - - /* FIXME */ - /* langJava = getNamedLanguage ("Java"); */ - - g_return_val_if_fail ((theWorkspace && name && name[0] != '\0'), NULL); - - if (!tags) - tags = g_ptr_array_new (); - - while (1) - { - const GPtrArray *tags2; - int got = 0, types = (tm_tag_class_t | tm_tag_namespace_t | - tm_tag_struct_t | tm_tag_typedef_t | - tm_tag_union_t | tm_tag_enum_t); - - if (file_tags) - { - g_ptr_array_set_size (tags, 0); - got = fill_find_tags_array (tags, file_tags, - new_name, NULL, types, FALSE, -1, FALSE); - } - if (got) - { - tags2 = tags; - } - else - { - TMTagAttrType attrs[] = { - tm_tag_attr_name_t, tm_tag_attr_type_t, - tm_tag_attr_none_t - }; - tags2 = tm_workspace_find (new_name, types, attrs, FALSE, -1); - } - - if ((tags2) && (tags2->len == 1) && (tag = TM_TAG (tags2->pdata[0]))) - { - if (tag->type == tm_tag_typedef_t && tag->atts.entry.var_type - && tag->atts.entry.var_type[0] != '\0') - { - char *tmp_name; - tmp_name = tag->atts.entry.var_type; - if (strcmp(tmp_name, new_name) == 0) { - new_name = NULL; - } - else { - new_name = tmp_name; - } - continue; - } - filename = (tag->atts.entry.file ? - tag->atts.entry.file->short_name : NULL); - if (tag->atts.entry.scope && tag->atts.entry.scope[0] != '\0') - { - del = 1; - if (tag->atts.entry.file && - tag->atts.entry.file->lang == langJava) - { - new_name = g_strdup_printf ("%s.%s", - tag->atts.entry.scope, - new_name); - } - else - { - new_name = g_strdup_printf ("%s::%s", - tag->atts.entry.scope, - new_name); - } - } - break; - } - else - { - return NULL; - } - } - - g_ptr_array_set_size (tags, 0); - - if (no_definitions && tag && tag->atts.entry.file) - { - local = tm_tags_extract (tag->atts.entry.file->tags_array, - (tm_tag_function_t | tm_tag_prototype_t | - tm_tag_member_t | tm_tag_field_t | - tm_tag_method_t | tm_tag_enumerator_t)); - } - else - { - local = tm_tags_extract (theWorkspace->tags_array, - (tm_tag_function_t | tm_tag_prototype_t | - tm_tag_member_t | tm_tag_field_t | - tm_tag_method_t | tm_tag_enumerator_t)); - } - if (local) - { - found = find_scope_members_tags (local, tags, langJava, new_name, - filename, no_definitions); - g_ptr_array_free (local, TRUE); - } - if (!found && search_global) - { - GPtrArray *global = tm_tags_extract (theWorkspace->global_tags, - (tm_tag_member_t | - tm_tag_prototype_t | - tm_tag_field_t | - tm_tag_method_t | - tm_tag_function_t | - tm_tag_enumerator_t - |tm_tag_struct_t | tm_tag_typedef_t | - tm_tag_union_t | tm_tag_enum_t)); - if (global) - { - find_scope_members_tags (global, tags, langJava, new_name, - filename, no_definitions); - g_ptr_array_free (global, TRUE); - } - } - if (del) - { - g_free (new_name); - } - - return tags; -} /* Returns a list of parent classes for the given class name @param name Name of the class @return A GPtrArray of TMTag pointers (includes the TMTag for the class) */ -const GPtrArray *tm_workspace_get_parents(const gchar *name) +static const GPtrArray *tm_workspace_get_parents(const gchar *name) { static TMTagAttrType type[] = { tm_tag_attr_name_t, tm_tag_attr_none_t }; static GPtrArray *parents = NULL; @@ -1330,3 +1334,5 @@ const GPtrArray *tm_workspace_get_parents(const gchar *name) } return parents; } + +#endif diff --git a/tagmanager/src/tm_workspace.h b/tagmanager/src/tm_workspace.h index 9956e2db..780f02cb 100644 --- a/tagmanager/src/tm_workspace.h +++ b/tagmanager/src/tm_workspace.h @@ -52,8 +52,6 @@ gboolean tm_workspace_create_global_tags(const char *pre_process, const char **i void tm_workspace_recreate_tags_array(void); -void tm_workspace_dump(void); - const GPtrArray *tm_workspace_find(const char *name, int type, TMTagAttrType *attrs , gboolean partial, langType lang); @@ -66,22 +64,20 @@ const GPtrArray *tm_workspace_find_scope_members(const GPtrArray *file_tags, gboolean find_global, gboolean no_definitions); -const GPtrArray * -tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *name, - gboolean search_global); - const TMTag *tm_get_current_tag(GPtrArray *file_tags, const gulong line, const guint tag_types); -const TMTag *tm_get_current_function(GPtrArray *file_tags, const gulong line); - -const GPtrArray *tm_workspace_get_parents(const gchar *name); - void tm_workspace_free(void); void tm_workspace_merge_file_tags(TMSourceFile *source_file); void tm_workspace_remove_file_tags(TMSourceFile *source_file); + +#ifdef TM_DEBUG +void tm_workspace_dump(void); +#endif /* TM_DEBUG */ + + #endif /* GEANY_PRIVATE */ #ifdef __cplusplus