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 */
110 %x GTK_DOC_BEFORE_NAME
119 /* Avoid warning from flex, cuz flex sucks */
121 yy_current_state = 0;
126 <*>\n { line_no++; REJECT; }
128 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
129 /* Thy evil easter egg */
131 #define KK(x) =atoi(__(&,,x,))
132 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
133 #define PP(Q) (P%Q)==0
134 #define ___(x,y,z) if(x z y)
135 #define __(a,x,y,z) a(yytext[y] x z)
136 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
137 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
138 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
139 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
150 \/\/.*$ { ; /*comment, ignore*/ }
152 <*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? {
156 char *str=g_strdup(yytext);
158 /* find first digit of line number */
160 while(*p&&!isdigit(*p)) p++;
163 /* find end of line number */
164 while(*p&&isdigit(*p)) p++;
167 /* find beginning of filename */
172 /* find end of filename */
173 if(p) p=strchr(p,'"');
176 /* stash number (minus one because we don't count this line) */
177 if(number) line_no=atoi(number)-1;
181 if(hline_filename) g_free(hline_filename);
182 hline_filename=g_strdup(filename);
189 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
190 if(look_for_includes==1) {
193 char *str = g_strdup(yytext);
194 file = strchr(str,'"');
195 if(!file) file = strchr(str,'<');
197 p = strchr(file,'"');
198 if(!p) p = strchr(file,'>');
200 include_files = g_list_prepend(include_files,g_strdup(file));
206 <CLASS_CODE_I>\/\*\*[ \t]*$ {
207 /* eat out gtk doc stuff */
208 BEGIN(GTK_DOC_BEFORE_NAME);
211 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
212 /* empty doc lines */
215 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
218 p = strchr(yytext, '*');
219 g_free(gtk_doc_func);
220 gtk_doc_func = g_strdup(p+2);
221 p = strchr(gtk_doc_func, ':');
223 g_strstrip(gtk_doc_func);
225 <GTK_DOC_BEFORE_NAME>\*\/ {
228 <GTK_DOC_BEFORE_NAME>. {
230 before_comment = CLASS_CODE_I;
232 <GTK_DOC>^[ \t]*\*[ \t]*$ {
233 /* empty doc lines */
236 <GTK_DOC>^[ \t]*\*?\*\/ {
240 <GTK_DOC>^[ \t]*\*[ \t] {
250 before_comment = CLASS_CODE_I;
267 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
268 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
269 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
270 <PROPERTY_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
271 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
275 before_comment = C_CODE;
277 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
278 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
279 <PROPERTY_CODE_I>\/\* {BEGIN(COMMENT); before_comment = PROPERTY_CODE_I; }
281 if(before_comment == C_CODE) add_to_cbuf(yytext);
282 BEGIN(before_comment);
285 /* comment, ignore */
286 if(before_comment == C_CODE) add_to_cbuf(yytext);
289 /* comment, ignore */
290 if(before_comment == C_CODE) add_to_cbuf(yytext);
296 class_after_c = FALSE;
299 ccode_line = line_no;
304 class_after_c = FALSE;
307 ccode_line = line_no;
310 ^\%(ht|headertop)\{ {
313 class_after_c = FALSE;
316 ccode_line = line_no;
318 ^\%(ph|privateheader)\{ {
321 class_after_c = FALSE;
324 ccode_line = line_no;
329 class_after_c = FALSE;
332 ccode_line = line_no;
337 class_after_c = FALSE;
340 ccode_line = line_no;
341 if(look_for_includes==0)
348 if(look_for_includes==1)
353 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
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); }
360 <C_CODE>\\. { add_to_cbuf(yytext); }
365 before_string = C_CODE;
368 <PROPERTY_CODE_I>\" {
370 before_string = PROPERTY_CODE_I;
373 <CODE_STRING>\\. { add_to_cbuf(yytext); }
375 BEGIN(before_string);
377 if (before_string == PROPERTY_CODE_I) {
378 yylval.id = cbuf->str;
379 g_string_free (cbuf, FALSE);
384 <CODE_STRING>. { add_to_cbuf(yytext); }
385 <CODE_STRING>\n { add_to_cbuf(yytext); }
393 if(parenth_depth<0) {
395 } else if(parenth_depth==0 && class_after_c) {
404 <C_CODE>. { add_to_cbuf(yytext); }
405 <C_CODE>\n { add_to_cbuf(yytext); }
408 static int found_classes = 0;
409 look_for_includes = 2;
412 if(++found_classes > 1) {
413 error_print(GOB_ERROR, line_no,
414 "Only one class per file allowed");
420 error { return ERROR; }
421 enum { return ENUM; }
422 flags { return FLAGS; }
424 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
425 int maj = 0, min = 0, pl = 0;
426 int rmaj = 0, rmin = 0, rpl = 0;
427 int effective_maj = 0;
428 int effective_rmaj = 0;
431 sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl);
432 effective_rmaj = rmaj;
434 effective_rmaj = rmaj + 1;
436 p = strchr (yytext,'r');
437 g_assert (p); /* we MUST have found it */
438 sscanf (p, "requires %d.%d.%d", &maj, &min, &pl);
441 effective_maj = maj + 1;
444 (rmaj == maj && rmin < min) ||
445 (rmaj == maj && rmin == min && rpl < pl)) {
446 error_printf (GOB_ERROR, line_no,
447 "GOB version at least %d.%d.%d required "
449 "To upgrade your gob, see: "
450 "http://www.5z.com/jirka/gob.html",
451 maj, min, pl, VERSION);
454 if(effective_rmaj != effective_maj) {
455 error_printf(GOB_ERROR, line_no,
456 "GOB major version %d required "
458 "To upgrade your gob, see: "
459 "http://www.5z.com/jirka/gob.html",
460 effective_maj, VERSION);
465 <CLASS_CODE,CLASS_CODE_I>class|this {
467 error_printf(GOB_WARN, line_no,
468 "'%s' keyword should not "
469 "be used when generating "
475 <CLASS_CODE>from {return FROM;}
477 <CLASS_CODE_I,PROPERTY_CODE_I>void {return VOID;}
478 <CLASS_CODE_I,PROPERTY_CODE_I>struct {return STRUCT;}
479 <CLASS_CODE_I,PROPERTY_CODE_I>union {return UNION;}
480 <CLASS_CODE_I,PROPERTY_CODE_I>enum {return ENUM;}
481 <CLASS_CODE_I,PROPERTY_CODE_I>signed {return SIGNED;}
482 <CLASS_CODE_I,PROPERTY_CODE_I>unsigned {return UNSIGNED;}
483 <CLASS_CODE_I,PROPERTY_CODE_I>long {return LONG;}
484 <CLASS_CODE_I,PROPERTY_CODE_I>short {return SHORT;}
485 <CLASS_CODE_I,PROPERTY_CODE_I>int {return INT;}
486 <CLASS_CODE_I,PROPERTY_CODE_I>float {return FLOAT;}
487 <CLASS_CODE_I,PROPERTY_CODE_I>double {return DOUBLE;}
488 <CLASS_CODE_I,PROPERTY_CODE_I>char {return CHAR;}
489 <CLASS_CODE_I,PROPERTY_CODE_I>const {return CONST;}
491 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
493 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
494 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
495 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
496 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
497 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
498 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
499 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
500 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
501 <CLASS_CODE_I>property {
502 yylval.line = line_no;
503 BEGIN(PROPERTY_CODE);
506 <PROPERTY_CODE_I>nick { yylval.line = line_no; return NICK; }
507 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
508 <PROPERTY_CODE_I>maximum { yylval.line = line_no; return MAXIMUM; }
509 <PROPERTY_CODE_I>minimum { yylval.line = line_no; return MINIMUM; }
510 <PROPERTY_CODE_I>default_value { yylval.line = line_no; return DEFAULT_VALUE; }
511 <PROPERTY_CODE_I>flags { yylval.line = line_no; return FLAGS; }
512 <PROPERTY_CODE_I>type { yylval.line = line_no; return TYPE; }
513 <PROPERTY_CODE_I>flags_type { yylval.line = line_no; return FLAGS_TYPE; }
514 <PROPERTY_CODE_I>enum_type { yylval.line = line_no; return ENUM_TYPE; }
515 <PROPERTY_CODE_I>param_type { yylval.line = line_no; return PARAM_TYPE; }
516 <PROPERTY_CODE_I>boxed_type { yylval.line = line_no; return BOXED_TYPE; }
517 <PROPERTY_CODE_I>object_type { yylval.line = line_no; return OBJECT_TYPE; }
519 yylval.line = line_no;
520 property_paren_depth = 1;
521 BEGIN(PROPERTY_CODE_I);
524 <PROPERTY_CODE_I>[(] {
525 yylval.line = line_no;
526 property_paren_depth++;
529 <PROPERTY_CODE_I>[)] {
530 yylval.line = line_no;
531 property_paren_depth--;
532 if (property_paren_depth == 0) {
538 <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]* {
539 yylval.id = g_strdup(yytext);
542 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z0-9_]*)+ {
543 /* This is cpp kind of token thingie */
545 yylval.id = g_strdup(yytext);
551 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
552 /* this one is for a classname with a namespace */
553 yylval.id = g_strdup(yytext);
556 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
557 /* this is for a classname with an empty namespace */
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_]* {
562 yylval.id = g_strdup(yytext);
565 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>\'\\.\'|\'.\' {
566 yylval.id = g_strdup(yytext);
570 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
571 yylval.id = g_strdup(yytext);
582 class_after_c = TRUE;
583 yylval.line = line_no;
585 ccode_line = line_no;
593 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ; /*ignore*/
596 yylval.line = line_no;
600 <*>[\n\r] ; /*ignore*/