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,
33 extern char *filename;
37 static GList *class_nodes = NULL;
40 static GList *typestack = NULL;
42 static GList *funcargs = NULL;
43 static GList *checks = NULL;
44 static int has_self = FALSE;
45 static int vararg = FALSE;
47 static GList *gtktypes = NULL;
52 extern int ccode_line;
63 if(strcmp(yytext,"\n")==0) {
64 out=g_strconcat("Error: ",str," before newline",NULL);
65 } else if(yytext[0]=='\0') {
66 out=g_strconcat("Error: ",str," at end of input",NULL);
68 char *tmp = g_strdup(yytext);
69 while((p=strchr(tmp,'\n')))
72 out=g_strconcat("Error: ",str," before '",tmp,"'",NULL);
76 fprintf(stderr,"%s:%d: %s\n",filename,line_no,out);
83 push_variable(char *name, int scope, int line_no, char *postfix)
86 Type *type = typestack->data;
87 typestack = g_list_remove(typestack,typestack->data);
89 type->postfix = postfix;
91 var = new_variable(scope,type,name,line_no);
92 class_nodes = g_list_append(class_nodes, var);
96 push_function(int scope, char *oid, char *id, char *onerror,
97 GString *cbuf,int line_no, int ccode_line, int vararg)
102 if(scope!=INIT_METHOD && scope!=CLASS_INIT_METHOD) {
103 type = typestack->data;
104 typestack = g_list_remove(typestack,typestack->data);
106 type = (Type *)new_type(0,g_strdup("void"),NULL);
109 /* a complicated and ugly test to figure out if we have
110 the wrong number of types for a signal */
111 if((scope == SIGNAL_FIRST_METHOD ||
112 scope == SIGNAL_LAST_METHOD ||
113 scope == PRIVATE_SIGNAL_FIRST_METHOD ||
114 scope == PRIVATE_SIGNAL_LAST_METHOD) &&
115 g_list_length(gtktypes) != g_list_length(funcargs) &&
116 !(g_list_length(funcargs) == 1 &&
117 g_list_length(gtktypes) == 2 &&
118 strcmp(gtktypes->next->data,"NONE")==0)) {
119 print_error(TRUE, _("The number of GTK arguments and "
120 "function arguments for a signal "
121 "don't seem to match"),line_no);
123 node = new_method(scope,type,oid,gtktypes,id,funcargs,
124 onerror,cbuf,line_no,ccode_line,vararg);
128 class_nodes = g_list_append(class_nodes, node);
132 push_funcarg(char *name, char *postfix)
135 Type *type = typestack->data;
136 typestack = g_list_remove(typestack,typestack->data);
138 type->postfix = postfix;
140 node = new_funcarg(type,name,checks);
143 funcargs = g_list_append(funcargs, node);
147 push_init_arg(char *name, int is_class)
154 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
156 tn = g_strdup(((Class *)class)->otype);
158 type = new_type(1,tn,NULL);
159 node = new_funcarg((Type *)type,name,NULL);
160 funcargs = g_list_prepend(funcargs, node);
169 type = new_type(1,g_strdup(((Class *)class)->otype),NULL);
170 ch = g_list_append(ch,new_check(NULL_CHECK,NULL));
171 ch = g_list_append(ch,new_check(TYPE_CHECK,NULL));
172 node = new_funcarg((Type *)type,id,ch);
173 funcargs = g_list_prepend(funcargs, node);
187 %token CONST VOID STRUCT UNION ENUM THREEDOTS
188 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
191 %token <id> TOKEN NUMBER TYPETOKEN ARRAY_DIM
192 %token <cbuf> CCODE HCODE
193 %token <line> PUBLIC PRIVATE ARGUMENT VIRTUAL SIGNAL OVERRIDE
197 prog: ccodes class ccodes { ; }
203 ccodes: ccodes CCODE {
204 Node *node = new_ccode(FALSE,$<cbuf>2,ccode_line);
205 nodes = g_list_append(nodes,node);
208 Node *node = new_ccode(TRUE,$<cbuf>2,ccode_line);
209 nodes = g_list_append(nodes,node);
212 Node *node = new_ccode(FALSE,$<cbuf>1,ccode_line);
213 nodes = g_list_append(nodes,node);
216 Node *node = new_ccode(TRUE,$<cbuf>1,ccode_line);
217 nodes = g_list_append(nodes,node);
221 class: classdec '{' classcode '}' {
222 ((Class *)class)->nodes = class_nodes;
224 nodes = g_list_append(nodes,class);
228 classdec: CLASS TYPETOKEN FROM TYPETOKEN {
229 class = new_class($<id>2,$<id>4,NULL);
233 classcode: classcode method { ; }
234 | classcode variable { ; }
235 | classcode argument { ; }
241 variable: PUBLIC type TOKEN ';' {
242 push_variable($<id>3,PUBLIC_SCOPE,$<line>1,NULL);
244 | PUBLIC type TOKEN ARRAY_DIM ';' {
245 push_variable($<id>3,PUBLIC_SCOPE,$<line>1,$<id>4);
247 | PRIVATE type TOKEN ';' {
248 push_variable($<id>3,PRIVATE_SCOPE,$<line>1,NULL);
250 | PRIVATE type TOKEN ARRAY_DIM ';' {
251 push_variable($<id>3,PRIVATE_SCOPE,$<line>1,$<id>4);
254 argument: ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
255 if(strcmp($<id>5,"get")==0 &&
256 strcmp($<id>8,"set")==0) {
258 g_free($<id>5); g_free($<id>8);
259 node = new_argument($<id>3,$<list>2,$<id>4,
263 class_nodes = g_list_append(class_nodes,node);
264 } else if(strcmp($<id>5,"set")==0 &&
265 strcmp($<id>8,"get")==0) {
267 g_free($<id>5); g_free($<id>8);
268 node = new_argument($<id>3,$<list>2,$<id>4,
272 class_nodes = g_list_append(class_nodes,node);
274 g_free($<id>3); g_free($<id>4);
275 g_free($<id>5); g_free($<id>8);
276 g_list_foreach($<list>2,(GFunc)g_free,NULL);
277 g_string_free($<cbuf>10,TRUE);
278 g_string_free($<cbuf>7,TRUE);
279 yyerror(_("parse error"));
283 | ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE ';' {
284 if(strcmp($<id>5,"get")==0) {
287 node = new_argument($<id>3,$<list>2,$<id>4,
288 $<cbuf>7,$<line>6,NULL,0,
290 class_nodes = g_list_append(class_nodes,node);
291 } else if(strcmp($<id>5,"set")==0) {
294 node = new_argument($<id>3,$<list>2,$<id>4,
295 NULL,0,$<cbuf>7,$<line>6,
297 class_nodes = g_list_append(class_nodes,node);
299 g_free($<id>5); g_free($<id>3);
301 g_list_foreach($<list>2,(GFunc)g_free,NULL);
302 g_string_free($<cbuf>7,TRUE);
303 yyerror(_("parse error"));
309 argflags: '(' flaglist ')' { $<list>$ = $<list>2; }
310 | { $<list>$ = NULL; }
313 flaglist: TOKEN '|' flaglist {
314 $<list>$ = g_list_append($<list>3,$<id>1);
317 $<list>$ = g_list_append(NULL,$<id>1);
324 Type *type = typestack->data;
325 char *oldname = type->name;
326 type->name = g_strconcat("const ",oldname,NULL);
332 Node *node = new_type(0,$<id>1,NULL);
333 typestack = g_list_prepend(typestack,node);
336 Node *node = new_type(stars,$<id>1,NULL);
338 typestack = g_list_prepend(typestack,node);
342 type2: UNSIGNED integer {
343 $<id>$ = g_strconcat("unsigned ",$<id>2,NULL);
346 $<id>$ = g_strconcat("signed ",$<id>2,NULL);
349 $<id>$ = g_strdup($<id>1);
352 $<id>$ = g_strdup("unsigned char");
355 $<id>$ = g_strdup("signed char");
358 $<id>$ = g_strdup("char");
361 $<id>$ = g_strdup("double");
364 $<id>$ = g_strdup("float");
370 $<id>$ = g_strconcat($<id>1,$<id>2,NULL);
377 $<id>$ = g_strdup("void");
388 $<id>$ = "short int";
409 stars: '*' stars { stars++; }
413 fullsigtype: PRIVATE TOKEN sigtype {
414 if(strcmp($<id>2,"first")==0)
415 $<sigtype>$ = PRIVATE_SIGNAL_FIRST_METHOD;
416 else if(strcmp($<id>2,"last")==0)
417 $<sigtype>$ = PRIVATE_SIGNAL_LAST_METHOD;
419 yyerror(_("signal must be 'first' or 'last'"));
425 | TOKEN PRIVATE sigtype {
426 if(strcmp($<id>1,"first")==0)
427 $<sigtype>$ = PRIVATE_SIGNAL_FIRST_METHOD;
428 else if(strcmp($<id>1,"last")==0)
429 $<sigtype>$ = PRIVATE_SIGNAL_LAST_METHOD;
431 yyerror(_("signal must be 'first' or 'last'"));
438 $<sigtype>$ = PRIVATE_SIGNAL_LAST_METHOD;
441 if(strcmp($<id>1,"first")==0)
442 $<sigtype>$ = SIGNAL_FIRST_METHOD;
443 else if(strcmp($<id>1,"last")==0)
444 $<sigtype>$ = SIGNAL_LAST_METHOD;
446 yyerror(_("signal must be 'first' or 'last'"));
453 $<sigtype>$ = SIGNAL_LAST_METHOD;
457 sigtype: TOKEN '(' tokenlist ')' {
458 gtktypes = g_list_prepend(gtktypes,$<id>1);
462 tokenlist: tokenlist ',' TOKEN {
463 gtktypes = g_list_append(gtktypes,$<id>3);
466 gtktypes = g_list_append(gtktypes,$<id>1);
470 codenocode: '{' CCODE { $<cbuf>$=$<cbuf>2; }
471 | ';' { $<cbuf>$ = NULL; }
474 /*here CCODE will include the ending '}' */
475 method: SIGNAL fullsigtype type TOKEN '(' funcargs ')' onerror codenocode {
477 yyerror(_("signal without 'self' as "
481 push_function($<sigtype>2,NULL,
482 $<id>4, $<id>8, $<cbuf>9,$<line>1,
485 | VIRTUAL PRIVATE type TOKEN '(' funcargs ')' onerror codenocode {
487 yyerror(_("virtual method without 'self' as "
491 push_function(PRIVATE_VIRTUAL_METHOD, NULL, $<id>4,
492 $<id>8, $<cbuf>9,$<line>1,
495 | VIRTUAL type TOKEN '(' funcargs ')' onerror codenocode {
497 yyerror(_("virtual method without 'self' as "
501 push_function(VIRTUAL_METHOD, NULL, $<id>3,
502 $<id>7, $<cbuf>8,$<line>1,
505 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' onerror '{' CCODE {
506 push_function(OVERRIDE_METHOD, $<id>3,
507 $<id>6, $<id>10, $<cbuf>12,
511 | PUBLIC type TOKEN '(' funcargs ')' onerror '{' CCODE {
512 push_function(PUBLIC_SCOPE, NULL, $<id>3,
513 $<id>7, $<cbuf>9,$<line>1,$<line>8,
516 | PRIVATE type TOKEN '(' funcargs ')' onerror '{' CCODE {
517 push_function(PRIVATE_SCOPE, NULL, $<id>3,
518 $<id>7, $<cbuf>9,$<line>1,$<line>8,
521 | TOKEN '(' TOKEN ')' codenocode {
522 if(strcmp($<id>1,"init")==0) {
523 push_init_arg($<id>3,FALSE);
524 push_function(INIT_METHOD, NULL,
525 $<id>1, NULL, $<cbuf>5,$<line>2,
527 } else if(strcmp($<id>1,"class_init")==0) {
528 push_init_arg($<id>3,TRUE);
529 push_function(CLASS_INIT_METHOD, NULL,
530 $<id>1, NULL, $<cbuf>5,$<line>2,
535 g_string_free($<cbuf>3,TRUE);
536 yyerror(_("parse error"));
542 onerror: ONERROR numtok { $<id>$ = $<id>2; }
543 | ONERROR '{' CCODE {
544 $<id>$ = ($<cbuf>3)->str;
545 g_string_free($<cbuf>3,FALSE);
551 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
555 if(strcmp($<id>1,"self")==0)
559 yyerror(_("parse error"));
563 | TOKEN ',' arglist {
565 if(strcmp($<id>1,"self")==0)
569 yyerror(_("parse error"));
573 | arglist { has_self = FALSE; }
576 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
577 | arglist1 { vararg = FALSE; }
580 arglist1: arglist1 ',' arg { ; }
585 push_funcarg($<id>2,NULL);
587 | type TOKEN ARRAY_DIM {
588 push_funcarg($<id>2,$<id>3);
590 | type TOKEN '(' TOKEN checklist ')' {
591 if(strcmp($<id>4,"check")!=0) {
592 yyerror(_("parse error"));
596 push_funcarg($<id>2,NULL);
598 | type TOKEN ARRAY_DIM '(' TOKEN checklist ')' {
599 if(strcmp($<id>5,"check")!=0) {
600 yyerror(_("parse error"));
604 push_funcarg($<id>2,$<id>3);
608 checklist: checklist check { ; }
613 if(strcmp($<id>1,"type")==0) {
614 Node *node = new_check(TYPE_CHECK,NULL);
615 checks = g_list_append(checks,node);
616 } else if(strcmp($<id>1,"null")==0) {
617 Node *node = new_check(NULL_CHECK,NULL);
618 checks = g_list_append(checks,node);
620 yyerror(_("parse error"));
626 Node *node = new_check(GT_CHECK,$<id>2);
627 checks = g_list_append(checks,node);
630 Node *node = new_check(LT_CHECK,$<id>2);
631 checks = g_list_append(checks,node);
634 Node *node = new_check(GE_CHECK,$<id>3);
635 checks = g_list_append(checks,node);
638 Node *node = new_check(LE_CHECK,$<id>3);
639 checks = g_list_append(checks,node);
642 Node *node = new_check(EQ_CHECK,$<id>3);
643 checks = g_list_append(checks,node);
646 Node *node = new_check(NE_CHECK,$<id>3);
647 checks = g_list_append(checks,node);
651 numtok: NUMBER { $<id>$ = $<id>1; }
653 $<id>$ = g_strconcat("-",$<id>2,NULL);
656 | TOKEN { $<id>$ = $<id>1; }