- GList *li;
- for(li=c->nodes;li;li=g_list_next(li)) {
- Node *n = li->data;
- Method *m;
- if(n->type != METHOD_NODE)
- continue;
- m = (Method *)n;
- if(m->scope == INIT_METHOD) {
- if(m->line_no>0)
- out_addline_infile(out,m->line_no);
- print_method(out,"static ","\n"," ","\n",m,FALSE);
- if(m->line_no>0)
- out_addline_outfile(out);
- out_printf(out,"{\n");
- if(privates>0) {
- out_printf(out,"\t%s->_priv = "
- "g_new0 (%sPrivate,1);\n",
- ((FuncArg *)m->args->data)->name,
- typebase);
- }
- } else if(m->scope == CLASS_INIT_METHOD) {
- if(m->line_no>0)
- out_addline_infile(out,m->line_no);
- print_method(out,"static ","\n"," ","\n",m,FALSE);
- if(m->line_no>0)
- out_addline_outfile(out);
- out_printf(out,"{\n");
- if(signals>0 ||
- arguments>0)
+ char *root;
+
+ if(v->initializer == NULL)
+ return;
+
+ if(v->scope == PRIVATE_SCOPE)
+ root = g_strconcat(((FuncArg *)m->args->data)->name,
+ "->_priv", NULL);
+ else
+ root = g_strdup(((FuncArg *)m->args->data)->name);
+
+ if(v->initializer_line > 0)
+ out_addline_infile(out, v->initializer_line);
+
+ out_printf(out, "\t%s->%s = %s;\n",
+ root, v->id, v->initializer);
+
+ if(v->initializer_line > 0)
+ out_addline_outfile(out);
+
+ g_free(root);
+}
+
+static void
+print_destructor(Variable *v)
+{
+ char *root;
+
+ if(v->destructor == NULL)
+ return;
+
+ if(v->scope == PRIVATE_SCOPE)
+ root = "self->_priv";
+ else
+ root = "self";
+
+ if(v->destructor_simple) {
+ if(v->destructor_line > 0)
+ out_addline_infile(out, v->destructor_line);
+
+ out_printf(out, "\tif(%s->%s) { "
+ "((*(void (*)(void *))%s)) (%s->%s); "
+ "%s->%s = NULL; }\n",
+ root, v->id, v->destructor, root, v->id,
+ root, v->id);
+
+ if(v->destructor_line > 0)
+ out_addline_outfile(out);
+ } else {
+ out_printf(out, "#define VAR (%s->%s)\n", root, v->id);
+ out_printf(out, "\t{\n");
+ if(v->destructor_line > 0)
+ out_addline_infile(out, v->destructor_line);
+
+ out_printf(out, "\t%s}\n", v->destructor);
+
+ if(v->destructor_line > 0)
+ out_addline_outfile(out);
+ out_printf(out, "\tmemset(&VAR, 0, sizeof(VAR));\n");
+ out_printf(out, "#undef VAR\n");
+ }
+}
+
+static void
+add_destroy(Class *c)
+{
+ out_printf(out, "\nstatic void\n"
+ "___destroy(GtkObject *obj_self)\n"
+ "{\n");
+
+ if(destructors > 0) {
+ out_printf(out, "\t%s *self G_GNUC_UNUSED = %s (obj_self);\n",
+ typebase, macrobase);
+ }
+
+ if(destroy_handler) {
+ /* so we get possible bad argument warning */
+ if(destroy_handler->line_no > 0)
+ out_addline_infile(out, destroy_handler->line_no);
+ out_printf(out, "\t___%x_%s_destroy(obj_self);\n",
+ (guint)destroy_handler->unique_id, funcbase);
+ if(destroy_handler->line_no > 0)
+ out_addline_outfile(out);
+ }
+
+ if(destructors > 0) {
+ GList *li;
+ for(li = ((Class *)class)->nodes;
+ li != NULL;
+ li = li->next) {
+ Node *n = li->data;
+ Variable *v = (Variable *)n;
+ if(n->type == VARIABLE_NODE &&
+ v->scope != CLASS_SCOPE)
+ print_destructor(v);
+ }
+ }
+
+ out_printf(out, "}\n\n");
+}
+
+static void
+add_finalize(Class *c)
+{
+ out_printf(out, "\nstatic void\n"
+ "___finalize(GtkObject *obj_self)\n"
+ "{\n");
+
+ if(privates > 0) {
+ out_printf(out, "\t%s *self = %s (obj_self);\n",
+ typebase, macrobase);
+ }
+
+ if(finalize_handler) {
+ /* so we get possible bad argument warning */
+ if(finalize_handler->line_no > 0)
+ out_addline_infile(out, finalize_handler->line_no);
+ out_printf(out, "\t___%x_%s_finalize(obj_self);\n",
+ (guint)finalize_handler->unique_id, funcbase);
+ if(finalize_handler->line_no > 0)
+ out_addline_outfile(out);
+ }
+
+ if(privates > 0) {
+ out_printf(out, "\tg_free (self->_priv);\n"
+ "\tself->_priv = NULL;\n");
+ }
+
+ out_printf(out, "}\n\n");
+}
+
+static void
+add_inits(Class *c)
+{
+ GList *li;
+ for(li=c->nodes;li;li=g_list_next(li)) {
+ Node *n = li->data;
+ Method *m;
+ if(n->type != METHOD_NODE)
+ continue;
+ m = (Method *)n;
+ if(m->method == INIT_METHOD) {
+ if(m->line_no > 0)
+ out_addline_infile(out, m->line_no);
+ print_method(out, "static ", "\n", "", " ", "\n",
+ m, FALSE, FALSE, TRUE);
+ if(m->line_no > 0)
+ out_addline_outfile(out);
+ out_printf(out, "{\n");
+ if(privates > 0) {
+ out_printf(out, "\t%s->_priv = "
+ "g_new0 (%sPrivate, 1);\n",
+ ((FuncArg *)m->args->data)->name,
+ typebase);
+ }
+ if(initializers > 0) {
+ GList *li;
+ for(li = ((Class *)class)->nodes;
+ li != NULL;
+ li = li->next) {
+ Node *n = li->data;
+ Variable *v = (Variable *)n;
+ if(n->type != VARIABLE_NODE ||
+ v->scope == CLASS_SCOPE)
+ continue;
+ print_initializer(m, v);
+ }
+ }
+ } else if(m->method == CLASS_INIT_METHOD) {
+ gboolean did_gtk_obj = FALSE;
+
+ if(m->line_no > 0)
+ out_addline_infile(out, m->line_no);
+ print_method(out, "static ", "\n", "", " ", "\n",
+ m, FALSE, FALSE, TRUE);
+ if(m->line_no > 0)
+ out_addline_outfile(out);
+ out_printf(out, "{\n");
+ if(signals > 0 ||
+ arguments > 0 ||
+ need_destroy ||
+ need_finalize) {