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"
34 /* FIXME: add gettext support */
39 static GList *class_nodes = NULL;
42 static GList *enum_vals = NULL;
43 static GList *flag_vals = NULL;
44 static GList *error_vals = NULL;
46 static char *chunk_size = NULL;
47 static char *bonobo_object_class = NULL;
48 static GList *interfaces = NULL;
49 static GList *typestack = NULL;
50 static GList *funcargs = NULL;
51 static GList *checks = NULL;
52 static int has_self = FALSE;
53 static int vararg = FALSE;
54 static Method *last_added_method = NULL;
56 /* destructor and initializer for variables */
57 static gboolean destructor_unref = FALSE;
58 static char *destructor = NULL;
59 static int destructor_line = 0;
60 static gboolean destructor_simple = TRUE;
61 static char *initializer = NULL;
62 static int initializer_line = 0;
64 static char *onerror = NULL;
65 static char *defreturn = NULL;
67 static GList *gtktypes = NULL;
69 static Property *property = NULL;
71 /* this can be a global as we will only do one function at a time
73 static int the_scope = NO_SCOPE;
78 extern int ccode_line;
89 if(strcmp(yytext,"\n")==0) {
90 out=g_strconcat("Error: ",str," before newline",NULL);
91 } else if(yytext[0]=='\0') {
92 out=g_strconcat("Error: ", str, " at end of input", NULL);
94 char *tmp = g_strdup(yytext);
95 while((p=strchr(tmp, '\n')))
98 out=g_strconcat("Error: ", str, " before '", tmp, "'", NULL);
102 fprintf(stderr, "%s:%d: %s\n", filename, line_no, out);
111 Type *type = typestack->data;
112 typestack = g_list_remove(typestack,typestack->data);
117 push_variable (char *name, int scope, int line_no, char *postfix)
120 Type *type = pop_type ();
122 type->postfix = postfix;
124 var = node_new (VARIABLE_NODE,
129 "destructor_unref", destructor_unref,
130 "destructor:steal", destructor,
131 "destructor_line", destructor_line,
132 "destructor_simple", destructor_simple,
133 "initializer:steal", initializer,
134 "initializer_line", initializer_line,
136 class_nodes = g_list_append(class_nodes, var);
140 push_function (int scope, int method, char *oid, char *id,
141 GString *cbuf, int line_no, int ccode_line,
142 gboolean vararg, GList *flags)
148 g_assert(scope != CLASS_SCOPE);
150 if(method == INIT_METHOD || method == CLASS_INIT_METHOD) {
151 type = (Type *)node_new (TYPE_NODE,
158 /* a complicated and ugly test to figure out if we have
159 the wrong number of types for a signal */
160 if((method == SIGNAL_FIRST_METHOD ||
161 method == SIGNAL_LAST_METHOD) &&
162 g_list_length(gtktypes) != g_list_length(funcargs) &&
163 !(g_list_length(funcargs) == 1 &&
164 g_list_length(gtktypes) == 2 &&
165 strcmp(gtktypes->next->data, "NONE")==0)) {
166 error_print(GOB_WARN, line_no,
167 _("The number of GTK arguments and "
168 "function arguments for a signal "
169 "don't seem to match"));
171 if(g_list_length(gtktypes) > 2) {
173 for(li = gtktypes->next; li; li = li->next) {
174 if(strcmp(li->data, "NONE")==0) {
175 error_print(GOB_ERROR, line_no,
176 _("NONE can only appear in an "
177 "argument list by itself"));
183 c_cbuf = p = cbuf->str;
184 while(p && *p && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
191 node = node_new (METHOD_NODE,
196 "gtktypes:steal", gtktypes,
197 "flags:steal", flags,
199 "args:steal", funcargs,
200 "onerror:steal", onerror,
201 "defreturn:steal", defreturn,
202 "cbuf:steal", c_cbuf,
204 "ccode_line", ccode_line,
206 "unique_id", method_unique_id++,
209 last_added_method = (Method *)node;
213 /*only free segment if we haven't passed it
222 class_nodes = g_list_append(class_nodes, node);
226 free_all_global_state(void)
236 g_list_foreach(gtktypes, (GFunc)g_free, NULL);
237 g_list_free(gtktypes);
240 node_list_free (funcargs);
245 push_funcarg(char *name, char *postfix)
248 Type *type = pop_type();
250 type->postfix = postfix;
252 node = node_new (FUNCARG_NODE,
255 "checks:steal", checks,
259 funcargs = g_list_append(funcargs, node);
263 push_init_arg(char *name, int is_class)
270 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
272 tn = g_strdup(((Class *)class)->otype);
274 type = node_new (TYPE_NODE,
278 node = node_new (FUNCARG_NODE,
279 "atype:steal", (Type *)type,
282 funcargs = g_list_prepend(funcargs, node);
286 push_self(char *id, gboolean constant)
291 type = node_new (TYPE_NODE,
292 "name", ((Class *)class)->otype,
293 "pointer", constant ? "const *" : "*",
295 ch = g_list_append (ch, node_new (CHECK_NODE,
296 "chtype", NULL_CHECK,
298 ch = g_list_append (ch, node_new (CHECK_NODE,
299 "chtype", TYPE_CHECK,
301 node = node_new (FUNCARG_NODE,
302 "atype:steal", (Type *)type,
306 funcargs = g_list_prepend(funcargs, node);
310 find_var_or_die(const char *id, int line)
314 for(li = class_nodes; li != NULL; li = li->next) {
316 Node *node = li->data;
317 if(node->type != VARIABLE_NODE)
320 if(strcmp(var->id, id)==0)
324 error_printf(GOB_ERROR, line, _("Variable %s not defined here"), id);
326 g_assert_not_reached();
331 set_return_value(char *type, char *val)
333 if(strcmp(type, "onerror")==0) {
339 } else if(strcmp(type, "defreturn")==0) {
350 export_accessors (const char *var_name,
362 the_type = (Type *)node_copy ((Node *)type);
364 the_type = get_tree_type (gtktype, TRUE);
366 if (the_type == NULL) {
367 error_print (GOB_ERROR, line_no,
368 _("Cannot determine type of property or argument"));
373 char *get_id = g_strdup_printf ("get_%s", var_name);
374 GString *get_cbuf = g_string_new (NULL);
375 Node *node1 = node_new (TYPE_NODE,
376 "name", the_type->name,
377 "pointer", the_type->pointer,
378 "postfix", the_type->postfix,
380 Node *node3 = node_new (TYPE_NODE,
381 "name", class->class.otype,
385 g_string_sprintf (get_cbuf,
387 "g_object_get (G_OBJECT (self), \"%s\", "
391 the_type->pointer ? the_type->pointer : "",
394 typestack = g_list_prepend (typestack, node1);
395 typestack = g_list_prepend (typestack, node3);
397 push_funcarg ("self", FALSE);
399 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
400 get_id, get_cbuf, get_lineno,
401 lineno, FALSE, NULL);
405 char *set_id = g_strdup_printf ("set_%s", var_name);
406 GString *set_cbuf = g_string_new (NULL);
407 Node *node1 = node_new (TYPE_NODE,
408 "name", the_type->name,
409 "pointer", the_type->pointer,
410 "postfix", the_type->postfix,
412 Node *node2 = node_new (TYPE_NODE,
415 Node *node3 = node_new (TYPE_NODE,
416 "name", class->class.otype,
420 g_string_sprintf (set_cbuf,
421 "\tg_object_set (G_OBJECT (self), "
422 "\"%s\", val, NULL);\n",
425 typestack = g_list_prepend (typestack, node2);
426 typestack = g_list_prepend (typestack, node1);
427 typestack = g_list_prepend (typestack, node3);
429 push_funcarg ("self", FALSE);
430 push_funcarg ("val", FALSE);
432 typestack = g_list_prepend (typestack, node2);
433 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
434 set_id, set_cbuf, set_lineno,
435 lineno, FALSE, NULL);
438 node_free ((Node *)the_type);
442 property_link_and_export (Node *node)
444 Property *prop = (Property *)node;
448 char *get = NULL, *set = NULL;
451 if (prop->set != NULL ||
453 error_print (GOB_ERROR, prop->line_no,
454 _("Property linking requested, but "
455 "getters and setters exist"));
458 var = find_var_or_die (prop->name, prop->line_no);
459 if(var->scope == PRIVATE_SCOPE) {
460 root = "self->_priv";
461 } else if (var->scope == CLASS_SCOPE) {
462 root = "SELF_GET_CLASS(self)";
464 error_print (GOB_ERROR, prop->line_no,
465 _("Self aliases needed when autolinking to a classwide member"));
470 if (strcmp (prop->gtktype, "STRING") == 0) {
471 set = g_strdup_printf("{ char *old = %s->%s; "
472 "%s->%s = g_value_dup_string (VAL); g_free (old); }",
475 get = g_strdup_printf("g_value_set_string (VAL, %s->%s);",
477 } else if (strcmp (prop->gtktype, "OBJECT") == 0) {
478 set = g_strdup_printf("{ GtkObject *___old = (GtkObject *)%s->%s; "
479 "GtkObject *___new = (GtkObject *)gtk_value_get_object (VAL); "
480 "if (___new != NULL) { "
481 "gtk_object_ref (GTK_OBJECT (___new)); "
482 "%s->%s = GTK_OBJECT (___new); "
486 "if (___old != NULL) { "
487 "gtk_object_unref (GTK_OBJECT (___old)); "
493 get = g_strdup_printf("g_value_set_object (VAL, %s->%s);",
495 } else if (strcmp (prop->gtktype, "BOXED") == 0) {
496 if (prop->extra_gtktype == NULL) {
497 error_print (GOB_ERROR, prop->line_no,
498 _("Property linking requested for BOXED, but "
499 "boxed_type not set"));
501 set = g_strdup_printf("{ gpointer ___old = (gpointer)%s->%s; "
502 "gpointer ___new = (gpointer)gtk_value_get_boxed (VAL); "
503 "if (___new != ___old) { "
504 "if (___old != NULL) g_boxed_free (%s, ___old); "
505 "if (___new != NULL) %s->%s = g_boxed_copy (%s, ___new); "
506 "else %s->%s = NULL;"
514 get = g_strdup_printf("g_value_set_object (VAL, %s->%s);",
519 set_func = g_strdup_printf ("g_value_set_%s", prop->gtktype);
520 g_strdown (set_func);
521 get_func = g_strdup_printf ("g_value_get_%s", prop->gtktype);
522 g_strdown (get_func);
524 set = g_strdup_printf("%s->%s = %s (VAL);",
527 get = g_strdup_printf("%s (VAL, %s->%s);",
537 "get_line", prop->line_no,
539 "set_line", prop->line_no,
544 export_accessors (prop->name,
545 prop->get != NULL, prop->get_line,
546 prop->set != NULL, prop->set_line,
557 if (strcmp (s, "BOOL") == 0) {
558 error_print (GOB_WARN, line_no,
559 _("BOOL type is deprecated, please use BOOLEAN"));
561 return g_strdup ("BOOLEAN");
568 ensure_property (void)
570 if (property == NULL)
571 property = (Property *)node_new (PROPERTY_NODE, NULL);
585 %token CONST VOID STRUCT UNION ENUM THREEDOTS
586 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
588 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
589 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
590 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
591 %token <line> VIRTUAL SIGNAL OVERRIDE
592 %token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
593 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
597 prog: ccodes class ccodes { ; }
604 Node *node = node_new (CCODE_NODE,
606 "cbuf:steal", ($<cbuf>1)->str,
607 "line_no", ccode_line,
609 nodes = g_list_append(nodes,node);
610 g_string_free($<cbuf>1,FALSE);
613 Node *node = node_new (CCODE_NODE,
615 "cbuf:steal", ($<cbuf>1)->str,
616 "line_no", ccode_line,
618 nodes = g_list_append(nodes,node);
619 g_string_free($<cbuf>1,FALSE);
622 Node *node = node_new (CCODE_NODE,
624 "cbuf:steal", ($<cbuf>1)->str,
625 "line_no", ccode_line,
627 nodes = g_list_append(nodes,node);
628 g_string_free($<cbuf>1,FALSE);
631 Node *node = node_new (CCODE_NODE,
633 "cbuf:steal", ($<cbuf>1)->str,
634 "line_no", ccode_line,
636 nodes = g_list_append(nodes,node);
637 g_string_free($<cbuf>1,FALSE);
640 Node *node = node_new (CCODE_NODE,
642 "cbuf:steal", ($<cbuf>1)->str,
643 "line_no", ccode_line,
645 nodes = g_list_append(nodes,node);
646 g_string_free($<cbuf>1,FALSE);
649 Node *node = node_new (CCODE_NODE,
651 "cbuf:steal", ($<cbuf>1)->str,
652 "line_no", ccode_line,
654 nodes = g_list_append(nodes,node);
655 g_string_free($<cbuf>1,FALSE);
659 ccodes: ccodes ccode { ; }
660 | ccodes enumcode { ; }
661 | ccodes flagcode { ; }
662 | ccodes errorcode { ; }
669 class: classdec '{' classcode '}' {
670 ((Class *)class)->nodes = class_nodes;
672 nodes = g_list_append(nodes,class);
675 ((Class *)class)->nodes = NULL;
677 nodes = g_list_append(nodes,class);
681 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
682 class = node_new (CLASS_NODE,
683 "otype:steal", $<id>2,
684 "ptype:steal", $<id>4,
685 "bonobo_object_class:steal", bonobo_object_class,
686 "interfaces:steal", interfaces,
687 "chunk_size:steal", chunk_size,
689 bonobo_object_class = NULL;
696 | '(' TOKEN TOKEN ')' classflags {
697 if(strcmp($<id>2,"chunks") == 0) {
699 chunk_size = g_strdup($<id>3);
700 } else if(strcmp($<id>2,"BonoboObject") == 0) {
701 g_free (bonobo_object_class);
702 bonobo_object_class = g_strdup($<id>3);
704 yyerror(_("parse error"));
708 | '(' TOKEN TYPETOKEN ')' classflags {
709 if (strcmp ($<id>2, "interface") == 0) {
710 interfaces = g_list_append (interfaces,
713 yyerror(_("parse error"));
717 | '(' TOKEN NUMBER ')' classflags {
718 if(strcmp($<id>2,"chunks") == 0) {
720 if(atoi($<id>3) != 0)
721 chunk_size = g_strdup($<id>3);
725 yyerror(_("parse error"));
731 classcode: classcode thing { ; }
737 if (strcmp ($<id>1, "BonoboObject") != 0) {
739 yyerror (_("parse error"));
743 last_added_method->bonobo_object_func = TRUE;
745 | TOKEN TYPETOKEN method {
746 if (strcmp ($<id>1, "interface") != 0) {
749 yyerror (_("parse error"));
753 node_set ((Node *)last_added_method,
754 "interface:steal", $<id>2,
763 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
764 | PRIVATE { the_scope = PRIVATE_SCOPE; }
765 | PROTECTED { the_scope = PROTECTED_SCOPE; }
766 | CLASSWIDE { the_scope = CLASS_SCOPE; }
769 destructor: TOKEN TOKEN {
770 if (strcmp ($<id>1, "destroywith") == 0) {
772 destructor_unref = FALSE;
774 destructor_line = line_no;
775 destructor_simple = TRUE;
776 } else if (strcmp ($<id>1, "unrefwith") == 0) {
778 destructor_unref = TRUE;
780 destructor_line = line_no;
781 destructor_simple = TRUE;
785 yyerror (_("parse error"));
790 if (strcmp ($<id>1, "destroy") == 0) {
792 destructor_unref = FALSE;
793 destructor = ($<cbuf>3)->str;
794 g_string_free($<cbuf>3, FALSE);
795 destructor_line = ccode_line;
796 destructor_simple = FALSE;
797 } else if (strcmp ($<id>1, "unref") == 0) {
799 destructor_unref = TRUE;
800 destructor = ($<cbuf>3)->str;
801 g_string_free ($<cbuf>3, FALSE);
802 destructor_line = ccode_line;
803 destructor_simple = FALSE;
806 g_string_free ($<cbuf>3, TRUE);
807 yyerror (_("parse error"));
813 initializer: '=' numtok {
814 initializer = $<id>2;
815 initializer_line = ccode_line;
818 initializer = ($<cbuf>3)->str;
819 initializer_line = ccode_line;
820 g_string_free($<cbuf>3, FALSE);
825 varoptions: destructor initializer { ; }
826 | initializer destructor { ; }
827 | initializer { destructor = NULL; }
828 | destructor { initializer = NULL; }
835 variable: scope type TOKEN varoptions ';' {
836 push_variable($<id>3, the_scope,$<line>1, NULL);
838 | scope type TOKEN ARRAY_DIM varoptions ';' {
839 push_variable($<id>3, the_scope, $<line>1, $<id>4);
843 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
845 if(strcmp($<id>6,"get")==0 &&
846 strcmp($<id>9,"set")==0) {
847 Type *type = pop_type();
850 node = node_new (ARGUMENT_NODE,
851 "gtktype:steal", $<id>3,
853 "flags:steal", $<list>2,
854 "name:steal", $<id>4,
855 "get:steal", ($<cbuf>8)->str,
856 "get_line", $<line>7,
857 "set:steal", ($<cbuf>11)->str,
858 "set_line", $<line>10,
862 class_nodes = g_list_append(class_nodes,node);
864 g_string_free ($<cbuf>8, FALSE);
865 g_string_free ($<cbuf>11, FALSE);
867 } else if(strcmp($<id>6,"set")==0 &&
868 strcmp($<id>9,"get")==0) {
869 Type *type = pop_type();
872 node = node_new (ARGUMENT_NODE,
873 "gtktype:steal", $<id>3,
875 "flags:steal", $<list>2,
876 "name:steal", $<id>4,
877 "get:steal", ($<cbuf>11)->str,
878 "get_line", $<line>10,
879 "set:steal", ($<cbuf>8)->str,
880 "set_line", $<line>7,
883 g_string_free ($<cbuf>11, FALSE);
884 g_string_free ($<cbuf>8, FALSE);
885 class_nodes = g_list_append(class_nodes,node);
891 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
892 g_list_free ($<list>2);
893 g_string_free ($<cbuf>11, TRUE);
894 g_string_free ($<cbuf>8, TRUE);
895 yyerror (_("parse error"));
899 if ($<id>5 != NULL) {
900 Argument *arg = (Argument *)node;
901 export_accessors (arg->name,
902 arg->get != NULL, arg->get_line,
903 arg->set != NULL, arg->set_line,
911 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
913 if(strcmp($<id>6, "get") == 0) {
914 Type *type = pop_type();
916 node = node_new (ARGUMENT_NODE,
917 "gtktype:steal", $<id>3,
919 "flags:steal", $<list>2,
920 "name:steal", $<id>4,
921 "get:steal", ($<cbuf>8)->str,
922 "get_line", $<line>7,
926 g_string_free ($<cbuf>8, FALSE);
927 class_nodes = g_list_append(class_nodes, node);
928 } else if(strcmp($<id>6, "set") == 0) {
929 Type *type = pop_type();
931 node = node_new (ARGUMENT_NODE,
932 "gtktype:steal", $<id>3,
934 "flags:steal", $<list>2,
935 "name:steal", $<id>4,
936 "set:steal", ($<cbuf>8)->str,
937 "set_line", $<line>7,
941 g_string_free ($<cbuf>8, FALSE);
942 class_nodes = g_list_append (class_nodes, node);
947 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
948 g_list_free ($<list>2);
949 g_string_free ($<cbuf>8, TRUE);
950 yyerror(_("parse error"));
954 if ($<id>5 != NULL) {
955 Argument *arg = (Argument *)node;
956 export_accessors (arg->name,
957 arg->get != NULL, arg->get_line,
958 arg->set != NULL, arg->set_line,
965 | ARGUMENT flags argtype TOKEN export TOKEN {
967 char *get, *set = NULL;
972 if(strcmp($<id>6, "link")!=0 &&
973 strcmp($<id>6, "stringlink")!=0 &&
974 strcmp($<id>6, "objectlink")!=0) {
978 g_list_foreach($<list>2,(GFunc)g_free,NULL);
979 g_list_free($<list>2);
980 yyerror(_("parse error"));
986 var = find_var_or_die($<id>4, $<line>1);
987 if(var->scope == PRIVATE_SCOPE)
988 root = "self->_priv";
989 else if(var->scope == CLASS_SCOPE) {
990 root = "SELF_GET_CLASS(self)";
992 error_print(GOB_ERROR, $<line>1,
993 _("Self aliases needed when autolinking to a classwide member"));
997 if(strcmp($<id>6, "link")==0) {
998 set = g_strdup_printf("%s->%s = ARG;",
1000 } else if(strcmp($<id>6, "stringlink")==0) {
1001 set = g_strdup_printf("g_free (%s->%s); "
1002 "%s->%s = g_strdup (ARG);",
1005 } else if(strcmp($<id>6, "objectlink")==0) {
1006 set = g_strdup_printf(
1008 "g_object_ref (G_OBJECT (ARG)); "
1009 "if (%s->%s != NULL) "
1010 "g_object_unref (G_OBJECT (%s->%s)); "
1016 g_assert_not_reached();
1019 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
1024 type = (Type *)node_copy ((Node *)var->vtype);
1026 node = node_new (ARGUMENT_NODE,
1027 "gtktype:steal", $<id>3,
1028 "atype:steal", type,
1029 "flags:steal", $<list>2,
1030 "name:steal", $<id>4,
1032 "get_line", $<line>1,
1034 "set_line", $<line>1,
1035 "line_no", $<line>1,
1038 if ($<id>5 != NULL) {
1039 Argument *arg = (Argument *)node;
1040 export_accessors (arg->name,
1041 arg->get != NULL, arg->get_line,
1042 arg->set != NULL, arg->set_line,
1049 class_nodes = g_list_append (class_nodes, node);
1053 export: '(' TOKEN ')' {
1054 if (strcmp ($<id>2, "export")!=0) {
1056 yyerror (_("parse error"));
1066 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1068 node_set ((Node *)property,
1069 "line_no", $<line>1,
1070 "gtktype:steal", debool ($<id>2),
1071 "name:steal", $<id>3,
1073 if (strcmp ($<id>5, "get") == 0 &&
1074 strcmp ($<id>8, "set") == 0) {
1075 node_set ((Node *)property,
1076 "get:steal", ($<cbuf>7)->str,
1077 "get_line", $<line>6,
1078 "set:steal", ($<cbuf>10)->str,
1079 "set_line", $<line>9,
1081 g_string_free ($<cbuf>7, FALSE);
1082 g_string_free ($<cbuf>10, FALSE);
1085 } else if (strcmp ($<id>5, "set") == 0 &&
1086 strcmp ($<id>8, "get") == 0) {
1087 node_set ((Node *)property,
1088 "get:steal", ($<cbuf>10)->str,
1089 "get_line", $<line>9,
1090 "set:steal", ($<cbuf>7)->str,
1091 "set_line", $<line>6,
1093 g_string_free ($<cbuf>7, FALSE);
1094 g_string_free ($<cbuf>10, FALSE);
1098 g_string_free ($<cbuf>7, TRUE);
1099 g_string_free ($<cbuf>10, TRUE);
1102 node_free ((Node *)property);
1104 yyerror (_("parse error"));
1107 property_link_and_export ((Node *)property);
1108 if (property != NULL) {
1109 class_nodes = g_list_append (class_nodes,
1114 | PROPERTY TOKEN TOKEN param_spec 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 node_set ((Node *)property,
1123 "get:steal", ($<cbuf>7)->str,
1124 "get_line", $<line>6,
1126 g_string_free ($<cbuf>7, FALSE);
1128 } else if (strcmp ($<id>5, "set") == 0) {
1129 node_set ((Node *)property,
1130 "set:steal", ($<cbuf>7)->str,
1131 "set_line", $<line>6,
1133 g_string_free ($<cbuf>7, FALSE);
1136 g_string_free ($<cbuf>7, TRUE);
1138 node_free ((Node *)property);
1140 yyerror (_("parse error"));
1143 property_link_and_export ((Node *)property);
1144 if (property != NULL) {
1145 class_nodes = g_list_append (class_nodes,
1150 | PROPERTY TOKEN TOKEN param_spec ';' {
1152 node_set ((Node *)property,
1153 "line_no", $<line>1,
1154 "gtktype:steal", debool ($<id>2),
1155 "name:steal", $<id>3,
1157 property_link_and_export ((Node *)property);
1158 if (property != NULL) {
1159 class_nodes = g_list_append (class_nodes,
1166 param_spec: '(' param_spec_list ')' { ; }
1170 param_spec_list: param_spec_list ',' param_spec_value { ; }
1171 | param_spec_value { ; }
1174 string: STRING { $<id>$ = $<id>1; }
1175 | TOKEN '(' STRING ')' {
1176 if (strcmp ($<id>1, "_") != 0) {
1178 yyerror(_("parse error"));
1182 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1187 anyval: numtok { $<id>$ = $<id>1; }
1188 | string { $<id>$ = $<id>1; }
1191 param_spec_value: NICK '=' string {
1193 node_set ((Node *)property,
1194 "nick:steal", $<id>3,
1197 | BLURB '=' string {
1199 node_set ((Node *)property,
1200 "blurb:steal", $<id>3,
1203 | MAXIMUM '=' numtok {
1205 node_set ((Node *)property,
1206 "maximum:steal", $<id>3,
1209 | MINIMUM '=' numtok {
1211 node_set ((Node *)property,
1212 "minimum:steal", $<id>3,
1215 | DEFAULT_VALUE '=' anyval {
1217 node_set ((Node *)property,
1218 "default_value:steal", $<id>3,
1221 | FLAGS '=' flaglist {
1223 node_set ((Node *)property,
1224 "flags:steal", $<list>3,
1228 Type *type = pop_type ();
1230 node_set ((Node *)property,
1231 "ptype:steal", type,
1234 | FLAGS_TYPE '=' TOKEN {
1236 node_set ((Node *)property,
1237 "extra_gtktype:steal", $<id>3,
1240 | ENUM_TYPE '=' TOKEN {
1242 node_set ((Node *)property,
1243 "extra_gtktype:steal", $<id>3,
1246 | PARAM_TYPE '=' TOKEN {
1248 node_set ((Node *)property,
1249 "extra_gtktype:steal", $<id>3,
1252 | BOXED_TYPE '=' TOKEN {
1254 node_set ((Node *)property,
1255 "extra_gtktype:steal", $<id>3,
1258 | OBJECT_TYPE '=' TOKEN {
1260 node_set ((Node *)property,
1261 "extra_gtktype:steal", $<id>3,
1266 if (strcmp ($<id>1, "link") == 0) {
1268 node_set ((Node *)property,
1271 } else if (strcmp ($<id>1, "export") == 0) {
1273 node_set ((Node *)property,
1278 yyerror(_("parse error"));
1284 argtype: TOKEN '(' TOKEN type ')' {
1285 if(strcmp($<id>3,"type")!=0) {
1288 yyerror(_("parse error"));
1291 $<id>$ = debool ($<id>1);
1294 $<id>$ = debool ($<id>1);
1295 typestack = g_list_prepend(typestack,NULL);
1299 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1300 | { $<list>$ = NULL; }
1303 flaglist: TOKEN '|' flaglist {
1304 $<list>$ = g_list_append($<list>3,$<id>1);
1307 $<list>$ = g_list_append(NULL,$<id>1);
1312 type: specifier_list pointer {
1313 Node *node = node_new (TYPE_NODE,
1314 "name:steal", $<id>1,
1315 "pointer:steal", $<id>2,
1317 typestack = g_list_prepend(typestack,node);
1320 Node *node = node_new (TYPE_NODE,
1321 "name:steal", $<id>1,
1323 typestack = g_list_prepend(typestack,node);
1327 /* The special cases are neccessary to avoid conflicts */
1328 specifier_list: spec_list {
1335 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1339 $<id>$ = g_strconcat($<id>1, " const", NULL);
1342 | strunionenum TOKEN {
1343 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1346 | CONST strunionenum TOKEN {
1347 $<id>$ = g_strconcat("const ", $<id>2, " ",
1351 | strunionenum TOKEN CONST {
1352 $<id>$ = g_strconcat($<id>1, " ",
1353 $<id>2, " const", NULL);
1358 /* The special const cases take care of conflicts ! */
1359 spec_list: specifier spec_list {
1360 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1363 | TYPETOKEN spec_list {
1364 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1369 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1376 $<id>$ = g_strconcat($<id>1, " const", NULL);
1380 $<id>$ = g_strdup($<id>1);
1383 $<id>$ = g_strconcat($<id>1, " const", NULL);
1387 specifier: VOID { $<id>$ = "void"; }
1388 | CHAR { $<id>$ = "char"; }
1389 | SHORT { $<id>$ = "short"; }
1390 | INT { $<id>$ = "int"; }
1391 | LONG { $<id>$ = "long"; }
1392 | FLOAT { $<id>$ = "float"; }
1393 | DOUBLE { $<id>$ = "double"; }
1394 | SIGNED { $<id>$ = "signed"; }
1395 | UNSIGNED { $<id>$ = "unsigned"; }
1398 strunionenum: STRUCT { $<id>$ = "struct"; }
1399 | UNION { $<id>$ = "union"; }
1400 | ENUM { $<id>$ = "enum"; }
1403 pointer: '*' { $<id>$ = g_strdup("*"); }
1404 | '*' CONST { $<id>$ = g_strdup("* const"); }
1406 $<id>$ = g_strconcat("*", $<id>2, NULL);
1409 | '*' CONST pointer {
1410 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1415 /* this never sets the_scope */
1416 simplesigtype: TOKEN sigtype {
1417 if(strcmp($<id>1, "first")==0)
1418 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1419 else if(strcmp($<id>1, "last")==0)
1420 $<sigtype>$ = SIGNAL_LAST_METHOD;
1422 yyerror(_("signal must be 'first' or 'last'"));
1429 $<sigtype>$ = SIGNAL_LAST_METHOD;
1433 /* this always sets the_scope */
1434 fullsigtype: scope TOKEN sigtype {
1435 if(strcmp($<id>2,"first")==0)
1436 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1437 else if(strcmp($<id>2,"last")==0)
1438 $<sigtype>$ = SIGNAL_LAST_METHOD;
1440 yyerror(_("signal must be 'first' or 'last'"));
1446 | TOKEN scope sigtype {
1447 if(strcmp($<id>1,"first")==0)
1448 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1449 else if(strcmp($<id>1,"last")==0)
1450 $<sigtype>$ = SIGNAL_LAST_METHOD;
1452 yyerror(_("signal must be 'first' or 'last'"));
1459 $<sigtype>$ = SIGNAL_LAST_METHOD;
1462 /* the_scope was default thus public */
1463 the_scope = PUBLIC_SCOPE;
1467 sigtype: TOKEN '(' tokenlist ')' {
1468 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1472 tokenlist: tokenlist ',' TOKEN {
1473 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1476 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1480 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1481 | ';' { $<cbuf>$ = NULL; }
1484 /*here CCODE will include the ending '}' */
1485 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1487 yyerror(_("signal without 'self' as "
1488 "first parameter"));
1489 free_all_global_state();
1492 if(the_scope == CLASS_SCOPE) {
1493 yyerror(_("a method cannot be of class scope"));
1494 free_all_global_state();
1497 push_function(the_scope, $<sigtype>3,NULL,
1498 $<id>5, $<cbuf>10,$<line>1,
1499 ccode_line, vararg, $<list>2);
1501 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1503 yyerror(_("signal without 'self' as "
1504 "first parameter"));
1505 free_all_global_state();
1508 if(the_scope == CLASS_SCOPE) {
1509 yyerror(_("a method cannot be of class scope"));
1510 free_all_global_state();
1513 push_function(the_scope, $<sigtype>4, NULL,
1514 $<id>6, $<cbuf>11, $<line>2,
1515 ccode_line, vararg, $<list>3);
1517 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1519 yyerror(_("virtual method without 'self' as "
1520 "first parameter"));
1521 free_all_global_state();
1524 if(the_scope == CLASS_SCOPE) {
1525 yyerror(_("a method cannot be of class scope"));
1526 free_all_global_state();
1529 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1531 ccode_line, vararg, NULL);
1533 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1535 yyerror(_("virtual method without 'self' as "
1536 "first parameter"));
1537 free_all_global_state();
1540 if(the_scope == CLASS_SCOPE) {
1541 yyerror(_("a method cannot be of class scope"));
1542 free_all_global_state();
1545 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1547 ccode_line, vararg, NULL);
1549 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1551 yyerror(_("virtual method without 'self' as "
1552 "first parameter"));
1553 free_all_global_state();
1556 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1557 $<id>3, $<cbuf>8, $<line>1,
1558 ccode_line, vararg, NULL);
1560 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1561 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1563 $<line>1, ccode_line,
1566 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1567 if(the_scope == CLASS_SCOPE) {
1568 yyerror(_("a method cannot be of class scope"));
1569 free_all_global_state();
1572 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1573 $<cbuf>8, $<line>1, ccode_line,
1576 | TOKEN '(' TOKEN ')' codenocode {
1577 if(strcmp($<id>1, "init")==0) {
1578 push_init_arg($<id>3,FALSE);
1579 push_function(NO_SCOPE, INIT_METHOD, NULL,
1580 $<id>1, $<cbuf>5, $<line>2,
1581 ccode_line, FALSE, NULL);
1582 } else if(strcmp($<id>1, "class_init")==0) {
1583 push_init_arg($<id>3,TRUE);
1584 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1585 $<id>1, $<cbuf>5, $<line>2,
1586 ccode_line, FALSE, NULL);
1590 g_string_free($<cbuf>5,TRUE);
1591 yyerror(_("parse error "
1592 "(untyped blocks must be init or "
1599 returnvals: TOKEN retcode {
1600 g_free(onerror); onerror = NULL;
1601 g_free(defreturn); defreturn = NULL;
1602 if(!set_return_value($<id>1, $<id>2)) {
1605 yyerror(_("parse error"));
1610 | TOKEN retcode TOKEN retcode {
1611 g_free(onerror); onerror = NULL;
1612 g_free(defreturn); defreturn = NULL;
1613 if(!set_return_value($<id>1, $<id>2)) {
1614 g_free($<id>1); g_free($<id>2);
1615 g_free($<id>3); g_free($<id>4);
1616 yyerror(_("parse error"));
1619 if(!set_return_value($<id>3, $<id>4)) {
1620 onerror = defreturn = NULL;
1621 g_free($<id>1); g_free($<id>2);
1622 g_free($<id>3); g_free($<id>4);
1623 yyerror(_("parse error"));
1630 g_free(onerror); onerror = NULL;
1631 g_free(defreturn); defreturn = NULL;
1635 retcode: numtok { $<id>$ = $<id>1; }
1637 $<id>$ = ($<cbuf>3)->str;
1638 g_string_free($<cbuf>3, FALSE);
1642 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1646 if(strcmp($<id>1,"self")==0)
1647 push_self($<id>1, FALSE);
1650 yyerror(_("parse error"));
1657 if(strcmp($<id>1,"self")==0)
1658 push_self($<id>1, TRUE);
1661 yyerror(_("parse error"));
1668 if(strcmp($<id>2,"self")==0)
1669 push_self($<id>2, TRUE);
1672 yyerror(_("parse error"));
1676 | TOKEN ',' arglist {
1678 if(strcmp($<id>1,"self")==0)
1679 push_self($<id>1, FALSE);
1682 yyerror(_("parse error"));
1686 | TOKEN CONST ',' arglist {
1688 if(strcmp($<id>1,"self")==0)
1689 push_self($<id>1, TRUE);
1692 yyerror(_("parse error"));
1696 | CONST TOKEN ',' arglist {
1698 if(strcmp($<id>2,"self")==0)
1699 push_self($<id>2, TRUE);
1702 yyerror(_("parse error"));
1706 | arglist { has_self = FALSE; }
1709 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1710 | arglist1 { vararg = FALSE; }
1713 arglist1: arglist1 ',' arg { ; }
1718 push_funcarg($<id>2,NULL);
1720 | type TOKEN ARRAY_DIM {
1721 push_funcarg($<id>2,$<id>3);
1723 | type TOKEN '(' TOKEN checklist ')' {
1724 if(strcmp($<id>4,"check")!=0) {
1725 yyerror(_("parse error"));
1729 push_funcarg($<id>2,NULL);
1731 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1732 if(strcmp($<id>5,"check")!=0) {
1733 yyerror(_("parse error"));
1737 push_funcarg($<id>2,$<id>3);
1741 checklist: checklist check { ; }
1746 if(strcmp($<id>1,"type")==0) {
1747 Node *node = node_new (CHECK_NODE,
1748 "chtype", TYPE_CHECK,
1750 checks = g_list_append(checks,node);
1751 } else if(strcmp($<id>1,"null")==0) {
1752 Node *node = node_new (CHECK_NODE,
1753 "chtype", NULL_CHECK,
1755 checks = g_list_append(checks,node);
1757 yyerror(_("parse error"));
1763 Node *node = node_new (CHECK_NODE,
1765 "number:steal", $<id>2,
1767 checks = g_list_append(checks,node);
1770 Node *node = node_new (CHECK_NODE,
1772 "number:steal", $<id>2,
1774 checks = g_list_append(checks,node);
1777 Node *node = node_new (CHECK_NODE,
1779 "number:steal", $<id>3,
1781 checks = g_list_append(checks,node);
1784 Node *node = node_new (CHECK_NODE,
1786 "number:steal", $<id>3,
1788 checks = g_list_append(checks,node);
1791 Node *node = node_new (CHECK_NODE,
1793 "number:steal", $<id>3,
1795 checks = g_list_append(checks,node);
1798 Node *node = node_new (CHECK_NODE,
1800 "number:steal", $<id>3,
1802 checks = g_list_append(checks,node);
1806 enumcode: ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
1807 Node *node = node_new (ENUMDEF_NODE,
1808 "etype:steal", $<id>6,
1809 "prefix:steal", $<id>2,
1810 "values:steal", enum_vals,
1813 nodes = g_list_append (nodes, node);
1815 | ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
1816 Node *node = node_new (ENUMDEF_NODE,
1817 "etype:steal", $<id>7,
1818 "prefix:steal", $<id>2,
1819 "values:steal", enum_vals,
1822 nodes = g_list_append (nodes, node);
1826 enumvals: enumvals ',' enumval {;}
1830 enumval: TOKEN '=' numtok {
1834 /* A float value, that's a bad enum */
1835 if (num[0] >= '0' &&
1837 strchr (num, '.') != NULL) {
1840 yyerror(_("parse error (enumerator value not integer constant)"));
1844 node = node_new (ENUMVALUE_NODE,
1845 "name:steal", $<id>1,
1848 enum_vals = g_list_append (enum_vals, node);
1853 node = node_new (ENUMVALUE_NODE,
1854 "name:steal", $<id>1,
1856 enum_vals = g_list_append (enum_vals, node);
1860 flagcode: FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
1861 Node *node = node_new (FLAGS_NODE,
1862 "ftype:steal", $<id>6,
1863 "prefix:steal", $<id>2,
1864 "values:steal", flag_vals,
1867 nodes = g_list_append (nodes, node);
1869 | FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
1870 Node *node = node_new (FLAGS_NODE,
1871 "ftype:steal", $<id>7,
1872 "prefix:steal", $<id>2,
1873 "values:steal", flag_vals,
1876 nodes = g_list_append (nodes, node);
1880 flagvals: flagvals ',' TOKEN {
1881 flag_vals = g_list_append (flag_vals, $<id>3);
1884 flag_vals = g_list_append (flag_vals, $<id>1);
1888 errorcode: ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
1889 Node *node = node_new (ERROR_NODE,
1890 "etype:steal", $<id>6,
1891 "prefix:steal", $<id>2,
1892 "values:steal", error_vals,
1895 nodes = g_list_append (nodes, node);
1897 | ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
1898 Node *node = node_new (ERROR_NODE,
1899 "etype:steal", $<id>7,
1900 "prefix:steal", $<id>2,
1901 "values:steal", error_vals,
1904 nodes = g_list_append (nodes, node);
1908 errorvals: errorvals ',' TOKEN {
1909 error_vals = g_list_append (error_vals, $<id>3);
1912 error_vals = g_list_append (error_vals, $<id>1);
1917 numtok: NUMBER { $<id>$ = $<id>1; }
1919 $<id>$ = g_strconcat("-",$<id>2,NULL);
1922 | SINGLE_CHAR { $<id>$ = $<id>1; }
1923 | TOKEN { $<id>$ = $<id>1; }