2 * Copyright (C) 1999-2000 the Free Software Foundation.
3 * Copyright (C) 2000 Eazel, Inc.
4 * Copyright (C) 2001-2004 George (Jiri) Lebl
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
31 #include "treefuncs.h"
35 /* FIXME: add gettext support */
40 static GList *class_nodes = NULL;
43 static GList *enum_vals = NULL;
44 static GList *flag_vals = NULL;
45 static GList *error_vals = NULL;
47 static char *chunk_size = NULL;
48 static char *bonobo_object_class = NULL;
49 static GList *interfaces = NULL;
50 static GList *typestack = NULL;
51 static GList *funcargs = NULL;
52 static GList *checks = NULL;
53 static int has_self = FALSE;
54 static int vararg = FALSE;
55 static Method *last_added_method = NULL;
57 /* destructor and initializer for variables */
58 static gboolean destructor_unref = FALSE;
59 static char *destructor = NULL;
60 static int destructor_line = 0;
61 static gboolean destructor_simple = TRUE;
62 static char *initializer = NULL;
63 static int initializer_line = 0;
65 static char *onerror = NULL;
66 static char *defreturn = NULL;
68 static GList *gtktypes = NULL;
70 static Property *property = NULL;
72 /* this can be a global as we will only do one function at a time
74 static int the_scope = NO_SCOPE;
79 extern int ccode_line;
81 extern gboolean for_cpp;
91 if(strcmp(yytext,"\n")==0) {
92 out=g_strconcat("Error: ",str," before newline",NULL);
93 } else if(yytext[0]=='\0') {
94 out=g_strconcat("Error: ", str, " at end of input", NULL);
96 char *tmp = g_strdup(yytext);
97 while((p=strchr(tmp, '\n')))
100 out=g_strconcat("Error: ", str, " before '", tmp, "'", NULL);
104 fprintf(stderr, "%s:%d: %s\n", filename, line_no, out);
113 Type *type = typestack->data;
114 typestack = g_list_remove(typestack,typestack->data);
119 push_variable (char *name, int scope, int line_no, char *postfix)
122 Type *type = pop_type ();
124 type->postfix = postfix;
126 var = node_new (VARIABLE_NODE,
131 "destructor_unref", destructor_unref,
132 "destructor:steal", destructor,
133 "destructor_line", destructor_line,
134 "destructor_simple", destructor_simple,
135 "initializer:steal", initializer,
136 "initializer_line", initializer_line,
138 class_nodes = g_list_append(class_nodes, var);
142 push_function (int scope, int method, char *oid, char *id,
143 GString *cbuf, int line_no, int ccode_line,
144 gboolean vararg, GList *flags)
150 g_assert(scope != CLASS_SCOPE);
152 if(method == INIT_METHOD || method == CLASS_INIT_METHOD) {
153 type = (Type *)node_new (TYPE_NODE,
160 /* a complicated and ugly test to figure out if we have
161 the wrong number of types for a signal */
162 if((method == SIGNAL_FIRST_METHOD ||
163 method == SIGNAL_LAST_METHOD) &&
164 g_list_length(gtktypes) != g_list_length(funcargs) &&
165 !(g_list_length(funcargs) == 1 &&
166 g_list_length(gtktypes) == 2 &&
167 strcmp(gtktypes->next->data, "NONE")==0)) {
168 error_print(GOB_WARN, line_no,
169 _("The number of GTK arguments and "
170 "function arguments for a signal "
171 "don't seem to match"));
173 if(g_list_length(gtktypes) > 2) {
175 for(li = gtktypes->next; li; li = li->next) {
176 if(strcmp(li->data, "NONE")==0) {
177 error_print(GOB_ERROR, line_no,
178 _("NONE can only appear in an "
179 "argument list by itself"));
185 c_cbuf = p = cbuf->str;
186 while(p && *p && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
193 node = node_new (METHOD_NODE,
198 "gtktypes:steal", gtktypes,
199 "flags:steal", flags,
201 "args:steal", funcargs,
202 "onerror:steal", onerror,
203 "defreturn:steal", defreturn,
204 "cbuf:steal", c_cbuf,
206 "ccode_line", ccode_line,
208 "unique_id", method_unique_id++,
211 last_added_method = (Method *)node;
215 /*only free segment if we haven't passed it
224 class_nodes = g_list_append(class_nodes, node);
228 free_all_global_state(void)
238 g_list_foreach(gtktypes, (GFunc)g_free, NULL);
239 g_list_free(gtktypes);
242 node_list_free (funcargs);
247 push_funcarg(char *name, char *postfix)
250 Type *type = pop_type();
252 type->postfix = postfix;
254 node = node_new (FUNCARG_NODE,
257 "checks:steal", checks,
261 funcargs = g_list_append(funcargs, node);
265 push_init_arg(char *name, int is_class)
272 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
274 tn = g_strdup(((Class *)class)->otype);
276 type = node_new (TYPE_NODE,
280 node = node_new (FUNCARG_NODE,
281 "atype:steal", (Type *)type,
284 funcargs = g_list_prepend(funcargs, node);
288 push_self(char *id, gboolean constant)
293 type = node_new (TYPE_NODE,
294 "name", ((Class *)class)->otype,
295 "pointer", constant ? "const *" : "*",
297 ch = g_list_append (ch, node_new (CHECK_NODE,
298 "chtype", NULL_CHECK,
300 ch = g_list_append (ch, node_new (CHECK_NODE,
301 "chtype", TYPE_CHECK,
303 node = node_new (FUNCARG_NODE,
304 "atype:steal", (Type *)type,
308 funcargs = g_list_prepend(funcargs, node);
312 find_var_or_die(const char *id, int line)
316 for(li = class_nodes; li != NULL; li = li->next) {
318 Node *node = li->data;
319 if(node->type != VARIABLE_NODE)
322 if(strcmp(var->id, id)==0)
326 error_printf(GOB_ERROR, line, _("Variable %s not defined here"), id);
328 g_assert_not_reached();
333 set_return_value(char *type, char *val)
335 if(strcmp(type, "onerror")==0) {
341 } else if(strcmp(type, "defreturn")==0) {
352 export_accessors (const char *var_name,
364 the_type = (Type *)node_copy ((Node *)type);
366 the_type = get_tree_type (gtktype, TRUE);
368 if (the_type == NULL) {
369 error_print (GOB_ERROR, line_no,
370 _("Cannot determine type of property or argument"));
375 char *get_id = g_strdup_printf ("get_%s", var_name);
376 GString *get_cbuf = g_string_new (NULL);
377 Node *node1 = node_new (TYPE_NODE,
378 "name", the_type->name,
379 "pointer", the_type->pointer,
380 "postfix", the_type->postfix,
382 Node *node3 = node_new (TYPE_NODE,
383 "name", class->class.otype,
387 g_string_sprintf (get_cbuf,
389 "g_object_get (G_OBJECT (self), \"%s\", "
393 the_type->pointer ? the_type->pointer : "",
396 typestack = g_list_prepend (typestack, node1);
397 typestack = g_list_prepend (typestack, node3);
399 push_funcarg ("self", FALSE);
401 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
402 get_id, get_cbuf, get_lineno,
403 lineno, FALSE, NULL);
407 char *set_id = g_strdup_printf ("set_%s", var_name);
408 GString *set_cbuf = g_string_new (NULL);
409 Node *node1 = node_new (TYPE_NODE,
410 "name", the_type->name,
411 "pointer", the_type->pointer,
412 "postfix", the_type->postfix,
414 Node *node2 = node_new (TYPE_NODE,
417 Node *node3 = node_new (TYPE_NODE,
418 "name", class->class.otype,
422 g_string_sprintf (set_cbuf,
423 "\tg_object_set (G_OBJECT (self), "
424 "\"%s\", val, NULL);\n",
427 typestack = g_list_prepend (typestack, node2);
428 typestack = g_list_prepend (typestack, node1);
429 typestack = g_list_prepend (typestack, node3);
431 push_funcarg ("self", FALSE);
432 push_funcarg ("val", FALSE);
434 typestack = g_list_prepend (typestack, node2);
435 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
436 set_id, set_cbuf, set_lineno,
437 lineno, FALSE, NULL);
440 node_free ((Node *)the_type);
444 get_prop_enum_flag_cast (Property *prop)
447 if (prop->extra_gtktype == NULL ||
448 /* HACK! just in case someone made this
449 * work with 2.0.0 by using the TYPE
451 ((strstr (prop->extra_gtktype, "_TYPE_") != NULL ||
452 strstr (prop->extra_gtktype, "TYPE_") == prop->extra_gtktype) &&
453 strchr (prop->extra_gtktype, ':') == NULL)) {
454 if (prop->ptype != NULL)
455 return get_type (prop->ptype, TRUE);
457 return g_strdup ("");
459 tmp = remove_sep (prop->extra_gtktype);
460 ret = g_strdup_printf ("(%s) ", tmp);
466 property_link_and_export (Node *node)
468 Property *prop = (Property *)node;
472 char *get = NULL, *set = NULL;
475 if (prop->set != NULL ||
477 error_print (GOB_ERROR, prop->line_no,
478 _("Property linking requested, but "
479 "getters and setters exist"));
482 var = find_var_or_die (prop->name, prop->line_no);
483 if(var->scope == PRIVATE_SCOPE) {
484 root = "self->_priv";
485 } else if (var->scope == CLASS_SCOPE) {
486 root = "SELF_GET_CLASS(self)";
488 error_print (GOB_ERROR, prop->line_no,
489 _("Self aliases needed when autolinking to a classwide member"));
494 if (strcmp (prop->gtktype, "STRING") == 0) {
495 set = g_strdup_printf("{ char *old = %s->%s; "
496 "%s->%s = g_value_dup_string (VAL); g_free (old); }",
499 get = g_strdup_printf("g_value_set_string (VAL, %s->%s);",
501 } else if (strcmp (prop->gtktype, "OBJECT") == 0) {
503 if (prop->extra_gtktype != NULL) {
504 cast = remove_sep (prop->extra_gtktype);
506 cast = g_strdup ("void");
508 set = g_strdup_printf("{ GObject *___old = (GObject *)%s->%s; "
509 "%s->%s = (%s *)g_value_dup_object (VAL); "
510 "if (___old != NULL) { "
511 "g_object_unref (G_OBJECT (___old)); "
517 get = g_strdup_printf ("g_value_set_object (VAL, "
518 "(gpointer)%s->%s);",
521 } else if (strcmp (prop->gtktype, "BOXED") == 0) {
522 char *type = make_me_type (prop->extra_gtktype,
524 if (prop->extra_gtktype == NULL) {
525 error_print (GOB_ERROR, prop->line_no,
526 _("Property linking requested for BOXED, but "
527 "boxed_type not set"));
529 set = g_strdup_printf("{ gpointer ___old = (gpointer)%s->%s; "
530 "gpointer ___new = (gpointer)g_value_get_boxed (VAL); "
531 "if (___new != ___old) { "
532 "if (___old != NULL) g_boxed_free (%s, ___old); "
533 "if (___new != NULL) %s->%s = g_boxed_copy (%s, ___new); "
534 "else %s->%s = NULL;"
542 get = g_strdup_printf("g_value_set_boxed (VAL, %s->%s);",
548 const char *getcast = "";
549 const char *setcast = "";
550 char *to_free = NULL;
551 set_func = g_strdup_printf ("g_value_set_%s", prop->gtktype);
552 g_strdown (set_func);
553 get_func = g_strdup_printf ("g_value_get_%s", prop->gtktype);
554 g_strdown (get_func);
557 if (strcmp (prop->gtktype, "FLAGS") == 0) {
558 setcast = "(guint) ";
560 get_prop_enum_flag_cast (prop);
561 } else if (strcmp (prop->gtktype, "ENUM") == 0) {
564 get_prop_enum_flag_cast (prop);
565 } else if (strcmp (prop->gtktype, "POINTER") == 0) {
566 setcast = "(gpointer) ";
567 getcast = g_strdup_printf ("(%s%s) ",
569 prop->ptype->pointer ? prop->ptype->pointer : "");
573 set = g_strdup_printf("%s->%s = %s%s (VAL);",
577 get = g_strdup_printf("%s (VAL, %s%s->%s);",
589 "get_line", prop->line_no,
591 "set_line", prop->line_no,
596 export_accessors (prop->name,
597 prop->get != NULL, prop->get_line,
598 prop->set != NULL, prop->set_line,
609 if (strcmp (s, "BOOL") == 0) {
610 error_print (GOB_WARN, line_no,
611 _("BOOL type is deprecated, please use BOOLEAN"));
613 return g_strdup ("BOOLEAN");
620 ensure_property (void)
622 if (property == NULL)
623 property = (Property *)node_new (PROPERTY_NODE, NULL);
637 %token CONST VOID STRUCT UNION ENUM THREEDOTS
638 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
640 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
641 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
642 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
643 %token <line> VIRTUAL SIGNAL OVERRIDE
644 %token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
645 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
649 prog: ccodes class ccodes { ; }
656 Node *node = node_new (CCODE_NODE,
658 "cbuf:steal", ($<cbuf>1)->str,
659 "line_no", ccode_line,
661 nodes = g_list_append(nodes,node);
662 g_string_free($<cbuf>1,FALSE);
665 Node *node = node_new (CCODE_NODE,
667 "cbuf:steal", ($<cbuf>1)->str,
668 "line_no", ccode_line,
670 nodes = g_list_append(nodes,node);
671 g_string_free($<cbuf>1,FALSE);
674 Node *node = node_new (CCODE_NODE,
676 "cbuf:steal", ($<cbuf>1)->str,
677 "line_no", ccode_line,
679 nodes = g_list_append(nodes,node);
680 g_string_free($<cbuf>1,FALSE);
683 Node *node = node_new (CCODE_NODE,
685 "cbuf:steal", ($<cbuf>1)->str,
686 "line_no", ccode_line,
688 nodes = g_list_append(nodes,node);
689 g_string_free($<cbuf>1,FALSE);
692 Node *node = node_new (CCODE_NODE,
694 "cbuf:steal", ($<cbuf>1)->str,
695 "line_no", ccode_line,
697 nodes = g_list_append(nodes,node);
698 g_string_free($<cbuf>1,FALSE);
701 Node *node = node_new (CCODE_NODE,
703 "cbuf:steal", ($<cbuf>1)->str,
704 "line_no", ccode_line,
706 nodes = g_list_append(nodes,node);
707 g_string_free($<cbuf>1,FALSE);
711 ccodes: ccodes ccode { ; }
712 | ccodes enumcode { ; }
713 | ccodes flagcode { ; }
714 | ccodes errorcode { ; }
721 class: classdec '{' classcode '}' {
722 ((Class *)class)->nodes = class_nodes;
724 nodes = g_list_append(nodes,class);
727 ((Class *)class)->nodes = NULL;
729 nodes = g_list_append(nodes,class);
733 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
734 class = node_new (CLASS_NODE,
735 "otype:steal", $<id>2,
736 "ptype:steal", $<id>4,
737 "bonobo_object_class:steal", bonobo_object_class,
738 "interfaces:steal", interfaces,
739 "chunk_size:steal", chunk_size,
741 bonobo_object_class = NULL;
748 | '(' TOKEN TOKEN ')' classflags {
749 if(strcmp($<id>2,"chunks") == 0) {
751 chunk_size = g_strdup($<id>3);
752 } else if(strcmp($<id>2,"BonoboObject") == 0) {
753 g_free (bonobo_object_class);
754 bonobo_object_class = g_strdup($<id>3);
756 yyerror(_("parse error"));
760 | '(' TOKEN TYPETOKEN ')' classflags {
761 if (strcmp ($<id>2, "interface") == 0) {
762 interfaces = g_list_append (interfaces,
765 yyerror(_("parse error"));
769 | '(' TOKEN NUMBER ')' classflags {
770 if(strcmp($<id>2,"chunks") == 0) {
772 if(atoi($<id>3) != 0)
773 chunk_size = g_strdup($<id>3);
777 yyerror(_("parse error"));
783 classcode: classcode thing { ; }
789 if (strcmp ($<id>1, "BonoboObject") != 0) {
791 yyerror (_("parse error"));
795 last_added_method->bonobo_object_func = TRUE;
797 | TOKEN TYPETOKEN method {
798 if (strcmp ($<id>1, "interface") != 0) {
801 yyerror (_("parse error"));
805 node_set ((Node *)last_added_method,
806 "interface:steal", $<id>2,
815 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
816 | PRIVATE { the_scope = PRIVATE_SCOPE; }
817 | PROTECTED { the_scope = PROTECTED_SCOPE; }
818 | CLASSWIDE { the_scope = CLASS_SCOPE; }
821 destructor: TOKEN TOKEN {
822 if (strcmp ($<id>1, "destroywith") == 0) {
824 destructor_unref = FALSE;
826 destructor_line = line_no;
827 destructor_simple = TRUE;
828 } else if (strcmp ($<id>1, "unrefwith") == 0) {
830 destructor_unref = TRUE;
832 destructor_line = line_no;
833 destructor_simple = TRUE;
837 yyerror (_("parse error"));
842 if (strcmp ($<id>1, "destroy") == 0) {
844 destructor_unref = FALSE;
845 destructor = ($<cbuf>3)->str;
846 g_string_free($<cbuf>3, FALSE);
847 destructor_line = ccode_line;
848 destructor_simple = FALSE;
849 } else if (strcmp ($<id>1, "unref") == 0) {
851 destructor_unref = TRUE;
852 destructor = ($<cbuf>3)->str;
853 g_string_free ($<cbuf>3, FALSE);
854 destructor_line = ccode_line;
855 destructor_simple = FALSE;
858 g_string_free ($<cbuf>3, TRUE);
859 yyerror (_("parse error"));
865 initializer: '=' numtok {
866 initializer = $<id>2;
867 initializer_line = ccode_line;
870 initializer = ($<cbuf>3)->str;
871 initializer_line = ccode_line;
872 g_string_free($<cbuf>3, FALSE);
877 varoptions: destructor initializer { ; }
878 | initializer destructor { ; }
879 | initializer { destructor = NULL; }
880 | destructor { initializer = NULL; }
887 variable: scope type TOKEN varoptions ';' {
888 push_variable($<id>3, the_scope,$<line>1, NULL);
890 | scope type TOKEN ARRAY_DIM varoptions ';' {
891 push_variable($<id>3, the_scope, $<line>1, $<id>4);
895 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
897 if(strcmp($<id>6,"get")==0 &&
898 strcmp($<id>9,"set")==0) {
899 Type *type = pop_type();
902 node = node_new (ARGUMENT_NODE,
903 "gtktype:steal", $<id>3,
905 "flags:steal", $<list>2,
906 "name:steal", $<id>4,
907 "get:steal", ($<cbuf>8)->str,
908 "get_line", $<line>7,
909 "set:steal", ($<cbuf>11)->str,
910 "set_line", $<line>10,
914 class_nodes = g_list_append(class_nodes,node);
916 g_string_free ($<cbuf>8, FALSE);
917 g_string_free ($<cbuf>11, FALSE);
919 } else if(strcmp($<id>6,"set")==0 &&
920 strcmp($<id>9,"get")==0) {
921 Type *type = pop_type();
924 node = node_new (ARGUMENT_NODE,
925 "gtktype:steal", $<id>3,
927 "flags:steal", $<list>2,
928 "name:steal", $<id>4,
929 "get:steal", ($<cbuf>11)->str,
930 "get_line", $<line>10,
931 "set:steal", ($<cbuf>8)->str,
932 "set_line", $<line>7,
935 g_string_free ($<cbuf>11, FALSE);
936 g_string_free ($<cbuf>8, FALSE);
937 class_nodes = g_list_append(class_nodes,node);
943 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
944 g_list_free ($<list>2);
945 g_string_free ($<cbuf>11, TRUE);
946 g_string_free ($<cbuf>8, TRUE);
947 yyerror (_("parse error"));
951 if ($<id>5 != NULL) {
952 Argument *arg = (Argument *)node;
953 export_accessors (arg->name,
954 arg->get != NULL, arg->get_line,
955 arg->set != NULL, arg->set_line,
963 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
965 if(strcmp($<id>6, "get") == 0) {
966 Type *type = pop_type();
968 node = node_new (ARGUMENT_NODE,
969 "gtktype:steal", $<id>3,
971 "flags:steal", $<list>2,
972 "name:steal", $<id>4,
973 "get:steal", ($<cbuf>8)->str,
974 "get_line", $<line>7,
978 g_string_free ($<cbuf>8, FALSE);
979 class_nodes = g_list_append(class_nodes, node);
980 } else if(strcmp($<id>6, "set") == 0) {
981 Type *type = pop_type();
983 node = node_new (ARGUMENT_NODE,
984 "gtktype:steal", $<id>3,
986 "flags:steal", $<list>2,
987 "name:steal", $<id>4,
988 "set:steal", ($<cbuf>8)->str,
989 "set_line", $<line>7,
993 g_string_free ($<cbuf>8, FALSE);
994 class_nodes = g_list_append (class_nodes, node);
999 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
1000 g_list_free ($<list>2);
1001 g_string_free ($<cbuf>8, TRUE);
1002 yyerror(_("parse error"));
1006 if ($<id>5 != NULL) {
1007 Argument *arg = (Argument *)node;
1008 export_accessors (arg->name,
1009 arg->get != NULL, arg->get_line,
1010 arg->set != NULL, arg->set_line,
1017 | ARGUMENT flags argtype TOKEN export TOKEN {
1019 char *get, *set = NULL;
1024 if(strcmp($<id>6, "link")!=0 &&
1025 strcmp($<id>6, "stringlink")!=0 &&
1026 strcmp($<id>6, "objectlink")!=0) {
1030 g_list_foreach($<list>2,(GFunc)g_free,NULL);
1031 g_list_free($<list>2);
1032 yyerror(_("parse error"));
1038 var = find_var_or_die($<id>4, $<line>1);
1039 if(var->scope == PRIVATE_SCOPE) {
1040 root = "self->_priv";
1041 } else if(var->scope == CLASS_SCOPE) {
1042 root = "SELF_GET_CLASS(self)";
1044 error_print(GOB_ERROR, $<line>1,
1045 _("Self aliases needed when autolinking to a classwide member"));
1050 if(strcmp($<id>6, "link")==0) {
1051 set = g_strdup_printf("%s->%s = ARG;",
1053 } else if(strcmp($<id>6, "stringlink")==0) {
1054 set = g_strdup_printf("g_free (%s->%s); "
1055 "%s->%s = g_strdup (ARG);",
1058 } else if(strcmp($<id>6, "objectlink")==0) {
1059 set = g_strdup_printf(
1061 "g_object_ref (G_OBJECT (ARG)); "
1062 "if (%s->%s != NULL) "
1063 "g_object_unref (G_OBJECT (%s->%s)); "
1069 g_assert_not_reached();
1072 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
1077 type = (Type *)node_copy ((Node *)var->vtype);
1079 node = node_new (ARGUMENT_NODE,
1080 "gtktype:steal", $<id>3,
1081 "atype:steal", type,
1082 "flags:steal", $<list>2,
1083 "name:steal", $<id>4,
1085 "get_line", $<line>1,
1087 "set_line", $<line>1,
1088 "line_no", $<line>1,
1091 if ($<id>5 != NULL) {
1092 Argument *arg = (Argument *)node;
1093 export_accessors (arg->name,
1094 arg->get != NULL, arg->get_line,
1095 arg->set != NULL, arg->set_line,
1102 class_nodes = g_list_append (class_nodes, node);
1106 export: '(' TOKEN ')' {
1107 if (strcmp ($<id>2, "export")!=0) {
1109 yyerror (_("parse error"));
1119 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1121 node_set ((Node *)property,
1122 "line_no", $<line>1,
1123 "gtktype:steal", debool ($<id>2),
1124 "name:steal", $<id>3,
1126 if (strcmp ($<id>5, "get") == 0 &&
1127 strcmp ($<id>8, "set") == 0) {
1128 node_set ((Node *)property,
1129 "get:steal", ($<cbuf>7)->str,
1130 "get_line", $<line>6,
1131 "set:steal", ($<cbuf>10)->str,
1132 "set_line", $<line>9,
1134 g_string_free ($<cbuf>7, FALSE);
1135 g_string_free ($<cbuf>10, FALSE);
1138 } else if (strcmp ($<id>5, "set") == 0 &&
1139 strcmp ($<id>8, "get") == 0) {
1140 node_set ((Node *)property,
1141 "get:steal", ($<cbuf>10)->str,
1142 "get_line", $<line>9,
1143 "set:steal", ($<cbuf>7)->str,
1144 "set_line", $<line>6,
1146 g_string_free ($<cbuf>7, FALSE);
1147 g_string_free ($<cbuf>10, FALSE);
1151 g_string_free ($<cbuf>7, TRUE);
1152 g_string_free ($<cbuf>10, TRUE);
1155 node_free ((Node *)property);
1157 yyerror (_("parse error"));
1160 property_link_and_export ((Node *)property);
1161 if (property != NULL) {
1162 class_nodes = g_list_append (class_nodes,
1167 | PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE ';' {
1169 node_set ((Node *)property,
1170 "line_no", $<line>1,
1171 "gtktype:steal", debool ($<id>2),
1172 "name:steal", $<id>3,
1174 if (strcmp ($<id>5, "get") == 0) {
1175 node_set ((Node *)property,
1176 "get:steal", ($<cbuf>7)->str,
1177 "get_line", $<line>6,
1179 g_string_free ($<cbuf>7, FALSE);
1181 } else if (strcmp ($<id>5, "set") == 0) {
1182 node_set ((Node *)property,
1183 "set:steal", ($<cbuf>7)->str,
1184 "set_line", $<line>6,
1186 g_string_free ($<cbuf>7, FALSE);
1189 g_string_free ($<cbuf>7, TRUE);
1191 node_free ((Node *)property);
1193 yyerror (_("parse error"));
1196 property_link_and_export ((Node *)property);
1197 if (property != NULL) {
1198 class_nodes = g_list_append (class_nodes,
1203 | PROPERTY TOKEN TOKEN param_spec ';' {
1205 node_set ((Node *)property,
1206 "line_no", $<line>1,
1207 "gtktype:steal", debool ($<id>2),
1208 "name:steal", $<id>3,
1210 property_link_and_export ((Node *)property);
1211 if (property != NULL) {
1212 class_nodes = g_list_append (class_nodes,
1219 param_spec: '(' param_spec_list ')' { ; }
1223 param_spec_list: param_spec_list ',' param_spec_value { ; }
1224 | param_spec_value { ; }
1227 string: STRING { $<id>$ = $<id>1; }
1228 | TOKEN '(' STRING ')' {
1229 if (strcmp ($<id>1, "_") != 0) {
1231 yyerror(_("parse error"));
1235 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1240 anyval: numtok { $<id>$ = $<id>1; }
1241 | string { $<id>$ = $<id>1; }
1244 param_spec_value: NICK '=' string {
1246 node_set ((Node *)property,
1247 "nick:steal", $<id>3,
1250 | BLURB '=' string {
1252 node_set ((Node *)property,
1253 "blurb:steal", $<id>3,
1256 | MAXIMUM '=' numtok {
1258 node_set ((Node *)property,
1259 "maximum:steal", $<id>3,
1262 | MINIMUM '=' numtok {
1264 node_set ((Node *)property,
1265 "minimum:steal", $<id>3,
1268 | DEFAULT_VALUE '=' anyval {
1270 node_set ((Node *)property,
1271 "default_value:steal", $<id>3,
1274 | FLAGS '=' flaglist {
1276 node_set ((Node *)property,
1277 "flags:steal", $<list>3,
1281 Type *type = pop_type ();
1283 node_set ((Node *)property,
1284 "ptype:steal", type,
1287 | FLAGS_TYPE '=' TYPETOKEN {
1289 node_set ((Node *)property,
1290 "extra_gtktype:steal", $<id>3,
1293 | FLAGS_TYPE '=' TOKEN {
1295 node_set ((Node *)property,
1296 "extra_gtktype:steal", $<id>3,
1299 | ENUM_TYPE '=' TYPETOKEN {
1301 node_set ((Node *)property,
1302 "extra_gtktype:steal", $<id>3,
1305 | ENUM_TYPE '=' TOKEN {
1307 node_set ((Node *)property,
1308 "extra_gtktype:steal", $<id>3,
1311 | PARAM_TYPE '=' TYPETOKEN {
1313 node_set ((Node *)property,
1314 "extra_gtktype:steal", $<id>3,
1317 | PARAM_TYPE '=' TOKEN {
1319 node_set ((Node *)property,
1320 "extra_gtktype:steal", $<id>3,
1323 | BOXED_TYPE '=' TYPETOKEN {
1325 node_set ((Node *)property,
1326 "extra_gtktype:steal", $<id>3,
1329 | BOXED_TYPE '=' TOKEN {
1331 node_set ((Node *)property,
1332 "extra_gtktype:steal", $<id>3,
1335 | OBJECT_TYPE '=' TYPETOKEN {
1337 node_set ((Node *)property,
1338 "extra_gtktype:steal", $<id>3,
1341 | OBJECT_TYPE '=' TOKEN {
1343 node_set ((Node *)property,
1344 "extra_gtktype:steal", $<id>3,
1349 if (strcmp ($<id>1, "override") == 0) {
1351 node_set ((Node *)property,
1354 } else if (strcmp ($<id>1, "link") == 0) {
1356 node_set ((Node *)property,
1359 } else if (strcmp ($<id>1, "export") == 0) {
1361 node_set ((Node *)property,
1366 yyerror(_("parse error"));
1372 argtype: TOKEN '(' TOKEN type ')' {
1373 if(strcmp($<id>3,"type")!=0) {
1376 yyerror(_("parse error"));
1379 $<id>$ = debool ($<id>1);
1382 $<id>$ = debool ($<id>1);
1383 typestack = g_list_prepend(typestack,NULL);
1387 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1388 | { $<list>$ = NULL; }
1391 flaglist: TOKEN '|' flaglist {
1392 $<list>$ = g_list_append($<list>3,$<id>1);
1395 $<list>$ = g_list_append(NULL,$<id>1);
1400 type: specifier_list pointer {
1401 Node *node = node_new (TYPE_NODE,
1402 "name:steal", $<id>1,
1403 "pointer:steal", $<id>2,
1405 typestack = g_list_prepend(typestack,node);
1408 Node *node = node_new (TYPE_NODE,
1409 "name:steal", $<id>1,
1411 typestack = g_list_prepend(typestack,node);
1415 /* The special cases are neccessary to avoid conflicts */
1416 specifier_list: spec_list {
1423 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1427 $<id>$ = g_strconcat($<id>1, " const", NULL);
1430 | strunionenum TOKEN {
1431 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1434 | CONST strunionenum TOKEN {
1435 $<id>$ = g_strconcat("const ", $<id>2, " ",
1439 | strunionenum TOKEN CONST {
1440 $<id>$ = g_strconcat($<id>1, " ",
1441 $<id>2, " const", NULL);
1446 /* The special const cases take care of conflicts ! */
1447 spec_list: specifier spec_list {
1448 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1451 | TYPETOKEN spec_list {
1452 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1457 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1464 $<id>$ = g_strconcat($<id>1, " const", NULL);
1468 $<id>$ = g_strdup($<id>1);
1471 $<id>$ = g_strconcat($<id>1, " const", NULL);
1475 specifier: VOID { $<id>$ = "void"; }
1476 | CHAR { $<id>$ = "char"; }
1477 | SHORT { $<id>$ = "short"; }
1478 | INT { $<id>$ = "int"; }
1479 | LONG { $<id>$ = "long"; }
1480 | FLOAT { $<id>$ = "float"; }
1481 | DOUBLE { $<id>$ = "double"; }
1482 | SIGNED { $<id>$ = "signed"; }
1483 | UNSIGNED { $<id>$ = "unsigned"; }
1486 strunionenum: STRUCT { $<id>$ = "struct"; }
1487 | UNION { $<id>$ = "union"; }
1488 | ENUM { $<id>$ = "enum"; }
1491 pointer: '*' { $<id>$ = g_strdup("*"); }
1492 | '*' CONST { $<id>$ = g_strdup("* const"); }
1494 $<id>$ = g_strconcat("*", $<id>2, NULL);
1497 | '*' CONST pointer {
1498 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1503 /* this never sets the_scope */
1504 simplesigtype: TOKEN sigtype {
1505 if(strcmp($<id>1, "first")==0)
1506 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1507 else if(strcmp($<id>1, "last")==0)
1508 $<sigtype>$ = SIGNAL_LAST_METHOD;
1510 yyerror(_("signal must be 'first' or 'last'"));
1517 $<sigtype>$ = SIGNAL_LAST_METHOD;
1521 /* this always sets the_scope */
1522 fullsigtype: scope TOKEN sigtype {
1523 if(strcmp($<id>2,"first")==0)
1524 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1525 else if(strcmp($<id>2,"last")==0)
1526 $<sigtype>$ = SIGNAL_LAST_METHOD;
1528 yyerror(_("signal must be 'first' or 'last'"));
1534 | TOKEN scope sigtype {
1535 if(strcmp($<id>1,"first")==0)
1536 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1537 else if(strcmp($<id>1,"last")==0)
1538 $<sigtype>$ = SIGNAL_LAST_METHOD;
1540 yyerror(_("signal must be 'first' or 'last'"));
1547 $<sigtype>$ = SIGNAL_LAST_METHOD;
1550 /* the_scope was default thus public */
1551 the_scope = PUBLIC_SCOPE;
1555 sigtype: TOKEN '(' tokenlist ')' {
1556 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1560 tokenlist: tokenlist ',' TOKEN {
1561 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1564 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1568 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1569 | ';' { $<cbuf>$ = NULL; }
1572 /*here CCODE will include the ending '}' */
1573 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1575 yyerror(_("signal without 'self' as "
1576 "first parameter"));
1577 free_all_global_state();
1580 if(the_scope == CLASS_SCOPE) {
1581 yyerror(_("a method cannot be of class scope"));
1582 free_all_global_state();
1585 push_function(the_scope, $<sigtype>3,NULL,
1586 $<id>5, $<cbuf>10,$<line>1,
1587 ccode_line, vararg, $<list>2);
1589 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1591 yyerror(_("signal without 'self' as "
1592 "first parameter"));
1593 free_all_global_state();
1596 if(the_scope == CLASS_SCOPE) {
1597 yyerror(_("a method cannot be of class scope"));
1598 free_all_global_state();
1601 push_function(the_scope, $<sigtype>4, NULL,
1602 $<id>6, $<cbuf>11, $<line>2,
1603 ccode_line, vararg, $<list>3);
1605 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1607 yyerror(_("virtual method without 'self' as "
1608 "first parameter"));
1609 free_all_global_state();
1612 if(the_scope == CLASS_SCOPE) {
1613 yyerror(_("a method cannot be of class scope"));
1614 free_all_global_state();
1617 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1619 ccode_line, vararg, NULL);
1621 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1623 yyerror(_("virtual method without 'self' as "
1624 "first parameter"));
1625 free_all_global_state();
1628 if(the_scope == CLASS_SCOPE) {
1629 yyerror(_("a method cannot be of class scope"));
1630 free_all_global_state();
1633 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1635 ccode_line, vararg, NULL);
1637 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1639 yyerror(_("virtual method without 'self' as "
1640 "first parameter"));
1641 free_all_global_state();
1644 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1645 $<id>3, $<cbuf>8, $<line>1,
1646 ccode_line, vararg, NULL);
1648 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1649 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1651 $<line>1, ccode_line,
1654 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1655 if(the_scope == CLASS_SCOPE) {
1656 yyerror(_("a method cannot be of class scope"));
1657 free_all_global_state();
1660 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1661 $<cbuf>8, $<line>1, ccode_line,
1664 | TOKEN '(' TOKEN ')' codenocode {
1665 if(strcmp($<id>1, "init")==0) {
1666 push_init_arg($<id>3,FALSE);
1667 push_function(NO_SCOPE, INIT_METHOD, NULL,
1668 $<id>1, $<cbuf>5, $<line>2,
1669 ccode_line, FALSE, NULL);
1670 } else if(strcmp($<id>1, "class_init")==0) {
1671 push_init_arg($<id>3,TRUE);
1672 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1673 $<id>1, $<cbuf>5, $<line>2,
1674 ccode_line, FALSE, NULL);
1678 g_string_free($<cbuf>5,TRUE);
1679 yyerror(_("parse error "
1680 "(untyped blocks must be init or "
1687 returnvals: TOKEN retcode {
1688 g_free(onerror); onerror = NULL;
1689 g_free(defreturn); defreturn = NULL;
1690 if(!set_return_value($<id>1, $<id>2)) {
1693 yyerror(_("parse error"));
1698 | TOKEN retcode TOKEN retcode {
1699 g_free(onerror); onerror = NULL;
1700 g_free(defreturn); defreturn = NULL;
1701 if(!set_return_value($<id>1, $<id>2)) {
1702 g_free($<id>1); g_free($<id>2);
1703 g_free($<id>3); g_free($<id>4);
1704 yyerror(_("parse error"));
1707 if(!set_return_value($<id>3, $<id>4)) {
1708 onerror = defreturn = NULL;
1709 g_free($<id>1); g_free($<id>2);
1710 g_free($<id>3); g_free($<id>4);
1711 yyerror(_("parse error"));
1718 g_free(onerror); onerror = NULL;
1719 g_free(defreturn); defreturn = NULL;
1723 retcode: numtok { $<id>$ = $<id>1; }
1725 $<id>$ = ($<cbuf>2)->str;
1726 g_string_free($<cbuf>2, FALSE);
1730 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1734 if(strcmp($<id>1,"self")==0)
1735 push_self($<id>1, FALSE);
1738 yyerror(_("parse error"));
1745 if(strcmp($<id>1,"self")==0)
1746 push_self($<id>1, TRUE);
1749 yyerror(_("parse error"));
1756 if(strcmp($<id>2,"self")==0)
1757 push_self($<id>2, TRUE);
1760 yyerror(_("parse error"));
1764 | TOKEN ',' arglist {
1766 if(strcmp($<id>1,"self")==0)
1767 push_self($<id>1, FALSE);
1770 yyerror(_("parse error"));
1774 | TOKEN CONST ',' arglist {
1776 if(strcmp($<id>1,"self")==0)
1777 push_self($<id>1, TRUE);
1780 yyerror(_("parse error"));
1784 | CONST TOKEN ',' arglist {
1786 if(strcmp($<id>2,"self")==0)
1787 push_self($<id>2, TRUE);
1790 yyerror(_("parse error"));
1794 | arglist { has_self = FALSE; }
1797 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1798 | arglist1 { vararg = FALSE; }
1801 arglist1: arglist1 ',' arg { ; }
1806 push_funcarg($<id>2,NULL);
1808 | type TOKEN ARRAY_DIM {
1809 push_funcarg($<id>2,$<id>3);
1811 | type TOKEN '(' TOKEN checklist ')' {
1812 if(strcmp($<id>4,"check")!=0) {
1813 yyerror(_("parse error"));
1817 push_funcarg($<id>2,NULL);
1819 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1820 if(strcmp($<id>5,"check")!=0) {
1821 yyerror(_("parse error"));
1825 push_funcarg($<id>2,$<id>3);
1829 checklist: checklist check { ; }
1834 if(strcmp($<id>1,"type")==0) {
1835 Node *node = node_new (CHECK_NODE,
1836 "chtype", TYPE_CHECK,
1838 checks = g_list_append(checks,node);
1839 } else if(strcmp($<id>1,"null")==0) {
1840 Node *node = node_new (CHECK_NODE,
1841 "chtype", NULL_CHECK,
1843 checks = g_list_append(checks,node);
1845 yyerror(_("parse error"));
1851 Node *node = node_new (CHECK_NODE,
1853 "number:steal", $<id>2,
1855 checks = g_list_append(checks,node);
1858 Node *node = node_new (CHECK_NODE,
1860 "number:steal", $<id>2,
1862 checks = g_list_append(checks,node);
1865 Node *node = node_new (CHECK_NODE,
1867 "number:steal", $<id>3,
1869 checks = g_list_append(checks,node);
1872 Node *node = node_new (CHECK_NODE,
1874 "number:steal", $<id>3,
1876 checks = g_list_append(checks,node);
1879 Node *node = node_new (CHECK_NODE,
1881 "number:steal", $<id>3,
1883 checks = g_list_append(checks,node);
1886 Node *node = node_new (CHECK_NODE,
1888 "number:steal", $<id>3,
1890 checks = g_list_append(checks,node);
1894 enumcode: ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
1895 Node *node = node_new (ENUMDEF_NODE,
1896 "etype:steal", $<id>6,
1897 "prefix:steal", $<id>2,
1898 "values:steal", enum_vals,
1901 nodes = g_list_append (nodes, node);
1903 | ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
1904 Node *node = node_new (ENUMDEF_NODE,
1905 "etype:steal", $<id>7,
1906 "prefix:steal", $<id>2,
1907 "values:steal", enum_vals,
1910 nodes = g_list_append (nodes, node);
1914 enumvals: enumvals ',' enumval {;}
1918 enumval: TOKEN '=' numtok {
1922 /* A float value, that's a bad enum */
1923 if (num[0] >= '0' &&
1925 strchr (num, '.') != NULL) {
1928 yyerror(_("parse error (enumerator value not integer constant)"));
1932 node = node_new (ENUMVALUE_NODE,
1933 "name:steal", $<id>1,
1936 enum_vals = g_list_append (enum_vals, node);
1941 node = node_new (ENUMVALUE_NODE,
1942 "name:steal", $<id>1,
1944 enum_vals = g_list_append (enum_vals, node);
1948 flagcode: FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
1949 Node *node = node_new (FLAGS_NODE,
1950 "ftype:steal", $<id>6,
1951 "prefix:steal", $<id>2,
1952 "values:steal", flag_vals,
1955 nodes = g_list_append (nodes, node);
1957 | FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
1958 Node *node = node_new (FLAGS_NODE,
1959 "ftype:steal", $<id>7,
1960 "prefix:steal", $<id>2,
1961 "values:steal", flag_vals,
1964 nodes = g_list_append (nodes, node);
1968 flagvals: flagvals ',' TOKEN {
1969 flag_vals = g_list_append (flag_vals, $<id>3);
1972 flag_vals = g_list_append (flag_vals, $<id>1);
1976 errorcode: ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
1977 Node *node = node_new (ERROR_NODE,
1978 "etype:steal", $<id>6,
1979 "prefix:steal", $<id>2,
1980 "values:steal", error_vals,
1983 nodes = g_list_append (nodes, node);
1985 | ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
1986 Node *node = node_new (ERROR_NODE,
1987 "etype:steal", $<id>7,
1988 "prefix:steal", $<id>2,
1989 "values:steal", error_vals,
1992 nodes = g_list_append (nodes, node);
1996 errorvals: errorvals ',' TOKEN {
1997 error_vals = g_list_append (error_vals, $<id>3);
2000 error_vals = g_list_append (error_vals, $<id>1);
2005 numtok: NUMBER { $<id>$ = $<id>1; }
2007 $<id>$ = g_strconcat("-",$<id>2,NULL);
2010 | SINGLE_CHAR { $<id>$ = $<id>1; }
2011 | TOKEN { $<id>$ = $<id>1; }