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
}
static char *
-get_type(Type *t, gboolean postfix_to_stars)
+get_type(const Type *t, gboolean postfix_to_stars)
{
char *s;
int i;
extra = 0;
if(postfix_to_stars) {
- char *p;
+ const char *p;
/*XXX: this is ugly perhaps we can do this whole postfix thing
in a nicer way, we just count the number of '[' s and from
that we deduce the number of dimensions, so that we can print
}
static char *
-get_gtk_doc(char *id)
+get_gtk_doc(const char *id)
{
char *val;
}
static void
-print_type(FILE *fp, Type *t, gboolean postfix_to_stars)
+print_type(FILE *fp, const Type *t, gboolean postfix_to_stars)
{
char *s;
static void
-print_method(FILE *fp, char *typeprefix, char *nameprefix,
- char *subnameprefix,
- char *namepostfix, char *postfix, 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;
- char *id;
+ const char *id;
out_printf(fp, "%s", typeprefix);
print_type(fp, m->mtype, TRUE);
print_type(fp, arg->atype, FALSE);
if(li->next)
out_printf(fp, "%s%s,%s", arg->name,
- arg->atype->postfix?
- arg->atype->postfix:"",
- one_arg_per_line?"\n\t\t\t\t\t":" ");
+ arg->atype->postfix ?
+ arg->atype->postfix : "",
+ one_arg_per_line ? "\n\t\t\t\t\t" : " ");
else
out_printf(fp, "%s%s", arg->name,
- arg->atype->postfix?
- arg->atype->postfix:"");
+ arg->atype->postfix ?
+ arg->atype->postfix : "");
}
if(m->vararg)
out_printf(fp, ",%s...",
- one_arg_per_line?"\n\t\t\t\t\t":" ");
+ one_arg_per_line ? "\n\t\t\t\t\t" : " ");
} else {
out_printf(fp, "void");
}
- out_printf(fp, ")%s", postfix);
+ out_printf(fp, "%s)%s", afterargs, postfix);
}
static gboolean
}
+/* just the vararg macros, we use the same func pointers for these as in non-gnu */
static void
make_method_gnu_aliases(Class *c)
{
GList *li;
- for(li=c->nodes;li;li=g_list_next(li)) {
+ for(li = c->nodes; li != NULL; li = li->next) {
Node *node = li->data;
if(node->type == METHOD_NODE) {
Method *m = (Method *)node;
if(for_cpp && strcmp(m->id, "new")==0)
continue;
- out_printf(out, "static const typeof(&%s_%s) %s "
- "__attribute__ ((__unused__)) "
- "= %s_%s;\n", funcbase, get_real_id(m->id),
- m->id, funcbase, get_real_id(m->id));
- out_printf(out, "#define %s(args...) "
- "%s_%s(##args)\n", m->id,
- funcbase, get_real_id(m->id));
+ if(m->args != NULL)
+ out_printf(out, "#define %s(args...) "
+ "%s_%s(args)\n", m->id,
+ funcbase, get_real_id(m->id));
+ else
+ out_printf(out, "#define %s() "
+ "%s_%s()\n", m->id,
+ funcbase, get_real_id(m->id));
}
}
}
make_method_nongnu_aliases(Class *c)
{
GList *li;
+
+ gboolean local_made_aliases = FALSE;
for(li=c->nodes; li; li=g_list_next(li)) {
Node *node = li->data;
if(for_cpp && strcmp(m->id, "new")==0)
continue;
- print_method(out, "static ", "(* ", "", ") ", "",
+ if( ! local_made_aliases)
+ out_printf(out, "\n/* Short form pointers */\n");
+
+ print_method(out, "static ", "(* const ", "", ") ",
+ "", "",
m, FALSE, TRUE, FALSE);
out_printf(out, " = %s_%s;\n", funcbase,
get_real_id(m->id));
- made_aliases = TRUE;
+ local_made_aliases = TRUE;
}
}
+ if(local_made_aliases) {
+ out_printf(out, "\n");
+ made_aliases = TRUE;
+ }
}
static void
GList *li;
/* if we haven't had any methods, just return */
- if(!made_aliases)
+ if( ! made_aliases)
return;
- if(!no_gnu)
+ if( ! no_gnu)
out_printf(out, "\n\n#if (!defined __GNUC__) || (defined __GNUC__ && defined __STRICT_ANSI__)\n");
out_printf(out,
"/*REALLY BAD HACK\n"
}
static void
-put_vs_method(Method *m)
+put_vs_method(const Method *m)
{
if(m->method != SIGNAL_LAST_METHOD &&
m->method != SIGNAL_FIRST_METHOD &&
/* 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);
}
static void
-put_pub_method(Method *m)
+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
-put_prot_method(Method *m)
+put_prot_method(const Method *m)
{
if(m->scope != PROTECTED_SCOPE)
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);
}
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
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);
}
{
char *chunk_size = ((Class*)class)->chunk_size;
- out_printf(out, "guint\n"
- "%s_get_type (void)\n"
- "{\n"
- "\tstatic guint type = 0;\n\n"
- "\tif (!type) {\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 = gtk_type_unique (%s_get_type(), &info);\n",
- funcbase, typebase, typebase, typebase,
- funcbase, funcbase, pfuncbase);
+ 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 = gtk_type_unique (%s_get_type(), &info);\n",
+ funcbase, typebase, typebase, typebase,
+ funcbase, funcbase, pfuncbase);
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");
+ 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, char *oname, gboolean did_base_obj)
+add_overrides(Class *c, const char *oname, gboolean did_base_obj)
{
GList *li;
GHashTable *done;
}
static void
-set_def_handlers(Class *c, char *oname)
+set_def_handlers(Class *c, const char *oname)
{
GList *li;
gboolean set_line = FALSE;
} else {
if(m->cbuf)
out_printf(out, "\t%s->%s = ___real_%s_%s;\n",
- oname, get_real_id(m->id),
- funcbase, get_real_id(m->id));
+ oname, get_real_id(m->id),
+ funcbase, get_real_id(m->id));
else
out_printf(out, "\t%s->%s = NULL;\n",
- oname, get_real_id(m->id));
+ oname, get_real_id(m->id));
}
}
if(set_line)
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);
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);
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 */
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");
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 */
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"
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 */
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);
" * Public methods\n"
" */\n");
- out_printf(outh, "guint\t%s_get_type\t(void);\n", funcbase);
+ 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) {
Node *n = l->data;
if(n->type == METHOD_NODE) {
}
}
-/* 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);
}
}
add_enums(c);
- add_get_type();
+ if ( ! overrode_get_type)
+ add_get_type();
if(any_method_to_alias(c)) {
- if(no_gnu)
- make_method_nongnu_aliases(c);
- else {
- out_printf(out, "\n#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\n");
+ if( ! no_gnu) {
+ out_printf(out, "/* Short form macros */\n");
+ out_printf(out, "#if defined(__GNUC__) && !defined(__STRICT_ANSI__)\n");
make_method_gnu_aliases(c);
- out_printf(out, "#else /* __GNUC__ && !__STRICT_ANSI__ */\n");
- make_method_nongnu_aliases(c);
- out_printf(out, "#endif /* __GNUC__ && !__STRICT_ANSI__ */\n\n");
+ out_printf(out, "#endif /* __GNUC__ && !__STRICT_ANSI__ */\n");
}
+ make_method_nongnu_aliases(c);
}
out_printf(out, "/* a macro for creating a new object of our type */\n");
out_printf(out, "/* Generated by GOB (v%s) on %s"
" (do not edit directly) */\n\n",
VERSION, ctime(&curtime));
+
+ out_printf(out, "/* End world hunger, donate to the World Food Programme, http://www.wfp.org */\n\n");
}
static void
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);