+ print_type(out, m->mtype, TRUE);
+ if(m->defreturn)
+ out_printf(out, ")(%s);\n}\n", m->defreturn);
+ else if(m->onerror)
+ out_printf(out, ")(%s);\n}\n", m->onerror);
+ else
+ out_printf(out, ")(0);\n}\n");
+ }
+
+ if(!m->cbuf)
+ break;
+ if(m->line_no > 0)
+ out_addline_infile(out, m->line_no);
+ print_method(out, "static ", "\n___real_", "", " ", "", "\n",
+ m, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE);
+ print_method_body(m, FALSE, TRUE);
+ /* the outfile line was added above */
+ break;
+ case OVERRIDE_METHOD:
+ if(!m->cbuf)
+ break;
+ if(m->line_no > 0)
+ out_addline_infile(out, m->line_no);
+ s = g_strdup_printf("\n___%x_", (guint)m->unique_id);
+ print_method(out, "static ", s, "", " ", "", "\n",
+ m, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE);
+ g_free(s);
+ out_addline_outfile(out);
+ s = replace_sep(m->otype, '_');
+ gob_strup (s);
+ args = get_arg_names_for_macro(m);
+ if(is_void) {
+ out_printf(out, "#define PARENT_HANDLER(%s) \\\n"
+ "\t{ if(%s_CLASS(parent_class)->%s) \\\n"
+ "\t\t(* %s_CLASS(parent_class)->%s)(%s); }\n",
+ args, s, m->id, s, m->id, args);
+ } else {
+ out_printf(out, "#define PARENT_HANDLER(%s) \\\n"
+ "\t((%s_CLASS(parent_class)->%s)? \\\n"
+ "\t\t(* %s_CLASS(parent_class)->%s)(%s): \\\n"
+ "\t\t(",
+ args, s, m->id, s, m->id, args);
+ out_printf(out, "(");
+ print_type(out, m->mtype, TRUE);
+ out_printf(out, ")%s))\n",
+ m->onerror?m->onerror:"0");
+ }
+ g_free(args);
+ g_free(s);
+ print_method_body(m, TRUE, TRUE);
+ /* the outfile line was added above */
+ out_printf(out, "#undef PARENT_HANDLER\n");
+ break;
+ case CONSTRUCTOR_METHOD:
+ case DISPOSE_METHOD:
+ case FINALIZE_METHOD:
+ if(m->line_no > 0)
+ out_addline_infile(out, m->line_no);
+ print_method(out, "static ", "\n", "", " ", "", "\n",
+ m, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE);
+ print_method_body(m, TRUE, TRUE);
+ /* the outfile line was added above */
+ default:
+ break;
+ }
+}
+
+static void
+open_files(void)
+{
+ char *outfile, *outfileh, *outfileph;
+
+ outfilebase = g_strconcat (fullfilebase, for_cpp ? ".cc" : ".c", NULL);
+ outfile = g_strconcat(outfilebase, no_touch ? "#gob#" : "", NULL);
+
+ outfilehbase = g_strconcat (fullfilebase, ".h", NULL);
+ outfileh = g_strconcat(outfilehbase, no_touch_headers ? "#gob#" : "", NULL);
+
+ if ((privates > 0 || protecteds > 0 ||
+ private_header == PRIVATE_HEADER_ALWAYS) &&
+ private_header != PRIVATE_HEADER_NEVER) {
+ char sep[2] = {0,0};
+ if (file_sep != 0)
+ sep[0] = file_sep;
+ outfilephbase = g_strconcat (fullfilebase, sep, "private.h", NULL);
+ outfileph = g_strconcat (outfilephbase, no_touch_headers ? "#gob#" : "", NULL);
+ } else {
+ outfilephbase = NULL;
+ outfileph = NULL;
+ }
+
+
+ if ( ! no_write) {
+ out = fopen (outfile, "w");
+ if (out == NULL) {
+ error_printf (GOB_ERROR, 0,
+ "Cannot open outfile: %s", outfile);
+ }
+ outh = fopen (outfileh, "w");
+ if (outh == NULL) {
+ error_printf (GOB_ERROR, 0,
+ "Cannot open outfile: %s", outfileh);
+ }
+ if (outfileph != NULL) {
+ outph = fopen (outfileph, "w");
+ if (outph == NULL) {
+ error_printf (GOB_ERROR, 0,
+ "Cannot open outfile: %s",
+ outfileph);
+ }
+ }
+ }
+}
+
+static void
+put_argument_nongnu_wrappers (Class *c)
+{
+ GList *li;
+
+ if (get_properties < 0 && set_properties < 0)
+ return;
+
+ for (li = c->nodes; li != NULL; li = li->next) {
+ Node *n = li->data;
+ const char *name, *gtktype;
+ gboolean get, set;
+ Type *atype;
+ char *aname;
+ char *cast;
+
+ if (n->type == ARGUMENT_NODE) {
+ Argument *a = (Argument *)n;
+ name = a->name;
+ gtktype = a->gtktype;
+ atype = a->atype;
+ get = a->get != NULL;
+ set = a->set != NULL;
+ } else if (n->type == PROPERTY_NODE) {
+ Property *p = (Property *)n;
+ name = p->name;
+ gtktype = p->gtktype;
+ atype = p->ptype;
+ get = p->get != NULL;
+ set = p->set != NULL;
+ } else {
+ continue;
+ }
+
+ aname = g_strdup (name);
+ gob_strup (aname);
+
+ if (atype != NULL)
+ cast = get_type (atype, TRUE);
+ else
+ cast = g_strdup (get_cast (gtktype, TRUE));
+
+ if (cast != NULL) {
+ if (set)
+ out_printf (outh, "#define %s_PROP_%s(arg) \t"
+ "\"%s\",(%s)(arg)\n",
+ macrobase, aname, name, cast);
+ if (get)
+ out_printf (outh, "#define %s_GET_PROP_%s(arg)\t"
+ "\"%s\",(%s*)(arg)\n",
+ macrobase, aname, name, cast);
+ } else {
+ if(set)
+ out_printf (outh, "#define %s_PROP_%s(arg) \t"
+ "\"%s\",(arg)\n",
+ macrobase, aname, name);
+ if(get)
+ out_printf (outh, "#define %s_GET_PROP_%s(arg)\t"
+ "\"%s\",(arg)\n",
+ macrobase, aname, name);
+ }
+ g_free (cast);
+ g_free (aname);
+ }
+}
+
+static void
+put_argument_gnu_wrappers(Class *c)
+{
+ GList *li;
+
+ if(get_properties < 0 && set_properties < 0)
+ return;
+
+ for (li = c->nodes; li != NULL; li = li->next) {
+ Node *n = li->data;
+ const char *name, *gtktype;
+ gboolean get, set;
+ Type *atype;
+ char *aname;
+ char *cast;
+
+ if (n->type == ARGUMENT_NODE) {
+ Argument *a = (Argument *)n;
+ name = a->name;
+ gtktype = a->gtktype;
+ atype = a->atype;
+ get = a->get != NULL;
+ set = a->set != NULL;
+ } else if (n->type == PROPERTY_NODE) {
+ Property *p = (Property *)n;
+ name = p->name;
+ gtktype = p->gtktype;
+ atype = p->ptype;
+ get = p->get != NULL;
+ set = p->set != NULL;
+ } else {
+ continue;
+ }
+
+ aname = g_strdup (name);
+ gob_strup (aname);
+
+ if (atype != NULL)
+ cast = get_type (atype, TRUE);
+ else
+ cast = g_strdup (get_cast (gtktype, TRUE));
+
+ if (cast != NULL) {
+ if (set)
+ out_printf (outh, "#define %s_PROP_%s(arg) \t"
+ "\"%s\", __extension__ ({%sz = (arg); z;})\n",
+ macrobase, aname, name, cast);
+ if (get)
+ out_printf (outh, "#define %s_GET_PROP_%s(arg)\t"
+ "\"%s\", __extension__ ({%s*z = (arg); z;})\n",
+ macrobase, aname, name, cast);
+ } else {
+ if (set)
+ out_printf (outh, "#define %s_PROP_%s(arg) \t"
+ "\"%s\",(arg)\n",
+ macrobase, aname, name);
+ if (get)
+ out_printf (outh, "#define %s_GET_PROP_%s(arg)\t"
+ "\"%s\",(arg)\n",
+ macrobase, aname, name);
+ }
+ g_free (cast);
+ g_free (aname);
+ }
+}
+
+static void
+print_ccode_block(CCode *cc)
+{
+ FILE *fp;
+ switch(cc->cctype) {
+ case HT_CCODE:
+ /* HT code is printed exactly like normal header
+ code but is printed before */
+ case H_CCODE:
+ fp = outh;
+ out_printf(fp, "\n");
+ break;
+ case AT_CCODE:
+ /* AT code is printed exactly like normal 'all'
+ code but is printed before */
+ case A_CCODE:
+ if(outph) {
+ out_printf(outph, "\n");
+ out_printf(outph, "%s\n", cc->cbuf);
+ out_addline_infile(outph, cc->line_no);
+ out_addline_outfile(outph);
+ }
+ out_printf(outh, "\n");
+ out_printf(outh, "%s\n", cc->cbuf);
+ fp = out;
+ out_printf(fp, "\n");
+ out_addline_infile(fp, cc->line_no);
+ break;
+ default:
+ case CT_CCODE:
+ case C_CCODE:
+ fp = out;
+ out_printf(fp, "\n");
+ out_addline_infile(fp, cc->line_no);
+ break;
+ case PH_CCODE:
+ if(outph)
+ fp = outph;
+ else
+ fp = out;
+ out_printf(fp, "\n");
+ out_addline_infile(fp, cc->line_no);
+ break;
+ }
+ out_printf(fp, "%s\n", cc->cbuf);
+ if(cc->cctype == C_CCODE ||
+ cc->cctype == AD_CCODE ||
+ cc->cctype == A_CCODE ||
+ cc->cctype == AT_CCODE ||
+ cc->cctype == PH_CCODE)
+ out_addline_outfile(fp);
+}
+
+static void
+print_class_block(Class *c)
+{
+ GList *li;
+ char *s;
+ gboolean printed_private = FALSE;
+
+ if (c->glade_xml)
+ {
+ out_printf(outph ? outph : outh, "#include <gtk/gtk.h>\n");
+ out_printf(outph ? outph : outh, "#include <glade/glade-xml.h>\n\n");
+ }
+
+ if(any_special) {
+ out_printf(out, "/* utility types we may need */\n");
+ if(special_array[SPECIAL_2POINTER])
+ out_printf(out, "typedef struct { "
+ "gpointer a; gpointer b; "
+ "} ___twopointertype;\n");
+ if(special_array[SPECIAL_3POINTER])
+ out_printf(out, "typedef struct { "
+ "gpointer a; gpointer b; "
+ "gpointer c; "
+ "} ___threepointertype;\n");
+ if(special_array[SPECIAL_INT_POINTER])
+ out_printf(out, "typedef struct { "
+ "gint a; gpointer b; "
+ "} ___intpointertype;\n");
+ out_printf(out, "\n");
+ }
+
+ out_printf(outh, "\n/*\n"
+ " * Type checking and casting macros\n"
+ " */\n");
+ out_printf(outh, "#define %s\t"
+ "(%s_get_type())\n",
+ macrotype, funcbase);
+ out_printf(outh, "#define %s(obj)\t"
+ "G_TYPE_CHECK_INSTANCE_CAST((obj), %s_get_type(), %s)\n",
+ macrobase, funcbase, typebase);
+ out_printf(outh, "#define %s_CONST(obj)\t"
+ "G_TYPE_CHECK_INSTANCE_CAST((obj), %s_get_type(), %s const)\n",
+ macrobase, funcbase, typebase);
+ out_printf(outh, "#define %s_CLASS(klass)\t"
+ "G_TYPE_CHECK_CLASS_CAST((klass), %s_get_type(), %sClass)\n",
+ macrobase, funcbase, typebase);
+ out_printf(outh, "#define %s(obj)\t"
+ "G_TYPE_CHECK_INSTANCE_TYPE((obj), %s_get_type ())\n\n",
+ macrois, funcbase);
+ out_printf(outh,
+ "#define %s_GET_CLASS(obj)\t"
+ "G_TYPE_INSTANCE_GET_CLASS((obj), %s_get_type(), %sClass)\n",
+ macrobase, funcbase, typebase);
+
+ if ( ! no_self_alias) {
+ out_printf(out, "/* self casting macros */\n");
+ out_printf(out, "#define SELF(x) %s(x)\n", macrobase);
+ out_printf(out, "#define SELF_CONST(x) %s_CONST(x)\n", macrobase);
+ out_printf(out, "#define IS_SELF(x) %s(x)\n", macrois);
+ out_printf(out, "#define TYPE_SELF %s\n", macrotype);
+ out_printf(out, "#define SELF_CLASS(x) %s_CLASS(x)\n\n",
+ macrobase);
+ out_printf(out, "#define SELF_GET_CLASS(x) %s_GET_CLASS(x)\n\n",
+ macrobase);
+
+ out_printf(out, "/* self typedefs */\n");
+ out_printf(out, "typedef %s Self;\n", typebase);
+ out_printf(out, "typedef %sClass SelfClass;\n\n", typebase);
+ }
+
+ if (privates > 0 ||
+ always_private_struct) {
+ out_printf (outh, "\n/* Private structure type */\n");
+ out_printf (outh, "typedef struct _%sPrivate %sPrivate;\n",
+ typebase, typebase);
+ if (privates == 0)
+ out_printf (outh, "/* There are no privates, this "
+ "structure is thus never defined */\n");
+ }
+
+ out_printf (outh, "\n/*\n"
+ " * Main object structure\n"
+ " */\n");
+ s = replace_sep (c->otype, '_');
+ gob_strup (s);
+ out_printf (outh, "#ifndef __TYPEDEF_%s__\n"
+ "#define __TYPEDEF_%s__\n", s, s);
+ g_free (s);
+ out_printf (outh, "typedef struct _%s %s;\n"
+ "#endif\n", typebase, typebase);
+ out_printf (outh, "struct _%s {\n\t%s __parent__;\n",
+ typebase, ptypebase);
+ for (li = c->nodes; li; li=li->next) {
+ static gboolean printed_public = FALSE;
+ Node *n = li->data;
+ Variable *v = (Variable *)n;
+ if(n->type == VARIABLE_NODE &&
+ v->scope == PUBLIC_SCOPE) {
+ if( ! printed_public) {
+ out_printf(outh, "\t/*< public >*/\n");
+ printed_public = TRUE;
+ }
+ put_variable((Variable *)n, outh);
+ }
+ }
+ /* put protecteds always AFTER publics */
+ for (li = c->nodes; li != NULL; li = li->next) {
+ Node *n = li->data;
+ Variable *v = (Variable *)n;
+ if (n->type == VARIABLE_NODE &&
+ v->scope == PROTECTED_SCOPE) {
+ if ( ! printed_private) {
+ out_printf (outh, "\t/*< private >*/\n");
+ printed_private = TRUE;
+ }
+ put_variable ((Variable *)n, outh);
+ }
+ }
+ if (privates > 0 ||
+ always_private_struct) {
+ if ( ! printed_private)
+ out_printf (outh, "\t/*< private >*/\n");
+ out_printf (outh, "\t%sPrivate *_priv;\n", typebase);
+ }
+ out_printf (outh, "};\n");
+
+ if (privates > 0) {
+ FILE *outfp;
+
+ /* if we are to stick this into the private
+ header, if not stick it directly into the
+ C file */
+ if (outph != NULL)
+ outfp = outph;
+ else
+ outfp = out;
+
+ out_printf (outfp, "struct _%sPrivate {\n",
+ typebase);
+ if (privates > 0)
+ {
+ for(li=c->nodes; li; li=li->next) {
+ Node *n = li->data;
+ Variable *v = (Variable *)n;
+ if(n->type == VARIABLE_NODE &&
+ v->scope == PRIVATE_SCOPE) {
+ out_addline_infile(outfp, v->line_no);
+ put_variable(v, outfp);
+ }
+ }
+ out_addline_outfile(outfp);
+ }
+ out_printf(outfp, "};\n");
+ }
+
+ out_printf(outh, "\n/*\n"
+ " * Class definition\n"
+ " */\n");
+ out_printf(outh, "typedef struct _%sClass %sClass;\n",
+ typebase, typebase);
+ out_printf(outh,
+ "struct _%sClass {\n\t%sClass __parent__;\n",
+ typebase, ptypebase);
+ for(li = c->nodes; li != NULL; li = li->next) {
+ Node *n = li->data;
+ if(n->type == METHOD_NODE)
+ put_vs_method((Method *)n);
+ }
+ /* If BonoboX type class put down the epv */
+ if (c->bonobo_object_class != NULL) {
+ out_printf (outh,
+ "\t/* Bonobo object epv */\n"
+ "\tPOA_%s__epv _epv;\n",
+ c->bonobo_object_class);
+ }
+ /* put class scope variables */
+ for (li = c->nodes; li != NULL; li = li->next) {
+ Node *n = li->data;
+ Variable *v = (Variable *)n;
+ if (n->type == VARIABLE_NODE &&
+ v->scope == CLASS_SCOPE)
+ put_variable ((Variable *)n, outh);
+ }
+ out_printf (outh, "};\n\n");
+
+ out_printf (out, "/* here are local prototypes */\n");
+ if (set_properties > 0) {
+ out_printf (out, "static void ___object_set_property "
+ "(GObject *object, guint property_id, "
+ "const GValue *value, GParamSpec *pspec);\n");
+ }
+ if (get_properties > 0) {
+ out_printf (out, "static void ___object_get_property "
+ "(GObject *object, guint property_id, "
+ "GValue *value, GParamSpec *pspec);\n");
+ }
+
+ out_printf (outh, "\n/*\n"
+ " * Public methods\n"
+ " */\n");
+
+ 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) {
+ Node *n = li->data;
+ if(n->type == METHOD_NODE) {
+ put_pub_method((Method *)n);
+ put_prot_method((Method *)n);
+ put_priv_method_prot((Method *)n);
+ }
+ }
+
+ /* this idea is less and less apealing to me */
+ if (signals > 0) {
+ out_printf (outh, "\n/*\n"
+ " * Signal connection wrapper macros\n"
+ " */\n");
+ if( ! no_gnu) {
+ out_printf(outh, "#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\n");
+ put_signal_macros (c, TRUE);
+ out_printf(outh, "#else /* __GNUC__ && !__STRICT_ANSI__ */\n");
+ put_signal_macros (c, FALSE);
+ out_printf(outh, "#endif /* __GNUC__ && !__STRICT_ANSI__ */\n");
+ } else {
+ put_signal_macros (c, FALSE);
+ out_printf(outh, "\n");
+ }
+
+ out_printf (out, "\n/*\n"
+ " * Signal connection wrapper macro shortcuts\n"
+ " */\n");
+ put_local_signal_macros (c);
+ out_printf(outh, "\n");
+ }
+
+ /* argument wrapping macros */
+ if(get_properties > 0 || set_properties > 0) {
+ out_printf(outh, "\n/*\n"
+ " * Argument wrapping macros\n"
+ " */\n");
+ if( ! no_gnu) {
+ out_printf(outh, "#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\n");
+ put_argument_gnu_wrappers(c);
+ out_printf(outh, "#else /* __GNUC__ && !__STRICT_ANSI__ */\n");
+ put_argument_nongnu_wrappers(c);
+ out_printf(outh, "#endif /* __GNUC__ && !__STRICT_ANSI__ */\n\n");
+ } else {
+ put_argument_nongnu_wrappers(c);
+ }
+ }
+
+ if(signals > 0) {
+ for(li = c->nodes; li != NULL; li = li->next) {
+ Node *n = li->data;
+ if(n->type == METHOD_NODE)
+ add_signal_prots((Method *)n);
+ }
+ }
+
+ add_enums (c);
+
+ if(any_method_to_alias(c)) {
+ out_printf (out, "/* Short form macros */\n");
+ make_method_aliases (c);
+ }
+
+ add_interface_inits (c);
+
+ if (!overrode_get_type) {
+ if (c->bonobo_object_class != NULL)
+ add_bonobo_object_get_type();
+ else if (c->dynamic)
+ add_dynamic_get_type();
+ else
+ add_get_type();
+ }
+
+ out_printf (out, "/* a macro for creating a new object of our type */\n");
+ out_printf (out,
+ "#define GET_NEW ((%s *)g_object_new(%s_get_type(), NULL))\n\n",
+ typebase, funcbase);
+
+ out_printf (out, "/* a function for creating a new object of our type */\n");
+ out_printf (out, "#include <stdarg.h>\n");
+ out_printf (out,
+ "static %s * GET_NEW_VARG (const char *first, ...)%s;\n"
+ "static %s *\nGET_NEW_VARG (const char *first, ...)\n"
+ "{\n\t%s *ret;\n\tva_list ap;\n"
+ "\tva_start (ap, first);\n"
+ "\tret = (%s *)g_object_new_valist (%s_get_type (), "
+ "first, ap);\n"
+ "\tva_end (ap);\n"
+ "\treturn ret;\n}\n\n",
+ typebase,
+ no_gnu ? "" : " G_GNUC_UNUSED",
+ typebase, typebase, typebase, funcbase);
+
+ if (c->glade_xml)
+ {
+ out_printf (out, "/* a function to connect glade callback */\n");
+ out_printf (out,"static void\n"
+ "___glade_xml_connect_foreach(const gchar *handler_name,\n"
+ "GObject *object,\n"
+ "const gchar *signal_name,\n"
+ "const gchar *signal_data,\n"
+ "GObject *connect_object,\n"
+ "gboolean after,\n"
+ "gpointer user_data)\n"
+ "{\n"
+ "\tstatic GModule * allsymbols = NULL;\n"
+ " \n"
+ "\tif (!allsymbols) allsymbols = g_module_open(NULL, 0);\n"
+ "\tif (allsymbols) {\n"
+ "\t\tgchar * func_name = g_strdup_printf(\"%s_%%s\", handler_name);\n"
+ "\t\tGCallback func;\n"
+ "\n"
+ "\t\tif (!g_module_symbol(allsymbols, func_name, (gpointer)&func)){\n"
+ "\t\t\tif (!g_module_symbol(allsymbols, handler_name, (gpointer)&func)) {\n"
+ "\t\t\t\tg_warning(\"could not find signal handler '%%s'.\", func_name);\n"
+ "\t\t\t\tg_free(func_name);\n"
+ "\t\t\t\treturn;\n"
+ "\t\t\t}\n"
+ "\t\t}\n"
+ "\t\tif (after)\n"
+ "\t\t\tg_signal_connect_data(object, signal_name, func, user_data, NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);\n"
+ "\t\telse\n"
+ "\t\t\tg_signal_connect_data(object, signal_name, func, user_data, NULL, G_CONNECT_SWAPPED);\n"
+ "\t\tg_free(func_name);\n"
+ "\t}\n"
+ "}\n"
+ "\n",
+ funcbase);
+ }
+
+ for (li = nodes; li != NULL; li = li->next) {
+ Node *node = li->data;
+ if (node->type == CCODE_NODE) {
+ CCode *cc = (CCode *)node;
+ if (cc->cctype == AD_CCODE)
+ print_ccode_block (cc);