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 (const char *var_name,
298 const char *get_cbuf,
300 const char *set_cbuf,
307 char *cast = g_strdup (get_cast (gtktype, FALSE));
308 char *p = strchr (cast, ' ');
313 /* leak, but we don't really care any more */
314 type = (Type *)new_type (cast,
319 if (get_cbuf != NULL) {
320 char *get_id = g_strdup_printf ("get_%s", var_name);
321 GString *get_cbuf_copy = g_string_new (get_cbuf);
323 Node *node1 = new_type (g_strdup (type->name),
324 g_strdup (type->pointer),
325 g_strdup (type->postfix));
326 Node *node3 = new_type (g_strdup (class->class.otype),
330 tmp = g_strdup_printf ("\t%s%s ARG;\n",
332 type->pointer ? type->pointer : "");
333 get_cbuf_copy = g_string_prepend (get_cbuf_copy, tmp);
336 tmp = g_strdup_printf ("\n\t\treturn ARG;\n");
337 get_cbuf_copy = g_string_append (get_cbuf_copy, tmp);
340 typestack = g_list_prepend (typestack, node1);
341 typestack = g_list_prepend (typestack, node3);
343 push_funcarg ("self", FALSE);
345 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
346 get_id, get_cbuf_copy, get_lineno,
347 lineno, FALSE, NULL);
350 if (set_cbuf != NULL) {
351 char *set_id = g_strdup_printf ("set_%s", var_name);
352 GString *set_cbuf_copy = g_string_new (set_cbuf);
353 Node *node1 = new_type (g_strdup (type->name),
354 g_strdup (type->pointer),
355 g_strdup (type->postfix));
356 Node *node2 = new_type (g_strdup ("void"),
359 Node *node3 = new_type (g_strdup (class->class.otype),
363 typestack = g_list_prepend (typestack, node2);
364 typestack = g_list_prepend (typestack, node1);
365 typestack = g_list_prepend (typestack, node3);
367 push_funcarg ("self", FALSE);
368 push_funcarg ("ARG", FALSE);
370 typestack = g_list_prepend (typestack, node2);
371 push_function (PUBLIC_SCOPE, REGULAR_METHOD, NULL,
372 set_id, set_cbuf_copy, set_lineno,
373 lineno, FALSE, NULL);
388 %token CONST VOID STRUCT UNION ENUM THREEDOTS
389 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
391 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM
392 %token <cbuf> CCODE HTCODE PHCODE HCODE ACODE ATCODE
393 %token <line> PUBLIC PRIVATE PROTECTED CLASSWIDE ARGUMENT VIRTUAL SIGNAL OVERRIDE
397 prog: ccodes class ccodes { ; }
404 Node *node = new_ccode(C_CCODE,($<cbuf>1)->str,
406 nodes = g_list_append(nodes,node);
407 g_string_free($<cbuf>1,FALSE);
410 Node *node = new_ccode(H_CCODE,($<cbuf>1)->str,
412 nodes = g_list_append(nodes,node);
413 g_string_free($<cbuf>1,FALSE);
416 Node *node = new_ccode(HT_CCODE,($<cbuf>1)->str,
418 nodes = g_list_append(nodes,node);
419 g_string_free($<cbuf>1,FALSE);
422 Node *node = new_ccode(PH_CCODE,($<cbuf>1)->str,
424 nodes = g_list_append(nodes,node);
425 g_string_free($<cbuf>1,FALSE);
428 Node *node = new_ccode(A_CCODE,($<cbuf>1)->str,
430 nodes = g_list_append(nodes,node);
431 g_string_free($<cbuf>1,FALSE);
434 Node *node = new_ccode(AT_CCODE,($<cbuf>1)->str,
436 nodes = g_list_append(nodes,node);
437 g_string_free($<cbuf>1,FALSE);
441 ccodes: ccodes ccode { ; }
445 class: classdec '{' classcode '}' {
446 ((Class *)class)->nodes = class_nodes;
448 nodes = g_list_append(nodes,class);
451 ((Class *)class)->nodes = NULL;
453 nodes = g_list_append(nodes,class);
457 classdec: CLASS TYPETOKEN FROM TYPETOKEN classflags {
458 class = new_class ($<id>2, $<id>4,
459 bonobo_x_class, chunk_size, NULL);
464 | '(' TOKEN TOKEN ')' classflags {
465 if(strcmp($<id>2,"chunks") == 0) {
467 chunk_size = g_strdup($<id>3);
468 } else if(strcmp($<id>2,"BonoboX") == 0) {
469 g_free (bonobo_x_class);
470 bonobo_x_class = g_strdup($<id>3);
472 yyerror(_("parse error"));
476 | '(' TOKEN NUMBER ')' classflags {
477 if(strcmp($<id>2,"chunks") == 0) {
479 if(atoi($<id>3) != 0)
480 chunk_size = g_strdup($<id>3);
484 yyerror(_("parse error"));
490 classcode: classcode thing { ; }
496 if (strcmp ($<id>1, "BonoboX") != 0) {
498 yyerror(_("parse error"));
501 last_added_method->bonobo_x_func = TRUE;
508 scope: PUBLIC { the_scope = PUBLIC_SCOPE; }
509 | PRIVATE { the_scope = PRIVATE_SCOPE; }
510 | PROTECTED { the_scope = PROTECTED_SCOPE; }
511 | CLASSWIDE { the_scope = CLASS_SCOPE; }
514 destructor: TOKEN TOKEN {
515 if(strcmp($<id>1, "destroywith")==0) {
518 destructor_line = line_no;
519 destructor_simple = TRUE;
523 yyerror(_("parse error"));
528 if(strcmp($<id>1, "destroy")==0) {
530 destructor = ($<cbuf>3)->str;
531 g_string_free($<cbuf>3, FALSE);
532 destructor_line = ccode_line;
533 destructor_simple = FALSE;
536 g_string_free($<cbuf>3, TRUE);
537 yyerror(_("parse error"));
543 initializer: '=' numtok {
544 initializer = $<id>2;
545 initializer_line = ccode_line;
548 initializer = ($<cbuf>3)->str;
549 initializer_line = ccode_line;
550 g_string_free($<cbuf>3, FALSE);
555 varoptions: destructor initializer { ; }
556 | initializer destructor { ; }
557 | initializer { destructor = NULL; }
558 | destructor { initializer = NULL; }
565 variable: scope type TOKEN varoptions ';' {
566 push_variable($<id>3, the_scope,$<line>1, NULL);
568 | scope type TOKEN ARRAY_DIM varoptions ';' {
569 push_variable($<id>3, the_scope, $<line>1, $<id>4);
573 argument: ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE TOKEN '{' CCODE ';' {
574 if(strcmp($<id>6,"get")==0 &&
575 strcmp($<id>9,"set")==0) {
577 Type *type = pop_type();
580 node = new_argument ($<id>3, type, $<list>2, $<id>4,
581 ($<cbuf>8)->str, $<line>7,
582 ($<cbuf>11)->str,$<line>10,
585 class_nodes = g_list_append(class_nodes,node);
588 export_accessors ($<id>4,
589 ($<cbuf>8)->str, $<line>7,
590 ($<cbuf>11)->str, $<line>10,
597 g_string_free ($<cbuf>8, FALSE);
598 g_string_free ($<cbuf>11, FALSE);
600 } else if(strcmp($<id>6,"set")==0 &&
601 strcmp($<id>9,"get")==0) {
603 Type *type = pop_type();
606 node = new_argument ($<id>3, type, $<list>2, $<id>4,
607 ($<cbuf>11)->str,$<line>10,
608 ($<cbuf>8)->str,$<line>7,
612 export_accessors ($<id>4,
613 ($<cbuf>11)->str, $<line>10,
614 ($<cbuf>8)->str, $<line>7,
621 g_string_free ($<cbuf>11, FALSE);
622 g_string_free ($<cbuf>8, FALSE);
623 class_nodes = g_list_append(class_nodes,node);
629 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
630 g_list_free ($<list>2);
631 g_string_free ($<cbuf>11, TRUE);
632 g_string_free ($<cbuf>8, TRUE);
633 yyerror (_("parse error"));
637 | ARGUMENT flags argtype TOKEN export TOKEN '{' CCODE ';' {
638 if(strcmp($<id>6, "get") == 0) {
640 Type *type = pop_type();
642 node = new_argument ($<id>3, type, $<list>2, $<id>4,
643 ($<cbuf>8)->str, $<line>7,
647 export_accessors ($<id>4,
648 ($<cbuf>8)->str, $<line>7,
656 g_string_free ($<cbuf>8, FALSE);
657 class_nodes = g_list_append(class_nodes, node);
658 } else if(strcmp($<id>6, "set") == 0) {
660 Type *type = pop_type();
662 node = new_argument ($<id>3, type, $<list>2, $<id>4,
664 ($<cbuf>8)->str, $<line>7,
667 export_accessors ($<id>4,
669 ($<cbuf>8)->str, $<line>7,
676 g_string_free ($<cbuf>8, FALSE);
677 class_nodes = g_list_append (class_nodes, node);
682 g_list_foreach ($<list>2, (GFunc)g_free, NULL);
683 g_list_free ($<list>2);
684 g_string_free ($<cbuf>8, TRUE);
685 yyerror(_("parse error"));
689 | ARGUMENT flags argtype TOKEN export TOKEN {
691 char *get, *set = NULL;
696 if(strcmp($<id>6, "link")!=0 &&
697 strcmp($<id>6, "stringlink")!=0 &&
698 strcmp($<id>6, "objectlink")!=0) {
702 g_list_foreach($<list>2,(GFunc)g_free,NULL);
703 g_list_free($<list>2);
704 yyerror(_("parse error"));
710 var = find_var_or_die($<id>4, $<line>1);
711 if(var->scope == PRIVATE_SCOPE)
712 root = "self->_priv";
713 else if(var->scope == CLASS_SCOPE) {
714 root = "SELF_GET_CLASS(self)";
716 error_print(GOB_ERROR, $<line>1,
717 _("Self aliases needed when autolinking to a classwide member"));
721 if(strcmp($<id>6, "link")==0) {
722 set = g_strdup_printf("%s->%s = ARG;",
724 } else if(strcmp ($<id>6, "stringlink")==0) {
725 set = g_strdup_printf("g_free(%s->%s); "
726 "%s->%s = g_strdup(ARG);",
729 } else if(strcmp ($<id>6, "objectlink")==0) {
730 set = g_strdup_printf(
732 "gtk_object_ref (GTK_OBJECT (ARG)); "
733 "if (%s->%s != NULL) "
734 "gtk_object_unref (GTK_OBJECT (%s->%s)); "
740 g_assert_not_reached();
743 if (strcmp ($<id>6, "stringlink")==0) {
744 get = g_strdup_printf("ARG = g_strdup(%s->%s);", root, $<id>4);
746 /* For everything else, get is just straight assignment */
747 get = g_strdup_printf("ARG = %s->%s;", root, $<id>4);
754 type = copy_type(var->vtype);
756 node = new_argument ($<id>3, type, $<list>2,
762 export_accessors ($<id>4,
771 class_nodes = g_list_append(class_nodes,node);
775 export: '(' TOKEN ')' {
776 if (strcmp ($<id>2, "export")!=0) {
778 yyerror (_("parse error"));
785 argtype: TOKEN '(' TOKEN type ')' {
786 if(strcmp($<id>3,"type")!=0) {
789 yyerror(_("parse error"));
796 typestack = g_list_prepend(typestack,NULL);
800 flags: '(' flaglist ')' { $<list>$ = $<list>2; }
801 | { $<list>$ = NULL; }
804 flaglist: TOKEN '|' flaglist {
805 $<list>$ = g_list_append($<list>3,$<id>1);
808 $<list>$ = g_list_append(NULL,$<id>1);
813 type: specifier_list pointer {
814 Node *node = new_type($<id>1, $<id>2, NULL);
815 typestack = g_list_prepend(typestack,node);
818 Node *node = new_type($<id>1, NULL, NULL);
819 typestack = g_list_prepend(typestack,node);
823 /* The special cases are neccessary to avoid conflicts */
824 specifier_list: spec_list {
831 $<id>$ = g_strconcat("const ", $<id>2, NULL);
835 $<id>$ = g_strconcat($<id>1, " const", NULL);
838 | strunionenum TOKEN {
839 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
842 | CONST strunionenum TOKEN {
843 $<id>$ = g_strconcat("const ", $<id>2, " ",
847 | strunionenum TOKEN CONST {
848 $<id>$ = g_strconcat($<id>1, " ",
849 $<id>2, " const", NULL);
854 /* The special const cases take care of conflicts ! */
855 spec_list: specifier spec_list {
856 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
859 | TYPETOKEN spec_list {
860 $<id>$ = g_strconcat($<id>1, " ", $<id>2, NULL);
865 $<id>$ = g_strconcat("const ", $<id>2, NULL);
872 $<id>$ = g_strconcat($<id>1, " const", NULL);
876 $<id>$ = g_strdup($<id>1);
879 $<id>$ = g_strconcat($<id>1, " const", NULL);
883 specifier: VOID { $<id>$ = "void"; }
884 | CHAR { $<id>$ = "char"; }
885 | SHORT { $<id>$ = "short"; }
886 | INT { $<id>$ = "int"; }
887 | LONG { $<id>$ = "long"; }
888 | FLOAT { $<id>$ = "float"; }
889 | DOUBLE { $<id>$ = "double"; }
890 | SIGNED { $<id>$ = "signed"; }
891 | UNSIGNED { $<id>$ = "unsigned"; }
894 strunionenum: STRUCT { $<id>$ = "struct"; }
895 | UNION { $<id>$ = "union"; }
896 | ENUM { $<id>$ = "enum"; }
899 pointer: '*' { $<id>$ = g_strdup("*"); }
900 | '*' CONST { $<id>$ = g_strdup("* const"); }
902 $<id>$ = g_strconcat("*", $<id>2, NULL);
905 | '*' CONST pointer {
906 $<id>$ = g_strconcat("* const", $<id>3, NULL);
911 /* this never sets the_scope */
912 simplesigtype: TOKEN sigtype {
913 if(strcmp($<id>1, "first")==0)
914 $<sigtype>$ = SIGNAL_FIRST_METHOD;
915 else if(strcmp($<id>1, "last")==0)
916 $<sigtype>$ = SIGNAL_LAST_METHOD;
918 yyerror(_("signal must be 'first' or 'last'"));
925 $<sigtype>$ = SIGNAL_LAST_METHOD;
929 /* this always sets the_scope */
930 fullsigtype: scope TOKEN sigtype {
931 if(strcmp($<id>2,"first")==0)
932 $<sigtype>$ = SIGNAL_FIRST_METHOD;
933 else if(strcmp($<id>2,"last")==0)
934 $<sigtype>$ = SIGNAL_LAST_METHOD;
936 yyerror(_("signal must be 'first' or 'last'"));
942 | TOKEN scope sigtype {
943 if(strcmp($<id>1,"first")==0)
944 $<sigtype>$ = SIGNAL_FIRST_METHOD;
945 else if(strcmp($<id>1,"last")==0)
946 $<sigtype>$ = SIGNAL_LAST_METHOD;
948 yyerror(_("signal must be 'first' or 'last'"));
955 $<sigtype>$ = SIGNAL_LAST_METHOD;
958 /* the_scope was default thus public */
959 the_scope = PUBLIC_SCOPE;
963 sigtype: TOKEN '(' tokenlist ')' {
964 gtktypes = g_list_prepend(gtktypes, $<id>1);
968 tokenlist: tokenlist ',' TOKEN {
969 gtktypes = g_list_append(gtktypes, $<id>3);
972 gtktypes = g_list_append(gtktypes, $<id>1);
976 codenocode: '{' CCODE { $<cbuf>$ = $<cbuf>2; }
977 | ';' { $<cbuf>$ = NULL; }
980 /*here CCODE will include the ending '}' */
981 method: SIGNAL flags fullsigtype type TOKEN '(' funcargs ')' returnvals codenocode {
983 yyerror(_("signal without 'self' as "
985 free_all_global_state();
988 if(the_scope == CLASS_SCOPE) {
989 yyerror(_("a method cannot be of class scope"));
990 free_all_global_state();
993 push_function(the_scope, $<sigtype>3,NULL,
994 $<id>5, $<cbuf>10,$<line>1,
995 ccode_line, vararg, $<list>2);
997 | scope SIGNAL flags simplesigtype type TOKEN '(' funcargs ')' returnvals codenocode {
999 yyerror(_("signal without 'self' as "
1000 "first parameter"));
1001 free_all_global_state();
1004 if(the_scope == CLASS_SCOPE) {
1005 yyerror(_("a method cannot be of class scope"));
1006 free_all_global_state();
1009 push_function(the_scope, $<sigtype>4, NULL,
1010 $<id>6, $<cbuf>11, $<line>2,
1011 ccode_line, vararg, $<list>3);
1013 | VIRTUAL scope type TOKEN '(' funcargs ')' returnvals codenocode {
1015 yyerror(_("virtual method without 'self' as "
1016 "first parameter"));
1017 free_all_global_state();
1020 if(the_scope == CLASS_SCOPE) {
1021 yyerror(_("a method cannot be of class scope"));
1022 free_all_global_state();
1025 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1027 ccode_line, vararg, NULL);
1029 | scope VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1031 yyerror(_("virtual method without 'self' as "
1032 "first parameter"));
1033 free_all_global_state();
1036 if(the_scope == CLASS_SCOPE) {
1037 yyerror(_("a method cannot be of class scope"));
1038 free_all_global_state();
1041 push_function(the_scope, VIRTUAL_METHOD, NULL, $<id>4,
1043 ccode_line, vararg, NULL);
1045 | VIRTUAL type TOKEN '(' funcargs ')' returnvals codenocode {
1047 yyerror(_("virtual method without 'self' as "
1048 "first parameter"));
1049 free_all_global_state();
1052 push_function(PUBLIC_SCOPE, VIRTUAL_METHOD, NULL,
1053 $<id>3, $<cbuf>8, $<line>1,
1054 ccode_line, vararg, NULL);
1056 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' returnvals codenocode {
1057 push_function(NO_SCOPE, OVERRIDE_METHOD, $<id>3,
1059 $<line>1, ccode_line,
1062 | scope type TOKEN '(' funcargs ')' returnvals codenocode {
1063 if(the_scope == CLASS_SCOPE) {
1064 yyerror(_("a method cannot be of class scope"));
1065 free_all_global_state();
1068 push_function(the_scope, REGULAR_METHOD, NULL, $<id>3,
1069 $<cbuf>8, $<line>1, ccode_line,
1072 | TOKEN '(' TOKEN ')' codenocode {
1073 if(strcmp($<id>1, "init")==0) {
1074 push_init_arg($<id>3,FALSE);
1075 push_function(NO_SCOPE, INIT_METHOD, NULL,
1076 $<id>1, $<cbuf>5, $<line>2,
1077 ccode_line, FALSE, NULL);
1078 } else if(strcmp($<id>1, "class_init")==0) {
1079 push_init_arg($<id>3,TRUE);
1080 push_function(NO_SCOPE, CLASS_INIT_METHOD, NULL,
1081 $<id>1, $<cbuf>5, $<line>2,
1082 ccode_line, FALSE, NULL);
1086 g_string_free($<cbuf>5,TRUE);
1087 yyerror(_("parse error "
1088 "(untyped blocks must be init or "
1095 returnvals: TOKEN retcode {
1096 g_free(onerror); onerror = NULL;
1097 g_free(defreturn); defreturn = NULL;
1098 if(!set_return_value($<id>1, $<id>2)) {
1101 yyerror(_("parse error"));
1106 | TOKEN retcode TOKEN retcode {
1107 g_free(onerror); onerror = NULL;
1108 g_free(defreturn); defreturn = NULL;
1109 if(!set_return_value($<id>1, $<id>2)) {
1110 g_free($<id>1); g_free($<id>2);
1111 g_free($<id>3); g_free($<id>4);
1112 yyerror(_("parse error"));
1115 if(!set_return_value($<id>3, $<id>4)) {
1116 onerror = defreturn = NULL;
1117 g_free($<id>1); g_free($<id>2);
1118 g_free($<id>3); g_free($<id>4);
1119 yyerror(_("parse error"));
1126 g_free(onerror); onerror = NULL;
1127 g_free(defreturn); defreturn = NULL;
1131 retcode: numtok { $<id>$ = $<id>1; }
1133 $<id>$ = ($<cbuf>3)->str;
1134 g_string_free($<cbuf>3, FALSE);
1138 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
1142 if(strcmp($<id>1,"self")==0)
1143 push_self($<id>1, FALSE);
1146 yyerror(_("parse error"));
1153 if(strcmp($<id>1,"self")==0)
1154 push_self($<id>1, TRUE);
1157 yyerror(_("parse error"));
1164 if(strcmp($<id>2,"self")==0)
1165 push_self($<id>2, TRUE);
1168 yyerror(_("parse error"));
1172 | TOKEN ',' arglist {
1174 if(strcmp($<id>1,"self")==0)
1175 push_self($<id>1, FALSE);
1178 yyerror(_("parse error"));
1182 | TOKEN CONST ',' arglist {
1184 if(strcmp($<id>1,"self")==0)
1185 push_self($<id>1, TRUE);
1188 yyerror(_("parse error"));
1192 | CONST TOKEN ',' arglist {
1194 if(strcmp($<id>2,"self")==0)
1195 push_self($<id>2, TRUE);
1198 yyerror(_("parse error"));
1202 | arglist { has_self = FALSE; }
1205 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
1206 | arglist1 { vararg = FALSE; }
1209 arglist1: arglist1 ',' arg { ; }
1214 push_funcarg($<id>2,NULL);
1216 | type TOKEN ARRAY_DIM {
1217 push_funcarg($<id>2,$<id>3);
1219 | type TOKEN '(' TOKEN checklist ')' {
1220 if(strcmp($<id>4,"check")!=0) {
1221 yyerror(_("parse error"));
1225 push_funcarg($<id>2,NULL);
1227 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
1228 if(strcmp($<id>5,"check")!=0) {
1229 yyerror(_("parse error"));
1233 push_funcarg($<id>2,$<id>3);
1237 checklist: checklist check { ; }
1242 if(strcmp($<id>1,"type")==0) {
1243 Node *node = new_check(TYPE_CHECK,NULL);
1244 checks = g_list_append(checks,node);
1245 } else if(strcmp($<id>1,"null")==0) {
1246 Node *node = new_check(NULL_CHECK,NULL);
1247 checks = g_list_append(checks,node);
1249 yyerror(_("parse error"));
1255 Node *node = new_check(GT_CHECK,$<id>2);
1256 checks = g_list_append(checks,node);
1259 Node *node = new_check(LT_CHECK,$<id>2);
1260 checks = g_list_append(checks,node);
1263 Node *node = new_check(GE_CHECK,$<id>3);
1264 checks = g_list_append(checks,node);
1267 Node *node = new_check(LE_CHECK,$<id>3);
1268 checks = g_list_append(checks,node);
1271 Node *node = new_check(EQ_CHECK,$<id>3);
1272 checks = g_list_append(checks,node);
1275 Node *node = new_check(NE_CHECK,$<id>3);
1276 checks = g_list_append(checks,node);
1280 numtok: NUMBER { $<id>$ = $<id>1; }
1282 $<id>$ = g_strconcat("-",$<id>2,NULL);
1285 | TOKEN { $<id>$ = $<id>1; }