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,
28 #include "treefuncs.h"
33 static int parenth_depth = 0;
34 static int before_comment
35 /* New flex is on drugs */
36 #if defined(FLEX_SCANNER) && ! defined(INITIAL)
41 static gboolean class_after_c = FALSE;
42 static int code_type = CCODE;
43 static int before_string;
44 static int property_paren_depth = 0;
47 static char *gtk_doc_func = NULL; /* current gtk-doc func */
48 GHashTable *gtk_doc_hash = NULL;
50 static GString *cbuf = NULL;
53 GList *include_files = NULL;
54 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
55 static int look_for_includes = 0;
58 /* last filename parsed from a #line directive */
59 char *hline_filename = NULL;
65 cbuf = g_string_new(NULL);
67 cbuf = g_string_assign(cbuf, "");
75 cbuf = g_string_new(s);
77 cbuf = g_string_append(cbuf,s);
82 add_gtk_doc_func(void)
88 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
89 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
95 /* Ugly warning avoiding */
109 %x GTK_DOC_BEFORE_NAME
118 /* Avoid warning from flex, cuz flex sucks */
120 yy_current_state = 0;
125 <*>\n { line_no++; REJECT; }
127 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
128 /* Thy evil easter egg */
130 #define KK(x) =atoi(__(&,,x,))
131 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
132 #define PP(Q) (P%Q)==0
133 #define ___(x,y,z) if(x z y)
134 #define __(a,x,y,z) a(yytext[y] x z)
135 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
136 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
137 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
138 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
149 \/\/.*$ { ; /*comment, ignore*/ }
151 <*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? {
155 char *str=g_strdup(yytext);
157 /* find first digit of line number */
159 while(*p&&!isdigit(*p)) p++;
162 /* find end of line number */
163 while(*p&&isdigit(*p)) p++;
166 /* find beginning of filename */
171 /* find end of filename */
172 if(p) p=strchr(p,'"');
175 /* stash number (minus one because we don't count this line) */
176 if(number) line_no=atoi(number)-1;
180 if(hline_filename) g_free(hline_filename);
181 hline_filename=g_strdup(filename);
188 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
189 if(look_for_includes==1) {
192 char *str = g_strdup(yytext);
193 file = strchr(str,'"');
194 if(!file) file = strchr(str,'<');
196 p = strchr(file,'"');
197 if(!p) p = strchr(file,'>');
199 include_files = g_list_prepend(include_files,g_strdup(file));
205 <CLASS_CODE_I>\/\*\*[ \t]*$ {
206 /* eat out gtk doc stuff */
207 BEGIN(GTK_DOC_BEFORE_NAME);
210 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
211 /* empty doc lines */
214 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
217 p = strchr(yytext, '*');
218 g_free(gtk_doc_func);
219 gtk_doc_func = g_strdup(p+2);
220 p = strchr(gtk_doc_func, ':');
222 g_strstrip(gtk_doc_func);
224 <GTK_DOC_BEFORE_NAME>\*\/ {
227 <GTK_DOC_BEFORE_NAME>. {
229 before_comment = CLASS_CODE_I;
231 <GTK_DOC>^[ \t]*\*[ \t]*$ {
232 /* empty doc lines */
235 <GTK_DOC>^[ \t]*\*?\*\/ {
239 <GTK_DOC>^[ \t]*\*[ \t] {
249 before_comment = CLASS_CODE_I;
266 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
267 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
268 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
269 <PROPERTY_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
270 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
274 before_comment = C_CODE;
276 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
277 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
278 <PROPERTY_CODE_I>\/\* {BEGIN(COMMENT); before_comment = PROPERTY_CODE_I; }
280 if(before_comment == C_CODE) add_to_cbuf(yytext);
281 BEGIN(before_comment);
284 /* comment, ignore */
285 if(before_comment == C_CODE) add_to_cbuf(yytext);
288 /* comment, ignore */
289 if(before_comment == C_CODE) add_to_cbuf(yytext);
295 class_after_c = FALSE;
298 ccode_line = line_no;
303 class_after_c = FALSE;
306 ccode_line = line_no;
309 ^\%(ht|headertop)\{ {
312 class_after_c = FALSE;
315 ccode_line = line_no;
317 ^\%(ph|privateheader)\{ {
320 class_after_c = FALSE;
323 ccode_line = line_no;
328 class_after_c = FALSE;
331 ccode_line = line_no;
336 class_after_c = FALSE;
339 ccode_line = line_no;
340 if(look_for_includes==0)
347 if(look_for_includes==1)
352 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
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); }
359 <C_CODE>\\. { add_to_cbuf(yytext); }
364 before_string = C_CODE;
367 <PROPERTY_CODE_I>\" {
369 before_string = PROPERTY_CODE_I;
372 <CODE_STRING>\\. { add_to_cbuf(yytext); }
374 BEGIN(before_string);
376 if (before_string == PROPERTY_CODE_I) {
377 yylval.id = cbuf->str;
378 g_string_free (cbuf, FALSE);
383 <CODE_STRING>. { add_to_cbuf(yytext); }
384 <CODE_STRING>\n { add_to_cbuf(yytext); }
392 if(parenth_depth<0) {
394 } else if(parenth_depth==0 && class_after_c) {
403 <C_CODE>. { add_to_cbuf(yytext); }
404 <C_CODE>\n { add_to_cbuf(yytext); }
407 static int found_classes = 0;
408 look_for_includes = 2;
411 if(++found_classes > 1) {
412 error_print(GOB_ERROR, line_no,
413 "Only one class per file allowed");
419 error { return ERROR; }
420 enum { return ENUM; }
421 flags { return FLAGS; }
423 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
424 int maj = 0, min = 0, pl = 0;
425 int rmaj = 0, rmin = 0, rpl = 0;
426 int effective_maj = 0;
427 int effective_rmaj = 0;
430 sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl);
431 effective_rmaj = rmaj;
433 effective_rmaj = rmaj + 1;
435 p = strchr (yytext,'r');
436 g_assert (p); /* we MUST have found it */
437 sscanf (p, "requires %d.%d.%d", &maj, &min, &pl);
440 effective_maj = maj + 1;
443 (rmaj == maj && rmin < min) ||
444 (rmaj == maj && rmin == min && rpl < pl)) {
445 error_printf (GOB_ERROR, line_no,
446 "GOB version at least %d.%d.%d required "
448 "To upgrade your gob, see: "
449 "http://www.5z.com/jirka/gob.html",
450 maj, min, pl, VERSION);
453 if(effective_rmaj != effective_maj) {
454 error_printf(GOB_ERROR, line_no,
455 "GOB major version %d required "
457 "To upgrade your gob, see: "
458 "http://www.5z.com/jirka/gob.html",
459 effective_maj, VERSION);
464 <CLASS_CODE,CLASS_CODE_I>class|this {
466 error_printf(GOB_WARN, line_no,
467 "'%s' keyword should not "
468 "be used when generating "
474 <CLASS_CODE>from {return FROM;}
476 <CLASS_CODE_I,PROPERTY_CODE_I>void {return VOID;}
477 <CLASS_CODE_I,PROPERTY_CODE_I>struct {return STRUCT;}
478 <CLASS_CODE_I,PROPERTY_CODE_I>union {return UNION;}
479 <CLASS_CODE_I,PROPERTY_CODE_I>enum {return ENUM;}
480 <CLASS_CODE_I,PROPERTY_CODE_I>signed {return SIGNED;}
481 <CLASS_CODE_I,PROPERTY_CODE_I>unsigned {return UNSIGNED;}
482 <CLASS_CODE_I,PROPERTY_CODE_I>long {return LONG;}
483 <CLASS_CODE_I,PROPERTY_CODE_I>short {return SHORT;}
484 <CLASS_CODE_I,PROPERTY_CODE_I>int {return INT;}
485 <CLASS_CODE_I,PROPERTY_CODE_I>float {return FLOAT;}
486 <CLASS_CODE_I,PROPERTY_CODE_I>double {return DOUBLE;}
487 <CLASS_CODE_I,PROPERTY_CODE_I>char {return CHAR;}
488 <CLASS_CODE_I,PROPERTY_CODE_I>const {return CONST;}
490 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
492 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
493 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
494 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
495 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
496 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
497 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
498 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
499 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
500 <CLASS_CODE_I>property {
501 yylval.line = line_no;
502 BEGIN(PROPERTY_CODE);
505 <PROPERTY_CODE_I>nick { yylval.line = line_no; return NICK; }
506 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
507 <PROPERTY_CODE_I>maximum { yylval.line = line_no; return MAXIMUM; }
508 <PROPERTY_CODE_I>minimum { yylval.line = line_no; return MINIMUM; }
509 <PROPERTY_CODE_I>default_value { yylval.line = line_no; return DEFAULT_VALUE; }
510 <PROPERTY_CODE_I>flags { yylval.line = line_no; return FLAGS; }
511 <PROPERTY_CODE_I>type { yylval.line = line_no; return TYPE; }
512 <PROPERTY_CODE_I>flags_type { yylval.line = line_no; return FLAGS_TYPE; }
513 <PROPERTY_CODE_I>enum_type { yylval.line = line_no; return ENUM_TYPE; }
514 <PROPERTY_CODE_I>param_type { yylval.line = line_no; return PARAM_TYPE; }
515 <PROPERTY_CODE_I>boxed_type { yylval.line = line_no; return BOXED_TYPE; }
516 <PROPERTY_CODE_I>object_type { yylval.line = line_no; return OBJECT_TYPE; }
518 yylval.line = line_no;
519 property_paren_depth = 1;
520 BEGIN(PROPERTY_CODE_I);
523 <PROPERTY_CODE_I>[(] {
524 yylval.line = line_no;
525 property_paren_depth++;
528 <PROPERTY_CODE_I>[)] {
529 yylval.line = line_no;
530 property_paren_depth--;
531 if (property_paren_depth == 0) {
537 <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]* {
538 yylval.id = g_strdup(yytext);
541 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z0-9_]*)+ {
542 /* This is cpp kind of token thingie */
544 yylval.id = g_strdup(yytext);
550 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
551 /* this one is for a classname with a namespace */
552 yylval.id = g_strdup(yytext);
555 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
556 /* this is for a classname with an empty namespace */
557 yylval.id = g_strdup(yytext);
560 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]* {
561 yylval.id = g_strdup(yytext);
564 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>\'\\.\'|\'.\' {
565 yylval.id = g_strdup(yytext);
569 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
570 yylval.id = g_strdup(yytext);
581 class_after_c = TRUE;
582 yylval.line = line_no;
584 ccode_line = line_no;
592 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ; /*ignore*/
595 yylval.line = line_no;
599 <*>[\n\r] ; /*ignore*/