X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/c9d96fcfcf9b74099775a3a260eccdfdc31474c7..2753ff6cefbe916211d543f1029879e2a075d111:/src/main.c diff --git a/src/main.c b/src/main.c index bf205ac..0cdd6ff 100644 --- a/src/main.c +++ b/src/main.c @@ -67,6 +67,7 @@ static int privates = 0; /* number of private data members */ static int protecteds = 0; /* number of protected methods */ static int destructors = 0; /* number of variable destructors */ static int initializers = 0; /* number of variable initializers */ +static gboolean overrode_get_type = FALSE; /* provided your won _get_type */ static gboolean made_aliases = FALSE; /* if we made any shorthand aliases and need the REALLY UGLY HACK to @@ -93,7 +94,7 @@ gboolean no_gnu = FALSE; gboolean exit_on_warn = FALSE; gboolean exit_on_error = TRUE; gboolean got_error = FALSE; -gint private_header = PRIVATE_HEADER_ALWAYS; +gint private_header = PRIVATE_HEADER_ONDEMAND; gboolean no_extern_c = FALSE; gboolean no_write = FALSE; gboolean no_lines = FALSE; @@ -193,12 +194,17 @@ print_type(FILE *fp, const Type *t, gboolean postfix_to_stars) static void -print_method(FILE *fp, const char *typeprefix, const char *nameprefix, - const char *subnameprefix, - const char *namepostfix, const char *postfix, const Method *m, - gboolean one_arg_per_line, - gboolean no_funcbase, - gboolean kill_underscore) +print_method (FILE *fp, + const char *typeprefix, + const char *nameprefix, + const char *subnameprefix, + const char *namepostfix, + const char *afterargs, + const char *postfix, + const Method *m, + gboolean one_arg_per_line, + gboolean no_funcbase, + gboolean kill_underscore) { GList *li; const char *id; @@ -239,7 +245,7 @@ print_method(FILE *fp, const char *typeprefix, const char *nameprefix, } else { out_printf(fp, "void"); } - out_printf(fp, ")%s", postfix); + out_printf(fp, "%s)%s", afterargs, postfix); } static gboolean @@ -286,7 +292,7 @@ make_method_gnu_aliases(Class *c) if(m->args != NULL) out_printf(out, "#define %s(args...) " - "%s_%s(##args)\n", m->id, + "%s_%s(args)\n", m->id, funcbase, get_real_id(m->id)); else out_printf(out, "#define %s() " @@ -320,7 +326,8 @@ make_method_nongnu_aliases(Class *c) if( ! local_made_aliases) out_printf(out, "\n/* Short form pointers */\n"); - print_method(out, "static ", "(* const ", "", ") ", "", + print_method(out, "static ", "(* const ", "", ") ", + "", "", m, FALSE, TRUE, FALSE); out_printf(out, " = %s_%s;\n", funcbase, get_real_id(m->id)); @@ -402,10 +409,10 @@ put_vs_method(const Method *m) /* if a signal mark it as such */ if(m->method != VIRTUAL_METHOD) - print_method(outh, "\t/*signal*/", "(* ", "", ") ", ";\n", + print_method(outh, "\t/*signal*/", "(* ", "", ") ", "", ";\n", m, FALSE, TRUE, TRUE); else - print_method(outh, "\t", "(* ", "", ") ", ";\n", + print_method(outh, "\t", "(* ", "", ") ", "", ";\n", m, FALSE, TRUE, TRUE); } @@ -415,45 +422,51 @@ put_pub_method(const Method *m) if(m->scope != PUBLIC_SCOPE) return; - print_method(outh, "", "\t", "", "\t", ";\n", m, TRUE, FALSE, TRUE); + print_method(outh, "", "\t", "", "\t", "", ";\n", m, TRUE, FALSE, TRUE); } -/* I'm starting not to like this idea */ -#if 0 static void -put_signal_connect(Method *m) +put_signal_macro (const Method *m, gboolean gnu) { + char *id; + if(m->method != SIGNAL_LAST_METHOD && m->method != SIGNAL_FIRST_METHOD) return; - out_printf(outh, "guint \t%s_%s__connect_full\t(%s *object,\n" - "\t\t\t\t\tconst char *name,\n" - "\t\t\t\t\tGtkSignalFunc func,\n" - "\t\t\t\t\tGtkCallbackMarshal marshal,\n" - "\t\t\t\t\tgpointer data,\n" - "\t\t\t\t\tGtkDestroyNotify destroy_func,\n" - "\t\t\t\t\tgboolean object_signal,\n" - "\t\t\t\t\tgboolean after);\n", - funcbase, m->id, typebase); - - out_printf(outh, "#define %s_%s__connect(object,name,func,data) " - "%s_%s__connect_full((object),(name),(func),NULL," - "(data),NULL,FALSE,FALSE)\n", - funcbase, m->id, funcbase, m->id); - out_printf(outh, "#define %s_%s__connect_after(object,name,func,data) " - "%s__connect_%s_full((object),(name),(func),NULL," - "(data),NULL,FALSE,TRUE)\n", - funcbase, m->id, funcbase, m->id); - - out_printf(outh, "guint \t%s_%s__connect_while_alive\t(%s *object,\n" - "\t\t\t\t\tconst char *name,\n" - "\t\t\t\t\tGtkSignalFunc func,\n" - "\t\t\t\t\tgpointer data,\n" - "\t\t\t\t\tGtkObject *alive_object);\n\n", - funcbase, m->id, typebase); + id = g_strdup (m->id); + g_strup (id); + + if ( ! gnu) { + out_printf (outh, "#define %s_SIGNAL_%s(func)\t" + "\"%s\",GTK_SIGNAL_FUNC(func)\n", + macrobase, id, get_real_id (m->id)); + } else { + out_printf (outh, "#define %s_SIGNAL_%s(func)\t" + "\"%s\",GTK_SIGNAL_FUNC(({", + macrobase, id, get_real_id (m->id)); + print_method (outh, "", "(* ___", "", ") ", ", gpointer data ", + " = func; ", m, FALSE, TRUE, TRUE); + out_printf (outh, "___%s; }))\n", get_real_id (m->id)); + + } + g_free (id); +} + +static void +put_signal_macros (const Class *c, gboolean gnu) +{ + const GList *li; + + if (signals < 0) + return; + + for (li = c->nodes; li != NULL; li = li->next) { + const Node *n = li->data; + if (n->type == METHOD_NODE) + put_signal_macro ((Method *)n, gnu); + } } -#endif static void @@ -463,10 +476,10 @@ put_prot_method(const Method *m) return; if(outph) - print_method(outph, "", "\t", "", "\t", ";\n", + print_method(outph, "", "\t", "", "\t", "", ";\n", m, FALSE, FALSE, TRUE); else - print_method(out, "", "\t", "", "\t", ";\n", + print_method(out, "", "\t", "", "\t", "", ";\n", m, FALSE, FALSE, TRUE); } @@ -478,7 +491,7 @@ put_priv_method_prot(Method *m) m->method == VIRTUAL_METHOD) { if(m->cbuf) print_method(out, - "static ", "___real_", "", " ", ";\n", + "static ", "___real_", "", " ", "", ";\n", m, FALSE, FALSE, TRUE); } /* no else, here, it might still have a private prototype, it's not @@ -488,14 +501,14 @@ put_priv_method_prot(Method *m) m->cbuf)) { /* add unique ID */ char *s = g_strdup_printf("___%x_", (guint)m->unique_id); - print_method(out, "static ", s, "", " ", + print_method(out, "static ", s, "", " ", "", no_gnu?";\n":" G_GNUC_UNUSED;\n", m, FALSE, FALSE, FALSE); g_free(s); } else if(m->scope == PRIVATE_SCOPE || m->method == INIT_METHOD || m->method == CLASS_INIT_METHOD) - print_method(out, "static ", "", "", " ", + print_method(out, "static ", "", "", " ", "", no_gnu?";\n":" G_GNUC_UNUSED;\n", m, FALSE, FALSE, TRUE); } @@ -546,7 +559,8 @@ make_inits(Class *cl) NULL, NULL, NULL, g_strdup("class_init"), make_func_arg(cl->otype, TRUE, g_strdup("c")), NULL, NULL, NULL, 0, 0, FALSE, - method_unique_id++); + method_unique_id++, + FALSE /*bonobo_x_func*/); cl->nodes = g_list_prepend(cl->nodes, node); } if(!got_init) { @@ -556,7 +570,8 @@ make_inits(Class *cl) NULL, NULL, NULL, g_strdup("init"), make_func_arg(cl->otype, FALSE, g_strdup("o")), NULL, NULL, NULL, 0, 0, FALSE, - method_unique_id++); + method_unique_id++, + FALSE /*bonobo_x_func*/); cl->nodes = g_list_prepend(cl->nodes, node); } } @@ -739,14 +754,17 @@ add_signal_prots(Method *m) "\t(*rfunc)((%s *)object", s, s, typebase); } else { const char *retcast = get_cast(m->gtktypes->data, FALSE); + gboolean is_none = (strcmp(m->gtktypes->next->data, "NONE")==0); out_printf(out, "\t___%s rfunc;\n\t" "%s *retval;\n\n" "\trfunc = (___%s)func;\n\n" "\tretval = GTK_RETLOC_%s(args[%d]);\n\n" "\t*retval = (*rfunc)((%s *)object", - s, retcast, s, (char *)m->gtktypes->data, - g_list_length(m->gtktypes)-1, typebase); + s, retcast, s, + (char *)m->gtktypes->data, + g_list_length(m->gtktypes) - (is_none ? 2 : 1), + typebase); } print_signal_marsal_args(m); @@ -806,8 +824,8 @@ add_get_type(void) "GtkType\n" "%s_get_type (void)\n" "{\n" - "\tstatic guint type = 0;\n\n" - "\tif ( ! type) {\n" + "\tstatic GtkType type = 0;\n\n" + "\tif (type == 0) {\n" "\t\tstatic const GtkTypeInfo info = {\n" "\t\t\t\"%s\",\n" "\t\t\tsizeof (%s),\n" @@ -834,6 +852,49 @@ add_get_type(void) "}\n\n"); } +static void +add_bonobo_x_get_type (void) +{ + char *chunk_size = ((Class*)class)->chunk_size; + + out_printf(out, + "GtkType\n" + "%s_get_type (void)\n" + "{\n" + "\tstatic GtkType type = 0;\n\n" + "\tif (type == 0) {\n" + "\t\tstatic const GtkTypeInfo info = {\n" + "\t\t\t\"%s\",\n" + "\t\t\tsizeof (%s),\n" + "\t\t\tsizeof (%sClass),\n" + "\t\t\t(GtkClassInitFunc) %s_class_init,\n" + "\t\t\t(GtkObjectInitFunc) %s_init,\n" + "\t\t\t/* reserved_1 */ NULL,\n" + "\t\t\t/* reserved_2 */ NULL,\n" + "\t\t\t(GtkClassInitFunc) NULL\n" + "\t\t};\n\n" + "\t\ttype = bonobo_x_type_unique\n" + "\t\t\t(%s_get_type (),\n" + "\t\t\tPOA_%s__init, NULL,\n" + "\t\t\tGTK_STRUCT_OFFSET (%sClass, _epv),\n" + "\t\t\t&info);\n", + funcbase, typebase, typebase, typebase, + funcbase, funcbase, pfuncbase, + ((Class*)class)->bonobo_x_class, + typebase); + if(chunk_size) { + out_printf(out, + "#if %s > 0\n" + "\t\tgtk_type_set_chunk_alloc(type, %s);\n" + "#endif\n", + chunk_size, chunk_size); + } + out_printf(out, + "\t}\n\n" + "\treturn type;\n" + "}\n\n"); +} + static void add_overrides(Class *c, const char *oname, gboolean did_base_obj) { @@ -1340,6 +1401,36 @@ add_finalize(Class *c) "#undef __GOB_FUNCTION__\n\n"); } +static void +make_bonobo_x_epv (Class *c, const char *classname) +{ + GList *li; + gboolean added_line = FALSE; + + for (li = c->nodes; li != NULL; li = li->next) { + Node *n = li->data; + Method *m = (Method *)n; + if(n->type != METHOD_NODE || + m->method == OVERRIDE_METHOD) + continue; + + if (m->bonobo_x_func) { + if(m->line_no > 0) { + out_addline_infile(out, m->line_no); + added_line = TRUE; + } else if (m->line_no == 0 && + added_line) { + out_addline_outfile(out); + added_line = FALSE; + } + out_printf (out, "\t%s->_epv.%s = %s;\n", + classname, m->id, m->id); + } + } + if (added_line) + out_addline_outfile(out); +} + static void add_inits(Class *c) { @@ -1356,7 +1447,7 @@ add_inits(Class *c) if(m->method == INIT_METHOD) { if(m->line_no > 0) out_addline_infile(out, m->line_no); - print_method(out, "static ", "\n", "", " ", "\n", + print_method(out, "static ", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); if(m->line_no > 0) out_addline_outfile(out); @@ -1390,7 +1481,7 @@ add_inits(Class *c) if(m->line_no > 0) out_addline_infile(out, m->line_no); - print_method(out, "static ", "\n", "", " ", "\n", + print_method(out, "static ", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); if(m->line_no > 0) out_addline_outfile(out); @@ -1463,6 +1554,9 @@ add_inits(Class *c) if(get_arguments > 0 || set_arguments > 0) make_arguments(c); + if (c->bonobo_x_class != NULL) { + make_bonobo_x_epv (c, ((FuncArg *)m->args->data)->name); + } } else continue; @@ -1661,6 +1755,8 @@ print_preconditions(Method *m) static void print_method_body(Method *m, int pre) { + if (m->line_no > 0) + out_addline_outfile(out); out_printf(out, "{\n" "#define __GOB_FUNCTION__ \"%s::%s\"\n", ((Class *)class)->otype, @@ -1746,10 +1842,10 @@ put_method(Method *m) if(m->line_no > 0) out_addline_infile(out, m->line_no); if(m->scope == PRIVATE_SCOPE) - print_method(out, "static ", "\n", "", " ", "\n", + print_method(out, "static ", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); else /* PUBLIC, PROTECTED */ - print_method(out, "", "\n", "", " ", "\n", + print_method(out, "", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); print_method_body(m, TRUE); /* the outfile line was added above */ @@ -1759,10 +1855,10 @@ put_method(Method *m) if(m->line_no > 0) out_addline_infile(out, m->line_no); if(m->scope == PRIVATE_SCOPE) - print_method(out, "static ", "\n", "", " ", "\n", + print_method(out, "static ", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); else /* PUBLIC, PROTECTED */ - print_method(out, "", "\n", "", " ", "\n", + print_method(out, "", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); out_addline_outfile(out); out_printf(out, "{\n"); @@ -1801,7 +1897,7 @@ put_method(Method *m) break; if(m->line_no > 0) out_addline_infile(out, m->line_no); - print_method(out, "static ", "\n___real_", "", " ", "\n", + print_method(out, "static ", "\n___real_", "", " ", "", "\n", m, FALSE, FALSE, TRUE); print_method_body(m, FALSE); /* the outfile line was added above */ @@ -1810,10 +1906,10 @@ put_method(Method *m) if(m->line_no > 0) out_addline_infile(out, m->line_no); if(m->scope==PRIVATE_SCOPE) - print_method(out, "static ", "\n", "", " ", "\n", + print_method(out, "static ", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); else /* PUBLIC, PROTECTED */ - print_method(out, "", "\n", "", " ", "\n", + print_method(out, "", "\n", "", " ", "", "\n", m, FALSE, FALSE, TRUE); out_addline_outfile(out); out_printf(out, "{\n" @@ -1859,7 +1955,7 @@ put_method(Method *m) break; if(m->line_no > 0) out_addline_infile(out, m->line_no); - print_method(out, "static ", "\n___real_", "", " ", "\n", + print_method(out, "static ", "\n___real_", "", " ", "", "\n", m, FALSE, FALSE, TRUE); print_method_body(m, FALSE); /* the outfile line was added above */ @@ -1870,7 +1966,7 @@ put_method(Method *m) 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", + print_method(out, "static ", s, "", " ", "", "\n", m, FALSE, FALSE, FALSE); g_free(s); out_addline_outfile(out); @@ -2153,6 +2249,7 @@ print_class_block(Class *c) 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", @@ -2262,6 +2359,13 @@ print_class_block(Class *c) if(n->type == METHOD_NODE) put_vs_method((Method *)n); } + /* If BonoboX type class put down the epv */ + if (c->bonobo_x_class != NULL) { + out_printf (outh, + "\t/* Bonobo object epv */\n" + "\tPOA_%s__epv _epv;\n", + c->bonobo_x_class); + } /* put class scope variables */ for(l = c->nodes; l != NULL; l = l->next) { Node *n = l->data; @@ -2288,11 +2392,13 @@ print_class_block(Class *c) " * Public methods\n" " */\n"); - out_printf(outh, "GtkType\t%s_get_type\t(void)", funcbase); - if ( ! no_gnu) { - out_printf(outh, " G_GNUC_CONST;\n"); - } else { - out_printf(outh, ";\n"); + if ( ! overrode_get_type) { + out_printf(outh, "GtkType\t%s_get_type\t(void)", funcbase); + if ( ! no_gnu) { + out_printf(outh, " G_GNUC_CONST;\n"); + } else { + out_printf(outh, ";\n"); + } } for(l = c->nodes; l != NULL; l = l->next) { @@ -2304,39 +2410,34 @@ print_class_block(Class *c) } } -/* this idea is less and less apealing to me */ -#if 0 - if(!no_signal_connect) { - if(signals>0) { - out_printf(outh, "\n/*\n" - " * Signal connection methods\n" - " */\n"); - } - - for(l=c->nodes;l;l=g_list_next(l)) { - Node *n = l->data; - if(n->type == METHOD_NODE) - put_signal_connect((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\n"); + } else { + put_signal_macros (c, FALSE); } } -#endif - /* argument wrapping macros */ if(get_arguments > 0 || set_arguments > 0) { + out_printf(outh, "\n/*\n" + " * Argument wrapping macros\n" + " */\n"); if( ! no_gnu) { - out_printf(outh, "\n/*\n" - " * Argument wrapping macros\n" - " */\n"); 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 { - out_printf(outh, "\n/*\n" - " * Argument wrapping macros\n" - " */\n"); put_argument_nongnu_wrappers(c); } } @@ -2351,7 +2452,12 @@ print_class_block(Class *c) add_enums(c); - add_get_type(); + if ( ! overrode_get_type) { + if (c->bonobo_x_class != NULL) + add_bonobo_x_get_type (); + else + add_get_type (); + } if(any_method_to_alias(c)) { if( ! no_gnu) { @@ -2766,6 +2872,7 @@ main(int argc, char *argv[]) protecteds = count_protecteds((Class *)class); destructors = count_destructors((Class *)class); initializers = count_initializers((Class *)class); + overrode_get_type = find_get_type((Class *)class); make_bases(); make_inits((Class *)class);