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,
34 char *filename = "stdin";
44 static char *funcbase;
45 static char *pfuncbase;
46 static char *macrobase;
48 static char *typebase;
49 static char *ptypebase;
51 static int signals = 0;
52 static int arguments = 0;
53 static int overrides = 0;
58 int exit_on_warn = FALSE;
59 int exit_on_error = TRUE;
60 int got_error = FALSE;
63 print_error(int is_warn, char *error,int line)
73 fprintf(stderr,"%s:%d: %s %s\n",filename,line,w,error);
75 fprintf(stderr,"%s: %s %s\n",filename,w,error);
76 if((!is_warn || exit_on_warn) && exit_on_error)
81 remove_sep(char *base)
84 char *s = g_strdup(base);
85 while((p=strchr(s,':')))
91 replace_sep(char *base, char r)
94 char *s = g_strdup(base);
95 while((p=strchr(s,':')))
105 /*separate the namespace part and then replace rest of
108 separns_replace_sep(char *base, char **ns, char **name, char r)
111 char *s = g_strdup(base);
113 if((p=strchr(s,':')) && p!=s) {
120 while((p=strchr(s,':')))
123 *name = g_strdup(s+1);
130 make_is_macro(char *base)
135 separns_replace_sep(base,&s1,&s2,'_');
137 s = g_strconcat(s1,"_IS_",s2,NULL);
139 s = g_strconcat("IS_",s2,NULL);
152 filebase = replace_sep(((Class *)class)->otype,'-');
155 funcbase = replace_sep(((Class *)class)->otype,'_');
158 pfuncbase = replace_sep(((Class *)class)->ptype,'_');
159 g_strdown(pfuncbase);
161 macrobase = replace_sep(((Class *)class)->otype,'_');
164 macrois = make_is_macro(((Class *)class)->otype);
166 typebase = remove_sep(((Class *)class)->otype);
168 ptypebase = remove_sep(((Class *)class)->ptype);
172 def_methods(Class *c)
176 out_printf(out,"\n");
177 for(li=c->nodes;li;li=g_list_next(li)) {
178 Node *node = li->data;
179 if(node->type == METHOD_NODE) {
180 Method *m = (Method *)node;
182 if(m->scope == INIT_METHOD ||
183 m->scope == CLASS_INIT_METHOD ||
184 m->scope == OVERRIDE_METHOD)
187 out_printf(out,"#define %s %s_%s\n",m->id,funcbase,m->id);
190 out_printf(out,"\n");
194 undef_methods(Class *c)
198 out_printf(out,"\n");
199 for(li=c->nodes;li;li=g_list_next(li)) {
200 Node *node = li->data;
201 if(node->type == METHOD_NODE) {
202 Method *m = (Method *)node;
204 if(m->scope == INIT_METHOD ||
205 m->scope == CLASS_INIT_METHOD ||
206 m->scope == OVERRIDE_METHOD)
209 out_printf(out,"#undef %s\n",m->id);
212 out_printf(out,"\n");
216 print_type(FILE *fp, Type *t)
220 s = remove_sep(t->name);
221 out_printf(fp,"%s ",s);
224 for(i=0;i<t->stars;i++)
229 put_variable(Variable *v)
231 out_printf(outh,"\t");
232 if(v->scope == PRIVATE_SCOPE)
233 out_printf(outh,"/* private */ ");
234 print_type(outh,v->vtype);
236 out_printf(outh,"%s;\n",v->id);
240 print_method(FILE *fp, char *typeprefix, char *nameprefix,
241 char *namepostfix,char *postfix, Method *m)
245 out_printf(fp,"%s",typeprefix);
246 print_type(fp,m->mtype);
247 out_printf(fp,"%s%s_%s%s(",
248 nameprefix,funcbase,m->id,namepostfix);
251 for(li=m->args;li;li=g_list_next(li)) {
252 FuncArg *arg = li->data;
253 print_type(fp,arg->atype);
255 out_printf(fp,"%s, ",arg->name);
257 out_printf(fp,"%s",arg->name);
261 out_printf(fp,"void");
263 out_printf(fp,")%s\n",postfix);
267 put_vs_method(Method *m)
269 if(m->scope != SIGNAL_LAST_METHOD &&
270 m->scope != SIGNAL_FIRST_METHOD &&
271 m->scope != VIRTUAL_METHOD)
274 print_method(outh,"\t","(* ",") ",";",m);
278 put_pub_method(Method *m)
280 if(m->scope == PRIVATE_SCOPE ||
281 m->scope == OVERRIDE_METHOD ||
282 m->scope == INIT_METHOD ||
283 m->scope == CLASS_INIT_METHOD)
286 print_method(outh,"","\t","\t",";",m);
290 put_priv_method_prot(Method *m)
292 if(m->scope == PUBLIC_SCOPE)
295 if(m->scope == SIGNAL_LAST_METHOD ||
296 m->scope == SIGNAL_FIRST_METHOD ||
297 m->scope == VIRTUAL_METHOD) {
300 print_method(out,"static ","_real_"," ",";",m);
302 print_method(out,"static ",""," ",";",m);
307 make_init_args(Class *cl, char *name, int is_class)
314 tn = g_strconcat(cl->otype,":Class",NULL);
316 tn = g_strdup(cl->otype);
318 type = new_type(1,tn);
319 node = new_funcarg((Type *)type,name,NULL);
320 return g_list_prepend(NULL, node);
324 make_inits(Class *cl)
326 int got_class_init = FALSE;
327 int got_init = FALSE;
330 for(li=cl->nodes;li;li=g_list_next(li)) {
332 if(n->type == METHOD_NODE) {
333 Method *m = (Method *)n;
334 if(m->scope == INIT_METHOD) {
336 print_error(FALSE,"init defined more then once",m->line_no);
338 } else if(m->scope == CLASS_INIT_METHOD) {
340 print_error(FALSE,"class_init defined more then once",m->line_no);
341 got_class_init = TRUE;
345 if(!got_class_init) {
346 node = new_method(CLASS_INIT_METHOD,
347 (Type *)new_type(0,g_strdup("void")),
348 NULL,NULL,g_strdup("class_init"),
349 make_init_args(cl,g_strdup("c"),TRUE),
351 cl->nodes = g_list_prepend(cl->nodes,node);
354 node = new_method(INIT_METHOD,
355 (Type *)new_type(0,g_strdup("void")),
356 NULL,NULL,g_strdup("init"),
357 make_init_args(cl,g_strdup("o"),FALSE),
359 cl->nodes = g_list_prepend(cl->nodes,node);
363 static GHashTable *marsh = NULL;
366 add_signal_prots(Method *m)
372 if(m->scope != SIGNAL_LAST_METHOD &&
373 m->scope != SIGNAL_FIRST_METHOD)
377 marsh = g_hash_table_new(NULL,NULL);
379 if(strcmp(m->gtktypes->data,"NONE")==0 &&
380 strcmp(m->gtktypes->next->data,"NONE")==0)
383 s = g_strdup_printf("__Sig%d",sig++);
385 g_hash_table_insert(marsh,m,s);
387 out_printf(out,"\ntypedef ");
388 print_type(out,m->mtype);
390 out_printf(out,"(*%s) (",s);
392 for(li=m->args;li;li=g_list_next(li)) {
393 FuncArg *arg = li->data;
394 print_type(out,arg->atype);
395 out_printf(out,", ");
397 out_printf(out,"gpointer);\n");
399 out_printf(out,"\nstatic void\n"
400 "marshal_%s (GtkObject * object,\n"
401 "\tGtkSignalFunc func,\n"
402 "\tgpointer func_data,\n"
406 if(strcmp(m->gtktypes->data,"NONE")==0) {
408 out_printf(out, "\t%s rfunc;\n\n"
409 "\trfunc = (%s)func;\n\n"
410 "\t(*rfunc)((%s *)object",s,s,typebase);
411 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
412 for(i=0,li=m->gtktypes->next;li;
413 i++,li=g_list_next(li)) {
414 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
418 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
421 out_printf(out, "\t%s rfunc;\n\t",s);
422 print_type(out,m->mtype);
423 out_printf(out, " *retval;\n\n"
424 "\trfunc = (%s)func;\n\n"
425 "\tretval = GTK_RETLOC_%s(args[%d]);\n\n"
426 "\t*retval = (*rfunc)((%s *)object",
427 s,(char *)m->gtktypes->data,
428 g_list_length(m->gtktypes)-1,typebase);
429 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
430 for(i=0,li=m->gtktypes->next;li;
431 i++,li=g_list_next(li)) {
432 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
436 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
445 out_printf(out,"\n");
447 out_printf(out,"enum {\n");
448 for(li=c->nodes;li;li=g_list_next(li)) {
450 if(n->type == METHOD_NODE) {
451 Method *m = (Method *)n;
452 if(m->scope == SIGNAL_LAST_METHOD ||
453 m->scope == SIGNAL_FIRST_METHOD) {
454 char *s = g_strdup(m->id);
456 out_printf(out,"\t%s_SIGNAL,\n",s);
461 out_printf(out,"\tLAST_SIGNAL\n};\n\n");
464 out_printf(out,"enum {\n\tARG_0,\n");
465 for(li=c->nodes;li;li=g_list_next(li)) {
467 if(n->type == ARGUMENT_NODE) {
468 Argument *a = (Argument *)n;
469 char *s = g_strdup(a->name);
471 out_printf(out,"\tARG_%s,\n",s);
475 out_printf(out, "};\n\n");
480 "static guint object_signals[LAST_SIGNAL] = {0};\n\n");
482 out_printf(out, "static %sClass *parent_class = NULL;\n\n",ptypebase);
488 out_printf(out, "guint\n"
489 "%s_get_type (void)\n"
491 "\tstatic guint type = 0;\n\n"
493 "\t\tstatic const GtkTypeInfo info = {\n"
495 "\t\t\tsizeof (%s),\n"
496 "\t\t\tsizeof (%sClass),\n"
497 "\t\t\t(GtkClassInitFunc) %s_class_init,\n"
498 "\t\t\t(GtkObjectInitFunc) %s_init,\n"
499 "\t\t\t/* reserved_1 */ NULL,\n"
500 "\t\t\t/* reserved_2 */ NULL,\n"
501 "\t\t\t(GtkClassInitFunc) NULL,\n"
503 "\t\ttype = gtk_type_unique (%s_get_type(), &info);\n"
507 funcbase,typebase,typebase,typebase,
508 funcbase,funcbase,pfuncbase);
512 add_overrides(Class *c, char *oname)
518 done = g_hash_table_new(g_str_hash,g_str_equal);
519 s = g_strdup("GtkObject"); /* This was already done */
520 g_hash_table_insert(done,s,s);
521 for(li=c->nodes;li;li=g_list_next(li)) {
525 if(n->type != METHOD_NODE ||
526 ((Method *)n)->scope != OVERRIDE_METHOD)
530 s = remove_sep(m->otype);
532 if(g_hash_table_lookup(done,s)) {
536 g_hash_table_insert(done,s,s);
538 f = replace_sep(m->otype,'_');
541 out_printf(out,"\t%sClass *%s_class = (%sClass *)%s;\n",
546 g_hash_table_foreach(done,(GHFunc)g_free,NULL);
547 g_hash_table_destroy(done);
551 add_signals(Class *c)
555 out_printf(out,"\n");
556 for(li=c->nodes;li;li=g_list_next(li)) {
562 if(n->type != METHOD_NODE ||
563 (((Method *)n)->scope != SIGNAL_FIRST_METHOD &&
564 ((Method *)n)->scope != SIGNAL_LAST_METHOD))
569 if(g_hash_table_lookup(marsh,m))
570 mar = g_strconcat("marshal_",
571 (char *)g_hash_table_lookup(marsh,m),
574 mar = g_strdup("gtk_signal_default_marshaller");
576 is_none = (strcmp(m->gtktypes->next->data,"NONE")==0);
578 sig = g_strdup(m->id);
580 out_printf(out,"\tobject_signals[%s_SIGNAL] =\n"
581 "\t\tgtk_signal_new (\"%s\",\n"
582 "\t\t\tGTK_RUN_%s,\n"
583 "\t\t\tgtk_object_class->type,\n"
584 "\t\t\tGTK_SIGNAL_OFFSET (%sClass, %s),\n"
586 "\t\t\tGTK_TYPE_%s, %d",
588 m->scope==SIGNAL_LAST_METHOD?"LAST":"FIRST",
589 typebase,m->id,mar,(char *)m->gtktypes->data,
590 is_none?0:g_list_length(m->gtktypes->next));
596 for(l=m->gtktypes->next;l;l=g_list_next(l))
597 out_printf(out,",\n\t\t\tGTK_TYPE_%s",
601 out_printf(out,");\n");
603 out_printf(out,"\tgtk_object_class_add_signals (gtk_object_class,\n"
604 "\t\tobject_signals, LAST_SIGNAL);\n\n");
608 set_def_handlers(Class *c, char *oname)
612 out_printf(out,"\n");
613 for(li=c->nodes;li;li=g_list_next(li)) {
616 if(n->type != METHOD_NODE ||
617 (((Method *)n)->scope != SIGNAL_FIRST_METHOD &&
618 ((Method *)n)->scope != SIGNAL_LAST_METHOD &&
619 ((Method *)n)->scope != VIRTUAL_METHOD &&
620 ((Method *)n)->scope != OVERRIDE_METHOD))
625 if(m->scope == OVERRIDE_METHOD) {
627 s = replace_sep(m->otype,'_');
629 out_printf(out,"\t%s_class->%s = %s_%s;\n",
630 s,m->id,funcbase,m->id);
633 out_printf(out,"\t%s->%s = _real_%s_%s;\n",
634 oname,m->id,funcbase,m->id);
636 out_printf(out,"\t%s->%s = NULL;\n",
643 make_arguments(Class *c)
647 out_printf(out,"\n");
648 for(li=c->nodes;li;li=g_list_next(li)) {
654 if(n->type != ARGUMENT_NODE)
660 flags = g_string_new("GTK_ARG_READWRITE");
662 flags = g_string_new("GTK_ARG_READABLE");
664 flags = g_string_new("GTK_ARG_WRITABLE");
666 for(l=a->flags;l;l=g_list_next(l))
667 g_string_sprintfa(flags," | GTK_ARG_%s",(char *)l->data);
669 s = g_strdup(a->name);
671 out_printf(out,"\tgtk_object_add_arg_type(\"%s::%s\",\n"
675 typebase,a->name,a->gtktype,flags->str,s);
677 g_string_free(flags,TRUE);
681 "\n\tgtk_object_class->set_arg = __object_set_arg;\n"
682 "\tgtk_object_class->get_arg = __object_get_arg;\n");
689 for(li=c->nodes;li;li=g_list_next(li)) {
692 if(n->type != METHOD_NODE)
695 if(m->scope == INIT_METHOD) {
697 out_addline_infile(out,m->line_no);
698 print_method(out,"static ","\n"," ","",m);
700 out_addline_outfile(out);
701 out_printf(out,"{\n");
702 } else if(m->scope == CLASS_INIT_METHOD) {
704 out_addline_infile(out,m->line_no);
705 print_method(out,"static ","\n"," ","",m);
707 out_addline_outfile(out);
708 out_printf(out,"{\n");
714 "gtk_object_class = "
715 "(GtkObjectClass*) %s;\n",
716 ((FuncArg *)m->args->data)->name);
720 ((FuncArg *)m->args->data)->name);
722 out_printf(out,"\n\tparent_class = "
723 "gtk_type_class (%s_get_type ());\n",
729 set_def_handlers(c, ((FuncArg *)m->args->data)->name);
737 out_printf(out," {\n");
738 out_addline_infile(out,m->ccode_line);
739 out_printf(out,"%s\n",m->cbuf->str);
740 out_addline_outfile(out);
741 out_printf(out," }\n",m->cbuf->str);
743 out_printf(out,"return;\n");
745 out_printf(out,"}\n");
750 add_getset_arg(Class *c, int is_set)
753 out_printf(out,"\nstatic void\n"
754 "__object_%s_arg (GtkObject *object,\n"
758 "\t%s *self, *this;\n\n"
759 "\tself = this = %s (object);\n\n"
760 "\tswitch (arg_id) {\n",
761 is_set?"set":"get",typebase,macrobase);
763 for(li=c->nodes;li;li=g_list_next(li)) {
769 if(n->type != ARGUMENT_NODE)
774 line_no = a->set_line;
777 line_no = a->get_line;
781 s = g_strdup(a->name);
783 out_printf(out,"\tcase ARG_%s:\n"
784 "#define ARG (GTK_VALUE_%s(*arg))\n"
788 out_addline_infile(out,line_no);
789 out_printf(out,"%s\n",cbuf->str);
790 out_addline_outfile(out);
791 out_printf(out,"\t\t}\n\t\tbreak;\n"
794 out_printf(out,"\tdefault:\n\t\tbreak;\n\t}\n}\n");
798 print_checks(Method *m, FuncArg *fa)
802 is_void = (strcmp(m->mtype->name,"void")==0 &&
803 m->mtype->stars == 0);
805 for(li=fa->checks;li;li=g_list_next(li)) {
806 Check *ch = li->data;
809 out_printf(out,"\tg_return_if_fail (");
811 out_printf(out,"\tg_return_val_if_fail (");
814 out_printf(out,"%s != NULL",fa->name);
817 s = make_is_macro(fa->atype->name);
818 out_printf(out,"%s (%s)",s,fa->name);
822 out_printf(out,"%s < %s",fa->name,ch->number);
825 out_printf(out,"%s > %s",fa->name,ch->number);
828 out_printf(out,"%s <= %s",fa->name,ch->number);
831 out_printf(out,"%s >= %s",fa->name,ch->number);
834 out_printf(out,"%s == %s",fa->name,ch->number);
837 out_printf(out,"%s != %s",fa->name,ch->number);
841 out_printf(out,");\n");
843 out_printf(out,", (");
844 print_type(out,m->mtype);
845 out_printf(out,")%s);\n",
846 m->onerror?m->onerror:"0");
852 print_preconditions(Method *m)
856 for(li=m->args;li;li=g_list_next(li)) {
857 FuncArg *fa = li->data;
864 print_method_body(Method *m, int pre)
866 out_printf(out,"{\n");
868 print_preconditions(m);
869 out_printf(out,"\t{\n");
872 out_addline_infile(out,m->ccode_line);
873 out_printf(out,"\t\t%s\n",m->cbuf->str);
874 out_addline_outfile(out);
877 out_printf(out,"\t}\n");
878 out_printf(out,"}\n");
882 put_method(Method *m)
885 out_printf(out,"\n");
888 out_addline_infile(out,m->line_no);
889 print_method(out,"","\n"," ","",m);
890 print_method_body(m,TRUE);
893 out_addline_infile(out,m->line_no);
894 print_method(out,"static ","\n"," ","",m);
895 print_method_body(m,TRUE);
897 case SIGNAL_FIRST_METHOD:
898 case SIGNAL_LAST_METHOD:
899 out_addline_infile(out,m->line_no);
900 print_method(out,"","\n"," ","",m);
901 out_addline_outfile(out);
902 out_printf(out,"{\n");
905 if(strcmp(m->mtype->name,"void")==0 &&
906 m->mtype->stars==0) {
908 print_preconditions(m);
909 if(((FuncArg *)m->args->data)->name)
910 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (%s),\n"
911 "\t\tobject_signals[%s_SIGNAL]",
912 ((FuncArg *)m->args->data)->name,s);
913 for(li=m->args->next;li;li=g_list_next(li)) {
914 FuncArg *fa = li->data;
915 out_printf(out,",\n\t\t%s",fa->name);
917 out_printf(out,");\n}\n");
920 out_printf(out,"\t");
921 print_type(out,m->mtype);
922 out_printf(out,"return_val;\n");
923 print_preconditions(m);
924 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (%s),\n"
925 "\t\tobject_signals[%s_SIGNAL]",
926 ((FuncArg *)m->args->data)->name,s);
927 for(li=m->args->next;li;li=g_list_next(li)) {
928 FuncArg *fa = li->data;
929 out_printf(out,",\n\t\t%s",fa->name);
931 out_printf(out,",\n\t\t&return_val);\n"
932 "\treturn return_val;\n}\n");
937 out_addline_infile(out,m->line_no);
938 print_method(out,"static ","\n_real_"," ","",m);
939 print_method_body(m,FALSE);
942 out_addline_infile(out,m->line_no);
943 print_method(out,"","\n"," ","",m);
944 out_addline_outfile(out);
946 "\t%sClass *class;\n",typebase);
947 print_preconditions(m);
948 out_printf(out,"\tclass = %s_CLASS(GTK_OBJECT(%s)->klass);\n\n"
950 macrobase, ((FuncArg *)m->args->data)->name, m->id);
951 if(strcmp(m->mtype->name,"void")==0 &&
952 m->mtype->stars==0) {
954 out_printf(out,"\t\t(*class->%s)(%s",m->id,
955 ((FuncArg *)m->args->data)->name);
956 for(li=m->args->next;li;li=g_list_next(li)) {
957 FuncArg *fa = li->data;
958 out_printf(out,",%s",fa->name);
960 out_printf(out,");\n}\n");
963 out_printf(out,"\t\treturn (*class->%s)(%s",m->id,
964 ((FuncArg *)m->args->data)->name);
965 for(li=m->args->next;li;li=g_list_next(li)) {
966 FuncArg *fa = li->data;
967 out_printf(out,",%s",fa->name);
969 out_printf(out,");\n"
972 print_type(out,m->mtype);
973 out_printf(out,")(%s);\n}\n",
974 m->onerror?m->onerror:"0");
979 out_addline_infile(out,m->line_no);
980 print_method(out,"static ","\n_real_"," ","",m);
981 print_method_body(m,FALSE);
983 case OVERRIDE_METHOD:
984 out_addline_infile(out,m->line_no);
985 print_method(out,"static ","\n"," ","",m);
986 print_method_body(m,TRUE);
994 check_duplicate(Class *c,Node *node,char *id, int line_no)
997 for(l=c->nodes;l;l=g_list_next(l)) {
1002 if(n->type == METHOD_NODE) {
1003 Method *m = (Method *)n;
1005 nline_no = m->line_no;
1006 } else if(n->type == VARIABLE_NODE) {
1007 Variable *v = (Variable *)n;
1009 nline_no = v->line_no;
1013 line_no>=nline_no ||
1016 s = g_strdup_printf("symbol '%s' redefined, "
1017 "first defined on line %d",
1019 print_error(FALSE,s,nline_no);
1024 check_duplicate_symbols(Class *c)
1027 for(l=c->nodes;l;l=g_list_next(l)) {
1029 if(n->type == METHOD_NODE) {
1030 Method *m = (Method *)n;
1031 check_duplicate(c,n,m->id,m->line_no);
1032 } else if(n->type == VARIABLE_NODE) {
1033 Variable *v = (Variable *)n;
1034 check_duplicate(c,n,v->id,v->line_no);
1040 check_duplicate_named(Class *c,Node *node,char *id, int line_no)
1043 for(l=c->nodes;l;l=g_list_next(l)) {
1048 if(n->type == METHOD_NODE) {
1049 Method *m = (Method *)n;
1050 if(m->scope == SIGNAL_LAST_METHOD ||
1051 m->scope == SIGNAL_FIRST_METHOD) {
1053 nline_no = m->line_no;
1056 } else if(n->type == ARGUMENT_NODE) {
1057 Argument *a = (Argument *)n;
1059 nline_no = a->line_no;
1063 line_no>=nline_no ||
1066 s = g_strdup_printf("named symbol (argument or signal) '%s' "
1067 "redefined, first defined on line %d",
1069 print_error(FALSE,s,nline_no);
1074 check_duplicate_signals_args(Class *c)
1077 for(l=c->nodes;l;l=g_list_next(l)) {
1079 if(n->type == METHOD_NODE) {
1080 Method *m = (Method *)n;
1081 if(m->scope == SIGNAL_LAST_METHOD ||
1082 m->scope == SIGNAL_FIRST_METHOD)
1083 check_duplicate_named(c,n,m->id,m->line_no);
1084 } else if(n->type == ARGUMENT_NODE) {
1085 Argument *a = (Argument *)n;
1086 check_duplicate_named(c,n,a->name,a->line_no);
1092 check_public_new(Class *c)
1095 for(l=c->nodes;l;l=g_list_next(l)) {
1097 if(n->type == METHOD_NODE) {
1098 Method *m = (Method *)n;
1099 if(m->scope!=PUBLIC_SCOPE &&
1100 strcmp(m->id,"new")==0)
1102 "'new' should be a public method",
1109 count_signals(Class *c)
1113 for(l=c->nodes;l;l=g_list_next(l)) {
1115 if(n->type == METHOD_NODE) {
1116 Method *m = (Method *)n;
1117 if(m->scope == SIGNAL_LAST_METHOD ||
1118 m->scope == SIGNAL_FIRST_METHOD)
1126 count_arguments(Class *c)
1131 for(li=c->nodes;li;li=g_list_next(li)) {
1133 if(n->type == ARGUMENT_NODE)
1140 count_overrides(Class *c)
1144 for(l=c->nodes;l;l=g_list_next(l)) {
1146 if(n->type == METHOD_NODE) {
1147 Method *m = (Method *)n;
1148 if(m->scope == OVERRIDE_METHOD)
1159 char *outfile,*outfileh;
1161 outfile = g_strconcat(filebase,".c",NULL);
1162 outfileh = g_strconcat(filebase,".h",NULL);
1164 out = fopen(outfile,"w");
1166 g_error("Cannot open outfile: %s",outfile);
1168 outh = fopen(outfileh,"w");
1170 g_error("Cannot open outfile: %s",outfileh);
1175 generate_outfiles(void)
1182 out_printf(outh,"/* Generated by GOB (v%s) on %s"
1183 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1184 out_printf(out,"/* Generated by GOB (v%s) on %s"
1185 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1187 p = replace_sep(((Class *)class)->otype,'_');
1189 out_printf(outh,"#ifndef __%s_H__\n#define __%s_H__\n\n"
1190 "#include <gtk/gtk.h>\n\n",p,p);
1193 out_printf(outh,"#ifdef __cplusplus\n"
1195 "#endif /* __cplusplus */\n\n");
1197 out_printf(out,"#include \"%s.h\"\n\n",filebase);
1199 for(li=nodes;li;li=g_list_next(li)) {
1200 Node *node = li->data;
1201 if(node->type == CCODE_NODE) {
1202 CCode *cc = (CCode *)node;
1208 out_addline_infile(fp,cc->line_no);
1210 out_printf(fp,"\n%s\n",cc->cbuf->str);
1212 out_addline_outfile(fp);
1213 } else if(node->type == CLASS_NODE) {
1215 Class *c = (Class *)class;
1218 signals = count_signals(c);
1219 arguments = count_arguments(c);
1220 overrides = count_overrides(c);
1222 out_printf(outh,"\n#define %s(obj)\t"
1223 "GTK_CHECK_CAST((obj),%s_get_type(),%s)\n",
1224 macrobase,funcbase,typebase);
1225 out_printf(outh,"#define %s_CLASS(klass)\t"
1226 "GTK_CHECK_CLASS_CAST((klass),%s_get_type(),%sClass)\n",
1227 macrobase,funcbase,typebase);
1228 out_printf(outh,"#define %s(obj)\t"
1229 "GTK_CHECK_TYPE((obj), %s_get_type ())\n\n",
1232 otype = remove_sep(c->otype);
1233 ptype = remove_sep(c->ptype);
1234 out_printf(outh,"\ntypedef struct _%s %s;\n",otype,otype);
1235 out_printf(outh,"struct _%s {\n\t%s __parent__;\n",
1237 for(l=c->nodes;l;l=g_list_next(l)) {
1239 if(n->type == VARIABLE_NODE)
1240 put_variable((Variable *)n);
1242 out_printf(outh,"};\n");
1244 out_printf(outh,"\ntypedef struct _%sClass %sClass;\n",
1247 "struct _%sClass {\n\t%sClass __parent__;\n",
1249 for(l=c->nodes;l;l=g_list_next(l)) {
1251 if(n->type == METHOD_NODE)
1252 put_vs_method((Method *)n);
1254 out_printf(outh,"};\n\n");
1256 out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
1259 out_printf(out,"static void __object_set_arg "
1260 "(GtkObject *object, GtkArg *arg, "
1262 "static void __object_get_arg "
1263 "(GtkObject *object, GtkArg *arg, "
1264 "guint arg_id);\n");
1267 for(l=c->nodes;l;l=g_list_next(l)) {
1269 if(n->type == METHOD_NODE) {
1270 put_pub_method((Method *)n);
1271 put_priv_method_prot((Method *)n);
1276 for(l=c->nodes;l;l=g_list_next(l)) {
1278 if(n->type == METHOD_NODE) {
1279 add_signal_prots((Method *)n);
1290 out_printf(out,"#define GET_NEW (gtk_type_new(%s_get_type()))\n",
1296 add_getset_arg(c, TRUE);
1297 add_getset_arg(c, FALSE);
1300 for(l=c->nodes;l;l=g_list_next(l)) {
1302 if(n->type == METHOD_NODE) {
1303 put_method((Method *)n);
1307 out_printf(out,"#undef GET_NEW\n");
1314 g_assert_not_reached();
1317 out_printf(outh,"\n#ifdef __cplusplus\n"
1319 "#endif /* __cplusplus */\n\n"
1324 usage(poptContext optCon, int exitcode, char *error, char *addl)
1326 poptPrintUsage(optCon, stderr, 0);
1327 if (error) fprintf(stderr, "%s: %s", error, addl);
1333 main(int argc, char *argv[])
1338 struct poptOption optionsTable[] = {
1339 { "exit-on-warn", 'w', 0, &exit_on_warn, 0,
1340 "exit on warnings" },
1342 { NULL, 0, 0, NULL, 0 }
1345 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
1346 poptSetOtherOptionHelp(optCon, "[OPTIONS]* [filename]");
1348 while ((c = poptGetNextOpt(optCon)) >= 0)
1351 filename = poptGetArg(optCon);
1352 if(!(poptPeekArg(optCon) == NULL))
1353 usage(optCon, 1, "Specify only one file",
1354 ".e.g., filename.gob");
1357 /* an error occurred during option processing */
1358 fprintf(stderr, "%s: %s\n",
1359 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
1365 yyin = fopen(filename,"r");
1367 fprintf(stderr,"Error: can't open file '%s'\n",
1376 g_error("Parsing errors, quitting");
1378 print_error(FALSE," no class defined",0);
1382 exit_on_error = FALSE;
1383 make_inits((Class *)class);
1384 check_duplicate_symbols((Class *)class);
1385 check_duplicate_signals_args((Class *)class);
1386 check_public_new((Class *)class);
1387 exit_on_error = TRUE;
1394 generate_outfiles();
1399 poptFreeContext(optCon);