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 get_prop_enum_flag_cast (Property *prop)
445 if (prop->extra_gtktype == NULL ||
446 /* HACK! just in case someone made this
447 * work with 2.0.0 by using the TYPE
449 ((strstr (prop->extra_gtktype, "_TYPE_") != NULL ||
450 strstr (prop->extra_gtktype, "TYPE_") == prop->extra_gtktype) &&
451 strchr (prop->extra_gtktype, ':') == NULL)) {
452 if (prop->ptype != NULL)
453 return get_type (prop->ptype, TRUE);
455 return g_strdup ("");
457 tmp = remove_sep (prop->extra_gtktype);
458 ret = g_strdup_printf ("(%s) ", tmp);
464 property_link_and_export (Node *node)
466 Property *prop = (Property *)node;
470 char *get = NULL, *set = NULL;
473 if (prop->set != NULL ||
475 error_print (GOB_ERROR, prop->line_no,
476 _("Property linking requested, but "
477 "getters and setters exist"));
480 var = find_var_or_die (prop->name, prop->line_no);
481 if(var->scope == PRIVATE_SCOPE) {
482 root = "self->_priv";
483 } else if (var->scope == CLASS_SCOPE) {
484 root = "SELF_GET_CLASS(self)";
486 error_print (GOB_ERROR, prop->line_no,
487 _("Self aliases needed when autolinking to a classwide member"));
492 if (strcmp (prop->gtktype, "STRING") == 0) {
493 set = g_strdup_printf("{ char *old = %s->%s; "
494 "%s->%s = g_value_dup_string (VAL); g_free (old); }",
497 get = g_strdup_printf("g_value_set_string (VAL, %s->%s);",
499 } else if (strcmp (prop->gtktype, "OBJECT") == 0) {
501 if (prop->extra_gtktype != NULL) {
502 cast = remove_sep (prop->extra_gtktype);
506 set = g_strdup_printf("{ GObject *___old = (GObject *)%s->%s; "
507 "%s->%s = (%s *)g_value_dup_object (VAL); "
508 "if (___old != NULL) { "
509 "g_object_unref (G_OBJECT (___old)); "
515 get = g_strdup_printf ("g_value_set_object (VAL, "
516 "(gpointer)%s->%s);",
519 } else if (strcmp (prop->gtktype, "BOXED") == 0) {
520 if (prop->extra_gtktype == NULL) {
521 error_print (GOB_ERROR, prop->line_no,
522 _("Property linking requested for BOXED, but "
523 "boxed_type not set"));
525 set = g_strdup_printf("{ gpointer ___old = (gpointer)%s->%s; "
526 "gpointer ___new = (gpointer)g_value_get_boxed (VAL); "
527 "if (___new != ___old) { "
528 "if (___old != NULL) g_boxed_free (%s, ___old); "
529 "if (___new != NULL) %s->%s = g_boxed_copy (%s, ___new); "
530 "else %s->%s = NULL;"
538 get = g_strdup_printf("g_value_set_boxed (VAL, %s->%s);",
543 const char *getcast = "";
544 const char *setcast = "";
545 char *to_free = NULL;
546 set_func = g_strdup_printf ("g_value_set_%s", prop->gtktype);
547 g_strdown (set_func);
548 get_func = g_strdup_printf ("g_value_get_%s", prop->gtktype);
549 g_strdown (get_func);
551 if (strcmp (prop->gtktype, "FLAGS") == 0) {
552 setcast = "(guint) ";
554 get_prop_enum_flag_cast (prop);
555 } else if (strcmp (prop->gtktype, "ENUM") == 0) {
558 get_prop_enum_flag_cast (prop);
561 set = g_strdup_printf("%s->%s = %s%s (VAL);",
565 get = g_strdup_printf("%s (VAL, %s%s->%s);",
577 "get_line", prop->line_no,
579 "set_line", prop->line_no,
584 export_accessors (prop->name,
585 prop->get != NULL, prop->get_line,
586 prop->set != NULL, prop->set_line,
597 if (strcmp (s, "BOOL") == 0) {
598 error_print (GOB_WARN, line_no,
599 _("BOOL type is deprecated, please use BOOLEAN"));
601 return g_strdup ("BOOLEAN");
608 ensure_property (void)
610 if (property == NULL)
611 property = (Property *)node_new (PROPERTY_NODE, NULL);
625 %token CONST VOID STRUCT UNION ENUM THREEDOTS
626 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
628 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
629 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
630 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
631 %token <line> VIRTUAL SIGNAL OVERRIDE
632 %token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
633 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
637 prog: ccodes class ccodes { ; }
644 Node *node = node_new (CCODE_NODE,
646 "cbuf:steal", ($<cbuf>1)->str,
647 "line_no", ccode_line,
649 nodes = g_list_append(nodes,node);
650 g_string_free($<cbuf>1,FALSE);
653 Node *node = node_new (CCODE_NODE,
655 "cbuf:steal", ($<cbuf>1)->str,
656 "line_no", ccode_line,
658 nodes = g_list_append(nodes,node);
659 g_string_free($<cbuf>1,FALSE);
662 Node *node = node_new (CCODE_NODE,
664 "cbuf:steal", ($<cbuf>1)->str,
665 "line_no", ccode_line,
667 nodes = g_list_append(nodes,node);
668 g_string_free($<cbuf>1,FALSE);
671 Node *node = node_new (CCODE_NODE,
673 "cbuf:steal", ($<cbuf>1)->str,
674 "line_no", ccode_line,
676 nodes = g_list_append(nodes,node);
677 g_string_free($<cbuf>1,FALSE);
680 Node *node = node_new (CCODE_NODE,
682 "cbuf:steal", ($<cbuf>1)->str,
683 "line_no", ccode_line,
685 nodes = g_list_append(nodes,node);
686 g_string_free($<cbuf>1,FALSE);
689 Node *node = node_new (CCODE_NODE,
691 "cbuf:steal", ($<cbuf>1)->str,
692 "line_no", ccode_line,
694 nodes = g_list_append(nodes,node);
695 g_string_free($<cbuf>1,FALSE);
699 ccodes: ccodes ccode { ; }
700 | ccodes enumcode { ; }
701 | ccodes flagcode { ; }
702 | ccodes errorcode { ; }
709 class: classdec '{' classcode '}' {
710 ((Class *)class)->nodes = class_nodes;
712 nodes = g_list_append(nodes,class);
715 ((Class *)class)->nodes = NULL;
717 nodes = g_list_append(nodes,class);
721 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
722 class = node_new (CLASS_NODE,
723 "otype:steal", $<id>2,
724 "ptype:steal", $<id>4,
725 "bonobo_object_class:steal", bonobo_object_class,
726 "interfaces:steal", interfaces,
727 "chunk_size:steal", chunk_size,
729 bonobo_object_class = NULL;
736 | '(' TOKEN TOKEN ')' classflags {
737 if(strcmp($<id>2,"chunks") == 0) {
739 chunk_size = g_strdup($<id>3);
740 } else if(strcmp($<id>2,"BonoboObject") == 0) {
741 g_free (bonobo_object_class);
742 bonobo_object_class = g_strdup($<id>3);
744 yyerror(_("parse error"));
748 | '(' TOKEN TYPETOKEN ')' classflags {
749 if (strcmp ($<id>2, "interface") == 0) {
750 interfaces = g_list_append (interfaces,
753 yyerror(_("parse error"));
757 | '(' TOKEN NUMBER ')' classflags {
758 if(strcmp($<id>2,"chunks") == 0) {
760 if(atoi($<id>3) != 0)
761 chunk_size = g_strdup($<id>3);
765 yyerror(_("parse error"));
771 classcode: classcode thing { ; }
777 if (strcmp ($<id>1, "BonoboObject") != 0) {
779 yyerror (_("parse error"));
783 last_added_method->bonobo_object_func = TRUE;
785 | TOKEN TYPETOKEN method {
786 if (strcmp ($<id>1, "interface") != 0) {
789 yyerror (_("parse error"));
793 node_set ((Node *)last_added_method,
794 "interface:steal", $<id>2,
803 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
804 | PRIVATE { the_scope = PRIVATE_SCOPE; }
805 | PROTECTED { the_scope = PROTECTED_SCOPE; }
806 | CLASSWIDE { the_scope = CLASS_SCOPE; }
809 destructor: TOKEN TOKEN {
810 if (strcmp ($<id>1, "destroywith") == 0) {
812 destructor_unref = FALSE;
814 destructor_line = line_no;
815 destructor_simple = TRUE;
816 } else if (strcmp ($<id>1, "unrefwith") == 0) {
818 destructor_unref = TRUE;
820 destructor_line = line_no;
821 destructor_simple = TRUE;
825 yyerror (_("parse error"));
830 if (strcmp ($<id>1, "destroy") == 0) {
832 destructor_unref = FALSE;
833 destructor = ($<cbuf>3)->str;
834 g_string_free($<cbuf>3, FALSE);
835 destructor_line = ccode_line;
836 destructor_simple = FALSE;
837 } else if (strcmp ($<id>1, "unref") == 0) {
839 destructor_unref = TRUE;
840 destructor = ($<cbuf>3)->str;
841 g_string_free ($<cbuf>3, FALSE);
842 destructor_line = ccode_line;
843 destructor_simple = FALSE;
846 g_string_free ($<cbuf>3, TRUE);
847 yyerror (_("parse error"));
853 initializer: '=' numtok {
854 initializer = $<id>2;
855 initializer_line = ccode_line;
858 initializer = ($<cbuf>3)->str;
859 initializer_line = ccode_line;
860 g_string_free($<cbuf>3, FALSE);
865 varoptions: destructor initializer { ; }
866 | initializer destructor { ; }
867 | initializer { destructor = NULL; }
868 | destructor { initializer = NULL; }
875 variable: scope type TOKEN varoptions ';' {
876 push_variable($<id>3, the_scope,$<line>1, NULL);
878 | scope type TOKEN ARRAY_DIM varoptions ';' {
879 push_variable($<id>3, the_scope, $<line>1, $<id>4);
883 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
885 if(strcmp($<id>6,"get")==0 &&
886 strcmp($<id>9,"set")==0) {
887 Type *type = pop_type();
890 node = node_new (ARGUMENT_NODE,
891 "gtktype:steal", $<id>3,
893 "flags:steal", $<list>2,
894 "name:steal", $<id>4,
895 "get:steal", ($<cbuf>8)->str,
896 "get_line", $<line>7,
897 "set:steal", ($<cbuf>11)->str,
898 "set_line", $<line>10,
902 class_nodes = g_list_append(class_nodes,node);
904 g_string_free ($<cbuf>8, FALSE);
905 g_string_free ($<cbuf>11, FALSE);
907 } else if(strcmp($<id>6,"set")==0 &&
908 strcmp($<id>9,"get")==0) {
909 Type *type = pop_type();
912 node = node_new (ARGUMENT_NODE,
913 "gtktype:steal", $<id>3,
915 "flags:steal", $<list>2,
916 "name:steal", $<id>4,
917 "get:steal", ($<cbuf>11)->str,
918 "get_line", $<line>10,
919 "set:steal", ($<cbuf>8)->str,
920 "set_line", $<line>7,
923 g_string_free ($<cbuf>11, FALSE);
924 g_string_free ($<cbuf>8, FALSE);
925 class_nodes = g_list_append(class_nodes,node);
931 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
932 g_list_free ($<list>2);
933 g_string_free ($<cbuf>11, TRUE);
934 g_string_free ($<cbuf>8, TRUE);
935 yyerror (_("parse error"));
939 if ($<id>5 != NULL) {
940 Argument *arg = (Argument *)node;
941 export_accessors (arg->name,
942 arg->get != NULL, arg->get_line,
943 arg->set != NULL, arg->set_line,
951 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
953 if(strcmp($<id>6, "get") == 0) {
954 Type *type = pop_type();
956 node = node_new (ARGUMENT_NODE,
957 "gtktype:steal", $<id>3,
959 "flags:steal", $<list>2,
960 "name:steal", $<id>4,
961 "get:steal", ($<cbuf>8)->str,
962 "get_line", $<line>7,
966 g_string_free ($<cbuf>8, FALSE);
967 class_nodes = g_list_append(class_nodes, node);
968 } else if(strcmp($<id>6, "set") == 0) {
969 Type *type = pop_type();
971 node = node_new (ARGUMENT_NODE,
972 "gtktype:steal", $<id>3,
974 "flags:steal", $<list>2,
975 "name:steal", $<id>4,
976 "set:steal", ($<cbuf>8)->str,
977 "set_line", $<line>7,
981 g_string_free ($<cbuf>8, FALSE);
982 class_nodes = g_list_append (class_nodes, node);
987 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
988 g_list_free ($<list>2);
989 g_string_free ($<cbuf>8, TRUE);
990 yyerror(_("parse error"));
994 if ($<id>5 != NULL) {
995 Argument *arg = (Argument *)node;
996 export_accessors (arg->name,
997 arg->get != NULL, arg->get_line,
998 arg->set != NULL, arg->set_line,
1005 | ARGUMENT flags argtype TOKEN export TOKEN {
1007 char *get, *set = NULL;
1012 if(strcmp($<id>6, "link")!=0 &&
1013 strcmp($<id>6, "stringlink")!=0 &&
1014 strcmp($<id>6, "objectlink")!=0) {
1018 g_list_foreach($<list>2,(GFunc)g_free,NULL);
1019 g_list_free($<list>2);
1020 yyerror(_("parse error"));
1026 var = find_var_or_die($<id>4, $<line>1);
1027 if(var->scope == PRIVATE_SCOPE)
1028 root = "self->_priv";
1029 else if(var->scope == CLASS_SCOPE) {
1030 root = "SELF_GET_CLASS(self)";
1032 error_print(GOB_ERROR, $<line>1,
1033 _("Self aliases needed when autolinking to a classwide member"));
1037 if(strcmp($<id>6, "link")==0) {
1038 set = g_strdup_printf("%s->%s = ARG;",
1040 } else if(strcmp($<id>6, "stringlink")==0) {
1041 set = g_strdup_printf("g_free (%s->%s); "
1042 "%s->%s = g_strdup (ARG);",
1045 } else if(strcmp($<id>6, "objectlink")==0) {
1046 set = g_strdup_printf(
1048 "g_object_ref (G_OBJECT (ARG)); "
1049 "if (%s->%s != NULL) "
1050 "g_object_unref (G_OBJECT (%s->%s)); "
1056 g_assert_not_reached();
1059 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
1064 type = (Type *)node_copy ((Node *)var->vtype);
1066 node = node_new (ARGUMENT_NODE,
1067 "gtktype:steal", $<id>3,
1068 "atype:steal", type,
1069 "flags:steal", $<list>2,
1070 "name:steal", $<id>4,
1072 "get_line", $<line>1,
1074 "set_line", $<line>1,
1075 "line_no", $<line>1,
1078 if ($<id>5 != NULL) {
1079 Argument *arg = (Argument *)node;
1080 export_accessors (arg->name,
1081 arg->get != NULL, arg->get_line,
1082 arg->set != NULL, arg->set_line,
1089 class_nodes = g_list_append (class_nodes, node);
1093 export: '(' TOKEN ')' {
1094 if (strcmp ($<id>2, "export")!=0) {
1096 yyerror (_("parse error"));
1106 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1108 node_set ((Node *)property,
1109 "line_no", $<line>1,
1110 "gtktype:steal", debool ($<id>2),
1111 "name:steal", $<id>3,
1113 if (strcmp ($<id>5, "get") == 0 &&
1114 strcmp ($<id>8, "set") == 0) {
1115 node_set ((Node *)property,
1116 "get:steal", ($<cbuf>7)->str,
1117 "get_line", $<line>6,
1118 "set:steal", ($<cbuf>10)->str,
1119 "set_line", $<line>9,
1121 g_string_free ($<cbuf>7, FALSE);
1122 g_string_free ($<cbuf>10, FALSE);
1125 } else if (strcmp ($<id>5, "set") == 0 &&
1126 strcmp ($<id>8, "get") == 0) {
1127 node_set ((Node *)property,
1128 "get:steal", ($<cbuf>10)->str,
1129 "get_line", $<line>9,
1130 "set:steal", ($<cbuf>7)->str,
1131 "set_line", $<line>6,
1133 g_string_free ($<cbuf>7, FALSE);
1134 g_string_free ($<cbuf>10, FALSE);
1138 g_string_free ($<cbuf>7, TRUE);
1139 g_string_free ($<cbuf>10, TRUE);
1142 node_free ((Node *)property);
1144 yyerror (_("parse error"));
1147 property_link_and_export ((Node *)property);
1148 if (property != NULL) {
1149 class_nodes = g_list_append (class_nodes,
1154 | PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE ';' {
1156 node_set ((Node *)property,
1157 "line_no", $<line>1,
1158 "gtktype:steal", debool ($<id>2),
1159 "name:steal", $<id>3,
1161 if (strcmp ($<id>5, "get") == 0) {
1162 node_set ((Node *)property,
1163 "get:steal", ($<cbuf>7)->str,
1164 "get_line", $<line>6,
1166 g_string_free ($<cbuf>7, FALSE);
1168 } else if (strcmp ($<id>5, "set") == 0) {
1169 node_set ((Node *)property,
1170 "set:steal", ($<cbuf>7)->str,
1171 "set_line", $<line>6,
1173 g_string_free ($<cbuf>7, FALSE);
1176 g_string_free ($<cbuf>7, TRUE);
1178 node_free ((Node *)property);
1180 yyerror (_("parse error"));
1183 property_link_and_export ((Node *)property);
1184 if (property != NULL) {
1185 class_nodes = g_list_append (class_nodes,
1190 | PROPERTY TOKEN TOKEN param_spec ';' {
1192 node_set ((Node *)property,
1193 "line_no", $<line>1,
1194 "gtktype:steal", debool ($<id>2),
1195 "name:steal", $<id>3,
1197 property_link_and_export ((Node *)property);
1198 if (property != NULL) {
1199 class_nodes = g_list_append (class_nodes,
1206 param_spec: '(' param_spec_list ')' { ; }
1210 param_spec_list: param_spec_list ',' param_spec_value { ; }
1211 | param_spec_value { ; }
1214 string: STRING { $<id>$ = $<id>1; }
1215 | TOKEN '(' STRING ')' {
1216 if (strcmp ($<id>1, "_") != 0) {
1218 yyerror(_("parse error"));
1222 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1227 anyval: numtok { $<id>$ = $<id>1; }
1228 | string { $<id>$ = $<id>1; }
1231 param_spec_value: NICK '=' string {
1233 node_set ((Node *)property,
1234 "nick:steal", $<id>3,
1237 | BLURB '=' string {
1239 node_set ((Node *)property,
1240 "blurb:steal", $<id>3,
1243 | MAXIMUM '=' numtok {
1245 node_set ((Node *)property,
1246 "maximum:steal", $<id>3,
1249 | MINIMUM '=' numtok {
1251 node_set ((Node *)property,
1252 "minimum:steal", $<id>3,
1255 | DEFAULT_VALUE '=' anyval {
1257 node_set ((Node *)property,
1258 "default_value:steal", $<id>3,
1261 | FLAGS '=' flaglist {
1263 node_set ((Node *)property,
1264 "flags:steal", $<list>3,
1268 Type *type = pop_type ();
1270 node_set ((Node *)property,
1271 "ptype:steal", type,
1274 | FLAGS_TYPE '=' TYPETOKEN {
1276 node_set ((Node *)property,
1277 "extra_gtktype:steal", $<id>3,
1280 | FLAGS_TYPE '=' TOKEN {
1282 node_set ((Node *)property,
1283 "extra_gtktype:steal", $<id>3,
1286 | ENUM_TYPE '=' TYPETOKEN {
1288 node_set ((Node *)property,
1289 "extra_gtktype:steal", $<id>3,
1292 | ENUM_TYPE '=' TOKEN {
1294 node_set ((Node *)property,
1295 "extra_gtktype:steal", $<id>3,
1298 | PARAM_TYPE '=' TYPETOKEN {
1300 node_set ((Node *)property,
1301 "extra_gtktype:steal", $<id>3,
1304 | PARAM_TYPE '=' TOKEN {
1306 node_set ((Node *)property,
1307 "extra_gtktype:steal", $<id>3,
1310 | BOXED_TYPE '=' TYPETOKEN {
1312 node_set ((Node *)property,
1313 "extra_gtktype:steal", $<id>3,
1316 | BOXED_TYPE '=' TOKEN {
1318 node_set ((Node *)property,
1319 "extra_gtktype:steal", $<id>3,
1322 | OBJECT_TYPE '=' TYPETOKEN {
1324 node_set ((Node *)property,
1325 "extra_gtktype:steal", $<id>3,
1328 | OBJECT_TYPE '=' TOKEN {
1330 node_set ((Node *)property,
1331 "extra_gtktype:steal", $<id>3,
1336 if (strcmp ($<id>1, "link") == 0) {
1338 node_set ((Node *)property,
1341 } else if (strcmp ($<id>1, "export") == 0) {
1343 node_set ((Node *)property,
1348 yyerror(_("parse error"));
1354 argtype: TOKEN '(' TOKEN type ')' {
1355 if(strcmp($<id>3,"type")!=0) {
1358 yyerror(_("parse error"));
1361 $<id>$ = debool ($<id>1);
1364 $<id>$ = debool ($<id>1);
1365 typestack = g_list_prepend(typestack,NULL);
1369 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1370 | { $<list>$ = NULL; }
1373 flaglist: TOKEN '|' flaglist {
1374 $<list>$ = g_list_append($<list>3,$<id>1);
1377 $<list>$ = g_list_append(NULL,$<id>1);
1382 type: specifier_list pointer {
1383 Node *node = node_new (TYPE_NODE,
1384 "name:steal", $<id>1,
1385 "pointer:steal", $<id>2,
1387 typestack = g_list_prepend(typestack,node);
1390 Node *node = node_new (TYPE_NODE,
1391 "name:steal", $<id>1,
1393 typestack = g_list_prepend(typestack,node);
1397 /* The special cases are neccessary to avoid conflicts */
1398 specifier_list: spec_list {
1405 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1409 $<id>$ = g_strconcat($<id>1, " const", NULL);
1412 | strunionenum TOKEN {
1413 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1416 | CONST strunionenum TOKEN {
1417 $<id>$ = g_strconcat("const ", $<id>2, " ",
1421 | strunionenum TOKEN CONST {
1422 $<id>$ = g_strconcat($<id>1, " ",
1423 $<id>2, " const", NULL);
1428 /* The special const cases take care of conflicts ! */
1429 spec_list: specifier spec_list {
1430 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1433 | TYPETOKEN spec_list {
1434 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1439 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1446 $<id>$ = g_strconcat($<id>1, " const", NULL);
1450 $<id>$ = g_strdup($<id>1);
1453 $<id>$ = g_strconcat($<id>1, " const", NULL);
1457 specifier: VOID { $<id>$ = "void"; }
1458 | CHAR { $<id>$ = "char"; }
1459 | SHORT { $<id>$ = "short"; }
1460 | INT { $<id>$ = "int"; }
1461 | LONG { $<id>$ = "long"; }
1462 | FLOAT { $<id>$ = "float"; }
1463 | DOUBLE { $<id>$ = "double"; }
1464 | SIGNED { $<id>$ = "signed"; }
1465 | UNSIGNED { $<id>$ = "unsigned"; }
1468 strunionenum: STRUCT { $<id>$ = "struct"; }
1469 | UNION { $<id>$ = "union"; }
1470 | ENUM { $<id>$ = "enum"; }
1473 pointer: '*' { $<id>$ = g_strdup("*"); }
1474 | '*' CONST { $<id>$ = g_strdup("* const"); }
1476 $<id>$ = g_strconcat("*", $<id>2, NULL);
1479 | '*' CONST pointer {
1480 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1485 /* this never sets the_scope */
1486 simplesigtype: TOKEN sigtype {
1487 if(strcmp($<id>1, "first")==0)
1488 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1489 else if(strcmp($<id>1, "last")==0)
1490 $<sigtype>$ = SIGNAL_LAST_METHOD;
1492 yyerror(_("signal must be 'first' or 'last'"));
1499 $<sigtype>$ = SIGNAL_LAST_METHOD;
1503 /* this always sets the_scope */
1504 fullsigtype: scope TOKEN sigtype {
1505 if(strcmp($<id>2,"first")==0)
1506 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1507 else if(strcmp($<id>2,"last")==0)
1508 $<sigtype>$ = SIGNAL_LAST_METHOD;
1510 yyerror(_("signal must be 'first' or 'last'"));
1516 | TOKEN scope sigtype {
1517 if(strcmp($<id>1,"first")==0)
1518 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1519 else if(strcmp($<id>1,"last")==0)
1520 $<sigtype>$ = SIGNAL_LAST_METHOD;
1522 yyerror(_("signal must be 'first' or 'last'"));
1529 $<sigtype>$ = SIGNAL_LAST_METHOD;
1532 /* the_scope was default thus public */
1533 the_scope = PUBLIC_SCOPE;
1537 sigtype: TOKEN '(' tokenlist ')' {
1538 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1542 tokenlist: tokenlist ',' TOKEN {
1543 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1546 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1550 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1551 | ';' { $<cbuf>$ = NULL; }
1554 /*here CCODE will include the ending '}' */
1555 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1557 yyerror(_("signal without 'self' as "
1558 "first parameter"));
1559 free_all_global_state();
1562 if(the_scope == CLASS_SCOPE) {
1563 yyerror(_("a method cannot be of class scope"));
1564 free_all_global_state();
1567 push_function(the_scope, $<sigtype>3,NULL,
1568 $<id>5, $<cbuf>10,$<line>1,
1569 ccode_line, vararg, $<list>2);
1571 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1573 yyerror(_("signal without 'self' as "
1574 "first parameter"));
1575 free_all_global_state();
1578 if(the_scope == CLASS_SCOPE) {
1579 yyerror(_("a method cannot be of class scope"));
1580 free_all_global_state();
1583 push_function(the_scope, $<sigtype>4, NULL,
1584 $<id>6, $<cbuf>11, $<line>2,
1585 ccode_line, vararg, $<list>3);
1587 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1589 yyerror(_("virtual method without 'self' as "
1590 "first parameter"));
1591 free_all_global_state();
1594 if(the_scope == CLASS_SCOPE) {
1595 yyerror(_("a method cannot be of class scope"));
1596 free_all_global_state();
1599 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1601 ccode_line, vararg, NULL);
1603 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1605 yyerror(_("virtual method without 'self' as "
1606 "first parameter"));
1607 free_all_global_state();
1610 if(the_scope == CLASS_SCOPE) {
1611 yyerror(_("a method cannot be of class scope"));
1612 free_all_global_state();
1615 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1617 ccode_line, vararg, NULL);
1619 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1621 yyerror(_("virtual method without 'self' as "
1622 "first parameter"));
1623 free_all_global_state();
1626 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1627 $<id>3, $<cbuf>8, $<line>1,
1628 ccode_line, vararg, NULL);
1630 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1631 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1633 $<line>1, ccode_line,
1636 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1637 if(the_scope == CLASS_SCOPE) {
1638 yyerror(_("a method cannot be of class scope"));
1639 free_all_global_state();
1642 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1643 $<cbuf>8, $<line>1, ccode_line,
1646 | TOKEN '(' TOKEN ')' codenocode {
1647 if(strcmp($<id>1, "init")==0) {
1648 push_init_arg($<id>3,FALSE);
1649 push_function(NO_SCOPE, INIT_METHOD, NULL,
1650 $<id>1, $<cbuf>5, $<line>2,
1651 ccode_line, FALSE, NULL);
1652 } else if(strcmp($<id>1, "class_init")==0) {
1653 push_init_arg($<id>3,TRUE);
1654 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1655 $<id>1, $<cbuf>5, $<line>2,
1656 ccode_line, FALSE, NULL);
1660 g_string_free($<cbuf>5,TRUE);
1661 yyerror(_("parse error "
1662 "(untyped blocks must be init or "
1669 returnvals: TOKEN retcode {
1670 g_free(onerror); onerror = NULL;
1671 g_free(defreturn); defreturn = NULL;
1672 if(!set_return_value($<id>1, $<id>2)) {
1675 yyerror(_("parse error"));
1680 | TOKEN retcode TOKEN retcode {
1681 g_free(onerror); onerror = NULL;
1682 g_free(defreturn); defreturn = NULL;
1683 if(!set_return_value($<id>1, $<id>2)) {
1684 g_free($<id>1); g_free($<id>2);
1685 g_free($<id>3); g_free($<id>4);
1686 yyerror(_("parse error"));
1689 if(!set_return_value($<id>3, $<id>4)) {
1690 onerror = defreturn = NULL;
1691 g_free($<id>1); g_free($<id>2);
1692 g_free($<id>3); g_free($<id>4);
1693 yyerror(_("parse error"));
1700 g_free(onerror); onerror = NULL;
1701 g_free(defreturn); defreturn = NULL;
1705 retcode: numtok { $<id>$ = $<id>1; }
1707 $<id>$ = ($<cbuf>3)->str;
1708 g_string_free($<cbuf>3, FALSE);
1712 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1716 if(strcmp($<id>1,"self")==0)
1717 push_self($<id>1, FALSE);
1720 yyerror(_("parse error"));
1727 if(strcmp($<id>1,"self")==0)
1728 push_self($<id>1, TRUE);
1731 yyerror(_("parse error"));
1738 if(strcmp($<id>2,"self")==0)
1739 push_self($<id>2, TRUE);
1742 yyerror(_("parse error"));
1746 | TOKEN ',' arglist {
1748 if(strcmp($<id>1,"self")==0)
1749 push_self($<id>1, FALSE);
1752 yyerror(_("parse error"));
1756 | TOKEN CONST ',' arglist {
1758 if(strcmp($<id>1,"self")==0)
1759 push_self($<id>1, TRUE);
1762 yyerror(_("parse error"));
1766 | CONST TOKEN ',' arglist {
1768 if(strcmp($<id>2,"self")==0)
1769 push_self($<id>2, TRUE);
1772 yyerror(_("parse error"));
1776 | arglist { has_self = FALSE; }
1779 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1780 | arglist1 { vararg = FALSE; }
1783 arglist1: arglist1 ',' arg { ; }
1788 push_funcarg($<id>2,NULL);
1790 | type TOKEN ARRAY_DIM {
1791 push_funcarg($<id>2,$<id>3);
1793 | type TOKEN '(' TOKEN checklist ')' {
1794 if(strcmp($<id>4,"check")!=0) {
1795 yyerror(_("parse error"));
1799 push_funcarg($<id>2,NULL);
1801 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1802 if(strcmp($<id>5,"check")!=0) {
1803 yyerror(_("parse error"));
1807 push_funcarg($<id>2,$<id>3);
1811 checklist: checklist check { ; }
1816 if(strcmp($<id>1,"type")==0) {
1817 Node *node = node_new (CHECK_NODE,
1818 "chtype", TYPE_CHECK,
1820 checks = g_list_append(checks,node);
1821 } else if(strcmp($<id>1,"null")==0) {
1822 Node *node = node_new (CHECK_NODE,
1823 "chtype", NULL_CHECK,
1825 checks = g_list_append(checks,node);
1827 yyerror(_("parse error"));
1833 Node *node = node_new (CHECK_NODE,
1835 "number:steal", $<id>2,
1837 checks = g_list_append(checks,node);
1840 Node *node = node_new (CHECK_NODE,
1842 "number:steal", $<id>2,
1844 checks = g_list_append(checks,node);
1847 Node *node = node_new (CHECK_NODE,
1849 "number:steal", $<id>3,
1851 checks = g_list_append(checks,node);
1854 Node *node = node_new (CHECK_NODE,
1856 "number:steal", $<id>3,
1858 checks = g_list_append(checks,node);
1861 Node *node = node_new (CHECK_NODE,
1863 "number:steal", $<id>3,
1865 checks = g_list_append(checks,node);
1868 Node *node = node_new (CHECK_NODE,
1870 "number:steal", $<id>3,
1872 checks = g_list_append(checks,node);
1876 enumcode: ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
1877 Node *node = node_new (ENUMDEF_NODE,
1878 "etype:steal", $<id>6,
1879 "prefix:steal", $<id>2,
1880 "values:steal", enum_vals,
1883 nodes = g_list_append (nodes, node);
1885 | ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
1886 Node *node = node_new (ENUMDEF_NODE,
1887 "etype:steal", $<id>7,
1888 "prefix:steal", $<id>2,
1889 "values:steal", enum_vals,
1892 nodes = g_list_append (nodes, node);
1896 enumvals: enumvals ',' enumval {;}
1900 enumval: TOKEN '=' numtok {
1904 /* A float value, that's a bad enum */
1905 if (num[0] >= '0' &&
1907 strchr (num, '.') != NULL) {
1910 yyerror(_("parse error (enumerator value not integer constant)"));
1914 node = node_new (ENUMVALUE_NODE,
1915 "name:steal", $<id>1,
1918 enum_vals = g_list_append (enum_vals, node);
1923 node = node_new (ENUMVALUE_NODE,
1924 "name:steal", $<id>1,
1926 enum_vals = g_list_append (enum_vals, node);
1930 flagcode: FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
1931 Node *node = node_new (FLAGS_NODE,
1932 "ftype:steal", $<id>6,
1933 "prefix:steal", $<id>2,
1934 "values:steal", flag_vals,
1937 nodes = g_list_append (nodes, node);
1939 | FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
1940 Node *node = node_new (FLAGS_NODE,
1941 "ftype:steal", $<id>7,
1942 "prefix:steal", $<id>2,
1943 "values:steal", flag_vals,
1946 nodes = g_list_append (nodes, node);
1950 flagvals: flagvals ',' TOKEN {
1951 flag_vals = g_list_append (flag_vals, $<id>3);
1954 flag_vals = g_list_append (flag_vals, $<id>1);
1958 errorcode: ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
1959 Node *node = node_new (ERROR_NODE,
1960 "etype:steal", $<id>6,
1961 "prefix:steal", $<id>2,
1962 "values:steal", error_vals,
1965 nodes = g_list_append (nodes, node);
1967 | ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
1968 Node *node = node_new (ERROR_NODE,
1969 "etype:steal", $<id>7,
1970 "prefix:steal", $<id>2,
1971 "values:steal", error_vals,
1974 nodes = g_list_append (nodes, node);
1978 errorvals: errorvals ',' TOKEN {
1979 error_vals = g_list_append (error_vals, $<id>3);
1982 error_vals = g_list_append (error_vals, $<id>1);
1987 numtok: NUMBER { $<id>$ = $<id>1; }
1989 $<id>$ = g_strconcat("-",$<id>2,NULL);
1992 | SINGLE_CHAR { $<id>$ = $<id>1; }
1993 | TOKEN { $<id>$ = $<id>1; }