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);
568 set = g_strdup_printf("%s->%s = %s%s (VAL);",
572 get = g_strdup_printf("%s (VAL, %s%s->%s);",
584 "get_line", prop->line_no,
586 "set_line", prop->line_no,
591 export_accessors (prop->name,
592 prop->get != NULL, prop->get_line,
593 prop->set != NULL, prop->set_line,
604 if (strcmp (s, "BOOL") == 0) {
605 error_print (GOB_WARN, line_no,
606 _("BOOL type is deprecated, please use BOOLEAN"));
608 return g_strdup ("BOOLEAN");
615 ensure_property (void)
617 if (property == NULL)
618 property = (Property *)node_new (PROPERTY_NODE, NULL);
632 %token CONST VOID STRUCT UNION ENUM THREEDOTS
633 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
635 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
636 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
637 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
638 %token <line> VIRTUAL SIGNAL OVERRIDE
639 %token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
640 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
644 prog: ccodes class ccodes { ; }
651 Node *node = node_new (CCODE_NODE,
653 "cbuf:steal", ($<cbuf>1)->str,
654 "line_no", ccode_line,
656 nodes = g_list_append(nodes,node);
657 g_string_free($<cbuf>1,FALSE);
660 Node *node = node_new (CCODE_NODE,
662 "cbuf:steal", ($<cbuf>1)->str,
663 "line_no", ccode_line,
665 nodes = g_list_append(nodes,node);
666 g_string_free($<cbuf>1,FALSE);
669 Node *node = node_new (CCODE_NODE,
671 "cbuf:steal", ($<cbuf>1)->str,
672 "line_no", ccode_line,
674 nodes = g_list_append(nodes,node);
675 g_string_free($<cbuf>1,FALSE);
678 Node *node = node_new (CCODE_NODE,
680 "cbuf:steal", ($<cbuf>1)->str,
681 "line_no", ccode_line,
683 nodes = g_list_append(nodes,node);
684 g_string_free($<cbuf>1,FALSE);
687 Node *node = node_new (CCODE_NODE,
689 "cbuf:steal", ($<cbuf>1)->str,
690 "line_no", ccode_line,
692 nodes = g_list_append(nodes,node);
693 g_string_free($<cbuf>1,FALSE);
696 Node *node = node_new (CCODE_NODE,
698 "cbuf:steal", ($<cbuf>1)->str,
699 "line_no", ccode_line,
701 nodes = g_list_append(nodes,node);
702 g_string_free($<cbuf>1,FALSE);
706 ccodes: ccodes ccode { ; }
707 | ccodes enumcode { ; }
708 | ccodes flagcode { ; }
709 | ccodes errorcode { ; }
716 class: classdec '{' classcode '}' {
717 ((Class *)class)->nodes = class_nodes;
719 nodes = g_list_append(nodes,class);
722 ((Class *)class)->nodes = NULL;
724 nodes = g_list_append(nodes,class);
728 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
729 class = node_new (CLASS_NODE,
730 "otype:steal", $<id>2,
731 "ptype:steal", $<id>4,
732 "bonobo_object_class:steal", bonobo_object_class,
733 "interfaces:steal", interfaces,
734 "chunk_size:steal", chunk_size,
736 bonobo_object_class = NULL;
743 | '(' TOKEN TOKEN ')' classflags {
744 if(strcmp($<id>2,"chunks") == 0) {
746 chunk_size = g_strdup($<id>3);
747 } else if(strcmp($<id>2,"BonoboObject") == 0) {
748 g_free (bonobo_object_class);
749 bonobo_object_class = g_strdup($<id>3);
751 yyerror(_("parse error"));
755 | '(' TOKEN TYPETOKEN ')' classflags {
756 if (strcmp ($<id>2, "interface") == 0) {
757 interfaces = g_list_append (interfaces,
760 yyerror(_("parse error"));
764 | '(' TOKEN NUMBER ')' classflags {
765 if(strcmp($<id>2,"chunks") == 0) {
767 if(atoi($<id>3) != 0)
768 chunk_size = g_strdup($<id>3);
772 yyerror(_("parse error"));
778 classcode: classcode thing { ; }
784 if (strcmp ($<id>1, "BonoboObject") != 0) {
786 yyerror (_("parse error"));
790 last_added_method->bonobo_object_func = TRUE;
792 | TOKEN TYPETOKEN method {
793 if (strcmp ($<id>1, "interface") != 0) {
796 yyerror (_("parse error"));
800 node_set ((Node *)last_added_method,
801 "interface:steal", $<id>2,
810 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
811 | PRIVATE { the_scope = PRIVATE_SCOPE; }
812 | PROTECTED { the_scope = PROTECTED_SCOPE; }
813 | CLASSWIDE { the_scope = CLASS_SCOPE; }
816 destructor: TOKEN TOKEN {
817 if (strcmp ($<id>1, "destroywith") == 0) {
819 destructor_unref = FALSE;
821 destructor_line = line_no;
822 destructor_simple = TRUE;
823 } else if (strcmp ($<id>1, "unrefwith") == 0) {
825 destructor_unref = TRUE;
827 destructor_line = line_no;
828 destructor_simple = TRUE;
832 yyerror (_("parse error"));
837 if (strcmp ($<id>1, "destroy") == 0) {
839 destructor_unref = FALSE;
840 destructor = ($<cbuf>3)->str;
841 g_string_free($<cbuf>3, FALSE);
842 destructor_line = ccode_line;
843 destructor_simple = FALSE;
844 } else if (strcmp ($<id>1, "unref") == 0) {
846 destructor_unref = TRUE;
847 destructor = ($<cbuf>3)->str;
848 g_string_free ($<cbuf>3, FALSE);
849 destructor_line = ccode_line;
850 destructor_simple = FALSE;
853 g_string_free ($<cbuf>3, TRUE);
854 yyerror (_("parse error"));
860 initializer: '=' numtok {
861 initializer = $<id>2;
862 initializer_line = ccode_line;
865 initializer = ($<cbuf>3)->str;
866 initializer_line = ccode_line;
867 g_string_free($<cbuf>3, FALSE);
872 varoptions: destructor initializer { ; }
873 | initializer destructor { ; }
874 | initializer { destructor = NULL; }
875 | destructor { initializer = NULL; }
882 variable: scope type TOKEN varoptions ';' {
883 push_variable($<id>3, the_scope,$<line>1, NULL);
885 | scope type TOKEN ARRAY_DIM varoptions ';' {
886 push_variable($<id>3, the_scope, $<line>1, $<id>4);
890 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
892 if(strcmp($<id>6,"get")==0 &&
893 strcmp($<id>9,"set")==0) {
894 Type *type = pop_type();
897 node = node_new (ARGUMENT_NODE,
898 "gtktype:steal", $<id>3,
900 "flags:steal", $<list>2,
901 "name:steal", $<id>4,
902 "get:steal", ($<cbuf>8)->str,
903 "get_line", $<line>7,
904 "set:steal", ($<cbuf>11)->str,
905 "set_line", $<line>10,
909 class_nodes = g_list_append(class_nodes,node);
911 g_string_free ($<cbuf>8, FALSE);
912 g_string_free ($<cbuf>11, FALSE);
914 } else if(strcmp($<id>6,"set")==0 &&
915 strcmp($<id>9,"get")==0) {
916 Type *type = pop_type();
919 node = node_new (ARGUMENT_NODE,
920 "gtktype:steal", $<id>3,
922 "flags:steal", $<list>2,
923 "name:steal", $<id>4,
924 "get:steal", ($<cbuf>11)->str,
925 "get_line", $<line>10,
926 "set:steal", ($<cbuf>8)->str,
927 "set_line", $<line>7,
930 g_string_free ($<cbuf>11, FALSE);
931 g_string_free ($<cbuf>8, FALSE);
932 class_nodes = g_list_append(class_nodes,node);
938 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
939 g_list_free ($<list>2);
940 g_string_free ($<cbuf>11, TRUE);
941 g_string_free ($<cbuf>8, TRUE);
942 yyerror (_("parse error"));
946 if ($<id>5 != NULL) {
947 Argument *arg = (Argument *)node;
948 export_accessors (arg->name,
949 arg->get != NULL, arg->get_line,
950 arg->set != NULL, arg->set_line,
958 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
960 if(strcmp($<id>6, "get") == 0) {
961 Type *type = pop_type();
963 node = node_new (ARGUMENT_NODE,
964 "gtktype:steal", $<id>3,
966 "flags:steal", $<list>2,
967 "name:steal", $<id>4,
968 "get:steal", ($<cbuf>8)->str,
969 "get_line", $<line>7,
973 g_string_free ($<cbuf>8, FALSE);
974 class_nodes = g_list_append(class_nodes, node);
975 } else if(strcmp($<id>6, "set") == 0) {
976 Type *type = pop_type();
978 node = node_new (ARGUMENT_NODE,
979 "gtktype:steal", $<id>3,
981 "flags:steal", $<list>2,
982 "name:steal", $<id>4,
983 "set:steal", ($<cbuf>8)->str,
984 "set_line", $<line>7,
988 g_string_free ($<cbuf>8, FALSE);
989 class_nodes = g_list_append (class_nodes, node);
994 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
995 g_list_free ($<list>2);
996 g_string_free ($<cbuf>8, TRUE);
997 yyerror(_("parse error"));
1001 if ($<id>5 != NULL) {
1002 Argument *arg = (Argument *)node;
1003 export_accessors (arg->name,
1004 arg->get != NULL, arg->get_line,
1005 arg->set != NULL, arg->set_line,
1012 | ARGUMENT flags argtype TOKEN export TOKEN {
1014 char *get, *set = NULL;
1019 if(strcmp($<id>6, "link")!=0 &&
1020 strcmp($<id>6, "stringlink")!=0 &&
1021 strcmp($<id>6, "objectlink")!=0) {
1025 g_list_foreach($<list>2,(GFunc)g_free,NULL);
1026 g_list_free($<list>2);
1027 yyerror(_("parse error"));
1033 var = find_var_or_die($<id>4, $<line>1);
1034 if(var->scope == PRIVATE_SCOPE) {
1035 root = "self->_priv";
1036 } else if(var->scope == CLASS_SCOPE) {
1037 root = "SELF_GET_CLASS(self)";
1039 error_print(GOB_ERROR, $<line>1,
1040 _("Self aliases needed when autolinking to a classwide member"));
1045 if(strcmp($<id>6, "link")==0) {
1046 set = g_strdup_printf("%s->%s = ARG;",
1048 } else if(strcmp($<id>6, "stringlink")==0) {
1049 set = g_strdup_printf("g_free (%s->%s); "
1050 "%s->%s = g_strdup (ARG);",
1053 } else if(strcmp($<id>6, "objectlink")==0) {
1054 set = g_strdup_printf(
1056 "g_object_ref (G_OBJECT (ARG)); "
1057 "if (%s->%s != NULL) "
1058 "g_object_unref (G_OBJECT (%s->%s)); "
1064 g_assert_not_reached();
1067 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
1072 type = (Type *)node_copy ((Node *)var->vtype);
1074 node = node_new (ARGUMENT_NODE,
1075 "gtktype:steal", $<id>3,
1076 "atype:steal", type,
1077 "flags:steal", $<list>2,
1078 "name:steal", $<id>4,
1080 "get_line", $<line>1,
1082 "set_line", $<line>1,
1083 "line_no", $<line>1,
1086 if ($<id>5 != NULL) {
1087 Argument *arg = (Argument *)node;
1088 export_accessors (arg->name,
1089 arg->get != NULL, arg->get_line,
1090 arg->set != NULL, arg->set_line,
1097 class_nodes = g_list_append (class_nodes, node);
1101 export: '(' TOKEN ')' {
1102 if (strcmp ($<id>2, "export")!=0) {
1104 yyerror (_("parse error"));
1114 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1116 node_set ((Node *)property,
1117 "line_no", $<line>1,
1118 "gtktype:steal", debool ($<id>2),
1119 "name:steal", $<id>3,
1121 if (strcmp ($<id>5, "get") == 0 &&
1122 strcmp ($<id>8, "set") == 0) {
1123 node_set ((Node *)property,
1124 "get:steal", ($<cbuf>7)->str,
1125 "get_line", $<line>6,
1126 "set:steal", ($<cbuf>10)->str,
1127 "set_line", $<line>9,
1129 g_string_free ($<cbuf>7, FALSE);
1130 g_string_free ($<cbuf>10, FALSE);
1133 } else if (strcmp ($<id>5, "set") == 0 &&
1134 strcmp ($<id>8, "get") == 0) {
1135 node_set ((Node *)property,
1136 "get:steal", ($<cbuf>10)->str,
1137 "get_line", $<line>9,
1138 "set:steal", ($<cbuf>7)->str,
1139 "set_line", $<line>6,
1141 g_string_free ($<cbuf>7, FALSE);
1142 g_string_free ($<cbuf>10, FALSE);
1146 g_string_free ($<cbuf>7, TRUE);
1147 g_string_free ($<cbuf>10, TRUE);
1150 node_free ((Node *)property);
1152 yyerror (_("parse error"));
1155 property_link_and_export ((Node *)property);
1156 if (property != NULL) {
1157 class_nodes = g_list_append (class_nodes,
1162 | PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE ';' {
1164 node_set ((Node *)property,
1165 "line_no", $<line>1,
1166 "gtktype:steal", debool ($<id>2),
1167 "name:steal", $<id>3,
1169 if (strcmp ($<id>5, "get") == 0) {
1170 node_set ((Node *)property,
1171 "get:steal", ($<cbuf>7)->str,
1172 "get_line", $<line>6,
1174 g_string_free ($<cbuf>7, FALSE);
1176 } else if (strcmp ($<id>5, "set") == 0) {
1177 node_set ((Node *)property,
1178 "set:steal", ($<cbuf>7)->str,
1179 "set_line", $<line>6,
1181 g_string_free ($<cbuf>7, FALSE);
1184 g_string_free ($<cbuf>7, TRUE);
1186 node_free ((Node *)property);
1188 yyerror (_("parse error"));
1191 property_link_and_export ((Node *)property);
1192 if (property != NULL) {
1193 class_nodes = g_list_append (class_nodes,
1198 | PROPERTY TOKEN TOKEN param_spec ';' {
1200 node_set ((Node *)property,
1201 "line_no", $<line>1,
1202 "gtktype:steal", debool ($<id>2),
1203 "name:steal", $<id>3,
1205 property_link_and_export ((Node *)property);
1206 if (property != NULL) {
1207 class_nodes = g_list_append (class_nodes,
1214 param_spec: '(' param_spec_list ')' { ; }
1218 param_spec_list: param_spec_list ',' param_spec_value { ; }
1219 | param_spec_value { ; }
1222 string: STRING { $<id>$ = $<id>1; }
1223 | TOKEN '(' STRING ')' {
1224 if (strcmp ($<id>1, "_") != 0) {
1226 yyerror(_("parse error"));
1230 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1235 anyval: numtok { $<id>$ = $<id>1; }
1236 | string { $<id>$ = $<id>1; }
1239 param_spec_value: NICK '=' string {
1241 node_set ((Node *)property,
1242 "nick:steal", $<id>3,
1245 | BLURB '=' string {
1247 node_set ((Node *)property,
1248 "blurb:steal", $<id>3,
1251 | MAXIMUM '=' numtok {
1253 node_set ((Node *)property,
1254 "maximum:steal", $<id>3,
1257 | MINIMUM '=' numtok {
1259 node_set ((Node *)property,
1260 "minimum:steal", $<id>3,
1263 | DEFAULT_VALUE '=' anyval {
1265 node_set ((Node *)property,
1266 "default_value:steal", $<id>3,
1269 | FLAGS '=' flaglist {
1271 node_set ((Node *)property,
1272 "flags:steal", $<list>3,
1276 Type *type = pop_type ();
1278 node_set ((Node *)property,
1279 "ptype:steal", type,
1282 | FLAGS_TYPE '=' TYPETOKEN {
1284 node_set ((Node *)property,
1285 "extra_gtktype:steal", $<id>3,
1288 | FLAGS_TYPE '=' TOKEN {
1290 node_set ((Node *)property,
1291 "extra_gtktype:steal", $<id>3,
1294 | ENUM_TYPE '=' TYPETOKEN {
1296 node_set ((Node *)property,
1297 "extra_gtktype:steal", $<id>3,
1300 | ENUM_TYPE '=' TOKEN {
1302 node_set ((Node *)property,
1303 "extra_gtktype:steal", $<id>3,
1306 | PARAM_TYPE '=' TYPETOKEN {
1308 node_set ((Node *)property,
1309 "extra_gtktype:steal", $<id>3,
1312 | PARAM_TYPE '=' TOKEN {
1314 node_set ((Node *)property,
1315 "extra_gtktype:steal", $<id>3,
1318 | BOXED_TYPE '=' TYPETOKEN {
1320 node_set ((Node *)property,
1321 "extra_gtktype:steal", $<id>3,
1324 | BOXED_TYPE '=' TOKEN {
1326 node_set ((Node *)property,
1327 "extra_gtktype:steal", $<id>3,
1330 | OBJECT_TYPE '=' TYPETOKEN {
1332 node_set ((Node *)property,
1333 "extra_gtktype:steal", $<id>3,
1336 | OBJECT_TYPE '=' TOKEN {
1338 node_set ((Node *)property,
1339 "extra_gtktype:steal", $<id>3,
1344 if (strcmp ($<id>1, "link") == 0) {
1346 node_set ((Node *)property,
1349 } else if (strcmp ($<id>1, "export") == 0) {
1351 node_set ((Node *)property,
1356 yyerror(_("parse error"));
1362 argtype: TOKEN '(' TOKEN type ')' {
1363 if(strcmp($<id>3,"type")!=0) {
1366 yyerror(_("parse error"));
1369 $<id>$ = debool ($<id>1);
1372 $<id>$ = debool ($<id>1);
1373 typestack = g_list_prepend(typestack,NULL);
1377 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1378 | { $<list>$ = NULL; }
1381 flaglist: TOKEN '|' flaglist {
1382 $<list>$ = g_list_append($<list>3,$<id>1);
1385 $<list>$ = g_list_append(NULL,$<id>1);
1390 type: specifier_list pointer {
1391 Node *node = node_new (TYPE_NODE,
1392 "name:steal", $<id>1,
1393 "pointer:steal", $<id>2,
1395 typestack = g_list_prepend(typestack,node);
1398 Node *node = node_new (TYPE_NODE,
1399 "name:steal", $<id>1,
1401 typestack = g_list_prepend(typestack,node);
1405 /* The special cases are neccessary to avoid conflicts */
1406 specifier_list: spec_list {
1413 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1417 $<id>$ = g_strconcat($<id>1, " const", NULL);
1420 | strunionenum TOKEN {
1421 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1424 | CONST strunionenum TOKEN {
1425 $<id>$ = g_strconcat("const ", $<id>2, " ",
1429 | strunionenum TOKEN CONST {
1430 $<id>$ = g_strconcat($<id>1, " ",
1431 $<id>2, " const", NULL);
1436 /* The special const cases take care of conflicts ! */
1437 spec_list: specifier spec_list {
1438 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1441 | TYPETOKEN spec_list {
1442 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1447 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1454 $<id>$ = g_strconcat($<id>1, " const", NULL);
1458 $<id>$ = g_strdup($<id>1);
1461 $<id>$ = g_strconcat($<id>1, " const", NULL);
1465 specifier: VOID { $<id>$ = "void"; }
1466 | CHAR { $<id>$ = "char"; }
1467 | SHORT { $<id>$ = "short"; }
1468 | INT { $<id>$ = "int"; }
1469 | LONG { $<id>$ = "long"; }
1470 | FLOAT { $<id>$ = "float"; }
1471 | DOUBLE { $<id>$ = "double"; }
1472 | SIGNED { $<id>$ = "signed"; }
1473 | UNSIGNED { $<id>$ = "unsigned"; }
1476 strunionenum: STRUCT { $<id>$ = "struct"; }
1477 | UNION { $<id>$ = "union"; }
1478 | ENUM { $<id>$ = "enum"; }
1481 pointer: '*' { $<id>$ = g_strdup("*"); }
1482 | '*' CONST { $<id>$ = g_strdup("* const"); }
1484 $<id>$ = g_strconcat("*", $<id>2, NULL);
1487 | '*' CONST pointer {
1488 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1493 /* this never sets the_scope */
1494 simplesigtype: TOKEN sigtype {
1495 if(strcmp($<id>1, "first")==0)
1496 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1497 else if(strcmp($<id>1, "last")==0)
1498 $<sigtype>$ = SIGNAL_LAST_METHOD;
1500 yyerror(_("signal must be 'first' or 'last'"));
1507 $<sigtype>$ = SIGNAL_LAST_METHOD;
1511 /* this always sets the_scope */
1512 fullsigtype: scope TOKEN sigtype {
1513 if(strcmp($<id>2,"first")==0)
1514 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1515 else if(strcmp($<id>2,"last")==0)
1516 $<sigtype>$ = SIGNAL_LAST_METHOD;
1518 yyerror(_("signal must be 'first' or 'last'"));
1524 | TOKEN scope sigtype {
1525 if(strcmp($<id>1,"first")==0)
1526 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1527 else if(strcmp($<id>1,"last")==0)
1528 $<sigtype>$ = SIGNAL_LAST_METHOD;
1530 yyerror(_("signal must be 'first' or 'last'"));
1537 $<sigtype>$ = SIGNAL_LAST_METHOD;
1540 /* the_scope was default thus public */
1541 the_scope = PUBLIC_SCOPE;
1545 sigtype: TOKEN '(' tokenlist ')' {
1546 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1550 tokenlist: tokenlist ',' TOKEN {
1551 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1554 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1558 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1559 | ';' { $<cbuf>$ = NULL; }
1562 /*here CCODE will include the ending '}' */
1563 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1565 yyerror(_("signal without 'self' as "
1566 "first parameter"));
1567 free_all_global_state();
1570 if(the_scope == CLASS_SCOPE) {
1571 yyerror(_("a method cannot be of class scope"));
1572 free_all_global_state();
1575 push_function(the_scope, $<sigtype>3,NULL,
1576 $<id>5, $<cbuf>10,$<line>1,
1577 ccode_line, vararg, $<list>2);
1579 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1581 yyerror(_("signal without 'self' as "
1582 "first parameter"));
1583 free_all_global_state();
1586 if(the_scope == CLASS_SCOPE) {
1587 yyerror(_("a method cannot be of class scope"));
1588 free_all_global_state();
1591 push_function(the_scope, $<sigtype>4, NULL,
1592 $<id>6, $<cbuf>11, $<line>2,
1593 ccode_line, vararg, $<list>3);
1595 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1597 yyerror(_("virtual method without 'self' as "
1598 "first parameter"));
1599 free_all_global_state();
1602 if(the_scope == CLASS_SCOPE) {
1603 yyerror(_("a method cannot be of class scope"));
1604 free_all_global_state();
1607 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1609 ccode_line, vararg, NULL);
1611 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1613 yyerror(_("virtual method without 'self' as "
1614 "first parameter"));
1615 free_all_global_state();
1618 if(the_scope == CLASS_SCOPE) {
1619 yyerror(_("a method cannot be of class scope"));
1620 free_all_global_state();
1623 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1625 ccode_line, vararg, NULL);
1627 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1629 yyerror(_("virtual method without 'self' as "
1630 "first parameter"));
1631 free_all_global_state();
1634 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1635 $<id>3, $<cbuf>8, $<line>1,
1636 ccode_line, vararg, NULL);
1638 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1639 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1641 $<line>1, ccode_line,
1644 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1645 if(the_scope == CLASS_SCOPE) {
1646 yyerror(_("a method cannot be of class scope"));
1647 free_all_global_state();
1650 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1651 $<cbuf>8, $<line>1, ccode_line,
1654 | TOKEN '(' TOKEN ')' codenocode {
1655 if(strcmp($<id>1, "init")==0) {
1656 push_init_arg($<id>3,FALSE);
1657 push_function(NO_SCOPE, INIT_METHOD, NULL,
1658 $<id>1, $<cbuf>5, $<line>2,
1659 ccode_line, FALSE, NULL);
1660 } else if(strcmp($<id>1, "class_init")==0) {
1661 push_init_arg($<id>3,TRUE);
1662 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1663 $<id>1, $<cbuf>5, $<line>2,
1664 ccode_line, FALSE, NULL);
1668 g_string_free($<cbuf>5,TRUE);
1669 yyerror(_("parse error "
1670 "(untyped blocks must be init or "
1677 returnvals: TOKEN retcode {
1678 g_free(onerror); onerror = NULL;
1679 g_free(defreturn); defreturn = NULL;
1680 if(!set_return_value($<id>1, $<id>2)) {
1683 yyerror(_("parse error"));
1688 | TOKEN retcode TOKEN retcode {
1689 g_free(onerror); onerror = NULL;
1690 g_free(defreturn); defreturn = NULL;
1691 if(!set_return_value($<id>1, $<id>2)) {
1692 g_free($<id>1); g_free($<id>2);
1693 g_free($<id>3); g_free($<id>4);
1694 yyerror(_("parse error"));
1697 if(!set_return_value($<id>3, $<id>4)) {
1698 onerror = defreturn = NULL;
1699 g_free($<id>1); g_free($<id>2);
1700 g_free($<id>3); g_free($<id>4);
1701 yyerror(_("parse error"));
1708 g_free(onerror); onerror = NULL;
1709 g_free(defreturn); defreturn = NULL;
1713 retcode: numtok { $<id>$ = $<id>1; }
1715 $<id>$ = ($<cbuf>2)->str;
1716 g_string_free($<cbuf>2, FALSE);
1720 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1724 if(strcmp($<id>1,"self")==0)
1725 push_self($<id>1, FALSE);
1728 yyerror(_("parse error"));
1735 if(strcmp($<id>1,"self")==0)
1736 push_self($<id>1, TRUE);
1739 yyerror(_("parse error"));
1746 if(strcmp($<id>2,"self")==0)
1747 push_self($<id>2, TRUE);
1750 yyerror(_("parse error"));
1754 | TOKEN ',' arglist {
1756 if(strcmp($<id>1,"self")==0)
1757 push_self($<id>1, FALSE);
1760 yyerror(_("parse error"));
1764 | TOKEN CONST ',' arglist {
1766 if(strcmp($<id>1,"self")==0)
1767 push_self($<id>1, TRUE);
1770 yyerror(_("parse error"));
1774 | CONST TOKEN ',' arglist {
1776 if(strcmp($<id>2,"self")==0)
1777 push_self($<id>2, TRUE);
1780 yyerror(_("parse error"));
1784 | arglist { has_self = FALSE; }
1787 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1788 | arglist1 { vararg = FALSE; }
1791 arglist1: arglist1 ',' arg { ; }
1796 push_funcarg($<id>2,NULL);
1798 | type TOKEN ARRAY_DIM {
1799 push_funcarg($<id>2,$<id>3);
1801 | type TOKEN '(' TOKEN checklist ')' {
1802 if(strcmp($<id>4,"check")!=0) {
1803 yyerror(_("parse error"));
1807 push_funcarg($<id>2,NULL);
1809 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1810 if(strcmp($<id>5,"check")!=0) {
1811 yyerror(_("parse error"));
1815 push_funcarg($<id>2,$<id>3);
1819 checklist: checklist check { ; }
1824 if(strcmp($<id>1,"type")==0) {
1825 Node *node = node_new (CHECK_NODE,
1826 "chtype", TYPE_CHECK,
1828 checks = g_list_append(checks,node);
1829 } else if(strcmp($<id>1,"null")==0) {
1830 Node *node = node_new (CHECK_NODE,
1831 "chtype", NULL_CHECK,
1833 checks = g_list_append(checks,node);
1835 yyerror(_("parse error"));
1841 Node *node = node_new (CHECK_NODE,
1843 "number:steal", $<id>2,
1845 checks = g_list_append(checks,node);
1848 Node *node = node_new (CHECK_NODE,
1850 "number:steal", $<id>2,
1852 checks = g_list_append(checks,node);
1855 Node *node = node_new (CHECK_NODE,
1857 "number:steal", $<id>3,
1859 checks = g_list_append(checks,node);
1862 Node *node = node_new (CHECK_NODE,
1864 "number:steal", $<id>3,
1866 checks = g_list_append(checks,node);
1869 Node *node = node_new (CHECK_NODE,
1871 "number:steal", $<id>3,
1873 checks = g_list_append(checks,node);
1876 Node *node = node_new (CHECK_NODE,
1878 "number:steal", $<id>3,
1880 checks = g_list_append(checks,node);
1884 enumcode: ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
1885 Node *node = node_new (ENUMDEF_NODE,
1886 "etype:steal", $<id>6,
1887 "prefix:steal", $<id>2,
1888 "values:steal", enum_vals,
1891 nodes = g_list_append (nodes, node);
1893 | ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
1894 Node *node = node_new (ENUMDEF_NODE,
1895 "etype:steal", $<id>7,
1896 "prefix:steal", $<id>2,
1897 "values:steal", enum_vals,
1900 nodes = g_list_append (nodes, node);
1904 enumvals: enumvals ',' enumval {;}
1908 enumval: TOKEN '=' numtok {
1912 /* A float value, that's a bad enum */
1913 if (num[0] >= '0' &&
1915 strchr (num, '.') != NULL) {
1918 yyerror(_("parse error (enumerator value not integer constant)"));
1922 node = node_new (ENUMVALUE_NODE,
1923 "name:steal", $<id>1,
1926 enum_vals = g_list_append (enum_vals, node);
1931 node = node_new (ENUMVALUE_NODE,
1932 "name:steal", $<id>1,
1934 enum_vals = g_list_append (enum_vals, node);
1938 flagcode: FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
1939 Node *node = node_new (FLAGS_NODE,
1940 "ftype:steal", $<id>6,
1941 "prefix:steal", $<id>2,
1942 "values:steal", flag_vals,
1945 nodes = g_list_append (nodes, node);
1947 | FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
1948 Node *node = node_new (FLAGS_NODE,
1949 "ftype:steal", $<id>7,
1950 "prefix:steal", $<id>2,
1951 "values:steal", flag_vals,
1954 nodes = g_list_append (nodes, node);
1958 flagvals: flagvals ',' TOKEN {
1959 flag_vals = g_list_append (flag_vals, $<id>3);
1962 flag_vals = g_list_append (flag_vals, $<id>1);
1966 errorcode: ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
1967 Node *node = node_new (ERROR_NODE,
1968 "etype:steal", $<id>6,
1969 "prefix:steal", $<id>2,
1970 "values:steal", error_vals,
1973 nodes = g_list_append (nodes, node);
1975 | ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
1976 Node *node = node_new (ERROR_NODE,
1977 "etype:steal", $<id>7,
1978 "prefix:steal", $<id>2,
1979 "values:steal", error_vals,
1982 nodes = g_list_append (nodes, node);
1986 errorvals: errorvals ',' TOKEN {
1987 error_vals = g_list_append (error_vals, $<id>3);
1990 error_vals = g_list_append (error_vals, $<id>1);
1995 numtok: NUMBER { $<id>$ = $<id>1; }
1997 $<id>$ = g_strconcat("-",$<id>2,NULL);
2000 | SINGLE_CHAR { $<id>$ = $<id>1; }
2001 | TOKEN { $<id>$ = $<id>1; }