2 * Copyright (C) 1999 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
29 #include "treefuncs.h"
37 static GList *class_nodes = NULL;
40 static char *chunk_size = NULL;
41 static char *bonobo_x_class = NULL;
42 static GList *typestack = NULL;
43 static GList *funcargs = NULL;
44 static GList *checks = NULL;
45 static int has_self = FALSE;
46 static int vararg = FALSE;
47 static Method *last_added_method = NULL;
49 /* destructor and initializer for variables */
50 static char *destructor = NULL;
51 static int destructor_line = 0;
52 static gboolean destructor_simple = TRUE;
53 static char *initializer = NULL;
54 static int initializer_line = 0;
56 static char *onerror = NULL;
57 static char *defreturn = NULL;
59 static GList *gtktypes = NULL;
61 /* this can be a global as we will only do one function at a time
63 static int the_scope = NO_SCOPE;
68 extern int ccode_line;
79 if(strcmp(yytext,"\n")==0) {
80 out=g_strconcat("Error: ",str," before newline",NULL);
81 } else if(yytext[0]=='\0') {
82 out=g_strconcat("Error: ", str, " at end of input", NULL);
84 char *tmp = g_strdup(yytext);
85 while((p=strchr(tmp, '\n')))
88 out=g_strconcat("Error: ", str, " before '", tmp, "'", NULL);
92 fprintf(stderr, "%s:%d: %s\n", filename, line_no, out);
101 Type *type = typestack->data;
102 typestack = g_list_remove(typestack,typestack->data);
107 push_variable(char *name, int scope, int line_no, char *postfix)
110 Type *type = pop_type();
112 type->postfix = postfix;
114 var = new_variable(scope, type, name, line_no,
115 destructor, destructor_line,
117 initializer, initializer_line);
118 class_nodes = g_list_append(class_nodes, var);
122 push_function(int scope, int method, char *oid, char *id,
123 GString *cbuf, int line_no, int ccode_line,
124 gboolean vararg, GList *flags)
130 g_assert(scope != CLASS_SCOPE);
132 if(method == INIT_METHOD || method == CLASS_INIT_METHOD) {
133 type = (Type *)new_type(g_strdup("void"), NULL, NULL);
138 /* a complicated and ugly test to figure out if we have
139 the wrong number of types for a signal */
140 if((method == SIGNAL_FIRST_METHOD ||
141 method == SIGNAL_LAST_METHOD) &&
142 g_list_length(gtktypes) != g_list_length(funcargs) &&
143 !(g_list_length(funcargs) == 1 &&
144 g_list_length(gtktypes) == 2 &&
145 strcmp(gtktypes->next->data, "NONE")==0)) {
146 error_print(GOB_WARN, line_no,
147 _("The number of GTK arguments and "
148 "function arguments for a signal "
149 "don't seem to match"));
151 if(g_list_length(gtktypes) > 2) {
153 for(li = gtktypes->next; li; li = li->next) {
154 if(strcmp(li->data, "NONE")==0) {
155 error_print(GOB_ERROR, line_no,
156 _("NONE can only appear in an "
157 "argument list by itself"));
163 c_cbuf = p = cbuf->str;
164 while(p && *p && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
171 node = new_method(scope, method, type, oid, gtktypes, flags,
172 id, funcargs, onerror, defreturn, c_cbuf, line_no,
173 ccode_line, vararg, method_unique_id++,
176 last_added_method = (Method *)node;
180 /*only free segment if we haven't passed it
189 class_nodes = g_list_append(class_nodes, node);
193 free_all_global_state(void)
203 g_list_foreach(gtktypes, (GFunc)g_free, NULL);
204 g_list_free(gtktypes);
207 free_node_list(funcargs);
212 push_funcarg(char *name, char *postfix)
215 Type *type = pop_type();
217 type->postfix = postfix;
219 node = new_funcarg(type, name, checks);
222 funcargs = g_list_append(funcargs, node);
226 push_init_arg(char *name, int is_class)
233 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
235 tn = g_strdup(((Class *)class)->otype);
237 type = new_type(tn, g_strdup("*"), NULL);
238 node = new_funcarg((Type *)type,name,NULL);
239 funcargs = g_list_prepend(funcargs, node);
243 push_self(char *id, gboolean constant)
248 type = new_type(g_strdup(((Class *)class)->otype),
249 g_strdup(constant ? "const *" : "*"), NULL);
250 ch = g_list_append(ch,new_check(NULL_CHECK,NULL));
251 ch = g_list_append(ch,new_check(TYPE_CHECK,NULL));
252 node = new_funcarg((Type *)type,id,ch);
253 funcargs = g_list_prepend(funcargs, node);
257 find_var_or_die(const char *id, int line)
261 for(li = class_nodes; li != NULL; li = li->next) {
263 Node *node = li->data;
264 if(node->type != VARIABLE_NODE)
267 if(strcmp(var->id, id)==0)
271 error_printf(GOB_ERROR, line, _("Variable %s not defined here"), id);
273 g_assert_not_reached();
278 set_return_value(char *type, char *val)
280 if(strcmp(type, "onerror")==0) {
286 } else if(strcmp(type, "defreturn")==0) {
297 export_accessors (char *var_name,
306 char *get_id = g_strdup_printf ("get_%s", var_name);
307 GString *get_cbuf_copy = g_string_new (get_cbuf->str);
309 Node *node1 = new_type (type->name, type->pointer, type->postfix);
310 Node *node3 = new_type (class->class.otype, "*", NULL);
312 tmp = g_strdup_printf ("\t%s%s ARG;\n",
314 type->pointer ? type->pointer : "");
315 get_cbuf_copy = g_string_prepend (get_cbuf_copy, tmp);
318 tmp = g_strdup_printf ("\n\t\treturn ARG;\n");
319 get_cbuf_copy = g_string_append (get_cbuf_copy, tmp);
322 typestack = g_list_prepend (typestack, node1);
323 typestack = g_list_prepend (typestack, node3);
325 push_funcarg ("self", FALSE);
327 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
328 get_id, get_cbuf_copy, get_lineno,
329 lineno, FALSE, NULL);
333 char *set_id = g_strdup_printf ("set_%s", var_name);
334 GString *set_cbuf_copy = g_string_new (set_cbuf->str);
335 Node *node1 = new_type (type->name, type->pointer, type->postfix);
336 Node *node2 = new_type ("void", NULL, NULL);
337 Node *node3 = new_type (class->class.otype, "*", NULL);
339 typestack = g_list_prepend (typestack, node2);
340 typestack = g_list_prepend (typestack, node1);
341 typestack = g_list_prepend (typestack, node3);
343 push_funcarg ("self", FALSE);
344 push_funcarg ("ARG", FALSE);
346 typestack = g_list_prepend (typestack, node2);
347 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
348 set_id, set_cbuf_copy, set_lineno,
349 lineno, FALSE, NULL);
364 %token CONST VOID STRUCT UNION ENUM THREEDOTS
365 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
367 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM
368 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE
369 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE ARGUMENT VIRTUAL SIGNAL OVERRIDE
373 prog: ccodes class ccodes { ; }
380 Node *node = new_ccode(C_CCODE,($<cbuf>1)->str,
382 nodes = g_list_append(nodes,node);
383 g_string_free($<cbuf>1,FALSE);
386 Node *node = new_ccode(H_CCODE,($<cbuf>1)->str,
388 nodes = g_list_append(nodes,node);
389 g_string_free($<cbuf>1,FALSE);
392 Node *node = new_ccode(HT_CCODE,($<cbuf>1)->str,
394 nodes = g_list_append(nodes,node);
395 g_string_free($<cbuf>1,FALSE);
398 Node *node = new_ccode(PH_CCODE,($<cbuf>1)->str,
400 nodes = g_list_append(nodes,node);
401 g_string_free($<cbuf>1,FALSE);
404 Node *node = new_ccode(A_CCODE,($<cbuf>1)->str,
406 nodes = g_list_append(nodes,node);
407 g_string_free($<cbuf>1,FALSE);
410 Node *node = new_ccode(AT_CCODE,($<cbuf>1)->str,
412 nodes = g_list_append(nodes,node);
413 g_string_free($<cbuf>1,FALSE);
417 ccodes: ccodes ccode { ; }
421 class: classdec '{' classcode '}' {
422 ((Class *)class)->nodes = class_nodes;
424 nodes = g_list_append(nodes,class);
427 ((Class *)class)->nodes = NULL;
429 nodes = g_list_append(nodes,class);
433 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
434 class = new_class ($<id>2, $<id>4,
435 bonobo_x_class, chunk_size, NULL);
440 | '(' TOKEN TOKEN ')' classflags {
441 if(strcmp($<id>2,"chunks") == 0) {
443 chunk_size = g_strdup($<id>3);
444 } else if(strcmp($<id>2,"BonoboX") == 0) {
445 g_free (bonobo_x_class);
446 bonobo_x_class = g_strdup($<id>3);
448 yyerror(_("parse error"));
452 | '(' TOKEN NUMBER ')' classflags {
453 if(strcmp($<id>2,"chunks") == 0) {
455 if(atoi($<id>3) != 0)
456 chunk_size = g_strdup($<id>3);
460 yyerror(_("parse error"));
466 classcode: classcode thing { ; }
472 if (strcmp ($<id>1, "BonoboX") != 0) {
474 yyerror(_("parse error"));
477 last_added_method->bonobo_x_func = TRUE;
484 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
485 | PRIVATE { the_scope = PRIVATE_SCOPE; }
486 | PROTECTED { the_scope = PROTECTED_SCOPE; }
487 | CLASSWIDE { the_scope = CLASS_SCOPE; }
490 destructor: TOKEN TOKEN {
491 if(strcmp($<id>1, "destroywith")==0) {
494 destructor_line = line_no;
495 destructor_simple = TRUE;
499 yyerror(_("parse error"));
504 if(strcmp($<id>1, "destroy")==0) {
506 destructor = ($<cbuf>3)->str;
507 g_string_free($<cbuf>3, FALSE);
508 destructor_line = ccode_line;
509 destructor_simple = FALSE;
512 g_string_free($<cbuf>3, TRUE);
513 yyerror(_("parse error"));
519 initializer: '=' numtok {
520 initializer = $<id>2;
521 initializer_line = ccode_line;
524 initializer = ($<cbuf>3)->str;
525 initializer_line = ccode_line;
526 g_string_free($<cbuf>3, FALSE);
531 varoptions: destructor initializer { ; }
532 | initializer destructor { ; }
533 | initializer { destructor = NULL; }
534 | destructor { initializer = NULL; }
541 variable: scope type TOKEN varoptions ';' {
542 push_variable($<id>3, the_scope,$<line>1, NULL);
544 | scope type TOKEN ARRAY_DIM varoptions ';' {
545 push_variable($<id>3, the_scope, $<line>1, $<id>4);
549 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
550 if(strcmp($<id>6,"get")==0 &&
551 strcmp($<id>9,"set")==0) {
553 Type *type = pop_type();
556 node = new_argument ($<id>3, type, $<list>2, $<id>4,
557 ($<cbuf>8)->str, $<line>7,
558 ($<cbuf>11)->str,$<line>10,
561 class_nodes = g_list_append(class_nodes,node);
564 export_accessors ($<id>4,
566 $<cbuf>11, $<line>10,
571 g_string_free ($<cbuf>8, FALSE);
572 g_string_free ($<cbuf>11, FALSE);
574 } else if(strcmp($<id>6,"set")==0 &&
575 strcmp($<id>9,"get")==0) {
577 Type *type = pop_type();
580 node = new_argument ($<id>3, type, $<list>2, $<id>4,
581 ($<cbuf>11)->str,$<line>10,
582 ($<cbuf>8)->str,$<line>7,
584 g_string_free ($<cbuf>11, FALSE);
585 g_string_free ($<cbuf>8, FALSE);
586 class_nodes = g_list_append(class_nodes,node);
592 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
593 g_list_free ($<list>2);
594 g_string_free ($<cbuf>11, TRUE);
595 g_string_free ($<cbuf>8, TRUE);
596 yyerror (_("parse error"));
600 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
601 if(strcmp($<id>6, "get") == 0) {
603 Type *type = pop_type();
605 node = new_argument ($<id>3, type, $<list>2, $<id>4,
606 ($<cbuf>8)->str, $<line>7,
610 export_accessors ($<id>4,
617 g_string_free ($<cbuf>8, FALSE);
618 class_nodes = g_list_append(class_nodes, node);
619 } else if(strcmp($<id>6, "set") == 0) {
621 Type *type = pop_type();
623 node = new_argument ($<id>3, type, $<list>2, $<id>4,
625 ($<cbuf>8)->str, $<line>7,
628 export_accessors ($<id>4,
635 g_string_free ($<cbuf>8, FALSE);
636 class_nodes = g_list_append (class_nodes, node);
641 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
642 g_list_free ($<list>2);
643 g_string_free ($<cbuf>8, TRUE);
644 yyerror(_("parse error"));
648 | ARGUMENT flags argtype TOKEN export TOKEN {
650 char *get, *set = NULL;
655 if(strcmp($<id>6, "link")!=0 &&
656 strcmp($<id>6, "stringlink")!=0 &&
657 strcmp($<id>6, "objectlink")!=0) {
661 g_list_foreach($<list>2,(GFunc)g_free,NULL);
662 g_list_free($<list>2);
663 yyerror(_("parse error"));
669 var = find_var_or_die($<id>4, $<line>1);
670 if(var->scope == PRIVATE_SCOPE)
671 root = "self->_priv";
672 else if(var->scope == CLASS_SCOPE) {
673 root = "SELF_GET_CLASS(self)";
675 error_print(GOB_ERROR, $<line>1,
676 _("Self aliases needed when autolinking to a classwide member"));
680 if(strcmp($<id>6, "link")==0) {
681 set = g_strdup_printf("%s->%s = ARG;",
683 } else if(strcmp ($<id>6, "stringlink")==0) {
684 set = g_strdup_printf("g_free(%s->%s); "
685 "%s->%s = g_strdup(ARG);",
688 } else if(strcmp ($<id>6, "objectlink")==0) {
689 set = g_strdup_printf(
691 "gtk_object_ref (GTK_OBJECT (ARG)); "
692 "if (%s->%s != NULL) "
693 "gtk_object_unref (GTK_OBJECT (%s->%s)); "
699 g_assert_not_reached();
702 if(strcmp ($<id>6, "stringlink")==0) {
703 get = g_strdup_printf("ARG = g_strdup(%s->%s);", root, $<id>4);
705 /* For everything else, get is just straight assignment */
706 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
712 type = copy_type(var->vtype);
714 node = new_argument ($<id>3, type, $<list>2,
720 export_accessors ($<id>4,
721 g_string_new (get), $<line>1,
722 g_string_new (set), $<line>1,
727 class_nodes = g_list_append(class_nodes,node);
731 export: '(' TOKEN ')' {
732 if (strcmp ($<id>2, "export")!=0) {
734 yyerror (_("parse error"));
741 argtype: TOKEN '(' TOKEN type ')' {
742 if(strcmp($<id>3,"type")!=0) {
745 yyerror(_("parse error"));
752 typestack = g_list_prepend(typestack,NULL);
756 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
757 | { $<list>$ = NULL; }
760 flaglist: TOKEN '|' flaglist {
761 $<list>$ = g_list_append($<list>3,$<id>1);
764 $<list>$ = g_list_append(NULL,$<id>1);
769 type: specifier_list pointer {
770 Node *node = new_type($<id>1, $<id>2, NULL);
771 typestack = g_list_prepend(typestack,node);
774 Node *node = new_type($<id>1, NULL, NULL);
775 typestack = g_list_prepend(typestack,node);
779 /* The special cases are neccessary to avoid conflicts */
780 specifier_list: spec_list {
787 $<id>$ = g_strconcat("const ", $<id>2, NULL);
791 $<id>$ = g_strconcat($<id>1, " const", NULL);
794 | strunionenum TOKEN {
795 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
798 | CONST strunionenum TOKEN {
799 $<id>$ = g_strconcat("const ", $<id>2, " ",
803 | strunionenum TOKEN CONST {
804 $<id>$ = g_strconcat($<id>1, " ",
805 $<id>2, " const", NULL);
810 /* The special const cases take care of conflicts ! */
811 spec_list: specifier spec_list {
812 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
815 | TYPETOKEN spec_list {
816 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
821 $<id>$ = g_strconcat("const ", $<id>2, NULL);
828 $<id>$ = g_strconcat($<id>1, " const", NULL);
832 $<id>$ = g_strdup($<id>1);
835 $<id>$ = g_strconcat($<id>1, " const", NULL);
839 specifier: VOID { $<id>$ = "void"; }
840 | CHAR { $<id>$ = "char"; }
841 | SHORT { $<id>$ = "short"; }
842 | INT { $<id>$ = "int"; }
843 | LONG { $<id>$ = "long"; }
844 | FLOAT { $<id>$ = "float"; }
845 | DOUBLE { $<id>$ = "double"; }
846 | SIGNED { $<id>$ = "signed"; }
847 | UNSIGNED { $<id>$ = "unsigned"; }
850 strunionenum: STRUCT { $<id>$ = "struct"; }
851 | UNION { $<id>$ = "union"; }
852 | ENUM { $<id>$ = "enum"; }
855 pointer: '*' { $<id>$ = g_strdup("*"); }
856 | '*' CONST { $<id>$ = g_strdup("* const"); }
858 $<id>$ = g_strconcat("*", $<id>2, NULL);
861 | '*' CONST pointer {
862 $<id>$ = g_strconcat("* const", $<id>3, NULL);
867 /* this never sets the_scope */
868 simplesigtype: TOKEN sigtype {
869 if(strcmp($<id>1, "first")==0)
870 $<sigtype>$ = SIGNAL_FIRST_METHOD;
871 else if(strcmp($<id>1, "last")==0)
872 $<sigtype>$ = SIGNAL_LAST_METHOD;
874 yyerror(_("signal must be 'first' or 'last'"));
881 $<sigtype>$ = SIGNAL_LAST_METHOD;
885 /* this always sets the_scope */
886 fullsigtype: scope TOKEN sigtype {
887 if(strcmp($<id>2,"first")==0)
888 $<sigtype>$ = SIGNAL_FIRST_METHOD;
889 else if(strcmp($<id>2,"last")==0)
890 $<sigtype>$ = SIGNAL_LAST_METHOD;
892 yyerror(_("signal must be 'first' or 'last'"));
898 | TOKEN scope sigtype {
899 if(strcmp($<id>1,"first")==0)
900 $<sigtype>$ = SIGNAL_FIRST_METHOD;
901 else if(strcmp($<id>1,"last")==0)
902 $<sigtype>$ = SIGNAL_LAST_METHOD;
904 yyerror(_("signal must be 'first' or 'last'"));
911 $<sigtype>$ = SIGNAL_LAST_METHOD;
914 /* the_scope was default thus public */
915 the_scope = PUBLIC_SCOPE;
919 sigtype: TOKEN '(' tokenlist ')' {
920 gtktypes = g_list_prepend(gtktypes, $<id>1);
924 tokenlist: tokenlist ',' TOKEN {
925 gtktypes = g_list_append(gtktypes, $<id>3);
928 gtktypes = g_list_append(gtktypes, $<id>1);
932 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
933 | ';' { $<cbuf>$ = NULL; }
936 /*here CCODE will include the ending '}' */
937 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
939 yyerror(_("signal without 'self' as "
941 free_all_global_state();
944 if(the_scope == CLASS_SCOPE) {
945 yyerror(_("a method cannot be of class scope"));
946 free_all_global_state();
949 push_function(the_scope, $<sigtype>3,NULL,
950 $<id>5, $<cbuf>10,$<line>1,
951 ccode_line, vararg, $<list>2);
953 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
955 yyerror(_("signal without 'self' as "
957 free_all_global_state();
960 if(the_scope == CLASS_SCOPE) {
961 yyerror(_("a method cannot be of class scope"));
962 free_all_global_state();
965 push_function(the_scope, $<sigtype>4, NULL,
966 $<id>6, $<cbuf>11, $<line>2,
967 ccode_line, vararg, $<list>3);
969 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
971 yyerror(_("virtual method without 'self' as "
973 free_all_global_state();
976 if(the_scope == CLASS_SCOPE) {
977 yyerror(_("a method cannot be of class scope"));
978 free_all_global_state();
981 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
983 ccode_line, vararg, NULL);
985 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
987 yyerror(_("virtual method without 'self' as "
989 free_all_global_state();
992 if(the_scope == CLASS_SCOPE) {
993 yyerror(_("a method cannot be of class scope"));
994 free_all_global_state();
997 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
999 ccode_line, vararg, NULL);
1001 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1003 yyerror(_("virtual method without 'self' as "
1004 "first parameter"));
1005 free_all_global_state();
1008 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1009 $<id>3, $<cbuf>8, $<line>1,
1010 ccode_line, vararg, NULL);
1012 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1013 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1015 $<line>1, ccode_line,
1018 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1019 if(the_scope == CLASS_SCOPE) {
1020 yyerror(_("a method cannot be of class scope"));
1021 free_all_global_state();
1024 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1025 $<cbuf>8, $<line>1, ccode_line,
1028 | TOKEN '(' TOKEN ')' codenocode {
1029 if(strcmp($<id>1, "init")==0) {
1030 push_init_arg($<id>3,FALSE);
1031 push_function(NO_SCOPE, INIT_METHOD, NULL,
1032 $<id>1, $<cbuf>5, $<line>2,
1033 ccode_line, FALSE, NULL);
1034 } else if(strcmp($<id>1, "class_init")==0) {
1035 push_init_arg($<id>3,TRUE);
1036 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1037 $<id>1, $<cbuf>5, $<line>2,
1038 ccode_line, FALSE, NULL);
1042 g_string_free($<cbuf>5,TRUE);
1043 yyerror(_("parse error "
1044 "(untyped blocks must be init or "
1051 returnvals: TOKEN retcode {
1052 g_free(onerror); onerror = NULL;
1053 g_free(defreturn); defreturn = NULL;
1054 if(!set_return_value($<id>1, $<id>2)) {
1057 yyerror(_("parse error"));
1062 | TOKEN retcode TOKEN retcode {
1063 g_free(onerror); onerror = NULL;
1064 g_free(defreturn); defreturn = NULL;
1065 if(!set_return_value($<id>1, $<id>2)) {
1066 g_free($<id>1); g_free($<id>2);
1067 g_free($<id>3); g_free($<id>4);
1068 yyerror(_("parse error"));
1071 if(!set_return_value($<id>3, $<id>4)) {
1072 onerror = defreturn = NULL;
1073 g_free($<id>1); g_free($<id>2);
1074 g_free($<id>3); g_free($<id>4);
1075 yyerror(_("parse error"));
1082 g_free(onerror); onerror = NULL;
1083 g_free(defreturn); defreturn = NULL;
1087 retcode: numtok { $<id>$ = $<id>1; }
1089 $<id>$ = ($<cbuf>3)->str;
1090 g_string_free($<cbuf>3, FALSE);
1094 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1098 if(strcmp($<id>1,"self")==0)
1099 push_self($<id>1, FALSE);
1102 yyerror(_("parse error"));
1109 if(strcmp($<id>1,"self")==0)
1110 push_self($<id>1, TRUE);
1113 yyerror(_("parse error"));
1120 if(strcmp($<id>2,"self")==0)
1121 push_self($<id>2, TRUE);
1124 yyerror(_("parse error"));
1128 | TOKEN ',' arglist {
1130 if(strcmp($<id>1,"self")==0)
1131 push_self($<id>1, FALSE);
1134 yyerror(_("parse error"));
1138 | TOKEN CONST ',' arglist {
1140 if(strcmp($<id>1,"self")==0)
1141 push_self($<id>1, TRUE);
1144 yyerror(_("parse error"));
1148 | CONST TOKEN ',' arglist {
1150 if(strcmp($<id>2,"self")==0)
1151 push_self($<id>2, TRUE);
1154 yyerror(_("parse error"));
1158 | arglist { has_self = FALSE; }
1161 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1162 | arglist1 { vararg = FALSE; }
1165 arglist1: arglist1 ',' arg { ; }
1170 push_funcarg($<id>2,NULL);
1172 | type TOKEN ARRAY_DIM {
1173 push_funcarg($<id>2,$<id>3);
1175 | type TOKEN '(' TOKEN checklist ')' {
1176 if(strcmp($<id>4,"check")!=0) {
1177 yyerror(_("parse error"));
1181 push_funcarg($<id>2,NULL);
1183 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1184 if(strcmp($<id>5,"check")!=0) {
1185 yyerror(_("parse error"));
1189 push_funcarg($<id>2,$<id>3);
1193 checklist: checklist check { ; }
1198 if(strcmp($<id>1,"type")==0) {
1199 Node *node = new_check(TYPE_CHECK,NULL);
1200 checks = g_list_append(checks,node);
1201 } else if(strcmp($<id>1,"null")==0) {
1202 Node *node = new_check(NULL_CHECK,NULL);
1203 checks = g_list_append(checks,node);
1205 yyerror(_("parse error"));
1211 Node *node = new_check(GT_CHECK,$<id>2);
1212 checks = g_list_append(checks,node);
1215 Node *node = new_check(LT_CHECK,$<id>2);
1216 checks = g_list_append(checks,node);
1219 Node *node = new_check(GE_CHECK,$<id>3);
1220 checks = g_list_append(checks,node);
1223 Node *node = new_check(LE_CHECK,$<id>3);
1224 checks = g_list_append(checks,node);
1227 Node *node = new_check(EQ_CHECK,$<id>3);
1228 checks = g_list_append(checks,node);
1231 Node *node = new_check(NE_CHECK,$<id>3);
1232 checks = g_list_append(checks,node);
1236 numtok: NUMBER { $<id>$ = $<id>1; }
1238 $<id>$ = g_strconcat("-",$<id>2,NULL);
1241 | TOKEN { $<id>$ = $<id>1; }