3 # gtk-doc - GTK DocBook documentation generator.
4 # Copyright (C) 1998 Damon Chaplin
5 # 2007-2016 Stefan Sauer
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 The scangobj tool gets information about object hierarchies and signals by
24 compiling and running a small C program. CFLAGS and LDFLAGS must be set
25 appropriately before running this script.
33 from . import common
, config
41 #include <glib-object.h>
44 QUERY_CHILD_PROPS_PROTOTYPE
= "extern GParamSpec** %s (gpointer class, guint *n_properties);"
46 QUERY_CHILD_PROPS_CODE
= """
48 properties = %s (class, &n_properties);
58 #ifdef GTK_IS_WIDGET_CLASS
61 static GType object_types[$ntypes];
64 get_object_types (void)
66 gpointer g_object_class;
70 object_types[i] = G_TYPE_INVALID;
72 /* reference the GObjectClass to initialize the param spec pool
73 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
74 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
76 /* Need to make sure all the types are loaded in and initialize
77 * their signals and properties.
79 for (i=0; object_types[i]; i++) {
80 if (G_TYPE_IS_CLASSED (object_types[i]))
81 g_type_class_ref (object_types[i]);
82 if (G_TYPE_IS_INTERFACE (object_types[i]))
83 g_type_default_interface_ref (object_types[i]);
86 g_type_class_unref (g_object_class);
92 * This uses GObject type functions to output signal prototypes and the object
96 /* The output files */
97 const gchar *signals_filename = "$new_signals_filename";
98 const gchar *hierarchy_filename = "$new_hierarchy_filename";
99 const gchar *interfaces_filename = "$new_interfaces_filename";
100 const gchar *prerequisites_filename = "$new_prerequisites_filename";
101 const gchar *args_filename = "$new_args_filename";
103 static void output_signals (void);
104 static void output_object_signals (FILE *fp,
106 static void output_object_signal (FILE *fp,
107 const gchar *object_class_name,
109 static const gchar * get_type_name (GType type,
110 gboolean * is_pointer);
111 static void output_object_hierarchy (void);
112 static void output_hierarchy (FILE *fp,
116 static void output_object_interfaces (void);
117 static void output_interfaces (FILE *fp,
120 static void output_interface_prerequisites (void);
121 static void output_prerequisites (FILE *fp,
124 static void output_args (void);
125 static void output_object_args (FILE *fp, GType object_type);
128 main (int argc, char *argv[])
135 output_object_hierarchy ();
136 output_object_interfaces ();
137 output_interface_prerequisites ();
144 output_signals (void)
149 fp = fopen (signals_filename, "w");
151 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
155 for (i = 0; object_types[i]; i++)
156 output_object_signals (fp, object_types[i]);
162 compare_signals (const void *a, const void *b)
164 const guint *signal_a = a;
165 const guint *signal_b = b;
167 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
170 /* This outputs all the signals of one object. */
172 output_object_signals (FILE *fp, GType object_type)
174 const gchar *object_class_name;
175 guint *signals, n_signals;
178 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
179 G_TYPE_IS_INTERFACE (object_type)) {
181 object_class_name = g_type_name (object_type);
183 signals = g_signal_list_ids (object_type, &n_signals);
184 qsort (signals, n_signals, sizeof (guint), compare_signals);
186 for (sig = 0; sig < n_signals; sig++) {
187 output_object_signal (fp, object_class_name, signals[sig]);
193 /* This outputs one signal. */
195 output_object_signal (FILE *fp,
196 const gchar *object_name,
199 GSignalQuery query_info;
200 const gchar *type_name, *ret_type, *object_arg, *arg_name;
201 gchar *pos, *object_arg_lower;
205 gint param_num, widget_num, event_num, callback_num;
207 gchar signal_name[128];
210 /* g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
213 widget_num = event_num = callback_num = 0;
215 g_signal_query (signal_id, &query_info);
217 /* Output the signal object type and the argument name. We assume the
218 * type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
219 * convert to lower case for the argument name. */
221 sprintf (pos, "%s ", object_name);
224 /* Try to come up with a sensible variable name for the first arg
225 * It chops off 2 know prefixes :/ and makes the name lowercase
226 * It should replace lowercase -> uppercase with '_'
227 * GFileMonitor -> file_monitor
228 * GIOExtensionPoint -> extension_point
229 * GtkTreeView -> tree_view
230 * if 2nd char is upper case too
231 * search for first lower case and go back one char
233 * search for next upper case
235 if (!strncmp (object_name, "Gtk", 3))
236 object_arg = object_name + 3;
237 else if (!strncmp (object_name, "Gnome", 5))
238 object_arg = object_name + 5;
240 object_arg = object_name;
242 object_arg_lower = g_ascii_strdown (object_arg, -1);
243 sprintf (pos, "*%s\\n", object_arg_lower);
245 if (!strncmp (object_arg_lower, "widget", 6))
247 g_free(object_arg_lower);
249 /* Convert signal name to use underscores rather than dashes '-'. */
250 strncpy (signal_name, query_info.signal_name, 127);
251 signal_name[127] = '\\0';
252 for (i = 0; signal_name[i]; i++) {
253 if (signal_name[i] == '-')
254 signal_name[i] = '_';
257 /* Output the signal parameters. */
258 for (param = 0; param < query_info.n_params; param++) {
259 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
261 /* Most arguments to the callback are called "arg1", "arg2", etc.
262 GtkWidgets are called "widget", "widget2", ...
263 GtkCallbacks are called "callback", "callback2", ... */
264 if (!strcmp (type_name, "GtkWidget")) {
266 arg_num = &widget_num;
268 else if (!strcmp (type_name, "GtkCallback")
269 || !strcmp (type_name, "GtkCCallback")) {
270 arg_name = "callback";
271 arg_num = &callback_num;
275 arg_num = ¶m_num;
277 sprintf (pos, "%s ", type_name);
280 if (!arg_num || *arg_num == 0)
281 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
283 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
296 /* We use one-character flags for simplicity. */
297 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
299 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
301 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
303 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
305 if (query_info.signal_flags & G_SIGNAL_DETAILED)
307 if (query_info.signal_flags & G_SIGNAL_ACTION)
309 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
313 /* Output the return type and function name. */
314 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
317 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
318 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
322 /* Returns the type name to use for a signal argument or return value, given
323 the GtkType from the signal info. It also sets is_pointer to TRUE if the
324 argument needs a '*' since it is a pointer. */
326 get_type_name (GType type, gboolean * is_pointer)
328 const gchar *type_name;
331 type_name = g_type_name (type);
345 /* These all have normal C type names so they are OK. */
349 /* A GtkString is really a gchar*. */
355 /* We use a gint for both of these. Hopefully a subtype with a decent
356 name will be registered and used instead, as GTK+ does itself. */
360 /* The boxed type shouldn't be used itself, only subtypes. Though we
361 return 'gpointer' just in case. */
365 /* A GParam is really a GParamSpec*. */
369 #if GLIB_CHECK_VERSION (2, 25, 9)
379 /* For all GObject subclasses we can use the class name with a "*",
380 e.g. 'GtkWidget *'. */
381 if (g_type_is_a (type, G_TYPE_OBJECT))
384 /* Also catch non GObject root types */
385 if (G_TYPE_IS_CLASSED (type))
388 /* All boxed subtypes will be pointers as well. */
389 /* Exception: GStrv */
390 if (g_type_is_a (type, G_TYPE_BOXED) &&
391 !g_type_is_a (type, G_TYPE_STRV))
394 /* All pointer subtypes will be pointers as well. */
395 if (g_type_is_a (type, G_TYPE_POINTER))
398 /* But enums are not */
399 if (g_type_is_a (type, G_TYPE_ENUM) ||
400 g_type_is_a (type, G_TYPE_FLAGS))
407 /* This outputs the hierarchy of all objects which have been initialized,
408 i.e. by calling their XXX_get_type() initialization function. */
410 output_object_hierarchy (void)
415 GType root_types[$ntypes] = { G_TYPE_INVALID, };
417 fp = fopen (hierarchy_filename, "w");
419 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
422 output_hierarchy (fp, G_TYPE_OBJECT, 0);
423 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
425 for (i=0; object_types[i]; i++) {
426 root = object_types[i];
427 while ((type = g_type_parent (root))) {
430 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
431 for (j=0; root_types[j]; j++) {
432 if (root == root_types[j]) {
433 root = G_TYPE_INVALID; break;
437 root_types[j] = root;
438 output_hierarchy (fp, root, 0);
446 /* This is called recursively to output the hierarchy of a object. */
448 output_hierarchy (FILE *fp,
459 for (i = 0; i < level; i++)
461 fprintf (fp, "%s\\n", g_type_name (type));
463 children = g_type_children (type, &n_children);
465 for (i=0; i < n_children; i++)
466 output_hierarchy (fp, children[i], level + 1);
471 static void output_object_interfaces (void)
476 fp = fopen (interfaces_filename, "w");
478 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
481 output_interfaces (fp, G_TYPE_OBJECT);
483 for (i = 0; object_types[i]; i++) {
484 if (!g_type_parent (object_types[i]) &&
485 (object_types[i] != G_TYPE_OBJECT) &&
486 G_TYPE_IS_INSTANTIATABLE (object_types[i])) {
487 output_interfaces (fp, object_types[i]);
494 output_interfaces (FILE *fp,
498 GType *children, *interfaces;
499 guint n_children, n_interfaces;
504 interfaces = g_type_interfaces (type, &n_interfaces);
506 if (n_interfaces > 0) {
507 fprintf (fp, "%s", g_type_name (type));
508 for (i=0; i < n_interfaces; i++)
509 fprintf (fp, " %s", g_type_name (interfaces[i]));
514 children = g_type_children (type, &n_children);
516 for (i=0; i < n_children; i++)
517 output_interfaces (fp, children[i]);
522 static void output_interface_prerequisites (void)
526 fp = fopen (prerequisites_filename, "w");
528 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
531 output_prerequisites (fp, G_TYPE_INTERFACE);
536 output_prerequisites (FILE *fp,
539 #if GLIB_CHECK_VERSION(2,1,0)
541 GType *children, *prerequisites;
542 guint n_children, n_prerequisites;
547 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
549 if (n_prerequisites > 0) {
550 fprintf (fp, "%s", g_type_name (type));
551 for (i=0; i < n_prerequisites; i++)
552 fprintf (fp, " %s", g_type_name (prerequisites[i]));
555 g_free (prerequisites);
557 children = g_type_children (type, &n_children);
559 for (i=0; i < n_children; i++)
560 output_prerequisites (fp, children[i]);
572 fp = fopen (args_filename, "w");
574 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
578 for (i = 0; object_types[i]; i++) {
579 output_object_args (fp, object_types[i]);
586 compare_param_specs (const void *a, const void *b)
588 GParamSpec *spec_a = *(GParamSpec **)a;
589 GParamSpec *spec_b = *(GParamSpec **)b;
591 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
594 /* Its common to have unsigned properties restricted
595 * to the signed range. Therefore we make this look
596 * a bit nicer by spelling out the max constants.
599 /* Don't use "==" with floats, it might trigger a gcc warning. */
600 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
603 describe_double_constant (gdouble value)
607 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
608 desc = g_strdup ("G_MAXDOUBLE");
609 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
610 desc = g_strdup ("G_MINDOUBLE");
611 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
612 desc = g_strdup ("-G_MAXDOUBLE");
613 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
614 desc = g_strdup ("G_MAXFLOAT");
615 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
616 desc = g_strdup ("G_MINFLOAT");
617 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
618 desc = g_strdup ("-G_MAXFLOAT");
620 /* make sure floats are output with a decimal dot irrespective of
621 * current locale. Use formatd since we want human-readable numbers
622 * and do not need the exact same bit representation when deserialising */
623 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
624 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
631 describe_signed_constant (gsize size, gint64 value)
637 if (sizeof (int) == 2) {
638 if (value == G_MAXINT)
639 desc = g_strdup ("G_MAXINT");
640 else if (value == G_MININT)
641 desc = g_strdup ("G_MININT");
645 if (sizeof (int) == 4) {
646 if (value == G_MAXINT)
647 desc = g_strdup ("G_MAXINT");
648 else if (value == G_MININT)
649 desc = g_strdup ("G_MININT");
651 if (value == G_MAXLONG)
652 desc = g_strdup ("G_MAXLONG");
653 else if (value == G_MINLONG)
654 desc = g_strdup ("G_MINLONG");
657 if (value == G_MAXINT64)
658 desc = g_strdup ("G_MAXINT64");
659 else if (value == G_MININT64)
660 desc = g_strdup ("G_MININT64");
666 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
672 describe_unsigned_constant (gsize size, guint64 value)
678 if (sizeof (int) == 2) {
679 if (value == (guint64)G_MAXINT)
680 desc = g_strdup ("G_MAXINT");
681 else if (value == G_MAXUINT)
682 desc = g_strdup ("G_MAXUINT");
686 if (sizeof (int) == 4) {
687 if (value == (guint64)G_MAXINT)
688 desc = g_strdup ("G_MAXINT");
689 else if (value == G_MAXUINT)
690 desc = g_strdup ("G_MAXUINT");
692 if (value == (guint64)G_MAXLONG)
693 desc = g_strdup ("G_MAXLONG");
694 else if (value == G_MAXULONG)
695 desc = g_strdup ("G_MAXULONG");
698 if (value == G_MAXINT64)
699 desc = g_strdup ("G_MAXINT64");
700 else if (value == G_MAXUINT64)
701 desc = g_strdup ("G_MAXUINT64");
707 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
713 describe_type (GParamSpec *spec)
719 if (G_IS_PARAM_SPEC_CHAR (spec)) {
720 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
722 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
723 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
724 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
725 desc = g_strdup ("");
726 else if (pspec->minimum == G_MININT8)
727 desc = g_strdup_printf ("<= %s", upper);
728 else if (pspec->maximum == G_MAXINT8)
729 desc = g_strdup_printf (">= %s", lower);
731 desc = g_strdup_printf ("[%s,%s]", lower, upper);
735 else if (G_IS_PARAM_SPEC_UCHAR (spec)) {
736 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
738 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
739 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
740 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
741 desc = g_strdup ("");
742 else if (pspec->minimum == 0)
743 desc = g_strdup_printf ("<= %s", upper);
744 else if (pspec->maximum == G_MAXUINT8)
745 desc = g_strdup_printf (">= %s", lower);
747 desc = g_strdup_printf ("[%s,%s]", lower, upper);
751 else if (G_IS_PARAM_SPEC_INT (spec)) {
752 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
754 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
755 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
756 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
757 desc = g_strdup ("");
758 else if (pspec->minimum == G_MININT)
759 desc = g_strdup_printf ("<= %s", upper);
760 else if (pspec->maximum == G_MAXINT)
761 desc = g_strdup_printf (">= %s", lower);
763 desc = g_strdup_printf ("[%s,%s]", lower, upper);
767 else if (G_IS_PARAM_SPEC_UINT (spec)) {
768 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
770 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
771 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
772 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
773 desc = g_strdup ("");
774 else if (pspec->minimum == 0)
775 desc = g_strdup_printf ("<= %s", upper);
776 else if (pspec->maximum == G_MAXUINT)
777 desc = g_strdup_printf (">= %s", lower);
779 desc = g_strdup_printf ("[%s,%s]", lower, upper);
783 else if (G_IS_PARAM_SPEC_LONG (spec)) {
784 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
786 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
787 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
788 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
789 desc = g_strdup ("");
790 else if (pspec->minimum == G_MINLONG)
791 desc = g_strdup_printf ("<= %s", upper);
792 else if (pspec->maximum == G_MAXLONG)
793 desc = g_strdup_printf (">= %s", lower);
795 desc = g_strdup_printf ("[%s,%s]", lower, upper);
799 else if (G_IS_PARAM_SPEC_ULONG (spec)) {
800 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
802 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
803 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
804 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
805 desc = g_strdup ("");
806 else if (pspec->minimum == 0)
807 desc = g_strdup_printf ("<= %s", upper);
808 else if (pspec->maximum == G_MAXULONG)
809 desc = g_strdup_printf (">= %s", lower);
811 desc = g_strdup_printf ("[%s,%s]", lower, upper);
815 else if (G_IS_PARAM_SPEC_INT64 (spec)) {
816 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
818 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
819 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
820 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
821 desc = g_strdup ("");
822 else if (pspec->minimum == G_MININT64)
823 desc = g_strdup_printf ("<= %s", upper);
824 else if (pspec->maximum == G_MAXINT64)
825 desc = g_strdup_printf (">= %s", lower);
827 desc = g_strdup_printf ("[%s,%s]", lower, upper);
831 else if (G_IS_PARAM_SPEC_UINT64 (spec)) {
832 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
834 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
835 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
836 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
837 desc = g_strdup ("");
838 else if (pspec->minimum == 0)
839 desc = g_strdup_printf ("<= %s", upper);
840 else if (pspec->maximum == G_MAXUINT64)
841 desc = g_strdup_printf (">= %s", lower);
843 desc = g_strdup_printf ("[%s,%s]", lower, upper);
847 else if (G_IS_PARAM_SPEC_FLOAT (spec)) {
848 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
850 lower = describe_double_constant (pspec->minimum);
851 upper = describe_double_constant (pspec->maximum);
852 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT)) {
853 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
854 desc = g_strdup ("");
856 desc = g_strdup_printf ("<= %s", upper);
858 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
859 desc = g_strdup_printf (">= %s", lower);
861 desc = g_strdup_printf ("[%s,%s]", lower, upper);
865 else if (G_IS_PARAM_SPEC_DOUBLE (spec)) {
866 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
868 lower = describe_double_constant (pspec->minimum);
869 upper = describe_double_constant (pspec->maximum);
870 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE)) {
871 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
872 desc = g_strdup ("");
874 desc = g_strdup_printf ("<= %s", upper);
876 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
877 desc = g_strdup_printf (">= %s", lower);
879 desc = g_strdup_printf ("[%s,%s]", lower, upper);
883 #if GLIB_CHECK_VERSION (2, 12, 0)
884 else if (G_IS_PARAM_SPEC_GTYPE (spec)) {
885 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
888 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
891 #if GLIB_CHECK_VERSION (2, 25, 9)
892 else if (G_IS_PARAM_SPEC_VARIANT (spec)) {
893 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
896 variant_type = g_variant_type_dup_string (pspec->type);
897 desc = g_strdup_printf ("GVariant<%s>", variant_type);
898 g_free (variant_type);
902 desc = g_strdup ("");
909 describe_default (GParamSpec *spec)
913 if (G_IS_PARAM_SPEC_CHAR (spec)) {
914 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
916 desc = g_strdup_printf ("%d", pspec->default_value);
918 else if (G_IS_PARAM_SPEC_UCHAR (spec)) {
919 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
921 desc = g_strdup_printf ("%u", pspec->default_value);
923 else if (G_IS_PARAM_SPEC_BOOLEAN (spec)) {
924 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
926 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
928 else if (G_IS_PARAM_SPEC_INT (spec)) {
929 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
931 desc = g_strdup_printf ("%d", pspec->default_value);
933 else if (G_IS_PARAM_SPEC_UINT (spec)) {
934 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
936 desc = g_strdup_printf ("%u", pspec->default_value);
938 else if (G_IS_PARAM_SPEC_LONG (spec)) {
939 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
941 desc = g_strdup_printf ("%ld", pspec->default_value);
943 else if (G_IS_PARAM_SPEC_LONG (spec)) {
944 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
946 desc = g_strdup_printf ("%lu", pspec->default_value);
948 else if (G_IS_PARAM_SPEC_INT64 (spec)) {
949 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
951 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
953 else if (G_IS_PARAM_SPEC_UINT64 (spec))
955 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
957 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
959 else if (G_IS_PARAM_SPEC_UNICHAR (spec)) {
960 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
962 if (g_unichar_isprint (pspec->default_value))
963 desc = g_strdup_printf ("'%c'", pspec->default_value);
965 desc = g_strdup_printf ("%u", pspec->default_value);
967 else if (G_IS_PARAM_SPEC_ENUM (spec)) {
968 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
970 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
972 desc = g_strdup_printf ("%s", value->value_name);
974 desc = g_strdup_printf ("%d", pspec->default_value);
976 else if (G_IS_PARAM_SPEC_FLAGS (spec)) {
977 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
981 default_value = pspec->default_value;
982 acc = g_string_new ("");
984 while (default_value) {
985 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
991 g_string_append (acc, " | ");
992 g_string_append (acc, value->value_name);
994 default_value &= ~value->value;
997 if (default_value == 0)
998 desc = g_string_free (acc, FALSE);
1000 desc = g_strdup_printf ("%d", pspec->default_value);
1001 g_string_free (acc, TRUE);
1004 else if (G_IS_PARAM_SPEC_FLOAT (spec)) {
1005 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1007 /* make sure floats are output with a decimal dot irrespective of
1008 * current locale. Use formatd since we want human-readable numbers
1009 * and do not need the exact same bit representation when deserialising */
1010 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1011 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1012 pspec->default_value);
1014 else if (G_IS_PARAM_SPEC_DOUBLE (spec)) {
1015 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1017 /* make sure floats are output with a decimal dot irrespective of
1018 * current locale. Use formatd since we want human-readable numbers
1019 * and do not need the exact same bit representation when deserialising */
1020 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1021 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1022 pspec->default_value);
1024 else if (G_IS_PARAM_SPEC_STRING (spec)) {
1025 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1027 if (pspec->default_value) {
1028 gchar *esc = g_strescape (pspec->default_value, NULL);
1029 desc = g_strdup_printf ("\\"%s\\"", esc);
1033 desc = g_strdup_printf ("NULL");
1035 #if GLIB_CHECK_VERSION (2, 25, 9)
1036 else if (G_IS_PARAM_SPEC_VARIANT (spec)) {
1037 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1039 if (pspec->default_value)
1040 desc = g_variant_print (pspec->default_value, TRUE);
1042 desc = g_strdup ("NULL");
1046 desc = g_strdup ("");
1054 output_object_args (FILE *fp, GType object_type)
1057 const gchar *object_class_name;
1059 gchar flags[16], *pos;
1060 GParamSpec **properties;
1062 gboolean child_prop;
1063 gboolean style_prop;
1064 gboolean is_pointer;
1065 const gchar *type_name;
1067 gchar *default_value;
1069 if (G_TYPE_IS_OBJECT (object_type)) {
1070 class = g_type_class_peek (object_type);
1074 properties = g_object_class_list_properties (class, &n_properties);
1076 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1077 else if (G_TYPE_IS_INTERFACE (object_type)) {
1078 class = g_type_default_interface_ref (object_type);
1083 properties = g_object_interface_list_properties (class, &n_properties);
1089 object_class_name = g_type_name (object_type);
1095 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1096 for (arg = 0; arg < n_properties; arg++) {
1097 GParamSpec *spec = properties[arg];
1098 const gchar *nick, *blurb, *dot;
1100 if (spec->owner_type != object_type)
1104 /* We use one-character flags for simplicity. */
1105 if (child_prop && !style_prop)
1109 if (spec->flags & G_PARAM_READABLE)
1111 if (spec->flags & G_PARAM_WRITABLE)
1113 if (spec->flags & G_PARAM_CONSTRUCT)
1115 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1119 nick = g_param_spec_get_nick (spec);
1120 blurb = g_param_spec_get_blurb (spec);
1124 int str_len = strlen (blurb);
1125 if (str_len > 0 && blurb[str_len - 1] != '.')
1129 type_desc = describe_type (spec);
1130 default_value = describe_default (spec);
1131 type_name = get_type_name (spec->value_type, &is_pointer);
1132 fprintf (fp, "<ARG>\\n"
1133 "<NAME>%s::%s</NAME>\\n"
1134 "<TYPE>%s%s</TYPE>\\n"
1135 "<RANGE>%s</RANGE>\\n"
1136 "<FLAGS>%s</FLAGS>\\n"
1137 "<NICK>%s</NICK>\\n"
1138 "<BLURB>%s%s</BLURB>\\n"
1139 "<DEFAULT>%s</DEFAULT>\\n"
1141 object_class_name, g_param_spec_get_name (spec), type_name,
1142 is_pointer ? "*" : "", type_desc, flags, nick ? nick : "(null)",
1143 blurb ? blurb : "(null)", dot, default_value);
1145 g_free (default_value);
1148 g_free (properties);
1150 #ifdef GTK_IS_CONTAINER_CLASS
1151 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1152 properties = gtk_container_class_list_child_properties (class, &n_properties);
1158 #ifdef GTK_IS_CELL_AREA_CLASS
1159 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1160 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1166 #ifdef GTK_IS_WIDGET_CLASS
1167 #if GTK_CHECK_VERSION(2,1,0) && !GTK_CHECK_VERSION(3,89,2)
1168 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1169 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1187 c_file
= options
.module
+ '-scan.c'
1188 output
= open(c_file
, 'w')
1190 base_filename
= os
.path
.join(options
.output_dir
, options
.module
)
1191 old_signals_filename
= base_filename
+ '.signals'
1192 new_signals_filename
= base_filename
+ '.signals.new'
1193 old_hierarchy_filename
= base_filename
+ '.hierarchy'
1194 new_hierarchy_filename
= base_filename
+ '.hierarchy.new'
1195 old_interfaces_filename
= base_filename
+ '.interfaces'
1196 new_interfaces_filename
= base_filename
+ '.interfaces.new'
1197 old_prerequisites_filename
= base_filename
+ '.prerequisites'
1198 new_prerequisites_filename
= base_filename
+ '.prerequisites.new'
1199 old_args_filename
= base_filename
+ '.args'
1200 new_args_filename
= base_filename
+ '.args.new'
1202 # generate a C program to scan the types
1209 for line
in open(options
.types
):
1210 if line
.startswith('#include'):
1212 elif line
.startswith('%') or line
.strip() == '':
1216 get_types
+= ' object_types[i++] = ' + line
+ ' ();\n'
1217 forward_decls
+= 'extern GType ' + line
+ ' (void);\n'
1220 output
.write(COMMON_INCLUDES
)
1223 output
.write(includes
)
1225 output
.write(forward_decls
)
1227 if options
.query_child_properties
:
1228 output
.write(QUERY_CHILD_PROPS_PROTOTYPE
% options
.query_child_properties
)
1230 # substitute local vars in the template
1231 type_init_func
= options
.type_init_func
1232 output
.write(string
.Template(MAIN_CODE
).substitute(locals()))
1234 if options
.query_child_properties
:
1235 output
.write(QUERY_CHILD_PROPS_CODE
% options
.query_child_properties
)
1237 output
.write(MAIN_CODE_END
)
1241 # Compile and run our file
1242 if 'libtool' in options
.cc
:
1243 o_file
= options
.module
+ '-scan.lo'
1245 o_file
= options
.module
+ '-scan.o'
1247 x_file
= options
.module
+ '-scan' + config
.exeext
1250 if not options
.verbose
:
1251 stdout
= ">/dev/null"
1254 command
= '%s %s %s -c -o %s %s' % (options
.cc
, stdout
, options
.cflags
, o_file
, c_file
)
1255 res
= subprocess
.check_call(command
, shell
=True)
1257 logging
.warning('Compilation of scanner failed: %d', res
)
1261 command
= '%s %s %s %s -o %s' % (options
.ld
, stdout
, o_file
, options
.ldflags
, x_file
)
1262 res
= subprocess
.check_call(command
, shell
=True)
1264 logging
.warning('Linking of scanner failed: %d', res
)
1268 command
= '%s ./%s' % (options
.run
, x_file
)
1269 res
= subprocess
.check_call(command
, shell
=True)
1271 logging
.warning('Running scanner failed: %d', res
)
1274 if 'GTK_DOC_KEEP_INTERMEDIATE' not in os
.environ
:
1279 common
.UpdateFileIfChanged(old_signals_filename
, new_signals_filename
, False)
1280 common
.UpdateFileIfChanged(old_hierarchy_filename
, new_hierarchy_filename
, False)
1281 common
.UpdateFileIfChanged(old_interfaces_filename
, new_interfaces_filename
, False)
1282 common
.UpdateFileIfChanged(old_prerequisites_filename
, new_prerequisites_filename
, False)
1283 common
.UpdateFileIfChanged(old_args_filename
, new_args_filename
, False)