Branch data Line data Source code
1 : : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 : : * GObject introspection: IDL generator
3 : : *
4 : : * Copyright (C) 2005 Matthias Clasen
5 : : * Copyright (C) 2008,2009 Red Hat, Inc.
6 : : *
7 : : * SPDX-License-Identifier: LGPL-2.1-or-later
8 : : *
9 : : * This library is free software; you can redistribute it and/or
10 : : * modify it under the terms of the GNU Lesser General Public
11 : : * License as published by the Free Software Foundation; either
12 : : * version 2 of the License, or (at your option) any later version.
13 : : *
14 : : * This library is distributed in the hope that it will be useful,
15 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : * Lesser General Public License for more details.
18 : : *
19 : : * You should have received a copy of the GNU Lesser General Public
20 : : * License along with this library; if not, write to the
21 : : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 : : * Boston, MA 02111-1307, USA.
23 : : */
24 : :
25 : : #include "config.h"
26 : :
27 : : #include "girwriter-private.h"
28 : :
29 : : #include "gibaseinfo-private.h"
30 : : #include "girepository.h"
31 : : #include "girepository-private.h"
32 : : #include "gitypelib-internal.h"
33 : :
34 : : #include <errno.h>
35 : : #include <string.h>
36 : : #include <stdio.h>
37 : :
38 : : #include <glib.h>
39 : : #include <glib-object.h>
40 : : #include <glib/gstdio.h>
41 : :
42 : : typedef struct {
43 : : FILE *file;
44 : : GSList *stack;
45 : : gboolean show_all;
46 : : } Xml;
47 : :
48 : : typedef struct {
49 : : char *name;
50 : : unsigned has_children : 1;
51 : : } XmlElement;
52 : :
53 : : static XmlElement *
54 : 0 : xml_element_new (const char *name)
55 : : {
56 : : XmlElement *elem;
57 : :
58 : 0 : elem = g_slice_new (XmlElement);
59 : 0 : elem->name = g_strdup (name);
60 : 0 : elem->has_children = FALSE;
61 : 0 : return elem;
62 : : }
63 : :
64 : : static void
65 : 0 : xml_element_free (XmlElement *elem)
66 : : {
67 : 0 : g_free (elem->name);
68 : 0 : g_slice_free (XmlElement, elem);
69 : 0 : }
70 : :
71 : : static void
72 : : xml_printf (Xml *xml, const char *fmt, ...) G_GNUC_PRINTF (2, 3);
73 : :
74 : : static void
75 : 0 : xml_printf (Xml *xml, const char *fmt, ...)
76 : : {
77 : : va_list ap;
78 : : char *s;
79 : :
80 : 0 : va_start (ap, fmt);
81 : 0 : s = g_markup_vprintf_escaped (fmt, ap);
82 : 0 : fputs (s, xml->file);
83 : 0 : g_free (s);
84 : 0 : va_end (ap);
85 : 0 : }
86 : :
87 : : static void
88 : 0 : xml_start_element (Xml *xml, const char *element_name)
89 : : {
90 : 0 : XmlElement *parent = NULL;
91 : :
92 [ # # ]: 0 : if (xml->stack)
93 : : {
94 : 0 : parent = xml->stack->data;
95 : :
96 [ # # ]: 0 : if (!parent->has_children)
97 : 0 : xml_printf (xml, ">\n");
98 : :
99 : 0 : parent->has_children = TRUE;
100 : : }
101 : :
102 : 0 : xml_printf (xml, "%*s<%s", g_slist_length(xml->stack)*2, "", element_name);
103 : :
104 : 0 : xml->stack = g_slist_prepend (xml->stack, xml_element_new (element_name));
105 : 0 : }
106 : :
107 : : static void
108 : 0 : xml_end_element (Xml *xml, const char *name)
109 : : {
110 : : XmlElement *elem;
111 : :
112 : 0 : g_assert (xml->stack != NULL);
113 : :
114 : 0 : elem = xml->stack->data;
115 : 0 : xml->stack = g_slist_delete_link (xml->stack, xml->stack);
116 : :
117 [ # # ]: 0 : if (name != NULL)
118 : 0 : g_assert_cmpstr (name, ==, elem->name);
119 : :
120 [ # # ]: 0 : if (elem->has_children)
121 : 0 : xml_printf (xml, "%*s</%s>\n", g_slist_length (xml->stack)*2, "", elem->name);
122 : : else
123 : 0 : xml_printf (xml, "/>\n");
124 : :
125 : 0 : xml_element_free (elem);
126 : 0 : }
127 : :
128 : : static void
129 : 0 : xml_end_element_unchecked (Xml *xml)
130 : : {
131 : 0 : xml_end_element (xml, NULL);
132 : 0 : }
133 : :
134 : : static Xml *
135 : 0 : xml_open (FILE *file)
136 : : {
137 : : Xml *xml;
138 : :
139 : 0 : xml = g_slice_new (Xml);
140 : 0 : xml->file = file;
141 : 0 : xml->stack = NULL;
142 : :
143 : 0 : return xml;
144 : : }
145 : :
146 : : static void
147 : 0 : xml_close (Xml *xml)
148 : : {
149 : 0 : g_assert (xml->stack == NULL);
150 [ # # ]: 0 : if (xml->file != NULL)
151 : : {
152 : 0 : fflush (xml->file);
153 [ # # ]: 0 : if (xml->file != stdout)
154 : 0 : fclose (xml->file);
155 : 0 : xml->file = NULL;
156 : : }
157 : 0 : }
158 : :
159 : : static void
160 : 0 : xml_free (Xml *xml)
161 : : {
162 : 0 : xml_close (xml);
163 : 0 : g_slice_free (Xml, xml);
164 : 0 : }
165 : :
166 : :
167 : : static void
168 : 0 : check_unresolved (GIBaseInfo *info)
169 : : {
170 [ # # # # : 0 : if (!GI_IS_UNRESOLVED_INFO (info))
# # # # ]
171 : 0 : return;
172 : :
173 : 0 : g_critical ("Found unresolved type '%s' '%s'",
174 : : gi_base_info_get_name (info), gi_base_info_get_namespace (info));
175 : : }
176 : :
177 : : static void
178 : 0 : write_type_name (const char *ns,
179 : : GIBaseInfo *info,
180 : : Xml *file)
181 : : {
182 [ # # ]: 0 : if (strcmp (ns, gi_base_info_get_namespace (info)) != 0)
183 : 0 : xml_printf (file, "%s.", gi_base_info_get_namespace (info));
184 : :
185 : 0 : xml_printf (file, "%s", gi_base_info_get_name (info));
186 : 0 : }
187 : :
188 : : static void
189 : 0 : write_type_name_attribute (const char *ns,
190 : : GIBaseInfo *info,
191 : : const char *attr_name,
192 : : Xml *file)
193 : : {
194 : 0 : xml_printf (file, " %s=\"", attr_name);
195 : 0 : write_type_name (ns, info, file);
196 : 0 : xml_printf (file, "\"");
197 : 0 : }
198 : :
199 : : static void
200 : 0 : write_ownership_transfer (GITransfer transfer,
201 : : Xml *file)
202 : : {
203 [ # # # # ]: 0 : switch (transfer)
204 : : {
205 : 0 : case GI_TRANSFER_NOTHING:
206 : 0 : xml_printf (file, " transfer-ownership=\"none\"");
207 : 0 : break;
208 : 0 : case GI_TRANSFER_CONTAINER:
209 : 0 : xml_printf (file, " transfer-ownership=\"container\"");
210 : 0 : break;
211 : 0 : case GI_TRANSFER_EVERYTHING:
212 : 0 : xml_printf (file, " transfer-ownership=\"full\"");
213 : 0 : break;
214 : 0 : default:
215 : : g_assert_not_reached ();
216 : : }
217 : 0 : }
218 : :
219 : : static void
220 : 0 : write_type_info (const char *ns,
221 : : GITypeInfo *info,
222 : : Xml *file)
223 : : {
224 : : int tag;
225 : : GITypeInfo *type;
226 : : gboolean is_pointer;
227 : :
228 : 0 : check_unresolved ((GIBaseInfo*)info);
229 : :
230 : 0 : tag = gi_type_info_get_tag (info);
231 : 0 : is_pointer = gi_type_info_is_pointer (info);
232 : :
233 [ # # ]: 0 : if (tag == GI_TYPE_TAG_VOID)
234 : : {
235 : 0 : xml_start_element (file, "type");
236 : :
237 [ # # ]: 0 : xml_printf (file, " name=\"%s\"", is_pointer ? "any" : "none");
238 : :
239 : 0 : xml_end_element (file, "type");
240 : : }
241 [ # # # # ]: 0 : else if (GI_TYPE_TAG_IS_BASIC (tag))
242 : : {
243 : 0 : xml_start_element (file, "type");
244 : 0 : xml_printf (file, " name=\"%s\"", gi_type_tag_to_string (tag));
245 : 0 : xml_end_element (file, "type");
246 : : }
247 [ # # ]: 0 : else if (tag == GI_TYPE_TAG_ARRAY)
248 : : {
249 : : unsigned int length_index;
250 : : size_t size;
251 : 0 : const char *name = NULL;
252 : :
253 : 0 : xml_start_element (file, "array");
254 : :
255 [ # # # # : 0 : switch (gi_type_info_get_array_type (info)) {
# ]
256 : 0 : case GI_ARRAY_TYPE_C:
257 : 0 : break;
258 : 0 : case GI_ARRAY_TYPE_ARRAY:
259 : 0 : name = "GLib.Array";
260 : 0 : break;
261 : 0 : case GI_ARRAY_TYPE_PTR_ARRAY:
262 : 0 : name = "GLib.PtrArray";
263 : 0 : break;
264 : 0 : case GI_ARRAY_TYPE_BYTE_ARRAY:
265 : 0 : name = "GLib.ByteArray";
266 : 0 : break;
267 : 0 : default:
268 : 0 : break;
269 : : }
270 : :
271 [ # # ]: 0 : if (name)
272 : 0 : xml_printf (file, " name=\"%s\"", name);
273 : :
274 : 0 : type = gi_type_info_get_param_type (info, 0);
275 : :
276 [ # # ]: 0 : if (gi_type_info_get_array_length_index (info, &length_index))
277 : 0 : xml_printf (file, " length=\"%u\"", length_index);
278 : :
279 [ # # ]: 0 : if (gi_type_info_get_array_fixed_size (info, &size))
280 : 0 : xml_printf (file, " fixed-size=\"%zu\"", size);
281 : :
282 [ # # ]: 0 : if (gi_type_info_is_zero_terminated (info))
283 : 0 : xml_printf (file, " zero-terminated=\"1\"");
284 : :
285 : 0 : write_type_info (ns, type, file);
286 : :
287 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
288 : :
289 : 0 : xml_end_element (file, "array");
290 : : }
291 [ # # ]: 0 : else if (tag == GI_TYPE_TAG_INTERFACE)
292 : : {
293 : 0 : GIBaseInfo *iface = gi_type_info_get_interface (info);
294 : 0 : xml_start_element (file, "type");
295 : 0 : write_type_name_attribute (ns, iface, "name", file);
296 : 0 : xml_end_element (file, "type");
297 : 0 : gi_base_info_unref (iface);
298 : : }
299 [ # # ]: 0 : else if (tag == GI_TYPE_TAG_GLIST)
300 : : {
301 : 0 : xml_start_element (file, "type");
302 : 0 : xml_printf (file, " name=\"GLib.List\"");
303 : 0 : type = gi_type_info_get_param_type (info, 0);
304 [ # # ]: 0 : if (type)
305 : : {
306 : 0 : write_type_info (ns, type, file);
307 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
308 : : }
309 : 0 : xml_end_element (file, "type");
310 : : }
311 [ # # ]: 0 : else if (tag == GI_TYPE_TAG_GSLIST)
312 : : {
313 : 0 : xml_start_element (file, "type");
314 : 0 : xml_printf (file, " name=\"GLib.SList\"");
315 : 0 : type = gi_type_info_get_param_type (info, 0);
316 [ # # ]: 0 : if (type)
317 : : {
318 : 0 : write_type_info (ns, type, file);
319 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
320 : : }
321 : 0 : xml_end_element (file, "type");
322 : : }
323 [ # # ]: 0 : else if (tag == GI_TYPE_TAG_GHASH)
324 : : {
325 : 0 : xml_start_element (file, "type");
326 : 0 : xml_printf (file, " name=\"GLib.HashTable\"");
327 : 0 : type = gi_type_info_get_param_type (info, 0);
328 [ # # ]: 0 : if (type)
329 : : {
330 : 0 : write_type_info (ns, type, file);
331 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
332 : 0 : type = gi_type_info_get_param_type (info, 1);
333 : 0 : write_type_info (ns, type, file);
334 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
335 : : }
336 : 0 : xml_end_element (file, "type");
337 : : }
338 [ # # ]: 0 : else if (tag == GI_TYPE_TAG_ERROR)
339 : : {
340 : 0 : xml_start_element (file, "type");
341 : 0 : xml_printf (file, " name=\"GLib.Error\"");
342 : 0 : xml_end_element (file, "type");
343 : : }
344 : : else
345 : : {
346 : 0 : g_printerr ("Unhandled type tag %d\n", tag);
347 : : g_assert_not_reached ();
348 : : }
349 : 0 : }
350 : :
351 : : static void
352 : 0 : write_attributes (Xml *file,
353 : : GIBaseInfo *info)
354 : : {
355 : 0 : GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
356 : : const char *name, *value;
357 : :
358 [ # # ]: 0 : while (gi_base_info_iterate_attributes (info, &iter, &name, &value))
359 : : {
360 : 0 : xml_start_element (file, "attribute");
361 : 0 : xml_printf (file, " name=\"%s\" value=\"%s\"", name, value);
362 : 0 : xml_end_element (file, "attribute");
363 : : }
364 : 0 : }
365 : :
366 : : static void
367 : 0 : write_return_value_attributes (Xml *file,
368 : : GICallableInfo *info)
369 : : {
370 : 0 : GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
371 : : const char *name, *value;
372 : :
373 [ # # ]: 0 : while (gi_callable_info_iterate_return_attributes (info, &iter, &name, &value))
374 : : {
375 : 0 : xml_start_element (file, "attribute");
376 : 0 : xml_printf (file, " name=\"%s\" value=\"%s\"", name, value);
377 : 0 : xml_end_element (file, "attribute");
378 : : }
379 : 0 : }
380 : :
381 : : static void
382 : : write_constant_value (const char *ns,
383 : : GITypeInfo *info,
384 : : GIArgument *argument,
385 : : Xml *file);
386 : :
387 : : static void
388 : : write_callback_info (const char *ns,
389 : : GICallbackInfo *info,
390 : : Xml *file);
391 : :
392 : : static void
393 : 0 : write_field_info (const char *ns,
394 : : GIFieldInfo *info,
395 : : GIConstantInfo *branch,
396 : : Xml *file)
397 : : {
398 : : const char *name;
399 : : GIFieldInfoFlags flags;
400 : : size_t size;
401 : : size_t offset;
402 : : GITypeInfo *type;
403 : : GIBaseInfo *interface;
404 : : GIArgument value;
405 : :
406 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
407 : 0 : flags = gi_field_info_get_flags (info);
408 : 0 : size = gi_field_info_get_size (info);
409 : 0 : offset = gi_field_info_get_offset (info);
410 : :
411 : 0 : xml_start_element (file, "field");
412 : 0 : xml_printf (file, " name=\"%s\"", name);
413 : :
414 : : /* Fields are assumed to be read-only
415 : : * (see also girwriter.py and girparser.c)
416 : : */
417 [ # # ]: 0 : if (!(flags & GI_FIELD_IS_READABLE))
418 : 0 : xml_printf (file, " readable=\"0\"");
419 [ # # ]: 0 : if (flags & GI_FIELD_IS_WRITABLE)
420 : 0 : xml_printf (file, " writable=\"1\"");
421 : :
422 [ # # ]: 0 : if (size)
423 : 0 : xml_printf (file, " bits=\"%zu\"", size);
424 : :
425 : 0 : write_attributes (file, (GIBaseInfo*) info);
426 : :
427 : 0 : type = gi_field_info_get_type_info (info);
428 : :
429 [ # # ]: 0 : if (branch)
430 : : {
431 : 0 : xml_printf (file, " branch=\"");
432 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
433 : 0 : type = gi_constant_info_get_type_info (branch);
434 : 0 : gi_constant_info_get_value (branch, &value);
435 : 0 : write_constant_value (ns, type, &value, file);
436 : 0 : xml_printf (file, "\"");
437 : : }
438 : :
439 [ # # ]: 0 : if (file->show_all)
440 : : {
441 : 0 : xml_printf (file, "offset=\"%zu\"", offset);
442 : : }
443 : :
444 : 0 : interface = gi_type_info_get_interface (type);
445 [ # # # # : 0 : if (interface != NULL && GI_IS_CALLBACK_INFO (interface))
# # # # #
# ]
446 : 0 : write_callback_info (ns, (GICallbackInfo *)interface, file);
447 : : else
448 : 0 : write_type_info (ns, type, file);
449 : :
450 [ # # ]: 0 : if (interface)
451 : 0 : gi_base_info_unref (interface);
452 : :
453 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
454 : :
455 : 0 : xml_end_element (file, "field");
456 : 0 : }
457 : :
458 : : static void
459 : 0 : write_callable_info (const char *ns,
460 : : GICallableInfo *info,
461 : : Xml *file)
462 : : {
463 : : GITypeInfo *type;
464 : :
465 [ # # ]: 0 : if (gi_callable_info_can_throw_gerror (info))
466 : 0 : xml_printf (file, " throws=\"1\"");
467 : :
468 : 0 : write_attributes (file, (GIBaseInfo*) info);
469 : :
470 : 0 : type = gi_callable_info_get_return_type (info);
471 : :
472 : 0 : xml_start_element (file, "return-value");
473 : :
474 : 0 : write_ownership_transfer (gi_callable_info_get_caller_owns (info), file);
475 : :
476 [ # # ]: 0 : if (gi_callable_info_may_return_null (info))
477 : 0 : xml_printf (file, " allow-none=\"1\"");
478 : :
479 [ # # ]: 0 : if (gi_callable_info_skip_return (info))
480 : 0 : xml_printf (file, " skip=\"1\"");
481 : :
482 : 0 : write_return_value_attributes (file, info);
483 : :
484 : 0 : write_type_info (ns, type, file);
485 : :
486 : 0 : xml_end_element (file, "return-value");
487 : :
488 [ # # ]: 0 : if (gi_callable_info_get_n_args (info) <= 0)
489 : 0 : return;
490 : :
491 : 0 : xml_start_element (file, "parameters");
492 [ # # ]: 0 : for (unsigned int i = 0; i < gi_callable_info_get_n_args (info); i++)
493 : : {
494 : 0 : GIArgInfo *arg = gi_callable_info_get_arg (info, i);
495 : : unsigned int closure_index, destroy_index;
496 : :
497 : 0 : xml_start_element (file, "parameter");
498 : 0 : xml_printf (file, " name=\"%s\"",
499 : : gi_base_info_get_name ((GIBaseInfo *) arg));
500 : :
501 : 0 : write_ownership_transfer (gi_arg_info_get_ownership_transfer (arg), file);
502 : :
503 [ # # # # ]: 0 : switch (gi_arg_info_get_direction (arg))
504 : : {
505 : 0 : case GI_DIRECTION_IN:
506 : 0 : break;
507 : 0 : case GI_DIRECTION_OUT:
508 [ # # ]: 0 : xml_printf (file, " direction=\"out\" caller-allocates=\"%s\"",
509 : 0 : gi_arg_info_is_caller_allocates (arg) ? "1" : "0");
510 : 0 : break;
511 : 0 : case GI_DIRECTION_INOUT:
512 : 0 : xml_printf (file, " direction=\"inout\"");
513 : 0 : break;
514 : 0 : default:
515 : : g_assert_not_reached ();
516 : : }
517 : :
518 [ # # ]: 0 : if (gi_arg_info_may_be_null (arg))
519 : 0 : xml_printf (file, " allow-none=\"1\"");
520 : :
521 [ # # ]: 0 : if (gi_arg_info_is_return_value (arg))
522 : 0 : xml_printf (file, " retval=\"1\"");
523 : :
524 [ # # ]: 0 : if (gi_arg_info_is_optional (arg))
525 : 0 : xml_printf (file, " optional=\"1\"");
526 : :
527 [ # # # # : 0 : switch (gi_arg_info_get_scope (arg))
# # ]
528 : : {
529 : 0 : case GI_SCOPE_TYPE_INVALID:
530 : 0 : break;
531 : 0 : case GI_SCOPE_TYPE_CALL:
532 : 0 : xml_printf (file, " scope=\"call\"");
533 : 0 : break;
534 : 0 : case GI_SCOPE_TYPE_ASYNC:
535 : 0 : xml_printf (file, " scope=\"async\"");
536 : 0 : break;
537 : 0 : case GI_SCOPE_TYPE_NOTIFIED:
538 : 0 : xml_printf (file, " scope=\"notified\"");
539 : 0 : break;
540 : 0 : case GI_SCOPE_TYPE_FOREVER:
541 : 0 : xml_printf (file, " scope=\"forever\"");
542 : 0 : break;
543 : 0 : default:
544 : : g_assert_not_reached ();
545 : : }
546 : :
547 [ # # ]: 0 : if (gi_arg_info_get_closure_index (arg, &closure_index))
548 : 0 : xml_printf (file, " closure=\"%u\"", closure_index);
549 : :
550 [ # # ]: 0 : if (gi_arg_info_get_destroy_index (arg, &destroy_index))
551 : 0 : xml_printf (file, " destroy=\"%u\"", destroy_index);
552 : :
553 [ # # ]: 0 : if (gi_arg_info_is_skip (arg))
554 : 0 : xml_printf (file, " skip=\"1\"");
555 : :
556 : 0 : write_attributes (file, (GIBaseInfo*) arg);
557 : :
558 : 0 : type = gi_arg_info_get_type_info (arg);
559 : 0 : write_type_info (ns, type, file);
560 : :
561 : 0 : xml_end_element (file, "parameter");
562 : :
563 : 0 : gi_base_info_unref ((GIBaseInfo *)arg);
564 : : }
565 : :
566 : 0 : xml_end_element (file, "parameters");
567 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
568 : : }
569 : :
570 : : static void
571 : 0 : write_function_info (const char *ns,
572 : : GIFunctionInfo *info,
573 : : Xml *file)
574 : : {
575 : : GIFunctionInfoFlags flags;
576 : : const char *tag;
577 : : const char *name;
578 : : const char *symbol;
579 : : gboolean deprecated;
580 : :
581 : 0 : flags = gi_function_info_get_flags (info);
582 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
583 : 0 : symbol = gi_function_info_get_symbol (info);
584 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
585 : :
586 [ # # ]: 0 : if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
587 : 0 : tag = "constructor";
588 [ # # ]: 0 : else if (flags & GI_FUNCTION_IS_METHOD)
589 : 0 : tag = "method";
590 : : else
591 : 0 : tag = "function";
592 : :
593 : 0 : xml_start_element (file, tag);
594 : 0 : xml_printf (file, " name=\"%s\" c:identifier=\"%s\"",
595 : : name, symbol);
596 : :
597 [ # # # # ]: 0 : if ((flags & GI_FUNCTION_IS_SETTER) || (flags & GI_FUNCTION_IS_GETTER))
598 : : {
599 : 0 : GIPropertyInfo *property = gi_function_info_get_property (info);
600 : :
601 [ # # ]: 0 : if (property != NULL)
602 : : {
603 : 0 : const char *property_name = gi_base_info_get_name ((GIBaseInfo *)property);
604 : :
605 [ # # ]: 0 : if (flags & GI_FUNCTION_IS_SETTER)
606 : 0 : xml_printf (file, " glib:set-property=\"%s\"", property_name);
607 [ # # ]: 0 : else if (flags & GI_FUNCTION_IS_GETTER)
608 : 0 : xml_printf (file, " glib:get-property=\"%s\"", property_name);
609 : :
610 : 0 : gi_base_info_unref ((GIBaseInfo *) property);
611 : : }
612 : : }
613 : :
614 [ # # ]: 0 : if (deprecated)
615 : 0 : xml_printf (file, " deprecated=\"1\"");
616 : :
617 : 0 : write_callable_info (ns, (GICallableInfo*)info, file);
618 : 0 : xml_end_element (file, tag);
619 : 0 : }
620 : :
621 : : static void
622 : 0 : write_callback_info (const char *ns,
623 : : GICallbackInfo *info,
624 : : Xml *file)
625 : : {
626 : : const char *name;
627 : : gboolean deprecated;
628 : :
629 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
630 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
631 : :
632 : 0 : xml_start_element (file, "callback");
633 : 0 : xml_printf (file, " name=\"%s\"", name);
634 : :
635 [ # # ]: 0 : if (deprecated)
636 : 0 : xml_printf (file, " deprecated=\"1\"");
637 : :
638 : 0 : write_callable_info (ns, (GICallableInfo*)info, file);
639 : 0 : xml_end_element (file, "callback");
640 : 0 : }
641 : :
642 : : static void
643 : 0 : write_struct_info (const char *ns,
644 : : GIStructInfo *info,
645 : : Xml *file)
646 : : {
647 : : const char *name;
648 : : const char *type_name;
649 : : const char *type_init;
650 : : const char *func;
651 : : gboolean deprecated;
652 : : gboolean is_gtype_struct;
653 : : gboolean foreign;
654 : : size_t size;
655 : : unsigned int n_elts;
656 : :
657 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
658 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
659 : :
660 : 0 : type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
661 : 0 : type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
662 : :
663 [ # # ]: 0 : if (gi_registered_type_info_is_boxed (GI_REGISTERED_TYPE_INFO (info)))
664 : : {
665 : 0 : xml_start_element (file, "glib:boxed");
666 : 0 : xml_printf (file, " glib:name=\"%s\"", name);
667 : : }
668 : : else
669 : : {
670 : 0 : xml_start_element (file, "record");
671 : 0 : xml_printf (file, " name=\"%s\"", name);
672 : : }
673 : :
674 [ # # ]: 0 : if (type_name != NULL)
675 : 0 : xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init);
676 : :
677 [ # # ]: 0 : if (deprecated)
678 : 0 : xml_printf (file, " deprecated=\"1\"");
679 : :
680 : 0 : is_gtype_struct = gi_struct_info_is_gtype_struct (info);
681 [ # # ]: 0 : if (is_gtype_struct)
682 : 0 : xml_printf (file, " glib:is-gtype-struct=\"1\"");
683 : :
684 : 0 : func = gi_struct_info_get_copy_function_name (info);
685 [ # # ]: 0 : if (func)
686 : 0 : xml_printf (file, " copy-function=\"%s\"", func);
687 : :
688 : 0 : func = gi_struct_info_get_free_function_name (info);
689 [ # # ]: 0 : if (func)
690 : 0 : xml_printf (file, " free-function=\"%s\"", func);
691 : :
692 : 0 : write_attributes (file, (GIBaseInfo*) info);
693 : :
694 : 0 : size = gi_struct_info_get_size (info);
695 [ # # ]: 0 : if (file->show_all)
696 : 0 : xml_printf (file, " size=\"%zu\"", size);
697 : :
698 : 0 : foreign = gi_struct_info_is_foreign (info);
699 [ # # ]: 0 : if (foreign)
700 : 0 : xml_printf (file, " foreign=\"1\"");
701 : :
702 : 0 : n_elts = gi_struct_info_get_n_fields (info) + gi_struct_info_get_n_methods (info);
703 [ # # ]: 0 : if (n_elts > 0)
704 : : {
705 [ # # ]: 0 : for (unsigned int i = 0; i < gi_struct_info_get_n_fields (info); i++)
706 : : {
707 : 0 : GIFieldInfo *field = gi_struct_info_get_field (info, i);
708 : 0 : write_field_info (ns, field, NULL, file);
709 : 0 : gi_base_info_unref ((GIBaseInfo *)field);
710 : : }
711 : :
712 [ # # ]: 0 : for (unsigned int i = 0; i < gi_struct_info_get_n_methods (info); i++)
713 : : {
714 : 0 : GIFunctionInfo *function = gi_struct_info_get_method (info, i);
715 : 0 : write_function_info (ns, function, file);
716 : 0 : gi_base_info_unref ((GIBaseInfo *)function);
717 : : }
718 : :
719 : : }
720 : :
721 : 0 : xml_end_element_unchecked (file);
722 : 0 : }
723 : :
724 : : static void
725 : 0 : write_value_info (const char *ns,
726 : : GIValueInfo *info,
727 : : Xml *file)
728 : : {
729 : : const char *name;
730 : : int64_t value;
731 : : char *value_str;
732 : : gboolean deprecated;
733 : :
734 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
735 : 0 : value = gi_value_info_get_value (info);
736 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
737 : :
738 : 0 : xml_start_element (file, "member");
739 : 0 : value_str = g_strdup_printf ("%" G_GINT64_FORMAT, value);
740 : 0 : xml_printf (file, " name=\"%s\" value=\"%s\"", name, value_str);
741 : 0 : g_free (value_str);
742 : :
743 [ # # ]: 0 : if (deprecated)
744 : 0 : xml_printf (file, " deprecated=\"1\"");
745 : :
746 : 0 : write_attributes (file, (GIBaseInfo*) info);
747 : :
748 : 0 : xml_end_element (file, "member");
749 : 0 : }
750 : :
751 : : static void
752 : 0 : write_constant_value (const char *ns,
753 : : GITypeInfo *type,
754 : : GIArgument *value,
755 : : Xml *file)
756 : : {
757 [ # # # # : 0 : switch (gi_type_info_get_tag (type))
# # # # #
# # # # ]
758 : : {
759 : 0 : case GI_TYPE_TAG_BOOLEAN:
760 : 0 : xml_printf (file, "%d", value->v_boolean);
761 : 0 : break;
762 : 0 : case GI_TYPE_TAG_INT8:
763 : 0 : xml_printf (file, "%d", value->v_int8);
764 : 0 : break;
765 : 0 : case GI_TYPE_TAG_UINT8:
766 : 0 : xml_printf (file, "%d", value->v_uint8);
767 : 0 : break;
768 : 0 : case GI_TYPE_TAG_INT16:
769 : 0 : xml_printf (file, "%" G_GINT16_FORMAT, value->v_int16);
770 : 0 : break;
771 : 0 : case GI_TYPE_TAG_UINT16:
772 : 0 : xml_printf (file, "%" G_GUINT16_FORMAT, value->v_uint16);
773 : 0 : break;
774 : 0 : case GI_TYPE_TAG_INT32:
775 : 0 : xml_printf (file, "%" G_GINT32_FORMAT, value->v_int32);
776 : 0 : break;
777 : 0 : case GI_TYPE_TAG_UINT32:
778 : 0 : xml_printf (file, "%" G_GUINT32_FORMAT, value->v_uint32);
779 : 0 : break;
780 : 0 : case GI_TYPE_TAG_INT64:
781 : 0 : xml_printf (file, "%" G_GINT64_FORMAT, value->v_int64);
782 : 0 : break;
783 : 0 : case GI_TYPE_TAG_UINT64:
784 : 0 : xml_printf (file, "%" G_GUINT64_FORMAT, value->v_uint64);
785 : 0 : break;
786 : 0 : case GI_TYPE_TAG_FLOAT:
787 : 0 : xml_printf (file, "%f", (double)value->v_float);
788 : 0 : break;
789 : 0 : case GI_TYPE_TAG_DOUBLE:
790 : 0 : xml_printf (file, "%f", value->v_double);
791 : 0 : break;
792 : 0 : case GI_TYPE_TAG_UTF8:
793 : : case GI_TYPE_TAG_FILENAME:
794 : 0 : xml_printf (file, "%s", value->v_string);
795 : 0 : break;
796 : 0 : default:
797 : : g_assert_not_reached ();
798 : : }
799 : 0 : }
800 : :
801 : : static void
802 : 0 : write_constant_info (const char *ns,
803 : : GIConstantInfo *info,
804 : : Xml *file)
805 : : {
806 : : GITypeInfo *type;
807 : : const char *name;
808 : : GIArgument value;
809 : :
810 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
811 : :
812 : 0 : xml_start_element (file, "constant");
813 : 0 : xml_printf (file, " name=\"%s\"", name);
814 : :
815 : 0 : type = gi_constant_info_get_type_info (info);
816 : 0 : xml_printf (file, " value=\"");
817 : :
818 : 0 : gi_constant_info_get_value (info, &value);
819 : 0 : write_constant_value (ns, type, &value, file);
820 : 0 : xml_printf (file, "\"");
821 : :
822 : 0 : write_type_info (ns, type, file);
823 : :
824 : 0 : write_attributes (file, (GIBaseInfo*) info);
825 : :
826 : 0 : xml_end_element (file, "constant");
827 : :
828 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
829 : 0 : }
830 : :
831 : :
832 : : static void
833 : 0 : write_enum_info (const char *ns,
834 : : GIEnumInfo *info,
835 : : Xml *file)
836 : : {
837 : : const char *name;
838 : : const char *type_name;
839 : : const char *type_init;
840 : : const char *error_domain;
841 : : gboolean deprecated;
842 : :
843 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
844 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
845 : :
846 : 0 : type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
847 : 0 : type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
848 : 0 : error_domain = gi_enum_info_get_error_domain (info);
849 : :
850 [ # # # # : 0 : if (GI_IS_ENUM_INFO (info))
# # # # ]
851 : 0 : xml_start_element (file, "enumeration");
852 : : else
853 : 0 : xml_start_element (file, "bitfield");
854 : 0 : xml_printf (file, " name=\"%s\"", name);
855 : :
856 [ # # ]: 0 : if (type_init)
857 : 0 : xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init);
858 [ # # ]: 0 : if (error_domain)
859 : 0 : xml_printf (file, " glib:error-domain=\"%s\"", error_domain);
860 : :
861 [ # # ]: 0 : if (deprecated)
862 : 0 : xml_printf (file, " deprecated=\"1\"");
863 : :
864 : 0 : write_attributes (file, (GIBaseInfo*) info);
865 : :
866 [ # # ]: 0 : for (unsigned int i = 0; i < gi_enum_info_get_n_values (info); i++)
867 : : {
868 : 0 : GIValueInfo *value = gi_enum_info_get_value (info, i);
869 : 0 : write_value_info (ns, value, file);
870 : 0 : gi_base_info_unref ((GIBaseInfo *)value);
871 : : }
872 : :
873 : 0 : xml_end_element_unchecked (file);
874 : 0 : }
875 : :
876 : : static void
877 : 0 : write_signal_info (const char *ns,
878 : : GISignalInfo *info,
879 : : Xml *file)
880 : : {
881 : : GSignalFlags flags;
882 : : const char *name;
883 : : gboolean deprecated;
884 : :
885 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
886 : 0 : flags = gi_signal_info_get_flags (info);
887 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
888 : :
889 : 0 : xml_start_element (file, "glib:signal");
890 : 0 : xml_printf (file, " name=\"%s\"", name);
891 : :
892 [ # # ]: 0 : if (deprecated)
893 : 0 : xml_printf (file, " deprecated=\"1\"");
894 : :
895 [ # # ]: 0 : if (flags & G_SIGNAL_RUN_FIRST)
896 : 0 : xml_printf (file, " when=\"FIRST\"");
897 [ # # ]: 0 : else if (flags & G_SIGNAL_RUN_LAST)
898 : 0 : xml_printf (file, " when=\"LAST\"");
899 [ # # ]: 0 : else if (flags & G_SIGNAL_RUN_CLEANUP)
900 : 0 : xml_printf (file, " when=\"CLEANUP\"");
901 : :
902 [ # # ]: 0 : if (flags & G_SIGNAL_NO_RECURSE)
903 : 0 : xml_printf (file, " no-recurse=\"1\"");
904 : :
905 [ # # ]: 0 : if (flags & G_SIGNAL_DETAILED)
906 : 0 : xml_printf (file, " detailed=\"1\"");
907 : :
908 [ # # ]: 0 : if (flags & G_SIGNAL_ACTION)
909 : 0 : xml_printf (file, " action=\"1\"");
910 : :
911 [ # # ]: 0 : if (flags & G_SIGNAL_NO_HOOKS)
912 : 0 : xml_printf (file, " no-hooks=\"1\"");
913 : :
914 : 0 : write_callable_info (ns, (GICallableInfo*)info, file);
915 : :
916 : 0 : xml_end_element (file, "glib:signal");
917 : 0 : }
918 : :
919 : : static void
920 : 0 : write_vfunc_info (const char *ns,
921 : : GIVFuncInfo *info,
922 : : Xml *file)
923 : : {
924 : : GIVFuncInfoFlags flags;
925 : : const char *name;
926 : : GIFunctionInfo *invoker;
927 : : gboolean deprecated;
928 : : size_t offset;
929 : :
930 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
931 : 0 : flags = gi_vfunc_info_get_flags (info);
932 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
933 : 0 : offset = gi_vfunc_info_get_offset (info);
934 : 0 : invoker = gi_vfunc_info_get_invoker (info);
935 : :
936 : 0 : xml_start_element (file, "virtual-method");
937 : 0 : xml_printf (file, " name=\"%s\"", name);
938 : :
939 [ # # ]: 0 : if (deprecated)
940 : 0 : xml_printf (file, " deprecated=\"1\"");
941 : :
942 [ # # ]: 0 : if (flags & GI_VFUNC_MUST_CHAIN_UP)
943 : 0 : xml_printf (file, " must-chain-up=\"1\"");
944 : :
945 [ # # ]: 0 : if (flags & GI_VFUNC_MUST_OVERRIDE)
946 : 0 : xml_printf (file, " override=\"always\"");
947 [ # # ]: 0 : else if (flags & GI_VFUNC_MUST_NOT_OVERRIDE)
948 : 0 : xml_printf (file, " override=\"never\"");
949 : :
950 : 0 : xml_printf (file, " offset=\"%zu\"", offset);
951 : :
952 [ # # ]: 0 : if (invoker)
953 : : {
954 : 0 : xml_printf (file, " invoker=\"%s\"", gi_base_info_get_name ((GIBaseInfo*)invoker));
955 : 0 : gi_base_info_unref ((GIBaseInfo *)invoker);
956 : : }
957 : :
958 : 0 : write_callable_info (ns, (GICallableInfo*)info, file);
959 : :
960 : 0 : xml_end_element (file, "virtual-method");
961 : 0 : }
962 : :
963 : : static void
964 : 0 : write_property_info (const char *ns,
965 : : GIPropertyInfo *info,
966 : : Xml *file)
967 : : {
968 : : GParamFlags flags;
969 : : const char *name;
970 : : gboolean deprecated;
971 : : GITypeInfo *type;
972 : :
973 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
974 : 0 : flags = gi_property_info_get_flags (info);
975 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
976 : :
977 : 0 : xml_start_element (file, "property");
978 : 0 : xml_printf (file, " name=\"%s\"", name);
979 : :
980 [ # # ]: 0 : if (deprecated)
981 : 0 : xml_printf (file, " deprecated=\"1\"");
982 : :
983 : : /* Properties are assumed to be read-only (see also girwriter.py) */
984 [ # # ]: 0 : if (!(flags & G_PARAM_READABLE))
985 : 0 : xml_printf (file, " readable=\"0\"");
986 [ # # ]: 0 : if (flags & G_PARAM_WRITABLE)
987 : 0 : xml_printf (file, " writable=\"1\"");
988 : :
989 [ # # ]: 0 : if (flags & G_PARAM_CONSTRUCT)
990 : 0 : xml_printf (file, " construct=\"1\"");
991 : :
992 [ # # ]: 0 : if (flags & G_PARAM_CONSTRUCT_ONLY)
993 : 0 : xml_printf (file, " construct-only=\"1\"");
994 : :
995 [ # # ]: 0 : if (flags & G_PARAM_READABLE)
996 : : {
997 : 0 : GIFunctionInfo *getter = gi_property_info_get_getter (info);
998 : :
999 [ # # ]: 0 : if (getter != NULL)
1000 : : {
1001 : 0 : xml_printf (file, " getter=\"%s\"", gi_base_info_get_name ((GIBaseInfo *) getter));
1002 : 0 : gi_base_info_unref ((GIBaseInfo *) getter);
1003 : : }
1004 : : }
1005 : :
1006 [ # # ]: 0 : if (flags & G_PARAM_WRITABLE)
1007 : : {
1008 : 0 : GIFunctionInfo *setter = gi_property_info_get_setter (info);
1009 : :
1010 [ # # ]: 0 : if (setter != NULL)
1011 : : {
1012 : 0 : xml_printf (file, " setter=\"%s\"", gi_base_info_get_name ((GIBaseInfo *) setter));
1013 : 0 : gi_base_info_unref ((GIBaseInfo *) setter);
1014 : : }
1015 : : }
1016 : :
1017 : 0 : write_ownership_transfer (gi_property_info_get_ownership_transfer (info), file);
1018 : :
1019 : 0 : write_attributes (file, (GIBaseInfo*) info);
1020 : :
1021 : 0 : type = gi_property_info_get_type_info (info);
1022 : :
1023 : 0 : write_type_info (ns, type, file);
1024 : :
1025 : 0 : xml_end_element (file, "property");
1026 : 0 : }
1027 : :
1028 : : static void
1029 : 0 : write_object_info (const char *ns,
1030 : : GIObjectInfo *info,
1031 : : Xml *file)
1032 : : {
1033 : : const char *name;
1034 : : const char *type_name;
1035 : : const char *type_init;
1036 : : const char *func;
1037 : : gboolean deprecated;
1038 : : gboolean is_abstract;
1039 : : gboolean is_fundamental;
1040 : : gboolean is_final;
1041 : : GIObjectInfo *pnode;
1042 : : GIStructInfo *class_struct;
1043 : :
1044 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
1045 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
1046 : 0 : is_abstract = gi_object_info_get_abstract (info);
1047 : 0 : is_fundamental = gi_object_info_get_fundamental (info);
1048 : 0 : is_final = gi_object_info_get_final (info);
1049 : :
1050 : 0 : type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
1051 : 0 : type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
1052 : 0 : xml_start_element (file, "class");
1053 : 0 : xml_printf (file, " name=\"%s\"", name);
1054 : :
1055 : 0 : pnode = gi_object_info_get_parent (info);
1056 [ # # ]: 0 : if (pnode)
1057 : : {
1058 : 0 : write_type_name_attribute (ns, (GIBaseInfo *)pnode, "parent", file);
1059 : 0 : gi_base_info_unref ((GIBaseInfo *)pnode);
1060 : : }
1061 : :
1062 : 0 : class_struct = gi_object_info_get_class_struct (info);
1063 [ # # ]: 0 : if (class_struct)
1064 : : {
1065 : 0 : write_type_name_attribute (ns, (GIBaseInfo*) class_struct, "glib:type-struct", file);
1066 : 0 : gi_base_info_unref ((GIBaseInfo*)class_struct);
1067 : : }
1068 : :
1069 [ # # ]: 0 : if (is_abstract)
1070 : 0 : xml_printf (file, " abstract=\"1\"");
1071 : :
1072 [ # # ]: 0 : if (is_final)
1073 : 0 : xml_printf (file, " final=\"1\"");
1074 : :
1075 : 0 : xml_printf (file, " glib:type-name=\"%s\" glib:get-type=\"%s\"", type_name, type_init);
1076 : :
1077 [ # # ]: 0 : if (is_fundamental)
1078 : 0 : xml_printf (file, " glib:fundamental=\"1\"");
1079 : :
1080 : 0 : func = gi_object_info_get_unref_function_name (info);
1081 [ # # ]: 0 : if (func)
1082 : 0 : xml_printf (file, " glib:unref-function=\"%s\"", func);
1083 : :
1084 : 0 : func = gi_object_info_get_ref_function_name (info);
1085 [ # # ]: 0 : if (func)
1086 : 0 : xml_printf (file, " glib:ref-function=\"%s\"", func);
1087 : :
1088 : 0 : func = gi_object_info_get_set_value_function_name (info);
1089 [ # # ]: 0 : if (func)
1090 : 0 : xml_printf (file, " glib:set-value-function=\"%s\"", func);
1091 : :
1092 : 0 : func = gi_object_info_get_get_value_function_name (info);
1093 [ # # ]: 0 : if (func)
1094 : 0 : xml_printf (file, " glib:get-value-function=\"%s\"", func);
1095 : :
1096 [ # # ]: 0 : if (deprecated)
1097 : 0 : xml_printf (file, " deprecated=\"1\"");
1098 : :
1099 : 0 : write_attributes (file, (GIBaseInfo*) info);
1100 : :
1101 [ # # ]: 0 : if (gi_object_info_get_n_interfaces (info) > 0)
1102 : : {
1103 [ # # ]: 0 : for (unsigned int i = 0; i < gi_object_info_get_n_interfaces (info); i++)
1104 : : {
1105 : 0 : GIInterfaceInfo *imp = gi_object_info_get_interface (info, i);
1106 : 0 : xml_start_element (file, "implements");
1107 : 0 : write_type_name_attribute (ns, (GIBaseInfo *)imp, "name", file);
1108 : 0 : xml_end_element (file, "implements");
1109 : 0 : gi_base_info_unref ((GIBaseInfo*)imp);
1110 : : }
1111 : : }
1112 : :
1113 [ # # ]: 0 : for (unsigned int i = 0; i < gi_object_info_get_n_fields (info); i++)
1114 : : {
1115 : 0 : GIFieldInfo *field = gi_object_info_get_field (info, i);
1116 : 0 : write_field_info (ns, field, NULL, file);
1117 : 0 : gi_base_info_unref ((GIBaseInfo *)field);
1118 : : }
1119 : :
1120 [ # # ]: 0 : for (unsigned int i = 0; i < gi_object_info_get_n_methods (info); i++)
1121 : : {
1122 : 0 : GIFunctionInfo *function = gi_object_info_get_method (info, i);
1123 : 0 : write_function_info (ns, function, file);
1124 : 0 : gi_base_info_unref ((GIBaseInfo *)function);
1125 : : }
1126 : :
1127 [ # # ]: 0 : for (unsigned int i = 0; i < gi_object_info_get_n_properties (info); i++)
1128 : : {
1129 : 0 : GIPropertyInfo *prop = gi_object_info_get_property (info, i);
1130 : 0 : write_property_info (ns, prop, file);
1131 : 0 : gi_base_info_unref ((GIBaseInfo *)prop);
1132 : : }
1133 : :
1134 [ # # ]: 0 : for (unsigned int i = 0; i < gi_object_info_get_n_signals (info); i++)
1135 : : {
1136 : 0 : GISignalInfo *signal = gi_object_info_get_signal (info, i);
1137 : 0 : write_signal_info (ns, signal, file);
1138 : 0 : gi_base_info_unref ((GIBaseInfo *)signal);
1139 : : }
1140 : :
1141 [ # # ]: 0 : for (unsigned int i = 0; i < gi_object_info_get_n_vfuncs (info); i++)
1142 : : {
1143 : 0 : GIVFuncInfo *vfunc = gi_object_info_get_vfunc (info, i);
1144 : 0 : write_vfunc_info (ns, vfunc, file);
1145 : 0 : gi_base_info_unref ((GIBaseInfo *)vfunc);
1146 : : }
1147 : :
1148 [ # # ]: 0 : for (unsigned int i = 0; i < gi_object_info_get_n_constants (info); i++)
1149 : : {
1150 : 0 : GIConstantInfo *constant = gi_object_info_get_constant (info, i);
1151 : 0 : write_constant_info (ns, constant, file);
1152 : 0 : gi_base_info_unref ((GIBaseInfo *)constant);
1153 : : }
1154 : :
1155 : 0 : xml_end_element (file, "class");
1156 : 0 : }
1157 : :
1158 : : static void
1159 : 0 : write_interface_info (const char *ns,
1160 : : GIInterfaceInfo *info,
1161 : : Xml *file)
1162 : : {
1163 : : const char *name;
1164 : : const char *type_name;
1165 : : const char *type_init;
1166 : : GIStructInfo *class_struct;
1167 : : gboolean deprecated;
1168 : :
1169 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
1170 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
1171 : :
1172 : 0 : type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
1173 : 0 : type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
1174 : 0 : xml_start_element (file, "interface");
1175 : 0 : xml_printf (file, " name=\"%s\" glib:type-name=\"%s\" glib:get-type=\"%s\"",
1176 : : name, type_name, type_init);
1177 : :
1178 : 0 : class_struct = gi_interface_info_get_iface_struct (info);
1179 [ # # ]: 0 : if (class_struct)
1180 : : {
1181 : 0 : write_type_name_attribute (ns, (GIBaseInfo*) class_struct, "glib:type-struct", file);
1182 : 0 : gi_base_info_unref ((GIBaseInfo*)class_struct);
1183 : : }
1184 : :
1185 [ # # ]: 0 : if (deprecated)
1186 : 0 : xml_printf (file, " deprecated=\"1\"");
1187 : :
1188 : 0 : write_attributes (file, (GIBaseInfo*) info);
1189 : :
1190 [ # # ]: 0 : if (gi_interface_info_get_n_prerequisites (info) > 0)
1191 : : {
1192 [ # # ]: 0 : for (unsigned int i = 0; i < gi_interface_info_get_n_prerequisites (info); i++)
1193 : : {
1194 : 0 : GIBaseInfo *req = gi_interface_info_get_prerequisite (info, i);
1195 : :
1196 : 0 : xml_start_element (file, "prerequisite");
1197 : 0 : write_type_name_attribute (ns, req, "name", file);
1198 : :
1199 : 0 : xml_end_element_unchecked (file);
1200 : 0 : gi_base_info_unref (req);
1201 : : }
1202 : : }
1203 : :
1204 [ # # ]: 0 : for (unsigned int i = 0; i < gi_interface_info_get_n_methods (info); i++)
1205 : : {
1206 : 0 : GIFunctionInfo *function = gi_interface_info_get_method (info, i);
1207 : 0 : write_function_info (ns, function, file);
1208 : 0 : gi_base_info_unref ((GIBaseInfo *)function);
1209 : : }
1210 : :
1211 [ # # ]: 0 : for (unsigned int i = 0; i < gi_interface_info_get_n_properties (info); i++)
1212 : : {
1213 : 0 : GIPropertyInfo *prop = gi_interface_info_get_property (info, i);
1214 : 0 : write_property_info (ns, prop, file);
1215 : 0 : gi_base_info_unref ((GIBaseInfo *)prop);
1216 : : }
1217 : :
1218 [ # # ]: 0 : for (unsigned int i = 0; i < gi_interface_info_get_n_signals (info); i++)
1219 : : {
1220 : 0 : GISignalInfo *signal = gi_interface_info_get_signal (info, i);
1221 : 0 : write_signal_info (ns, signal, file);
1222 : 0 : gi_base_info_unref ((GIBaseInfo *)signal);
1223 : : }
1224 : :
1225 [ # # ]: 0 : for (unsigned int i = 0; i < gi_interface_info_get_n_vfuncs (info); i++)
1226 : : {
1227 : 0 : GIVFuncInfo *vfunc = gi_interface_info_get_vfunc (info, i);
1228 : 0 : write_vfunc_info (ns, vfunc, file);
1229 : 0 : gi_base_info_unref ((GIBaseInfo *)vfunc);
1230 : : }
1231 : :
1232 [ # # ]: 0 : for (unsigned int i = 0; i < gi_interface_info_get_n_constants (info); i++)
1233 : : {
1234 : 0 : GIConstantInfo *constant = gi_interface_info_get_constant (info, i);
1235 : 0 : write_constant_info (ns, constant, file);
1236 : 0 : gi_base_info_unref ((GIBaseInfo *)constant);
1237 : : }
1238 : :
1239 : 0 : xml_end_element (file, "interface");
1240 : 0 : }
1241 : :
1242 : : static void
1243 : 0 : write_union_info (const char *ns,
1244 : : GIUnionInfo *info,
1245 : : Xml *file)
1246 : : {
1247 : : const char *name;
1248 : : const char *type_name;
1249 : : const char *type_init;
1250 : : const char *func;
1251 : : gboolean deprecated;
1252 : : size_t size;
1253 : :
1254 : 0 : name = gi_base_info_get_name ((GIBaseInfo *)info);
1255 : 0 : deprecated = gi_base_info_is_deprecated ((GIBaseInfo *)info);
1256 : :
1257 : 0 : type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
1258 : 0 : type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
1259 : :
1260 : : /* FIXME: Add support for boxed unions */
1261 : 0 : xml_start_element (file, "union");
1262 : 0 : xml_printf (file, " name=\"%s\"", name);
1263 : :
1264 [ # # ]: 0 : if (type_name)
1265 : 0 : xml_printf (file, " type-name=\"%s\" get-type=\"%s\"", type_name, type_init);
1266 : :
1267 [ # # ]: 0 : if (deprecated)
1268 : 0 : xml_printf (file, " deprecated=\"1\"");
1269 : :
1270 : 0 : size = gi_union_info_get_size (info);
1271 [ # # ]: 0 : if (file->show_all)
1272 : 0 : xml_printf (file, " size=\"%" G_GSIZE_FORMAT "\"", size);
1273 : :
1274 : 0 : func = gi_union_info_get_copy_function_name (info);
1275 [ # # ]: 0 : if (func)
1276 : 0 : xml_printf (file, " copy-function=\"%s\"", func);
1277 : :
1278 : 0 : func = gi_union_info_get_free_function_name (info);
1279 [ # # ]: 0 : if (func)
1280 : 0 : xml_printf (file, " free-function=\"%s\"", func);
1281 : :
1282 : 0 : write_attributes (file, (GIBaseInfo*) info);
1283 : :
1284 [ # # ]: 0 : if (gi_union_info_is_discriminated (info))
1285 : : {
1286 : : size_t offset;
1287 : : GITypeInfo *type;
1288 : :
1289 : 0 : gi_union_info_get_discriminator_offset (info, &offset);
1290 : 0 : type = gi_union_info_get_discriminator_type (info);
1291 : :
1292 : 0 : xml_start_element (file, "discriminator");
1293 : 0 : xml_printf (file, " offset=\"%zu\" type=\"", offset);
1294 : 0 : write_type_info (ns, type, file);
1295 : 0 : xml_end_element (file, "discriminator");
1296 : 0 : gi_base_info_unref ((GIBaseInfo *)type);
1297 : : }
1298 : :
1299 [ # # ]: 0 : for (unsigned int i = 0; i < gi_union_info_get_n_fields (info); i++)
1300 : : {
1301 : 0 : GIFieldInfo *field = gi_union_info_get_field (info, i);
1302 : 0 : GIConstantInfo *constant = gi_union_info_get_discriminator (info, i);
1303 : 0 : write_field_info (ns, field, constant, file);
1304 : 0 : gi_base_info_unref ((GIBaseInfo *)field);
1305 [ # # ]: 0 : if (constant)
1306 : 0 : gi_base_info_unref ((GIBaseInfo *)constant);
1307 : : }
1308 : :
1309 [ # # ]: 0 : for (unsigned int i = 0; i < gi_union_info_get_n_methods (info); i++)
1310 : : {
1311 : 0 : GIFunctionInfo *function = gi_union_info_get_method (info, i);
1312 : 0 : write_function_info (ns, function, file);
1313 : 0 : gi_base_info_unref ((GIBaseInfo *)function);
1314 : : }
1315 : :
1316 : 0 : xml_end_element (file, "union");
1317 : 0 : }
1318 : :
1319 : :
1320 : : /**
1321 : : * gi_ir_writer_write:
1322 : : * @repository: repository containing @ns
1323 : : * @filename: (type filename): filename to write to
1324 : : * @ns: GIR namespace to write
1325 : : * @needs_prefix: if the filename needs prefixing
1326 : : * @show_all: if field size calculations should be included
1327 : : *
1328 : : * Writes the output of a typelib represented by @ns
1329 : : * into a GIR xml file named @filename.
1330 : : *
1331 : : * Since: 2.80
1332 : : */
1333 : : void
1334 : 0 : gi_ir_writer_write (GIRepository *repository,
1335 : : const char *filename,
1336 : : const char *ns,
1337 : : gboolean needs_prefix,
1338 : : gboolean show_all)
1339 : : {
1340 : : FILE *ofile;
1341 : : size_t i;
1342 : : unsigned int j;
1343 : : char **dependencies;
1344 : : Xml *xml;
1345 : :
1346 [ # # ]: 0 : if (filename == NULL)
1347 : 0 : ofile = stdout;
1348 : : else
1349 : : {
1350 : : char *full_filename;
1351 : :
1352 [ # # ]: 0 : if (needs_prefix)
1353 : 0 : full_filename = g_strdup_printf ("%s-%s", ns, filename);
1354 : : else
1355 : 0 : full_filename = g_strdup (filename);
1356 : 0 : ofile = g_fopen (filename, "w");
1357 : :
1358 [ # # ]: 0 : if (ofile == NULL)
1359 : : {
1360 : 0 : g_fprintf (stderr, "failed to open '%s': %s\n",
1361 : 0 : full_filename, g_strerror (errno));
1362 : 0 : g_free (full_filename);
1363 : :
1364 : 0 : return;
1365 : : }
1366 : :
1367 : 0 : g_free (full_filename);
1368 : : }
1369 : :
1370 : 0 : xml = xml_open (ofile);
1371 : 0 : xml->show_all = show_all;
1372 : 0 : xml_printf (xml, "<?xml version=\"1.0\"?>\n");
1373 : 0 : xml_start_element (xml, "repository");
1374 : 0 : xml_printf (xml, " version=\"1.0\"\n"
1375 : : " xmlns=\"http://www.gtk.org/introspection/core/1.0\"\n"
1376 : : " xmlns:c=\"http://www.gtk.org/introspection/c/1.0\"\n"
1377 : : " xmlns:glib=\"http://www.gtk.org/introspection/glib/1.0\"");
1378 : :
1379 : 0 : dependencies = gi_repository_get_immediate_dependencies (repository, ns, NULL);
1380 [ # # ]: 0 : if (dependencies != NULL)
1381 : : {
1382 [ # # ]: 0 : for (i = 0; dependencies[i]; i++)
1383 : : {
1384 : 0 : char **parts = g_strsplit (dependencies[i], "-", 2);
1385 : 0 : xml_start_element (xml, "include");
1386 : 0 : xml_printf (xml, " name=\"%s\" version=\"%s\"", parts[0], parts[1]);
1387 : 0 : xml_end_element (xml, "include");
1388 : 0 : g_strfreev (parts);
1389 : : }
1390 : : }
1391 : :
1392 : : if (TRUE)
1393 : : {
1394 : : const char * const *shared_libraries;
1395 : : const char *c_prefix;
1396 : 0 : const char *cur_ns = ns;
1397 : : const char *cur_version;
1398 : : unsigned int n_infos;
1399 : :
1400 : 0 : cur_version = gi_repository_get_version (repository, cur_ns);
1401 : :
1402 : 0 : shared_libraries = gi_repository_get_shared_libraries (repository, cur_ns, NULL);
1403 : 0 : c_prefix = gi_repository_get_c_prefix (repository, cur_ns);
1404 : 0 : xml_start_element (xml, "namespace");
1405 : 0 : xml_printf (xml, " name=\"%s\" version=\"%s\"", cur_ns, cur_version);
1406 [ # # ]: 0 : if (shared_libraries != NULL)
1407 : : {
1408 : 0 : char *shared_libraries_str = g_strjoinv (",", (char **) shared_libraries);
1409 : 0 : xml_printf (xml, " shared-library=\"%s\"", shared_libraries_str);
1410 : 0 : g_free (shared_libraries_str);
1411 : : }
1412 [ # # ]: 0 : if (c_prefix)
1413 : 0 : xml_printf (xml, " c:prefix=\"%s\"", c_prefix);
1414 : :
1415 : 0 : n_infos = gi_repository_get_n_infos (repository, cur_ns);
1416 [ # # ]: 0 : for (j = 0; j < n_infos; j++)
1417 : : {
1418 : 0 : GIBaseInfo *info = gi_repository_get_info (repository, cur_ns, j);
1419 : :
1420 [ # # # # : 0 : if (GI_IS_FUNCTION_INFO (info))
# # # # ]
1421 : 0 : write_function_info (ns, (GIFunctionInfo *)info, xml);
1422 [ # # # # : 0 : else if (GI_IS_CALLBACK_INFO (info))
# # # # ]
1423 : 0 : write_callback_info (ns, (GICallbackInfo *)info, xml);
1424 [ # # # # : 0 : else if (GI_IS_STRUCT_INFO (info))
# # # # ]
1425 : 0 : write_struct_info (ns, (GIStructInfo *)info, xml);
1426 [ # # # # : 0 : else if (GI_IS_UNION_INFO (info))
# # # # ]
1427 : 0 : write_union_info (ns, (GIUnionInfo *)info, xml);
1428 [ # # # # : 0 : else if (GI_IS_ENUM_INFO (info) ||
# # # # ]
1429 [ # # # # : 0 : GI_IS_FLAGS_INFO (info))
# # # # ]
1430 : 0 : write_enum_info (ns, (GIEnumInfo *)info, xml);
1431 [ # # # # : 0 : else if (GI_IS_CONSTANT_INFO (info))
# # # # ]
1432 : 0 : write_constant_info (ns, (GIConstantInfo *)info, xml);
1433 [ # # # # : 0 : else if (GI_IS_OBJECT_INFO (info))
# # # # ]
1434 : 0 : write_object_info (ns, (GIObjectInfo *)info, xml);
1435 [ # # # # : 0 : else if (GI_IS_INTERFACE_INFO (info))
# # # # ]
1436 : 0 : write_interface_info (ns, (GIInterfaceInfo *)info, xml);
1437 : : else
1438 : 0 : g_error ("unknown info type %s", g_type_name (G_TYPE_FROM_INSTANCE (info)));
1439 : :
1440 : 0 : gi_base_info_unref (info);
1441 : : }
1442 : :
1443 : 0 : xml_end_element (xml, "namespace");
1444 : : }
1445 : :
1446 : 0 : xml_end_element (xml, "repository");
1447 : :
1448 : 0 : xml_free (xml);
1449 : : }
|