2 * Copyright (C) 1999-2000 the Free Software Foundation.
3 * Copyright (C) 2001 George Lebl
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 #include "treefuncs.h"
38 static GList *class_nodes = NULL;
41 static char *chunk_size = NULL;
42 static char *bonobo_x_class = NULL;
43 static GList *typestack = NULL;
44 static GList *funcargs = NULL;
45 static GList *checks = NULL;
46 static int has_self = FALSE;
47 static int vararg = FALSE;
48 static Method *last_added_method = NULL;
50 /* destructor and initializer for variables */
51 static gboolean destructor_unref = FALSE;
52 static char *destructor = NULL;
53 static int destructor_line = 0;
54 static gboolean destructor_simple = TRUE;
55 static char *initializer = NULL;
56 static int initializer_line = 0;
58 static char *onerror = NULL;
59 static char *defreturn = NULL;
61 static GList *gtktypes = NULL;
63 static Property *property = NULL;
65 /* this can be a global as we will only do one function at a time
67 static int the_scope = NO_SCOPE;
72 extern int ccode_line;
83 if(strcmp(yytext,"\n")==0) {
84 out=g_strconcat("Error: ",str," before newline",NULL);
85 } else if(yytext[0]=='\0') {
86 out=g_strconcat("Error: ", str, " at end of input", NULL);
88 char *tmp = g_strdup(yytext);
89 while((p=strchr(tmp, '\n')))
92 out=g_strconcat("Error: ", str, " before '", tmp, "'", NULL);
96 fprintf(stderr, "%s:%d: %s\n", filename, line_no, out);
105 Type *type = typestack->data;
106 typestack = g_list_remove(typestack,typestack->data);
111 push_variable (char *name, int scope, int line_no, char *postfix)
114 Type *type = pop_type ();
116 type->postfix = postfix;
118 var = node_new (VARIABLE_NODE,
123 "destructor_unref", destructor_unref,
124 "destructor:steal", destructor,
125 "destructor_line", destructor_line,
126 "destructor_simple", destructor_simple,
127 "initializer:steal", initializer,
128 "initializer_line", initializer_line,
130 class_nodes = g_list_append(class_nodes, var);
134 push_function (int scope, int method, char *oid, char *id,
135 GString *cbuf, int line_no, int ccode_line,
136 gboolean vararg, GList *flags)
142 g_assert(scope != CLASS_SCOPE);
144 if(method == INIT_METHOD || method == CLASS_INIT_METHOD) {
145 type = (Type *)node_new (TYPE_NODE,
152 /* a complicated and ugly test to figure out if we have
153 the wrong number of types for a signal */
154 if((method == SIGNAL_FIRST_METHOD ||
155 method == SIGNAL_LAST_METHOD) &&
156 g_list_length(gtktypes) != g_list_length(funcargs) &&
157 !(g_list_length(funcargs) == 1 &&
158 g_list_length(gtktypes) == 2 &&
159 strcmp(gtktypes->next->data, "NONE")==0)) {
160 error_print(GOB_WARN, line_no,
161 _("The number of GTK arguments and "
162 "function arguments for a signal "
163 "don't seem to match"));
165 if(g_list_length(gtktypes) > 2) {
167 for(li = gtktypes->next; li; li = li->next) {
168 if(strcmp(li->data, "NONE")==0) {
169 error_print(GOB_ERROR, line_no,
170 _("NONE can only appear in an "
171 "argument list by itself"));
177 c_cbuf = p = cbuf->str;
178 while(p && *p && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
185 node = node_new (METHOD_NODE,
190 "gtktypes:steal", gtktypes,
191 "flags:steal", flags,
193 "args:steal", funcargs,
194 "onerror:steal", onerror,
195 "defreturn:steal", defreturn,
196 "cbuf:steal", c_cbuf,
198 "ccode_line", ccode_line,
200 "unique_id", method_unique_id++,
203 last_added_method = (Method *)node;
207 /*only free segment if we haven't passed it
216 class_nodes = g_list_append(class_nodes, node);
220 free_all_global_state(void)
230 g_list_foreach(gtktypes, (GFunc)g_free, NULL);
231 g_list_free(gtktypes);
234 node_list_free (funcargs);
239 push_funcarg(char *name, char *postfix)
242 Type *type = pop_type();
244 type->postfix = postfix;
246 node = node_new (FUNCARG_NODE,
249 "checks:steal", checks,
253 funcargs = g_list_append(funcargs, node);
257 push_init_arg(char *name, int is_class)
264 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
266 tn = g_strdup(((Class *)class)->otype);
268 type = node_new (TYPE_NODE,
272 node = node_new (FUNCARG_NODE,
273 "atype:steal", (Type *)type,
276 funcargs = g_list_prepend(funcargs, node);
280 push_self(char *id, gboolean constant)
285 type = node_new (TYPE_NODE,
286 "name", ((Class *)class)->otype,
287 "pointer", constant ? "const *" : "*",
289 ch = g_list_append (ch, node_new (CHECK_NODE,
290 "chtype", NULL_CHECK,
292 ch = g_list_append (ch, node_new (CHECK_NODE,
293 "chtype", TYPE_CHECK,
295 node = node_new (FUNCARG_NODE,
296 "atype:steal", (Type *)type,
300 funcargs = g_list_prepend(funcargs, node);
304 find_var_or_die(const char *id, int line)
308 for(li = class_nodes; li != NULL; li = li->next) {
310 Node *node = li->data;
311 if(node->type != VARIABLE_NODE)
314 if(strcmp(var->id, id)==0)
318 error_printf(GOB_ERROR, line, _("Variable %s not defined here"), id);
320 g_assert_not_reached();
325 set_return_value(char *type, char *val)
327 if(strcmp(type, "onerror")==0) {
333 } else if(strcmp(type, "defreturn")==0) {
344 export_accessors (const char *var_name,
356 the_type = (Type *)node_copy ((Node *)type);
358 the_type = get_tree_type (gtktype, TRUE);
360 if (the_type == NULL) {
361 error_print (GOB_ERROR, line_no,
362 _("Cannot determine type of property or argument"));
367 char *get_id = g_strdup_printf ("get_%s", var_name);
368 GString *get_cbuf = g_string_new (NULL);
369 Node *node1 = node_new (TYPE_NODE,
370 "name", the_type->name,
371 "pointer", the_type->pointer,
372 "postfix", the_type->postfix,
374 Node *node3 = node_new (TYPE_NODE,
375 "name", class->class.otype,
379 g_string_sprintf (get_cbuf,
381 "g_object_get (G_OBJECT (self), \"%s\", "
385 the_type->pointer ? the_type->pointer : "",
388 typestack = g_list_prepend (typestack, node1);
389 typestack = g_list_prepend (typestack, node3);
391 push_funcarg ("self", FALSE);
393 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
394 get_id, get_cbuf, get_lineno,
395 lineno, FALSE, NULL);
399 char *set_id = g_strdup_printf ("set_%s", var_name);
400 GString *set_cbuf = g_string_new (NULL);
401 Node *node1 = node_new (TYPE_NODE,
402 "name", the_type->name,
403 "pointer", the_type->pointer,
404 "postfix", the_type->postfix,
406 Node *node2 = node_new (TYPE_NODE,
409 Node *node3 = node_new (TYPE_NODE,
410 "name", class->class.otype,
414 g_string_sprintf (set_cbuf,
415 "\tg_object_set (G_OBJECT (self), "
416 "\"%s\", val, NULL);\n",
419 typestack = g_list_prepend (typestack, node2);
420 typestack = g_list_prepend (typestack, node1);
421 typestack = g_list_prepend (typestack, node3);
423 push_funcarg ("self", FALSE);
424 push_funcarg ("val", FALSE);
426 typestack = g_list_prepend (typestack, node2);
427 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
428 set_id, set_cbuf, set_lineno,
429 lineno, FALSE, NULL);
432 node_free ((Node *)the_type);
436 property_link_and_export (Node *node)
438 Property *prop = (Property *)node;
442 char *get = NULL, *set = NULL;
445 if (prop->set != NULL ||
447 error_print (GOB_ERROR, prop->line_no,
448 _("Property linking requested, but "
449 "getters and setters exist"));
452 var = find_var_or_die (prop->name, prop->line_no);
453 if(var->scope == PRIVATE_SCOPE) {
454 root = "self->_priv";
455 } else if (var->scope == CLASS_SCOPE) {
456 root = "SELF_GET_CLASS(self)";
458 error_print (GOB_ERROR, prop->line_no,
459 _("Self aliases needed when autolinking to a classwide member"));
464 if (strcmp (prop->gtktype, "STRING") == 0) {
465 set = g_strdup_printf("g_free (%s->%s); "
466 "%s->%s = g_value_dup_string (VAL);",
469 get = g_strdup_printf("g_value_set_string (VAL, %s->%s);",
471 } else if (strcmp (prop->gtktype, "OBJECT") == 0) {
472 set = g_strdup_printf("{ GtkObject *___old = (GtkObject *)%s->%s; "
473 "GtkObject *___new = (GtkObject *)gtk_value_get_object (VAL); "
474 "if (___new != NULL) { "
475 "gtk_object_ref (GTK_OBJECT (___new)); "
476 "%s->%s = GTK_OBJECT (___new); "
480 "if (___old != NULL) { "
481 "gtk_object_unref (GTK_OBJECT (___old)); "
487 get = g_strdup_printf("g_value_set_object (VAL, %s->%s);",
489 } else if (strcmp (prop->gtktype, "BOXED") == 0) {
490 if (prop->extra_gtktype == NULL) {
491 error_print (GOB_ERROR, prop->line_no,
492 _("Property linking requested for BOXED, but "
493 "boxed_type not set"));
495 set = g_strdup_printf("{ gpointer ___old = (gpointer)%s->%s; "
496 "gpointer ___new = (gpointer)gtk_value_get_boxed (VAL); "
497 "if (___new != ___old) { "
498 "if (___old != NULL) g_boxed_free (%s, ___old); "
499 "if (___new != NULL) %s->%s = g_boxed_copy (%s, ___new); "
500 "else %s->%s = NULL;"
508 get = g_strdup_printf("g_value_set_object (VAL, %s->%s);",
513 set_func = g_strdup_printf ("g_value_set_%s", prop->gtktype);
514 g_strdown (set_func);
515 get_func = g_strdup_printf ("g_value_get_%s", prop->gtktype);
516 g_strdown (get_func);
518 set = g_strdup_printf("%s->%s = %s (VAL);",
521 get = g_strdup_printf("%s (VAL, %s->%s);",
531 "get_line", prop->line_no,
533 "set_line", prop->line_no,
538 export_accessors (prop->name,
539 prop->get != NULL, prop->get_line,
540 prop->set != NULL, prop->get_line,
551 if (strcmp (s, "BOOL") == 0) {
552 error_print (GOB_WARN, line_no,
553 _("BOOL type is deprecated, please use BOOLEAN"));
555 return g_strdup ("BOOLEAN");
562 ensure_property (void)
564 if (property == NULL)
565 property = (Property *)node_new (PROPERTY_NODE, NULL);
579 %token CONST VOID STRUCT UNION ENUM THREEDOTS
580 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
582 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
583 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
584 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
585 %token <line> VIRTUAL SIGNAL OVERRIDE
586 %token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE FLAGS TYPE
587 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
591 prog: ccodes class ccodes { ; }
598 Node *node = node_new (CCODE_NODE,
600 "cbuf:steal", ($<cbuf>1)->str,
601 "line_no", ccode_line,
603 nodes = g_list_append(nodes,node);
604 g_string_free($<cbuf>1,FALSE);
607 Node *node = node_new (CCODE_NODE,
609 "cbuf:steal", ($<cbuf>1)->str,
610 "line_no", ccode_line,
612 nodes = g_list_append(nodes,node);
613 g_string_free($<cbuf>1,FALSE);
616 Node *node = node_new (CCODE_NODE,
618 "cbuf:steal", ($<cbuf>1)->str,
619 "line_no", ccode_line,
621 nodes = g_list_append(nodes,node);
622 g_string_free($<cbuf>1,FALSE);
625 Node *node = node_new (CCODE_NODE,
627 "cbuf:steal", ($<cbuf>1)->str,
628 "line_no", ccode_line,
630 nodes = g_list_append(nodes,node);
631 g_string_free($<cbuf>1,FALSE);
634 Node *node = node_new (CCODE_NODE,
636 "cbuf:steal", ($<cbuf>1)->str,
637 "line_no", ccode_line,
639 nodes = g_list_append(nodes,node);
640 g_string_free($<cbuf>1,FALSE);
643 Node *node = node_new (CCODE_NODE,
645 "cbuf:steal", ($<cbuf>1)->str,
646 "line_no", ccode_line,
648 nodes = g_list_append(nodes,node);
649 g_string_free($<cbuf>1,FALSE);
653 ccodes: ccodes ccode { ; }
657 class: classdec '{' classcode '}' {
658 ((Class *)class)->nodes = class_nodes;
660 nodes = g_list_append(nodes,class);
663 ((Class *)class)->nodes = NULL;
665 nodes = g_list_append(nodes,class);
669 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
670 class = node_new (CLASS_NODE,
671 "otype:steal", $<id>2,
672 "ptype:steal", $<id>4,
673 "bonobo_x_class:steal", bonobo_x_class,
674 "chunk_size:steal", chunk_size,
680 | '(' TOKEN TOKEN ')' classflags {
681 if(strcmp($<id>2,"chunks") == 0) {
683 chunk_size = g_strdup($<id>3);
684 } else if(strcmp($<id>2,"BonoboX") == 0) {
685 g_free (bonobo_x_class);
686 bonobo_x_class = g_strdup($<id>3);
688 yyerror(_("parse error"));
692 | '(' TOKEN NUMBER ')' classflags {
693 if(strcmp($<id>2,"chunks") == 0) {
695 if(atoi($<id>3) != 0)
696 chunk_size = g_strdup($<id>3);
700 yyerror(_("parse error"));
706 classcode: classcode thing { ; }
712 if (strcmp ($<id>1, "BonoboX") != 0) {
714 yyerror(_("parse error"));
717 last_added_method->bonobo_x_func = TRUE;
725 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
726 | PRIVATE { the_scope = PRIVATE_SCOPE; }
727 | PROTECTED { the_scope = PROTECTED_SCOPE; }
728 | CLASSWIDE { the_scope = CLASS_SCOPE; }
731 destructor: TOKEN TOKEN {
732 if (strcmp ($<id>1, "destroywith") == 0) {
734 destructor_unref = FALSE;
736 destructor_line = line_no;
737 destructor_simple = TRUE;
738 } else if (strcmp ($<id>1, "unrefwith") == 0) {
740 destructor_unref = TRUE;
742 destructor_line = line_no;
743 destructor_simple = TRUE;
747 yyerror (_("parse error"));
752 if (strcmp ($<id>1, "destroy") == 0) {
754 destructor_unref = FALSE;
755 destructor = ($<cbuf>3)->str;
756 g_string_free($<cbuf>3, FALSE);
757 destructor_line = ccode_line;
758 destructor_simple = FALSE;
759 } else if (strcmp ($<id>1, "unref") == 0) {
761 destructor_unref = TRUE;
762 destructor = ($<cbuf>3)->str;
763 g_string_free ($<cbuf>3, FALSE);
764 destructor_line = ccode_line;
765 destructor_simple = FALSE;
768 g_string_free ($<cbuf>3, TRUE);
769 yyerror (_("parse error"));
775 initializer: '=' numtok {
776 initializer = $<id>2;
777 initializer_line = ccode_line;
780 initializer = ($<cbuf>3)->str;
781 initializer_line = ccode_line;
782 g_string_free($<cbuf>3, FALSE);
787 varoptions: destructor initializer { ; }
788 | initializer destructor { ; }
789 | initializer { destructor = NULL; }
790 | destructor { initializer = NULL; }
797 variable: scope type TOKEN varoptions ';' {
798 push_variable($<id>3, the_scope,$<line>1, NULL);
800 | scope type TOKEN ARRAY_DIM varoptions ';' {
801 push_variable($<id>3, the_scope, $<line>1, $<id>4);
805 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
807 if(strcmp($<id>6,"get")==0 &&
808 strcmp($<id>9,"set")==0) {
809 Type *type = pop_type();
812 node = node_new (ARGUMENT_NODE,
813 "gtktype:steal", $<id>3,
815 "flags:steal", $<list>2,
816 "name:steal", $<id>4,
817 "get:steal", ($<cbuf>8)->str,
818 "get_line", $<line>7,
819 "set:steal", ($<cbuf>11)->str,
820 "set_line", $<line>10,
824 class_nodes = g_list_append(class_nodes,node);
826 g_string_free ($<cbuf>8, FALSE);
827 g_string_free ($<cbuf>11, FALSE);
829 } else if(strcmp($<id>6,"set")==0 &&
830 strcmp($<id>9,"get")==0) {
831 Type *type = pop_type();
834 node = node_new (ARGUMENT_NODE,
835 "gtktype:steal", $<id>3,
837 "flags:steal", $<list>2,
838 "name:steal", $<id>4,
839 "get:steal", ($<cbuf>11)->str,
840 "get_line", $<line>10,
841 "set:steal", ($<cbuf>8)->str,
842 "set_line", $<line>7,
845 g_string_free ($<cbuf>11, FALSE);
846 g_string_free ($<cbuf>8, FALSE);
847 class_nodes = g_list_append(class_nodes,node);
853 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
854 g_list_free ($<list>2);
855 g_string_free ($<cbuf>11, TRUE);
856 g_string_free ($<cbuf>8, TRUE);
857 yyerror (_("parse error"));
861 if ($<id>5 != NULL) {
862 Argument *arg = (Argument *)node;
863 export_accessors (arg->name,
864 arg->get != NULL, arg->get_line,
865 arg->set != NULL, arg->set_line,
873 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
875 if(strcmp($<id>6, "get") == 0) {
876 Type *type = pop_type();
878 node = node_new (ARGUMENT_NODE,
879 "gtktype:steal", $<id>3,
881 "flags:steal", $<list>2,
882 "name:steal", $<id>4,
883 "get:steal", ($<cbuf>8)->str,
884 "get_line", $<line>7,
888 g_string_free ($<cbuf>8, FALSE);
889 class_nodes = g_list_append(class_nodes, node);
890 } else if(strcmp($<id>6, "set") == 0) {
891 Type *type = pop_type();
893 node = node_new (ARGUMENT_NODE,
894 "gtktype:steal", $<id>3,
896 "flags:steal", $<list>2,
897 "name:steal", $<id>4,
898 "set:steal", ($<cbuf>8)->str,
899 "set_line", $<line>7,
903 g_string_free ($<cbuf>8, FALSE);
904 class_nodes = g_list_append (class_nodes, node);
909 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
910 g_list_free ($<list>2);
911 g_string_free ($<cbuf>8, TRUE);
912 yyerror(_("parse error"));
916 if ($<id>5 != NULL) {
917 Argument *arg = (Argument *)node;
918 export_accessors (arg->name,
919 arg->get != NULL, arg->get_line,
920 arg->set != NULL, arg->set_line,
927 | ARGUMENT flags argtype TOKEN export TOKEN {
929 char *get, *set = NULL;
934 if(strcmp($<id>6, "link")!=0 &&
935 strcmp($<id>6, "stringlink")!=0 &&
936 strcmp($<id>6, "objectlink")!=0) {
940 g_list_foreach($<list>2,(GFunc)g_free,NULL);
941 g_list_free($<list>2);
942 yyerror(_("parse error"));
948 var = find_var_or_die($<id>4, $<line>1);
949 if(var->scope == PRIVATE_SCOPE)
950 root = "self->_priv";
951 else if(var->scope == CLASS_SCOPE) {
952 root = "SELF_GET_CLASS(self)";
954 error_print(GOB_ERROR, $<line>1,
955 _("Self aliases needed when autolinking to a classwide member"));
959 if(strcmp($<id>6, "link")==0) {
960 set = g_strdup_printf("%s->%s = ARG;",
962 } else if(strcmp($<id>6, "stringlink")==0) {
963 set = g_strdup_printf("g_free (%s->%s); "
964 "%s->%s = g_strdup (ARG);",
967 } else if(strcmp($<id>6, "objectlink")==0) {
968 set = g_strdup_printf(
970 "g_object_ref (G_OBJECT (ARG)); "
971 "if (%s->%s != NULL) "
972 "g_object_unref (G_OBJECT (%s->%s)); "
978 g_assert_not_reached();
981 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
986 type = (Type *)node_copy ((Node *)var->vtype);
988 node = node_new (ARGUMENT_NODE,
989 "gtktype:steal", $<id>3,
991 "flags:steal", $<list>2,
992 "name:steal", $<id>4,
994 "get_line", $<line>1,
996 "set_line", $<line>1,
1000 if ($<id>5 != NULL) {
1001 Argument *arg = (Argument *)node;
1002 export_accessors (arg->name,
1003 arg->get != NULL, arg->get_line,
1004 arg->set != NULL, arg->set_line,
1011 class_nodes = g_list_append (class_nodes, node);
1015 export: '(' TOKEN ')' {
1016 if (strcmp ($<id>2, "export")!=0) {
1018 yyerror (_("parse error"));
1028 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1030 node_set ((Node *)property,
1031 "line_no", $<line>1,
1032 "gtktype:steal", debool ($<id>2),
1033 "name:steal", $<id>3,
1035 if (strcmp ($<id>5, "get") == 0 &&
1036 strcmp ($<id>8, "set") == 0) {
1037 node_set ((Node *)property,
1038 "get:steal", ($<cbuf>7)->str,
1039 "get_line", $<line>6,
1040 "set:steal", ($<cbuf>10)->str,
1041 "set_line", $<line>9,
1043 g_string_free ($<cbuf>7, FALSE);
1044 g_string_free ($<cbuf>10, FALSE);
1047 } else if (strcmp ($<id>5, "set") == 0 &&
1048 strcmp ($<id>8, "get") == 0) {
1049 node_set ((Node *)property,
1050 "get:steal", ($<cbuf>10)->str,
1051 "get_line", $<line>9,
1052 "set:steal", ($<cbuf>7)->str,
1053 "set_line", $<line>6,
1055 g_string_free ($<cbuf>7, FALSE);
1056 g_string_free ($<cbuf>10, FALSE);
1060 g_string_free ($<cbuf>7, TRUE);
1061 g_string_free ($<cbuf>10, TRUE);
1064 node_free ((Node *)property);
1066 yyerror (_("parse error"));
1069 property_link_and_export ((Node *)property);
1070 if (property != NULL) {
1071 class_nodes = g_list_append (class_nodes,
1076 | PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE ';' {
1078 node_set ((Node *)property,
1079 "line_no", $<line>1,
1080 "gtktype:steal", debool ($<id>2),
1081 "name:steal", $<id>3,
1083 if (strcmp ($<id>5, "get") == 0) {
1084 node_set ((Node *)property,
1085 "get:steal", ($<cbuf>7)->str,
1086 "get_line", $<line>6,
1088 g_string_free ($<cbuf>7, FALSE);
1090 } else if (strcmp ($<id>5, "set") == 0) {
1091 node_set ((Node *)property,
1092 "set:steal", ($<cbuf>7)->str,
1093 "set_line", $<line>6,
1095 g_string_free ($<cbuf>7, FALSE);
1098 g_string_free ($<cbuf>7, TRUE);
1100 node_free ((Node *)property);
1102 yyerror (_("parse error"));
1105 property_link_and_export ((Node *)property);
1106 if (property != NULL) {
1107 class_nodes = g_list_append (class_nodes,
1112 | PROPERTY TOKEN TOKEN param_spec ';' {
1114 node_set ((Node *)property,
1115 "line_no", $<line>1,
1116 "gtktype:steal", debool ($<id>2),
1117 "name:steal", $<id>3,
1119 property_link_and_export ((Node *)property);
1120 if (property != NULL) {
1121 class_nodes = g_list_append (class_nodes,
1128 param_spec: '(' param_spec_list ')' { ; }
1132 param_spec_list: param_spec_list ',' param_spec_value { ; }
1133 | param_spec_value { ; }
1136 string: STRING { $<id>$ = $<id>1; }
1137 | TOKEN '(' STRING ')' {
1138 if (strcmp ($<id>1, "_") != 0) {
1140 yyerror(_("parse error"));
1144 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1149 anyval: numtok { $<id>$ = $<id>1; }
1150 | string { $<id>$ = $<id>1; }
1153 param_spec_value: NICK '=' string {
1155 node_set ((Node *)property,
1156 "nick:steal", $<id>3,
1159 | BLURB '=' string {
1161 node_set ((Node *)property,
1162 "blurb:steal", $<id>3,
1165 | MAXIMUM '=' numtok {
1167 node_set ((Node *)property,
1168 "maximum:steal", $<id>3,
1171 | MINIMUM '=' numtok {
1173 node_set ((Node *)property,
1174 "minimum:steal", $<id>3,
1177 | DEFAULT_VALUE '=' anyval {
1179 node_set ((Node *)property,
1180 "default_value:steal", $<id>3,
1183 | FLAGS '=' flaglist {
1185 node_set ((Node *)property,
1186 "flags:steal", $<list>3,
1190 Type *type = pop_type ();
1192 node_set ((Node *)property,
1193 "ptype:steal", type,
1196 | FLAGS_TYPE '=' TOKEN {
1198 node_set ((Node *)property,
1199 "extra_gtktype:steal", $<id>3,
1202 | ENUM_TYPE '=' TOKEN {
1204 node_set ((Node *)property,
1205 "extra_gtktype:steal", $<id>3,
1208 | PARAM_TYPE '=' TOKEN {
1210 node_set ((Node *)property,
1211 "extra_gtktype:steal", $<id>3,
1214 | BOXED_TYPE '=' TOKEN {
1216 node_set ((Node *)property,
1217 "extra_gtktype:steal", $<id>3,
1220 | OBJECT_TYPE '=' TOKEN {
1222 node_set ((Node *)property,
1223 "extra_gtktype:steal", $<id>3,
1228 if (strcmp ($<id>1, "link") == 0) {
1230 node_set ((Node *)property,
1233 } else if (strcmp ($<id>1, "export") == 0) {
1235 node_set ((Node *)property,
1240 yyerror(_("parse error"));
1246 argtype: TOKEN '(' TOKEN type ')' {
1247 if(strcmp($<id>3,"type")!=0) {
1250 yyerror(_("parse error"));
1253 $<id>$ = debool ($<id>1);
1256 $<id>$ = debool ($<id>1);
1257 typestack = g_list_prepend(typestack,NULL);
1261 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1262 | { $<list>$ = NULL; }
1265 flaglist: TOKEN '|' flaglist {
1266 $<list>$ = g_list_append($<list>3,$<id>1);
1269 $<list>$ = g_list_append(NULL,$<id>1);
1274 type: specifier_list pointer {
1275 Node *node = node_new (TYPE_NODE,
1276 "name:steal", $<id>1,
1277 "pointer:steal", $<id>2,
1279 typestack = g_list_prepend(typestack,node);
1282 Node *node = node_new (TYPE_NODE,
1283 "name:steal", $<id>1,
1285 typestack = g_list_prepend(typestack,node);
1289 /* The special cases are neccessary to avoid conflicts */
1290 specifier_list: spec_list {
1297 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1301 $<id>$ = g_strconcat($<id>1, " const", NULL);
1304 | strunionenum TOKEN {
1305 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1308 | CONST strunionenum TOKEN {
1309 $<id>$ = g_strconcat("const ", $<id>2, " ",
1313 | strunionenum TOKEN CONST {
1314 $<id>$ = g_strconcat($<id>1, " ",
1315 $<id>2, " const", NULL);
1320 /* The special const cases take care of conflicts ! */
1321 spec_list: specifier spec_list {
1322 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1325 | TYPETOKEN spec_list {
1326 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1331 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1338 $<id>$ = g_strconcat($<id>1, " const", NULL);
1342 $<id>$ = g_strdup($<id>1);
1345 $<id>$ = g_strconcat($<id>1, " const", NULL);
1349 specifier: VOID { $<id>$ = "void"; }
1350 | CHAR { $<id>$ = "char"; }
1351 | SHORT { $<id>$ = "short"; }
1352 | INT { $<id>$ = "int"; }
1353 | LONG { $<id>$ = "long"; }
1354 | FLOAT { $<id>$ = "float"; }
1355 | DOUBLE { $<id>$ = "double"; }
1356 | SIGNED { $<id>$ = "signed"; }
1357 | UNSIGNED { $<id>$ = "unsigned"; }
1360 strunionenum: STRUCT { $<id>$ = "struct"; }
1361 | UNION { $<id>$ = "union"; }
1362 | ENUM { $<id>$ = "enum"; }
1365 pointer: '*' { $<id>$ = g_strdup("*"); }
1366 | '*' CONST { $<id>$ = g_strdup("* const"); }
1368 $<id>$ = g_strconcat("*", $<id>2, NULL);
1371 | '*' CONST pointer {
1372 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1377 /* this never sets the_scope */
1378 simplesigtype: TOKEN sigtype {
1379 if(strcmp($<id>1, "first")==0)
1380 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1381 else if(strcmp($<id>1, "last")==0)
1382 $<sigtype>$ = SIGNAL_LAST_METHOD;
1384 yyerror(_("signal must be 'first' or 'last'"));
1391 $<sigtype>$ = SIGNAL_LAST_METHOD;
1395 /* this always sets the_scope */
1396 fullsigtype: scope TOKEN sigtype {
1397 if(strcmp($<id>2,"first")==0)
1398 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1399 else if(strcmp($<id>2,"last")==0)
1400 $<sigtype>$ = SIGNAL_LAST_METHOD;
1402 yyerror(_("signal must be 'first' or 'last'"));
1408 | TOKEN scope sigtype {
1409 if(strcmp($<id>1,"first")==0)
1410 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1411 else if(strcmp($<id>1,"last")==0)
1412 $<sigtype>$ = SIGNAL_LAST_METHOD;
1414 yyerror(_("signal must be 'first' or 'last'"));
1421 $<sigtype>$ = SIGNAL_LAST_METHOD;
1424 /* the_scope was default thus public */
1425 the_scope = PUBLIC_SCOPE;
1429 sigtype: TOKEN '(' tokenlist ')' {
1430 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1434 tokenlist: tokenlist ',' TOKEN {
1435 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1438 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1442 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1443 | ';' { $<cbuf>$ = NULL; }
1446 /*here CCODE will include the ending '}' */
1447 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1449 yyerror(_("signal without 'self' as "
1450 "first parameter"));
1451 free_all_global_state();
1454 if(the_scope == CLASS_SCOPE) {
1455 yyerror(_("a method cannot be of class scope"));
1456 free_all_global_state();
1459 push_function(the_scope, $<sigtype>3,NULL,
1460 $<id>5, $<cbuf>10,$<line>1,
1461 ccode_line, vararg, $<list>2);
1463 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1465 yyerror(_("signal without 'self' as "
1466 "first parameter"));
1467 free_all_global_state();
1470 if(the_scope == CLASS_SCOPE) {
1471 yyerror(_("a method cannot be of class scope"));
1472 free_all_global_state();
1475 push_function(the_scope, $<sigtype>4, NULL,
1476 $<id>6, $<cbuf>11, $<line>2,
1477 ccode_line, vararg, $<list>3);
1479 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1481 yyerror(_("virtual method without 'self' as "
1482 "first parameter"));
1483 free_all_global_state();
1486 if(the_scope == CLASS_SCOPE) {
1487 yyerror(_("a method cannot be of class scope"));
1488 free_all_global_state();
1491 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1493 ccode_line, vararg, NULL);
1495 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1497 yyerror(_("virtual method without 'self' as "
1498 "first parameter"));
1499 free_all_global_state();
1502 if(the_scope == CLASS_SCOPE) {
1503 yyerror(_("a method cannot be of class scope"));
1504 free_all_global_state();
1507 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1509 ccode_line, vararg, NULL);
1511 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1513 yyerror(_("virtual method without 'self' as "
1514 "first parameter"));
1515 free_all_global_state();
1518 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1519 $<id>3, $<cbuf>8, $<line>1,
1520 ccode_line, vararg, NULL);
1522 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1523 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1525 $<line>1, ccode_line,
1528 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1529 if(the_scope == CLASS_SCOPE) {
1530 yyerror(_("a method cannot be of class scope"));
1531 free_all_global_state();
1534 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1535 $<cbuf>8, $<line>1, ccode_line,
1538 | TOKEN '(' TOKEN ')' codenocode {
1539 if(strcmp($<id>1, "init")==0) {
1540 push_init_arg($<id>3,FALSE);
1541 push_function(NO_SCOPE, INIT_METHOD, NULL,
1542 $<id>1, $<cbuf>5, $<line>2,
1543 ccode_line, FALSE, NULL);
1544 } else if(strcmp($<id>1, "class_init")==0) {
1545 push_init_arg($<id>3,TRUE);
1546 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1547 $<id>1, $<cbuf>5, $<line>2,
1548 ccode_line, FALSE, NULL);
1552 g_string_free($<cbuf>5,TRUE);
1553 yyerror(_("parse error "
1554 "(untyped blocks must be init or "
1561 returnvals: TOKEN retcode {
1562 g_free(onerror); onerror = NULL;
1563 g_free(defreturn); defreturn = NULL;
1564 if(!set_return_value($<id>1, $<id>2)) {
1567 yyerror(_("parse error"));
1572 | TOKEN retcode TOKEN retcode {
1573 g_free(onerror); onerror = NULL;
1574 g_free(defreturn); defreturn = NULL;
1575 if(!set_return_value($<id>1, $<id>2)) {
1576 g_free($<id>1); g_free($<id>2);
1577 g_free($<id>3); g_free($<id>4);
1578 yyerror(_("parse error"));
1581 if(!set_return_value($<id>3, $<id>4)) {
1582 onerror = defreturn = NULL;
1583 g_free($<id>1); g_free($<id>2);
1584 g_free($<id>3); g_free($<id>4);
1585 yyerror(_("parse error"));
1592 g_free(onerror); onerror = NULL;
1593 g_free(defreturn); defreturn = NULL;
1597 retcode: numtok { $<id>$ = $<id>1; }
1599 $<id>$ = ($<cbuf>3)->str;
1600 g_string_free($<cbuf>3, FALSE);
1604 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1608 if(strcmp($<id>1,"self")==0)
1609 push_self($<id>1, FALSE);
1612 yyerror(_("parse error"));
1619 if(strcmp($<id>1,"self")==0)
1620 push_self($<id>1, TRUE);
1623 yyerror(_("parse error"));
1630 if(strcmp($<id>2,"self")==0)
1631 push_self($<id>2, TRUE);
1634 yyerror(_("parse error"));
1638 | TOKEN ',' arglist {
1640 if(strcmp($<id>1,"self")==0)
1641 push_self($<id>1, FALSE);
1644 yyerror(_("parse error"));
1648 | TOKEN CONST ',' arglist {
1650 if(strcmp($<id>1,"self")==0)
1651 push_self($<id>1, TRUE);
1654 yyerror(_("parse error"));
1658 | CONST TOKEN ',' arglist {
1660 if(strcmp($<id>2,"self")==0)
1661 push_self($<id>2, TRUE);
1664 yyerror(_("parse error"));
1668 | arglist { has_self = FALSE; }
1671 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1672 | arglist1 { vararg = FALSE; }
1675 arglist1: arglist1 ',' arg { ; }
1680 push_funcarg($<id>2,NULL);
1682 | type TOKEN ARRAY_DIM {
1683 push_funcarg($<id>2,$<id>3);
1685 | type TOKEN '(' TOKEN checklist ')' {
1686 if(strcmp($<id>4,"check")!=0) {
1687 yyerror(_("parse error"));
1691 push_funcarg($<id>2,NULL);
1693 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1694 if(strcmp($<id>5,"check")!=0) {
1695 yyerror(_("parse error"));
1699 push_funcarg($<id>2,$<id>3);
1703 checklist: checklist check { ; }
1708 if(strcmp($<id>1,"type")==0) {
1709 Node *node = node_new (CHECK_NODE,
1710 "chtype", TYPE_CHECK,
1712 checks = g_list_append(checks,node);
1713 } else if(strcmp($<id>1,"null")==0) {
1714 Node *node = node_new (CHECK_NODE,
1715 "chtype", NULL_CHECK,
1717 checks = g_list_append(checks,node);
1719 yyerror(_("parse error"));
1725 Node *node = node_new (CHECK_NODE,
1727 "number:steal", $<id>2,
1729 checks = g_list_append(checks,node);
1732 Node *node = node_new (CHECK_NODE,
1734 "number:steal", $<id>2,
1736 checks = g_list_append(checks,node);
1739 Node *node = node_new (CHECK_NODE,
1741 "number:steal", $<id>3,
1743 checks = g_list_append(checks,node);
1746 Node *node = node_new (CHECK_NODE,
1748 "number:steal", $<id>3,
1750 checks = g_list_append(checks,node);
1753 Node *node = node_new (CHECK_NODE,
1755 "number:steal", $<id>3,
1757 checks = g_list_append(checks,node);
1760 Node *node = node_new (CHECK_NODE,
1762 "number:steal", $<id>3,
1764 checks = g_list_append(checks,node);
1768 numtok: NUMBER { $<id>$ = $<id>1; }
1770 $<id>$ = g_strconcat("-",$<id>2,NULL);
1773 | SINGLE_CHAR { $<id>$ = $<id>1; }
1774 | TOKEN { $<id>$ = $<id>1; }