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,'>');
202 include_files = g_list_prepend(include_files,g_strdup(file));
209 <CLASS_CODE_I>\/\*\*[ \t]*$ {
210 /* eat out gtk doc stuff */
211 BEGIN(GTK_DOC_BEFORE_NAME);
214 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
215 /* empty doc lines */
218 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
221 p = strchr(yytext, '*');
222 g_free(gtk_doc_func);
223 gtk_doc_func = g_strdup(p+2);
224 p = strchr(gtk_doc_func, ':');
226 g_strstrip(gtk_doc_func);
228 <GTK_DOC_BEFORE_NAME>\*\/ {
231 <GTK_DOC_BEFORE_NAME>. {
233 before_comment = CLASS_CODE_I;
235 <GTK_DOC>^[ \t]*\*[ \t]*$ {
236 /* empty doc lines */
239 <GTK_DOC>^[ \t]*\*?\*\/ {
243 <GTK_DOC>^[ \t]*\*[ \t] {
253 before_comment = CLASS_CODE_I;
270 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
271 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
272 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
273 <PROPERTY_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
274 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
278 before_comment = C_CODE;
280 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
281 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
282 <PROPERTY_CODE_I>\/\* {BEGIN(COMMENT); before_comment = PROPERTY_CODE_I; }
284 if(before_comment == C_CODE) add_to_cbuf(yytext);
285 BEGIN(before_comment);
288 /* comment, ignore */
289 if(before_comment == C_CODE) add_to_cbuf(yytext);
292 /* comment, ignore */
293 if(before_comment == C_CODE) add_to_cbuf(yytext);
299 class_after_c = FALSE;
302 ccode_line = line_no;
307 class_after_c = FALSE;
310 ccode_line = line_no;
313 ^\%(ht|headertop)\{ {
316 class_after_c = FALSE;
319 ccode_line = line_no;
321 ^\%(ph|privateheader)\{ {
324 class_after_c = FALSE;
327 ccode_line = line_no;
332 class_after_c = FALSE;
335 ccode_line = line_no;
340 class_after_c = FALSE;
343 ccode_line = line_no;
344 if(look_for_includes==0)
351 if(look_for_includes==1)
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); }
360 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
361 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
363 <C_CODE>\\. { add_to_cbuf(yytext); }
368 before_string = C_CODE;
371 <PROPERTY_CODE_I>\" {
373 before_string = PROPERTY_CODE_I;
376 <CODE_STRING>\\. { add_to_cbuf(yytext); }
378 BEGIN(before_string);
380 if (before_string == PROPERTY_CODE_I) {
381 yylval.id = cbuf->str;
382 g_string_free (cbuf, FALSE);
387 <CODE_STRING>. { add_to_cbuf(yytext); }
388 <CODE_STRING>\n { add_to_cbuf(yytext); }
396 if(parenth_depth<0) {
398 } else if(parenth_depth==0 && class_after_c) {
407 <C_CODE>. { add_to_cbuf(yytext); }
408 <C_CODE>\n { add_to_cbuf(yytext); }
411 static int found_classes = 0;
412 look_for_includes = 2;
415 if(++found_classes > 1) {
416 error_print(GOB_ERROR, line_no,
417 "Only one class per file allowed");
423 error { return ERROR; }
424 enum { return ENUM; }
425 flags { return FLAGS; }
427 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
428 int maj = 0, min = 0, pl = 0;
429 int rmaj = 0, rmin = 0, rpl = 0;
430 int effective_maj = 0;
431 int effective_rmaj = 0;
434 sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl);
435 effective_rmaj = rmaj;
437 effective_rmaj = rmaj + 1;
439 p = strchr (yytext,'r');
440 g_assert (p); /* we MUST have found it */
441 sscanf (p, "requires %d.%d.%d", &maj, &min, &pl);
444 effective_maj = maj + 1;
447 (rmaj == maj && rmin < min) ||
448 (rmaj == maj && rmin == min && rpl < pl)) {
449 error_printf (GOB_ERROR, line_no,
450 "GOB version at least %d.%d.%d required "
452 "To upgrade your gob, see: "
453 "http://www.5z.com/jirka/gob.html",
454 maj, min, pl, VERSION);
457 if(effective_rmaj != effective_maj) {
458 error_printf(GOB_ERROR, line_no,
459 "GOB major version %d required "
461 "To upgrade your gob, see: "
462 "http://www.5z.com/jirka/gob.html",
463 effective_maj, VERSION);
468 <CLASS_CODE,CLASS_CODE_I>class|this {
470 error_printf(GOB_WARN, line_no,
471 "'%s' keyword should not "
472 "be used when generating "
478 <CLASS_CODE>from {return FROM;}
481 before_string = CLASS_CODE;
484 <CLASS_STRING>\\. { add_to_cbuf(yytext); }
486 BEGIN(before_string);
488 yylval.id = cbuf->str;
489 g_string_free (cbuf, FALSE);
493 <CLASS_STRING>. { add_to_cbuf(yytext); }
494 <CLASS_STRING>\n { add_to_cbuf(yytext); }
496 <CLASS_CODE_I,PROPERTY_CODE_I>void {return VOID;}
497 <CLASS_CODE_I,PROPERTY_CODE_I>struct {return STRUCT;}
498 <CLASS_CODE_I,PROPERTY_CODE_I>union {return UNION;}
499 <CLASS_CODE_I,PROPERTY_CODE_I>enum {return ENUM;}
500 <CLASS_CODE_I,PROPERTY_CODE_I>signed {return SIGNED;}
501 <CLASS_CODE_I,PROPERTY_CODE_I>unsigned {return UNSIGNED;}
502 <CLASS_CODE_I,PROPERTY_CODE_I>long {return LONG;}
503 <CLASS_CODE_I,PROPERTY_CODE_I>short {return SHORT;}
504 <CLASS_CODE_I,PROPERTY_CODE_I>int {return INT;}
505 <CLASS_CODE_I,PROPERTY_CODE_I>float {return FLOAT;}
506 <CLASS_CODE_I,PROPERTY_CODE_I>double {return DOUBLE;}
507 <CLASS_CODE_I,PROPERTY_CODE_I>char {return CHAR;}
508 <CLASS_CODE_I,PROPERTY_CODE_I>const {return CONST;}
510 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
512 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
513 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
514 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
515 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
516 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
517 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
518 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
519 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
520 <CLASS_CODE_I>property {
521 yylval.line = line_no;
522 BEGIN(PROPERTY_CODE);
525 <PROPERTY_CODE_I>nick { yylval.line = line_no; return NICK; }
526 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
527 <PROPERTY_CODE_I>maximum { yylval.line = line_no; return MAXIMUM; }
528 <PROPERTY_CODE_I>minimum { yylval.line = line_no; return MINIMUM; }
529 <PROPERTY_CODE_I>default_value { yylval.line = line_no; return DEFAULT_VALUE; }
530 <PROPERTY_CODE_I>flags { yylval.line = line_no; return FLAGS; }
531 <PROPERTY_CODE_I>type { yylval.line = line_no; return TYPE; }
532 <PROPERTY_CODE_I>flags_type { yylval.line = line_no; return FLAGS_TYPE; }
533 <PROPERTY_CODE_I>enum_type { yylval.line = line_no; return ENUM_TYPE; }
534 <PROPERTY_CODE_I>param_type { yylval.line = line_no; return PARAM_TYPE; }
535 <PROPERTY_CODE_I>boxed_type { yylval.line = line_no; return BOXED_TYPE; }
536 <PROPERTY_CODE_I>object_type { yylval.line = line_no; return OBJECT_TYPE; }
538 yylval.line = line_no;
539 property_paren_depth = 1;
540 BEGIN(PROPERTY_CODE_I);
543 <PROPERTY_CODE_I>[(] {
544 yylval.line = line_no;
545 property_paren_depth++;
548 <PROPERTY_CODE_I>[)] {
549 yylval.line = line_no;
550 property_paren_depth--;
551 if (property_paren_depth == 0) {
557 <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]* {
558 yylval.id = g_strdup(yytext);
561 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z0-9_]*)+ {
562 /* This is cpp kind of token thingie */
564 yylval.id = g_strdup(yytext);
570 <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_]*)+ {
571 /* this one is for a classname with a namespace */
572 yylval.id = g_strdup(yytext);
575 <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_]*)* {
576 /* this is for a classname with an empty namespace */
577 yylval.id = g_strdup(yytext);
580 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]* {
581 yylval.id = g_strdup(yytext);
584 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>\'\\.\'|\'.\' {
585 yylval.id = g_strdup(yytext);
589 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
590 yylval.id = g_strdup(yytext);
593 <CLASS_CODE_I>:[0-9]+ {
594 /* cheat for bitfield */
595 yylval.id = g_strdup(yytext);
602 <CLASS_CODE_I,PROPERTY_CODE>\{ {
605 class_after_c = TRUE;
606 yylval.line = line_no;
608 ccode_line = line_no;
616 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ; /*ignore*/
619 yylval.line = line_no;
623 <*>[\n\r] ; /*ignore*/
625 ^[ \t]*prealloc[ \t]+[0-9]+[ \t]*$ {
628 p = strchr (yytext,'p');
629 g_assert (p); /* we MUST have found it */
630 sscanf (p, "prealloc %d", &t);