2 * Copyright (C) 1999 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
33 char *filename = "stdin";
43 static char *funcbase;
44 static char *pfuncbase;
45 static char *macrobase;
47 static char *typebase;
48 static char *ptypebase;
50 static int signals = 0;
51 static int arguments = 0;
56 int exit_on_warn = FALSE;
59 print_error(int is_warn, char *error,int line)
67 fprintf(stderr,"%s:%d: %s %s\n",filename,line,w,error);
69 fprintf(stderr,"%s: %s %s\n",filename,w,error);
70 if(!is_warn || exit_on_warn)
75 remove_sep(char *base)
78 char *s = g_strdup(base);
79 while((p=strchr(s,':')))
85 replace_sep(char *base, char r)
88 char *s = g_strdup(base);
89 while((p=strchr(s,':')))
99 /*separate the namespace part and then replace rest of
102 separns_replace_sep(char *base, char **ns, char **name, char r)
105 char *s = g_strdup(base);
107 if((p=strchr(s,':')) && p!=s) {
114 while((p=strchr(s,':')))
117 *name = g_strdup(s+1);
124 make_is_macro(char *base)
129 separns_replace_sep(base,&s1,&s2,'_');
131 s = g_strconcat(s1,"_IS_",s2,NULL);
133 s = g_strconcat("IS_",s2,NULL);
146 filebase = replace_sep(((Class *)class)->otype,'-');
149 funcbase = replace_sep(((Class *)class)->otype,'_');
152 pfuncbase = replace_sep(((Class *)class)->ptype,'_');
153 g_strdown(pfuncbase);
155 macrobase = replace_sep(((Class *)class)->otype,'_');
158 macrois = make_is_macro(((Class *)class)->otype);
160 typebase = remove_sep(((Class *)class)->otype);
162 ptypebase = remove_sep(((Class *)class)->ptype);
166 def_methods(Class *c)
170 out_printf(out,"\n");
171 for(li=c->nodes;li;li=g_list_next(li)) {
172 Node *node = li->data;
173 if(node->type == METHOD_NODE) {
174 Method *m = (Method *)node;
176 if(m->scope == INIT_METHOD ||
177 m->scope == CLASS_INIT_METHOD ||
178 m->scope == OVERRIDE_METHOD)
181 out_printf(out,"#define %s %s_%s\n",m->id,funcbase,m->id);
184 out_printf(out,"\n");
188 undef_methods(Class *c)
192 out_printf(out,"\n");
193 for(li=c->nodes;li;li=g_list_next(li)) {
194 Node *node = li->data;
195 if(node->type == METHOD_NODE) {
196 Method *m = (Method *)node;
198 if(m->scope == INIT_METHOD ||
199 m->scope == CLASS_INIT_METHOD ||
200 m->scope == OVERRIDE_METHOD)
203 out_printf(out,"#undef %s\n",m->id);
206 out_printf(out,"\n");
210 print_type(FILE *fp, Type *t)
214 s = remove_sep(t->name);
215 out_printf(fp,"%s ",s);
218 for(i=0;i<t->stars;i++)
223 put_variable(Variable *v)
225 out_printf(outh,"\t");
226 if(v->scope == PRIVATE_SCOPE)
227 out_printf(outh,"/* private */ ");
228 print_type(outh,v->vtype);
230 out_printf(outh,"%s;\n",v->id);
234 print_method(FILE *fp, char *typeprefix, char *nameprefix,
235 char *namepostfix,char *postfix, Method *m)
239 out_printf(fp,"%s",typeprefix);
240 print_type(fp,m->mtype);
241 out_printf(fp,"%s%s_%s%s(",
242 nameprefix,funcbase,m->id,namepostfix);
245 for(li=m->args;li;li=g_list_next(li)) {
246 FuncArg *arg = li->data;
247 print_type(fp,arg->atype);
249 out_printf(fp,"%s, ",arg->name);
251 out_printf(fp,"%s",arg->name);
255 out_printf(fp,"void");
257 out_printf(fp,")%s\n",postfix);
261 put_vs_method(Method *m)
263 if(m->scope != SIGNAL_LAST_METHOD &&
264 m->scope != SIGNAL_FIRST_METHOD &&
265 m->scope != VIRTUAL_METHOD)
268 print_method(outh,"\t","(* ",") ",";",m);
272 put_pub_method(Method *m)
274 if(m->scope == PRIVATE_SCOPE ||
275 m->scope == OVERRIDE_METHOD ||
276 m->scope == INIT_METHOD ||
277 m->scope == CLASS_INIT_METHOD)
280 print_method(outh,"","\t","\t",";",m);
284 put_priv_method_prot(Method *m)
286 if(m->scope == PUBLIC_SCOPE)
289 if(m->scope == SIGNAL_LAST_METHOD ||
290 m->scope == SIGNAL_FIRST_METHOD ||
291 m->scope == VIRTUAL_METHOD) {
294 print_method(out,"static ","_real_"," ",";",m);
296 print_method(out,"static ",""," ",";",m);
301 make_init_args(Class *cl, char *name, int is_class)
308 tn = g_strconcat(cl->otype,":Class",NULL);
310 tn = g_strdup(cl->otype);
312 type = new_type(1,tn);
313 node = new_funcarg((Type *)type,name,NULL);
314 return g_list_prepend(NULL, node);
318 make_inits(Class *cl)
320 int got_class_init = FALSE;
321 int got_init = FALSE;
324 for(li=cl->nodes;li;li=g_list_next(li)) {
326 if(n->type == METHOD_NODE) {
327 Method *m = (Method *)n;
328 if(m->scope == INIT_METHOD) {
330 print_error(FALSE,"init defined more then once",m->line_no);
332 } else if(m->scope == CLASS_INIT_METHOD) {
334 print_error(FALSE,"class_init defined more then once",m->line_no);
335 got_class_init = TRUE;
339 if(!got_class_init) {
340 node = new_method(CLASS_INIT_METHOD,
341 (Type *)new_type(0,g_strdup("void")),
342 NULL,NULL,g_strdup("class_init"),
343 make_init_args(cl,g_strdup("c"),TRUE),
345 cl->nodes = g_list_prepend(cl->nodes,node);
348 node = new_method(INIT_METHOD,
349 (Type *)new_type(0,g_strdup("void")),
350 NULL,NULL,g_strdup("init"),
351 make_init_args(cl,g_strdup("o"),FALSE),
353 cl->nodes = g_list_prepend(cl->nodes,node);
357 static GHashTable *marsh = NULL;
360 add_signal_prots(Method *m)
366 if(m->scope != SIGNAL_LAST_METHOD &&
367 m->scope != SIGNAL_FIRST_METHOD)
371 marsh = g_hash_table_new(NULL,NULL);
373 if(strcmp(m->gtktypes->data,"NONE")==0 &&
374 strcmp(m->gtktypes->next->data,"NONE")==0)
377 s = g_strdup_printf("__Sig%d",sig++);
379 g_hash_table_insert(marsh,m,s);
381 out_printf(out,"\ntypedef ");
382 print_type(out,m->mtype);
384 out_printf(out,"(*%s) (",s);
386 for(li=m->args;li;li=g_list_next(li)) {
387 FuncArg *arg = li->data;
388 print_type(out,arg->atype);
389 out_printf(out,", ");
391 out_printf(out,"gpointer);\n");
393 out_printf(out,"\nstatic void\n"
394 "marshal_%s (GtkObject * object,\n"
395 "\tGtkSignalFunc func,\n"
396 "\tgpointer func_data,\n"
400 if(strcmp(m->gtktypes->data,"NONE")==0) {
402 out_printf(out, "\t%s rfunc;\n\n"
403 "\trfunc = (%s)func;\n\n"
404 "\t(*rfunc)((%s *)object",s,s,typebase);
405 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
406 for(i=0,li=m->gtktypes->next;li;
407 i++,li=g_list_next(li)) {
408 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
412 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
415 out_printf(out, "\t%s rfunc;\n\t",s);
416 print_type(out,m->mtype);
417 out_printf(out, " *retval;\n\n"
418 "\trfunc = (%s)func;\n\n"
419 "\tretval = GTK_RETLOC_%s(args[%d]);\n\n"
420 "\t*retval = (*rfunc)((%s *)object",
421 s,(char *)m->gtktypes->data,
422 g_list_length(m->gtktypes)-1,typebase);
423 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
424 for(i=0,li=m->gtktypes->next;li;
425 i++,li=g_list_next(li)) {
426 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
430 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
439 out_printf(out,"\n");
441 out_printf(out,"enum {\n");
442 for(li=c->nodes;li;li=g_list_next(li)) {
444 if(n->type == METHOD_NODE) {
445 Method *m = (Method *)n;
446 if(m->scope == SIGNAL_LAST_METHOD ||
447 m->scope == SIGNAL_FIRST_METHOD) {
448 char *s = g_strdup(m->id);
450 out_printf(out,"\t%s_SIGNAL,\n",s);
455 out_printf(out,"\tLAST_SIGNAL\n};\n\n");
458 out_printf(out,"enum {\n\tARG_0,\n");
459 for(li=c->nodes;li;li=g_list_next(li)) {
461 if(n->type == ARGUMENT_NODE) {
462 Argument *a = (Argument *)n;
463 char *s = g_strdup(a->name);
465 out_printf(out,"\tARG_%s,\n",s);
469 out_printf(out, "};\n\n");
474 "static guint object_signals[LAST_SIGNAL] = {0};\n\n");
476 out_printf(out, "static %sClass *parent_class = NULL;\n\n",ptypebase);
482 out_printf(out, "guint\n"
483 "%s_get_type (void)\n"
485 "\tstatic guint type = 0;\n\n"
487 "\t\tstatic const GtkTypeInfo info = {\n"
489 "\t\t\tsizeof (%s),\n"
490 "\t\t\tsizeof (%sClass),\n"
491 "\t\t\t(GtkClassInitFunc) %s_class_init,\n"
492 "\t\t\t(GtkObjectInitFunc) %s_init,\n"
493 "\t\t\t/* reserved_1 */ NULL,\n"
494 "\t\t\t/* reserved_2 */ NULL,\n"
495 "\t\t\t(GtkClassInitFunc) NULL,\n"
497 "\t\ttype = gtk_type_unique (%s_get_type(), &info);\n"
501 funcbase,typebase,typebase,typebase,
502 funcbase,funcbase,pfuncbase);
506 add_overrides(Class *c, char *oname)
512 done = g_hash_table_new(g_str_hash,g_str_equal);
513 s = g_strdup("GtkObject"); /* This was already done */
514 g_hash_table_insert(done,s,s);
515 for(li=c->nodes;li;li=g_list_next(li)) {
519 if(n->type != METHOD_NODE ||
520 ((Method *)n)->scope != OVERRIDE_METHOD)
524 s = remove_sep(m->otype);
526 if(g_hash_table_lookup(done,s)) {
530 g_hash_table_insert(done,s,s);
532 f = replace_sep(m->otype,'_');
535 out_printf(out,"\t%sClass *%s_class = (%sClass *)%s;\n",
540 g_hash_table_foreach(done,(GHFunc)g_free,NULL);
541 g_hash_table_destroy(done);
545 add_signals(Class *c)
549 out_printf(out,"\n");
550 for(li=c->nodes;li;li=g_list_next(li)) {
556 if(n->type != METHOD_NODE ||
557 (((Method *)n)->scope != SIGNAL_FIRST_METHOD &&
558 ((Method *)n)->scope != SIGNAL_LAST_METHOD))
563 if(g_hash_table_lookup(marsh,m))
564 mar = g_strconcat("marshal_",
565 (char *)g_hash_table_lookup(marsh,m),
568 mar = g_strdup("gtk_signal_default_marshaller");
570 is_none = (strcmp(m->gtktypes->next->data,"NONE")==0);
572 sig = g_strdup(m->id);
574 out_printf(out,"\tobject_signals[%s_SIGNAL] =\n"
575 "\t\tgtk_signal_new (\"%s\",\n"
576 "\t\t\tGTK_RUN_%s,\n"
577 "\t\t\tgtk_object_class->type,\n"
578 "\t\t\tGTK_SIGNAL_OFFSET (%sClass, %s),\n"
580 "\t\t\tGTK_TYPE_%s, %d",
582 m->scope==SIGNAL_LAST_METHOD?"LAST":"FIRST",
583 typebase,m->id,mar,(char *)m->gtktypes->data,
584 is_none?0:g_list_length(m->gtktypes->next));
590 for(l=m->gtktypes->next;l;l=g_list_next(l))
591 out_printf(out,",\n\t\t\tGTK_TYPE_%s",
595 out_printf(out,");\n");
597 out_printf(out,"\tgtk_object_class_add_signals (gtk_object_class,\n"
598 "\t\tobject_signals, LAST_SIGNAL);\n\n");
602 set_def_handlers(Class *c, char *oname)
606 out_printf(out,"\n");
607 for(li=c->nodes;li;li=g_list_next(li)) {
610 if(n->type != METHOD_NODE ||
611 (((Method *)n)->scope != SIGNAL_FIRST_METHOD &&
612 ((Method *)n)->scope != SIGNAL_LAST_METHOD &&
613 ((Method *)n)->scope != VIRTUAL_METHOD &&
614 ((Method *)n)->scope != OVERRIDE_METHOD))
619 if(m->scope == OVERRIDE_METHOD) {
621 s = replace_sep(m->otype,'_');
623 out_printf(out,"\t%s_class->%s = %s_%s;\n",
624 s,m->id,funcbase,m->id);
627 out_printf(out,"\t%s->%s = _real_%s_%s;\n",
628 oname,m->id,funcbase,m->id);
630 out_printf(out,"\t%s->%s = NULL;\n",
637 make_arguments(Class *c)
641 out_printf(out,"\n");
642 for(li=c->nodes;li;li=g_list_next(li)) {
648 if(n->type != ARGUMENT_NODE)
654 flags = g_string_new("GTK_ARG_READWRITE");
656 flags = g_string_new("GTK_ARG_READABLE");
658 flags = g_string_new("GTK_ARG_WRITABLE");
660 for(l=a->flags;l;l=g_list_next(l))
661 g_string_sprintfa(flags," | GTK_ARG_%s",(char *)l->data);
663 s = g_strdup(a->name);
665 out_printf(out,"\tgtk_object_add_arg_type(\"%s::%s\",\n"
669 typebase,a->name,a->gtktype,flags->str,s);
671 g_string_free(flags,TRUE);
675 "\n\tgtk_object_class->set_arg = __object_set_arg;\n"
676 "\tgtk_object_class->get_arg = __object_get_arg;\n");
683 for(li=c->nodes;li;li=g_list_next(li)) {
686 if(n->type != METHOD_NODE)
689 if(m->scope == INIT_METHOD) {
691 out_addline_infile(out,m->line_no);
692 print_method(out,"static ","\n"," ","",m);
694 out_addline_outfile(out);
695 out_printf(out,"{\n");
696 } else if(m->scope == CLASS_INIT_METHOD) {
698 out_addline_infile(out,m->line_no);
699 print_method(out,"static ","\n"," ","",m);
701 out_addline_outfile(out);
703 "\tGtkObjectClass *gtk_object_class = "
704 "(GtkObjectClass*) %s;\n",
705 ((FuncArg *)m->args->data)->name);
707 add_overrides(c, ((FuncArg *)m->args->data)->name);
709 out_printf(out,"\n\tparent_class = "
710 "gtk_type_class (%s_get_type ());\n",
716 set_def_handlers(c, ((FuncArg *)m->args->data)->name);
724 out_printf(out," {\n");
725 out_addline_infile(out,m->ccode_line);
726 out_printf(out,"%s\n",m->cbuf->str);
727 out_addline_outfile(out);
728 out_printf(out," }\n",m->cbuf->str);
730 out_printf(out,"return;\n");
732 out_printf(out,"}\n");
737 add_getset_arg(Class *c, int is_set)
740 out_printf(out,"\nstatic void\n"
741 "__object_%s_arg (GtkObject *object,\n"
746 "\tthis = %s (object);\n\n"
747 "\tswitch (arg_id) {\n",
748 is_set?"set":"get",typebase,macrobase);
750 for(li=c->nodes;li;li=g_list_next(li)) {
756 if(n->type != ARGUMENT_NODE)
761 line_no = a->set_line;
764 line_no = a->get_line;
768 s = g_strdup(a->name);
770 out_printf(out,"\tcase ARG_%s:\n"
771 "#define ARG (GTK_VALUE_%s(*arg))\n"
775 out_addline_infile(out,line_no);
776 out_printf(out,"%s\n",cbuf->str);
777 out_addline_outfile(out);
778 out_printf(out,"\t\t}\n\t\tbreak;\n"
781 out_printf(out,"\tdefault:\n\t\tbreak;\n\t}\n}\n");
785 print_checks(Method *m, FuncArg *fa)
789 is_void = (strcmp(m->mtype->name,"void")==0 &&
790 m->mtype->stars == 0);
792 for(li=fa->checks;li;li=g_list_next(li)) {
793 Check *ch = li->data;
796 out_printf(out,"\tg_return_if_fail (");
798 out_printf(out,"\tg_return_val_if_fail (");
801 out_printf(out,"%s != NULL",fa->name);
804 s = make_is_macro(fa->atype->name);
805 out_printf(out,"%s (%s)",s,fa->name);
809 out_printf(out,"%s < %s",fa->name,ch->number);
812 out_printf(out,"%s > %s",fa->name,ch->number);
815 out_printf(out,"%s <= %s",fa->name,ch->number);
818 out_printf(out,"%s >= %s",fa->name,ch->number);
821 out_printf(out,"%s == %s",fa->name,ch->number);
824 out_printf(out,"%s != %s",fa->name,ch->number);
828 out_printf(out,");\n");
830 out_printf(out,", (");
831 print_type(out,m->mtype);
832 out_printf(out,")%s);\n",
833 m->onerror?m->onerror:"0");
839 print_preconditions(Method *m)
843 for(li=m->args;li;li=g_list_next(li)) {
844 FuncArg *fa = li->data;
851 print_method_body(Method *m, int pre)
853 out_printf(out,"{\n");
855 print_preconditions(m);
856 out_printf(out,"\t{\n");
859 out_addline_infile(out,m->ccode_line);
860 out_printf(out,"\t\t%s\n",m->cbuf->str);
861 out_addline_outfile(out);
864 out_printf(out,"\t}\n");
865 out_printf(out,"}\n");
869 put_method(Method *m)
872 out_printf(out,"\n");
875 out_addline_infile(out,m->line_no);
876 print_method(out,"","\n"," ","",m);
877 print_method_body(m,TRUE);
880 out_addline_infile(out,m->line_no);
881 print_method(out,"static ","\n"," ","",m);
882 print_method_body(m,TRUE);
884 case SIGNAL_FIRST_METHOD:
885 case SIGNAL_LAST_METHOD:
886 out_addline_infile(out,m->line_no);
887 print_method(out,"","\n"," ","",m);
888 out_addline_outfile(out);
889 out_printf(out,"{\n");
892 if(strcmp(m->mtype->name,"void")==0 &&
893 m->mtype->stars==0) {
895 print_preconditions(m);
896 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (this),\n"
897 "\t\tobject_signals[%s_SIGNAL]",s);
898 for(li=m->args->next;li;li=g_list_next(li)) {
899 FuncArg *fa = li->data;
900 out_printf(out,",\n\t\t%s",fa->name);
902 out_printf(out,");\n}\n");
905 out_printf(out,"\t");
906 print_type(out,m->mtype);
907 out_printf(out,"return_val;\n");
908 print_preconditions(m);
909 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (this),\n"
910 "\t\tobject_signals[%s_SIGNAL]",s);
911 for(li=m->args->next;li;li=g_list_next(li)) {
912 FuncArg *fa = li->data;
913 out_printf(out,",\n\t\t%s",fa->name);
915 out_printf(out,",\n\t\t&return_val);\n"
916 "\treturn return_val;\n}\n");
921 out_addline_infile(out,m->line_no);
922 print_method(out,"static ","\n_real_"," ","",m);
923 print_method_body(m,FALSE);
926 out_addline_infile(out,m->line_no);
927 print_method(out,"","\n"," ","",m);
928 out_addline_outfile(out);
930 "\t%sClass *class;\n",typebase);
931 print_preconditions(m);
932 out_printf(out,"\tclass = %s_CLASS(GTK_OBJECT(this)->klass);\n\n"
935 if(strcmp(m->mtype->name,"void")==0 &&
936 m->mtype->stars==0) {
938 out_printf(out,"\t\t(*class->%s)(this",m->id);
939 for(li=m->args->next;li;li=g_list_next(li)) {
940 FuncArg *fa = li->data;
941 out_printf(out,",%s",fa->name);
943 out_printf(out,");\n}\n");
946 out_printf(out,"\t\treturn (*class->%s)(this",m->id);
947 for(li=m->args->next;li;li=g_list_next(li)) {
948 FuncArg *fa = li->data;
949 out_printf(out,",%s",fa->name);
951 out_printf(out,");\n"
954 print_type(out,m->mtype);
955 out_printf(out,")(%s);\n}\n",
956 m->onerror?m->onerror:"0");
961 out_addline_infile(out,m->line_no);
962 print_method(out,"static ","\n_real_"," ","",m);
963 print_method_body(m,FALSE);
965 case OVERRIDE_METHOD:
966 out_addline_infile(out,m->line_no);
967 print_method(out,"static ","\n"," ","",m);
968 print_method_body(m,TRUE);
976 count_signals(Class *c)
980 for(l=c->nodes;l;l=g_list_next(l)) {
982 if(n->type == METHOD_NODE) {
983 Method *m = (Method *)n;
984 if(m->scope == SIGNAL_LAST_METHOD ||
985 m->scope == SIGNAL_FIRST_METHOD)
993 count_arguments(Class *c)
998 for(li=c->nodes;li;li=g_list_next(li)) {
1000 if(n->type == ARGUMENT_NODE)
1011 char *outfile,*outfileh;
1013 outfile = g_strconcat(filebase,".c",NULL);
1014 outfileh = g_strconcat(filebase,".h",NULL);
1016 out = fopen(outfile,"w");
1018 g_error("Cannot open outfile: %s",outfile);
1020 outh = fopen(outfileh,"w");
1022 g_error("Cannot open outfile: %s",outfileh);
1027 generate_outfiles(void)
1034 out_printf(outh,"/* Generated by GOB (v%s) on %s"
1035 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1036 out_printf(out,"/* Generated by GOB (v%s) on %s"
1037 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1039 p = replace_sep(((Class *)class)->otype,'_');
1041 out_printf(outh,"#ifndef __%s_H__\n#define __%s_H__\n\n"
1042 "#include <gtk/gtk.h>\n\n",p,p);
1045 out_printf(outh,"#ifdef __cplusplus\n"
1047 "#endif /* __cplusplus */\n\n");
1049 out_printf(out,"#include \"%s.h\"\n\n",filebase);
1051 for(li=nodes;li;li=g_list_next(li)) {
1052 Node *node = li->data;
1053 if(node->type == CCODE_NODE) {
1054 CCode *cc = (CCode *)node;
1060 out_addline_infile(fp,cc->line_no);
1062 out_printf(fp,"\n%s\n",cc->cbuf->str);
1064 out_addline_outfile(fp);
1065 } else if(node->type == CLASS_NODE) {
1067 Class *c = (Class *)class;
1070 signals = count_signals(c);
1071 arguments = count_arguments(c);
1073 out_printf(outh,"\n#define %s(obj)\t"
1074 "GTK_CHECK_CAST((obj),%s_get_type(),%s)\n",
1075 macrobase,funcbase,typebase);
1076 out_printf(outh,"#define %s_CLASS(klass)\t"
1077 "GTK_CHECK_CLASS_CAST((klass),%s_get_type(),%sClass)\n",
1078 macrobase,funcbase,typebase);
1079 out_printf(outh,"#define %s(obj)\t"
1080 "GTK_CHECK_TYPE((obj), %s_get_type ())\n\n",
1083 otype = remove_sep(c->otype);
1084 ptype = remove_sep(c->ptype);
1085 out_printf(outh,"\ntypedef struct _%s %s;\n",otype,otype);
1086 out_printf(outh,"struct _%s {\n\t%s __parent__;\n",
1088 for(l=c->nodes;l;l=g_list_next(l)) {
1090 if(n->type == VARIABLE_NODE)
1091 put_variable((Variable *)n);
1093 out_printf(outh,"};\n");
1095 out_printf(outh,"\ntypedef struct _%sClass %sClass;\n",
1098 "struct _%sClass {\n\t%sClass __parent__;\n",
1100 for(l=c->nodes;l;l=g_list_next(l)) {
1102 if(n->type == METHOD_NODE)
1103 put_vs_method((Method *)n);
1105 out_printf(outh,"};\n\n");
1107 out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
1110 out_printf(out,"static void __object_set_arg "
1111 "(GtkObject *object, GtkArg *arg, "
1113 "static void __object_get_arg "
1114 "(GtkObject *object, GtkArg *arg, "
1115 "guint arg_id);\n");
1118 for(l=c->nodes;l;l=g_list_next(l)) {
1120 if(n->type == METHOD_NODE) {
1121 put_pub_method((Method *)n);
1122 put_priv_method_prot((Method *)n);
1127 for(l=c->nodes;l;l=g_list_next(l)) {
1129 if(n->type == METHOD_NODE) {
1130 add_signal_prots((Method *)n);
1141 out_printf(out,"#define GET_NEW (gtk_type_new(%s_get_type()))\n",
1147 add_getset_arg(c, TRUE);
1148 add_getset_arg(c, FALSE);
1151 for(l=c->nodes;l;l=g_list_next(l)) {
1153 if(n->type == METHOD_NODE) {
1154 put_method((Method *)n);
1158 out_printf(out,"#undef GET_NEW\n");
1165 g_assert_not_reached();
1168 out_printf(outh,"\n#ifdef __cplusplus\n"
1170 "#endif /* __cplusplus */\n\n"
1175 usage(poptContext optCon, int exitcode, char *error, char *addl)
1177 poptPrintUsage(optCon, stderr, 0);
1178 if (error) fprintf(stderr, "%s: %s", error, addl);
1184 main(int argc, char *argv[])
1189 struct poptOption optionsTable[] = {
1190 { "exit-on-warn", 'w', 0, &exit_on_warn, 0,
1191 "exit on warnings" },
1193 { NULL, 0, 0, NULL, 0 }
1196 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
1197 poptSetOtherOptionHelp(optCon, "[OPTIONS]* [filename]");
1199 while ((c = poptGetNextOpt(optCon)) >= 0)
1202 filename = poptGetArg(optCon);
1203 if(!(poptPeekArg(optCon) == NULL))
1204 usage(optCon, 1, "Specify only one file",
1205 ".e.g., filename.gob");
1208 /* an error occurred during option processing */
1209 fprintf(stderr, "%s: %s\n",
1210 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
1216 yyin = fopen(filename,"r");
1218 fprintf(stderr,"Error: can't open file '%s'\n",
1227 g_error("Parsing errors, quitting");
1229 print_error(FALSE," no class defined",0);
1233 make_inits((Class *)class);
1237 generate_outfiles();
1242 poptFreeContext(optCon);