Add tm_arglist_compare().

Fix comparison in tm_symbol_tag_compare().


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1197 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-01-16 15:24:01 +00:00
parent 9114f27848
commit 84b941bf63
3 changed files with 26 additions and 6 deletions

View File

@ -4,6 +4,9 @@
Backport improvements from Anjuta 2.02. Backport improvements from Anjuta 2.02.
Parse anonymous struct and enums (using contextual_fake_count). Parse anonymous struct and enums (using contextual_fake_count).
Add better C99 support, e.g. wchar_t variables. Add better C99 support, e.g. wchar_t variables.
* tagmanager/include/tm_symbol.h, tagmanager/tm_symbol.c:
Add tm_arglist_compare().
Fix comparison in tm_symbol_tag_compare().
2007-01-15 Enrico Tröger <enrico.troeger@uvena.de> 2007-01-15 Enrico Tröger <enrico.troeger@uvena.de>

View File

@ -10,6 +10,7 @@
#ifndef TM_SYMBOL_H #ifndef TM_SYMBOL_H
#define TM_SYMBOL_H #define TM_SYMBOL_H
/*! \file /*! \file
The TMSymbol structure and related routines are used by TMProject to maintain a symbol The TMSymbol structure and related routines are used by TMProject to maintain a symbol
hierarchy. The top level TMSymbol maintains a pretty simple hierarchy, consisting of hierarchy. The top level TMSymbol maintains a pretty simple hierarchy, consisting of
@ -60,6 +61,9 @@ tm_symbol_tree_free() and tm_symbol_tree_new().
*/ */
TMSymbol *tm_symbol_tree_update(TMSymbol *root, GPtrArray *tags); TMSymbol *tm_symbol_tree_update(TMSymbol *root, GPtrArray *tags);
/*! Arglist comparison function */
int tm_arglist_compare(const TMTag *t1, const TMTag *t2);
/*! Symbol comparison function - can be used for sorting purposes. */ /*! Symbol comparison function - can be used for sorting purposes. */
int tm_symbol_compare(const void *p1, const void *p2); int tm_symbol_compare(const void *p1, const void *p2);

View File

@ -75,6 +75,16 @@ int tm_symbol_compare(const void *p1, const void *p2)
return strcmp(s1->tag->name, s2->tag->name); return strcmp(s1->tag->name, s2->tag->name);
} }
/*
* Compares function argument lists.
* FIXME: Compare based on types, not an exact string match.
*/
int tm_arglist_compare(const TMTag* t1, const TMTag* t2)
{
return strcmp(NVL(t1->atts.entry.arglist, ""),
NVL(t2->atts.entry.arglist, ""));
}
/* Need this custom compare function to generate a symbol tree /* Need this custom compare function to generate a symbol tree
in a simgle pass from tag list */ in a simgle pass from tag list */
int tm_symbol_tag_compare(const TMTag **t1, const TMTag **t2) int tm_symbol_tag_compare(const TMTag **t1, const TMTag **t2)
@ -120,8 +130,8 @@ int tm_symbol_tag_compare(const TMTag **t1, const TMTag **t2)
/* If none of them are function/prototype, they are effectively equal */ /* If none of them are function/prototype, they are effectively equal */
if ((tm_tag_function_t != (*t1)->type) && if ((tm_tag_function_t != (*t1)->type) &&
(tm_tag_prototype_t != (*t1)->type)&& (tm_tag_prototype_t != (*t1)->type)&&
(tm_tag_function_t != (*t1)->type) && (tm_tag_function_t != (*t2)->type) &&
(tm_tag_prototype_t != (*t1)->type)) (tm_tag_prototype_t != (*t2)->type))
return 0; return 0;
/* Whichever is not a function/prototype goes first */ /* Whichever is not a function/prototype goes first */
@ -133,8 +143,7 @@ int tm_symbol_tag_compare(const TMTag **t1, const TMTag **t2)
return 1; return 1;
/* Compare the argument list */ /* Compare the argument list */
s1 = strcmp(NVL((*t1)->atts.entry.arglist, ""), s1 = tm_arglist_compare(*t1, *t2);
NVL((*t2)->atts.entry.arglist, ""));
if (s1 != 0) if (s1 != 0)
return s1; return s1;
@ -145,7 +154,7 @@ int tm_symbol_tag_compare(const TMTag **t1, const TMTag **t2)
if ((tm_tag_function_t != (*t1)->type) && if ((tm_tag_function_t != (*t1)->type) &&
(tm_tag_function_t == (*t2)->type)) (tm_tag_function_t == (*t2)->type))
return 1; return 1;
/* Give up */ /* Give up */
return 0; return 0;
} }
@ -165,12 +174,14 @@ TMSymbol *tm_symbol_tree_new(GPtrArray *tags_array)
#ifdef TM_DEBUG #ifdef TM_DEBUG
fprintf(stderr, "Dumping all tags..\n"); fprintf(stderr, "Dumping all tags..\n");
tm_tags_array_print(tags_array, stderr); tm_tags_array_print(tags_array, stderr);
#endif #endif
tags = tm_tags_extract(tags_array, tm_tag_max_t); tags = tm_tags_extract(tags_array, tm_tag_max_t);
#ifdef TM_DEBUG #ifdef TM_DEBUG
fprintf(stderr, "Dumping unordered tags..\n"); fprintf(stderr, "Dumping unordered tags..\n");
tm_tags_array_print(tags, stderr); tm_tags_array_print(tags, stderr);
#endif #endif
if (tags && (tags->len > 0)) if (tags && (tags->len > 0))
{ {
guint i; guint i;
@ -186,6 +197,7 @@ TMSymbol *tm_symbol_tree_new(GPtrArray *tags_array)
SYM_NEW(root); SYM_NEW(root);
tm_tags_custom_sort(tags, (TMTagCompareFunc) tm_symbol_tag_compare tm_tags_custom_sort(tags, (TMTagCompareFunc) tm_symbol_tag_compare
, FALSE); , FALSE);
#ifdef TM_DEBUG #ifdef TM_DEBUG
fprintf(stderr, "Dumping ordered tags.."); fprintf(stderr, "Dumping ordered tags..");
tm_tags_array_print(tags, stderr); tm_tags_array_print(tags, stderr);
@ -194,6 +206,7 @@ TMSymbol *tm_symbol_tree_new(GPtrArray *tags_array)
for (i=0; i < tags->len; ++i) for (i=0; i < tags->len; ++i)
{ {
tag = TM_TAG(tags->pdata[i]); tag = TM_TAG(tags->pdata[i]);
if (tm_tag_prototype_t == tag->type) if (tm_tag_prototype_t == tag->type)
{ {
if (sym && (tm_tag_function_t == sym->tag->type) && if (sym && (tm_tag_function_t == sym->tag->type) &&