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 node = new_method(scope,type,oid,gtktypes,id,funcargs,
108 onerror,cbuf,line_no,ccode_line,vararg);
112 class_nodes = g_list_append(class_nodes, node);
116 push_funcarg(char *name)
119 Type *type = typestack->data;
120 typestack = g_list_remove(typestack,typestack->data);
122 node = new_funcarg(type,name,checks);
125 funcargs = g_list_append(funcargs, node);
129 push_init_arg(char *name, int is_class)
136 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
138 tn = g_strdup(((Class *)class)->otype);
140 type = new_type(1,tn);
141 node = new_funcarg((Type *)type,name,NULL);
142 funcargs = g_list_prepend(funcargs, node);
151 type = new_type(1,g_strdup(((Class *)class)->otype));
152 ch = g_list_append(ch,new_check(NULL_CHECK,NULL));
153 ch = g_list_append(ch,new_check(TYPE_CHECK,NULL));
154 node = new_funcarg((Type *)type,id,ch);
155 funcargs = g_list_prepend(funcargs, node);
168 %token CONST VOID STRUCT UNION ENUM THREEDOTS
169 %token SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
172 %token <id> TOKEN NUMBER TYPETOKEN
173 %token <cbuf> CCODE HCODE
174 %token <line> PUBLIC PRIVATE ARGUMENT VIRTUAL SIGNAL OVERRIDE
178 prog: ccodes class ccodes { ; }
184 ccodes: ccodes CCODE {
185 Node *node = new_ccode(FALSE,$<cbuf>2,ccode_line);
186 nodes = g_list_append(nodes,node);
189 Node *node = new_ccode(TRUE,$<cbuf>2,ccode_line);
190 nodes = g_list_append(nodes,node);
193 Node *node = new_ccode(FALSE,$<cbuf>1,ccode_line);
194 nodes = g_list_append(nodes,node);
197 Node *node = new_ccode(TRUE,$<cbuf>1,ccode_line);
198 nodes = g_list_append(nodes,node);
202 class: classdec '{' classcode '}' {
203 ((Class *)class)->nodes = class_nodes;
205 nodes = g_list_append(nodes,class);
209 classdec: CLASS TYPETOKEN FROM TYPETOKEN {
210 class = new_class($<id>2,$<id>4,NULL);
214 classcode: classcode method { ; }
215 | classcode variable { ; }
216 | classcode argument { ; }
222 variable: PUBLIC type TOKEN ';' {
223 push_variable($<id>3,PUBLIC_SCOPE,$<line>1);
225 | PRIVATE type TOKEN ';' {
226 push_variable($<id>3,PRIVATE_SCOPE,$<line>1);
229 argument: ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
230 if(strcmp($<id>5,"get")==0 &&
231 strcmp($<id>8,"set")==0) {
233 g_free($<id>5); g_free($<id>8);
234 node = new_argument($<id>3,$<list>2,$<id>4,
238 class_nodes = g_list_append(class_nodes,node);
239 } else if(strcmp($<id>5,"set")==0 &&
240 strcmp($<id>8,"get")==0) {
242 g_free($<id>5); g_free($<id>8);
243 node = new_argument($<id>3,$<list>2,$<id>4,
247 class_nodes = g_list_append(class_nodes,node);
249 g_free($<id>3); g_free($<id>4);
250 g_free($<id>5); g_free($<id>8);
251 g_list_foreach($<list>2,(GFunc)g_free,NULL);
252 g_string_free($<cbuf>10,TRUE);
253 g_string_free($<cbuf>7,TRUE);
254 yyerror(_("parse error"));
258 | ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE ';' {
259 if(strcmp($<id>5,"get")==0) {
262 node = new_argument($<id>3,$<list>2,$<id>4,
263 $<cbuf>7,$<line>6,NULL,0,
265 class_nodes = g_list_append(class_nodes,node);
266 } else if(strcmp($<id>5,"set")==0) {
269 node = new_argument($<id>3,$<list>2,$<id>4,
270 NULL,0,$<cbuf>7,$<line>6,
272 class_nodes = g_list_append(class_nodes,node);
274 g_free($<id>5); g_free($<id>3);
276 g_list_foreach($<list>2,(GFunc)g_free,NULL);
277 g_string_free($<cbuf>7,TRUE);
278 yyerror(_("parse error"));
284 argflags: '(' flaglist ')' { $<list>$ = $<list>2; }
285 | { $<list>$ = NULL; }
288 flaglist: TOKEN '|' flaglist {
289 $<list>$ = g_list_append($<list>3,$<id>1);
292 $<list>$ = g_list_append(NULL,$<id>1);
299 Type *type = typestack->data;
300 char *oldname = type->name;
301 type->name = g_strconcat("const ",oldname,NULL);
307 Node *node = new_type(0,$<id>1);
308 typestack = g_list_prepend(typestack,node);
311 Node *node = new_type(stars,$<id>1);
313 typestack = g_list_prepend(typestack,node);
317 type2: UNSIGNED integer {
318 $<id>$ = g_strconcat("unsigned ",$<id>2,NULL);
321 $<id>$ = g_strconcat("signed ",$<id>2,NULL);
324 $<id>$ = g_strdup($<id>1);
327 $<id>$ = g_strdup("unsigned char");
330 $<id>$ = g_strdup("signed char");
333 $<id>$ = g_strdup("char");
336 $<id>$ = g_strdup("double");
339 $<id>$ = g_strdup("float");
345 $<id>$ = g_strconcat($<id>1,$<id>2,NULL);
352 $<id>$ = g_strdup("void");
363 $<id>$ = "short int";
384 stars: '*' stars { stars++; }
388 sigtype: TOKEN '(' tokenlist ')' {
389 gtktypes = g_list_prepend(gtktypes,$<id>1);
393 tokenlist: tokenlist ',' TOKEN {
394 gtktypes = g_list_append(gtktypes,$<id>3);
397 gtktypes = g_list_append(gtktypes,$<id>1);
401 codenocode: '{' CCODE { $<cbuf>$=$<cbuf>2; }
402 | ';' { $<cbuf>$ = NULL; }
405 /*here CCODE will include the ending '}' */
406 method: SIGNAL TOKEN sigtype type TOKEN '(' funcargs ')' onerror codenocode {
407 int sigtype = SIGNAL_LAST_METHOD;
408 if(strcmp($<id>2,"first")==0)
409 sigtype = SIGNAL_FIRST_METHOD;
410 else if(strcmp($<id>2,"last")==0)
411 sigtype = SIGNAL_LAST_METHOD;
413 yyerror(_("signal must be 'first' or 'last'"));
420 yyerror(_("signal without 'self' as "
424 push_function(sigtype,NULL,
425 $<id>5, $<id>9, $<cbuf>10,$<line>1,
428 | SIGNAL sigtype type TOKEN '(' funcargs ')' onerror codenocode {
430 yyerror(_("signal without 'self' as "
434 push_function(SIGNAL_LAST_METHOD, NULL,
435 $<id>4, $<id>8, $<cbuf>9,$<line>1,
438 | VIRTUAL type TOKEN '(' funcargs ')' onerror codenocode {
440 yyerror(_("virtual method without 'self' as "
444 push_function(VIRTUAL_METHOD, NULL, $<id>3,
445 $<id>7, $<cbuf>8,$<line>1,
448 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' onerror '{' CCODE {
449 push_function(OVERRIDE_METHOD, $<id>3,
450 $<id>6, $<id>10, $<cbuf>12,
454 | PUBLIC type TOKEN '(' funcargs ')' onerror '{' CCODE {
455 push_function(PUBLIC_SCOPE, NULL, $<id>3,
456 $<id>7, $<cbuf>9,$<line>1,$<line>8,
459 | PRIVATE type TOKEN '(' funcargs ')' onerror '{' CCODE {
460 push_function(PRIVATE_SCOPE, NULL, $<id>3,
461 $<id>7, $<cbuf>9,$<line>1,$<line>8,
464 | TOKEN '(' TOKEN ')' ';' {
465 if(strcmp($<id>1,"init")==0) {
466 push_init_arg($<id>3,FALSE);
467 push_function(INIT_METHOD, NULL, $<id>1,
468 NULL, NULL,$<line>2,0,
470 } else if(strcmp($<id>1,"class_init")==0) {
471 push_init_arg($<id>3,TRUE);
472 push_function(CLASS_INIT_METHOD, NULL,
473 $<id>1, NULL, NULL,$<line>2,0,
478 yyerror(_("parse error"));
482 | TOKEN '(' TOKEN ')' '{' CCODE {
483 if(strcmp($<id>1,"init")==0) {
484 push_init_arg($<id>3,FALSE);
485 push_function(INIT_METHOD, NULL,
486 $<id>1, NULL, $<cbuf>6,$<line>2,
488 } else if(strcmp($<id>1,"class_init")==0) {
489 push_init_arg($<id>3,TRUE);
490 push_function(CLASS_INIT_METHOD, NULL,
491 $<id>1, NULL, $<cbuf>6,$<line>2,
496 g_string_free($<cbuf>3,TRUE);
497 yyerror(_("parse error"));
503 onerror: ONERROR numtok { $<id>$ = $<id>2; }
504 | ONERROR '{' CCODE {
505 $<id>$ = ($<cbuf>3)->str;
506 g_string_free($<cbuf>3,FALSE);
512 funcargs: VOID { has_self = FALSE; }
515 if(strcmp($<id>1,"this")==0) {
517 print_error(TRUE,_("Use of 'this' is "
518 "depreciated, use 'self' "
520 } else if(strcmp($<id>1,"self")==0)
524 yyerror(_("parse error"));
528 | TOKEN ',' arglist {
530 if(strcmp($<id>1,"this")==0) {
532 print_error(TRUE,_("Use of 'this' is "
533 "depreciated, use 'self' "
535 } else if(strcmp($<id>1,"self")==0)
539 yyerror(_("parse error"));
543 | arglist { has_self = FALSE; }
546 arglist: arglist1 ',' THREEDOTS { vararg = TRUE; }
547 | arglist1 { vararg = FALSE; }
550 arglist1: arglist1 ',' arg { ; }
555 push_funcarg($<id>2);
557 | type TOKEN '(' TOKEN checklist ')' {
558 if(strcmp($<id>4,"check")!=0) {
559 yyerror(_("parse error"));
563 push_funcarg($<id>2);
567 checklist: checklist check { ; }
572 if(strcmp($<id>1,"type")==0) {
573 Node *node = new_check(TYPE_CHECK,NULL);
574 checks = g_list_append(checks,node);
575 } else if(strcmp($<id>1,"null")==0) {
576 Node *node = new_check(NULL_CHECK,NULL);
577 checks = g_list_append(checks,node);
579 yyerror(_("parse error"));
585 Node *node = new_check(GT_CHECK,$<id>2);
586 checks = g_list_append(checks,node);
589 Node *node = new_check(LT_CHECK,$<id>2);
590 checks = g_list_append(checks,node);
593 Node *node = new_check(GE_CHECK,$<id>3);
594 checks = g_list_append(checks,node);
597 Node *node = new_check(LE_CHECK,$<id>3);
598 checks = g_list_append(checks,node);
601 Node *node = new_check(EQ_CHECK,$<id>3);
602 checks = g_list_append(checks,node);
605 Node *node = new_check(NE_CHECK,$<id>3);
606 checks = g_list_append(checks,node);
610 numtok: NUMBER { $<id>$ = $<id>1; }
612 $<id>$ = g_strconcat("-",$<id>2,NULL);
615 | TOKEN { $<id>$ = $<id>1; }