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;
52 static int overrides = 0;
57 int exit_on_warn = FALSE;
60 print_error(int is_warn, char *error,int line)
68 fprintf(stderr,"%s:%d: %s %s\n",filename,line,w,error);
70 fprintf(stderr,"%s: %s %s\n",filename,w,error);
71 if(!is_warn || exit_on_warn)
76 remove_sep(char *base)
79 char *s = g_strdup(base);
80 while((p=strchr(s,':')))
86 replace_sep(char *base, char r)
89 char *s = g_strdup(base);
90 while((p=strchr(s,':')))
100 /*separate the namespace part and then replace rest of
103 separns_replace_sep(char *base, char **ns, char **name, char r)
106 char *s = g_strdup(base);
108 if((p=strchr(s,':')) && p!=s) {
115 while((p=strchr(s,':')))
118 *name = g_strdup(s+1);
125 make_is_macro(char *base)
130 separns_replace_sep(base,&s1,&s2,'_');
132 s = g_strconcat(s1,"_IS_",s2,NULL);
134 s = g_strconcat("IS_",s2,NULL);
147 filebase = replace_sep(((Class *)class)->otype,'-');
150 funcbase = replace_sep(((Class *)class)->otype,'_');
153 pfuncbase = replace_sep(((Class *)class)->ptype,'_');
154 g_strdown(pfuncbase);
156 macrobase = replace_sep(((Class *)class)->otype,'_');
159 macrois = make_is_macro(((Class *)class)->otype);
161 typebase = remove_sep(((Class *)class)->otype);
163 ptypebase = remove_sep(((Class *)class)->ptype);
167 def_methods(Class *c)
171 out_printf(out,"\n");
172 for(li=c->nodes;li;li=g_list_next(li)) {
173 Node *node = li->data;
174 if(node->type == METHOD_NODE) {
175 Method *m = (Method *)node;
177 if(m->scope == INIT_METHOD ||
178 m->scope == CLASS_INIT_METHOD ||
179 m->scope == OVERRIDE_METHOD)
182 out_printf(out,"#define %s %s_%s\n",m->id,funcbase,m->id);
185 out_printf(out,"\n");
189 undef_methods(Class *c)
193 out_printf(out,"\n");
194 for(li=c->nodes;li;li=g_list_next(li)) {
195 Node *node = li->data;
196 if(node->type == METHOD_NODE) {
197 Method *m = (Method *)node;
199 if(m->scope == INIT_METHOD ||
200 m->scope == CLASS_INIT_METHOD ||
201 m->scope == OVERRIDE_METHOD)
204 out_printf(out,"#undef %s\n",m->id);
207 out_printf(out,"\n");
211 print_type(FILE *fp, Type *t)
215 s = remove_sep(t->name);
216 out_printf(fp,"%s ",s);
219 for(i=0;i<t->stars;i++)
224 put_variable(Variable *v)
226 out_printf(outh,"\t");
227 if(v->scope == PRIVATE_SCOPE)
228 out_printf(outh,"/* private */ ");
229 print_type(outh,v->vtype);
231 out_printf(outh,"%s;\n",v->id);
235 print_method(FILE *fp, char *typeprefix, char *nameprefix,
236 char *namepostfix,char *postfix, Method *m)
240 out_printf(fp,"%s",typeprefix);
241 print_type(fp,m->mtype);
242 out_printf(fp,"%s%s_%s%s(",
243 nameprefix,funcbase,m->id,namepostfix);
246 for(li=m->args;li;li=g_list_next(li)) {
247 FuncArg *arg = li->data;
248 print_type(fp,arg->atype);
250 out_printf(fp,"%s, ",arg->name);
252 out_printf(fp,"%s",arg->name);
256 out_printf(fp,"void");
258 out_printf(fp,")%s\n",postfix);
262 put_vs_method(Method *m)
264 if(m->scope != SIGNAL_LAST_METHOD &&
265 m->scope != SIGNAL_FIRST_METHOD &&
266 m->scope != VIRTUAL_METHOD)
269 print_method(outh,"\t","(* ",") ",";",m);
273 put_pub_method(Method *m)
275 if(m->scope == PRIVATE_SCOPE ||
276 m->scope == OVERRIDE_METHOD ||
277 m->scope == INIT_METHOD ||
278 m->scope == CLASS_INIT_METHOD)
281 print_method(outh,"","\t","\t",";",m);
285 put_priv_method_prot(Method *m)
287 if(m->scope == PUBLIC_SCOPE)
290 if(m->scope == SIGNAL_LAST_METHOD ||
291 m->scope == SIGNAL_FIRST_METHOD ||
292 m->scope == VIRTUAL_METHOD) {
295 print_method(out,"static ","_real_"," ",";",m);
297 print_method(out,"static ",""," ",";",m);
302 make_init_args(Class *cl, char *name, int is_class)
309 tn = g_strconcat(cl->otype,":Class",NULL);
311 tn = g_strdup(cl->otype);
313 type = new_type(1,tn);
314 node = new_funcarg((Type *)type,name,NULL);
315 return g_list_prepend(NULL, node);
319 make_inits(Class *cl)
321 int got_class_init = FALSE;
322 int got_init = FALSE;
325 for(li=cl->nodes;li;li=g_list_next(li)) {
327 if(n->type == METHOD_NODE) {
328 Method *m = (Method *)n;
329 if(m->scope == INIT_METHOD) {
331 print_error(FALSE,"init defined more then once",m->line_no);
333 } else if(m->scope == CLASS_INIT_METHOD) {
335 print_error(FALSE,"class_init defined more then once",m->line_no);
336 got_class_init = TRUE;
340 if(!got_class_init) {
341 node = new_method(CLASS_INIT_METHOD,
342 (Type *)new_type(0,g_strdup("void")),
343 NULL,NULL,g_strdup("class_init"),
344 make_init_args(cl,g_strdup("c"),TRUE),
346 cl->nodes = g_list_prepend(cl->nodes,node);
349 node = new_method(INIT_METHOD,
350 (Type *)new_type(0,g_strdup("void")),
351 NULL,NULL,g_strdup("init"),
352 make_init_args(cl,g_strdup("o"),FALSE),
354 cl->nodes = g_list_prepend(cl->nodes,node);
358 static GHashTable *marsh = NULL;
361 add_signal_prots(Method *m)
367 if(m->scope != SIGNAL_LAST_METHOD &&
368 m->scope != SIGNAL_FIRST_METHOD)
372 marsh = g_hash_table_new(NULL,NULL);
374 if(strcmp(m->gtktypes->data,"NONE")==0 &&
375 strcmp(m->gtktypes->next->data,"NONE")==0)
378 s = g_strdup_printf("__Sig%d",sig++);
380 g_hash_table_insert(marsh,m,s);
382 out_printf(out,"\ntypedef ");
383 print_type(out,m->mtype);
385 out_printf(out,"(*%s) (",s);
387 for(li=m->args;li;li=g_list_next(li)) {
388 FuncArg *arg = li->data;
389 print_type(out,arg->atype);
390 out_printf(out,", ");
392 out_printf(out,"gpointer);\n");
394 out_printf(out,"\nstatic void\n"
395 "marshal_%s (GtkObject * object,\n"
396 "\tGtkSignalFunc func,\n"
397 "\tgpointer func_data,\n"
401 if(strcmp(m->gtktypes->data,"NONE")==0) {
403 out_printf(out, "\t%s rfunc;\n\n"
404 "\trfunc = (%s)func;\n\n"
405 "\t(*rfunc)((%s *)object",s,s,typebase);
406 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
407 for(i=0,li=m->gtktypes->next;li;
408 i++,li=g_list_next(li)) {
409 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
413 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
416 out_printf(out, "\t%s rfunc;\n\t",s);
417 print_type(out,m->mtype);
418 out_printf(out, " *retval;\n\n"
419 "\trfunc = (%s)func;\n\n"
420 "\tretval = GTK_RETLOC_%s(args[%d]);\n\n"
421 "\t*retval = (*rfunc)((%s *)object",
422 s,(char *)m->gtktypes->data,
423 g_list_length(m->gtktypes)-1,typebase);
424 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
425 for(i=0,li=m->gtktypes->next;li;
426 i++,li=g_list_next(li)) {
427 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
431 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
440 out_printf(out,"\n");
442 out_printf(out,"enum {\n");
443 for(li=c->nodes;li;li=g_list_next(li)) {
445 if(n->type == METHOD_NODE) {
446 Method *m = (Method *)n;
447 if(m->scope == SIGNAL_LAST_METHOD ||
448 m->scope == SIGNAL_FIRST_METHOD) {
449 char *s = g_strdup(m->id);
451 out_printf(out,"\t%s_SIGNAL,\n",s);
456 out_printf(out,"\tLAST_SIGNAL\n};\n\n");
459 out_printf(out,"enum {\n\tARG_0,\n");
460 for(li=c->nodes;li;li=g_list_next(li)) {
462 if(n->type == ARGUMENT_NODE) {
463 Argument *a = (Argument *)n;
464 char *s = g_strdup(a->name);
466 out_printf(out,"\tARG_%s,\n",s);
470 out_printf(out, "};\n\n");
475 "static guint object_signals[LAST_SIGNAL] = {0};\n\n");
477 out_printf(out, "static %sClass *parent_class = NULL;\n\n",ptypebase);
483 out_printf(out, "guint\n"
484 "%s_get_type (void)\n"
486 "\tstatic guint type = 0;\n\n"
488 "\t\tstatic const GtkTypeInfo info = {\n"
490 "\t\t\tsizeof (%s),\n"
491 "\t\t\tsizeof (%sClass),\n"
492 "\t\t\t(GtkClassInitFunc) %s_class_init,\n"
493 "\t\t\t(GtkObjectInitFunc) %s_init,\n"
494 "\t\t\t/* reserved_1 */ NULL,\n"
495 "\t\t\t/* reserved_2 */ NULL,\n"
496 "\t\t\t(GtkClassInitFunc) NULL,\n"
498 "\t\ttype = gtk_type_unique (%s_get_type(), &info);\n"
502 funcbase,typebase,typebase,typebase,
503 funcbase,funcbase,pfuncbase);
507 add_overrides(Class *c, char *oname)
513 done = g_hash_table_new(g_str_hash,g_str_equal);
514 s = g_strdup("GtkObject"); /* This was already done */
515 g_hash_table_insert(done,s,s);
516 for(li=c->nodes;li;li=g_list_next(li)) {
520 if(n->type != METHOD_NODE ||
521 ((Method *)n)->scope != OVERRIDE_METHOD)
525 s = remove_sep(m->otype);
527 if(g_hash_table_lookup(done,s)) {
531 g_hash_table_insert(done,s,s);
533 f = replace_sep(m->otype,'_');
536 out_printf(out,"\t%sClass *%s_class = (%sClass *)%s;\n",
541 g_hash_table_foreach(done,(GHFunc)g_free,NULL);
542 g_hash_table_destroy(done);
546 add_signals(Class *c)
550 out_printf(out,"\n");
551 for(li=c->nodes;li;li=g_list_next(li)) {
557 if(n->type != METHOD_NODE ||
558 (((Method *)n)->scope != SIGNAL_FIRST_METHOD &&
559 ((Method *)n)->scope != SIGNAL_LAST_METHOD))
564 if(g_hash_table_lookup(marsh,m))
565 mar = g_strconcat("marshal_",
566 (char *)g_hash_table_lookup(marsh,m),
569 mar = g_strdup("gtk_signal_default_marshaller");
571 is_none = (strcmp(m->gtktypes->next->data,"NONE")==0);
573 sig = g_strdup(m->id);
575 out_printf(out,"\tobject_signals[%s_SIGNAL] =\n"
576 "\t\tgtk_signal_new (\"%s\",\n"
577 "\t\t\tGTK_RUN_%s,\n"
578 "\t\t\tgtk_object_class->type,\n"
579 "\t\t\tGTK_SIGNAL_OFFSET (%sClass, %s),\n"
581 "\t\t\tGTK_TYPE_%s, %d",
583 m->scope==SIGNAL_LAST_METHOD?"LAST":"FIRST",
584 typebase,m->id,mar,(char *)m->gtktypes->data,
585 is_none?0:g_list_length(m->gtktypes->next));
591 for(l=m->gtktypes->next;l;l=g_list_next(l))
592 out_printf(out,",\n\t\t\tGTK_TYPE_%s",
596 out_printf(out,");\n");
598 out_printf(out,"\tgtk_object_class_add_signals (gtk_object_class,\n"
599 "\t\tobject_signals, LAST_SIGNAL);\n\n");
603 set_def_handlers(Class *c, char *oname)
607 out_printf(out,"\n");
608 for(li=c->nodes;li;li=g_list_next(li)) {
611 if(n->type != METHOD_NODE ||
612 (((Method *)n)->scope != SIGNAL_FIRST_METHOD &&
613 ((Method *)n)->scope != SIGNAL_LAST_METHOD &&
614 ((Method *)n)->scope != VIRTUAL_METHOD &&
615 ((Method *)n)->scope != OVERRIDE_METHOD))
620 if(m->scope == OVERRIDE_METHOD) {
622 s = replace_sep(m->otype,'_');
624 out_printf(out,"\t%s_class->%s = %s_%s;\n",
625 s,m->id,funcbase,m->id);
628 out_printf(out,"\t%s->%s = _real_%s_%s;\n",
629 oname,m->id,funcbase,m->id);
631 out_printf(out,"\t%s->%s = NULL;\n",
638 make_arguments(Class *c)
642 out_printf(out,"\n");
643 for(li=c->nodes;li;li=g_list_next(li)) {
649 if(n->type != ARGUMENT_NODE)
655 flags = g_string_new("GTK_ARG_READWRITE");
657 flags = g_string_new("GTK_ARG_READABLE");
659 flags = g_string_new("GTK_ARG_WRITABLE");
661 for(l=a->flags;l;l=g_list_next(l))
662 g_string_sprintfa(flags," | GTK_ARG_%s",(char *)l->data);
664 s = g_strdup(a->name);
666 out_printf(out,"\tgtk_object_add_arg_type(\"%s::%s\",\n"
670 typebase,a->name,a->gtktype,flags->str,s);
672 g_string_free(flags,TRUE);
676 "\n\tgtk_object_class->set_arg = __object_set_arg;\n"
677 "\tgtk_object_class->get_arg = __object_get_arg;\n");
684 for(li=c->nodes;li;li=g_list_next(li)) {
687 if(n->type != METHOD_NODE)
690 if(m->scope == INIT_METHOD) {
692 out_addline_infile(out,m->line_no);
693 print_method(out,"static ","\n"," ","",m);
695 out_addline_outfile(out);
696 out_printf(out,"{\n");
697 } else if(m->scope == CLASS_INIT_METHOD) {
699 out_addline_infile(out,m->line_no);
700 print_method(out,"static ","\n"," ","",m);
702 out_addline_outfile(out);
703 out_printf(out,"{\n");
709 "gtk_object_class = "
710 "(GtkObjectClass*) %s;\n",
711 ((FuncArg *)m->args->data)->name);
715 ((FuncArg *)m->args->data)->name);
717 out_printf(out,"\n\tparent_class = "
718 "gtk_type_class (%s_get_type ());\n",
724 set_def_handlers(c, ((FuncArg *)m->args->data)->name);
732 out_printf(out," {\n");
733 out_addline_infile(out,m->ccode_line);
734 out_printf(out,"%s\n",m->cbuf->str);
735 out_addline_outfile(out);
736 out_printf(out," }\n",m->cbuf->str);
738 out_printf(out,"return;\n");
740 out_printf(out,"}\n");
745 add_getset_arg(Class *c, int is_set)
748 out_printf(out,"\nstatic void\n"
749 "__object_%s_arg (GtkObject *object,\n"
754 "\tthis = %s (object);\n\n"
755 "\tswitch (arg_id) {\n",
756 is_set?"set":"get",typebase,macrobase);
758 for(li=c->nodes;li;li=g_list_next(li)) {
764 if(n->type != ARGUMENT_NODE)
769 line_no = a->set_line;
772 line_no = a->get_line;
776 s = g_strdup(a->name);
778 out_printf(out,"\tcase ARG_%s:\n"
779 "#define ARG (GTK_VALUE_%s(*arg))\n"
783 out_addline_infile(out,line_no);
784 out_printf(out,"%s\n",cbuf->str);
785 out_addline_outfile(out);
786 out_printf(out,"\t\t}\n\t\tbreak;\n"
789 out_printf(out,"\tdefault:\n\t\tbreak;\n\t}\n}\n");
793 print_checks(Method *m, FuncArg *fa)
797 is_void = (strcmp(m->mtype->name,"void")==0 &&
798 m->mtype->stars == 0);
800 for(li=fa->checks;li;li=g_list_next(li)) {
801 Check *ch = li->data;
804 out_printf(out,"\tg_return_if_fail (");
806 out_printf(out,"\tg_return_val_if_fail (");
809 out_printf(out,"%s != NULL",fa->name);
812 s = make_is_macro(fa->atype->name);
813 out_printf(out,"%s (%s)",s,fa->name);
817 out_printf(out,"%s < %s",fa->name,ch->number);
820 out_printf(out,"%s > %s",fa->name,ch->number);
823 out_printf(out,"%s <= %s",fa->name,ch->number);
826 out_printf(out,"%s >= %s",fa->name,ch->number);
829 out_printf(out,"%s == %s",fa->name,ch->number);
832 out_printf(out,"%s != %s",fa->name,ch->number);
836 out_printf(out,");\n");
838 out_printf(out,", (");
839 print_type(out,m->mtype);
840 out_printf(out,")%s);\n",
841 m->onerror?m->onerror:"0");
847 print_preconditions(Method *m)
851 for(li=m->args;li;li=g_list_next(li)) {
852 FuncArg *fa = li->data;
859 print_method_body(Method *m, int pre)
861 out_printf(out,"{\n");
863 print_preconditions(m);
864 out_printf(out,"\t{\n");
867 out_addline_infile(out,m->ccode_line);
868 out_printf(out,"\t\t%s\n",m->cbuf->str);
869 out_addline_outfile(out);
872 out_printf(out,"\t}\n");
873 out_printf(out,"}\n");
877 put_method(Method *m)
880 out_printf(out,"\n");
883 out_addline_infile(out,m->line_no);
884 print_method(out,"","\n"," ","",m);
885 print_method_body(m,TRUE);
888 out_addline_infile(out,m->line_no);
889 print_method(out,"static ","\n"," ","",m);
890 print_method_body(m,TRUE);
892 case SIGNAL_FIRST_METHOD:
893 case SIGNAL_LAST_METHOD:
894 out_addline_infile(out,m->line_no);
895 print_method(out,"","\n"," ","",m);
896 out_addline_outfile(out);
897 out_printf(out,"{\n");
900 if(strcmp(m->mtype->name,"void")==0 &&
901 m->mtype->stars==0) {
903 print_preconditions(m);
904 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (this),\n"
905 "\t\tobject_signals[%s_SIGNAL]",s);
906 for(li=m->args->next;li;li=g_list_next(li)) {
907 FuncArg *fa = li->data;
908 out_printf(out,",\n\t\t%s",fa->name);
910 out_printf(out,");\n}\n");
913 out_printf(out,"\t");
914 print_type(out,m->mtype);
915 out_printf(out,"return_val;\n");
916 print_preconditions(m);
917 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (this),\n"
918 "\t\tobject_signals[%s_SIGNAL]",s);
919 for(li=m->args->next;li;li=g_list_next(li)) {
920 FuncArg *fa = li->data;
921 out_printf(out,",\n\t\t%s",fa->name);
923 out_printf(out,",\n\t\t&return_val);\n"
924 "\treturn return_val;\n}\n");
929 out_addline_infile(out,m->line_no);
930 print_method(out,"static ","\n_real_"," ","",m);
931 print_method_body(m,FALSE);
934 out_addline_infile(out,m->line_no);
935 print_method(out,"","\n"," ","",m);
936 out_addline_outfile(out);
938 "\t%sClass *class;\n",typebase);
939 print_preconditions(m);
940 out_printf(out,"\tclass = %s_CLASS(GTK_OBJECT(this)->klass);\n\n"
943 if(strcmp(m->mtype->name,"void")==0 &&
944 m->mtype->stars==0) {
946 out_printf(out,"\t\t(*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}\n");
954 out_printf(out,"\t\treturn (*class->%s)(this",m->id);
955 for(li=m->args->next;li;li=g_list_next(li)) {
956 FuncArg *fa = li->data;
957 out_printf(out,",%s",fa->name);
959 out_printf(out,");\n"
962 print_type(out,m->mtype);
963 out_printf(out,")(%s);\n}\n",
964 m->onerror?m->onerror:"0");
969 out_addline_infile(out,m->line_no);
970 print_method(out,"static ","\n_real_"," ","",m);
971 print_method_body(m,FALSE);
973 case OVERRIDE_METHOD:
974 out_addline_infile(out,m->line_no);
975 print_method(out,"static ","\n"," ","",m);
976 print_method_body(m,TRUE);
984 count_signals(Class *c)
988 for(l=c->nodes;l;l=g_list_next(l)) {
990 if(n->type == METHOD_NODE) {
991 Method *m = (Method *)n;
992 if(m->scope == SIGNAL_LAST_METHOD ||
993 m->scope == SIGNAL_FIRST_METHOD)
1001 count_arguments(Class *c)
1006 for(li=c->nodes;li;li=g_list_next(li)) {
1008 if(n->type == ARGUMENT_NODE)
1015 count_overrides(Class *c)
1019 for(l=c->nodes;l;l=g_list_next(l)) {
1021 if(n->type == METHOD_NODE) {
1022 Method *m = (Method *)n;
1023 if(m->scope == OVERRIDE_METHOD)
1034 char *outfile,*outfileh;
1036 outfile = g_strconcat(filebase,".c",NULL);
1037 outfileh = g_strconcat(filebase,".h",NULL);
1039 out = fopen(outfile,"w");
1041 g_error("Cannot open outfile: %s",outfile);
1043 outh = fopen(outfileh,"w");
1045 g_error("Cannot open outfile: %s",outfileh);
1050 generate_outfiles(void)
1057 out_printf(outh,"/* Generated by GOB (v%s) on %s"
1058 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1059 out_printf(out,"/* Generated by GOB (v%s) on %s"
1060 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1062 p = replace_sep(((Class *)class)->otype,'_');
1064 out_printf(outh,"#ifndef __%s_H__\n#define __%s_H__\n\n"
1065 "#include <gtk/gtk.h>\n\n",p,p);
1068 out_printf(outh,"#ifdef __cplusplus\n"
1070 "#endif /* __cplusplus */\n\n");
1072 out_printf(out,"#include \"%s.h\"\n\n",filebase);
1074 for(li=nodes;li;li=g_list_next(li)) {
1075 Node *node = li->data;
1076 if(node->type == CCODE_NODE) {
1077 CCode *cc = (CCode *)node;
1083 out_addline_infile(fp,cc->line_no);
1085 out_printf(fp,"\n%s\n",cc->cbuf->str);
1087 out_addline_outfile(fp);
1088 } else if(node->type == CLASS_NODE) {
1090 Class *c = (Class *)class;
1093 signals = count_signals(c);
1094 arguments = count_arguments(c);
1095 overrides = count_overrides(c);
1097 out_printf(outh,"\n#define %s(obj)\t"
1098 "GTK_CHECK_CAST((obj),%s_get_type(),%s)\n",
1099 macrobase,funcbase,typebase);
1100 out_printf(outh,"#define %s_CLASS(klass)\t"
1101 "GTK_CHECK_CLASS_CAST((klass),%s_get_type(),%sClass)\n",
1102 macrobase,funcbase,typebase);
1103 out_printf(outh,"#define %s(obj)\t"
1104 "GTK_CHECK_TYPE((obj), %s_get_type ())\n\n",
1107 otype = remove_sep(c->otype);
1108 ptype = remove_sep(c->ptype);
1109 out_printf(outh,"\ntypedef struct _%s %s;\n",otype,otype);
1110 out_printf(outh,"struct _%s {\n\t%s __parent__;\n",
1112 for(l=c->nodes;l;l=g_list_next(l)) {
1114 if(n->type == VARIABLE_NODE)
1115 put_variable((Variable *)n);
1117 out_printf(outh,"};\n");
1119 out_printf(outh,"\ntypedef struct _%sClass %sClass;\n",
1122 "struct _%sClass {\n\t%sClass __parent__;\n",
1124 for(l=c->nodes;l;l=g_list_next(l)) {
1126 if(n->type == METHOD_NODE)
1127 put_vs_method((Method *)n);
1129 out_printf(outh,"};\n\n");
1131 out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
1134 out_printf(out,"static void __object_set_arg "
1135 "(GtkObject *object, GtkArg *arg, "
1137 "static void __object_get_arg "
1138 "(GtkObject *object, GtkArg *arg, "
1139 "guint arg_id);\n");
1142 for(l=c->nodes;l;l=g_list_next(l)) {
1144 if(n->type == METHOD_NODE) {
1145 put_pub_method((Method *)n);
1146 put_priv_method_prot((Method *)n);
1151 for(l=c->nodes;l;l=g_list_next(l)) {
1153 if(n->type == METHOD_NODE) {
1154 add_signal_prots((Method *)n);
1165 out_printf(out,"#define GET_NEW (gtk_type_new(%s_get_type()))\n",
1171 add_getset_arg(c, TRUE);
1172 add_getset_arg(c, FALSE);
1175 for(l=c->nodes;l;l=g_list_next(l)) {
1177 if(n->type == METHOD_NODE) {
1178 put_method((Method *)n);
1182 out_printf(out,"#undef GET_NEW\n");
1189 g_assert_not_reached();
1192 out_printf(outh,"\n#ifdef __cplusplus\n"
1194 "#endif /* __cplusplus */\n\n"
1199 usage(poptContext optCon, int exitcode, char *error, char *addl)
1201 poptPrintUsage(optCon, stderr, 0);
1202 if (error) fprintf(stderr, "%s: %s", error, addl);
1208 main(int argc, char *argv[])
1213 struct poptOption optionsTable[] = {
1214 { "exit-on-warn", 'w', 0, &exit_on_warn, 0,
1215 "exit on warnings" },
1217 { NULL, 0, 0, NULL, 0 }
1220 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
1221 poptSetOtherOptionHelp(optCon, "[OPTIONS]* [filename]");
1223 while ((c = poptGetNextOpt(optCon)) >= 0)
1226 filename = poptGetArg(optCon);
1227 if(!(poptPeekArg(optCon) == NULL))
1228 usage(optCon, 1, "Specify only one file",
1229 ".e.g., filename.gob");
1232 /* an error occurred during option processing */
1233 fprintf(stderr, "%s: %s\n",
1234 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
1240 yyin = fopen(filename,"r");
1242 fprintf(stderr,"Error: can't open file '%s'\n",
1251 g_error("Parsing errors, quitting");
1253 print_error(FALSE," no class defined",0);
1257 make_inits((Class *)class);
1261 generate_outfiles();
1266 poptFreeContext(optCon);