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"
34 static int parenth_depth = 0;
35 static int before_comment
36 /* New flex is on drugs */
37 #if defined(FLEX_SCANNER) && ! defined(INITIAL)
42 static gboolean class_after_c = FALSE;
43 static int code_type = CCODE;
44 static int before_string;
45 static int property_paren_depth = 0;
48 static char *gtk_doc_func = NULL; /* current gtk-doc func */
49 GHashTable *gtk_doc_hash = NULL;
51 static GString *cbuf = NULL;
54 GList *include_files = NULL;
55 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
56 static int look_for_includes = 0;
59 /* last filename parsed from a #line directive */
60 char *hline_filename = NULL;
66 cbuf = g_string_new(NULL);
68 cbuf = g_string_assign(cbuf, "");
76 cbuf = g_string_new(s);
78 cbuf = g_string_append(cbuf,s);
83 add_gtk_doc_func(void)
89 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
90 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
96 /* Ugly warning avoiding */
111 %x GTK_DOC_BEFORE_NAME
120 /* Avoid warning from flex, cuz flex sucks */
122 yy_current_state = 0;
127 <*>\n { line_no++; REJECT; }
129 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
130 /* Thy evil easter egg */
132 #define KK(x) =atoi(__(&,,x,))
133 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
134 #define PP(Q) (P%Q)==0
135 #define ___(x,y,z) if(x z y)
136 #define __(a,x,y,z) a(yytext[y] x z)
137 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
138 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
139 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
140 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
151 \/\/.*$ { ; /*comment, ignore*/ }
153 <*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? {
157 char *str=g_strdup(yytext);
159 /* find first digit of line number */
161 while(*p&&!isdigit(*p)) p++;
164 /* find end of line number */
165 while(*p&&isdigit(*p)) p++;
168 /* find beginning of filename */
173 /* find end of filename */
174 if(p) p=strchr(p,'"');
177 /* stash number (minus one because we don't count this line) */
178 if(number) line_no=atoi(number)-1;
182 if(hline_filename) g_free(hline_filename);
183 hline_filename=g_strdup(filename);
190 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
191 if(look_for_includes==1) {
194 char *str = g_strdup(yytext);
195 file = strchr(str,'"');
196 if(!file) file = strchr(str,'<');
198 p = strchr(file,'"');
199 if(!p) p = strchr(file,'>');
201 include_files = g_list_prepend(include_files,g_strdup(file));
207 <CLASS_CODE_I>\/\*\*[ \t]*$ {
208 /* eat out gtk doc stuff */
209 BEGIN(GTK_DOC_BEFORE_NAME);
212 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
213 /* empty doc lines */
216 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
219 p = strchr(yytext, '*');
220 g_free(gtk_doc_func);
221 gtk_doc_func = g_strdup(p+2);
222 p = strchr(gtk_doc_func, ':');
224 g_strstrip(gtk_doc_func);
226 <GTK_DOC_BEFORE_NAME>\*\/ {
229 <GTK_DOC_BEFORE_NAME>. {
231 before_comment = CLASS_CODE_I;
233 <GTK_DOC>^[ \t]*\*[ \t]*$ {
234 /* empty doc lines */
237 <GTK_DOC>^[ \t]*\*?\*\/ {
241 <GTK_DOC>^[ \t]*\*[ \t] {
251 before_comment = CLASS_CODE_I;
268 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
269 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
270 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
271 <PROPERTY_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
272 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
276 before_comment = C_CODE;
278 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
279 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
280 <PROPERTY_CODE_I>\/\* {BEGIN(COMMENT); before_comment = PROPERTY_CODE_I; }
282 if(before_comment == C_CODE) add_to_cbuf(yytext);
283 BEGIN(before_comment);
286 /* comment, ignore */
287 if(before_comment == C_CODE) add_to_cbuf(yytext);
290 /* comment, ignore */
291 if(before_comment == C_CODE) add_to_cbuf(yytext);
297 class_after_c = FALSE;
300 ccode_line = line_no;
305 class_after_c = FALSE;
308 ccode_line = line_no;
311 ^\%(ht|headertop)\{ {
314 class_after_c = FALSE;
317 ccode_line = line_no;
319 ^\%(ph|privateheader)\{ {
322 class_after_c = FALSE;
325 ccode_line = line_no;
330 class_after_c = FALSE;
333 ccode_line = line_no;
338 class_after_c = FALSE;
341 ccode_line = line_no;
342 if(look_for_includes==0)
349 if(look_for_includes==1)
354 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
355 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
356 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
357 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
358 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
359 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
361 <C_CODE>\\. { add_to_cbuf(yytext); }
366 before_string = C_CODE;
369 <PROPERTY_CODE_I>\" {
371 before_string = PROPERTY_CODE_I;
374 <CODE_STRING>\\. { add_to_cbuf(yytext); }
376 BEGIN(before_string);
378 if (before_string == PROPERTY_CODE_I) {
379 yylval.id = cbuf->str;
380 g_string_free (cbuf, FALSE);
385 <CODE_STRING>. { add_to_cbuf(yytext); }
386 <CODE_STRING>\n { add_to_cbuf(yytext); }
394 if(parenth_depth<0) {
396 } else if(parenth_depth==0 && class_after_c) {
405 <C_CODE>. { add_to_cbuf(yytext); }
406 <C_CODE>\n { add_to_cbuf(yytext); }
409 static int found_classes = 0;
410 look_for_includes = 2;
413 if(++found_classes > 1) {
414 error_print(GOB_ERROR, line_no,
415 "Only one class per file allowed");
421 error { return ERROR; }
422 enum { return ENUM; }
423 flags { return FLAGS; }
425 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
426 int maj = 0, min = 0, pl = 0;
427 int rmaj = 0, rmin = 0, rpl = 0;
428 int effective_maj = 0;
429 int effective_rmaj = 0;
432 sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl);
433 effective_rmaj = rmaj;
435 effective_rmaj = rmaj + 1;
437 p = strchr (yytext,'r');
438 g_assert (p); /* we MUST have found it */
439 sscanf (p, "requires %d.%d.%d", &maj, &min, &pl);
442 effective_maj = maj + 1;
445 (rmaj == maj && rmin < min) ||
446 (rmaj == maj && rmin == min && rpl < pl)) {
447 error_printf (GOB_ERROR, line_no,
448 "GOB version at least %d.%d.%d required "
450 "To upgrade your gob, see: "
451 "http://www.5z.com/jirka/gob.html",
452 maj, min, pl, VERSION);
455 if(effective_rmaj != effective_maj) {
456 error_printf(GOB_ERROR, line_no,
457 "GOB major version %d required "
459 "To upgrade your gob, see: "
460 "http://www.5z.com/jirka/gob.html",
461 effective_maj, VERSION);
466 <CLASS_CODE,CLASS_CODE_I>class|this {
468 error_printf(GOB_WARN, line_no,
469 "'%s' keyword should not "
470 "be used when generating "
476 <CLASS_CODE>from {return FROM;}
479 before_string = CLASS_CODE;
482 <CLASS_STRING>\\. { add_to_cbuf(yytext); }
484 BEGIN(before_string);
486 yylval.id = cbuf->str;
487 g_string_free (cbuf, FALSE);
491 <CLASS_STRING>. { add_to_cbuf(yytext); }
492 <CLASS_STRING>\n { add_to_cbuf(yytext); }
494 <CLASS_CODE_I,PROPERTY_CODE_I>void {return VOID;}
495 <CLASS_CODE_I,PROPERTY_CODE_I>struct {return STRUCT;}
496 <CLASS_CODE_I,PROPERTY_CODE_I>union {return UNION;}
497 <CLASS_CODE_I,PROPERTY_CODE_I>enum {return ENUM;}
498 <CLASS_CODE_I,PROPERTY_CODE_I>signed {return SIGNED;}
499 <CLASS_CODE_I,PROPERTY_CODE_I>unsigned {return UNSIGNED;}
500 <CLASS_CODE_I,PROPERTY_CODE_I>long {return LONG;}
501 <CLASS_CODE_I,PROPERTY_CODE_I>short {return SHORT;}
502 <CLASS_CODE_I,PROPERTY_CODE_I>int {return INT;}
503 <CLASS_CODE_I,PROPERTY_CODE_I>float {return FLOAT;}
504 <CLASS_CODE_I,PROPERTY_CODE_I>double {return DOUBLE;}
505 <CLASS_CODE_I,PROPERTY_CODE_I>char {return CHAR;}
506 <CLASS_CODE_I,PROPERTY_CODE_I>const {return CONST;}
508 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
510 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
511 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
512 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
513 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
514 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
515 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
516 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
517 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
518 <CLASS_CODE_I>property {
519 yylval.line = line_no;
520 BEGIN(PROPERTY_CODE);
523 <PROPERTY_CODE_I>nick { yylval.line = line_no; return NICK; }
524 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
525 <PROPERTY_CODE_I>maximum { yylval.line = line_no; return MAXIMUM; }
526 <PROPERTY_CODE_I>minimum { yylval.line = line_no; return MINIMUM; }
527 <PROPERTY_CODE_I>default_value { yylval.line = line_no; return DEFAULT_VALUE; }
528 <PROPERTY_CODE_I>flags { yylval.line = line_no; return FLAGS; }
529 <PROPERTY_CODE_I>type { yylval.line = line_no; return TYPE; }
530 <PROPERTY_CODE_I>flags_type { yylval.line = line_no; return FLAGS_TYPE; }
531 <PROPERTY_CODE_I>enum_type { yylval.line = line_no; return ENUM_TYPE; }
532 <PROPERTY_CODE_I>param_type { yylval.line = line_no; return PARAM_TYPE; }
533 <PROPERTY_CODE_I>boxed_type { yylval.line = line_no; return BOXED_TYPE; }
534 <PROPERTY_CODE_I>object_type { yylval.line = line_no; return OBJECT_TYPE; }
536 yylval.line = line_no;
537 property_paren_depth = 1;
538 BEGIN(PROPERTY_CODE_I);
541 <PROPERTY_CODE_I>[(] {
542 yylval.line = line_no;
543 property_paren_depth++;
546 <PROPERTY_CODE_I>[)] {
547 yylval.line = line_no;
548 property_paren_depth--;
549 if (property_paren_depth == 0) {
555 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>0|[1-9][0-9]*|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+|\.[0-9][0-9]* {
556 yylval.id = g_strdup(yytext);
559 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z0-9_]*)+ {
560 /* This is cpp kind of token thingie */
562 yylval.id = g_strdup(yytext);
568 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z_][A-Za-z0-9_]*)+ {
569 /* this one is for a classname with a namespace */
570 yylval.id = g_strdup(yytext);
573 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z_][A-Za-z0-9_]*)* {
574 /* this is for a classname with an empty namespace */
575 yylval.id = g_strdup(yytext);
578 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]* {
579 yylval.id = g_strdup(yytext);
582 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>\'\\.\'|\'.\' {
583 yylval.id = g_strdup(yytext);
587 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
588 yylval.id = g_strdup(yytext);
591 <CLASS_CODE_I>:[0-9]+ {
592 /* cheat for bitfield */
593 yylval.id = g_strdup(yytext);
600 <CLASS_CODE_I,PROPERTY_CODE>\{ {
603 class_after_c = TRUE;
604 yylval.line = line_no;
606 ccode_line = line_no;
614 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ; /*ignore*/
617 yylval.line = line_no;
621 <*>[\n\r] ; /*ignore*/
623 ^[ \t]*prealloc[ \t]+[0-9]+[ \t]*$ {
626 p = strchr (yytext,'p');
627 g_assert (p); /* we MUST have found it */
628 sscanf (p, "prealloc %d", &t);