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 char *type = make_me_type (prop->extra_gtktype,
522 if (prop->extra_gtktype == NULL) {
523 error_print (GOB_ERROR, prop->line_no,
524 _("Property linking requested for BOXED, but "
525 "boxed_type not set"));
527 set = g_strdup_printf("{ gpointer ___old = (gpointer)%s->%s; "
528 "gpointer ___new = (gpointer)g_value_get_boxed (VAL); "
529 "if (___new != ___old) { "
530 "if (___old != NULL) g_boxed_free (%s, ___old); "
531 "if (___new != NULL) %s->%s = g_boxed_copy (%s, ___new); "
532 "else %s->%s = NULL;"
540 get = g_strdup_printf("g_value_set_boxed (VAL, %s->%s);",
546 const char *getcast = "";
547 const char *setcast = "";
548 char *to_free = NULL;
549 set_func = g_strdup_printf ("g_value_set_%s", prop->gtktype);
550 g_strdown (set_func);
551 get_func = g_strdup_printf ("g_value_get_%s", prop->gtktype);
552 g_strdown (get_func);
554 if (strcmp (prop->gtktype, "FLAGS") == 0) {
555 setcast = "(guint) ";
557 get_prop_enum_flag_cast (prop);
558 } else if (strcmp (prop->gtktype, "ENUM") == 0) {
561 get_prop_enum_flag_cast (prop);
564 set = g_strdup_printf("%s->%s = %s%s (VAL);",
568 get = g_strdup_printf("%s (VAL, %s%s->%s);",
580 "get_line", prop->line_no,
582 "set_line", prop->line_no,
587 export_accessors (prop->name,
588 prop->get != NULL, prop->get_line,
589 prop->set != NULL, prop->set_line,
600 if (strcmp (s, "BOOL") == 0) {
601 error_print (GOB_WARN, line_no,
602 _("BOOL type is deprecated, please use BOOLEAN"));
604 return g_strdup ("BOOLEAN");
611 ensure_property (void)
613 if (property == NULL)
614 property = (Property *)node_new (PROPERTY_NODE, NULL);
628 %token CONST VOID STRUCT UNION ENUM THREEDOTS
629 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
631 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM SINGLE_CHAR
632 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE STRING
633 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE PROPERTY ARGUMENT
634 %token <line> VIRTUAL SIGNAL OVERRIDE
635 %token <line> NICK BLURB MAXIMUM MINIMUM DEFAULT_VALUE ERROR FLAGS TYPE
636 %token <line> FLAGS_TYPE ENUM_TYPE PARAM_TYPE BOXED_TYPE OBJECT_TYPE
640 prog: ccodes class ccodes { ; }
647 Node *node = node_new (CCODE_NODE,
649 "cbuf:steal", ($<cbuf>1)->str,
650 "line_no", ccode_line,
652 nodes = g_list_append(nodes,node);
653 g_string_free($<cbuf>1,FALSE);
656 Node *node = node_new (CCODE_NODE,
658 "cbuf:steal", ($<cbuf>1)->str,
659 "line_no", ccode_line,
661 nodes = g_list_append(nodes,node);
662 g_string_free($<cbuf>1,FALSE);
665 Node *node = node_new (CCODE_NODE,
667 "cbuf:steal", ($<cbuf>1)->str,
668 "line_no", ccode_line,
670 nodes = g_list_append(nodes,node);
671 g_string_free($<cbuf>1,FALSE);
674 Node *node = node_new (CCODE_NODE,
676 "cbuf:steal", ($<cbuf>1)->str,
677 "line_no", ccode_line,
679 nodes = g_list_append(nodes,node);
680 g_string_free($<cbuf>1,FALSE);
683 Node *node = node_new (CCODE_NODE,
685 "cbuf:steal", ($<cbuf>1)->str,
686 "line_no", ccode_line,
688 nodes = g_list_append(nodes,node);
689 g_string_free($<cbuf>1,FALSE);
692 Node *node = node_new (CCODE_NODE,
694 "cbuf:steal", ($<cbuf>1)->str,
695 "line_no", ccode_line,
697 nodes = g_list_append(nodes,node);
698 g_string_free($<cbuf>1,FALSE);
702 ccodes: ccodes ccode { ; }
703 | ccodes enumcode { ; }
704 | ccodes flagcode { ; }
705 | ccodes errorcode { ; }
712 class: classdec '{' classcode '}' {
713 ((Class *)class)->nodes = class_nodes;
715 nodes = g_list_append(nodes,class);
718 ((Class *)class)->nodes = NULL;
720 nodes = g_list_append(nodes,class);
724 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
725 class = node_new (CLASS_NODE,
726 "otype:steal", $<id>2,
727 "ptype:steal", $<id>4,
728 "bonobo_object_class:steal", bonobo_object_class,
729 "interfaces:steal", interfaces,
730 "chunk_size:steal", chunk_size,
732 bonobo_object_class = NULL;
739 | '(' TOKEN TOKEN ')' classflags {
740 if(strcmp($<id>2,"chunks") == 0) {
742 chunk_size = g_strdup($<id>3);
743 } else if(strcmp($<id>2,"BonoboObject") == 0) {
744 g_free (bonobo_object_class);
745 bonobo_object_class = g_strdup($<id>3);
747 yyerror(_("parse error"));
751 | '(' TOKEN TYPETOKEN ')' classflags {
752 if (strcmp ($<id>2, "interface") == 0) {
753 interfaces = g_list_append (interfaces,
756 yyerror(_("parse error"));
760 | '(' TOKEN NUMBER ')' classflags {
761 if(strcmp($<id>2,"chunks") == 0) {
763 if(atoi($<id>3) != 0)
764 chunk_size = g_strdup($<id>3);
768 yyerror(_("parse error"));
774 classcode: classcode thing { ; }
780 if (strcmp ($<id>1, "BonoboObject") != 0) {
782 yyerror (_("parse error"));
786 last_added_method->bonobo_object_func = TRUE;
788 | TOKEN TYPETOKEN method {
789 if (strcmp ($<id>1, "interface") != 0) {
792 yyerror (_("parse error"));
796 node_set ((Node *)last_added_method,
797 "interface:steal", $<id>2,
806 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
807 | PRIVATE { the_scope = PRIVATE_SCOPE; }
808 | PROTECTED { the_scope = PROTECTED_SCOPE; }
809 | CLASSWIDE { the_scope = CLASS_SCOPE; }
812 destructor: TOKEN TOKEN {
813 if (strcmp ($<id>1, "destroywith") == 0) {
815 destructor_unref = FALSE;
817 destructor_line = line_no;
818 destructor_simple = TRUE;
819 } else if (strcmp ($<id>1, "unrefwith") == 0) {
821 destructor_unref = TRUE;
823 destructor_line = line_no;
824 destructor_simple = TRUE;
828 yyerror (_("parse error"));
833 if (strcmp ($<id>1, "destroy") == 0) {
835 destructor_unref = FALSE;
836 destructor = ($<cbuf>3)->str;
837 g_string_free($<cbuf>3, FALSE);
838 destructor_line = ccode_line;
839 destructor_simple = FALSE;
840 } else if (strcmp ($<id>1, "unref") == 0) {
842 destructor_unref = TRUE;
843 destructor = ($<cbuf>3)->str;
844 g_string_free ($<cbuf>3, FALSE);
845 destructor_line = ccode_line;
846 destructor_simple = FALSE;
849 g_string_free ($<cbuf>3, TRUE);
850 yyerror (_("parse error"));
856 initializer: '=' numtok {
857 initializer = $<id>2;
858 initializer_line = ccode_line;
861 initializer = ($<cbuf>3)->str;
862 initializer_line = ccode_line;
863 g_string_free($<cbuf>3, FALSE);
868 varoptions: destructor initializer { ; }
869 | initializer destructor { ; }
870 | initializer { destructor = NULL; }
871 | destructor { initializer = NULL; }
878 variable: scope type TOKEN varoptions ';' {
879 push_variable($<id>3, the_scope,$<line>1, NULL);
881 | scope type TOKEN ARRAY_DIM varoptions ';' {
882 push_variable($<id>3, the_scope, $<line>1, $<id>4);
886 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
888 if(strcmp($<id>6,"get")==0 &&
889 strcmp($<id>9,"set")==0) {
890 Type *type = pop_type();
893 node = node_new (ARGUMENT_NODE,
894 "gtktype:steal", $<id>3,
896 "flags:steal", $<list>2,
897 "name:steal", $<id>4,
898 "get:steal", ($<cbuf>8)->str,
899 "get_line", $<line>7,
900 "set:steal", ($<cbuf>11)->str,
901 "set_line", $<line>10,
905 class_nodes = g_list_append(class_nodes,node);
907 g_string_free ($<cbuf>8, FALSE);
908 g_string_free ($<cbuf>11, FALSE);
910 } else if(strcmp($<id>6,"set")==0 &&
911 strcmp($<id>9,"get")==0) {
912 Type *type = pop_type();
915 node = node_new (ARGUMENT_NODE,
916 "gtktype:steal", $<id>3,
918 "flags:steal", $<list>2,
919 "name:steal", $<id>4,
920 "get:steal", ($<cbuf>11)->str,
921 "get_line", $<line>10,
922 "set:steal", ($<cbuf>8)->str,
923 "set_line", $<line>7,
926 g_string_free ($<cbuf>11, FALSE);
927 g_string_free ($<cbuf>8, FALSE);
928 class_nodes = g_list_append(class_nodes,node);
934 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
935 g_list_free ($<list>2);
936 g_string_free ($<cbuf>11, TRUE);
937 g_string_free ($<cbuf>8, TRUE);
938 yyerror (_("parse error"));
942 if ($<id>5 != NULL) {
943 Argument *arg = (Argument *)node;
944 export_accessors (arg->name,
945 arg->get != NULL, arg->get_line,
946 arg->set != NULL, arg->set_line,
954 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
956 if(strcmp($<id>6, "get") == 0) {
957 Type *type = pop_type();
959 node = node_new (ARGUMENT_NODE,
960 "gtktype:steal", $<id>3,
962 "flags:steal", $<list>2,
963 "name:steal", $<id>4,
964 "get:steal", ($<cbuf>8)->str,
965 "get_line", $<line>7,
969 g_string_free ($<cbuf>8, FALSE);
970 class_nodes = g_list_append(class_nodes, node);
971 } else if(strcmp($<id>6, "set") == 0) {
972 Type *type = pop_type();
974 node = node_new (ARGUMENT_NODE,
975 "gtktype:steal", $<id>3,
977 "flags:steal", $<list>2,
978 "name:steal", $<id>4,
979 "set:steal", ($<cbuf>8)->str,
980 "set_line", $<line>7,
984 g_string_free ($<cbuf>8, FALSE);
985 class_nodes = g_list_append (class_nodes, node);
990 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
991 g_list_free ($<list>2);
992 g_string_free ($<cbuf>8, TRUE);
993 yyerror(_("parse error"));
997 if ($<id>5 != NULL) {
998 Argument *arg = (Argument *)node;
999 export_accessors (arg->name,
1000 arg->get != NULL, arg->get_line,
1001 arg->set != NULL, arg->set_line,
1008 | ARGUMENT flags argtype TOKEN export TOKEN {
1010 char *get, *set = NULL;
1015 if(strcmp($<id>6, "link")!=0 &&
1016 strcmp($<id>6, "stringlink")!=0 &&
1017 strcmp($<id>6, "objectlink")!=0) {
1021 g_list_foreach($<list>2,(GFunc)g_free,NULL);
1022 g_list_free($<list>2);
1023 yyerror(_("parse error"));
1029 var = find_var_or_die($<id>4, $<line>1);
1030 if(var->scope == PRIVATE_SCOPE) {
1031 root = "self->_priv";
1032 } else if(var->scope == CLASS_SCOPE) {
1033 root = "SELF_GET_CLASS(self)";
1035 error_print(GOB_ERROR, $<line>1,
1036 _("Self aliases needed when autolinking to a classwide member"));
1041 if(strcmp($<id>6, "link")==0) {
1042 set = g_strdup_printf("%s->%s = ARG;",
1044 } else if(strcmp($<id>6, "stringlink")==0) {
1045 set = g_strdup_printf("g_free (%s->%s); "
1046 "%s->%s = g_strdup (ARG);",
1049 } else if(strcmp($<id>6, "objectlink")==0) {
1050 set = g_strdup_printf(
1052 "g_object_ref (G_OBJECT (ARG)); "
1053 "if (%s->%s != NULL) "
1054 "g_object_unref (G_OBJECT (%s->%s)); "
1060 g_assert_not_reached();
1063 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
1068 type = (Type *)node_copy ((Node *)var->vtype);
1070 node = node_new (ARGUMENT_NODE,
1071 "gtktype:steal", $<id>3,
1072 "atype:steal", type,
1073 "flags:steal", $<list>2,
1074 "name:steal", $<id>4,
1076 "get_line", $<line>1,
1078 "set_line", $<line>1,
1079 "line_no", $<line>1,
1082 if ($<id>5 != NULL) {
1083 Argument *arg = (Argument *)node;
1084 export_accessors (arg->name,
1085 arg->get != NULL, arg->get_line,
1086 arg->set != NULL, arg->set_line,
1093 class_nodes = g_list_append (class_nodes, node);
1097 export: '(' TOKEN ')' {
1098 if (strcmp ($<id>2, "export")!=0) {
1100 yyerror (_("parse error"));
1110 property: PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE TOKEN '{' CCODE ';' {
1112 node_set ((Node *)property,
1113 "line_no", $<line>1,
1114 "gtktype:steal", debool ($<id>2),
1115 "name:steal", $<id>3,
1117 if (strcmp ($<id>5, "get") == 0 &&
1118 strcmp ($<id>8, "set") == 0) {
1119 node_set ((Node *)property,
1120 "get:steal", ($<cbuf>7)->str,
1121 "get_line", $<line>6,
1122 "set:steal", ($<cbuf>10)->str,
1123 "set_line", $<line>9,
1125 g_string_free ($<cbuf>7, FALSE);
1126 g_string_free ($<cbuf>10, FALSE);
1129 } else if (strcmp ($<id>5, "set") == 0 &&
1130 strcmp ($<id>8, "get") == 0) {
1131 node_set ((Node *)property,
1132 "get:steal", ($<cbuf>10)->str,
1133 "get_line", $<line>9,
1134 "set:steal", ($<cbuf>7)->str,
1135 "set_line", $<line>6,
1137 g_string_free ($<cbuf>7, FALSE);
1138 g_string_free ($<cbuf>10, FALSE);
1142 g_string_free ($<cbuf>7, TRUE);
1143 g_string_free ($<cbuf>10, TRUE);
1146 node_free ((Node *)property);
1148 yyerror (_("parse error"));
1151 property_link_and_export ((Node *)property);
1152 if (property != NULL) {
1153 class_nodes = g_list_append (class_nodes,
1158 | PROPERTY TOKEN TOKEN param_spec TOKEN '{' CCODE ';' {
1160 node_set ((Node *)property,
1161 "line_no", $<line>1,
1162 "gtktype:steal", debool ($<id>2),
1163 "name:steal", $<id>3,
1165 if (strcmp ($<id>5, "get") == 0) {
1166 node_set ((Node *)property,
1167 "get:steal", ($<cbuf>7)->str,
1168 "get_line", $<line>6,
1170 g_string_free ($<cbuf>7, FALSE);
1172 } else if (strcmp ($<id>5, "set") == 0) {
1173 node_set ((Node *)property,
1174 "set:steal", ($<cbuf>7)->str,
1175 "set_line", $<line>6,
1177 g_string_free ($<cbuf>7, FALSE);
1180 g_string_free ($<cbuf>7, TRUE);
1182 node_free ((Node *)property);
1184 yyerror (_("parse error"));
1187 property_link_and_export ((Node *)property);
1188 if (property != NULL) {
1189 class_nodes = g_list_append (class_nodes,
1194 | PROPERTY TOKEN TOKEN param_spec ';' {
1196 node_set ((Node *)property,
1197 "line_no", $<line>1,
1198 "gtktype:steal", debool ($<id>2),
1199 "name:steal", $<id>3,
1201 property_link_and_export ((Node *)property);
1202 if (property != NULL) {
1203 class_nodes = g_list_append (class_nodes,
1210 param_spec: '(' param_spec_list ')' { ; }
1214 param_spec_list: param_spec_list ',' param_spec_value { ; }
1215 | param_spec_value { ; }
1218 string: STRING { $<id>$ = $<id>1; }
1219 | TOKEN '(' STRING ')' {
1220 if (strcmp ($<id>1, "_") != 0) {
1222 yyerror(_("parse error"));
1226 $<id>$ = g_strconcat ("_(", $<id>3, ")", NULL);
1231 anyval: numtok { $<id>$ = $<id>1; }
1232 | string { $<id>$ = $<id>1; }
1235 param_spec_value: NICK '=' string {
1237 node_set ((Node *)property,
1238 "nick:steal", $<id>3,
1241 | BLURB '=' string {
1243 node_set ((Node *)property,
1244 "blurb:steal", $<id>3,
1247 | MAXIMUM '=' numtok {
1249 node_set ((Node *)property,
1250 "maximum:steal", $<id>3,
1253 | MINIMUM '=' numtok {
1255 node_set ((Node *)property,
1256 "minimum:steal", $<id>3,
1259 | DEFAULT_VALUE '=' anyval {
1261 node_set ((Node *)property,
1262 "default_value:steal", $<id>3,
1265 | FLAGS '=' flaglist {
1267 node_set ((Node *)property,
1268 "flags:steal", $<list>3,
1272 Type *type = pop_type ();
1274 node_set ((Node *)property,
1275 "ptype:steal", type,
1278 | FLAGS_TYPE '=' TYPETOKEN {
1280 node_set ((Node *)property,
1281 "extra_gtktype:steal", $<id>3,
1284 | FLAGS_TYPE '=' TOKEN {
1286 node_set ((Node *)property,
1287 "extra_gtktype:steal", $<id>3,
1290 | ENUM_TYPE '=' TYPETOKEN {
1292 node_set ((Node *)property,
1293 "extra_gtktype:steal", $<id>3,
1296 | ENUM_TYPE '=' TOKEN {
1298 node_set ((Node *)property,
1299 "extra_gtktype:steal", $<id>3,
1302 | PARAM_TYPE '=' TYPETOKEN {
1304 node_set ((Node *)property,
1305 "extra_gtktype:steal", $<id>3,
1308 | PARAM_TYPE '=' TOKEN {
1310 node_set ((Node *)property,
1311 "extra_gtktype:steal", $<id>3,
1314 | BOXED_TYPE '=' TYPETOKEN {
1316 node_set ((Node *)property,
1317 "extra_gtktype:steal", $<id>3,
1320 | BOXED_TYPE '=' TOKEN {
1322 node_set ((Node *)property,
1323 "extra_gtktype:steal", $<id>3,
1326 | OBJECT_TYPE '=' TYPETOKEN {
1328 node_set ((Node *)property,
1329 "extra_gtktype:steal", $<id>3,
1332 | OBJECT_TYPE '=' TOKEN {
1334 node_set ((Node *)property,
1335 "extra_gtktype:steal", $<id>3,
1340 if (strcmp ($<id>1, "link") == 0) {
1342 node_set ((Node *)property,
1345 } else if (strcmp ($<id>1, "export") == 0) {
1347 node_set ((Node *)property,
1352 yyerror(_("parse error"));
1358 argtype: TOKEN '(' TOKEN type ')' {
1359 if(strcmp($<id>3,"type")!=0) {
1362 yyerror(_("parse error"));
1365 $<id>$ = debool ($<id>1);
1368 $<id>$ = debool ($<id>1);
1369 typestack = g_list_prepend(typestack,NULL);
1373 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
1374 | { $<list>$ = NULL; }
1377 flaglist: TOKEN '|' flaglist {
1378 $<list>$ = g_list_append($<list>3,$<id>1);
1381 $<list>$ = g_list_append(NULL,$<id>1);
1386 type: specifier_list pointer {
1387 Node *node = node_new (TYPE_NODE,
1388 "name:steal", $<id>1,
1389 "pointer:steal", $<id>2,
1391 typestack = g_list_prepend(typestack,node);
1394 Node *node = node_new (TYPE_NODE,
1395 "name:steal", $<id>1,
1397 typestack = g_list_prepend(typestack,node);
1401 /* The special cases are neccessary to avoid conflicts */
1402 specifier_list: spec_list {
1409 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1413 $<id>$ = g_strconcat($<id>1, " const", NULL);
1416 | strunionenum TOKEN {
1417 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1420 | CONST strunionenum TOKEN {
1421 $<id>$ = g_strconcat("const ", $<id>2, " ",
1425 | strunionenum TOKEN CONST {
1426 $<id>$ = g_strconcat($<id>1, " ",
1427 $<id>2, " const", NULL);
1432 /* The special const cases take care of conflicts ! */
1433 spec_list: specifier spec_list {
1434 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1437 | TYPETOKEN spec_list {
1438 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
1443 $<id>$ = g_strconcat("const ", $<id>2, NULL);
1450 $<id>$ = g_strconcat($<id>1, " const", NULL);
1454 $<id>$ = g_strdup($<id>1);
1457 $<id>$ = g_strconcat($<id>1, " const", NULL);
1461 specifier: VOID { $<id>$ = "void"; }
1462 | CHAR { $<id>$ = "char"; }
1463 | SHORT { $<id>$ = "short"; }
1464 | INT { $<id>$ = "int"; }
1465 | LONG { $<id>$ = "long"; }
1466 | FLOAT { $<id>$ = "float"; }
1467 | DOUBLE { $<id>$ = "double"; }
1468 | SIGNED { $<id>$ = "signed"; }
1469 | UNSIGNED { $<id>$ = "unsigned"; }
1472 strunionenum: STRUCT { $<id>$ = "struct"; }
1473 | UNION { $<id>$ = "union"; }
1474 | ENUM { $<id>$ = "enum"; }
1477 pointer: '*' { $<id>$ = g_strdup("*"); }
1478 | '*' CONST { $<id>$ = g_strdup("* const"); }
1480 $<id>$ = g_strconcat("*", $<id>2, NULL);
1483 | '*' CONST pointer {
1484 $<id>$ = g_strconcat("* const", $<id>3, NULL);
1489 /* this never sets the_scope */
1490 simplesigtype: TOKEN sigtype {
1491 if(strcmp($<id>1, "first")==0)
1492 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1493 else if(strcmp($<id>1, "last")==0)
1494 $<sigtype>$ = SIGNAL_LAST_METHOD;
1496 yyerror(_("signal must be 'first' or 'last'"));
1503 $<sigtype>$ = SIGNAL_LAST_METHOD;
1507 /* this always sets the_scope */
1508 fullsigtype: scope TOKEN sigtype {
1509 if(strcmp($<id>2,"first")==0)
1510 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1511 else if(strcmp($<id>2,"last")==0)
1512 $<sigtype>$ = SIGNAL_LAST_METHOD;
1514 yyerror(_("signal must be 'first' or 'last'"));
1520 | TOKEN scope sigtype {
1521 if(strcmp($<id>1,"first")==0)
1522 $<sigtype>$ = SIGNAL_FIRST_METHOD;
1523 else if(strcmp($<id>1,"last")==0)
1524 $<sigtype>$ = SIGNAL_LAST_METHOD;
1526 yyerror(_("signal must be 'first' or 'last'"));
1533 $<sigtype>$ = SIGNAL_LAST_METHOD;
1536 /* the_scope was default thus public */
1537 the_scope = PUBLIC_SCOPE;
1541 sigtype: TOKEN '(' tokenlist ')' {
1542 gtktypes = g_list_prepend(gtktypes, debool ($<id>1));
1546 tokenlist: tokenlist ',' TOKEN {
1547 gtktypes = g_list_append(gtktypes, debool ($<id>3));
1550 gtktypes = g_list_append(gtktypes, debool ($<id>1));
1554 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
1555 | ';' { $<cbuf>$ = NULL; }
1558 /*here CCODE will include the ending '}' */
1559 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1561 yyerror(_("signal without 'self' as "
1562 "first parameter"));
1563 free_all_global_state();
1566 if(the_scope == CLASS_SCOPE) {
1567 yyerror(_("a method cannot be of class scope"));
1568 free_all_global_state();
1571 push_function(the_scope, $<sigtype>3,NULL,
1572 $<id>5, $<cbuf>10,$<line>1,
1573 ccode_line, vararg, $<list>2);
1575 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
1577 yyerror(_("signal without 'self' as "
1578 "first parameter"));
1579 free_all_global_state();
1582 if(the_scope == CLASS_SCOPE) {
1583 yyerror(_("a method cannot be of class scope"));
1584 free_all_global_state();
1587 push_function(the_scope, $<sigtype>4, NULL,
1588 $<id>6, $<cbuf>11, $<line>2,
1589 ccode_line, vararg, $<list>3);
1591 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1593 yyerror(_("virtual method without 'self' as "
1594 "first parameter"));
1595 free_all_global_state();
1598 if(the_scope == CLASS_SCOPE) {
1599 yyerror(_("a method cannot be of class scope"));
1600 free_all_global_state();
1603 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1605 ccode_line, vararg, NULL);
1607 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1609 yyerror(_("virtual method without 'self' as "
1610 "first parameter"));
1611 free_all_global_state();
1614 if(the_scope == CLASS_SCOPE) {
1615 yyerror(_("a method cannot be of class scope"));
1616 free_all_global_state();
1619 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1621 ccode_line, vararg, NULL);
1623 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1625 yyerror(_("virtual method without 'self' as "
1626 "first parameter"));
1627 free_all_global_state();
1630 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1631 $<id>3, $<cbuf>8, $<line>1,
1632 ccode_line, vararg, NULL);
1634 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1635 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1637 $<line>1, ccode_line,
1640 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1641 if(the_scope == CLASS_SCOPE) {
1642 yyerror(_("a method cannot be of class scope"));
1643 free_all_global_state();
1646 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1647 $<cbuf>8, $<line>1, ccode_line,
1650 | TOKEN '(' TOKEN ')' codenocode {
1651 if(strcmp($<id>1, "init")==0) {
1652 push_init_arg($<id>3,FALSE);
1653 push_function(NO_SCOPE, INIT_METHOD, NULL,
1654 $<id>1, $<cbuf>5, $<line>2,
1655 ccode_line, FALSE, NULL);
1656 } else if(strcmp($<id>1, "class_init")==0) {
1657 push_init_arg($<id>3,TRUE);
1658 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1659 $<id>1, $<cbuf>5, $<line>2,
1660 ccode_line, FALSE, NULL);
1664 g_string_free($<cbuf>5,TRUE);
1665 yyerror(_("parse error "
1666 "(untyped blocks must be init or "
1673 returnvals: TOKEN retcode {
1674 g_free(onerror); onerror = NULL;
1675 g_free(defreturn); defreturn = NULL;
1676 if(!set_return_value($<id>1, $<id>2)) {
1679 yyerror(_("parse error"));
1684 | TOKEN retcode TOKEN retcode {
1685 g_free(onerror); onerror = NULL;
1686 g_free(defreturn); defreturn = NULL;
1687 if(!set_return_value($<id>1, $<id>2)) {
1688 g_free($<id>1); g_free($<id>2);
1689 g_free($<id>3); g_free($<id>4);
1690 yyerror(_("parse error"));
1693 if(!set_return_value($<id>3, $<id>4)) {
1694 onerror = defreturn = NULL;
1695 g_free($<id>1); g_free($<id>2);
1696 g_free($<id>3); g_free($<id>4);
1697 yyerror(_("parse error"));
1704 g_free(onerror); onerror = NULL;
1705 g_free(defreturn); defreturn = NULL;
1709 retcode: numtok { $<id>$ = $<id>1; }
1711 $<id>$ = ($<cbuf>2)->str;
1712 g_string_free($<cbuf>2, FALSE);
1716 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1720 if(strcmp($<id>1,"self")==0)
1721 push_self($<id>1, FALSE);
1724 yyerror(_("parse error"));
1731 if(strcmp($<id>1,"self")==0)
1732 push_self($<id>1, TRUE);
1735 yyerror(_("parse error"));
1742 if(strcmp($<id>2,"self")==0)
1743 push_self($<id>2, TRUE);
1746 yyerror(_("parse error"));
1750 | TOKEN ',' arglist {
1752 if(strcmp($<id>1,"self")==0)
1753 push_self($<id>1, FALSE);
1756 yyerror(_("parse error"));
1760 | TOKEN CONST ',' arglist {
1762 if(strcmp($<id>1,"self")==0)
1763 push_self($<id>1, TRUE);
1766 yyerror(_("parse error"));
1770 | CONST TOKEN ',' arglist {
1772 if(strcmp($<id>2,"self")==0)
1773 push_self($<id>2, TRUE);
1776 yyerror(_("parse error"));
1780 | arglist { has_self = FALSE; }
1783 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1784 | arglist1 { vararg = FALSE; }
1787 arglist1: arglist1 ',' arg { ; }
1792 push_funcarg($<id>2,NULL);
1794 | type TOKEN ARRAY_DIM {
1795 push_funcarg($<id>2,$<id>3);
1797 | type TOKEN '(' TOKEN checklist ')' {
1798 if(strcmp($<id>4,"check")!=0) {
1799 yyerror(_("parse error"));
1803 push_funcarg($<id>2,NULL);
1805 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1806 if(strcmp($<id>5,"check")!=0) {
1807 yyerror(_("parse error"));
1811 push_funcarg($<id>2,$<id>3);
1815 checklist: checklist check { ; }
1820 if(strcmp($<id>1,"type")==0) {
1821 Node *node = node_new (CHECK_NODE,
1822 "chtype", TYPE_CHECK,
1824 checks = g_list_append(checks,node);
1825 } else if(strcmp($<id>1,"null")==0) {
1826 Node *node = node_new (CHECK_NODE,
1827 "chtype", NULL_CHECK,
1829 checks = g_list_append(checks,node);
1831 yyerror(_("parse error"));
1837 Node *node = node_new (CHECK_NODE,
1839 "number:steal", $<id>2,
1841 checks = g_list_append(checks,node);
1844 Node *node = node_new (CHECK_NODE,
1846 "number:steal", $<id>2,
1848 checks = g_list_append(checks,node);
1851 Node *node = node_new (CHECK_NODE,
1853 "number:steal", $<id>3,
1855 checks = g_list_append(checks,node);
1858 Node *node = node_new (CHECK_NODE,
1860 "number:steal", $<id>3,
1862 checks = g_list_append(checks,node);
1865 Node *node = node_new (CHECK_NODE,
1867 "number:steal", $<id>3,
1869 checks = g_list_append(checks,node);
1872 Node *node = node_new (CHECK_NODE,
1874 "number:steal", $<id>3,
1876 checks = g_list_append(checks,node);
1880 enumcode: ENUM TOKEN '{' enumvals '}' TYPETOKEN ';' {
1881 Node *node = node_new (ENUMDEF_NODE,
1882 "etype:steal", $<id>6,
1883 "prefix:steal", $<id>2,
1884 "values:steal", enum_vals,
1887 nodes = g_list_append (nodes, node);
1889 | ENUM TOKEN '{' enumvals ',' '}' TYPETOKEN ';' {
1890 Node *node = node_new (ENUMDEF_NODE,
1891 "etype:steal", $<id>7,
1892 "prefix:steal", $<id>2,
1893 "values:steal", enum_vals,
1896 nodes = g_list_append (nodes, node);
1900 enumvals: enumvals ',' enumval {;}
1904 enumval: TOKEN '=' numtok {
1908 /* A float value, that's a bad enum */
1909 if (num[0] >= '0' &&
1911 strchr (num, '.') != NULL) {
1914 yyerror(_("parse error (enumerator value not integer constant)"));
1918 node = node_new (ENUMVALUE_NODE,
1919 "name:steal", $<id>1,
1922 enum_vals = g_list_append (enum_vals, node);
1927 node = node_new (ENUMVALUE_NODE,
1928 "name:steal", $<id>1,
1930 enum_vals = g_list_append (enum_vals, node);
1934 flagcode: FLAGS TOKEN '{' flagvals '}' TYPETOKEN ';' {
1935 Node *node = node_new (FLAGS_NODE,
1936 "ftype:steal", $<id>6,
1937 "prefix:steal", $<id>2,
1938 "values:steal", flag_vals,
1941 nodes = g_list_append (nodes, node);
1943 | FLAGS TOKEN '{' flagvals ',' '}' TYPETOKEN ';' {
1944 Node *node = node_new (FLAGS_NODE,
1945 "ftype:steal", $<id>7,
1946 "prefix:steal", $<id>2,
1947 "values:steal", flag_vals,
1950 nodes = g_list_append (nodes, node);
1954 flagvals: flagvals ',' TOKEN {
1955 flag_vals = g_list_append (flag_vals, $<id>3);
1958 flag_vals = g_list_append (flag_vals, $<id>1);
1962 errorcode: ERROR TOKEN '{' errorvals '}' TYPETOKEN ';' {
1963 Node *node = node_new (ERROR_NODE,
1964 "etype:steal", $<id>6,
1965 "prefix:steal", $<id>2,
1966 "values:steal", error_vals,
1969 nodes = g_list_append (nodes, node);
1971 | ERROR TOKEN '{' errorvals ',' '}' TYPETOKEN ';' {
1972 Node *node = node_new (ERROR_NODE,
1973 "etype:steal", $<id>7,
1974 "prefix:steal", $<id>2,
1975 "values:steal", error_vals,
1978 nodes = g_list_append (nodes, node);
1982 errorvals: errorvals ',' TOKEN {
1983 error_vals = g_list_append (error_vals, $<id>3);
1986 error_vals = g_list_append (error_vals, $<id>1);
1991 numtok: NUMBER { $<id>$ = $<id>1; }
1993 $<id>$ = g_strconcat("-",$<id>2,NULL);
1996 | SINGLE_CHAR { $<id>$ = $<id>1; }
1997 | TOKEN { $<id>$ = $<id>1; }