[geany/geany] 344eca: Add #if 0 around unused TM functions and move them to the end of the file

Jiří Techet git-noreply at xxxxx
Sat Nov 8 18:57:54 UTC 2014


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Sat, 18 Oct 2014 19:40:10 UTC
Commit:      344eca020474fb3ce948af529c318bd719f09ba9
             https://github.com/geany/geany/commit/344eca020474fb3ce948af529c318bd719f09ba9

Log Message:
-----------
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.


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

Modified: tagmanager/src/tm_source_file.c
69 lines changed, 35 insertions(+), 34 deletions(-)
===================================================================
@@ -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


Modified: tagmanager/src/tm_source_file.h
2 lines changed, 0 insertions(+), 2 deletions(-)
===================================================================
@@ -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);


Modified: tagmanager/src/tm_tag.c
4 lines changed, 4 insertions(+), 0 deletions(-)
===================================================================
@@ -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 */


Modified: tagmanager/src/tm_tag.h
5 lines changed, 5 insertions(+), 0 deletions(-)
===================================================================
@@ -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


Modified: tagmanager/src/tm_workspace.c
318 lines changed, 162 insertions(+), 156 deletions(-)
===================================================================
@@ -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,67 +905,13 @@ find_scope_members_tags (const GPtrArray * all, GPtrArray * tags,
 	return (int) tags->len;
 }
 
-
-#if 0
-static int
-find_namespace_members_tags (const GPtrArray * all, GPtrArray * tags,
-						 	const langType langJava, const char *name,
-						 	const char *filename)
-{
-	GPtrArray *local = g_ptr_array_new ();
-	unsigned int i;
-	TMTag *tag;
-	size_t len = strlen (name);
-
-	g_return_val_if_fail (all != NULL, 0);
-
-	for (i = 0; (i < all->len); ++i)
-	{
-		tag = TM_TAG (all->pdata[i]);
-		if (filename && tag->atts.entry.file &&
-			0 != strcmp (filename,
-						 tag->atts.entry.file->short_name))
-		{
-			continue;
-		}
-
-		if (tag && tag->atts.entry.scope && tag->atts.entry.scope[0] != '\0')
-		{
-			if (0 == strncmp (name, tag->atts.entry.scope, len))
-			{
-				g_ptr_array_add (local, tag);
-			}
-		}
-	}
-
-	if (local->len > 0)
-	{
-		char *scope;
-		for (i = 0; (i < local->len); ++i)
-		{
-			tag = TM_TAG (local->pdata[i]);
-			scope = tag->atts.entry.scope;
-
-			/* if we wanna complete something like
-			 * namespace1::
-			 * we'll just return the tags that have "namespace1"
-			 * as their scope. So we won't return classes/members/namespaces
-			 * under, for example, namespace2, where namespace1::namespace2
-			 */
-			if (scope && 0 == strcmp (name, scope))
-			{
-				g_ptr_array_add (tags, tag);
-			}
-		}
-	}
-
-	g_ptr_array_free (local, TRUE);
-	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_namespace_members (const GPtrArray * file_tags, const char *name,
-								 gboolean search_global)
+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;
@@ -1006,6 +921,9 @@ tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *na
 	static langType langJava = -1;
 	TMTag *tag = NULL;
 
+	/* FIXME */
+	/* langJava = getNamedLanguage ("Java"); */
+
 	g_return_val_if_fail ((theWorkspace && name && name[0] != '\0'), NULL);
 
 	if (!tags)
@@ -1024,8 +942,6 @@ tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *na
 			got = fill_find_tags_array (tags, file_tags,
 										  new_name, NULL, types, FALSE, -1, FALSE);
 		}
-
-
 		if (got)
 		{
 			tags2 = tags;
@@ -1044,7 +960,14 @@ tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *na
 			if (tag->type == tm_tag_typedef_t && tag->atts.entry.var_type
 				&& tag->atts.entry.var_type[0] != '\0')
 			{
-				new_name = tag->atts.entry.var_type;
+				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 ?
@@ -1076,30 +999,26 @@ tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *na
 
 	g_ptr_array_set_size (tags, 0);
 
-	if (tag && tag->atts.entry.file)
+	if (no_definitions && tag && tag->atts.entry.file)
 	{
 		local = tm_tags_extract (tag->atts.entry.file->tags_array,
-								 (tm_tag_function_t |
-								  tm_tag_field_t | tm_tag_enumerator_t |
-								  tm_tag_namespace_t | tm_tag_class_t ));
+								 (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_enumerator_t |
-								  tm_tag_namespace_t | tm_tag_class_t ));
+								  tm_tag_member_t | tm_tag_field_t |
+								  tm_tag_method_t | tm_tag_enumerator_t));
 	}
