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)
86 Type *type = typestack->data;
87 typestack = g_list_remove(typestack,typestack->data);
89 var = new_variable(scope,type,name,line_no);
90 class_nodes = g_list_append(class_nodes, var);
94 push_function(int scope, char *oid, char *id, char *onerror,
95 GString *cbuf,int line_no, int ccode_line, int vararg)
100 if(scope!=INIT_METHOD && scope!=CLASS_INIT_METHOD) {
101 type = typestack->data;
102 typestack = g_list_remove(typestack,typestack->data);
104 type = (Type *)new_type(0,g_strdup("void"));
107 /* a complicated and ugly test to figure out if we have
108 the wrong number of types for a signal */
109 if((scope == SIGNAL_FIRST_METHOD ||
110 scope == SIGNAL_LAST_METHOD ||
111 scope == PRIVATE_SIGNAL_FIRST_METHOD ||
112 scope == PRIVATE_SIGNAL_LAST_METHOD) &&
113 g_list_length(gtktypes) != g_list_length(funcargs) &&
114 !(g_list_length(funcargs) == 1 &&
115 g_list_length(gtktypes) == 2 &&
116 strcmp(gtktypes->next->data,"NONE")==0)) {
117 print_error(TRUE, _("The number of GTK arguments and "
118 "function arguments for a signal "
119 "don't seem to match"),line_no);
121 node = new_method(scope,type,oid,gtktypes,id,funcargs,
122 onerror,cbuf,line_no,ccode_line,vararg);
126 class_nodes = g_list_append(class_nodes, node);
130 push_funcarg(char *name)
133 Type *type = typestack->data;
134 typestack = g_list_remove(typestack,typestack->data);
136 node = new_funcarg(type,name,checks);
139 funcargs = g_list_append(funcargs, node);
143 push_init_arg(char *name, int is_class)
150 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
152 tn = g_strdup(((Class *)class)->otype);
154 type = new_type(1,tn);
155 node = new_funcarg((Type *)type,name,NULL);
156 funcargs = g_list_prepend(funcargs, node);
165 type = new_type(1,g_strdup(((Class *)class)->otype));
166 ch = g_list_append(ch,new_check(NULL_CHECK,NULL));
167 ch = g_list_append(ch,new_check(TYPE_CHECK,NULL));
168 node = new_funcarg((Type *)type,id,ch);
169 funcargs = g_list_prepend(funcargs, node);
183 %token CONST VOID STRUCT UNION ENUM THREEDOTS
184 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
187 %token <id> TOKEN NUMBER TYPETOKEN
188 %token <cbuf> CCODE HCODE
189 %token <line> PUBLIC PRIVATE ARGUMENT VIRTUAL SIGNAL OVERRIDE
193 prog: ccodes class ccodes { ; }
199 ccodes: ccodes CCODE {
200 Node *node = new_ccode(FALSE,$<cbuf>2,ccode_line);
201 nodes = g_list_append(nodes,node);
204 Node *node = new_ccode(TRUE,$<cbuf>2,ccode_line);
205 nodes = g_list_append(nodes,node);
208 Node *node = new_ccode(FALSE,$<cbuf>1,ccode_line);
209 nodes = g_list_append(nodes,node);
212 Node *node = new_ccode(TRUE,$<cbuf>1,ccode_line);
213 nodes = g_list_append(nodes,node);
217 class: classdec '{' classcode '}' {
218 ((Class *)class)->nodes = class_nodes;
220 nodes = g_list_append(nodes,class);
224 classdec: CLASS TYPETOKEN FROM TYPETOKEN {
225 class = new_class($<id>2,$<id>4,NULL);
229 classcode: classcode method { ; }
230 | classcode variable { ; }
231 | classcode argument { ; }
237 variable: PUBLIC type TOKEN ';' {
238 push_variable($<id>3,PUBLIC_SCOPE,$<line>1);
240 | PRIVATE type TOKEN ';' {
241 push_variable($<id>3,PRIVATE_SCOPE,$<line>1);
244 argument: ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
245 if(strcmp($<id>5,"get")==0 &&
246 strcmp($<id>8,"set")==0) {
248 g_free($<id>5); g_free($<id>8);
249 node = new_argument($<id>3,$<list>2,$<id>4,
253 class_nodes = g_list_append(class_nodes,node);
254 } else if(strcmp($<id>5,"set")==0 &&
255 strcmp($<id>8,"get")==0) {
257 g_free($<id>5); g_free($<id>8);
258 node = new_argument($<id>3,$<list>2,$<id>4,
262 class_nodes = g_list_append(class_nodes,node);
264 g_free($<id>3); g_free($<id>4);
265 g_free($<id>5); g_free($<id>8);
266 g_list_foreach($<list>2,(GFunc)g_free,NULL);
267 g_string_free($<cbuf>10,TRUE);
268 g_string_free($<cbuf>7,TRUE);
269 yyerror(_("parse error"));
273 | ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE ';' {
274 if(strcmp($<id>5,"get")==0) {
277 node = new_argument($<id>3,$<list>2,$<id>4,
278 $<cbuf>7,$<line>6,NULL,0,
280 class_nodes = g_list_append(class_nodes,node);
281 } else if(strcmp($<id>5,"set")==0) {
284 node = new_argument($<id>3,$<list>2,$<id>4,
285 NULL,0,$<cbuf>7,$<line>6,
287 class_nodes = g_list_append(class_nodes,node);
289 g_free($<id>5); g_free($<id>3);
291 g_list_foreach($<list>2,(GFunc)g_free,NULL);
292 g_string_free($<cbuf>7,TRUE);
293 yyerror(_("parse error"));
299 argflags: '(' flaglist ')' { $<list>$ = $<list>2; }
300 | { $<list>$ = NULL; }
303 flaglist: TOKEN '|' flaglist {
304 $<list>$ = g_list_append($<list>3,$<id>1);
307 $<list>$ = g_list_append(NULL,$<id>1);
314 Type *type = typestack->data;
315 char *oldname = type->name;
316 type->name = g_strconcat("const ",oldname,NULL);
322 Node *node = new_type(0,$<id>1);
323 typestack = g_list_prepend(typestack,node);
326 Node *node = new_type(stars,$<id>1);
328 typestack = g_list_prepend(typestack,node);
332 type2: UNSIGNED integer {
333 $<id>$ = g_strconcat("unsigned ",$<id>2,NULL);
336 $<id>$ = g_strconcat("signed ",$<id>2,NULL);
339 $<id>$ = g_strdup($<id>1);
342 $<id>$ = g_strdup("unsigned char");
345 $<id>$ = g_strdup("signed char");
348 $<id>$ = g_strdup("char");
351 $<id>$ = g_strdup("double");
354 $<id>$ = g_strdup("float");
360 $<id>$ = g_strconcat($<id>1,$<id>2,NULL);
367 $<id>$ = g_strdup("void");
378 $<id>$ = "short int";
399 stars: '*' stars { stars++; }
403 fullsigtype: PRIVATE TOKEN sigtype {
404 if(strcmp($<id>2,"first")==0)
405 $<sigtype>$ = PRIVATE_SIGNAL_FIRST_METHOD;
406 else if(strcmp($<id>2,"last")==0)
407 $<sigtype>$ = PRIVATE_SIGNAL_LAST_METHOD;
409 yyerror(_("signal must be 'first' or 'last'"));
415 | TOKEN PRIVATE sigtype {
416 if(strcmp($<id>1,"first")==0)
417 $<sigtype>$ = PRIVATE_SIGNAL_FIRST_METHOD;
418 else if(strcmp($<id>1,"last")==0)
419 $<sigtype>$ = PRIVATE_SIGNAL_LAST_METHOD;
421 yyerror(_("signal must be 'first' or 'last'"));
428 $<sigtype>$ = PRIVATE_SIGNAL_LAST_METHOD;
431 if(strcmp($<id>1,"first")==0)
432 $<sigtype>$ = SIGNAL_FIRST_METHOD;
433 else if(strcmp($<id>1,"last")==0)
434 $<sigtype>$ = SIGNAL_LAST_METHOD;
436 yyerror(_("signal must be 'first' or 'last'"));
443 $<sigtype>$ = SIGNAL_LAST_METHOD;
447 sigtype: TOKEN '(' tokenlist ')' {
448 gtktypes = g_list_prepend(gtktypes,$<id>1);
452 tokenlist: tokenlist ',' TOKEN {
453 gtktypes = g_list_append(gtktypes,$<id>3);
456 gtktypes = g_list_append(gtktypes,$<id>1);
460 codenocode: '{' CCODE { $<cbuf>$=$<cbuf>2; }
461 | ';' { $<cbuf>$ = NULL; }
464 /*here CCODE will include the ending '}' */
465 method: SIGNAL fullsigtype type TOKEN '(' funcargs ')' onerror codenocode {
467 yyerror(_("signal without 'self' as "
471 push_function($<sigtype>2,NULL,
472 $<id>4, $<id>8, $<cbuf>9,$<line>1,
475 | VIRTUAL PRIVATE type TOKEN '(' funcargs ')' onerror codenocode {
477 yyerror(_("virtual method without 'self' as "
481 push_function(PRIVATE_VIRTUAL_METHOD, NULL, $<id>4,
482 $<id>8, $<cbuf>9,$<line>1,
485 | VIRTUAL type TOKEN '(' funcargs ')' onerror codenocode {
487 yyerror(_("virtual method without 'self' as "
491 push_function(VIRTUAL_METHOD, NULL, $<id>3,
492 $<id>7, $<cbuf>8,$<line>1,
495 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' onerror '{' CCODE {
496 push_function(OVERRIDE_METHOD, $<id>3,
497 $<id>6, $<id>10, $<cbuf>12,
501 | PUBLIC type TOKEN '(' funcargs ')' onerror '{' CCODE {
502 push_function(PUBLIC_SCOPE, NULL, $<id>3,
503 $<id>7, $<cbuf>9,$<line>1,$<line>8,
506 | PRIVATE type TOKEN '(' funcargs ')' onerror '{' CCODE {
507 push_function(PRIVATE_SCOPE, NULL, $<id>3,
508 $<id>7, $<cbuf>9,$<line>1,$<line>8,
511 | TOKEN '(' TOKEN ')' codenocode {
512 if(strcmp($<id>1,"init")==0) {
513 push_init_arg($<id>3,FALSE);
514 push_function(INIT_METHOD, NULL,
515 $<id>1, NULL, $<cbuf>5,$<line>2,
517 } else if(strcmp($<id>1,"class_init")==0) {
518 push_init_arg($<id>3,TRUE);
519 push_function(CLASS_INIT_METHOD, NULL,
520 $<id>1, NULL, $<cbuf>5,$<line>2,
525 g_string_free($<cbuf>3,TRUE);
526 yyerror(_("parse error"));
532 onerror: ONERROR numtok { $<id>$ = $<id>2; }
533 | ONERROR '{' CCODE {
534 $<id>$ = ($<cbuf>3)->str;
535 g_string_free($<cbuf>3,FALSE);
541 funcargs: VOID { vararg = FALSE; has_self = FALSE; }
545 if(strcmp($<id>1,"self")==0)
549 yyerror(_("parse error"));
553 | TOKEN ',' arglist {
555 if(strcmp($<id>1,"self")==0)
559 yyerror(_("parse error"));
563 | arglist { has_self = FALSE; }
566 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
567 | arglist1 { vararg = FALSE; }
570 arglist1: arglist1 ',' arg { ; }
575 push_funcarg($<id>2);
577 | type TOKEN '(' TOKEN checklist ')' {
578 if(strcmp($<id>4,"check")!=0) {
579 yyerror(_("parse error"));
583 push_funcarg($<id>2);
587 checklist: checklist check { ; }
592 if(strcmp($<id>1,"type")==0) {
593 Node *node = new_check(TYPE_CHECK,NULL);
594 checks = g_list_append(checks,node);
595 } else if(strcmp($<id>1,"null")==0) {
596 Node *node = new_check(NULL_CHECK,NULL);
597 checks = g_list_append(checks,node);
599 yyerror(_("parse error"));
605 Node *node = new_check(GT_CHECK,$<id>2);
606 checks = g_list_append(checks,node);
609 Node *node = new_check(LT_CHECK,$<id>2);
610 checks = g_list_append(checks,node);
613 Node *node = new_check(GE_CHECK,$<id>3);
614 checks = g_list_append(checks,node);
617 Node *node = new_check(LE_CHECK,$<id>3);
618 checks = g_list_append(checks,node);
621 Node *node = new_check(EQ_CHECK,$<id>3);
622 checks = g_list_append(checks,node);
625 Node *node = new_check(NE_CHECK,$<id>3);
626 checks = g_list_append(checks,node);
630 numtok: NUMBER { $<id>$ = $<id>1; }
632 $<id>$ = g_strconcat("-",$<id>2,NULL);
635 | TOKEN { $<id>$ = $<id>1; }