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
]);
668 match
= tm_tags_find (src
, name
, partial
, &count
);
669 if (count
&& match
&& *match
)
671 for (tagIter
= 0; tagIter
< count
; ++tagIter
)
673 if (type
& match
[tagIter
]->type
)
675 g_ptr_array_add (dst
, match
[tagIter
]);
681 if (0 != strncmp (match
[tagIter
]->name
, name
, len
))
686 if (0 != strcmp (match
[tagIter
]->name
, name
))
696 tm_workspace_find (const char *name
, int type
, TMTagAttrType
* attrs
,
697 gboolean partial
, gboolean global_search
)
699 static GPtrArray
*tags
= NULL
;
705 g_ptr_array_set_size (tags
, 0);
707 tags
= g_ptr_array_new ();
709 fill_find_tags_array (tags
, theWorkspace
->work_object
.tags_array
,
710 name
, type
, partial
, TRUE
);
713 fill_find_tags_array (tags
, theWorkspace
->global_tags
,
714 name
, type
, partial
, TRUE
);
717 tm_tags_sort (tags
, attrs
, TRUE
);
722 tm_get_current_function (GPtrArray
* file_tags
, const gulong line
)
724 GPtrArray
*const local
= tm_tags_extract (file_tags
, tm_tag_function_t
);
725 if (local
&& local
->len
)
728 TMTag
*tag
, *function_tag
= NULL
;
729 gulong function_line
= 0;
732 for (i
= 0; (i
< local
->len
); ++i
)
734 tag
= TM_TAG (local
->pdata
[i
]);
735 delta
= line
- tag
->atts
.entry
.line
;
736 if (delta
>= 0 && delta
< line
- function_line
)
739 function_line
= tag
->atts
.entry
.line
;
742 g_ptr_array_free (local
, TRUE
);
749 find_scope_members_tags (const GPtrArray
* all
, GPtrArray
* tags
,
750 const langType langJava
, const char *name
,
751 const char *filename
)
753 GPtrArray
*local
= g_ptr_array_new ();
756 size_t len
= strlen (name
);
757 for (i
= 0; (i
< all
->len
); ++i
)
759 tag
= TM_TAG (all
->pdata
[i
]);
760 if (filename
&& tag
->atts
.entry
.file
&&
761 0 != strcmp (filename
,
762 tag
->atts
.entry
.file
->work_object
.short_name
))
766 if (tag
&& tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
768 if (0 == strncmp (name
, tag
->atts
.entry
.scope
, len
))
770 g_ptr_array_add (local
, tag
);
779 char *s_backup
= NULL
;
780 char *var_type
= NULL
;
782 for (i
= 0; (i
< local
->len
); ++i
)
784 tag
= TM_TAG (local
->pdata
[i
]);
785 scope
= tag
->atts
.entry
.scope
;
786 if (scope
&& 0 == strcmp (name
, scope
))
788 g_ptr_array_add (tags
, tag
);
792 j
= 0; /* someone could write better code :P */
797 backup
= s_backup
[0];
799 if (0 == strcmp (name
, tag
->atts
.entry
.scope
))
802 s_backup
[0] = backup
;
806 if (tag
->atts
.entry
.file
807 && tag
->atts
.entry
.file
->lang
== langJava
)
809 scope
= strrchr (tag
->atts
.entry
.scope
, '.');
811 var_type
= scope
+ 1;
815 scope
= strrchr (tag
->atts
.entry
.scope
, ':');
818 var_type
= scope
+ 1;
824 s_backup
[0] = backup
;
830 backup
= s_backup
[0];
833 for (j
= 0; (j
< local
->len
); ++j
)
837 tag2
= TM_TAG (local
->pdata
[j
]);
838 if (tag2
->atts
.entry
.type_ref
[1] &&
839 0 == strcmp (var_type
, tag2
->atts
.entry
.type_ref
[1]))
845 s_backup
[0] = backup
;
855 g_ptr_array_add (tags
, tag
);
859 g_ptr_array_free (local
, TRUE
);
860 return (int) tags
->len
;
865 find_namespace_members_tags (const GPtrArray
* all
, GPtrArray
* tags
,
866 const langType langJava
, const char *name
,
867 const char *filename
)
869 GPtrArray
*local
= g_ptr_array_new ();
872 size_t len
= strlen (name
);
874 g_return_val_if_fail (all
!= NULL
, 0);
876 for (i
= 0; (i
< all
->len
); ++i
)
878 tag
= TM_TAG (all
->pdata
[i
]);
879 if (filename
&& tag
->atts
.entry
.file
&&
880 0 != strcmp (filename
,
881 tag
->atts
.entry
.file
->work_object
.short_name
))
886 if (tag
&& tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
888 if (0 == strncmp (name
, tag
->atts
.entry
.scope
, len
))
890 g_ptr_array_add (local
, tag
);
898 for (i
= 0; (i
< local
->len
); ++i
)
900 tag
= TM_TAG (local
->pdata
[i
]);
901 scope
= tag
->atts
.entry
.scope
;
903 /* if we wanna complete something like
905 * we'll just return the tags that have "namespace1"
906 * as their scope. So we won't return classes/members/namespaces
907 * under, for example, namespace2, where namespace1::namespace2
909 if (scope
&& 0 == strcmp (name
, scope
))
911 g_ptr_array_add (tags
, tag
);
916 g_ptr_array_free (local
, TRUE
);
917 return (int) tags
->len
;
921 tm_workspace_find_namespace_members (const GPtrArray
* file_tags
, const char *name
,
922 gboolean search_global
)
924 static GPtrArray
*tags
= NULL
;
925 GPtrArray
*local
= NULL
;
926 char *new_name
= (char *) name
;
927 char *filename
= NULL
;
928 int found
= 0, del
= 0;
929 static langType langJava
= -1;
932 g_return_val_if_fail ((theWorkspace
&& name
&& name
[0] != '\0'), NULL
);
935 tags
= g_ptr_array_new ();
939 const GPtrArray
*tags2
;
940 int found
= 0, types
= (tm_tag_class_t
| tm_tag_namespace_t
|
941 tm_tag_struct_t
| tm_tag_typedef_t
|
942 tm_tag_union_t
| tm_tag_enum_t
);
946 g_ptr_array_set_size (tags
, 0);
947 found
= fill_find_tags_array (tags
, file_tags
,
948 new_name
, types
, FALSE
, FALSE
);
958 TMTagAttrType attrs
[] = {
959 tm_tag_attr_name_t
, tm_tag_attr_type_t
,
962 tags2
= tm_workspace_find (new_name
, types
, attrs
, FALSE
, TRUE
);
965 if ((tags2
) && (tags2
->len
== 1) && (tag
= TM_TAG (tags2
->pdata
[0])))
967 if (tag
->type
== tm_tag_typedef_t
&& tag
->atts
.entry
.type_ref
[1]
968 && tag
->atts
.entry
.type_ref
[1][0] != '\0')
970 new_name
= tag
->atts
.entry
.type_ref
[1];
973 filename
= (tag
->atts
.entry
.file
?
974 tag
->atts
.entry
.file
->work_object
.short_name
: NULL
);
975 if (tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
978 if (tag
->atts
.entry
.file
&&
979 tag
->atts
.entry
.file
->lang
== langJava
)
981 new_name
= g_strdup_printf ("%s.%s",
982 tag
->atts
.entry
.scope
,
987 new_name
= g_strdup_printf ("%s::%s",
988 tag
->atts
.entry
.scope
,
1000 g_ptr_array_set_size (tags
, 0);
1002 if (tag
&& tag
->atts
.entry
.file
)
1004 local
= tm_tags_extract (tag
->atts
.entry
.file
->work_object
.tags_array
,
1005 (tm_tag_function_t
|
1006 tm_tag_field_t
| tm_tag_enumerator_t
|
1007 tm_tag_namespace_t
| tm_tag_class_t
));
1011 local
= tm_tags_extract (theWorkspace
->work_object
.tags_array
,
1012 (tm_tag_function_t
| tm_tag_prototype_t
|
1014 tm_tag_field_t
| tm_tag_enumerator_t
|
1015 tm_tag_namespace_t
| tm_tag_class_t
));
1020 found
= find_namespace_members_tags (local
, tags
,
1021 langJava
, new_name
, filename
);
1022 g_ptr_array_free (local
, TRUE
);
1026 if (!found
&& search_global
)
1028 GPtrArray
*global
= tm_tags_extract (theWorkspace
->global_tags
,
1030 tm_tag_prototype_t
|
1034 tm_tag_enumerator_t
|
1035 tm_tag_namespace_t
|
1040 find_namespace_members_tags (global
, tags
, langJava
,
1041 new_name
, filename
);
1043 DEBUG_PRINT ("returning these");
1045 for (i=0; i < tags->len; i++) {
1048 cur_tag = (TMTag*)g_ptr_array_index (tags, i);
1049 tm_tag_print (cur_tag, stdout );
1052 g_ptr_array_free (global, TRUE);
1068 tm_workspace_find_scope_members (const GPtrArray * file_tags, const char *name,
1069 gboolean search_global)
1071 static GPtrArray *tags = NULL;
1072 GPtrArray *local = NULL;
1073 char *new_name = (char *) name;
1074 char *filename = NULL;
1075 int found = 0, del = 0;
1076 static langType langJava = -1;
1080 /* langJava = getNamedLanguage ("Java"); */
1082 g_return_val_if_fail ((theWorkspace
&& name
&& name
[0] != '\0'), NULL
);
1085 tags
= g_ptr_array_new ();
1089 const GPtrArray
*tags2
;
1090 int found
= 0, types
= (tm_tag_class_t
| tm_tag_namespace_t
|
1091 tm_tag_struct_t
| tm_tag_typedef_t
|
1092 tm_tag_union_t
| tm_tag_enum_t
);
1096 g_ptr_array_set_size (tags
, 0);
1097 found
= fill_find_tags_array (tags
, file_tags
,
1098 new_name
, types
, FALSE
, FALSE
);
1106 TMTagAttrType attrs
[] = {
1107 tm_tag_attr_name_t
, tm_tag_attr_type_t
,
1110 tags2
= tm_workspace_find (new_name
, types
, attrs
, FALSE
, TRUE
);
1113 if ((tags2
) && (tags2
->len
== 1) && (tag
= TM_TAG (tags2
->pdata
[0])))
1115 if (tag
->type
== tm_tag_typedef_t
&& tag
->atts
.entry
.type_ref
[1]
1116 && tag
->atts
.entry
.type_ref
[1][0] != '\0')
1119 tmp_name
= tag
->atts
.entry
.type_ref
[1];
1120 if (strcmp(tmp_name
, new_name
) == 0) {
1124 new_name
= tmp_name
;
1128 filename
= (tag
->atts
.entry
.file
?
1129 tag
->atts
.entry
.file
->work_object
.short_name
: NULL
);
1130 if (tag
->atts
.entry
.scope
&& tag
->atts
.entry
.scope
[0] != '\0')
1133 if (tag
->atts
.entry
.file
&&
1134 tag
->atts
.entry
.file
->lang
== langJava
)
1136 new_name
= g_strdup_printf ("%s.%s",
1137 tag
->atts
.entry
.scope
,
1142 new_name
= g_strdup_printf ("%s::%s",
1143 tag
->atts
.entry
.scope
,
1155 g_ptr_array_set_size (tags
, 0);
1157 if (tag
&& tag
->atts
.entry
.file
)
1159 local
= tm_tags_extract (tag
->atts
.entry
.file
->work_object
.tags_array
,
1160 (tm_tag_function_t
| tm_tag_prototype_t
|
1161 tm_tag_member_t
| tm_tag_field_t
|
1162 tm_tag_method_t
| tm_tag_enumerator_t
));
1166 local
= tm_tags_extract (theWorkspace
->work_object
.tags_array
,
1167 (tm_tag_function_t
| tm_tag_prototype_t
|
1168 tm_tag_member_t
| tm_tag_field_t
|
1169 tm_tag_method_t
| tm_tag_enumerator_t
));
1173 found
= find_scope_members_tags (local
, tags
,
1174 langJava
, new_name
, filename
);
1175 g_ptr_array_free (local
, TRUE
);
1177 if (!found
&& search_global
)
1179 GPtrArray
*global
= tm_tags_extract (theWorkspace
->global_tags
,
1181 tm_tag_prototype_t
|
1188 |tm_tag_struct_t
| tm_tag_typedef_t
|
1189 tm_tag_union_t
| tm_tag_enum_t
));
1192 find_scope_members_tags (global
, tags
, langJava
,
1193 new_name
, filename
);
1194 g_ptr_array_free (global
, TRUE
);
1206 tm_workspace_get_parents (const gchar
* name
)
1208 static TMTagAttrType type
[] = { tm_tag_attr_name_t
, tm_tag_attr_none_t
};
1209 static GPtrArray
*parents
= NULL
;
1210 const GPtrArray
*matches
;
1217 g_return_val_if_fail (name
&& isalpha (*name
), NULL
);
1219 if (NULL
== parents
)
1220 parents
= g_ptr_array_new ();
1222 g_ptr_array_set_size (parents
, 0);
1223 matches
= tm_workspace_find (name
, tm_tag_class_t
, type
, FALSE
, TRUE
);
1224 if ((NULL
== matches
) || (0 == matches
->len
))
1226 g_ptr_array_add (parents
, matches
->pdata
[0]);
1227 while (i
< parents
->len
)
1229 tag
= TM_TAG (parents
->pdata
[i
]);
1230 if ((NULL
!= tag
->atts
.entry
.inheritance
) &&
1231 (isalpha (tag
->atts
.entry
.inheritance
[0])))
1233 klasses
= g_strsplit (tag
->atts
.entry
.inheritance
, ",", 10);
1234 for (klass
= klasses
; (NULL
!= *klass
); ++klass
)
1236 for (j
= 0; j
< parents
->len
; ++j
)
1238 if (0 == strcmp (*klass
, TM_TAG (parents
->pdata
[j
])->name
))
1241 if (parents
->len
== j
)
1243 matches
= tm_workspace_find (*klass
, tm_tag_class_t
,
1245 if ((NULL
!= matches
) && (0 < matches
->len
))
1246 g_ptr_array_add (parents
, matches
->pdata
[0]);
1249 g_strfreev (klasses
);