-
 	if (local)
 	{
-		found = find_namespace_members_tags (local, tags,
-										 langJava, new_name, filename);
+		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,
@@ -1108,29 +1027,16 @@ tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *na
 											  tm_tag_field_t |
 											  tm_tag_method_t |
 											  tm_tag_function_t |
-											  tm_tag_enumerator_t |
-											  tm_tag_namespace_t |
-											  tm_tag_class_t ));
-
+											  tm_tag_enumerator_t
+											  |tm_tag_struct_t | tm_tag_typedef_t |
+											  tm_tag_union_t | tm_tag_enum_t));
 		if (global)
 		{
-			find_namespace_members_tags (global, tags, langJava,
-									 new_name, filename);
-/*/
-			DEBUG_PRINT ("returning these");
-  		    gint i;
-			for (i=0; i < tags->len; i++) {
-				TMTag *cur_tag;
-
-				cur_tag = (TMTag*)g_ptr_array_index (tags, i);
-				tm_tag_print (cur_tag, stdout );
-			}
-/*/
+			find_scope_members_tags (global, tags, langJava, new_name,
+									 filename, no_definitions);
 			g_ptr_array_free (global, TRUE);
 		}
 	}
-
-
 	if (del)
 	{
 		g_free (new_name);
@@ -1138,15 +1044,104 @@ tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *na
 
 	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 */
 
-/* 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)
+
+#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,
+						 	const char *filename)
+{
+	GPtrArray *local = g_ptr_array_new ();
+	unsigned int i;
+	TMTag *tag;
+	size_t len = strlen (name);
+
+	g_return_val_if_fail (all != NULL, 0);
+
+	for (i = 0; (i < all->len); ++i)
+	{
+		tag = TM_TAG (all->pdata[i]);
+		if (filename && tag->atts.entry.file &&
+			0 != strcmp (filename,
+						 tag->atts.entry.file->short_name))
+		{
+			continue;
+		}
+
+		if (tag && tag->atts.entry.scope && tag->atts.entry.scope[0] != '\0')
+		{
+			if (0 == strncmp (name, tag->atts.entry.scope, len))
+			{
+				g_ptr_array_add (local, tag);
+			}
+		}
+	}
+
+	if (local->len > 0)
+	{
+		char *scope;
+		for (i = 0; (i < local->len); ++i)
+		{
+			tag = TM_TAG (local->pdata[i]);
+			scope = tag->atts.entry.scope;
+
+			/* if we wanna complete something like
+			 * namespace1::
+			 * we'll just return the tags that have "namespace1"
+			 * as their scope. So we won't return classes/members/namespaces
+			 * under, for example, namespace2, where namespace1::namespace2
+			 */
+			if (scope && 0 == strcmp (name, scope))
+			{
+				g_ptr_array_add (tags, tag);
+			}
+		}
+	}
+
+	g_ptr_array_free (local, TRUE);
+	return (int) tags->len;
+}
+
+static const GPtrArray *
+tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *name,
+								 gboolean search_global)
 {
 	static GPtrArray *tags = NULL;
 	GPtrArray *local = NULL;
@@ -1156,9 +1151,6 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
 	static langType langJava = -1;
 	TMTag *tag = NULL;
 
-	/* FIXME */
-	/* langJava = getNamedLanguage ("Java"); */
-
 	g_return_val_if_fail ((theWorkspace && name && name[0] != '\0'), NULL);
 
 	if (!tags)
@@ -1177,6 +1169,8 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
 			got = fill_find_tags_array (tags, file_tags,
 										  new_name, NULL, types, FALSE, -1, FALSE);
 		}
+
+
 		if (got)
 		{
 			tags2 = tags;
@@ -1195,14 +1189,7 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
 			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;
-				}
+				new_name = tag->atts.entry.var_type;
 				continue;
 			}
 			filename = (tag->atts.entry.file ?
@@ -1234,26 +1221,30 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
 
 	g_ptr_array_set_size (tags, 0);
 
-	if (no_definitions && tag && tag->atts.entry.file)
+	if (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));
+								 (tm_tag_function_t |
+								  tm_tag_field_t | tm_tag_enumerator_t |
+								  tm_tag_namespace_t | tm_tag_class_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));
+								  tm_tag_member_t |
+								  tm_tag_field_t | tm_tag_enumerator_t |
+								  tm_tag_namespace_t | tm_tag_class_t ));
 	}
+
 	if (local)
 	{
-		found = find_scope_members_tags (local, tags, langJava, new_name,
-										 filename, no_definitions);
+		found = find_namespace_members_tags (local, tags,
+										 langJava, new_name, filename);
 		g_ptr_array_free (local, TRUE);
 	}
+
+
 	if (!found && search_global)
 	{
 		GPtrArray *global = tm_tags_extract (theWorkspace->global_tags,
@@ -1262,16 +1253,29 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
 											  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));
+											  tm_tag_enumerator_t |
+											  tm_tag_namespace_t |
+											  tm_tag_class_t ));
+
 		if (global)
 		{
-			find_scope_members_tags (global, tags, langJava, new_name,
-									 filename, no_definitions);
+			find_namespace_members_tags (global, tags, langJava,
+									 new_name, filename);
+/*/
+			DEBUG_PRINT ("returning these");
+  		    gint i;
+			for (i=0; i < tags->len; i++) {
+				TMTag *cur_tag;
+
+				cur_tag = (TMTag*)g_ptr_array_index (tags, i);
+				tm_tag_print (cur_tag, stdout );
+			}
+/*/
 			g_ptr_array_free (global, TRUE);
 		}
 	}
+
+
 	if (del)
 	{
 		g_free (new_name);
@@ -1283,7 +1287,7 @@ tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
 /* 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


Modified: tagmanager/src/tm_workspace.h
16 lines changed, 6 insertions(+), 10 deletions(-)
===================================================================
@@ -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



--------------
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