/* adapted from tm_workspace_find, Anjuta 2.02 */ const GPtrArray * tm_workspace_find_scoped (const char *name, const char *scope, gint type, TMTagAttrType *attrs, gboolean partial, langType lang, gboolean global_search) { static GPtrArray *tags = NULL; if ((!theWorkspace)) return NULL; if (tags) g_ptr_array_set_size (tags, 0); else tags = g_ptr_array_new (); fill_find_tags_array (tags, theWorkspace->work_object.tags_array, name, scope, type, partial, lang, FALSE); if (global_search) { /* for a scoped tag, I think we always want the same language */ fill_find_tags_array (tags, theWorkspace->global_tags, name, scope, type, partial, lang, FALSE); } if (attrs) tm_tags_sort (tags, attrs, TRUE); return tags; }
/* Returns all matching tags found in the workspace. @param name The name of the tag to find. @param scope The scope name of the tag to find, or NULL. @param type The tag types to return (TMTagType). Can be a bitmask. @param attrs The attributes to sort and dedup on (0 terminated integer array). @param lang Specifies the language(see the table in parsers.h) of the tags to be found, -1 for all @return Array of matching tags. */ GPtrArray *tm_workspace_find(const char *name, const char *scope, TMTagType type, TMTagAttrType *attrs, TMParserType lang) { GPtrArray *tags = g_ptr_array_new(); fill_find_tags_array(tags, theWorkspace->tags_array, name, scope, type, lang); fill_find_tags_array(tags, theWorkspace->global_tags, name, scope, type, lang); if (attrs) tm_tags_sort(tags, attrs, TRUE, FALSE); return tags; }
const GPtrArray * tm_workspace_find_namespace_members (const GPtrArray * file_tags, const char *name, gboolean search_global) { 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; 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') { new_name = tag->atts.entry.var_type; continue; } filename = (tag->atts.entry.file ? tag->atts.entry.file->work_object.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 (tag && tag->atts.entry.file) { local = tm_tags_extract (tag->atts.entry.file->work_object.tags_array, (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->work_object.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 )); } if (local) { 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, (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_namespace_t | tm_tag_class_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 ); } /*/ g_ptr_array_free (global, TRUE); } } if (del) { g_free (new_name); } return tags; }
/* 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; guint got = 0; TMTagType 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->var_type && tag->var_type[0] != '\0') { char *tmp_name; tmp_name = tag->var_type; if (strcmp(tmp_name, new_name) == 0) { new_name = NULL; } else { new_name = tmp_name; } continue; } filename = (tag->file ? tag->file->short_name : NULL); if (tag->scope && tag->scope[0] != '\0') { del = 1; if (tag->file && tag->file->lang == langJava) { new_name = g_strdup_printf ("%s.%s", tag->scope, new_name); } else { new_name = g_strdup_printf ("%s::%s", tag->scope, new_name); } } break; } else { return NULL; } } g_ptr_array_set_size (tags, 0); if (no_definitions && tag && tag->file) { local = tm_tags_extract (tag->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; }