}
}
+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)
{
"}\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)
{
" * 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) {
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");