2 * Copyright (C) 1999-2000 the Free Software Foundation.
3 * Copyright (C) 2000 Eazel, Inc.
4 * Copyright (C) 2001-2009 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 gboolean abstract = FALSE;
48 static gboolean dynamic = FALSE;
49 static char *chunk_size = NULL;
50 static char *bonobo_object_class = NULL;
51 static int glade_xml = FALSE;
52 static GList *interfaces = NULL;
53 static GList *typestack = NULL;
54 static GList *funcargs = NULL;
55 static GList *checks = NULL;
56 static int has_self = FALSE;
57 static int vararg = FALSE;
58 static Method *last_added_method = NULL;
60 /* destructor and initializer for variables */
61 static gboolean destructor_unref = FALSE;
62 static char *destructor = NULL;
63 static int destructor_line = 0;
64 static gboolean destructor_simple = TRUE;
65 static char *initializer = NULL;
66 static int initializer_line = 0;
67 static int glade_widget = FALSE;
69 static char *funcattrs = NULL;
70 static char *onerror = NULL;
71 static char *defreturn = NULL;
73 static GList *gtktypes = NULL;
74 static char *signal_name=NULL;
76 static Property *property = NULL;
78 /* this can be a global as we will only do one function at a time
80 static int the_scope = NO_SCOPE;
85 extern int ccode_line;
87 extern gboolean for_cpp;
97 if (strcmp (yytext, "\n") == 0 ||
98 strcmp (yytext, "\r") == 0) {
99 out = g_strconcat ("Error: ", str, " before end of line", NULL);
100 } else if (yytext[0] == '\0') {
101 out=g_strconcat("Error: ", str, " at end of input", NULL);
103 char *tmp = g_strdup(yytext);
104 while((p=strchr(tmp, '\n')))
107 out=g_strconcat("Error: ", str, " before '", tmp, "'", NULL);
111 fprintf(stderr, "%s:%d: %s\n", filename, line_no, out);
120 Type *type = typestack->data;
121 typestack = g_list_remove(typestack,typestack->data);
126 push_variable (char *name, int scope, int line_no, char *postfix)
129 Type *type = pop_type ();
131 type->postfix = postfix;
133 var = node_new (VARIABLE_NODE,
136 "glade_widget", glade_widget,
139 "destructor_unref", destructor_unref,
140 "destructor:steal", destructor,
141 "destructor_line", destructor_line,
142 "destructor_simple", destructor_simple,
143 "initializer:steal", initializer,
144 "initializer_line", initializer_line,
145 "initializer_simple", TRUE,
147 class_nodes = g_list_append(class_nodes, var);
148 glade_widget = FALSE;
152 push_function (int scope, int method, char *oid, char *id,
153 GString *cbuf, int line_no, int ccode_line,
154 gboolean vararg, GList *flags)
160 g_assert(scope != CLASS_SCOPE);
162 if(method == INIT_METHOD ||
163 method == CLASS_INIT_METHOD ||
164 method == CONSTRUCTOR_METHOD ||
165 method == DISPOSE_METHOD ||
166 method == FINALIZE_METHOD) {
167 type = (Type *)node_new (TYPE_NODE,
174 /* a complicated and ugly test to figure out if we have
175 the wrong number of types for a signal */
176 if((method == SIGNAL_FIRST_METHOD ||
177 method == SIGNAL_LAST_METHOD) &&
178 g_list_length(gtktypes) != g_list_length(funcargs) &&
179 !(g_list_length(funcargs) == 1 &&
180 g_list_length(gtktypes) == 2 &&
181 strcmp(gtktypes->next->data, "NONE")==0)) {
182 error_print(GOB_WARN, line_no,
183 _("The number of GTK arguments and "
184 "function arguments for a signal "
185 "don't seem to match"));
187 if(g_list_length(gtktypes) > 2) {
189 for(li = gtktypes->next; li; li = li->next) {
190 if(strcmp(li->data, "NONE")==0) {
191 error_print(GOB_ERROR, line_no,
192 _("NONE can only appear in an "
193 "argument list by itself"));
199 c_cbuf = p = cbuf->str;
200 while(p && *p && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
207 if (signal_name == NULL )
209 GString * buffer=g_string_new("");
210 g_string_printf(buffer, "\"%s\"", id);
211 signal_name = buffer->str;
212 g_string_free(buffer, FALSE);
214 node = node_new (METHOD_NODE,
219 "gtktypes:steal", gtktypes,
220 "flags:steal", flags,
222 "signal_name:steal", signal_name,
223 "args:steal", funcargs,
224 "funcattrs:steal", funcattrs,
225 "onerror:steal", onerror,
226 "defreturn:steal", defreturn,
227 "cbuf:steal", c_cbuf,
229 "ccode_line", ccode_line,
231 "unique_id", method_unique_id++,
234 last_added_method = (Method *)node;
238 /*only free segment if we haven't passed it
248 class_nodes = g_list_append(class_nodes, node);
252 free_all_global_state(void)
264 g_list_foreach(gtktypes, (GFunc)g_free, NULL);
265 g_list_free(gtktypes);
268 node_list_free (funcargs);
273 push_funcarg(char *name, char *postfix)
276 Type *type = pop_type();
278 type->postfix = postfix;
280 node = node_new (FUNCARG_NODE,
283 "checks:steal", checks,
287 funcargs = g_list_append(funcargs, node);
291 push_init_arg(char *name, int is_class)
298 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
300 tn = g_strdup(((Class *)class)->otype);
302 type = node_new (TYPE_NODE,
306 node = node_new (FUNCARG_NODE,
307 "atype:steal", (Type *)type,
310 funcargs = g_list_prepend(funcargs, node);
314 push_self(char *id, gboolean constant)
319 type = node_new (TYPE_NODE,
320 "name", ((Class *)class)->otype,
321 "pointer", constant ? "const *" : "*",
323 ch = g_list_append (ch, node_new (CHECK_NODE,
324 "chtype", NULL_CHECK,
326 ch = g_list_append (ch, node_new (CHECK_NODE,
327 "chtype", TYPE_CHECK,
329 node = node_new (FUNCARG_NODE,
330 "atype:steal", (Type *)type,
334 funcargs = g_list_prepend(funcargs, node);
338 find_var_or_die(const char *id, int line)
342 for(li = class_nodes; li != NULL; li = li->next) {
344 Node *node = li->data;
345 if(node->type != VARIABLE_NODE)
348 if(strcmp(var->id, id)==0)
352 error_printf(GOB_ERROR, line, _("Variable %s not defined here"), id);
354 g_assert_not_reached();
359 set_attr_value(char *type, char *val)
361 if(strcmp(type, "attr")==0) {
367 } else if(strcmp(type, "onerror")==0) {
373 } else if(strcmp(type, "defreturn")==0) {
384 export_accessors (const char *var_name,
396 the_type = (Type *)node_copy ((Node *)type);
398 the_type = get_tree_type (gtktype, TRUE);
400 if (the_type == NULL) {
401 error_print (GOB_ERROR, line_no,
402 _("Cannot determine type of property or argument"));
407 char *get_id = g_strdup_printf ("get_%s", var_name);
408 GString *get_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 *node3 = node_new (TYPE_NODE,
415 "name", class->class.otype,
419 g_string_printf(get_cbuf,
421 "g_object_get (G_OBJECT (self), \"%s\", "
425 the_type->pointer ? the_type->pointer : "",
428 typestack = g_list_prepend (typestack, node1);
429 typestack = g_list_prepend (typestack, node3);
431 push_funcarg ("self", FALSE);
433 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
434 get_id, get_cbuf, get_lineno,
435 lineno, FALSE, NULL);
439 char *set_id = g_strdup_printf ("set_%s", var_name);
440 GString *set_cbuf = g_string_new (NULL);
441 Node *node1 = node_new (TYPE_NODE,
442 "name", the_type->name,
443 "pointer", the_type->pointer,
444 "postfix", the_type->postfix,
446 Node *node2 = node_new (TYPE_NODE,
449 Node *node3 = node_new (TYPE_NODE,
450 "name", class->class.otype,
454 g_string_printf(set_cbuf,
455 "\tg_object_set (G_OBJECT (self), "
456 "\"%s\", val, NULL);\n",
459 typestack = g_list_prepend (typestack, node2);
460 typestack = g_list_prepend (typestack, node1);
461 typestack = g_list_prepend (typestack, node3);
463 push_funcarg ("self", FALSE);
464 push_funcarg ("val", FALSE);
466 typestack = g_list_prepend (typestack, node2);
467 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
468 set_id, set_cbuf, set_lineno,
469 lineno, FALSE, NULL);
472 node_free ((Node *)the_type);
476 get_prop_enum_flag_cast (Property *prop)
479 if (prop->extra_gtktype == NULL ||
480 /* HACK! just in case someone made this
481 * work with 2.0.0 by using the TYPE
483 ((strstr (prop->extra_gtktype, "_TYPE_") != NULL ||
484 strstr (prop->extra_gtktype, "TYPE_") == prop->extra_gtktype) &&
485 strchr (prop->extra_gtktype, ':') == NULL)) {
486 if (prop->ptype != NULL)
487 return get_type (prop->ptype, TRUE);
489 return g_strdup ("");
491 tmp = remove_sep (prop->extra_gtktype);
492 ret = g_strdup_printf ("(%s) ", tmp);
498 add_construct_glade (char * file, char * root, char * domain)
503 type = (Type *)node_new (TYPE_NODE,
507 initializer = g_strdup_printf("\t{\n"
508 "\tGtkWidget * root;\n"
509 "\t%%1$s->_priv->_glade_xml = glade_xml_new(%s, %s, %s);\n"
510 "\troot = glade_xml_get_widget(%%1$s->_priv->_glade_xml, %s);\n"
511 "\tgtk_widget_show(root);\n"
512 "\tgtk_container_add(GTK_CONTAINER(%%1$s), root);\n"
513 "\tglade_xml_signal_autoconnect_full(%%1$s->_priv->_glade_xml, (GladeXMLConnectFunc)___glade_xml_connect_foreach, (gpointer)%%1$s);\n"
514 "}\n", file, root, domain ? domain : "NULL", root);
516 var = node_new (VARIABLE_NODE,
517 "scope", PRIVATE_SCOPE,
519 "glade_widget", FALSE,
520 "id:steal", "_glade_xml",
521 "destructor_unref", FALSE,
522 "destructor", "g_object_unref",
523 "destructor_simple", TRUE,
524 "initializer", initializer,
525 "initializer_simple", FALSE,
527 class_nodes = g_list_prepend(class_nodes, var);
531 property_link_and_export (Node *node)
533 Property *prop = (Property *)node;
537 char *get = NULL, *set = NULL;
540 if (prop->set != NULL ||
542 error_print (GOB_ERROR, prop->line_no,
543 _("Property linking requested, but "
544 "getters and setters exist"));
547 var = find_var_or_die (prop->name, prop->line_no);
548 if(var->scope == PRIVATE_SCOPE) {
549 root = "self->_priv";
550 } else if (var->scope == CLASS_SCOPE) {
551 root = "SELF_GET_CLASS(self)";
553 error_print (GOB_ERROR, prop->line_no,
554 _("Self aliases needed when autolinking to a classwide member"));
559 if (strcmp (prop->gtktype, "STRING") == 0) {
560 set = g_strdup_printf("{ char *old = %s->%s; "
561 "%s->%s = g_value_dup_string (VAL); g_free (old); }",
564 get = g_strdup_printf("g_value_set_string (VAL, %s->%s);",
566 } else if (strcmp (prop->gtktype, "OBJECT") == 0) {
568 if (prop->extra_gtktype != NULL) {
569 cast = remove_sep (prop->extra_gtktype);
571 cast = g_strdup ("void");
573 set = g_strdup_printf("{ GObject *___old = (GObject *)%s->%s; "
574 "%s->%s = (%s *)g_value_dup_object (VAL); "
575 "if (___old != NULL) { "
576 "g_object_unref (G_OBJECT (___old)); "
582 get = g_strdup_printf ("g_value_set_object (VAL, "
583 "(gpointer)%s->%s);",
586 } else if (strcmp (prop->gtktype, "BOXED") == 0) {
587 char *type = make_me_type (prop->extra_gtktype,
589 if (prop->extra_gtktype == NULL) {
590 error_print (GOB_ERROR, prop->line_no,
591 _("Property linking requested for BOXED, but "
592 "boxed_type not set"));
594 set = g_strdup_printf("{ gpointer ___old = (gpointer)%s->%s; "
595 "gpointer ___new = (gpointer)g_value_get_boxed (VAL); "
596 "if (___new != ___old) { "
597 "if (___old != NULL) g_boxed_free (%s, ___old); "
598 "if (___new != NULL) %s->%s = g_boxed_copy (%s, ___new); "
599 "else %s->%s = NULL;"
607 get = g_strdup_printf("g_value_set_boxed (VAL, %s->%s);",
613 const char *getcast = "";
614 const char *setcast = "";
615 char *to_free = NULL;
616 set_func = g_strdup_printf ("g_value_set_%s", prop->gtktype);
617 gob_strdown (set_func);
618 get_func = g_strdup_printf ("g_value_get_%s", prop->gtktype);
619 gob_strdown (get_func);
622 if (strcmp (prop->gtktype, "FLAGS") == 0) {
623 setcast = "(guint) ";
625 get_prop_enum_flag_cast (prop);
626 } else if (strcmp (prop->gtktype, "ENUM") == 0) {
629 get_prop_enum_flag_cast (prop);
630 } else if (strcmp (prop->gtktype, "POINTER") == 0) {
631 setcast = "(gpointer) ";
632 getcast = g_strdup_printf ("(%s%s) ",
634 prop->ptype->pointer ? prop->ptype->pointer : "");
638 set = g_strdup_printf("%s->%s = %s%s (VAL);",
642 get = g_strdup_printf("%s (VAL, %s%s->%s);",
654 "get_line", prop->line_no,
656 "set_line", prop->line_no,
661 export_accessors (prop->name,
662 prop->get != NULL, prop->get_line,
663 prop->set != NULL, prop->set_line,
674 if (strcmp (s, "BOOL") == 0) {
675 error_print (GOB_WARN, line_no,
676 _("BOOL type is deprecated, please use BOOLEAN"));
678 return g_strdup ("BOOLEAN");
685 ensure_property (void)
687 if (property == NULL)
688 property = (Property *)node_new (PROPERTY_NODE, NULL);
702 %token CONST VOID STRUCT UNION ENUM THREEDOTS
703 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
705 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
706 %token <cbuf> CCODE CTCODE ADCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
707 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
708 %token <line> VIRTUAL SIGNAL OVERRIDE
709 %token <line> NAME NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
710 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
714 prog: ccodes class ccodes { ; }
721 Node *node = node_new (CCODE_NODE,
723 "cbuf:steal", ($<cbuf>1)->str,
724 "line_no", ccode_line,
726 nodes = g_list_append(nodes,node);
727 g_string_free($<cbuf>1,FALSE);
730 Node *node = node_new (CCODE_NODE,
732 "cbuf:steal", ($<cbuf>1)->str,
733 "line_no", ccode_line,
735 nodes = g_list_append(nodes,node);
736 g_string_free($<cbuf>1,FALSE);
739 Node *node = node_new (CCODE_NODE,
741 "cbuf:steal", ($<cbuf>1)->str,
742 "line_no", ccode_line,
744 nodes = g_list_append(nodes,node);
745 g_string_free($<cbuf>1,FALSE);
748 Node *node = node_new (CCODE_NODE,
750 "cbuf:steal", ($<cbuf>1)->str,
751 "line_no", ccode_line,
753 nodes = g_list_append(nodes,node);
754 g_string_free($<cbuf>1,FALSE);
757 Node *node = node_new (CCODE_NODE,
759 "cbuf:steal", ($<cbuf>1)->str,
760 "line_no", ccode_line,
762 nodes = g_list_append(nodes,node);
763 g_string_free($<cbuf>1,FALSE);
766 Node *node = node_new (CCODE_NODE,
768 "cbuf:steal", ($<cbuf>1)->str,
769 "line_no", ccode_line,
771 nodes = g_list_append(nodes,node);
772 g_string_free($<cbuf>1,FALSE);
775 Node *node = node_new (CCODE_NODE,
777 "cbuf:steal", ($<cbuf>1)->str,
778 "line_no", ccode_line,
780 nodes = g_list_append(nodes,node);
781 g_string_free($<cbuf>1,FALSE);
784 Node *node = node_new (CCODE_NODE,
786 "cbuf:steal", ($<cbuf>1)->str,
787 "line_no", ccode_line,
789 nodes = g_list_append(nodes,node);
790 g_string_free($<cbuf>1,FALSE);
794 ccodes: ccodes ccode { ; }
795 | ccodes enumcode { ; }
796 | ccodes flagcode { ; }
797 | ccodes errorcode { ; }
804 class: classdec '{' classcode '}' {
805 ((Class *)class)->nodes = class_nodes;
807 nodes = g_list_append(nodes,class);
810 ((Class *)class)->nodes = NULL;
812 nodes = g_list_append(nodes,class);
816 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
817 class = node_new (CLASS_NODE,
818 "otype:steal", $<id>2,
819 "ptype:steal", $<id>4,
820 "bonobo_object_class:steal", bonobo_object_class,
821 "glade_xml", glade_xml,
822 "interfaces:steal", interfaces,
823 "chunk_size:steal", chunk_size,
824 "abstract", abstract,
827 bonobo_object_class = NULL;
835 | '(' TOKEN ')' classflags {
836 if(strcmp($<id>2,"abstract") == 0) {
838 } else if(strcmp($<id>2,"dynamic") == 0) {
841 yyerror(_("parse error"));
845 | '(' TOKEN TOKEN ')' classflags {
846 if(strcmp($<id>2,"chunks") == 0) {
848 chunk_size = g_strdup($<id>3);
849 } else if(strcmp($<id>2,"BonoboObject") == 0) {
850 g_free (bonobo_object_class);
851 bonobo_object_class = g_strdup($<id>3);
853 yyerror(_("parse error"));
857 | '(' TOKEN TYPETOKEN ')' classflags {
858 if (strcmp ($<id>2, "interface") == 0) {
859 interfaces = g_list_append (interfaces,
862 yyerror(_("parse error"));
866 | '(' TOKEN NUMBER ')' classflags {
867 if(strcmp($<id>2,"chunks") == 0) {
869 if(atoi($<id>3) != 0)
870 chunk_size = g_strdup($<id>3);
874 yyerror(_("parse error"));
878 | '(' TOKEN STRING STRING ')' classflags {
879 if (strcmp ($<id>2, "GladeXML") == 0) {
881 add_construct_glade($<id>3, $<id>4, NULL);
883 yyerror(_("parse error"));
887 | '(' TOKEN STRING STRING STRING ')' classflags {
888 if (strcmp ($<id>2, "GladeXML") == 0) {
890 add_construct_glade($<id>3, $<id>4, $<id>5);
892 yyerror(_("parse error"));
896 | '(' TOKEN TOKEN STRING ')' classflags {
897 if (strcmp ($<id>2, "GladeXML") == 0) {
899 add_construct_glade($<id>3, $<id>4, NULL);
901 yyerror(_("parse error"));
905 | '(' TOKEN TOKEN STRING STRING ')' classflags {
906 if (strcmp ($<id>2, "GladeXML") == 0) {
908 add_construct_glade($<id>3, $<id>4, $<id>5);
910 yyerror(_("parse error"));
916 classcode: classcode thing { ; }
922 if (strcmp ($<id>1, "BonoboObject") != 0) {
924 yyerror (_("parse error"));
928 last_added_method->bonobo_object_func = TRUE;
930 | TOKEN TYPETOKEN method {
931 if (strcmp ($<id>1, "interface") != 0) {
934 yyerror (_("parse error"));
938 node_set ((Node *)last_added_method,
939 "interface:steal", $<id>2,
948 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
949 | PRIVATE { the_scope = PRIVATE_SCOPE; }
950 | PROTECTED { the_scope = PROTECTED_SCOPE; }
951 | CLASSWIDE { the_scope = CLASS_SCOPE; }
954 destructor: TOKEN TOKEN {
955 if (strcmp ($<id>1, "destroywith") == 0) {
957 destructor_unref = FALSE;
959 destructor_line = line_no;
960 destructor_simple = TRUE;
961 } else if (strcmp ($<id>1, "unrefwith") == 0) {
963 destructor_unref = TRUE;
965 destructor_line = line_no;
966 destructor_simple = TRUE;
970 yyerror (_("parse error"));
975 if (strcmp ($<id>1, "destroy") == 0) {
977 destructor_unref = FALSE;
978 destructor = ($<cbuf>3)->str;
979 g_string_free($<cbuf>3, FALSE);
980 destructor_line = ccode_line;
981 destructor_simple = FALSE;
982 } else if (strcmp ($<id>1, "unref") == 0) {
984 destructor_unref = TRUE;
985 destructor = ($<cbuf>3)->str;
986 g_string_free ($<cbuf>3, FALSE);
987 destructor_line = ccode_line;
988 destructor_simple = FALSE;
991 g_string_free ($<cbuf>3, TRUE);
992 yyerror (_("parse error"));
998 initializer: '=' numtok {
999 initializer = $<id>2;
1000 initializer_line = ccode_line;
1003 initializer = ($<cbuf>3)->str;
1004 initializer_line = ccode_line;
1005 g_string_free($<cbuf>3, FALSE);
1010 varoptions: destructor initializer { ; }
1011 | initializer destructor { ; }
1012 | initializer { destructor = NULL; }
1013 | destructor { initializer = NULL; }
1015 if (strcmp ($<id>1, "GladeXML") == 0) {
1016 glade_widget = TRUE;
1018 yyerror(_("parse error"));
1028 variable: scope type TOKEN varoptions ';' {
1029 push_variable($<id>3, the_scope,$<line>1, NULL);
1031 | scope type TOKEN ARRAY_DIM varoptions ';' {
1032 push_variable($<id>3, the_scope, $<line>1, $<id>4);
1036 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1038 if(strcmp($<id>6,"get")==0 &&
1039 strcmp($<id>9,"set")==0) {
1040 Type *type = pop_type();
1043 node = node_new (ARGUMENT_NODE,
1044 "gtktype:steal", $<id>3,
1045 "atype:steal", type,
1046 "flags:steal", $<list>2,
1047 "name:steal", $<id>4,
1048 "get:steal", ($<cbuf>8)->str,
1049 "get_line", $<line>7,
1050 "set:steal", ($<cbuf>11)->str,
1051 "set_line", $<line>10,
1052 "line_no", $<line>1,
1055 class_nodes = g_list_append(class_nodes,node);
1057 g_string_free ($<cbuf>8, FALSE);
1058 g_string_free ($<cbuf>11, FALSE);
1060 } else if(strcmp($<id>6,"set")==0 &&
1061 strcmp($<id>9,"get")==0) {
1062 Type *type = pop_type();
1065 node = node_new (ARGUMENT_NODE,
1066 "gtktype:steal", $<id>3,
1067 "atype:steal", type,
1068 "flags:steal", $<list>2,
1069 "name:steal", $<id>4,
1070 "get:steal", ($<cbuf>11)->str,
1071 "get_line", $<line>10,
1072 "set:steal", ($<cbuf>8)->str,
1073 "set_line", $<line>7,
1074 "line_no", $<line>1,
1076 g_string_free ($<cbuf>11, FALSE);
1077 g_string_free ($<cbuf>8, FALSE);
1078 class_nodes = g_list_append(class_nodes,node);
1084 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
1085 g_list_free ($<list>2);
1086 g_string_free ($<cbuf>11, TRUE);
1087 g_string_free ($<cbuf>8, TRUE);
1088 yyerror (_("parse error"));
1092 if ($<id>5 != NULL) {
1093 Argument *arg = (Argument *)node;
1094 export_accessors (arg->name,
1095 arg->get != NULL, arg->get_line,
1096 arg->set != NULL, arg->set_line,
1104 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
1106 if(strcmp($<id>6, "get") == 0) {
1107 Type *type = pop_type();
1109 node = node_new (ARGUMENT_NODE,
1110 "gtktype:steal", $<id>3,
1111 "atype:steal", type,
1112 "flags:steal", $<list>2,
1113 "name:steal", $<id>4,
1114 "get:steal", ($<cbuf>8)->str,
1115 "get_line", $<line>7,
1116 "line_no", $<line>1,
1119 g_string_free ($<cbuf>8, FALSE);
1120 class_nodes = g_list_append(class_nodes, node);
1121 } else if(strcmp($<id>6, "set") == 0) {
1122 Type *type = pop_type();
1124 node = node_new (ARGUMENT_NODE,
1125 "gtktype:steal", $<id>3,
1126 "atype:steal", type,
1127 "flags:steal", $<list>2,
1128 "name:steal", $<id>4,
1129 "set:steal", ($<cbuf>8)->str,
1130 "set_line", $<line>7,
1131 "line_no", $<line>1,
1134 g_string_free ($<cbuf>8, FALSE);
1135 class_nodes = g_list_append (class_nodes, node);
1140 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
1141 g_list_free ($<list>2);
1142 g_string_free ($<cbuf>8, TRUE);
1143 yyerror(_("parse error"));
1147 if ($<id>5 != NULL) {
1148 Argument *arg = (Argument *)node;
1149 export_accessors (arg->name,
1150 arg->get != NULL, arg->get_line,
1151 arg->set != NULL, arg->set_line,
1158 | ARGUMENT flags argtype TOKEN export TOKEN {
1160 char *get, *set = NULL;
1165 if(strcmp($<id>6, "link")!=0 &&
1166 strcmp($<id>6, "stringlink")!=0 &&
1167 strcmp($<id>6, "objectlink")!=0) {
1171 g_list_foreach($<list>2,(GFunc)g_free,NULL);
1172 g_list_free($<list>2);
1173 yyerror(_("parse error"));
1179 var = find_var_or_die($<id>4, $<line>1);
1180 if(var->scope == PRIVATE_SCOPE) {
1181 root = "self->_priv";
1182 } else if(var->scope == CLASS_SCOPE) {
1183 root = "SELF_GET_CLASS(self)";
1185 error_print(GOB_ERROR, $<line>1,
1186 _("Self aliases needed when autolinking to a classwide member"));
1191 if(strcmp($<id>6, "link")==0) {
1192 set = g_strdup_printf("%s->%s = ARG;",
1194 } else if(strcmp($<id>6, "stringlink")==0) {
1195 set = g_strdup_printf("g_free (%s->%s); "
1196 "%s->%s = g_strdup (ARG);",
1199 } else if(strcmp($<id>6, "objectlink")==0) {
1200 set = g_strdup_printf(
1202 "g_object_ref (G_OBJECT (ARG)); "
1203 "if (%s->%s != NULL) "
1204 "g_object_unref (G_OBJECT (%s->%s)); "
1210 g_assert_not_reached();
1213 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
1218 type = (Type *)node_copy ((Node *)var->vtype);
1220 node = node_new (ARGUMENT_NODE,
1221 "gtktype:steal", $<id>3,
1222 "atype:steal", type,
1223 "flags:steal", $<list>2,
1224 "name:steal", $<id>4,
1226 "get_line", $<line>1,
1228 "set_line", $<line>1,
1229 "line_no", $<line>1,
1232 if ($<id>5 != NULL) {
1233 Argument *arg = (Argument *)node;
1234 export_accessors (arg->name,
1235 arg->get != NULL, arg->get_line,
1236 arg->set != NULL, arg->set_line,
1243 class_nodes = g_list_append (class_nodes, node);
1247 export: '(' TOKEN ')' {
1248 if (strcmp ($<id>2, "export")!=0) {
1250 yyerror (_("parse error"));
1260 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1262 node_set ((Node *)property,
1263 "line_no", $<line>1,
1264 "gtktype:steal", debool ($<id>2),
1265 "name:steal", $<id>3,
1267 if (strcmp ($<id>5, "get") == 0 &&
1268 strcmp ($<id>8, "set") == 0) {
1269 node_set ((Node *)property,
1270 "get:steal", ($<cbuf>7)->str,
1271 "get_line", $<line>6,
1272 "set:steal", ($<cbuf>10)->str,
1273 "set_line", $<line>9,
1275 g_string_free ($<cbuf>7, FALSE);
1276 g_string_free ($<cbuf>10, FALSE);
1279 } else if (strcmp ($<id>5, "set") == 0 &&
1280 strcmp ($<id>8, "get") == 0) {
1281 node_set ((Node *)property,
1282 "get:steal", ($<cbuf>10)->str,
1283 "get_line", $<line>9,
1284 "set:steal", ($<cbuf>7)->str,
1285 "set_line", $<line>6,
1287 g_string_free ($<cbuf>7, FALSE);
1288 g_string_free ($<cbuf>10, FALSE);
1292 g_string_free ($<cbuf>7, TRUE);
1293 g_string_free ($<cbuf>10, TRUE);
1296 node_free ((Node *)property);
1298 yyerror (_("parse error"));
1301 property_link_and_export ((Node *)property);
1302 if (property != NULL) {
1303 class_nodes = g_list_append (class_nodes,
1308 | PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE ';' {
1310 node_set ((Node *)property,
1311 "line_no", $<line>1,
1312 "gtktype:steal", debool ($<id>2),
1313 "name:steal", $<id>3,
1315 if (strcmp ($<id>5, "get") == 0) {
1316 node_set ((Node *)property,
1317 "get:steal", ($<cbuf>7)->str,
1318 "get_line", $<line>6,
1320 g_string_free ($<cbuf>7, FALSE);
1322 } else if (strcmp ($<id>5, "set") == 0) {
1323 node_set ((Node *)property,
1324 "set:steal", ($<cbuf>7)->str,
1325 "set_line", $<line>6,
1327 g_string_free ($<cbuf>7, FALSE);
1330 g_string_free ($<cbuf>7, TRUE);
1332 node_free ((Node *)property);
1334 yyerror (_("parse error"));
1337 property_link_and_export ((Node *)property);
1338 if (property != NULL) {
1339 class_nodes = g_list_append (class_nodes,
1344 | PROPERTY TOKEN TOKEN param_spec ';' {
1346 node_set ((Node *)property,
1347 "line_no", $<line>1,
1348 "gtktype:steal", debool ($<id>2),
1349 "name:steal", $<id>3,
1351 property_link_and_export ((Node *)property);
1352 if (property != NULL) {
1353 class_nodes = g_list_append (class_nodes,
1360 param_spec: '(' param_spec_list ')' { ; }
1364 param_spec_list: param_spec_list ',' param_spec_value { ; }
1365 | param_spec_value { ; }
1368 string: STRING { $<id>$ = $<id>1; }
1369 | TOKEN '(' STRING ')' {
1370 if (strcmp ($<id>1, "_") != 0) {
1372 yyerror(_("parse error"));
1376 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1381 anyval: numtok { $<id>$ = $<id>1; }
1382 | string { $<id>$ = $<id>1; }
1385 param_spec_value: NAME '=' string {
1387 node_set ((Node *)property,
1388 "canonical_name:steal", gob_str_delete_quotes($<id>3),
1393 node_set ((Node *)property,
1394 "nick:steal", $<id>3,
1397 | BLURB '=' string {
1399 node_set ((Node *)property,
1400 "blurb:steal", $<id>3,
1403 | MAXIMUM '=' numtok {
1405 node_set ((Node *)property,
1406 "maximum:steal", $<id>3,
1409 | MINIMUM '=' numtok {
1411 node_set ((Node *)property,
1412 "minimum:steal", $<id>3,
1415 | DEFAULT_VALUE '=' anyval {
1417 node_set ((Node *)property,
1418 "default_value:steal", $<id>3,
1421 | FLAGS '=' flaglist {
1423 node_set ((Node *)property,
1424 "flags:steal", $<list>3,
1428 Type *type = pop_type ();
1430 node_set ((Node *)property,
1431 "ptype:steal", type,
1434 | FLAGS_TYPE '=' TYPETOKEN {
1436 node_set ((Node *)property,
1437 "extra_gtktype:steal", $<id>3,
1440 | FLAGS_TYPE '=' TOKEN {
1442 node_set ((Node *)property,
1443 "extra_gtktype:steal", $<id>3,
1446 | ENUM_TYPE '=' TYPETOKEN {
1448 node_set ((Node *)property,
1449 "extra_gtktype:steal", $<id>3,
1452 | ENUM_TYPE '=' TOKEN {
1454 node_set ((Node *)property,
1455 "extra_gtktype:steal", $<id>3,
1458 | PARAM_TYPE '=' TYPETOKEN {
1460 node_set ((Node *)property,
1461 "extra_gtktype:steal", $<id>3,
1464 | PARAM_TYPE '=' TOKEN {
1466 node_set ((Node *)property,
1467 "extra_gtktype:steal", $<id>3,
1470 | BOXED_TYPE '=' TYPETOKEN {
1472 node_set ((Node *)property,
1473 "extra_gtktype:steal", $<id>3,
1476 | BOXED_TYPE '=' TOKEN {
1478 node_set ((Node *)property,
1479 "extra_gtktype:steal", $<id>3,
1482 | OBJECT_TYPE '=' TYPETOKEN {
1484 node_set ((Node *)property,
1485 "extra_gtktype:steal", $<id>3,
1488 | OBJECT_TYPE '=' TOKEN {
1490 node_set ((Node *)property,
1491 "extra_gtktype:steal", $<id>3,
1496 if (strcmp ($<id>1, "override") == 0) {
1498 node_set ((Node *)property,
1501 } else if (strcmp ($<id>1, "link") == 0) {
1503 node_set ((Node *)property,
1506 } else if (strcmp ($<id>1, "export") == 0) {
1508 node_set ((Node *)property,
1513 yyerror(_("parse error"));
1519 argtype: TOKEN '(' TOKEN type ')' {
1520 if(strcmp($<id>3,"type")!=0) {
1523 yyerror(_("parse error"));
1526 $<id>$ = debool ($<id>1);
1529 $<id>$ = debool ($<id>1);
1530 typestack = g_list_prepend(typestack,NULL);
1534 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1535 | { $<list>$ = NULL; }
1538 flaglist: TOKEN '|' flaglist {
1539 $<list>$ = g_list_append($<list>3,$<id>1);
1542 $<list>$ = g_list_append(NULL,$<id>1);
1547 type: specifier_list pointer {
1548 Node *node = node_new (TYPE_NODE,
1549 "name:steal", $<id>1,
1550 "pointer:steal", $<id>2,
1552 typestack = g_list_prepend(typestack,node);
1555 Node *node = node_new (TYPE_NODE,
1556 "name:steal", $<id>1,
1558 typestack = g_list_prepend(typestack,node);
1562 /* The special cases are neccessary to avoid conflicts */
1563 specifier_list: spec_list {
1570 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1574 $<id>$ = g_strconcat($<id>1, " const", NULL);
1577 | strunionenum TOKEN {
1578 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1581 | CONST strunionenum TOKEN {
1582 $<id>$ = g_strconcat("const ", $<id>2, " ",
1586 | strunionenum TOKEN CONST {
1587 $<id>$ = g_strconcat($<id>1, " ",
1588 $<id>2, " const", NULL);
1593 /* The special const cases take care of conflicts ! */
1594 spec_list: specifier spec_list {
1595 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1598 | TYPETOKEN spec_list {
1599 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1604 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1611 $<id>$ = g_strconcat($<id>1, " const", NULL);
1615 $<id>$ = g_strdup($<id>1);
1618 $<id>$ = g_strconcat($<id>1, " const", NULL);
1622 specifier: VOID { $<id>$ = "void"; }
1623 | CHAR { $<id>$ = "char"; }
1624 | SHORT { $<id>$ = "short"; }
1625 | INT { $<id>$ = "int"; }
1626 | LONG { $<id>$ = "long"; }
1627 | FLOAT { $<id>$ = "float"; }
1628 | DOUBLE { $<id>$ = "double"; }
1629 | SIGNED { $<id>$ = "signed"; }
1630 | UNSIGNED { $<id>$ = "unsigned"; }
1633 strunionenum: STRUCT { $<id>$ = "struct"; }
1634 | UNION { $<id>$ = "union"; }
1635 | ENUM { $<id>$ = "enum"; }
1638 pointer: '*' { $<id>$ = g_strdup("*"); }
1639 | '*' CONST { $<id>$ = g_strdup("* const"); }
1641 $<id>$ = g_strconcat("*", $<id>2, NULL);
1644 | '*' CONST pointer {
1645 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1650 /* this never sets the_scope */
1651 simplesigtype: TOKEN sigtype {
1652 if(strcmp($<id>1, "first")==0)
1653 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1654 else if(strcmp($<id>1, "last")==0)
1655 $<sigtype>$ = SIGNAL_LAST_METHOD;
1657 yyerror(_("signal must be 'first' or 'last'"));
1664 $<sigtype>$ = SIGNAL_LAST_METHOD;
1668 /* this always sets the_scope */
1669 fullsigtype: scope TOKEN sigtype {
1670 if(strcmp($<id>2,"first")==0)
1671 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1672 else if(strcmp($<id>2,"last")==0)
1673 $<sigtype>$ = SIGNAL_LAST_METHOD;
1675 yyerror(_("signal must be 'first' or 'last'"));
1681 | TOKEN scope sigtype {
1682 if(strcmp($<id>1,"first")==0)
1683 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1684 else if(strcmp($<id>1,"last")==0)
1685 $<sigtype>$ = SIGNAL_LAST_METHOD;
1687 yyerror(_("signal must be 'first' or 'last'"));
1694 $<sigtype>$ = SIGNAL_LAST_METHOD;
1697 /* the_scope was default thus public */
1698 the_scope = PUBLIC_SCOPE;
1702 sigtype: TOKEN '(' tokenlist ')' {
1703 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1705 | TOKEN STRING '(' tokenlist ')' {
1706 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1711 tokenlist: tokenlist ',' TOKEN {
1712 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1715 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1719 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1720 | ';' { $<cbuf>$ = NULL; }
1723 /*here CCODE will include the ending '}' */
1724 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' methodmods codenocode {
1726 yyerror(_("signal without 'self' as "
1727 "first parameter"));
1728 free_all_global_state();
1731 if(the_scope == CLASS_SCOPE) {
1732 yyerror(_("a method cannot be of class scope"));
1733 free_all_global_state();
1736 if (funcattrs != NULL) {
1737 char *error = g_strdup_printf
1738 (_("function attribute macros ('%s' in this case) may not be used with signal methods"),
1743 push_function(the_scope, $<sigtype>3,NULL,
1744 $<id>5, $<cbuf>10,$<line>1,
1745 ccode_line, vararg, $<list>2);
1747 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' methodmods codenocode {
1749 yyerror(_("signal without 'self' as "
1750 "first parameter"));
1751 free_all_global_state();
1754 if(the_scope == CLASS_SCOPE) {
1755 yyerror(_("a method cannot be of class scope"));
1756 free_all_global_state();
1759 if (funcattrs != NULL) {
1760 char *error = g_strdup_printf
1761 (_("function attribute macros ('%s' in this case) may not be used with signal methods"),
1766 push_function(the_scope, $<sigtype>4, NULL,
1767 $<id>6, $<cbuf>11, $<line>2,
1768 ccode_line, vararg, $<list>3);
1770 | VIRTUAL scope type TOKEN '(' funcargs ')' methodmods codenocode {
1772 yyerror(_("virtual method without 'self' as "
1773 "first parameter"));
1774 free_all_global_state();
1777 if(the_scope == CLASS_SCOPE) {
1778 yyerror(_("a method cannot be of class scope"));
1779 free_all_global_state();
1782 if (funcattrs != NULL) {
1783 char *error = g_strdup_printf
1784 (_("function attribute macros ('%s' in this case) may not be used with virtual methods"),
1789 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1791 ccode_line, vararg, NULL);
1793 | scope VIRTUAL type TOKEN '(' funcargs ')' methodmods codenocode {
1795 yyerror(_("virtual method without 'self' as "
1796 "first parameter"));
1797 free_all_global_state();
1800 if(the_scope == CLASS_SCOPE) {
1801 yyerror(_("a method cannot be of class scope"));
1802 free_all_global_state();
1805 if (funcattrs != NULL) {
1806 char *error = g_strdup_printf
1807 (_("function attribute macros ('%s' in this case) may not be used with virtual methods"),
1812 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1814 ccode_line, vararg, NULL);
1816 | VIRTUAL type TOKEN '(' funcargs ')' methodmods codenocode {
1818 yyerror(_("virtual method without 'szelf' as "
1819 "first parameter"));
1820 free_all_global_state();
1823 if (funcattrs != NULL) {
1824 char *error = g_strdup_printf
1825 (_("function attribute macros ('%s' in this case) may not be used with virtual methods"),
1830 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1831 $<id>3, $<cbuf>8, $<line>1,
1832 ccode_line, vararg, NULL);
1834 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' methodmods codenocode {
1835 if (funcattrs != NULL) {
1836 char *error = g_strdup_printf
1837 (_("function attribute macros ('%s' in this case) may not be used with override methods"),
1842 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1844 $<line>1, ccode_line,
1847 | scope type TOKEN '(' funcargs ')' methodmods codenocode {
1848 if(the_scope == CLASS_SCOPE) {
1849 yyerror(_("a method cannot be of class scope"));
1850 free_all_global_state();
1853 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1854 $<cbuf>8, $<line>1, ccode_line,
1857 | TOKEN '(' TOKEN ')' codenocode {
1858 if(strcmp($<id>1, "init")==0) {
1859 push_init_arg($<id>3,FALSE);
1860 push_function(NO_SCOPE, INIT_METHOD, NULL,
1861 $<id>1, $<cbuf>5, $<line>2,
1862 ccode_line, FALSE, NULL);
1863 } else if(strcmp($<id>1, "class_init")==0) {
1864 push_init_arg($<id>3,TRUE);
1865 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1866 $<id>1, $<cbuf>5, $<line>2,
1867 ccode_line, FALSE, NULL);
1868 } else if(strcmp($<id>1, "constructor")==0) {
1869 push_init_arg($<id>3, FALSE);
1870 push_function(NO_SCOPE, CONSTRUCTOR_METHOD, NULL,
1871 $<id>1, $<cbuf>5, $<line>2,
1872 ccode_line, FALSE, NULL);
1873 } else if(strcmp($<id>1, "dispose")==0) {
1874 push_init_arg($<id>3, FALSE);
1875 push_function(NO_SCOPE, DISPOSE_METHOD, NULL,
1876 $<id>1, $<cbuf>5, $<line>2,
1877 ccode_line, FALSE, NULL);
1878 } else if(strcmp($<id>1, "finalize")==0) {
1879 push_init_arg($<id>3, FALSE);
1880 push_function(NO_SCOPE, FINALIZE_METHOD, NULL,
1881 $<id>1, $<cbuf>5, $<line>2,
1882 ccode_line, FALSE, NULL);
1887 g_string_free($<cbuf>5,TRUE);
1888 yyerror(_("parse error "
1889 "(untyped blocks must be init, "
1890 "class_init, constructor, dispose "
1897 methodmods: TOKEN retcode {
1898 g_free(funcattrs); funcattrs = NULL;
1899 g_free(onerror); onerror = NULL;
1900 g_free(defreturn); defreturn = NULL;
1901 if(!set_attr_value($<id>1, $<id>2)) {
1904 yyerror(_("parse error"));
1909 | TOKEN retcode TOKEN retcode {
1910 g_free(funcattrs); funcattrs = NULL;
1911 g_free(onerror); onerror = NULL;
1912 g_free(defreturn); defreturn = NULL;
1913 if(!set_attr_value($<id>1, $<id>2)) {
1914 g_free($<id>1); g_free($<id>2);
1915 g_free($<id>3); g_free($<id>4);
1916 yyerror(_("parse error"));
1919 if(!set_attr_value($<id>3, $<id>4)) {
1920 funcattrs = onerror = defreturn = NULL;
1921 g_free($<id>1); g_free($<id>2);
1922 g_free($<id>3); g_free($<id>4);
1923 yyerror(_("parse error"));
1929 | TOKEN retcode TOKEN retcode TOKEN retcode {
1930 g_free(funcattrs); funcattrs = NULL;
1931 g_free(onerror); onerror = NULL;
1932 g_free(defreturn); defreturn = NULL;
1933 if(!set_attr_value($<id>1, $<id>2)) {
1934 g_free($<id>1); g_free($<id>2);
1935 g_free($<id>3); g_free($<id>4);
1936 g_free($<id>5); g_free($<id>6);
1937 yyerror(_("parse error"));
1940 if(!set_attr_value($<id>3, $<id>4)) {
1941 funcattrs = onerror = defreturn = NULL;
1942 g_free($<id>1); g_free($<id>2);
1943 g_free($<id>3); g_free($<id>4);
1944 g_free($<id>5); g_free($<id>6);
1945 yyerror(_("parse error"));
1948 if(!set_attr_value($<id>5, $<id>6)) {
1949 funcattrs = onerror = defreturn = NULL;
1950 g_free($<id>1); g_free($<id>2);
1951 g_free($<id>3); g_free($<id>4);
1952 g_free($<id>5); g_free($<id>6);
1953 yyerror(_("parse error"));
1961 g_free(funcattrs); funcattrs = NULL;
1962 g_free(onerror); onerror = NULL;
1963 g_free(defreturn); defreturn = NULL;
1967 retcode: numtok { $<id>$ = $<id>1; }
1969 $<id>$ = ($<cbuf>2)->str;
1970 g_string_free($<cbuf>2, FALSE);
1974 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1978 if(strcmp($<id>1,"self")==0)
1979 push_self($<id>1, FALSE);
1982 yyerror(_("parse error"));
1989 if(strcmp($<id>1,"self")==0)
1990 push_self($<id>1, TRUE);
1993 yyerror(_("parse error"));
2000 if(strcmp($<id>2,"self")==0)
2001 push_self($<id>2, TRUE);
2004 yyerror(_("parse error"));
2008 | TOKEN ',' arglist {
2010 if(strcmp($<id>1,"self")==0)
2011 push_self($<id>1, FALSE);
2014 yyerror(_("parse error"));
2018 | TOKEN CONST ',' arglist {
2020 if(strcmp($<id>1,"self")==0)
2021 push_self($<id>1, TRUE);
2024 yyerror(_("parse error"));
2028 | CONST TOKEN ',' arglist {
2030 if(strcmp($<id>2,"self")==0)
2031 push_self($<id>2, TRUE);
2034 yyerror(_("parse error"));
2038 | arglist { has_self = FALSE; }
2041 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
2042 | arglist1 { vararg = FALSE; }
2045 arglist1: arglist1 ',' arg { ; }
2050 push_funcarg($<id>2,NULL);
2052 | type TOKEN ARRAY_DIM {
2053 push_funcarg($<id>2,$<id>3);
2055 | type TOKEN '(' TOKEN checklist ')' {
2056 if(strcmp($<id>4,"check")!=0) {
2057 yyerror(_("parse error"));
2061 push_funcarg($<id>2,NULL);
2063 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
2064 if(strcmp($<id>5,"check")!=0) {
2065 yyerror(_("parse error"));
2069 push_funcarg($<id>2,$<id>3);
2073 checklist: checklist check { ; }
2078 if(strcmp($<id>1,"type")==0) {
2079 Node *node = node_new (CHECK_NODE,
2080 "chtype", TYPE_CHECK,
2082 checks = g_list_append(checks,node);
2083 } else if(strcmp($<id>1,"null")==0) {
2084 Node *node = node_new (CHECK_NODE,
2085 "chtype", NULL_CHECK,
2087 checks = g_list_append(checks,node);
2089 yyerror(_("parse error"));
2095 Node *node = node_new (CHECK_NODE,
2097 "number:steal", $<id>2,
2099 checks = g_list_append(checks,node);
2102 Node *node = node_new (CHECK_NODE,
2104 "number:steal", $<id>2,
2106 checks = g_list_append(checks,node);
2109 Node *node = node_new (CHECK_NODE,
2111 "number:steal", $<id>3,
2113 checks = g_list_append(checks,node);
2116 Node *node = node_new (CHECK_NODE,
2118 "number:steal", $<id>3,
2120 checks = g_list_append(checks,node);
2123 Node *node = node_new (CHECK_NODE,
2125 "number:steal", $<id>3,
2127 checks = g_list_append(checks,node);
2130 Node *node = node_new (CHECK_NODE,
2132 "number:steal", $<id>3,
2134 checks = g_list_append(checks,node);
2138 enumcode: ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
2139 Node *node = node_new (ENUMDEF_NODE,
2140 "etype:steal", $<id>6,
2141 "prefix:steal", $<id>2,
2142 "values:steal", enum_vals,
2145 nodes = g_list_append (nodes, node);
2147 | ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
2148 Node *node = node_new (ENUMDEF_NODE,
2149 "etype:steal", $<id>7,
2150 "prefix:steal", $<id>2,
2151 "values:steal", enum_vals,
2154 nodes = g_list_append (nodes, node);
2158 enumvals: enumvals ',' enumval {;}
2162 enumval: TOKEN '=' numtok {
2166 /* A float value, that's a bad enum */
2167 if (num[0] >= '0' &&
2169 strchr (num, '.') != NULL) {
2172 yyerror(_("parse error (enumerator value not integer constant)"));
2176 node = node_new (ENUMVALUE_NODE,
2177 "name:steal", $<id>1,
2180 enum_vals = g_list_append (enum_vals, node);
2185 node = node_new (ENUMVALUE_NODE,
2186 "name:steal", $<id>1,
2188 enum_vals = g_list_append (enum_vals, node);
2192 flagcode: FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
2193 Node *node = node_new (FLAGS_NODE,
2194 "ftype:steal", $<id>6,
2195 "prefix:steal", $<id>2,
2196 "values:steal", flag_vals,
2199 nodes = g_list_append (nodes, node);
2201 | FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
2202 Node *node = node_new (FLAGS_NODE,
2203 "ftype:steal", $<id>7,
2204 "prefix:steal", $<id>2,
2205 "values:steal", flag_vals,
2208 nodes = g_list_append (nodes, node);
2212 flagvals: flagvals ',' TOKEN {
2213 flag_vals = g_list_append (flag_vals, $<id>3);
2216 flag_vals = g_list_append (flag_vals, $<id>1);
2220 errorcode: ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
2221 Node *node = node_new (ERROR_NODE,
2222 "etype:steal", $<id>6,
2223 "prefix:steal", $<id>2,
2224 "values:steal", error_vals,
2227 nodes = g_list_append (nodes, node);
2229 | ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
2230 Node *node = node_new (ERROR_NODE,
2231 "etype:steal", $<id>7,
2232 "prefix:steal", $<id>2,
2233 "values:steal", error_vals,
2236 nodes = g_list_append (nodes, node);
2240 errorvals: errorvals ',' TOKEN {
2241 error_vals = g_list_append (error_vals, $<id>3);
2244 error_vals = g_list_append (error_vals, $<id>1);
2249 numtok: NUMBER { $<id>$ = $<id>1; }
2251 $<id>$ = g_strconcat("-",$<id>2,NULL);
2254 | SINGLE_CHAR { $<id>$ = $<id>1; }
2255 | TOKEN { $<id>$ = $<id>1; }