Debian Codegraph @

gperl-i11n-info.c

raw symbols SCIP
1 /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8; -*- */
2
3 static GIFunctionInfo *
4 _find_struct_method (GIStructInfo *info, const gchar *method)
5 {
6 /* g_struct_info_find_method is broken for class structs like
7 * GtkWidgetClass, so we search manually. See
8 * <https://bugzilla.gnome.org/show_bug.cgi?id=700338>. */
9 gint n_methods;
10 gint i;
11 n_methods = g_struct_info_get_n_methods (info);
12 for (i = 0; i < n_methods; i++) {
13 GIFunctionInfo *method_info =
14 g_struct_info_get_method (info, i);
15 if (strEQ (g_base_info_get_name (method_info), method))
16 return method_info;
17 g_base_info_unref (method_info);
18 }
19 return NULL;
20 }
21
22 static GIFunctionInfo *
23 _find_enum_method (GIEnumInfo *info, const gchar *method)
24 {
25 #if GI_CHECK_VERSION (1, 29, 17)
26 gint n_methods;
27 gint i;
28 n_methods = g_enum_info_get_n_methods (info);
29 for (i = 0; i < n_methods; i++) {
30 GIFunctionInfo *method_info =
31 g_enum_info_get_method (info, i);
32 if (strEQ (g_base_info_get_name (method_info), method))
33 return method_info;
34 g_base_info_unref (method_info);
35 }
36 #endif
37 return NULL;
38 }
39
40 /* Caller owns return value */
41 static GIFunctionInfo *
42 get_function_info (GIRepository *repository,
43 const gchar *basename,
44 const gchar *namespace,
45 const gchar *method)
46 {
47 dwarn ("%s, %s, %s\n", basename, namespace, method);
48
49 if (namespace) {
50 GIFunctionInfo *function_info = NULL;
51 GIBaseInfo *namespace_info = g_irepository_find_by_name (
52 repository, basename, namespace);
53 if (!namespace_info)
54 ccroak ("Can't find information for namespace %s",
55 namespace);
56
57 switch (g_base_info_get_type (namespace_info)) {
58 case GI_INFO_TYPE_OBJECT:
59 function_info = g_object_info_find_method (
60 (GIObjectInfo *) namespace_info,
61 method);
62 break;
63 case GI_INFO_TYPE_INTERFACE:
64 function_info = g_interface_info_find_method (
65 (GIInterfaceInfo *) namespace_info,
66 method);
67 break;
68 case GI_INFO_TYPE_BOXED:
69 case GI_INFO_TYPE_STRUCT:
70 function_info = _find_struct_method (
71 (GIStructInfo *) namespace_info,
72 method);
73 break;
74 case GI_INFO_TYPE_UNION:
75 function_info = g_union_info_find_method (
76 (GIUnionInfo *) namespace_info,
77 method);
78 break;
79 case GI_INFO_TYPE_ENUM:
80 case GI_INFO_TYPE_FLAGS:
81 function_info = _find_enum_method (
82 (GIEnumInfo *) namespace_info,
83 method);
84 break;
85 default:
86 ccroak ("Base info for namespace %s has incorrect type",
87 namespace);
88 }
89
90 if (!function_info)
91 ccroak ("Can't find information for method "
92 "%s::%s", namespace, method);
93
94 g_base_info_unref (namespace_info);
95
96 return function_info;
97 } else {
98 GIBaseInfo *method_info = g_irepository_find_by_name (
99 repository, basename, method);
100
101 if (!method_info)
102 ccroak ("Can't find information for method %s", method);
103
104 switch (g_base_info_get_type (method_info)) {
105 case GI_INFO_TYPE_FUNCTION:
106 return (GIFunctionInfo *) method_info;
107 default:
108 ccroak ("Base info for method %s has incorrect type",
109 method);
110 }
111 }
112
113 return NULL;
114 }
115
116 /* Caller owns return value */
117 static GIFieldInfo *
118 get_field_info (GIBaseInfo *info, const gchar *field_name)
119 {
120 GIInfoType info_type;
121 info_type = g_base_info_get_type (info);
122 switch (info_type) {
123 case GI_INFO_TYPE_BOXED:
124 case GI_INFO_TYPE_STRUCT:
125 {
126 gint n_fields, i;
127 n_fields = g_struct_info_get_n_fields ((GIStructInfo *) info);
128 for (i = 0; i < n_fields; i++) {
129 GIFieldInfo *field_info;
130 field_info = g_struct_info_get_field ((GIStructInfo *) info, i);
131 if (0 == strcmp (field_name, g_base_info_get_name (field_info))) {
132 return field_info;
133 }
134 g_base_info_unref (field_info);
135 }
136 break;
137 }
138 case GI_INFO_TYPE_UNION:
139 {
140 gint n_fields, i;
141 n_fields = g_union_info_get_n_fields ((GIStructInfo *) info);
142 for (i = 0; i < n_fields; i++) {
143 GIFieldInfo *field_info;
144 field_info = g_union_info_get_field ((GIStructInfo *) info, i);
145 if (0 == strcmp (field_name, g_base_info_get_name (field_info))) {
146 return field_info;
147 }
148 g_base_info_unref (field_info);
149 }
150 break;
151 }
152 default:
153 break;
154 }
155 return NULL;
156 }
157
158 /* Caller owns return value */
159 static GISignalInfo *
160 get_signal_info (GIBaseInfo *container_info, const gchar *signal_name)
161 {
162 if (GI_IS_OBJECT_INFO (container_info)) {
163 return g_object_info_find_signal (container_info, signal_name);
164 } else if (GI_IS_INTERFACE_INFO (container_info)) {
165 #if GI_CHECK_VERSION (1, 35, 4)
166 return g_interface_info_find_signal (container_info, signal_name);
167 #else
168 {
169 gint n_signals;
170 gint i;
171 n_signals = g_interface_info_get_n_signals (container_info);
172 for (i = 0; i < n_signals; i++) {
173 GISignalInfo *siginfo =
174 g_interface_info_get_signal (container_info, i);
175 if (strEQ (g_base_info_get_name (siginfo), signal_name))
176 return siginfo;
177 g_base_info_unref (siginfo);
178 }
179 return NULL;
180 }
181 #endif
182 }
183 return NULL;
184 }
185
186 /* Caller owns return value. */
187 static gchar *
188 synthesize_gtype_name (GIBaseInfo *info)
189 {
190 const gchar *namespace = g_base_info_get_namespace (info);
191 const gchar *name = g_base_info_get_name (info);
192 if (0 == strncmp (namespace, "GObject", 8) ||
193 0 == strncmp (namespace, "GLib", 5))
194 {
195 namespace = "G";
196 }
197 return g_strconcat (namespace, name, NULL);
198 }
199
200 /* Caller owns return value. */
201 static gchar *
202 synthesize_prefixed_gtype_name (GIBaseInfo *info)
203 {
204 const gchar *namespace = g_base_info_get_namespace (info);
205 const gchar *name = g_base_info_get_name (info);
206 if (0 == strncmp (namespace, "GObject", 8) ||
207 0 == strncmp (namespace, "GLib", 5))
208 {
209 namespace = "G";
210 }
211 return g_strconcat ("GPerlI11n", namespace, name, NULL);
212 }
213
214 static GType
215 get_gtype (GIRegisteredTypeInfo *info)
216 {
217 GType gtype = g_registered_type_info_get_g_type (info);
218 /* Fall back to the registered type name, and if that doesn't work
219 * either, construct the full name and the prefixed full name and try
220 * them. */
221 if (!gtype || gtype == G_TYPE_NONE) {
222 const gchar *type_name = g_registered_type_info_get_type_name (info);
223 if (type_name) {
224 gtype = g_type_from_name (type_name);
225 }
226 }
227 if (!gtype || gtype == G_TYPE_NONE) {
228 gchar *full_name = synthesize_gtype_name (info);
229 gtype = g_type_from_name (full_name);
230 g_free (full_name);
231 }
232 if (!gtype || gtype == G_TYPE_NONE) {
233 gchar *full_name = synthesize_prefixed_gtype_name (info);
234 gtype = g_type_from_name (full_name);
235 g_free (full_name);
236 }
237 return gtype ? gtype : G_TYPE_NONE;
238 }
239
240 static const gchar *
241 get_package_for_basename (const gchar *basename)
242 {
243 SV **svp;
244 HV *basename_to_package =
245 get_hv ("Glib::Object::Introspection::_BASENAME_TO_PACKAGE", 0);
246 g_assert (basename_to_package);
247 svp = hv_fetch (basename_to_package, basename, strlen (basename), 0);
248 if (!svp || !gperl_sv_is_defined (*svp))
249 return NULL;
250 return SvPV_nolen (*svp);
251 }
252
253 static gboolean
254 is_forbidden_sub_name (const gchar *name)
255 {
256 HV *forbidden_sub_names =
257 get_hv ("Glib::Object::Introspection::_FORBIDDEN_SUB_NAMES", 0);
258 g_assert (forbidden_sub_names);
259 return hv_exists (forbidden_sub_names, name, strlen (name));
260 }