[geany/geany] 1de139: Improve ctags callback API

Jiří Techet git-noreply at xxxxx
Fri Jun 10 21:57:19 UTC 2016


Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Mon, 21 Mar 2016 17:28:36 UTC
Commit:      1de139854f4ba791fc7fce8358490cec90e695d3
             https://github.com/geany/geany/commit/1de139854f4ba791fc7fce8358490cec90e695d3

Log Message:
-----------
Improve ctags callback API

Communicate with ctags only using function calls and don't assign
ctags variables directly.


Modified Paths:
--------------
    tagmanager/ctags/entry.c
    tagmanager/ctags/parse.c
    tagmanager/ctags/parse.h
    tagmanager/src/tm_source_file.c

Modified: tagmanager/ctags/entry.c
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -393,7 +393,7 @@ extern void makeTagEntry (const tagEntryInfo *const tag)
 	int length = 0;
 
 	if (NULL != TagEntryFunction)
-		length = TagEntryFunction(tag);
+		length = TagEntryFunction(tag, TagEntryUserData);
 
 	++TagFile.numTags.added;
 	rememberMaxLengths (strlen (tag->name), (size_t) length);


Modified: tagmanager/ctags/parse.c
8 lines changed, 8 insertions(+), 0 deletions(-)
===================================================================
@@ -33,11 +33,19 @@ static parserDefinitionFunc* BuiltInParsers[] = { PARSER_LIST };
 parserDefinition** LanguageTable = NULL;
 static unsigned int LanguageCount = 0;
 tagEntryFunction TagEntryFunction = NULL;
+void *TagEntryUserData = NULL;
 
 /*
 *   FUNCTION DEFINITIONS
 */
 
+extern void setTagEntryFunction(tagEntryFunction entry_function, void *user_data)
+{
+    TagEntryFunction = entry_function;
+    TagEntryUserData = user_data;
+}
+
+
 extern void makeSimpleTag (const vString* const name,
 			   kindOption* const kinds, const int kind)
 {


Modified: tagmanager/ctags/parse.h
5 lines changed, 3 insertions(+), 2 deletions(-)
===================================================================
@@ -36,7 +36,7 @@ typedef void (*createRegexTag) (const vString* const name);
 typedef void (*simpleParser) (void);
 typedef boolean (*rescanParser) (const unsigned int passCount);
 typedef void (*parserInitialize) (langType language);
-typedef int (*tagEntryFunction) (const tagEntryInfo *const tag);
+typedef int (*tagEntryFunction) (const tagEntryInfo *const tag, void *user_data);
 
 typedef struct sKindOption {
     boolean enabled;			/* are tags for kind enabled? */
@@ -128,7 +128,8 @@ extern void checkRegex (void);
 
 /* Extra stuff for Tag Manager */
 extern tagEntryFunction TagEntryFunction;
-extern void setTagEntryFunction(tagEntryFunction entry_function);
+extern void *TagEntryUserData;
+extern void setTagEntryFunction(tagEntryFunction entry_function, void *user_data);
 
 #endif	/* _PARSE_H */
 


Modified: tagmanager/src/tm_source_file.c
15 lines changed, 5 insertions(+), 10 deletions(-)
===================================================================
@@ -45,8 +45,6 @@ typedef struct
 #define SOURCE_FILE_NEW(S) ((S) = g_slice_new(TMSourceFilePriv))
 #define SOURCE_FILE_FREE(S) g_slice_free(TMSourceFilePriv, (TMSourceFilePriv *) S)
 
-static TMSourceFile *current_source_file = NULL;
-
 static int get_path_max(const char *path)
 {
 #ifdef PATH_MAX
@@ -110,7 +108,7 @@ gchar *tm_get_real_path(const gchar *file_name)
 }
 
 /* add argument list of __init__() Python methods to the class tag */
-static void update_python_arglist(const TMTag *tag)
+static void update_python_arglist(const TMTag *tag, TMSourceFile *current_source_file)
 {
 	guint i;
 	const char *parent_tag_name;
@@ -144,15 +142,13 @@ static void update_python_arglist(const TMTag *tag)
  it finds a new tag. You should not have to use this function.
  @see tm_source_file_parse()
 */
-static int tm_source_file_tags(const tagEntryInfo *tag)
+static int tm_source_file_tags(const tagEntryInfo *tag, void *user_data)
 {
-	if (NULL == current_source_file)
-		return 0;
-
+	TMSourceFile *current_source_file = user_data;
 	TMTag *tm_tag = tm_tag_new(current_source_file, tag);
 
 	if (tm_tag->lang == TM_PARSER_PYTHON)
-		update_python_arglist(tm_tag);
+		update_python_arglist(tm_tag, current_source_file);
 
 	g_ptr_array_add(current_source_file->tags_array, tm_tag);
 
@@ -163,7 +159,6 @@ void tm_source_file_ctags_init()
 {
 	initializeParsing();
 	installLanguageMapDefaults();
-	TagEntryFunction = tm_source_file_tags;
 }
 
 /* Initializes a TMSourceFile structure from a file name. */
@@ -340,7 +335,6 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize
 		return TRUE;
 	}
 
-	current_source_file = source_file;
 	if (! LanguageTable [source_file->lang]->enabled)
 	{
 #ifdef TM_DEBUG
@@ -349,6 +343,7 @@ gboolean tm_source_file_parse(TMSourceFile *source_file, guchar* text_buf, gsize
 	}
 	else
 	{
+		setTagEntryFunction(tm_source_file_tags, source_file);
 		guint passCount = 0;
 		while (retry && passCount < 3)
 		{



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