1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (c) 2001-2002, Biswapesh Chattopadhyay
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
13 /* #include <libanjuta/anjuta-debug.h> */
19 #include <sys/types.h>
25 #include "tm_workspace.h"
26 #include "tm_project.h"
29 static TMWorkspace
*theWorkspace
= NULL
;
30 guint workspace_class_id
= 0;
33 tm_create_workspace (void)
35 char *file_name
= g_strdup_printf ("%s/anjuta_%ld.%d",
36 P_tmpdir
, time (NULL
), getpid ());
38 g_message ("Workspace created: %s", file_name
);
41 workspace_class_id
= tm_work_object_register (tm_workspace_free
,
43 tm_workspace_find_object
);
44 theWorkspace
= g_new (TMWorkspace
, 1);
45 if (FALSE
== tm_work_object_init (TM_WORK_OBJECT (theWorkspace
),
46 workspace_class_id
, file_name
, TRUE
))
49 g_free (theWorkspace
);
51 g_warning ("Failed to initialize workspace");
56 theWorkspace
->global_tags
= NULL
;
57 theWorkspace
->work_objects
= NULL
;
62 tm_workspace_free (gpointer workspace
)
66 if (workspace
!= theWorkspace
)
70 g_message ("Workspace destroyed");
75 if (theWorkspace
->work_objects
)
77 for (i
= 0; i
< theWorkspace
->work_objects
->len
; ++i
)
78 tm_work_object_free (theWorkspace
->work_objects
->pdata
[i
]);
79 g_ptr_array_free (theWorkspace
->work_objects
, TRUE
);
81 if (theWorkspace
->global_tags
)
83 for (i
= 0; i
< theWorkspace
->global_tags
->len
; ++i
)
84 tm_tag_free (theWorkspace
->global_tags
->pdata
[i
]);
85 g_ptr_array_free (theWorkspace
->global_tags
, TRUE
);
86 tm_tag_chunk_clean ();
88 unlink (theWorkspace
->work_object
.file_name
);
89 tm_work_object_destroy (TM_WORK_OBJECT (theWorkspace
));
90 g_free (theWorkspace
);
96 tm_get_workspace (void)
98 if (NULL
== theWorkspace
)
99 tm_create_workspace ();
104 tm_workspace_add_object (TMWorkObject
* work_object
)
106 if (NULL
== theWorkspace
)
107 tm_create_workspace ();
108 if (NULL
== theWorkspace
->work_objects
)
109 theWorkspace
->work_objects
= g_ptr_array_new ();
110 g_ptr_array_add (theWorkspace
->work_objects
, work_object
);
111 work_object
->parent
= TM_WORK_OBJECT (theWorkspace
);
116 tm_workspace_remove_object (TMWorkObject
* w
, gboolean free
)
119 if ((NULL
== theWorkspace
) || (NULL
== theWorkspace
->work_objects
)
122 for (i
= 0; i
< theWorkspace
->work_objects
->len
; ++i
)
124 if (theWorkspace
->work_objects
->pdata
[i
] == w
)
127 tm_work_object_free (w
);
128 g_ptr_array_remove_index_fast (theWorkspace
->work_objects
, i
);
129 tm_workspace_update (TM_WORK_OBJECT (theWorkspace
), TRUE
,
138 tm_workspace_load_tags (GPtrArray
* array
, const char *tags_file
)
144 if (NULL
== (fp
= fopen (tags_file
, "r")))
149 tags
= g_ptr_array_new ();
150 while (NULL
!= (tag
= tm_tag_new_from_file (NULL
, fp
)))
151 g_ptr_array_add (tags
, tag
);
157 tm_workspace_load_global_tags (const char *tags_file
)
159 if (NULL
== theWorkspace
)
160 tm_create_workspace ();
161 if (NULL
== theWorkspace
->global_tags
)
163 theWorkspace
->global_tags
= tm_workspace_load_tags (NULL
, tags_file
);
164 if (theWorkspace
->global_tags
)
171 if (tm_workspace_load_tags (theWorkspace
->global_tags
, tags_file
))
179 tm_workspace_reload_global_tags (const char *tags_file
)
182 if (NULL
== theWorkspace
)
183 tm_create_workspace ();
185 if (theWorkspace
->global_tags
)
187 for (i
= 0; i
< theWorkspace
->global_tags
->len
; ++i
)
188 tm_tag_free (theWorkspace
->global_tags
->pdata
[i
]);
189 g_ptr_array_free (theWorkspace
->global_tags
, TRUE
);
190 tm_tag_chunk_clean ();
193 theWorkspace
->global_tags
= tm_workspace_load_tags (NULL
, tags_file
);
194 if (theWorkspace
->global_tags
)
201 tm_file_inode_hash (gconstpointer key
)
203 struct stat file_stat
;
204 const char *filename
= (const char *) key
;
205 if (stat (filename
, &file_stat
) == 0)
208 g_message ("Hash for '%s' is '%d'\n", filename
, file_stat
.st_ino
);
210 return g_direct_hash (GUINT_TO_POINTER (file_stat
.st_ino
));
219 tm_move_entries_to_g_list (gpointer key
, gpointer value
, gpointer user_data
)
221 if (user_data
== NULL
)
224 GList
**pp_list
= (GList
**) user_data
;
226 *pp_list
= g_list_prepend (*pp_list
, value
);
230 tm_workspace_create_global_tags (const char *pre_process
, const char **includes
,
231 int includes_count
, const char *tags_file
)
239 TMWorkObject
*source_file
;
240 GPtrArray
*tags_array
;
241 GHashTable
*includes_files_hash
;
242 GList
*includes_files
= NULL
;
244 char *temp_file
= g_strdup_printf ("%s/%d_%ld_1.cpp", P_tmpdir
, getpid (),
246 char *temp_file2
= g_strdup_printf ("%s/%d_%ld_2.cpp", P_tmpdir
, getpid (),
248 TMTagAttrType sort_attrs
[] = {
249 tm_tag_attr_name_t
, tm_tag_attr_scope_t
,
250 tm_tag_attr_type_t
, 0
253 if (NULL
== (fp
= fopen (temp_file
, "w")))
257 includes_files_hash
= g_hash_table_new_full (tm_file_inode_hash
,
258 g_direct_equal
, NULL
, g_free
);
260 for (idx_inc
= 0; idx_inc
< includes_count
; idx_inc
++)
262 int dirty_len
= strlen (includes
[idx_inc
]);
263 char *clean_path
= malloc (dirty_len
- 1);
264 strncpy (clean_path
, includes
[idx_inc
] + 1, dirty_len
- 1);
265 clean_path
[dirty_len
- 2] = 0;
268 g_message ("[o][%s]\n", clean_path
);
270 glob (clean_path
, 0, NULL
, &globbuf
);
273 g_message ("matches: %d\n", globbuf
.gl_pathc
);
276 for (idx_glob
= 0; idx_glob
< globbuf
.gl_pathc
; idx_glob
++)
279 g_message (">>> %s\n", globbuf
.gl_pathv
[idx_glob
]);
281 if (!g_hash_table_lookup (includes_files_hash
,
282 globbuf
.gl_pathv
[idx_glob
]))
284 char *file_name_copy
= strdup (globbuf
.gl_pathv
[idx_glob
]);
285 g_hash_table_insert (includes_files_hash
, file_name_copy
,
288 g_message ("Added ...\n");
296 /* Checks for duplicate file entries which would case trouble */
297 g_hash_table_foreach (includes_files_hash
, tm_move_entries_to_g_list
,
300 includes_files
= g_list_reverse (includes_files
);
303 g_message ("writing out files to %s\n", temp_file
);
305 node
= includes_files
;
308 char *str
= g_strdup_printf ("#include \"%s\"\n", (char *) node
->data
);
309 int str_len
= strlen (str
);
311 fwrite (str
, str_len
, 1, fp
);
313 node
= g_list_next (node
);
316 g_list_free (includes_files
);
317 g_hash_table_destroy (includes_files_hash
);
318 includes_files_hash
= NULL
;
319 includes_files
= NULL
;
322 /* FIXME: The following grep command it be remove the lines
323 * G_BEGIN_DECLS and G_END_DECLS from the header files. The reason is
324 * that in tagmanager, the files are not correctly parsed and the typedefs
325 * following these lines are incorrectly parsed. The real fix should,
326 * of course be in tagmanager (c) parser. This is just a temporary fix.
330 ("%s %s | grep -v -E '^\\s*(G_BEGIN_DECLS|G_END_DECLS)\\s*$' > %s",
331 pre_process
, temp_file
, temp_file2
);
334 g_message ("Executing: %s", command
);
341 source_file
= tm_source_file_new (temp_file2
, TRUE
);
342 if (NULL
== source_file
)
349 if ((NULL
== source_file
->tags_array
) ||
350 (0 == source_file
->tags_array
->len
))
352 tm_source_file_free (source_file
);
356 * tags_array = tm_tags_extract(source_file->tags_array, tm_tag_class_t |
357 * tm_tag_typedef_t | tm_tag_prototype_t |
358 * tm_tag_enum_t | tm_tag_macro_with_arg_t);
360 tags_array
= tm_tags_extract (source_file
->tags_array
, tm_tag_max_t
);
362 if ((NULL
== tags_array
) || (0 == tags_array
->len
))
365 g_ptr_array_free (tags_array
, TRUE
);
366 tm_source_file_free (source_file
);
369 if (FALSE
== tm_tags_sort (tags_array
, sort_attrs
, TRUE
))
371 tm_source_file_free (source_file
);
374 if (NULL
== (fp
= fopen (tags_file
, "w")))
376 tm_source_file_free (source_file
);
379 for (i
= 0; i
< tags_array
->len
; ++i
)
382 * tm_tag_write(TM_TAG(tags_array->pdata[i]), fp,
383 * (tm_tag_attr_type_t | tm_tag_attr_scope_t |
384 * tm_tag_attr_arglist_t | tm_tag_attr_vartype_t |
385 * tm_tag_attr_pointer_t));
387 tm_tag_write (TM_TAG (tags_array
->pdata
[i
]), fp
, tm_tag_max_t
);
390 tm_source_file_free (source_file
);
391 g_ptr_array_free (tags_array
, TRUE
);
396 str_has_suffix (const char *haystack
, const char *needle
)
404 if (haystack
== NULL
)
406 return needle
[0] == '\0';
409 /* Eat one character at a time. */
410 h
= haystack
+ strlen (haystack
);
411 n
= needle
+ strlen (needle
);
423 while (*--h
== *--n
);
427 /* Merges a set of tags files. Note that the passed files are gzipped files */
429 tm_workspace_merge_global_tags (const gchar
* output_file
, GList
* tag_files
)
434 GPtrArray
*merged_tags
, *dedupped_tags
;
435 TMTagAttrType sort_attrs
[] = {
436 tm_tag_attr_name_t
, tm_tag_attr_scope_t
,
437 tm_tag_attr_type_t
, 0
440 if (!tag_files
|| !output_file
)
443 merged_tags
= g_ptr_array_sized_new (15000);
449 if (str_has_suffix ((const char *) node
->data
, ".gz"))
452 temp_file
= g_strdup_printf ("%s/%d_%ld_1.anjutatags",
453 P_tmpdir
, getpid (), time (NULL
));
454 command
= g_strdup_printf ("gunzip -c '%s' > %s",
455 (const char *) node
->data
, temp_file
);
458 tm_workspace_load_tags (merged_tags
, temp_file
);
464 tm_workspace_load_tags (merged_tags
, (const char *) node
->data
);
466 node
= g_list_next (node
);
468 if (merged_tags
->len
<= 0)
470 g_ptr_array_free (merged_tags
, TRUE
);
475 dedupped_tags
= tm_tags_extract (merged_tags
, tm_tag_attr_max_t
);
477 if (FALSE
== tm_tags_sort (dedupped_tags
, sort_attrs
, TRUE
))
479 g_ptr_array_free (dedupped_tags
, TRUE
);
480 tm_tags_array_free (merged_tags
, TRUE
);
481 tm_tag_chunk_clean ();
485 /* Save the output */
486 if (NULL
== (fp
= fopen (output_file
, "w")))
488 g_ptr_array_free (dedupped_tags
, TRUE
);
489 tm_tags_array_free (merged_tags
, TRUE
);
490 tm_tag_chunk_clean ();
493 for (i
= 0; i
< dedupped_tags
->len
; ++i
)
495 tm_tag_write (TM_TAG (dedupped_tags
->pdata
[i
]), fp
,
496 (tm_tag_attr_type_t
| tm_tag_attr_scope_t
|
497 tm_tag_attr_arglist_t
| tm_tag_attr_vartype_t
|
498 tm_tag_attr_pointer_t
));
501 g_ptr_array_free (dedupped_tags
, TRUE
);
502 tm_tags_array_free (merged_tags
, TRUE
);
503 tm_tag_chunk_clean ();
508 tm_workspace_find_object (TMWorkObject
* work_object
, const char *file_name
,
511 TMWorkObject
*w
= NULL
;
514 if (work_object
!= TM_WORK_OBJECT (theWorkspace
))
516 if ((NULL
== theWorkspace
) || (NULL
== theWorkspace
->work_objects
)
517 || (0 == theWorkspace
->work_objects
->len
))
519 for (i
= 0; i
< theWorkspace
->work_objects
->len
; ++i
)
523 tm_work_object_find (TM_WORK_OBJECT
524 (theWorkspace
->work_objects
->pdata
[i
]),
525 file_name
, name_only
)))
532 tm_workspace_recreate_tags_array (void)
536 TMTagAttrType sort_attrs
[] =
537 { tm_tag_attr_name_t
, tm_tag_attr_file_t
, tm_tag_attr_scope_t
,
538 tm_tag_attr_type_t
, 0
542 g_message ("Recreating workspace tags array");
545 if ((NULL
== theWorkspace
) || (NULL
== theWorkspace
->work_objects
))
547 if (NULL
!= theWorkspace
->work_object
.tags_array
)
548 g_ptr_array_set_size (theWorkspace
->work_object
.tags_array
, 0);
550 theWorkspace
->work_object
.tags_array
= g_ptr_array_new ();
553 g_message ("Total %d objects", theWorkspace
->work_objects
->len
);
555 for (i
= 0; i
< theWorkspace
->work_objects
->len
; ++i
)
557 w
= TM_WORK_OBJECT (theWorkspace
->work_objects
->pdata
[i
]);
559 g_message ("Adding tags of %s", w
->file_name
);
561 if ((NULL
!= w
) && (NULL
!= w
->tags_array
) && (w
->tags_array
->len
> 0))
563 for (j
= 0; j
< w
->tags_array
->len
; ++j
)
565 g_ptr_array_add (theWorkspace
->work_object
.tags_array
,
566 w
->tags_array
->pdata
[j
]);
571 g_message ("Total: %d tags", theWorkspace
->work_object
.tags_array
->len
);
573 tm_tags_sort (theWorkspace
->work_object
.tags_array
, sort_attrs
, TRUE
);
577 tm_workspace_update (TMWorkObject
* workspace
, gboolean force
,
578 gboolean recurse
, gboolean __unused__ update_parent
)
581 gboolean update_tags
= force
;
584 g_message ("Updating workspace");
587 if (workspace
!= TM_WORK_OBJECT (theWorkspace
))
589 if (NULL
== theWorkspace
)
591 if ((recurse
) && (theWorkspace
->work_objects
))
593 for (i
= 0; i
< theWorkspace
->work_objects
->len
; ++i
)
596 tm_work_object_update (TM_WORK_OBJECT
597 (theWorkspace
->work_objects
->pdata
[i
]),
603 tm_workspace_recreate_tags_array ();
604 workspace
->analyze_time
= time (NULL
);
609 tm_workspace_dump (void)
614 g_message ("Dumping TagManager workspace tree..");
616 tm_work_object_dump (TM_WORK_OBJECT (theWorkspace
));
617 if (theWorkspace
->work_objects
)
620 for (i
= 0; i
< theWorkspace
->work_objects
->len
; ++i
)
623 (TM_WORK_OBJECT (theWorkspace
->work_objects
->pdata
[i
])))
624 tm_project_dump (TM_PROJECT
625 (theWorkspace
->work_objects
->pdata
[i
]));
627 tm_work_object_dump (TM_WORK_OBJECT
628 (theWorkspace
->work_objects
->
636 fill_find_tags_array (GPtrArray
* dst
, const GPtrArray
* src
,
637 const char *name
, int type
, gboolean partial
,
644 if ((!src
) || (!dst
))
649 /* Simply copy all src tags to dst tags */
651 for (i
= 0; i
< src
->len
; i
++)
653 if (TM_TAG (src
->pdata
[i
])->type
& type
)
655 g_ptr_array_add (dst
, src
->pdata
[i
]);
669 match
= tm_tags_find (src
, name
, partial
, &count
);
670 if (count
&& match
&& *match
)
672 for (tagIter
= 0; tagIter
< count
; ++tagIter
)
674 if (type
& match
[tagIter
]->type
)
676 g_ptr_array_add (dst
, match
[tagIter
]);
682 if (0 != strncmp (match
[tagIter
]->name
, name
, len
))
687 if (0 != strcmp (match
[tagIter
]->name
, name
))
697 tm_workspace_find (const char *name
, int type
, TMTagAttrType
* attrs
,
698 gboolean partial
, gboolean global_search
)
700 static GPtrArray
*tags
= NULL
;
706 g_ptr_array_set_size (tags
, 0);
708 tags
= g_ptr_array_new ();
710 fill_find_tags_array (tags
, theWorkspace
->work_object
.tags_array
,
711 name
, type
, partial
, TRUE
);
714 fill_find_tags_array (tags
, theWorkspace
->global_tags
,
715 name
, type
, partial
, TRUE
);
718 tm_tags_sort (tags
, attrs
, TRUE
);
723 tm_get_current_function (GPtrArray
* file_tags
, const gulong line
)
725 GPtrArray
*const local
= tm_tags_extract (file_tags
, tm_tag_function_t
);
726 if (local
&& local
->len
)
729 TMTag
*tag
, *function_tag
= NULL
;
730 gulong function_line
= 0;
733 for (i
= 0; (i
< local
->len
); ++i
)
735 tag
= TM_TAG (local
->pdata
[i
]);
736 delta
= line
- tag
->atts
.entry
.line
;
737 if (delta
>= 0 && delta
< line
- function_line
)
740 function_line
= tag
->atts
.entry
.line
;
743 g_ptr_array_free (local
, TRUE
);
750 find_scope_members_tags (const GPtrArray
* all
, GPtrArray
* tags
,
751 const langType langJava
, const char *name
,
752 const char *filename
, gboolean no_definitions
)
754 GPtrArray
*local
= g_ptr_array_new ();
757 size_t len
= strlen (name
);
758 for (i
= 0; (i
< all
->len
); ++i
)
760 tag
= TM_TAG (all
->pdata
[i
]);
761 if (no_definitions
&& filename
&& tag
->atts
.entry
.file
&&
762 0 != strcmp (filename
,
763 tag
->atts
.entry
.file
->work_object
.short_name
))
767 if (tag
&& tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
769 if (0 == strncmp (name
, tag
->atts
.entry
.scope
, len
))
771 g_ptr_array_add (local
, tag
);
780 char *s_backup
= NULL
;
781 char *var_type
= NULL
;
783 for (i
= 0; (i
< local
->len
); ++i
)
785 tag
= TM_TAG (local
->pdata
[i
]);
786 scope
= tag
->atts
.entry
.scope
;
787 if (scope
&& 0 == strcmp (name
, scope
))
789 g_ptr_array_add (tags
, tag
);
793 j
= 0; /* someone could write better code :P */
798 backup
= s_backup
[0];
800 if (0 == strcmp (name
, tag
->atts
.entry
.scope
))
803 s_backup
[0] = backup
;
807 if (tag
->atts
.entry
.file
808 && tag
->atts
.entry
.file
->lang
== langJava
)
810 scope
= strrchr (tag
->atts
.entry
.scope
, '.');
812 var_type
= scope
+ 1;
816 scope
= strrchr (tag
->atts
.entry
.scope
, ':');
819 var_type
= scope
+ 1;
825 s_backup
[0] = backup
;
831 backup
= s_backup
[0];
834 for (j
= 0; (j
< local
->len
); ++j
)
838 tag2
= TM_TAG (local
->pdata
[j
]);
839 if (tag2
->atts
.entry
.type_ref
[1] &&
840 0 == strcmp (var_type
, tag2
->atts
.entry
.type_ref
[1]))
846 s_backup
[0] = backup
;
856 g_ptr_array_add (tags
, tag
);
860 g_ptr_array_free (local
, TRUE
);
861 return (int) tags
->len
;
866 find_namespace_members_tags (const GPtrArray
* all
, GPtrArray
* tags
,
867 const langType langJava
, const char *name
,
868 const char *filename
)
870 GPtrArray
*local
= g_ptr_array_new ();
873 size_t len
= strlen (name
);
875 g_return_val_if_fail (all
!= NULL
, 0);
877 for (i
= 0; (i
< all
->len
); ++i
)
879 tag
= TM_TAG (all
->pdata
[i
]);
880 if (filename
&& tag
->atts
.entry
.file
&&
881 0 != strcmp (filename
,
882 tag
->atts
.entry
.file
->work_object
.short_name
))
887 if (tag
&& tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
889 if (0 == strncmp (name
, tag
->atts
.entry
.scope
, len
))
891 g_ptr_array_add (local
, tag
);
899 for (i
= 0; (i
< local
->len
); ++i
)
901 tag
= TM_TAG (local
->pdata
[i
]);
902 scope
= tag
->atts
.entry
.scope
;
904 /* if we wanna complete something like
906 * we'll just return the tags that have "namespace1"
907 * as their scope. So we won't return classes/members/namespaces
908 * under, for example, namespace2, where namespace1::namespace2
910 if (scope
&& 0 == strcmp (name
, scope
))
912 g_ptr_array_add (tags
, tag
);
917 g_ptr_array_free (local
, TRUE
);
918 return (int) tags
->len
;
922 tm_workspace_find_namespace_members (const GPtrArray
* file_tags
, const char *name
,
923 gboolean search_global
)
925 static GPtrArray
*tags
= NULL
;
926 GPtrArray
*local
= NULL
;
927 char *new_name
= (char *) name
;
928 char *filename
= NULL
;
929 int found
= 0, del
= 0;
930 static langType langJava
= -1;
933 g_return_val_if_fail ((theWorkspace
&& name
&& name
[0] != '\0'), NULL
);
936 tags
= g_ptr_array_new ();
940 const GPtrArray
*tags2
;
941 int found
= 0, types
= (tm_tag_class_t
| tm_tag_namespace_t
|
942 tm_tag_struct_t
| tm_tag_typedef_t
|
943 tm_tag_union_t
| tm_tag_enum_t
);
947 g_ptr_array_set_size (tags
, 0);
948 found
= fill_find_tags_array (tags
, file_tags
,
949 new_name
, types
, FALSE
, FALSE
);
959 TMTagAttrType attrs
[] = {
960 tm_tag_attr_name_t
, tm_tag_attr_type_t
,
963 tags2
= tm_workspace_find (new_name
, types
, attrs
, FALSE
, TRUE
);
966 if ((tags2
) && (tags2
->len
== 1) && (tag
= TM_TAG (tags2
->pdata
[0])))
968 if (tag
->type
== tm_tag_typedef_t
&& tag
->atts
.entry
.type_ref
[1]
969 && tag
->atts
.entry
.type_ref
[1][0] != '\0')
971 new_name
= tag
->atts
.entry
.type_ref
[1];
974 filename
= (tag
->atts
.entry
.file
?
975 tag
->atts
.entry
.file
->work_object
.short_name
: NULL
);
976 if (tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
979 if (tag
->atts
.entry
.file
&&
980 tag
->atts
.entry
.file
->lang
== langJava
)
982 new_name
= g_strdup_printf ("%s.%s",
983 tag
->atts
.entry
.scope
,
988 new_name
= g_strdup_printf ("%s::%s",
989 tag
->atts
.entry
.scope
,
1001 g_ptr_array_set_size (tags
, 0);
1003 if (tag
&& tag
->atts
.entry
.file
)
1005 local
= tm_tags_extract (tag
->atts
.entry
.file
->work_object
.tags_array
,
1006 (tm_tag_function_t
|
1007 tm_tag_field_t
| tm_tag_enumerator_t
|
1008 tm_tag_namespace_t
| tm_tag_class_t
));
1012 local
= tm_tags_extract (theWorkspace
->work_object
.tags_array
,
1013 (tm_tag_function_t
| tm_tag_prototype_t
|
1015 tm_tag_field_t
| tm_tag_enumerator_t
|
1016 tm_tag_namespace_t
| tm_tag_class_t
));
1021 found
= find_namespace_members_tags (local
, tags
,
1022 langJava
, new_name
, filename
);
1023 g_ptr_array_free (local
, TRUE
);
1027 if (!found
&& search_global
)
1029 GPtrArray
*global
= tm_tags_extract (theWorkspace
->global_tags
,
1031 tm_tag_prototype_t
|
1035 tm_tag_enumerator_t
|
1036 tm_tag_namespace_t
|
1041 find_namespace_members_tags (global
, tags
, langJava
,
1042 new_name
, filename
);
1044 DEBUG_PRINT ("returning these");
1046 for (i=0; i < tags->len; i++) {
1049 cur_tag = (TMTag*)g_ptr_array_index (tags, i);
1050 tm_tag_print (cur_tag, stdout );
1053 g_ptr_array_free (global, TRUE);
1067 tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
1068 gboolean search_global, gboolean no_definitions)
1070 static GPtrArray *tags = NULL;
1071 GPtrArray *local = NULL;
1072 char *new_name = (char *) name;
1073 char *filename = NULL;
1074 int found = 0, del = 0;
1075 static langType langJava = -1;
1079 /* langJava = getNamedLanguage ("Java"); */
1081 g_return_val_if_fail ((theWorkspace
&& name
&& name
[0] != '\0'), NULL
);
1084 tags
= g_ptr_array_new ();
1088 const GPtrArray
*tags2
;
1089 int found
= 0, types
= (tm_tag_class_t
| tm_tag_namespace_t
|
1090 tm_tag_struct_t
| tm_tag_typedef_t
|
1091 tm_tag_union_t
| tm_tag_enum_t
);
1095 g_ptr_array_set_size (tags
, 0);
1096 found
= fill_find_tags_array (tags
, file_tags
,
1097 new_name
, types
, FALSE
, FALSE
);
1105 TMTagAttrType attrs
[] = {
1106 tm_tag_attr_name_t
, tm_tag_attr_type_t
,
1109 tags2
= tm_workspace_find (new_name
, types
, attrs
, FALSE
, TRUE
);
1112 if ((tags2
) && (tags2
->len
== 1) && (tag
= TM_TAG (tags2
->pdata
[0])))
1114 if (tag
->type
== tm_tag_typedef_t
&& tag
->atts
.entry
.type_ref
[1]
1115 && tag
->atts
.entry
.type_ref
[1][0] != '\0')
1118 tmp_name
= tag
->atts
.entry
.type_ref
[1];
1119 if (strcmp(tmp_name
, new_name
) == 0) {
1123 new_name
= tmp_name
;
1127 filename
= (tag
->atts
.entry
.file
?
1128 tag
->atts
.entry
.file
->work_object
.short_name
: NULL
);
1129 if (tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
1132 if (tag
->atts
.entry
.file
&&
1133 tag
->atts
.entry
.file
->lang
== langJava
)
1135 new_name
= g_strdup_printf ("%s.%s",
1136 tag
->atts
.entry
.scope
,
1141 new_name
= g_strdup_printf ("%s::%s",
1142 tag
->atts
.entry
.scope
,
1154 g_ptr_array_set_size (tags
, 0);
1156 if (no_definitions
&& tag
&& tag
->atts
.entry
.file
)
1158 local
= tm_tags_extract (tag
->atts
.entry
.file
->work_object
.tags_array
,
1159 (tm_tag_function_t
| tm_tag_prototype_t
|
1160 tm_tag_member_t
| tm_tag_field_t
|
1161 tm_tag_method_t
| tm_tag_enumerator_t
));
1165 local
= tm_tags_extract (theWorkspace
->work_object
.tags_array
,
1166 (tm_tag_function_t
| tm_tag_prototype_t
|
1167 tm_tag_member_t
| tm_tag_field_t
|
1168 tm_tag_method_t
| tm_tag_enumerator_t
));
1172 found
= find_scope_members_tags (local
, tags
, langJava
, new_name
,
1173 filename
, no_definitions
);
1174 g_ptr_array_free (local
, TRUE
);
1176 if (!found
&& search_global
)
1178 GPtrArray
*global
= tm_tags_extract (theWorkspace
->global_tags
,
1180 tm_tag_prototype_t
|
1185 |tm_tag_struct_t
| tm_tag_typedef_t
|
1186 tm_tag_union_t
| tm_tag_enum_t
));
1189 find_scope_members_tags (global
, tags
, langJava
, new_name
,
1190 filename
, no_definitions
);
1191 g_ptr_array_free (global
, TRUE
);
1203 tm_workspace_get_parents (const gchar
* name
)
1205 static TMTagAttrType type
[] = { tm_tag_attr_name_t
, tm_tag_attr_none_t
};
1206 static GPtrArray
*parents
= NULL
;
1207 const GPtrArray
*matches
;
1214 g_return_val_if_fail (name
&& isalpha (*name
), NULL
);
1216 if (NULL
== parents
)
1217 parents
= g_ptr_array_new ();
1219 g_ptr_array_set_size (parents
, 0);
1220 matches
= tm_workspace_find (name
, tm_tag_class_t
, type
, FALSE
, TRUE
);
1221 if ((NULL
== matches
) || (0 == matches
->len
))
1223 g_ptr_array_add (parents
, matches
->pdata
[0]);
1224 while (i
< parents
->len
)
1226 tag
= TM_TAG (parents
->pdata
[i
]);
1227 if ((NULL
!= tag
->atts
.entry
.inheritance
) &&
1228 (isalpha (tag
->atts
.entry
.inheritance
[0])))
1230 klasses
= g_strsplit (tag
->atts
.entry
.inheritance
, ",", 10);
1231 for (klass
= klasses
; (NULL
!= *klass
); ++klass
)
1233 for (j
= 0; j
< parents
->len
; ++j
)
1235 if (0 == strcmp (*klass
, TM_TAG (parents
->pdata
[j
])->name
))
1238 if (parents
->len
== j
)
1240 matches
= tm_workspace_find (*klass
, tm_tag_class_t
,
1242 if ((NULL
!= matches
) && (0 < matches
->len
))
1243 g_ptr_array_add (parents
, matches
->pdata
[0]);
1246 g_strfreev (klasses
);