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 = INITIAL;
35 static gboolean class_after_c = FALSE;
36 static int code_type = CCODE;
37 static int before_string;
38 static int property_paren_depth = 0;
41 static char *gtk_doc_func = NULL; /* current gtk-doc func */
42 GHashTable *gtk_doc_hash = NULL;
44 static GString *cbuf = NULL;
47 GList *include_files = NULL;
48 /* 0 no, 1 means yes, 2+ means don't even start looking anymore */
49 static int look_for_includes = 0;
52 /* last filename parsed from a #line directive */
53 char *hline_filename = NULL;
59 cbuf = g_string_new(NULL);
61 cbuf = g_string_assign(cbuf, "");
69 cbuf = g_string_new(s);
71 cbuf = g_string_append(cbuf,s);
76 add_gtk_doc_func(void)
82 gtk_doc_hash = g_hash_table_new(g_str_hash, g_str_equal);
83 g_hash_table_insert(gtk_doc_hash, gtk_doc_func, g_strdup(cbuf->str));
89 /* Ugly warning avoiding */
103 %x GTK_DOC_BEFORE_NAME
112 /* Avoid warning from flex, cuz flex sucks */
114 yy_current_state = 0;
119 <*>\n { line_no++; REJECT; }
121 <COMMENT>^(I(S.RI).E\(([1-9][0-9]+|[2-9]))/(\)) {
122 /* Thy evil easter egg */
124 #define KK(x) =atoi(__(&,,x,))
125 #define MM(x,a) {QQ(i);for(i=2;i<x;i++){a}}
126 #define PP(Q) (P%Q)==0
127 #define ___(x,y,z) if(x z y)
128 #define __(a,x,y,z) a(yytext[y] x z)
129 #define O__O(a,b) fprintf(stderr,"%s is %s!\n",a,b)
130 QQ(m)=1;___(__(,==,2,'P'),__(,==,5,'M'),&&
131 ){QQ(P)KK(8);MM(P,___(PP(i),,)m=0;)}__(,=,
132 7,0);___(,,m){O__O(__( &,,8,),__(&,,2,));}
143 \/\/.*$ { ; /*comment, ignore*/ }
145 <*>^#[ \t]*line[ \t]+[0-9]+([ \t]\"[^\n\r\f\"]*\")? {
149 char *str=g_strdup(yytext);
151 /* find first digit of line number */
153 while(*p&&!isdigit(*p)) p++;
156 /* find end of line number */
157 while(*p&&isdigit(*p)) p++;
160 /* find beginning of filename */
165 /* find end of filename */
166 if(p) p=strchr(p,'"');
169 /* stash number (minus one because we don't count this line) */
170 if(number) line_no=atoi(number)-1;
174 if(hline_filename) g_free(hline_filename);
175 hline_filename=g_strdup(filename);
182 <C_CODE>^#[ \t]*include[ \t][<"][^\n">]*[>"] {
183 if(look_for_includes==1) {
186 char *str = g_strdup(yytext);
187 file = strchr(str,'"');
188 if(!file) file = strchr(str,'<');
190 p = strchr(file,'"');
191 if(!p) p = strchr(file,'>');
193 include_files = g_list_prepend(include_files,g_strdup(file));
199 <CLASS_CODE_I>\/\*\*[ \t]*$ {
200 /* eat out gtk doc stuff */
201 BEGIN(GTK_DOC_BEFORE_NAME);
204 <GTK_DOC_BEFORE_NAME>^[ \t]*\*[ \t]*$ {
205 /* empty doc lines */
208 <GTK_DOC_BEFORE_NAME>^[ \t]*\*\ [_a-zA-Z][_a-zA-Z0-9]*:?[ \t]*$ {
211 p = strchr(yytext, '*');
212 g_free(gtk_doc_func);
213 gtk_doc_func = g_strdup(p+2);
214 p = strchr(gtk_doc_func, ':');
216 g_strstrip(gtk_doc_func);
218 <GTK_DOC_BEFORE_NAME>\*\/ {
221 <GTK_DOC_BEFORE_NAME>. {
223 before_comment = CLASS_CODE_I;
225 <GTK_DOC>^[ \t]*\*[ \t]*$ {
226 /* empty doc lines */
229 <GTK_DOC>^[ \t]*\*?\*\/ {
233 <GTK_DOC>^[ \t]*\*\ {
243 before_comment = CLASS_CODE_I;
260 <C_CODE>\/\/.*$ { add_to_cbuf(yytext); /*comment, ignore*/ }
261 <CLASS_CODE>\/\/.*$ { ; /*comment, ignore*/ }
262 <CLASS_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
263 <PROPERTY_CODE_I>\/\/.*$ { ; /*comment, ignore*/ }
264 \/\* {BEGIN(COMMENT); before_comment = INITIAL; }
268 before_comment = C_CODE;
270 <CLASS_CODE>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE; }
271 <CLASS_CODE_I>\/\* {BEGIN(COMMENT); before_comment = CLASS_CODE_I; }
272 <PROPERTY_CODE_I>\/\* {BEGIN(COMMENT); before_comment = PROPERTY_CODE_I; }
274 if(before_comment == C_CODE) add_to_cbuf(yytext);
275 BEGIN(before_comment);
278 /* comment, ignore */
279 if(before_comment == C_CODE) add_to_cbuf(yytext);
282 /* comment, ignore */
283 if(before_comment == C_CODE) add_to_cbuf(yytext);
289 class_after_c = FALSE;
292 ccode_line = line_no;
297 class_after_c = FALSE;
300 ccode_line = line_no;
303 ^\%(ht|headertop)\{ {
306 class_after_c = FALSE;
309 ccode_line = line_no;
311 ^\%(ph|privateheader)\{ {
314 class_after_c = FALSE;
317 ccode_line = line_no;
322 class_after_c = FALSE;
325 ccode_line = line_no;
330 class_after_c = FALSE;
333 ccode_line = line_no;
334 if(look_for_includes==0)
341 if(look_for_includes==1)
346 <C_CODE>\'\{\' { add_to_cbuf(yytext); }
347 <C_CODE>\'\\\{\' { add_to_cbuf(yytext); }
348 <C_CODE>\'\}\' { add_to_cbuf(yytext); }
349 <C_CODE>\'\\\}\' { add_to_cbuf(yytext); }
350 <C_CODE>\'\"\' { add_to_cbuf(yytext); }
351 <C_CODE>\'\\\"\' { add_to_cbuf(yytext); }
353 <C_CODE>\\. { add_to_cbuf(yytext); }
358 before_string = C_CODE;
361 <PROPERTY_CODE_I>\" {
363 before_string = PROPERTY_CODE_I;
366 <CODE_STRING>\\. { add_to_cbuf(yytext); }
368 BEGIN(before_string);
370 if (before_string == PROPERTY_CODE_I) {
371 yylval.id = cbuf->str;
372 g_string_free (cbuf, FALSE);
377 <CODE_STRING>. { add_to_cbuf(yytext); }
378 <CODE_STRING>\n { add_to_cbuf(yytext); }
386 if(parenth_depth<0) {
388 } else if(parenth_depth==0 && class_after_c) {
397 <C_CODE>. { add_to_cbuf(yytext); }
398 <C_CODE>\n { add_to_cbuf(yytext); }
401 static int found_classes = 0;
402 look_for_includes = 2;
405 if(++found_classes > 1) {
406 error_print(GOB_ERROR, line_no,
407 "Only one class per file allowed");
413 error { return ERROR; }
414 enum { return ENUM; }
415 flags { return FLAGS; }
417 ^[ \t]*requires[ \t]+[0-9]+\.[0-9]+\.[0-9]+[\t ]*$ {
418 int maj = 0, min = 0, pl = 0;
419 int rmaj = 0, rmin = 0, rpl = 0;
420 int effective_maj = 0;
421 int effective_rmaj = 0;
424 sscanf (VERSION, "%d.%d.%d", &rmaj, &rmin, &rpl);
425 effective_rmaj = rmaj;
427 effective_rmaj = rmaj + 1;
429 p = strchr (yytext,'r');
430 g_assert (p); /* we MUST have found it */
431 sscanf (p, "requires %d.%d.%d", &maj, &min, &pl);
434 effective_maj = maj + 1;
437 (rmaj == maj && rmin < min) ||
438 (rmaj == maj && rmin == min && rpl < pl)) {
439 error_printf (GOB_ERROR, line_no,
440 "GOB version at least %d.%d.%d required "
442 "To upgrade your gob, see: "
443 "http://www.5z.com/jirka/gob.html",
444 maj, min, pl, VERSION);
447 if(effective_rmaj != effective_maj) {
448 error_printf(GOB_ERROR, line_no,
449 "GOB major version %d required "
451 "To upgrade your gob, see: "
452 "http://www.5z.com/jirka/gob.html",
453 effective_maj, VERSION);
458 <CLASS_CODE,CLASS_CODE_I>class|this {
460 error_printf(GOB_WARN, line_no,
461 "'%s' keyword should not "
462 "be used when generating "
468 <CLASS_CODE>from {return FROM;}
470 <CLASS_CODE_I,PROPERTY_CODE_I>void {return VOID;}
471 <CLASS_CODE_I,PROPERTY_CODE_I>struct {return STRUCT;}
472 <CLASS_CODE_I,PROPERTY_CODE_I>union {return UNION;}
473 <CLASS_CODE_I,PROPERTY_CODE_I>enum {return ENUM;}
474 <CLASS_CODE_I,PROPERTY_CODE_I>signed {return SIGNED;}
475 <CLASS_CODE_I,PROPERTY_CODE_I>unsigned {return UNSIGNED;}
476 <CLASS_CODE_I,PROPERTY_CODE_I>long {return LONG;}
477 <CLASS_CODE_I,PROPERTY_CODE_I>short {return SHORT;}
478 <CLASS_CODE_I,PROPERTY_CODE_I>int {return INT;}
479 <CLASS_CODE_I,PROPERTY_CODE_I>float {return FLOAT;}
480 <CLASS_CODE_I,PROPERTY_CODE_I>double {return DOUBLE;}
481 <CLASS_CODE_I,PROPERTY_CODE_I>char {return CHAR;}
482 <CLASS_CODE_I,PROPERTY_CODE_I>const {return CONST;}
484 <CLASS_CODE_I>\.\.\. {return THREEDOTS;}
486 <CLASS_CODE_I>public {yylval.line = line_no; return PUBLIC;}
487 <CLASS_CODE_I>private {yylval.line = line_no; return PRIVATE;}
488 <CLASS_CODE_I>protected {yylval.line = line_no; return PROTECTED;}
489 <CLASS_CODE_I>classwide {yylval.line = line_no; return CLASSWIDE;}
490 <CLASS_CODE_I>argument {yylval.line = line_no; return ARGUMENT;}
491 <CLASS_CODE_I>virtual {yylval.line = line_no; return VIRTUAL;}
492 <CLASS_CODE_I>signal {yylval.line = line_no; return SIGNAL;}
493 <CLASS_CODE_I>override {yylval.line = line_no; return OVERRIDE;}
494 <CLASS_CODE_I>property {
495 yylval.line = line_no;
496 BEGIN(PROPERTY_CODE);
499 <PROPERTY_CODE_I>nick { yylval.line = line_no; return NICK; }
500 <PROPERTY_CODE_I>blurb { yylval.line = line_no; return BLURB; }
501 <PROPERTY_CODE_I>maximum { yylval.line = line_no; return MAXIMUM; }
502 <PROPERTY_CODE_I>minimum { yylval.line = line_no; return MINIMUM; }
503 <PROPERTY_CODE_I>default_value { yylval.line = line_no; return DEFAULT_VALUE; }
504 <PROPERTY_CODE_I>flags { yylval.line = line_no; return FLAGS; }
505 <PROPERTY_CODE_I>type { yylval.line = line_no; return TYPE; }
506 <PROPERTY_CODE_I>flags_type { yylval.line = line_no; return FLAGS_TYPE; }
507 <PROPERTY_CODE_I>enum_type { yylval.line = line_no; return ENUM_TYPE; }
508 <PROPERTY_CODE_I>param_type { yylval.line = line_no; return PARAM_TYPE; }
509 <PROPERTY_CODE_I>boxed_type { yylval.line = line_no; return BOXED_TYPE; }
510 <PROPERTY_CODE_I>object_type { yylval.line = line_no; return OBJECT_TYPE; }
512 yylval.line = line_no;
513 property_paren_depth = 1;
514 BEGIN(PROPERTY_CODE_I);
517 <PROPERTY_CODE_I>[(] {
518 yylval.line = line_no;
519 property_paren_depth++;
522 <PROPERTY_CODE_I>[)] {
523 yylval.line = line_no;
524 property_paren_depth--;
525 if (property_paren_depth == 0) {
531 <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]* {
532 yylval.id = g_strdup(yytext);
535 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)+ {
536 /* this one is for a classname with a namespace */
537 yylval.id = g_strdup(yytext);
540 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>:[A-Za-z_][A-Za-z0-9_]*(:[A-Za-z0-9_]*)* {
541 /* this is for a classname with an empty namespace */
542 yylval.id = g_strdup(yytext);
545 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>[A-Za-z_][A-Za-z0-9_]* {
546 yylval.id = g_strdup(yytext);
549 <CLASS_CODE,CLASS_CODE_I,PROPERTY_CODE,PROPERTY_CODE_I,INITIAL>\'\\.\'|\'.\' {
550 yylval.id = g_strdup(yytext);
554 <CLASS_CODE_I>(\[[0-9]*\]|\[[A-Za-z_][A-Za-z0-9_]*\])+ {
555 yylval.id = g_strdup(yytext);
566 class_after_c = TRUE;
567 yylval.line = line_no;
569 ccode_line = line_no;
577 <CLASS_CODE,CLASS_CODE_I,INITIAL,PROPERTY_CODE,PROPERTY_CODE_I>[\f\t ] ; /*ignore*/
580 yylval.line = line_no;
584 <*>[\n\r] ; /*ignore*/
588 /* Ugly warning avoiding */
590 static void warning_avoider(void) G_GNUC_UNUSED;
591 static void warning_avoider(void) {
592 yy_flex_realloc(NULL, 0);