From 84b941bf630ec6eb0810d8b16b8ba6b135f95ad9 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 16 Jan 2007 15:24:01 +0000 Subject: [PATCH] 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 --- ChangeLog | 3 +++ tagmanager/include/tm_symbol.h | 4 ++++ tagmanager/tm_symbol.c | 25 +++++++++++++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9f08fe68..b5d0572c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ Backport improvements from Anjuta 2.02. Parse anonymous struct and enums (using contextual_fake_count). 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 diff --git a/tagmanager/include/tm_symbol.h b/tagmanager/include/tm_symbol.h index db5c9224..e6207d3f 100644 --- a/tagmanager/include/tm_symbol.h +++ b/tagmanager/include/tm_symbol.h @@ -10,6 +10,7 @@ #ifndef TM_SYMBOL_H #define TM_SYMBOL_H + /*! \file 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 @@ -60,6 +61,9 @@ tm_symbol_tree_free() and tm_symbol_tree_new(). */ 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. */ int tm_symbol_compare(const void *p1, const void *p2); diff --git a/tagmanager/tm_symbol.c b/tagmanager/tm_symbol.c index 9310fcfc..015f9623 100644 --- a/tagmanager/tm_symbol.c +++ b/tagmanager/tm_symbol.c @@ -75,6 +75,16 @@ int tm_symbol_compare(const void *p1, const void *p2) 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 in a simgle pass from tag list */ 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 ((tm_tag_function_t != (*t1)->type) && (tm_tag_prototype_t != (*t1)->type)&& - (tm_tag_function_t != (*t1)->type) && - (tm_tag_prototype_t != (*t1)->type)) + (tm_tag_function_t != (*t2)->type) && + (tm_tag_prototype_t != (*t2)->type)) return 0; /* 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; /* Compare the argument list */ - s1 = strcmp(NVL((*t1)->atts.entry.arglist, ""), - NVL((*t2)->atts.entry.arglist, "")); + s1 = tm_arglist_compare(*t1, *t2); if (s1 != 0) return s1; @@ -145,7 +154,7 @@ int tm_symbol_tag_compare(const TMTag **t1, const TMTag **t2) if ((tm_tag_function_t != (*t1)->type) && (tm_tag_function_t == (*t2)->type)) return 1; - + /* Give up */ return 0; } @@ -165,12 +174,14 @@ TMSymbol *tm_symbol_tree_new(GPtrArray *tags_array) #ifdef TM_DEBUG fprintf(stderr, "Dumping all tags..\n"); tm_tags_array_print(tags_array, stderr); -#endif +#endif + tags = tm_tags_extract(tags_array, tm_tag_max_t); #ifdef TM_DEBUG fprintf(stderr, "Dumping unordered tags..\n"); tm_tags_array_print(tags, stderr); #endif + if (tags && (tags->len > 0)) { guint i; @@ -186,6 +197,7 @@ TMSymbol *tm_symbol_tree_new(GPtrArray *tags_array) SYM_NEW(root); tm_tags_custom_sort(tags, (TMTagCompareFunc) tm_symbol_tag_compare , FALSE); + #ifdef TM_DEBUG fprintf(stderr, "Dumping ordered tags.."); 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) { tag = TM_TAG(tags->pdata[i]); + if (tm_tag_prototype_t == tag->type) { if (sym && (tm_tag_function_t == sym->tag->type) &&