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);
504 cast = g_strdup ("void");
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"));
1038 if(strcmp($<id>6, "link")==0) {
1039 set = g_strdup_printf("%s->%s = ARG;",
1041 } else if(strcmp($<id>6, "stringlink")==0) {
1042 set = g_strdup_printf("g_free (%s->%s); "
1043 "%s->%s = g_strdup (ARG);",
1046 } else if(strcmp($<id>6, "objectlink")==0) {
1047 set = g_strdup_printf(
1049 "g_object_ref (G_OBJECT (ARG)); "
1050 "if (%s->%s != NULL) "
1051 "g_object_unref (G_OBJECT (%s->%s)); "
1057 g_assert_not_reached();
1060 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
1065 type = (Type *)node_copy ((Node *)var->vtype);
1067 node = node_new (ARGUMENT_NODE,
1068 "gtktype:steal", $<id>3,
1069 "atype:steal", type,
1070 "flags:steal", $<list>2,
1071 "name:steal", $<id>4,
1073 "get_line", $<line>1,
1075 "set_line", $<line>1,
1076 "line_no", $<line>1,
1079 if ($<id>5 != NULL) {
1080 Argument *arg = (Argument *)node;
1081 export_accessors (arg->name,
1082 arg->get != NULL, arg->get_line,
1083 arg->set != NULL, arg->set_line,
1090 class_nodes = g_list_append (class_nodes, node);
1094 export: '(' TOKEN ')' {
1095 if (strcmp ($<id>2, "export")!=0) {
1097 yyerror (_("parse error"));
1107 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1109 node_set ((Node *)property,
1110 "line_no", $<line>1,
1111 "gtktype:steal", debool ($<id>2),
1112 "name:steal", $<id>3,
1114 if (strcmp ($<id>5, "get") == 0 &&
1115 strcmp ($<id>8, "set") == 0) {
1116 node_set ((Node *)property,
1117 "get:steal", ($<cbuf>7)->str,
1118 "get_line", $<line>6,
1119 "set:steal", ($<cbuf>10)->str,
1120 "set_line", $<line>9,
1122 g_string_free ($<cbuf>7, FALSE);
1123 g_string_free ($<cbuf>10, FALSE);
1126 } else if (strcmp ($<id>5, "set") == 0 &&
1127 strcmp ($<id>8, "get") == 0) {
1128 node_set ((Node *)property,
1129 "get:steal", ($<cbuf>10)->str,
1130 "get_line", $<line>9,
1131 "set:steal", ($<cbuf>7)->str,
1132 "set_line", $<line>6,
1134 g_string_free ($<cbuf>7, FALSE);
1135 g_string_free ($<cbuf>10, FALSE);
1139 g_string_free ($<cbuf>7, TRUE);
1140 g_string_free ($<cbuf>10, TRUE);
1143 node_free ((Node *)property);
1145 yyerror (_("parse error"));
1148 property_link_and_export ((Node *)property);
1149 if (property != NULL) {
1150 class_nodes = g_list_append (class_nodes,
1155 | PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE ';' {
1157 node_set ((Node *)property,
1158 "line_no", $<line>1,
1159 "gtktype:steal", debool ($<id>2),
1160 "name:steal", $<id>3,
1162 if (strcmp ($<id>5, "get") == 0) {
1163 node_set ((Node *)property,
1164 "get:steal", ($<cbuf>7)->str,
1165 "get_line", $<line>6,
1167 g_string_free ($<cbuf>7, FALSE);
1169 } else if (strcmp ($<id>5, "set") == 0) {
1170 node_set ((Node *)property,
1171 "set:steal", ($<cbuf>7)->str,
1172 "set_line", $<line>6,
1174 g_string_free ($<cbuf>7, FALSE);
1177 g_string_free ($<cbuf>7, TRUE);
1179 node_free ((Node *)property);
1181 yyerror (_("parse error"));
1184 property_link_and_export ((Node *)property);
1185 if (property != NULL) {
1186 class_nodes = g_list_append (class_nodes,
1191 | PROPERTY TOKEN TOKEN param_spec ';' {
1193 node_set ((Node *)property,
1194 "line_no", $<line>1,
1195 "gtktype:steal", debool ($<id>2),
1196 "name:steal", $<id>3,
1198 property_link_and_export ((Node *)property);
1199 if (property != NULL) {
1200 class_nodes = g_list_append (class_nodes,
1207 param_spec: '(' param_spec_list ')' { ; }
1211 param_spec_list: param_spec_list ',' param_spec_value { ; }
1212 | param_spec_value { ; }
1215 string: STRING { $<id>$ = $<id>1; }
1216 | TOKEN '(' STRING ')' {
1217 if (strcmp ($<id>1, "_") != 0) {
1219 yyerror(_("parse error"));
1223 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1228 anyval: numtok { $<id>$ = $<id>1; }
1229 | string { $<id>$ = $<id>1; }
1232 param_spec_value: NICK '=' string {
1234 node_set ((Node *)property,
1235 "nick:steal", $<id>3,
1238 | BLURB '=' string {
1240 node_set ((Node *)property,
1241 "blurb:steal", $<id>3,
1244 | MAXIMUM '=' numtok {
1246 node_set ((Node *)property,
1247 "maximum:steal", $<id>3,
1250 | MINIMUM '=' numtok {
1252 node_set ((Node *)property,
1253 "minimum:steal", $<id>3,
1256 | DEFAULT_VALUE '=' anyval {
1258 node_set ((Node *)property,
1259 "default_value:steal", $<id>3,
1262 | FLAGS '=' flaglist {
1264 node_set ((Node *)property,
1265 "flags:steal", $<list>3,
1269 Type *type = pop_type ();
1271 node_set ((Node *)property,
1272 "ptype:steal", type,
1275 | FLAGS_TYPE '=' TYPETOKEN {
1277 node_set ((Node *)property,
1278 "extra_gtktype:steal", $<id>3,
1281 | FLAGS_TYPE '=' TOKEN {
1283 node_set ((Node *)property,
1284 "extra_gtktype:steal", $<id>3,
1287 | ENUM_TYPE '=' TYPETOKEN {
1289 node_set ((Node *)property,
1290 "extra_gtktype:steal", $<id>3,
1293 | ENUM_TYPE '=' TOKEN {
1295 node_set ((Node *)property,
1296 "extra_gtktype:steal", $<id>3,
1299 | PARAM_TYPE '=' TYPETOKEN {
1301 node_set ((Node *)property,
1302 "extra_gtktype:steal", $<id>3,
1305 | PARAM_TYPE '=' TOKEN {
1307 node_set ((Node *)property,
1308 "extra_gtktype:steal", $<id>3,
1311 | BOXED_TYPE '=' TYPETOKEN {
1313 node_set ((Node *)property,
1314 "extra_gtktype:steal", $<id>3,
1317 | BOXED_TYPE '=' TOKEN {
1319 node_set ((Node *)property,
1320 "extra_gtktype:steal", $<id>3,
1323 | OBJECT_TYPE '=' TYPETOKEN {
1325 node_set ((Node *)property,
1326 "extra_gtktype:steal", $<id>3,
1329 | OBJECT_TYPE '=' TOKEN {
1331 node_set ((Node *)property,
1332 "extra_gtktype:steal", $<id>3,
1337 if (strcmp ($<id>1, "link") == 0) {
1339 node_set ((Node *)property,
1342 } else if (strcmp ($<id>1, "export") == 0) {
1344 node_set ((Node *)property,
1349 yyerror(_("parse error"));
1355 argtype: TOKEN '(' TOKEN type ')' {
1356 if(strcmp($<id>3,"type")!=0) {
1359 yyerror(_("parse error"));
1362 $<id>$ = debool ($<id>1);
1365 $<id>$ = debool ($<id>1);
1366 typestack = g_list_prepend(typestack,NULL);
1370 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1371 | { $<list>$ = NULL; }
1374 flaglist: TOKEN '|' flaglist {
1375 $<list>$ = g_list_append($<list>3,$<id>1);
1378 $<list>$ = g_list_append(NULL,$<id>1);
1383 type: specifier_list pointer {
1384 Node *node = node_new (TYPE_NODE,
1385 "name:steal", $<id>1,
1386 "pointer:steal", $<id>2,
1388 typestack = g_list_prepend(typestack,node);
1391 Node *node = node_new (TYPE_NODE,
1392 "name:steal", $<id>1,
1394 typestack = g_list_prepend(typestack,node);
1398 /* The special cases are neccessary to avoid conflicts */
1399 specifier_list: spec_list {
1406 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1410 $<id>$ = g_strconcat($<id>1, " const", NULL);
1413 | strunionenum TOKEN {
1414 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1417 | CONST strunionenum TOKEN {
1418 $<id>$ = g_strconcat("const ", $<id>2, " ",
1422 | strunionenum TOKEN CONST {
1423 $<id>$ = g_strconcat($<id>1, " ",
1424 $<id>2, " const", NULL);
1429 /* The special const cases take care of conflicts ! */
1430 spec_list: specifier spec_list {
1431 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1434 | TYPETOKEN spec_list {
1435 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1440 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1447 $<id>$ = g_strconcat($<id>1, " const", NULL);
1451 $<id>$ = g_strdup($<id>1);
1454 $<id>$ = g_strconcat($<id>1, " const", NULL);
1458 specifier: VOID { $<id>$ = "void"; }
1459 | CHAR { $<id>$ = "char"; }
1460 | SHORT { $<id>$ = "short"; }
1461 | INT { $<id>$ = "int"; }
1462 | LONG { $<id>$ = "long"; }
1463 | FLOAT { $<id>$ = "float"; }
1464 | DOUBLE { $<id>$ = "double"; }
1465 | SIGNED { $<id>$ = "signed"; }
1466 | UNSIGNED { $<id>$ = "unsigned"; }
1469 strunionenum: STRUCT { $<id>$ = "struct"; }
1470 | UNION { $<id>$ = "union"; }
1471 | ENUM { $<id>$ = "enum"; }
1474 pointer: '*' { $<id>$ = g_strdup("*"); }
1475 | '*' CONST { $<id>$ = g_strdup("* const"); }
1477 $<id>$ = g_strconcat("*", $<id>2, NULL);
1480 | '*' CONST pointer {
1481 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1486 /* this never sets the_scope */
1487 simplesigtype: TOKEN sigtype {
1488 if(strcmp($<id>1, "first")==0)
1489 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1490 else if(strcmp($<id>1, "last")==0)
1491 $<sigtype>$ = SIGNAL_LAST_METHOD;
1493 yyerror(_("signal must be 'first' or 'last'"));
1500 $<sigtype>$ = SIGNAL_LAST_METHOD;
1504 /* this always sets the_scope */
1505 fullsigtype: scope TOKEN sigtype {
1506 if(strcmp($<id>2,"first")==0)
1507 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1508 else if(strcmp($<id>2,"last")==0)
1509 $<sigtype>$ = SIGNAL_LAST_METHOD;
1511 yyerror(_("signal must be 'first' or 'last'"));
1517 | TOKEN scope sigtype {
1518 if(strcmp($<id>1,"first")==0)
1519 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1520 else if(strcmp($<id>1,"last")==0)
1521 $<sigtype>$ = SIGNAL_LAST_METHOD;
1523 yyerror(_("signal must be 'first' or 'last'"));
1530 $<sigtype>$ = SIGNAL_LAST_METHOD;
1533 /* the_scope was default thus public */
1534 the_scope = PUBLIC_SCOPE;
1538 sigtype: TOKEN '(' tokenlist ')' {
1539 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1543 tokenlist: tokenlist ',' TOKEN {
1544 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1547 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1551 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1552 | ';' { $<cbuf>$ = NULL; }
1555 /*here CCODE will include the ending '}' */
1556 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1558 yyerror(_("signal without 'self' as "
1559 "first parameter"));
1560 free_all_global_state();
1563 if(the_scope == CLASS_SCOPE) {
1564 yyerror(_("a method cannot be of class scope"));
1565 free_all_global_state();
1568 push_function(the_scope, $<sigtype>3,NULL,
1569 $<id>5, $<cbuf>10,$<line>1,
1570 ccode_line, vararg, $<list>2);
1572 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1574 yyerror(_("signal without 'self' as "
1575 "first parameter"));
1576 free_all_global_state();
1579 if(the_scope == CLASS_SCOPE) {
1580 yyerror(_("a method cannot be of class scope"));
1581 free_all_global_state();
1584 push_function(the_scope, $<sigtype>4, NULL,
1585 $<id>6, $<cbuf>11, $<line>2,
1586 ccode_line, vararg, $<list>3);
1588 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1590 yyerror(_("virtual method without 'self' as "
1591 "first parameter"));
1592 free_all_global_state();
1595 if(the_scope == CLASS_SCOPE) {
1596 yyerror(_("a method cannot be of class scope"));
1597 free_all_global_state();
1600 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1602 ccode_line, vararg, NULL);
1604 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1606 yyerror(_("virtual method without 'self' as "
1607 "first parameter"));
1608 free_all_global_state();
1611 if(the_scope == CLASS_SCOPE) {
1612 yyerror(_("a method cannot be of class scope"));
1613 free_all_global_state();
1616 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1618 ccode_line, vararg, NULL);
1620 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1622 yyerror(_("virtual method without 'self' as "
1623 "first parameter"));
1624 free_all_global_state();
1627 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1628 $<id>3, $<cbuf>8, $<line>1,
1629 ccode_line, vararg, NULL);
1631 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1632 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1634 $<line>1, ccode_line,
1637 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1638 if(the_scope == CLASS_SCOPE) {
1639 yyerror(_("a method cannot be of class scope"));
1640 free_all_global_state();
1643 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1644 $<cbuf>8, $<line>1, ccode_line,
1647 | TOKEN '(' TOKEN ')' codenocode {
1648 if(strcmp($<id>1, "init")==0) {
1649 push_init_arg($<id>3,FALSE);
1650 push_function(NO_SCOPE, INIT_METHOD, NULL,
1651 $<id>1, $<cbuf>5, $<line>2,
1652 ccode_line, FALSE, NULL);
1653 } else if(strcmp($<id>1, "class_init")==0) {
1654 push_init_arg($<id>3,TRUE);
1655 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1656 $<id>1, $<cbuf>5, $<line>2,
1657 ccode_line, FALSE, NULL);
1661 g_string_free($<cbuf>5,TRUE);
1662 yyerror(_("parse error "
1663 "(untyped blocks must be init or "
1670 returnvals: TOKEN retcode {
1671 g_free(onerror); onerror = NULL;
1672 g_free(defreturn); defreturn = NULL;
1673 if(!set_return_value($<id>1, $<id>2)) {
1676 yyerror(_("parse error"));
1681 | TOKEN retcode TOKEN retcode {
1682 g_free(onerror); onerror = NULL;
1683 g_free(defreturn); defreturn = NULL;
1684 if(!set_return_value($<id>1, $<id>2)) {
1685 g_free($<id>1); g_free($<id>2);
1686 g_free($<id>3); g_free($<id>4);
1687 yyerror(_("parse error"));
1690 if(!set_return_value($<id>3, $<id>4)) {
1691 onerror = defreturn = NULL;
1692 g_free($<id>1); g_free($<id>2);
1693 g_free($<id>3); g_free($<id>4);
1694 yyerror(_("parse error"));
1701 g_free(onerror); onerror = NULL;
1702 g_free(defreturn); defreturn = NULL;
1706 retcode: numtok { $<id>$ = $<id>1; }
1708 $<id>$ = ($<cbuf>2)->str;
1709 g_string_free($<cbuf>2, FALSE);
1713 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1717 if(strcmp($<id>1,"self")==0)
1718 push_self($<id>1, FALSE);
1721 yyerror(_("parse error"));
1728 if(strcmp($<id>1,"self")==0)
1729 push_self($<id>1, TRUE);
1732 yyerror(_("parse error"));
1739 if(strcmp($<id>2,"self")==0)
1740 push_self($<id>2, TRUE);
1743 yyerror(_("parse error"));
1747 | TOKEN ',' arglist {
1749 if(strcmp($<id>1,"self")==0)
1750 push_self($<id>1, FALSE);
1753 yyerror(_("parse error"));
1757 | TOKEN CONST ',' arglist {
1759 if(strcmp($<id>1,"self")==0)
1760 push_self($<id>1, TRUE);
1763 yyerror(_("parse error"));
1767 | CONST TOKEN ',' arglist {
1769 if(strcmp($<id>2,"self")==0)
1770 push_self($<id>2, TRUE);
1773 yyerror(_("parse error"));
1777 | arglist { has_self = FALSE; }
1780 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1781 | arglist1 { vararg = FALSE; }
1784 arglist1: arglist1 ',' arg { ; }
1789 push_funcarg($<id>2,NULL);
1791 | type TOKEN ARRAY_DIM {
1792 push_funcarg($<id>2,$<id>3);
1794 | type TOKEN '(' TOKEN checklist ')' {
1795 if(strcmp($<id>4,"check")!=0) {
1796 yyerror(_("parse error"));
1800 push_funcarg($<id>2,NULL);
1802 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1803 if(strcmp($<id>5,"check")!=0) {
1804 yyerror(_("parse error"));
1808 push_funcarg($<id>2,$<id>3);
1812 checklist: checklist check { ; }
1817 if(strcmp($<id>1,"type")==0) {
1818 Node *node = node_new (CHECK_NODE,
1819 "chtype", TYPE_CHECK,
1821 checks = g_list_append(checks,node);
1822 } else if(strcmp($<id>1,"null")==0) {
1823 Node *node = node_new (CHECK_NODE,
1824 "chtype", NULL_CHECK,
1826 checks = g_list_append(checks,node);
1828 yyerror(_("parse error"));
1834 Node *node = node_new (CHECK_NODE,
1836 "number:steal", $<id>2,
1838 checks = g_list_append(checks,node);
1841 Node *node = node_new (CHECK_NODE,
1843 "number:steal", $<id>2,
1845 checks = g_list_append(checks,node);
1848 Node *node = node_new (CHECK_NODE,
1850 "number:steal", $<id>3,
1852 checks = g_list_append(checks,node);
1855 Node *node = node_new (CHECK_NODE,
1857 "number:steal", $<id>3,
1859 checks = g_list_append(checks,node);
1862 Node *node = node_new (CHECK_NODE,
1864 "number:steal", $<id>3,
1866 checks = g_list_append(checks,node);
1869 Node *node = node_new (CHECK_NODE,
1871 "number:steal", $<id>3,
1873 checks = g_list_append(checks,node);
1877 enumcode: ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
1878 Node *node = node_new (ENUMDEF_NODE,
1879 "etype:steal", $<id>6,
1880 "prefix:steal", $<id>2,
1881 "values:steal", enum_vals,
1884 nodes = g_list_append (nodes, node);
1886 | ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
1887 Node *node = node_new (ENUMDEF_NODE,
1888 "etype:steal", $<id>7,
1889 "prefix:steal", $<id>2,
1890 "values:steal", enum_vals,
1893 nodes = g_list_append (nodes, node);
1897 enumvals: enumvals ',' enumval {;}
1901 enumval: TOKEN '=' numtok {
1905 /* A float value, that's a bad enum */
1906 if (num[0] >= '0' &&
1908 strchr (num, '.') != NULL) {
1911 yyerror(_("parse error (enumerator value not integer constant)"));
1915 node = node_new (ENUMVALUE_NODE,
1916 "name:steal", $<id>1,
1919 enum_vals = g_list_append (enum_vals, node);
1924 node = node_new (ENUMVALUE_NODE,
1925 "name:steal", $<id>1,
1927 enum_vals = g_list_append (enum_vals, node);
1931 flagcode: FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
1932 Node *node = node_new (FLAGS_NODE,
1933 "ftype:steal", $<id>6,
1934 "prefix:steal", $<id>2,
1935 "values:steal", flag_vals,
1938 nodes = g_list_append (nodes, node);
1940 | FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
1941 Node *node = node_new (FLAGS_NODE,
1942 "ftype:steal", $<id>7,
1943 "prefix:steal", $<id>2,
1944 "values:steal", flag_vals,
1947 nodes = g_list_append (nodes, node);
1951 flagvals: flagvals ',' TOKEN {
1952 flag_vals = g_list_append (flag_vals, $<id>3);
1955 flag_vals = g_list_append (flag_vals, $<id>1);
1959 errorcode: ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
1960 Node *node = node_new (ERROR_NODE,
1961 "etype:steal", $<id>6,
1962 "prefix:steal", $<id>2,
1963 "values:steal", error_vals,
1966 nodes = g_list_append (nodes, node);
1968 | ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
1969 Node *node = node_new (ERROR_NODE,
1970 "etype:steal", $<id>7,
1971 "prefix:steal", $<id>2,
1972 "values:steal", error_vals,
1975 nodes = g_list_append (nodes, node);
1979 errorvals: errorvals ',' TOKEN {
1980 error_vals = g_list_append (error_vals, $<id>3);
1983 error_vals = g_list_append (error_vals, $<id>1);
1988 numtok: NUMBER { $<id>$ = $<id>1; }
1990 $<id>$ = g_strconcat("-",$<id>2,NULL);
1993 | SINGLE_CHAR { $<id>$ = $<id>1; }
1994 | TOKEN { $<id>$ = $<id>1; }