X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/185449d25b2f9c93d2928e4745e8aa64d7d9ab9c..4f931a71edce4d7456c233487703a894410fd599:/src/main.c diff --git a/src/main.c b/src/main.c index 9a9a1ac..424f12c 100644 --- a/src/main.c +++ b/src/main.c @@ -1126,6 +1126,29 @@ add_interfaces (void) } } +static void +add_dynamic_interfaces(void) +{ + GList *li; + for (li = ((Class *)class)->interfaces; + li != NULL; + li = li ->next) { + char *name = replace_sep (li->data, '_'); + char *type = make_pre_macro (li->data, "TYPE"); + + out_printf(out, + "\t\tg_type_module_add_interface(\n" + "\t\t\ttype_module,\n" + "\t\t\t%s_type_id,\n" + "\t\t\t%s,\n" + "\t\t\t&%s_info);\n", + funcbase, type, name); + + g_free(type); + g_free(name); + } +} + static void add_get_type(void) { @@ -1174,6 +1197,57 @@ add_get_type(void) "}\n\n"); } +static void +add_dynamic_get_type (void) +{ + out_printf(out, + "static GType %s_type_id;\n\n" + "GType\n" + "%s_get_type (void)\n" + "{\n" + "\treturn %s_type_id;\n" + "}\n\n", + funcbase, funcbase, funcbase); + + out_printf(out, + "void\n" + "%s_register_type (GTypeModule *type_module)\n" + "{\n" + "\tstatic const GTypeInfo info = {\n" + "\t\tsizeof (%sClass),\n" + "\t\t(GBaseInitFunc) NULL,\n" + "\t\t(GBaseFinalizeFunc) NULL,\n" + "\t\t(GClassInitFunc) %s_class_init,\n" + "\t\t(GClassFinalizeFunc) NULL,\n" + "\t\tNULL /* class_data */,\n" + "\t\tsizeof (%s),\n" + "\t\t%d /* n_preallocs */,\n" + "\t\t(GInstanceInitFunc) %s_init,\n" + "\t\tNULL\n" + "\t};\n\n", + funcbase, typebase, funcbase, typebase, prealloc, funcbase); + + add_interface_infos(); + + out_printf(out, + "\t%s_type_id = g_type_module_register_type(\n" + "\t\ttype_module,\n" + "\t\t%s,\n" + "\t\t\"%s\",\n" + "\t\t&info,\n" + "\t\t(GTypeFlags)%s\n" + "\t);\n\n" + "\t{\n", + funcbase, pmacrotype, typebase, + ((Class *)class)->abstract ? "G_TYPE_FLAG_ABSTRACT" : "0"); + + add_dynamic_interfaces(); + + out_printf(out, + "\t}\n" + "}\n\n"); +} + static void add_bonobo_object_get_type (void) { @@ -3652,8 +3726,23 @@ print_class_block(Class *c) " * Public methods\n" " */\n"); - if ( ! overrode_get_type) { - out_printf (outh, "GType\t%s_get_type\t(void) G_GNUC_CONST;\n", funcbase); + if (!overrode_get_type) { + /* + * For ordinary "static" types it should be safe to mark the + * get_type implementation as const, since the get_type + * function return really is constant at the call boundary + * (even though there is an initial setup on the first call). + * But for dynamic types, since the registration is explicitly + * separated, we need to settle for "pure" as the results of + * get_type differ before and after type registration. + */ + out_printf(outh, "GType\t%s_get_type\t(void) %s;\n", funcbase, + c->dynamic ? "G_GNUC_PURE" : "G_GNUC_CONST"); + } + + if (c->dynamic) { + out_printf(outh, "void\t%s_register_type\t(GTypeModule *);\n", + funcbase); } for(li = c->nodes; li != NULL; li = li->next) { @@ -3721,11 +3810,13 @@ print_class_block(Class *c) add_interface_inits (c); - if ( ! overrode_get_type) { + if (!overrode_get_type) { if (c->bonobo_object_class != NULL) - add_bonobo_object_get_type (); + add_bonobo_object_get_type(); + else if (c->dynamic) + add_dynamic_get_type(); else - add_get_type (); + add_get_type(); } out_printf (out, "/* a macro for creating a new object of our type */\n");