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;
46 static GList *gtktypes = NULL;
51 extern int ccode_line;
62 if(strcmp(yytext,"\n")==0) {
63 out=g_strconcat("Error: ",str," before newline",NULL);
64 } else if(yytext[0]=='\0') {
65 out=g_strconcat("Error: ",str," at end of input",NULL);
67 char *tmp = g_strdup(yytext);
68 while((p=strchr(tmp,'\n')))
71 out=g_strconcat("Error: ",str," before '",tmp,"'",NULL);
75 fprintf(stderr,"%s:%d: %s\n",filename,line_no,out);
82 push_variable(char *name, int scope, int line_no)
85 Type *type = typestack->data;
86 typestack = g_list_remove(typestack,typestack->data);
88 var = new_variable(scope,type,name,line_no);
89 class_nodes = g_list_append(class_nodes, var);
93 push_function(int scope, char *oid, char *id, char *onerror,
94 GString *cbuf,int line_no, int ccode_line)
99 if(scope!=INIT_METHOD && scope!=CLASS_INIT_METHOD) {
100 type = typestack->data;
101 typestack = g_list_remove(typestack,typestack->data);
103 type = (Type *)new_type(0,g_strdup("void"));
106 node = new_method(scope,type,oid,gtktypes,id,funcargs,
107 onerror,cbuf,line_no,ccode_line);
111 class_nodes = g_list_append(class_nodes, node);
115 push_funcarg(char *name)
118 Type *type = typestack->data;
119 typestack = g_list_remove(typestack,typestack->data);
121 node = new_funcarg(type,name,checks);
124 funcargs = g_list_append(funcargs, node);
128 push_init_arg(char *name, int is_class)
135 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
137 tn = g_strdup(((Class *)class)->otype);
139 type = new_type(1,tn);
140 node = new_funcarg((Type *)type,name,NULL);
141 funcargs = g_list_prepend(funcargs, node);
150 type = new_type(1,g_strdup(((Class *)class)->otype));
151 ch = g_list_append(ch,new_check(NULL_CHECK,NULL));
152 ch = g_list_append(ch,new_check(TYPE_CHECK,NULL));
153 node = new_funcarg((Type *)type,id,ch);
154 funcargs = g_list_prepend(funcargs, node);
167 %token VOID STRUCT UNION ENUM SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
171 %token <id> TOKEN NUMBER TYPETOKEN
172 %token <cbuf> CCODE HCODE
173 %token <line> PUBLIC PRIVATE ARGUMENT VIRTUAL SIGNAL OVERRIDE
177 prog: ccodes class ccodes { ; }
183 ccodes: ccodes CCODE {
184 Node *node = new_ccode(FALSE,$<cbuf>2,ccode_line);
185 nodes = g_list_append(nodes,node);
188 Node *node = new_ccode(TRUE,$<cbuf>2,ccode_line);
189 nodes = g_list_append(nodes,node);
192 Node *node = new_ccode(FALSE,$<cbuf>1,ccode_line);
193 nodes = g_list_append(nodes,node);
196 Node *node = new_ccode(TRUE,$<cbuf>1,ccode_line);
197 nodes = g_list_append(nodes,node);
201 class: classdec '{' classcode '}' {
202 ((Class *)class)->nodes = class_nodes;
204 nodes = g_list_append(nodes,class);
208 classdec: CLASS TYPETOKEN FROM TYPETOKEN {
209 class = new_class($<id>2,$<id>4,NULL);
213 classcode: classcode method { ; }
214 | classcode variable { ; }
215 | classcode argument { ; }
221 variable: PUBLIC type TOKEN ';' {
222 push_variable($<id>3,PUBLIC_SCOPE,$<line>1);
224 | PRIVATE type TOKEN ';' {
225 push_variable($<id>3,PRIVATE_SCOPE,$<line>1);
228 argument: ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
229 if(strcmp($<id>5,"get")==0 &&
230 strcmp($<id>8,"set")==0) {
232 g_free($<id>5); g_free($<id>8);
233 node = new_argument($<id>3,$<list>2,$<id>4,
237 class_nodes = g_list_append(class_nodes,node);
238 } else if(strcmp($<id>5,"set")==0 &&
239 strcmp($<id>8,"get")==0) {
241 g_free($<id>5); g_free($<id>8);
242 node = new_argument($<id>3,$<list>2,$<id>4,
246 class_nodes = g_list_append(class_nodes,node);
248 g_free($<id>3); g_free($<id>4);
249 g_free($<id>5); g_free($<id>8);
250 g_list_foreach($<list>2,(GFunc)g_free,NULL);
251 g_string_free($<cbuf>10,TRUE);
252 g_string_free($<cbuf>7,TRUE);
253 yyerror(_("parse error"));
257 | ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE ';' {
258 if(strcmp($<id>5,"get")==0) {
261 node = new_argument($<id>3,$<list>2,$<id>4,
262 $<cbuf>7,$<line>6,NULL,0,
264 class_nodes = g_list_append(class_nodes,node);
265 } else if(strcmp($<id>5,"set")==0) {
268 node = new_argument($<id>3,$<list>2,$<id>4,
269 NULL,0,$<cbuf>7,$<line>6,
271 class_nodes = g_list_append(class_nodes,node);
273 g_free($<id>5); g_free($<id>3);
275 g_list_foreach($<list>2,(GFunc)g_free,NULL);
276 g_string_free($<cbuf>7,TRUE);
277 yyerror(_("parse error"));
283 argflags: '(' flaglist ')' { $<list>$ = $<list>2; }
284 | { $<list>$ = NULL; }
287 flaglist: TOKEN '|' flaglist {
288 $<list>$ = g_list_append($<list>3,$<id>1);
291 $<list>$ = g_list_append(NULL,$<id>1);
297 Node *node = new_type(0,$<id>1);
298 typestack = g_list_prepend(typestack,node);
301 Node *node = new_type(stars,$<id>1);
303 typestack = g_list_prepend(typestack,node);
307 type1: UNSIGNED integer {
308 $<id>$ = g_strconcat("unsigned ",$<id>2,NULL);
311 $<id>$ = g_strconcat("signed ",$<id>2,NULL);
314 $<id>$ = g_strdup($<id>1);
317 $<id>$ = g_strdup("unsigned char");
320 $<id>$ = g_strdup("signed char");
323 $<id>$ = g_strdup("char");
326 $<id>$ = g_strdup("double");
329 $<id>$ = g_strdup("float");
335 $<id>$ = g_strconcat($<id>1,$<id>2,NULL);
342 $<id>$ = g_strdup("void");
353 $<id>$ = "short int";
374 stars: '*' stars { stars++; }
378 sigtype: TOKEN '(' tokenlist ')' {
379 gtktypes = g_list_prepend(gtktypes,$<id>1);
383 tokenlist: tokenlist ',' TOKEN {
384 gtktypes = g_list_append(gtktypes,$<id>3);
387 gtktypes = g_list_append(gtktypes,$<id>1);
391 codenocode: '{' CCODE { $<cbuf>$=$<cbuf>2; }
392 | ';' { $<cbuf>$ = NULL; }
395 /*here CCODE will include the ending '}' */
396 method: SIGNAL TOKEN sigtype type TOKEN '(' funcargs ')' onerror codenocode {
397 int sigtype = SIGNAL_LAST_METHOD;
398 if(strcmp($<id>2,"first")==0)
399 sigtype = SIGNAL_FIRST_METHOD;
400 else if(strcmp($<id>2,"last")==0)
401 sigtype = SIGNAL_LAST_METHOD;
403 yyerror(_("signal must be 'first' or 'last'"));
410 yyerror(_("signal without 'self' as "
414 push_function(sigtype,NULL,
415 $<id>5, $<id>9, $<cbuf>10,$<line>1,ccode_line);
417 | SIGNAL sigtype type TOKEN '(' funcargs ')' onerror codenocode {
419 yyerror(_("signal without 'self' as "
423 push_function(SIGNAL_LAST_METHOD, NULL,
424 $<id>4, $<id>8, $<cbuf>9,$<line>1,ccode_line);
426 | VIRTUAL type TOKEN '(' funcargs ')' onerror codenocode {
428 yyerror(_("virtual method without 'self' as "
432 push_function(VIRTUAL_METHOD, NULL, $<id>3,
433 $<id>7, $<cbuf>8,$<line>1,ccode_line);
435 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' onerror '{' CCODE {
436 push_function(OVERRIDE_METHOD, $<id>3,
437 $<id>6, $<id>10, $<cbuf>12,$<line>1,$<line>11);
439 | PUBLIC type TOKEN '(' funcargs ')' onerror '{' CCODE {
440 push_function(PUBLIC_SCOPE, NULL, $<id>3,
441 $<id>7, $<cbuf>9,$<line>1,$<line>8);
443 | PRIVATE type TOKEN '(' funcargs ')' onerror '{' CCODE {
444 push_function(PRIVATE_SCOPE, NULL, $<id>3,
445 $<id>7, $<cbuf>9,$<line>1,$<line>8);
447 | TOKEN '(' TOKEN ')' ';' {
448 if(strcmp($<id>1,"init")==0) {
449 push_init_arg($<id>3,FALSE);
450 push_function(INIT_METHOD, NULL, $<id>1,
451 NULL, NULL,$<line>2,0);
452 } else if(strcmp($<id>1,"class_init")==0) {
453 push_init_arg($<id>3,TRUE);
454 push_function(CLASS_INIT_METHOD, NULL,
455 $<id>1, NULL, NULL,$<line>2,0);
459 yyerror(_("parse error"));
463 | TOKEN '(' TOKEN ')' '{' CCODE {
464 if(strcmp($<id>1,"init")==0) {
465 push_init_arg($<id>3,FALSE);
466 push_function(INIT_METHOD, NULL,
467 $<id>1, NULL, $<cbuf>6,$<line>2,
469 } else if(strcmp($<id>1,"class_init")==0) {
470 push_init_arg($<id>3,TRUE);
471 push_function(CLASS_INIT_METHOD, NULL,
472 $<id>1, NULL, $<cbuf>6,$<line>2,
477 g_string_free($<cbuf>3,TRUE);
478 yyerror(_("parse error"));
484 onerror: ONERROR numtok { $<id>$ = $<id>2; }
485 | ONERROR '{' CCODE {
486 $<id>$ = ($<cbuf>3)->str;
487 g_string_free($<cbuf>3,FALSE);
495 funcargs: VOID { has_self = FALSE; }
498 if(strcmp($<id>1,"this")==0) {
500 print_error(TRUE,_("Use of 'this' is "
501 "depreciated, use 'self' "
503 } else if(strcmp($<id>1,"self")==0)
507 yyerror(_("parse error"));
511 | TOKEN ',' arglist {
513 if(strcmp($<id>1,"this")==0) {
515 print_error(TRUE,_("Use of 'this' is "
516 "depreciated, use 'self' "
518 } else if(strcmp($<id>1,"self")==0)
522 yyerror(_("parse error"));
526 | arglist { has_self = FALSE; }
529 arglist: arglist ',' arg { ; }
534 push_funcarg($<id>2);
536 | type TOKEN '(' TOKEN checklist ')' {
537 if(strcmp($<id>4,"check")!=0) {
538 yyerror(_("parse error"));
542 push_funcarg($<id>2);
546 checklist: checklist check { ; }
551 if(strcmp($<id>1,"type")==0) {
552 Node *node = new_check(TYPE_CHECK,NULL);
553 checks = g_list_append(checks,node);
554 } else if(strcmp($<id>1,"null")==0) {
555 Node *node = new_check(NULL_CHECK,NULL);
556 checks = g_list_append(checks,node);
558 yyerror(_("parse error"));
564 Node *node = new_check(GT_CHECK,$<id>2);
565 checks = g_list_append(checks,node);
568 Node *node = new_check(LT_CHECK,$<id>2);
569 checks = g_list_append(checks,node);
572 Node *node = new_check(GE_CHECK,$<id>3);
573 checks = g_list_append(checks,node);
576 Node *node = new_check(LE_CHECK,$<id>3);
577 checks = g_list_append(checks,node);
580 Node *node = new_check(EQ_CHECK,$<id>3);
581 checks = g_list_append(checks,node);
584 Node *node = new_check(NE_CHECK,$<id>3);
585 checks = g_list_append(checks,node);
589 numtok: NUMBER { $<id>$ = $<id>1; }
591 $<id>$ = g_strconcat("-",$<id>2,NULL);
594 | TOKEN { $<id>$ = $<id>1; }